为什么我的测试hadoop代码连接到libhdfs会引发Segmentation错误?

时间:2014-06-18 14:00:34

标签: c++ hadoop segmentation-fault

我使用libhdfs连接并写入hdfs系统。该程序工作正常,但是当我将GDB附加到它时,它在hdfsConnect中进行了段错误,但是连接通过并且我能够写入hdfs系统。但有时,连接不会发生。 seg故障困扰着我。这是代码和GDB BT。

#include "/home/hadoop_from_source/hdfs.h"
#include <jni.h>
#include <iostream>

int main (int arg, char* args[]) {

    hdfsFS hdfsFs = hdfsConnect("172.19.108.136",9000);

    if (hdfsFs != NULL)
        std:: cout << "Success" << std::endl;
    else
        std:: cout << "Fail " << std::endl;
}

编译和链接:

g++ test.cpp -o test.o -lhdfs -L .

GDB:

451     struct hdfsBuilder *bld = hdfsNewBuilder();
(gdb) 
452     if (!bld)
(gdb) 
451     struct hdfsBuilder *bld = hdfsNewBuilder();
(gdb) 
452     if (!bld)
(gdb) 
454     hdfsBuilderSetNameNode(bld, host);
(gdb) 
455     hdfsBuilderSetNameNodePort(bld, port);
(gdb) 
456     return hdfsBuilderConnect(bld);
(gdb) 
457 }
(gdb) 
456     return hdfsBuilderConnect(bld);
(gdb) 
0x00007ffff7df1e98 in hdfsBuilderConnect@plt () from ./libhdfs.so.0.0.0
(gdb) 
Single stepping until exit from function hdfsBuilderConnect@plt,
which has no line number information.
0x00007ffff7df1df8 in ?? () from ./libhdfs.so.0.0.0
(gdb) nexti
0x00007ffff7df1dfe in ?? () from ./libhdfs.so.0.0.0
(gdb) 
0x000000302f0146c0 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146c4 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146c8 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146cd in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146d2 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146d7 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146dc in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146e1 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146e6 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146eb in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146f0 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146f5 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146f8 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f0146fd in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f014702 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f014707 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f01470c in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f014711 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f014716 in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f01471a in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
0x000000302f01471e in _dl_runtime_resolve () from /lib64/ld-linux-x86-64.so.2
(gdb) 
hdfsBuilderConnect (bld=0x601370)
    at /home/hadoop-2.2.0-src/hadoop-hdfs-project/hadoop-hdfs/src/main/native/libhdfs/hdfs.c:563
563 {
(gdb) 
0x00007ffff7df8385  563 {
(gdb) 
0x00007ffff7df838a  563 {
(gdb) 
0x00007ffff7df838d  563 {
(gdb) 
0x00007ffff7df8392  563 {
(gdb) 
0x00007ffff7df8397  563 {
(gdb) 
0x00007ffff7df839c  563 {
(gdb) 
0x00007ffff7df83a1  563 {
(gdb) 
565     jobject jConfiguration = NULL, jFS = NULL, jURI = NULL, jCachePath = NULL;
(gdb) 
566     jstring jURIString = NULL, jUserString = NULL;
(gdb) 
0x00007ffff7df83c0  566     jstring jURIString = NULL, jUserString = NULL;
(gdb) 
575     env = getJNIEnv();
(gdb) 
[New Thread 0x7ffff2e41700 (LWP 7488)]
.
.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff3ca99b5 in ?? ()
(gdb) 

0 个答案:

没有答案