Hadoop fs 查找块大小?

发布于 2024-12-19 16:53:08 字数 145 浏览 2 评论 0 原文

在 Hadoop fs 中如何查找特定文件的块大小?

我主要对命令行感兴趣,例如:

hadoop fs ... hdfs://fs1.data/...

但它看起来不存在。有Java解决方案吗?

In Hadoop fs how to lookup the block size for a particular file?

I was primarily interested in a command line, something like:

hadoop fs ... hdfs://fs1.data/...

But it looks like that does not exist. Is there a Java solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

预谋 2024-12-26 16:53:08

其他答案中的 fsck 命令列出了块并允许您查看块的数量。但是,要查看实际块大小(以字节为单位)且没有额外的麻烦,请执行以下操作:

hadoop fs -stat %o /filename

默认块大小为:

hdfs getconf -confKey dfs.blocksize

有关单位的详细信息

然而,块大小的单位未记录在 hadoop fs -stat 命令中,看着 源代码行它调用的方法的文档< /a> 我们可以看到它使用字节并且无法报告超过大约 9 艾字节的块大小。

hdfs getconf 命令的单位可能不是字节。它返回配置文件中用于 dfs.blocksize 的任何字符串。 (这可以在 最终函数其间接调用者

The fsck commands in the other answers list the blocks and allow you to see the number of blocks. However, to see the actual block size in bytes with no extra cruft do:

hadoop fs -stat %o /filename

Default block size is:

hdfs getconf -confKey dfs.blocksize

Details about units

The units for the block size are not documented in the hadoop fs -stat command, however, looking at the source line and the docs for the method it calls we can see it uses bytes and cannot report block sizes over about 9 exabytes.

The units for the hdfs getconf command may not be bytes. It returns whatever string is being used for dfs.blocksize in the configuration file. (This is seen in the source for the final function and its indirect caller)

深海夜未眠 2024-12-26 16:53:08

似乎 hadoop fs 没有选项可以执行此操作。

但hadoop fsck 可以。

你可以试试这个

$HADOOP_HOME/bin/hadoop fsck /path/to/file -files -blocks

Seems hadoop fs doesn't have options to do this.

But hadoop fsck could.

You can try this

$HADOOP_HOME/bin/hadoop fsck /path/to/file -files -blocks
猫弦 2024-12-26 16:53:08

我认为这应该是可行的:

hadoop fsck /filename -blocks

但我得到连接被拒绝

I think it should be doable with:

hadoop fsck /filename -blocks

but I get Connection refused

要走干脆点 2024-12-26 16:53:08

尝试编写下面的代码

path=hdfs://a/b/c

size=`hdfs dfs -count ${path} | awk '{print $3}'`
echo $size

Try to code below

path=hdfs://a/b/c

size=`hdfs dfs -count ${path} | awk '{print $3}'`
echo $size
秋千易 2024-12-26 16:53:08

为了显示 HDFS 中现有文件的实际块大小,我使用了:

[pety@master1 ~]$ hdfs dfs -stat %o /tmp/testfile_64
67108864

For displaying the actual block size of the existing file within HDFS I used:

[pety@master1 ~]$ hdfs dfs -stat %o /tmp/testfile_64
67108864
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文