BlockManager implements BlockStatsMXBean { @VisibleForTesting public BlockPlacementPolicy getBlockPlacementPolicy() { return placementPolicies.getPolicy(false); } BlockManager(final Namesystem namesystem, final Configuration conf); long getPendingReplicationBlocksCount(); long getUnderReplicatedBlocksCount(); long getCorruptReplicaBlocksCount(); long getScheduledReplicationBlocksCount(); long getPendingDeletionBlocksCount(); long getStartupDelayBlockDeletionInMs(); long getExcessBlocksCount(); long getPostponedMisreplicatedBlocksCount(); int getPendingDataNodeMessageCount(); BlockStoragePolicy getStoragePolicy(final String policyName); BlockStoragePolicy getStoragePolicy(final byte policyId); BlockStoragePolicy[] getStoragePolicies(); void setBlockPoolId(String blockPoolId); String getBlockPoolId(); BlockStoragePolicySuite getStoragePolicySuite(); @VisibleForTesting BlockTokenSecretManager getBlockTokenSecretManager(); void activate(Configuration conf, long blockTotal); void close(); DatanodeManager getDatanodeManager(); @VisibleForTesting BlockPlacementPolicy getBlockPlacementPolicy(); void metaSave(PrintWriter out); int getMaxReplicationStreams(); int getDefaultStorageNum(BlockInfo block); short getMinStorageNum(BlockInfo block); boolean hasMinStorage(BlockInfo block); boolean hasMinStorage(BlockInfo block, int liveNum); boolean commitOrCompleteLastBlock(BlockCollection bc,
      Block commitBlock); void forceCompleteBlock(final BlockInfo block); LocatedBlock convertLastBlockToUnderConstruction(
      BlockCollection bc, long bytesToRemove); LocatedBlocks createLocatedBlocks(final BlockInfo[] blocks,
      final long fileSizeExcludeBlocksUnderConstruction,
      final boolean isFileUnderConstruction, final long offset,
      final long length, final boolean needBlockToken,
      final boolean inSnapshot, FileEncryptionInfo feInfo,
      ErasureCodingPolicy ecPolicy); ExportedBlockKeys getBlockKeys(); void setBlockToken(final LocatedBlock b,
      final AccessMode mode); DataEncryptionKey generateDataEncryptionKey(); short adjustReplication(short replication); void verifyReplication(String src,
                          short replication,
                          String clientName); boolean isSufficientlyReplicated(BlockInfo b); BlocksWithLocations getBlocks(DatanodeID datanode, long size
      ); void findAndMarkBlockAsCorrupt(final ExtendedBlock blk,
      final DatanodeInfo dn, String storageID, String reason); void setPostponeBlocksFromFuture(boolean postpone); int getUnderReplicatedNotMissingBlocks(); DatanodeStorageInfo[] chooseTarget4WebHDFS(String src,
      DatanodeDescriptor clientnode, Set<Node> excludes, long blocksize); DatanodeStorageInfo[] chooseTarget4AdditionalDatanode(String src,
      int numAdditionalNodes,
      Node clientnode,
      List<DatanodeStorageInfo> chosen,
      Set<Node> excludes,
      long blocksize,
      byte storagePolicyID,
      boolean isStriped); DatanodeStorageInfo[] chooseTarget4NewBlock(final String src,
      final int numOfReplicas, final Node client,
      final Set<Node> excludedNodes,
      final long blocksize,
      final List<String> favoredNodes,
      final byte storagePolicyID,
      final boolean isStriped); long requestBlockReportLeaseId(DatanodeRegistration nodeReg); void registerDatanode(DatanodeRegistration nodeReg); void setBlockTotal(long total); boolean isInSafeMode(); String getSafeModeTip(); void leaveSafeMode(boolean force); void removeBlocksAndUpdateSafemodeTotal(BlocksMapUpdateInfo blocks); boolean processReport(final DatanodeID nodeID,
      final DatanodeStorage storage,
      final BlockListAsLongs newReport, BlockReportContext context,
      boolean lastStorageInRpc); void markBlockReplicasAsCorrupt(Block oldBlock,
      BlockInfo block,
      long oldGenerationStamp, long oldNumBytes, 
      DatanodeStorageInfo[] newStorages); void processQueuedMessagesForBlock(Block b); void processAllPendingDNMessages(); void processMisReplicatedBlocks(); double getReplicationQueuesInitProgress(); boolean hasNonEcBlockUsingStripedID(); void setReplication(
      final short oldRepl, final short newRepl, final BlockInfo b); void removeStoredBlock(BlockInfo storedBlock, DatanodeDescriptor node); void processIncrementalBlockReport(final DatanodeID nodeID,
      final StorageReceivedDeletedBlocks srdb); NumberReplicas countNodes(Block b); int getActiveBlockCount(); DatanodeStorageInfo[] getStorages(BlockInfo block); Iterable<DatanodeStorageInfo> getStorages(final Block block); int getTotalBlocks(); void removeBlock(BlockInfo block); BlockInfo getStoredBlock(Block block); void checkReplication(BlockCollection bc); boolean checkBlocksProperlyReplicated(
      String src, BlockInfo[] blocks); @VisibleForTesting boolean containsInvalidateBlock(final DatanodeInfo dn,
      final Block block); short getExpectedReplicaNum(BlockInfo block); long getMissingBlocksCount(); long getMissingReplOneBlocksCount(); BlockInfo addBlockCollection(BlockInfo block,
      BlockCollection bc); BlockInfo addBlockCollectionWithCheck(
      BlockInfo block, BlockCollection bc); int numCorruptReplicas(Block block); void removeBlockFromMap(BlockInfo block); int getCapacity(); Iterator<BlockInfo> getCorruptReplicaBlockIterator(); Collection<DatanodeDescriptor> getCorruptReplicas(Block block); String getCorruptReason(Block block, DatanodeDescriptor node); int numOfUnderReplicatedBlocks(); void clearQueues(); static LocatedBlock newLocatedBlock(
      ExtendedBlock b, DatanodeStorageInfo[] storages,
      long startOffset, boolean corrupt); static LocatedStripedBlock newLocatedStripedBlock(
      ExtendedBlock b, DatanodeStorageInfo[] storages,
      byte[] indices, long startOffset, boolean corrupt); static LocatedBlock newLocatedBlock(ExtendedBlock eb, BlockInfo info,
      DatanodeStorageInfo[] locs, long offset); void shutdown(); void clear(); BlockReportLeaseManager getBlockReportLeaseManager(); @Override // BlockStatsMXBean Map<StorageType, StorageTypeStats> getStorageTypeStats(); void initializeReplQueues(); boolean isPopulatingReplQueues(); void setInitializedReplQueues(boolean v); boolean shouldPopulateReplQueues(); long getBytesInFuture(); void clearBytesInFuture(); void enqueueBlockOp(final Runnable action); T runBlockOp(final Callable<T> action); @VisibleForTesting void flushBlockOps(); int getBlockOpQueueLength(); static final Logger LOG; static final Logger blockLog; final Map<String, LightWeightHashSet<BlockInfo>> excessReplicateMap; final UnderReplicatedBlocks neededReplications; final short maxReplication; final short minReplication; final int defaultReplication; }
@Test public void testUseDelHint() { DatanodeStorageInfo delHint = new DatanodeStorageInfo( DFSTestUtil.getLocalDatanodeDescriptor(), new DatanodeStorage("id")); List<DatanodeStorageInfo> moreThan1Racks = Arrays.asList(delHint); List<StorageType> excessTypes = new ArrayList<>(); BlockPlacementPolicyDefault policyDefault = (BlockPlacementPolicyDefault) bm.getBlockPlacementPolicy(); excessTypes.add(StorageType.DEFAULT); Assert.assertTrue(policyDefault.useDelHint(delHint, null, moreThan1Racks, null, excessTypes)); excessTypes.remove(0); excessTypes.add(StorageType.SSD); Assert.assertFalse(policyDefault.useDelHint(delHint, null, moreThan1Racks, null, excessTypes)); }