DatanodeDescriptor extends DatanodeInfo { public Block[] getInvalidateBlocks(int maxblocks) { synchronized (invalidateBlocks) { Block[] deleteList = invalidateBlocks.pollToArray(new Block[Math.min( invalidateBlocks.size(), maxblocks)]); return deleteList.length == 0 ? null : deleteList; } } DatanodeDescriptor(DatanodeID nodeID);  DatanodeDescriptor(DatanodeID nodeID, 
                            String networkLocation); CachedBlocksList getPendingCached(); CachedBlocksList getCached(); CachedBlocksList getPendingUncached(); boolean isAlive(); void setAlive(boolean isAlive); synchronized boolean needKeyUpdate(); synchronized void setNeedKeyUpdate(boolean needKeyUpdate); LeavingServiceStatus getLeavingServiceStatus(); @VisibleForTesting boolean isHeartbeatedSinceRegistration(); @VisibleForTesting DatanodeStorageInfo getStorageInfo(String storageID); @VisibleForTesting DatanodeStorageInfo[] getStorageInfos(); EnumSet<StorageType> getStorageTypes(); StorageReport[] getStorageReports(); void resetBlocks(); void clearBlockQueues(); int numBlocks(); @VisibleForTesting void incrementPendingReplicationWithoutTargets(); @VisibleForTesting void decrementPendingReplicationWithoutTargets(); @VisibleForTesting void addBlockToBeReplicated(Block block,
      DatanodeStorageInfo[] targets); @VisibleForTesting int getNumberOfBlocksToBeErasureCoded(); @VisibleForTesting int getNumberOfReplicateBlocks(); List<BlockECReconstructionInfo> getErasureCodeCommand(
      int maxTransfers); BlockInfo[] getLeaseRecoveryCommand(int maxTransfers); Block[] getInvalidateBlocks(int maxblocks); @VisibleForTesting boolean containsInvalidateBlock(Block block); DatanodeStorageInfo chooseStorage4Block(StorageType t,
      long blockSize); int getBlocksScheduled(StorageType t); int getBlocksScheduled(); @Override int hashCode(); @Override boolean equals(Object obj); void setDisallowed(boolean flag); boolean isDisallowed(); int getVolumeFailures(); VolumeFailureSummary getVolumeFailureSummary(); @Override void updateRegInfo(DatanodeID nodeReg); synchronized long getBalancerBandwidth(); synchronized void setBalancerBandwidth(long bandwidth); @Override String dumpDatanode(); long getLastCachingDirectiveSentTimeMs(); void setLastCachingDirectiveSentTimeMs(long time); boolean checkBlockReportReceived(); void setForceRegistration(boolean force); boolean isRegistered(); boolean hasStorageType(StorageType type); static final Logger LOG; static final DatanodeDescriptor[] EMPTY_ARRAY; }
@Test public void testGetInvalidateBlocks() throws Exception { final int MAX_BLOCKS = 10; final int REMAINING_BLOCKS = 2; final int MAX_LIMIT = MAX_BLOCKS - REMAINING_BLOCKS; DatanodeDescriptor dd = DFSTestUtil.getLocalDatanodeDescriptor(); ArrayList<Block> blockList = new ArrayList<Block>(MAX_BLOCKS); for (int i=0; i<MAX_BLOCKS; i++) { blockList.add(new Block(i, 0, GenerationStamp.LAST_RESERVED_STAMP)); } dd.addBlocksToBeInvalidated(blockList); Block[] bc = dd.getInvalidateBlocks(MAX_LIMIT); assertEquals(bc.length, MAX_LIMIT); bc = dd.getInvalidateBlocks(MAX_LIMIT); assertEquals(bc.length, REMAINING_BLOCKS); }