@Test public void allocateBlock() throws Exception { ServerConfiguration.set(PropertyKey.WORKER_ALLOCATOR_CLASS, RoundRobinAllocator.class.getName()); mAllocator = Allocator.Factory.create(getMetadataEvictorView()); assertTempBlockMeta(mAllocator, mAnyTierLoc, 500, true, "MEM", 0); assertTempBlockMeta(mAllocator, mAnyTierLoc, 600, true, "SSD", 0); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc2, 700, true, "SSD", 1); assertTempBlockMeta(mAllocator, mAnyTierLoc, 700, true, "SSD", 0); assertTempBlockMeta(mAllocator, mAnyTierLoc, 1000, true, "SSD", 1); assertTempBlockMeta(mAllocator, mAnyTierLoc, 700, true, "SSD", 0); assertTempBlockMeta(mAllocator, mAnyTierLoc, 700, true, "HDD", 0); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc1, 200, true, "MEM", 0); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc1, 100, true, "MEM", 0); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc1, 700, false, "", 0); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc2, 100, true, "SSD", 1); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc2, 100, true, "SSD", 1); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc2, 1500, false, "", 0); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc3, 2000, true, "HDD", 1); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc3, 3000, true, "HDD", 2); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc3, 500, true, "HDD", 0); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc3, 2000, false, "HDD", 0); assertTempBlockMeta(mAllocator, mAnyDirInTierLoc3, 300, true, "HDD", 1); ServerConfiguration.reset(); }
@Nullable private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location) { Preconditions.checkNotNull(location, "location"); if (location.equals(BlockStoreLocation.anyTier())) { int tierIndex = 0; for (int i = 0; i < mMetadataView.getTierViews().size(); i++) { StorageTierView tierView = mMetadataView.getTierViews().get(tierIndex); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } else { tierIndex++; } } } else if (location.equals(BlockStoreLocation.anyDirInTier(location.tierAlias()))) { StorageTierView tierView = mMetadataView.getTierView(location.tierAlias()); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } } else if (location.equals(BlockStoreLocation.anyDirInTierWithMedium(location.mediumType()))) { String medium = location.mediumType(); int tierIndex = 0; for (int i = 0; i < mMetadataView.getTierViews().size(); i++) { StorageTierView tierView = mMetadataView.getTierViews().get(tierIndex); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, medium); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } else { tierIndex++; } } } else { StorageTierView tierView = mMetadataView.getTierView(location.tierAlias()); StorageDirView dirView = tierView.getDirView(location.dir()); if (dirView != null && dirView.getAvailableBytes() >= blockSize) { return dirView; } } return null; }
RoundRobinAllocator implements Allocator { @Nullable private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location) { Preconditions.checkNotNull(location, "location"); if (location.equals(BlockStoreLocation.anyTier())) { int tierIndex = 0; for (int i = 0; i < mMetadataView.getTierViews().size(); i++) { StorageTierView tierView = mMetadataView.getTierViews().get(tierIndex); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } else { tierIndex++; } } } else if (location.equals(BlockStoreLocation.anyDirInTier(location.tierAlias()))) { StorageTierView tierView = mMetadataView.getTierView(location.tierAlias()); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } } else if (location.equals(BlockStoreLocation.anyDirInTierWithMedium(location.mediumType()))) { String medium = location.mediumType(); int tierIndex = 0; for (int i = 0; i < mMetadataView.getTierViews().size(); i++) { StorageTierView tierView = mMetadataView.getTierViews().get(tierIndex); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, medium); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } else { tierIndex++; } } } else { StorageTierView tierView = mMetadataView.getTierView(location.tierAlias()); StorageDirView dirView = tierView.getDirView(location.dir()); if (dirView != null && dirView.getAvailableBytes() >= blockSize) { return dirView; } } return null; } }
RoundRobinAllocator implements Allocator { @Nullable private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location) { Preconditions.checkNotNull(location, "location"); if (location.equals(BlockStoreLocation.anyTier())) { int tierIndex = 0; for (int i = 0; i < mMetadataView.getTierViews().size(); i++) { StorageTierView tierView = mMetadataView.getTierViews().get(tierIndex); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } else { tierIndex++; } } } else if (location.equals(BlockStoreLocation.anyDirInTier(location.tierAlias()))) { StorageTierView tierView = mMetadataView.getTierView(location.tierAlias()); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } } else if (location.equals(BlockStoreLocation.anyDirInTierWithMedium(location.mediumType()))) { String medium = location.mediumType(); int tierIndex = 0; for (int i = 0; i < mMetadataView.getTierViews().size(); i++) { StorageTierView tierView = mMetadataView.getTierViews().get(tierIndex); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, medium); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } else { tierIndex++; } } } else { StorageTierView tierView = mMetadataView.getTierView(location.tierAlias()); StorageDirView dirView = tierView.getDirView(location.dir()); if (dirView != null && dirView.getAvailableBytes() >= blockSize) { return dirView; } } return null; } RoundRobinAllocator(BlockMetadataView view); }
RoundRobinAllocator implements Allocator { @Nullable private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location) { Preconditions.checkNotNull(location, "location"); if (location.equals(BlockStoreLocation.anyTier())) { int tierIndex = 0; for (int i = 0; i < mMetadataView.getTierViews().size(); i++) { StorageTierView tierView = mMetadataView.getTierViews().get(tierIndex); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } else { tierIndex++; } } } else if (location.equals(BlockStoreLocation.anyDirInTier(location.tierAlias()))) { StorageTierView tierView = mMetadataView.getTierView(location.tierAlias()); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } } else if (location.equals(BlockStoreLocation.anyDirInTierWithMedium(location.mediumType()))) { String medium = location.mediumType(); int tierIndex = 0; for (int i = 0; i < mMetadataView.getTierViews().size(); i++) { StorageTierView tierView = mMetadataView.getTierViews().get(tierIndex); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, medium); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } else { tierIndex++; } } } else { StorageTierView tierView = mMetadataView.getTierView(location.tierAlias()); StorageDirView dirView = tierView.getDirView(location.dir()); if (dirView != null && dirView.getAvailableBytes() >= blockSize) { return dirView; } } return null; } RoundRobinAllocator(BlockMetadataView view); @Override StorageDirView allocateBlockWithView(long sessionId, long blockSize,
      BlockStoreLocation location, BlockMetadataView metadataView); }
