Debugging “Wrong FS expected: file:///” exception from HDFS

本文介绍了一个常见的Hadoop编程错误,即在尝试从HDFS读取文件时遇到的WrongFS异常,并详细解释了如何通过正确配置路径资源来解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The Performance Zone is supported by New Relic and AppDynamics. Both are leaders in the APM space with high-profile customers and massive cost reductions for those users.

I just spent some time putting together some basic Java code to read some data from HDFS. Pretty basic stuff. No map reduce involved. Pretty boilerplate code like the stuff from this popular tutorial on the topic.

No matter what, I kept hitting my head on this error:

Exception in thread “main” java.lang.IllegalArgumentException: Wrong FS: hdfs://localhost:9000/user/hadoop/DOUG_SVD/out.txt, expected: file:///

If you checkout the tutorial above, what’s supposed to be happening is that an instance of Hadoop’s Configuration should encounter a fs.default.name property, in one of the config files its given. The Configuration should realize that this property has a value of hdfs://localhost:9000. When you use the Configuration to create a Hadoop FileSystem instance, it should happily read this property from Configuration and process paths from HDFS. That’s a long way of saying these three lines of Java code:

1. // pickup config files off classpath
2. Configuration conf = new Configuration()
3. // explicitely add other config files
4. conf.addResource("/home/hadoop/conf/core-site.xml");
5. // create a FileSystem object needed to load file resources
6. FileSystem fs = FileSystem.get(conf);
7. // load files and stuff below!

Well… My Hadoop config files (core-site.xml) appear setup correctly. It appears to be in my CLASSPATH. I’m even trying to explicitly add the resource. Basically I’ve followed all the troubleshooting tips you’re supposed to follow when you encounter this exception. But I’m STILL getting this exception. Head meet wall. This has to be something stupid.

Troubleshooting Hadoop’s Configuration & FileSystem Objects

Well before I reveal my dumb mistake in the above code, it turns out there’s some helpful functions to help debug these kind of problems:

As Configuration is just a bunch of key/value pairs from a set of resources, its useful to know what resources it thinks it loaded and what properties it thinks it loaded from those files.

  • getRaw() — return the raw value for a configuration item (like conf.getRaw("fs.default.name"))
  • toString() — Configuration‘s toString shows the resources loaded

You can similarly checkout FileSystem‘s helpful toString method. It nicely lays out where it thinks its pointing (native vs HDFS vs S3 etc).

So if you similarly are looking for a stupid mistake like I was, pepper your code with printouts of these bits of info. They will at least point you in a new direction to search for your dumb mistake.

Drumroll Please

Turns out I missed the crucial step of passing a Path object not a String to addResource. They appear to do slightly different things. Adding a String adds a resource relative to the classpath. Adding a Path is used to add a resource at an absolute location and does not consider the classpath. So to explicitly load the correct config file, the code above gets turned into (drumroll please):

1. // pickup config files off classpath
2. Configuration conf = new Configuration()
3. // explicitely add other config files
4. // PASS A PATH NOT A STRING!
5. conf.addResource(new Path("/home/hadoop/conf/core-site.xml"));
6. FileSystem fs = FileSystem.get(conf);
7. // load files and stuff below!

Then Tada! everything magically works! Hopefully these tips can save you the next time you encounter these kinds of problems.

<think>好的,我现在要解决用户在Yocto编译过程中遇到的“QA Issue: already-stripped”错误。首先,我需要了解这个错误的原因。用户提到在do_package阶段出现这个错误,日志显示文件被提前剥离了调试符号。根据之前的引用内容,比如引用[3]中提到的-dev包包含非符号链接的.so文件的问题,类似的QA问题通常与Yocto的打包规则有关。 Yocto在构建过程中会运行一系列的QA检查,确保生成的包符合预期标准。当出现“already-stripped”错误时,可能是因为某些文件在打包前已经被剥离了调试符号,而Yocto期望这些符号保留到特定阶段处理。例如,某些构建系统可能在编译过程中自动剥离符号,而Yocto的strip命令会在之后再次尝试处理,但发现没有符号可剥离,从而报错。 接下来,我需要回忆Yocto如何处理调试符号。通常,Yocto会在do_install之后执行do_package阶段,其中包含剥离符号的操作。如果上游的Makefile或构建脚本在安装步骤中已经执行了strip,就会导致冲突。此时,解决方案可能涉及禁止构建系统提前剥离符号。 根据用户提供的引用,例如引用[1]和[3]中的问题,解决方式通常是修改bbappend文件,添加相应的配置选项。类似地,这里可能需要调整构建参数,禁止内置的strip操作。例如,在Autotools项目中,可以通过设置参数来禁止strip,或者在CMake项目中传递特定的选项。 另外,可能需要检查配方中的INSANE_SKIP设置,添加对already-stripped的忽略,但这可能只是临时解决方案,正确的做法是阻止构建系统提前剥离符号。因此,应该优先修改构建系统的行为,而不是跳过QA检查。 总结可能的解决步骤:首先确认构建系统是否自行剥离符号,找到对应的编译选项禁用该行为。其次,在Yocto配方中添加相应的配置,如EXTRA_OECONF或EXTRA_OECMAKE参数。如果无法修改构建系统,可以考虑使用INSANE_SKIP来跳过该检查,但需谨慎。</think>在Yocto编译过程中出现"already-stripped" QA错误,通常是由于构建系统在安装阶段提前剥离了调试符号,与Yocto的默认处理流程冲突所致。以下是分步解决方案: ### 解决方法 1. **禁止构建系统自动剥离符号** - 对于Autotools项目: ```bitbake EXTRA_OECONF += "--disable-strip" ``` 或显式覆盖install命令: ```bitbake do_install:append() { oe_runmake 'STRIP=echo' install } ``` - 对于CMake项目: ```bitbake EXTRA_OECMAKE += "-DCMAKE_STRIP=: -DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=1" ``` 2. **调整Yocto配方参数** 在配方文件中添加: ```bitbake INHIBIT_PACKAGE_STRIP = "1" INHIBIT_SYSROOT_STRIP = "1" ``` 这会完全禁用Yocto的符号剥离流程,需要确保后续打包不需要这些操作[^3]。 3. **(临时方案)跳过QA检查** 在配方中添加: ```bitbake INSANE_SKIP:${PN} += "already-stripped" ``` 此方法适用于紧急情况,但会降低构建质量检查强度[^1]。 ### 原理说明 Yocto默认会在`do_package`阶段通过`${STRIP}`命令处理调试符号。当构建系统提前执行了strip操作,会导致Yocto检测到"文件已被剥离过但未保留调试信息"的矛盾状态。通过`INHIBIT_*`参数可关闭Yocto的默认处理,而修改构建系统参数则从源头阻止了双重剥离[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值