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