@Test public void allocateBlock() throws Exception { ServerConfiguration.set(PropertyKey.WORKER_ALLOCATOR_CLASS, GreedyAllocator.class.getName()); mAllocator = Allocator.Factory.create(getMetadataEvictorView()); assertTempBlockMeta(mAllocator, mAnyTierLoc, 500, true, "MEM", 0); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc2, 1000, true, "SSD", 0); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc2, 1500, true, "SSD", 1); assertTempBlockMeta(mAllocator, mAnyTierLoc, 1000, true, "SSD", 0); assertTempBlockMeta(mAllocator, mAnyTierLoc, 1000, true, "HDD", 0); assertTempBlockMeta(mAllocator, mAnyTierLoc, 2000, true, "HDD", 0); assertTempBlockMeta(mAllocator, mAnyTierLoc, 500, true, "MEM", 0); assertTempBlockMeta(mAllocator, mAnyTierLoc, 500, true, "SSD", 1); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc3, 1000, true, "HDD", 1); assertTempBlockMeta(mAllocator, mAnyTierLoc, 700, true, "HDD", 1); ServerConfiguration.reset(); }
@Nullable private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location) { Preconditions.checkNotNull(location, "location"); if (location.equals(BlockStoreLocation.anyTier())) { for (StorageTierView tierView : mMetadataView.getTierViews()) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getAvailableBytes() >= blockSize) { return dirView; } } } return null; } String mediumType = location.mediumType(); if (!mediumType.equals(BlockStoreLocation.ANY_MEDIUM) && location.equals(BlockStoreLocation.anyDirInTierWithMedium(mediumType))) { for (StorageTierView tierView : mMetadataView.getTierViews()) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getMediumType().equals(mediumType) && dirView.getAvailableBytes() >= blockSize) { return dirView; } } } return null; } String tierAlias = location.tierAlias(); StorageTierView tierView = mMetadataView.getTierView(tierAlias); if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getAvailableBytes() >= blockSize) { return dirView; } } return null; } int dirIndex = location.dir(); StorageDirView dirView = tierView.getDirView(dirIndex); if (dirView != null && dirView.getAvailableBytes() >= blockSize) { return dirView; } return null; }
GreedyAllocator implements Allocator { @Nullable private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location) { Preconditions.checkNotNull(location, "location"); if (location.equals(BlockStoreLocation.anyTier())) { for (StorageTierView tierView : mMetadataView.getTierViews()) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getAvailableBytes() >= blockSize) { return dirView; } } } return null; } String mediumType = location.mediumType(); if (!mediumType.equals(BlockStoreLocation.ANY_MEDIUM) && location.equals(BlockStoreLocation.anyDirInTierWithMedium(mediumType))) { for (StorageTierView tierView : mMetadataView.getTierViews()) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getMediumType().equals(mediumType) && dirView.getAvailableBytes() >= blockSize) { return dirView; } } } return null; } String tierAlias = location.tierAlias(); StorageTierView tierView = mMetadataView.getTierView(tierAlias); if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getAvailableBytes() >= blockSize) { return dirView; } } return null; } int dirIndex = location.dir(); StorageDirView dirView = tierView.getDirView(dirIndex); if (dirView != null && dirView.getAvailableBytes() >= blockSize) { return dirView; } return null; } }
GreedyAllocator implements Allocator { @Nullable private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location) { Preconditions.checkNotNull(location, "location"); if (location.equals(BlockStoreLocation.anyTier())) { for (StorageTierView tierView : mMetadataView.getTierViews()) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getAvailableBytes() >= blockSize) { return dirView; } } } return null; } String mediumType = location.mediumType(); if (!mediumType.equals(BlockStoreLocation.ANY_MEDIUM) && location.equals(BlockStoreLocation.anyDirInTierWithMedium(mediumType))) { for (StorageTierView tierView : mMetadataView.getTierViews()) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getMediumType().equals(mediumType) && dirView.getAvailableBytes() >= blockSize) { return dirView; } } } return null; } String tierAlias = location.tierAlias(); StorageTierView tierView = mMetadataView.getTierView(tierAlias); if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getAvailableBytes() >= blockSize) { return dirView; } } return null; } int dirIndex = location.dir(); StorageDirView dirView = tierView.getDirView(dirIndex); if (dirView != null && dirView.getAvailableBytes() >= blockSize) { return dirView; } return null; } GreedyAllocator(BlockMetadataView view); }
GreedyAllocator implements Allocator { @Nullable private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location) { Preconditions.checkNotNull(location, "location"); if (location.equals(BlockStoreLocation.anyTier())) { for (StorageTierView tierView : mMetadataView.getTierViews()) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getAvailableBytes() >= blockSize) { return dirView; } } } return null; } String mediumType = location.mediumType(); if (!mediumType.equals(BlockStoreLocation.ANY_MEDIUM) && location.equals(BlockStoreLocation.anyDirInTierWithMedium(mediumType))) { for (StorageTierView tierView : mMetadataView.getTierViews()) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getMediumType().equals(mediumType) && dirView.getAvailableBytes() >= blockSize) { return dirView; } } } return null; } String tierAlias = location.tierAlias(); StorageTierView tierView = mMetadataView.getTierView(tierAlias); if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getAvailableBytes() >= blockSize) { return dirView; } } return null; } int dirIndex = location.dir(); StorageDirView dirView = tierView.getDirView(dirIndex); if (dirView != null && dirView.getAvailableBytes() >= blockSize) { return dirView; } return null; } GreedyAllocator(BlockMetadataView view); @Override StorageDirView allocateBlockWithView(long sessionId, long blockSize,
      BlockStoreLocation location, BlockMetadataView metadataView); }
GreedyAllocator implements Allocator { @Nullable private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location) { Preconditions.checkNotNull(location, "location"); if (location.equals(BlockStoreLocation.anyTier())) { for (StorageTierView tierView : mMetadataView.getTierViews()) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getAvailableBytes() >= blockSize) { return dirView; } } } return null; } String mediumType = location.mediumType(); if (!mediumType.equals(BlockStoreLocation.ANY_MEDIUM) && location.equals(BlockStoreLocation.anyDirInTierWithMedium(mediumType))) { for (StorageTierView tierView : mMetadataView.getTierViews()) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getMediumType().equals(mediumType) && dirView.getAvailableBytes() >= blockSize) { return dirView; } } } return null; } String tierAlias = location.tierAlias(); StorageTierView tierView = mMetadataView.getTierView(tierAlias); if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.getAvailableBytes() >= blockSize) { return dirView; } } return null; } int dirIndex = location.dir(); StorageDirView dirView = tierView.getDirView(dirIndex); if (dirView != null && dirView.getAvailableBytes() >= blockSize) { return dirView; } return null; } GreedyAllocator(BlockMetadataView view); @Override StorageDirView allocateBlockWithView(long sessionId, long blockSize,
      BlockStoreLocation location, BlockMetadataView metadataView);  }