/** * Convert a CachedBlockList into a DatanodeCommand with a list of blocks. * * @param list The {@link CachedBlocksList}. This function * clears the list. * @param action The action to perform in the command. * @param poolId The block pool id. * @return A DatanodeCommand to be sent back to the DN, or null if * there is nothing to be done. */ private DatanodeCommand getCacheCommand(CachedBlocksList list, int action, String poolId) { int length = list.size(); if (length == 0) { return null; } // Read the existing cache commands. long[] blockIds = new long[length]; int i = 0; for (CachedBlock cachedBlock : list) { blockIds[i++] = cachedBlock.getBlockId(); } return new BlockIdCommand(action, poolId, blockIds); }
public static BlockIdCommandProto convert(BlockIdCommand cmd) { BlockIdCommandProto.Builder builder = BlockIdCommandProto.newBuilder() .setBlockPoolId(cmd.getBlockPoolId()); switch (cmd.getAction()) { case DatanodeProtocol.DNA_CACHE: builder.setAction(BlockIdCommandProto.Action.CACHE); break; case DatanodeProtocol.DNA_UNCACHE: builder.setAction(BlockIdCommandProto.Action.UNCACHE); break; default: throw new AssertionError("Invalid action"); } long[] blockIds = cmd.getBlockIds(); for (int i = 0; i < blockIds.length; i++) { builder.addBlockIds(blockIds[i]); } return builder.build(); }
case DatanodeProtocol.DNA_CACHE: LOG.info("DatanodeCommand action: DNA_CACHE for " + blockIdCmd.getBlockPoolId() + " of [" + blockIdArrayToString(blockIdCmd.getBlockIds()) + "]"); dn.getFSDataset().cache(blockIdCmd.getBlockPoolId(), blockIdCmd.getBlockIds()); break; case DatanodeProtocol.DNA_UNCACHE: LOG.info("DatanodeCommand action: DNA_UNCACHE for " + blockIdCmd.getBlockPoolId() + " of [" + blockIdArrayToString(blockIdCmd.getBlockIds()) + "]"); dn.getFSDataset().uncache(blockIdCmd.getBlockPoolId(), blockIdCmd.getBlockIds()); break; case DatanodeProtocol.DNA_SHUTDOWN:
case DatanodeProtocol.DNA_CACHE: LOG.info("DatanodeCommand action: DNA_CACHE for " + blockIdCmd.getBlockPoolId() + " of [" + blockIdArrayToString(blockIdCmd.getBlockIds()) + "]"); dn.getFSDataset().cache(blockIdCmd.getBlockPoolId(), blockIdCmd.getBlockIds()); break; case DatanodeProtocol.DNA_UNCACHE: LOG.info("DatanodeCommand action: DNA_UNCACHE for " + blockIdCmd.getBlockPoolId() + " of [" + blockIdArrayToString(blockIdCmd.getBlockIds()) + "]"); dn.getFSDataset().uncache(blockIdCmd.getBlockPoolId(), blockIdCmd.getBlockIds()); break; case DatanodeProtocol.DNA_SHUTDOWN:
public static BlockIdCommandProto convert(BlockIdCommand cmd) { BlockIdCommandProto.Builder builder = BlockIdCommandProto.newBuilder() .setBlockPoolId(cmd.getBlockPoolId()); switch (cmd.getAction()) { case DatanodeProtocol.DNA_CACHE: builder.setAction(BlockIdCommandProto.Action.CACHE); break; case DatanodeProtocol.DNA_UNCACHE: builder.setAction(BlockIdCommandProto.Action.UNCACHE); break; default: throw new AssertionError("Invalid action"); } long[] blockIds = cmd.getBlockIds(); for (int i = 0; i < blockIds.length; i++) { builder.addBlockIds(blockIds[i]); } return builder.build(); }
public static BlockIdCommand convert(BlockIdCommandProto blkIdCmd) { int numBlockIds = blkIdCmd.getBlockIdsCount(); long blockIds[] = new long[numBlockIds]; for (int i = 0; i < numBlockIds; i++) { blockIds[i] = blkIdCmd.getBlockIds(i); } int action = DatanodeProtocol.DNA_UNKNOWN; switch (blkIdCmd.getAction()) { case CACHE: action = DatanodeProtocol.DNA_CACHE; break; case UNCACHE: action = DatanodeProtocol.DNA_UNCACHE; break; default: throw new AssertionError("Unknown action type: " + blkIdCmd.getAction()); } return new BlockIdCommand(action, blkIdCmd.getBlockPoolId(), blockIds); }
case DatanodeProtocol.DNA_CACHE: LOG.info("DatanodeCommand action: DNA_CACHE for " + blockIdCmd.getBlockPoolId() + " of [" + blockIdArrayToString(blockIdCmd.getBlockIds()) + "]"); dn.getFSDataset().cache(blockIdCmd.getBlockPoolId(), blockIdCmd.getBlockIds()); break; case DatanodeProtocol.DNA_UNCACHE: LOG.info("DatanodeCommand action: DNA_UNCACHE for " + blockIdCmd.getBlockPoolId() + " of [" + blockIdArrayToString(blockIdCmd.getBlockIds()) + "]"); dn.getFSDataset().uncache(blockIdCmd.getBlockPoolId(), blockIdCmd.getBlockIds()); break; case DatanodeProtocol.DNA_SHUTDOWN:
public static BlockIdCommandProto convert(BlockIdCommand cmd) { BlockIdCommandProto.Builder builder = BlockIdCommandProto.newBuilder() .setBlockPoolId(cmd.getBlockPoolId()); switch (cmd.getAction()) { case DatanodeProtocol.DNA_CACHE: builder.setAction(BlockIdCommandProto.Action.CACHE); break; case DatanodeProtocol.DNA_UNCACHE: builder.setAction(BlockIdCommandProto.Action.UNCACHE); break; default: throw new AssertionError("Invalid action"); } long[] blockIds = cmd.getBlockIds(); for (int i = 0; i < blockIds.length; i++) { builder.addBlockIds(blockIds[i]); } return builder.build(); }
/** * Convert a CachedBlockList into a DatanodeCommand with a list of blocks. * * @param list The {@link CachedBlocksList}. This function * clears the list. * @param datanode The datanode. * @param action The action to perform in the command. * @param poolId The block pool id. * @return A DatanodeCommand to be sent back to the DN, or null if * there is nothing to be done. */ private DatanodeCommand getCacheCommand(CachedBlocksList list, DatanodeDescriptor datanode, int action, String poolId) { int length = list.size(); if (length == 0) { return null; } // Read the existing cache commands. long[] blockIds = new long[length]; int i = 0; for (Iterator<CachedBlock> iter = list.iterator(); iter.hasNext(); ) { CachedBlock cachedBlock = iter.next(); blockIds[i++] = cachedBlock.getBlockId(); } return new BlockIdCommand(action, poolId, blockIds); }
/** * Convert a CachedBlockList into a DatanodeCommand with a list of blocks. * * @param list The {@link CachedBlocksList}. This function * clears the list. * @param datanode The datanode. * @param action The action to perform in the command. * @param poolId The block pool id. * @return A DatanodeCommand to be sent back to the DN, or null if * there is nothing to be done. */ private DatanodeCommand getCacheCommand(CachedBlocksList list, DatanodeDescriptor datanode, int action, String poolId) { int length = list.size(); if (length == 0) { return null; } // Read the existing cache commands. long[] blockIds = new long[length]; int i = 0; for (Iterator<CachedBlock> iter = list.iterator(); iter.hasNext(); ) { CachedBlock cachedBlock = iter.next(); blockIds[i++] = cachedBlock.getBlockId(); } return new BlockIdCommand(action, poolId, blockIds); }
public static BlockIdCommand convert(BlockIdCommandProto blkIdCmd) { int numBlockIds = blkIdCmd.getBlockIdsCount(); long blockIds[] = new long[numBlockIds]; for (int i = 0; i < numBlockIds; i++) { blockIds[i] = blkIdCmd.getBlockIds(i); } int action = DatanodeProtocol.DNA_UNKNOWN; switch (blkIdCmd.getAction()) { case CACHE: action = DatanodeProtocol.DNA_CACHE; break; case UNCACHE: action = DatanodeProtocol.DNA_UNCACHE; break; default: throw new AssertionError("Unknown action type: " + blkIdCmd.getAction()); } return new BlockIdCommand(action, blkIdCmd.getBlockPoolId(), blockIds); }
public static BlockIdCommand convert(BlockIdCommandProto blkIdCmd) { int numBlockIds = blkIdCmd.getBlockIdsCount(); long blockIds[] = new long[numBlockIds]; for (int i = 0; i < numBlockIds; i++) { blockIds[i] = blkIdCmd.getBlockIds(i); } int action = DatanodeProtocol.DNA_UNKNOWN; switch (blkIdCmd.getAction()) { case CACHE: action = DatanodeProtocol.DNA_CACHE; break; case UNCACHE: action = DatanodeProtocol.DNA_UNCACHE; break; default: throw new AssertionError("Unknown action type: " + blkIdCmd.getAction()); } return new BlockIdCommand(action, blkIdCmd.getBlockPoolId(), blockIds); }
/** * Creates a cache or uncache DatanodeCommand from an array of locations */ private static DatanodeCommand getResponse(HdfsBlockLocation[] locs, int action) { String bpid = locs[0].getLocatedBlock().getBlock().getBlockPoolId(); long[] blocks = new long[locs.length]; for (int i=0; i<locs.length; i++) { blocks[i] = locs[i].getLocatedBlock().getBlock().getBlockId(); } return new BlockIdCommand(action, bpid, blocks); }