@Test public void testLRUEmulation() throws Exception { final long blockSize = 1000; Map<StorageDir, List<Long>> expectedListPerDir = new HashMap<>(); long blockId = 0; for (StorageTier tier : mMetaManager.getTiers()) { for (StorageDir dir : tier.getStorageDirs()) { expectedListPerDir.put(dir, new LinkedList<>()); while (dir.getAvailableBytes() > 0) { createBlock(++blockId, blockSize, dir); accessBlock(blockId); expectedListPerDir.get(dir).add(blockId); } } } for (StorageDir dir : expectedListPerDir.keySet()) { validateIteratorHeader( mBlockIterator.getIterator(dir.toBlockStoreLocation(), BlockOrder.Natural), expectedListPerDir.get(dir).iterator()); } }
@Override public Iterator<Long> getIterator(BlockStoreLocation location, BlockOrder order) { EvictionPlan evictionPlan = mEvictor.freeSpaceWithView(mReservedSpaces.get(location.tierAlias()), location, new BlockMetadataEvictorView(mMetadataManager, Collections.emptySet(), Collections.emptySet()), Evictor.Mode.BEST_EFFORT); List<Long> toEvict = Collections.emptyList(); if (evictionPlan.toEvict() != null) { toEvict = evictionPlan.toEvict().stream().map((kvp) -> kvp.getFirst()).collect(Collectors.toList()); } List<Long> toMove = Collections.emptyList(); if (evictionPlan.toMove() != null) { toMove = evictionPlan.toMove().stream().map((kvp) -> kvp.getSrcBlockId()) .collect(Collectors.toList()); } List<Long> iteratorList = toEvict; if (!toMove.isEmpty()) { iteratorList = toMove; } if (order == BlockOrder.Reverse) { Collections.reverse(iteratorList); } return iteratorList.iterator(); }
EmulatingBlockIterator implements BlockIterator { @Override public Iterator<Long> getIterator(BlockStoreLocation location, BlockOrder order) { EvictionPlan evictionPlan = mEvictor.freeSpaceWithView(mReservedSpaces.get(location.tierAlias()), location, new BlockMetadataEvictorView(mMetadataManager, Collections.emptySet(), Collections.emptySet()), Evictor.Mode.BEST_EFFORT); List<Long> toEvict = Collections.emptyList(); if (evictionPlan.toEvict() != null) { toEvict = evictionPlan.toEvict().stream().map((kvp) -> kvp.getFirst()).collect(Collectors.toList()); } List<Long> toMove = Collections.emptyList(); if (evictionPlan.toMove() != null) { toMove = evictionPlan.toMove().stream().map((kvp) -> kvp.getSrcBlockId()) .collect(Collectors.toList()); } List<Long> iteratorList = toEvict; if (!toMove.isEmpty()) { iteratorList = toMove; } if (order == BlockOrder.Reverse) { Collections.reverse(iteratorList); } return iteratorList.iterator(); } }
EmulatingBlockIterator implements BlockIterator { @Override public Iterator<Long> getIterator(BlockStoreLocation location, BlockOrder order) { EvictionPlan evictionPlan = mEvictor.freeSpaceWithView(mReservedSpaces.get(location.tierAlias()), location, new BlockMetadataEvictorView(mMetadataManager, Collections.emptySet(), Collections.emptySet()), Evictor.Mode.BEST_EFFORT); List<Long> toEvict = Collections.emptyList(); if (evictionPlan.toEvict() != null) { toEvict = evictionPlan.toEvict().stream().map((kvp) -> kvp.getFirst()).collect(Collectors.toList()); } List<Long> toMove = Collections.emptyList(); if (evictionPlan.toMove() != null) { toMove = evictionPlan.toMove().stream().map((kvp) -> kvp.getSrcBlockId()) .collect(Collectors.toList()); } List<Long> iteratorList = toEvict; if (!toMove.isEmpty()) { iteratorList = toMove; } if (order == BlockOrder.Reverse) { Collections.reverse(iteratorList); } return iteratorList.iterator(); } EmulatingBlockIterator(BlockMetadataManager metadataManager, Evictor evictor); }
EmulatingBlockIterator implements BlockIterator { @Override public Iterator<Long> getIterator(BlockStoreLocation location, BlockOrder order) { EvictionPlan evictionPlan = mEvictor.freeSpaceWithView(mReservedSpaces.get(location.tierAlias()), location, new BlockMetadataEvictorView(mMetadataManager, Collections.emptySet(), Collections.emptySet()), Evictor.Mode.BEST_EFFORT); List<Long> toEvict = Collections.emptyList(); if (evictionPlan.toEvict() != null) { toEvict = evictionPlan.toEvict().stream().map((kvp) -> kvp.getFirst()).collect(Collectors.toList()); } List<Long> toMove = Collections.emptyList(); if (evictionPlan.toMove() != null) { toMove = evictionPlan.toMove().stream().map((kvp) -> kvp.getSrcBlockId()) .collect(Collectors.toList()); } List<Long> iteratorList = toEvict; if (!toMove.isEmpty()) { iteratorList = toMove; } if (order == BlockOrder.Reverse) { Collections.reverse(iteratorList); } return iteratorList.iterator(); } EmulatingBlockIterator(BlockMetadataManager metadataManager, Evictor evictor); @Override Iterator<Long> getIterator(BlockStoreLocation location, BlockOrder order); @Override List<Long> getIntersectionList(BlockStoreLocation srcLocation, BlockOrder srcOrder,
      BlockStoreLocation dstLocation, BlockOrder dstOrder, int intersectionWidth,
      BlockOrder intersectionOrder, Function<Long, Boolean> blockFilterFunc); @Override Pair<List<Long>, List<Long>> getSwaps(BlockStoreLocation srcLocation, BlockOrder srcOrder,
      BlockStoreLocation dstLocation, BlockOrder dstOrder, int swapRange,
      BlockOrder intersectionOrder, Function<Long, Boolean> blockFilterFunc); @Override boolean aligned(BlockStoreLocation srcLocation, BlockStoreLocation dstLocation,
                         BlockOrder order, Function<Long, Boolean> blockFilterFunc); @Override List<BlockStoreEventListener> getListeners(); }
