更改 Hadoop 中现有文件的块大小

Change Block size of existing files in Hadoop

考虑在 hdfs-site.xml 中默认块大小为 64MB 的 hadoop 集群。然而,后来团队决定将其更改为 128MB。这是我对上述情况的问题?

  1. 此更改是否需要重新启动集群,或者它会被自动占用并且所有新文件都将具有默认的 128MB 块大小?
  2. 现有的块大小为 64M 的文件会怎样?配置中的更改会自动应用于现有文件吗?如果它会自动完成,那么什么时候会完成 - 一旦更改完成或集群启动时?如果没有自动完成,那么如何手动完成此块更改?

如前所述 你的观点:

  1. 无论何时更改配置,都需要重新启动 NameNode 和 DataNode 才能更改它们的行为。
  2. 不,不会。它将保留旧文件的旧块大小。为了让它接受新的块更改,您需要重写数据。您可以对数据执行 hadoop fs -cp 或 distcp。新副本将具有新的块大小,您可以删除旧数据。

查看link了解更多信息。

Will this change require restart of the cluster or it will be taken up automatically and all new files will have the default block size of 128MB

此 属性 更改需要重新启动集群才能生效。

What will happen to the existing files which have block size of 64M? Will the change in the configuration apply to existing files automatically?

现有块不会改变它们的块大小。

If not automatically done, then how to manually do this block change?

要更改现有文件,您可以使用 distcp。它将使用新的块大小复制文件。但是,您必须手动删除块大小较旧的旧文件。这是您可以使用的命令

hadoop distcp -Ddfs.block.size=XX /path/to/old/files /path/to/new/files/with/larger/block/sizes.

关于第 1 点 - 在 Hadoop 1.2.1 上,更改 hdfs-site.xml 文件中的 dfs.block.size 后不需要重新启动。通过查看位于 http://namenode:50070/dfshealth.jsp

的 Hadoop 管理页面,可以轻松验证文件块大小

确保更改所有数据节点上的 dfs.block.size。