RoundRobinAllocator implements Allocator { @Nullable private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location) { Preconditions.checkNotNull(location, "location"); if (location.equals(BlockStoreLocation.anyTier())) { int tierIndex = 0; for (int i = 0; i < mMetadataView.getTierViews().size(); i++) { StorageTierView tierView = mMetadataView.getTierViews().get(tierIndex); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } else { tierIndex++; } } } else if (location.equals(BlockStoreLocation.anyDirInTier(location.tierAlias()))) { StorageTierView tierView = mMetadataView.getTierView(location.tierAlias()); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } } else if (location.equals(BlockStoreLocation.anyDirInTierWithMedium(location.mediumType()))) { String medium = location.mediumType(); int tierIndex = 0; for (int i = 0; i < mMetadataView.getTierViews().size(); i++) { StorageTierView tierView = mMetadataView.getTierViews().get(tierIndex); int dirViewIndex = getNextAvailDirInTier(tierView, blockSize, medium); if (dirViewIndex >= 0) { mTierAliasToLastDirMap.put(tierView.getTierViewAlias(), dirViewIndex); return tierView.getDirView(dirViewIndex); } else { tierIndex++; } } } else { StorageTierView tierView = mMetadataView.getTierView(location.tierAlias()); StorageDirView dirView = tierView.getDirView(location.dir()); if (dirView != null && dirView.getAvailableBytes() >= blockSize) { return dirView; } } return null; } RoundRobinAllocator(BlockMetadataView view); @Override StorageDirView allocateBlockWithView(long sessionId, long blockSize,
      BlockStoreLocation location, BlockMetadataView metadataView);  }