EmulatingBlockIterator implements BlockIterator { @Override public Iterator<Long> getIterator(BlockStoreLocation location, BlockOrder order) { EvictionPlan evictionPlan = mEvictor.freeSpaceWithView(mReservedSpaces.get(location.tierAlias()), location, new BlockMetadataEvictorView(mMetadataManager, Collections.emptySet(), Collections.emptySet()), Evictor.Mode.BEST_EFFORT); List<Long> toEvict = Collections.emptyList(); if (evictionPlan.toEvict() != null) { toEvict = evictionPlan.toEvict().stream().map((kvp) -> kvp.getFirst()).collect(Collectors.toList()); } List<Long> toMove = Collections.emptyList(); if (evictionPlan.toMove() != null) { toMove = evictionPlan.toMove().stream().map((kvp) -> kvp.getSrcBlockId()) .collect(Collectors.toList()); } List<Long> iteratorList = toEvict; if (!toMove.isEmpty()) { iteratorList = toMove; } if (order == BlockOrder.Reverse) { Collections.reverse(iteratorList); } return iteratorList.iterator(); } EmulatingBlockIterator(BlockMetadataManager metadataManager, Evictor evictor); @Override Iterator<Long> getIterator(BlockStoreLocation location, BlockOrder order); @Override List<Long> getIntersectionList(BlockStoreLocation srcLocation, BlockOrder srcOrder,
      BlockStoreLocation dstLocation, BlockOrder dstOrder, int intersectionWidth,
      BlockOrder intersectionOrder, Function<Long, Boolean> blockFilterFunc); @Override Pair<List<Long>, List<Long>> getSwaps(BlockStoreLocation srcLocation, BlockOrder srcOrder,
      BlockStoreLocation dstLocation, BlockOrder dstOrder, int swapRange,
      BlockOrder intersectionOrder, Function<Long, Boolean> blockFilterFunc); @Override boolean aligned(BlockStoreLocation srcLocation, BlockStoreLocation dstLocation,
                         BlockOrder order, Function<Long, Boolean> blockFilterFunc); @Override List<BlockStoreEventListener> getListeners();  }