hadoop - 如何让HDFS的replica block的位置自己设置?

标签 hadoop hdfs

我的目标是让HDFS的replica block的位置节点自己定。 查看HDFS的代码后,我在这里找到了调用轨迹(hadoop 2.2版本)

BlockManager.getDatanodeDescriptors(List<String>) line: 1400    
BlockManager.chooseTarget(String, int, DatanodeDescriptor, HashMap<Node,Node>, long, List<String>) line: 1378   
FSNamesystem.getAdditionalBlock(String, long, String, ExtendedBlock, HashMap<Node,Node>, List<String>) line: 2477   
NameNodeRpcServer.addBlock(String, String, ExtendedBlock, DatanodeInfo[], long, String[]) line: 555 
ClientNamenodeProtocolServerSideTranslatorPB.addBlock(RpcController, ClientNamenodeProtocolProtos$AddBlockRequestProto) line: 387   
ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(Descriptors$MethodDescriptor, RpcController, Message) line: 59582  
ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(RPC$Server, String, Writable, long) line: 585  
ProtobufRpcEngine$Server(RPC$Server).call(RPC$RpcKind, String, Writable, long) line: 928    

我发现 BlockManager.java 有一个 chooseTarget方法:

 public DatanodeDescriptor[] chooseTarget(final String src,
  final int numOfReplicas, final DatanodeDescriptor client,
  final HashMap<Node, Node> excludedNodes,
  final long blocksize, List<String> favoredNodes) throws IOException {

我想如果我可以设置 List<String> favoredNodes的值(value),那么我的目标就可以实现。

最佳答案

我从 DistributedFileSystem.java(hadoop 2.2 版本)找到 API

  /**
   * Same as  
   * {@link #create(Path, FsPermission, boolean, int, short, long, 
   * Progressable)} with the addition of favoredNodes that is a hint to 
   * where the namenode should place the file blocks.
   * The favored nodes hint is not persisted in HDFS. Hence it may be honored
   * at the creation time only. HDFS could move the blocks during balancing or
   * replication, to move the blocks from favored nodes. A value of null means
   * no favored nodes for this create
   */
  public HdfsDataOutputStream create(final Path f,
      final FsPermission permission, final boolean overwrite,
      final int bufferSize, final short replication, final long blockSize,
      final Progressable progress, final InetSocketAddress[] favoredNodes)
          throws IOException {

关于hadoop - 如何让HDFS的replica block的位置自己设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32779439/

相关文章:

Hadoop PIG Helper GROUP 错误

hadoop - "the container format for fields in a row"对文件格式意味着什么?

networking - Hadoop 自定义节点上的输入分布

hadoop - 将 Solr HDFS 数据复制到另一个集群

hadoop - 数据未加载到 Hive 中的分区表中

java - 如何在hadoop中获取像素rgb值?

hadoop - 当我按JPS命令时,辅助名称节点未显示

shell - Oozie 在随机节点上运行 shell 脚本

docker - 如何修复简单的HDFS HA群集中的 “HA is not enabled”错误

file - 如何检查HDFS文件是否包含二进制数据?