baidu / braft

An industrial-grade C++ implementation of RAFT consensus algorithm based on brpc, widely used inside Baidu to build highly-available distributed systems.
Apache License 2.0
3.93k stars 879 forks source link

braft 客户端运行 报错 #28

Closed ghost closed 6 years ago

ghost commented 6 years ago

Fail to define ESTOP(-20) which is already defined as `未知的错误 -20', abort.

帮忙看看需要怎么处理,从哪个方面去检查这个错误

ghost commented 6 years ago

有人知道是怎么回事吗? Fail to define brpc::ENOSERVICE(1001) which is already defined as `未知的错误 1001', abort.

chenzhangyi commented 6 years ago

这个是因为bthread被链接了两次,是不是brpc用的是动态连接,braft用的是静态链接。

On Mon, May 14, 2018 at 3:03 PM, wind-zhang notifications@github.com wrote:

有人知道是怎么回事吗?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/brpc/braft/issues/28#issuecomment-388716538, or mute the thread https://github.com/notifications/unsubscribe-auth/AGfYT1N8ecT2bb0LxX3CqC9O-zBJWCSmks5tySwkgaJpZM4T9I-x .

ghost commented 6 years ago

LIBS := -lrt -lssl -lcrypto -ldl -lz -llitezip -lliteunzip -lipclib \ -lLicenseReader ./lib/libbraft.a ./lib/libbrpc.a -lgflags -lleveldb -llog4cplus \ -lprotobuf -lindigolicmgr -lISUSC -lISUUI -luuid -lpthread

这是我的makefile 链接选项,都是静态连接,帮忙看看 是否有什么问题

还需要什么信息,我马上提供

chenzhangyi commented 6 years ago

检查下你们的模块或者管理的模块是不是同样定义了错误码为 未知的错误 -20

On Tue, May 15, 2018 at 9:22 AM, wind-zhang notifications@github.com wrote:

LIBS := -lrt -lssl -lcrypto -ldl -lz -llitezip -lliteunzip -lipclib -lLicenseReader ./lib/libbraft.a ./lib/libbrpc.a -lgflags -lleveldb -llog4cplus -lprotobuf -lindigolicmgr -lISUSC -lISUUI -luuid -lpthread

这是我的makefile 链接选项,都是静态连接,帮忙看看 是否有什么问题

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/brpc/braft/issues/28#issuecomment-389012392, or mute the thread https://github.com/notifications/unsubscribe-auth/AGfYT2SGvbu4dFdZ9cS8Ojkz3sK9IQVOks5tyi3ugaJpZM4T9I-x .

ghost commented 6 years ago

./license_client.bin
Fail to define brpc::ENOSERVICE(1001) which is already defined as `未知的错误 1001', abort.[zhangxf@localhost license-rpc]$ [zhangxf@localhost license-rpc]$ [zhangxf@localhost license-rpc]$ [zhangxf@localhost license-rpc]$ grep -R "1001" * common/braft/include/braft/errno.pb.h: EVOTEFORCANDIDATE = 10010, common/braft/include/braft/errno.pb.h: ENEWLEADER = 10011, common/braft/include/braft/errno.pb.h: ELEADERCONFLICT = 10012, common/braft/include/braft/errno.pb.h: ETRANSFERLEADERSHIP = 10013, common/braft/include/braft/errno.pb.h: ELOGDELETED = 10014, common/braft/include/braft/errno.pb.h: ENOMOREUSERLOG = 10015 common/braft/include/braft/log.h:// log_inprogress_0001001: open segment common/brpc/include/brpc/ts.h: TS_PES_STREAM_ID_DSMC_STREAM = 0xf2, // 0b11110010 common/brpc/include/brpc/ts.h: TS_PES_STREAM_ID_13522_STREAM = 0xf3, // 0b11110011 common/brpc/include/brpc/ts.h: TS_PES_STREAM_ID_ANCILLARY_STREAM = 0xf9, // 0b11111001 common/brpc/include/brpc/errno.pb.h: ENOSERVICE = 1001, common/brpc/include/butil/third_party/modp_b64/modp_b64_data.h:0x0000d000, 0x0000e000, 0x0000f000, 0x00000001, 0x00001001, 0x00002001, common/brpc/include/butil/third_party/valgrind/valgrind.h: enum { VG_USERREQ__RUNNING_ON_VALGRIND = 0x1001, common/brpc/include/idl_options.proto: optional ConvertibleIdlType idl_type = 91001; common/brpc/include/idl_options.pb.h:static const int kIdlTypeFieldNumber = 91001;

没有其他模块 重新定义这些错误码

jamesge commented 6 years ago

可能还是链接的嫌疑比较大,如果Makefile不大全部贴一下

ghost commented 6 years ago

这个问题跟make没关系,我调整了源码的 引入顺序,这个问题解决了, 但是 测试发现 无法select leader void send_request(const std::string &request,std::string &response,void *arg) { //发送消息 if (braft::rtb::update_configuration("licenserpc", "192.168.109.128:8100:0") != 0) { LOG(INFO) << "Fail to register configuration 192.168.109.128:8100:0 of group licenserpc"; require(false,"Fail to register configuration 192.168.109.128:8100:0 of group licenserpc"); }

//0、get rpc-channel braft::PeerId leader; brpc::Channel channel; LOG(INFO) <<"the group is "<<"licenserpc"<<endl; // line 76 if (braft::rtb::select_leader("licenserpc" , &leader) != 0) { butil::Status st = braft::rtb::refresh_leader("licenserpc", 1000); if (!st.ok()) { LOG(INFO)<< "Fail to refresh_leader : " << st<<endl; require(false,"Fail to refresh_leader"); } } LOG(INFO) <<"leader.addr="<<leader.addr<<" the leader is "<<leader<<endl; //line 86 if (channel.Init(leader.addr, NULL) != 0) { LOG(INFO) << "Fail to init channel to " << leader<<endl; require(false,"Fail to init channel to "); }

//1、sendrequest brpc::Controller cntl; cntl.set_timeout_ms(10000);

LicenseResponse licenseResp; LicenseRequest licenseReq; licenseReq.set_value(request);

LicenseService_Stub stub(&channel); stub.do_license_busi(&cntl, &licenseReq, &licenseResp, NULL);

if (cntl.Failed()) { LOG(WARNING) << "Fail to send request to " << leader << " : " << cntl.ErrorText(); braft::rtb::update_leader("licenserpc", braft::PeerId()); // Clear leadership since this RPC failed. require(false,"link error");
} if ("yes"!=licenseResp.success()) { LOG(WARNING) << "Fail to send request to " << leader << ", redirecting to " //line 106 << (licenseResp.has_redirect() ? licenseResp.redirect() : "nowhere");

braft::rtb::update_leader("licenserpc", licenseResp.redirect());
require(false,"do busi error");    

} std::string respValue=licenseResp.value();

}

上面是 发送rpc的接口封装,里面的 具体信息是为了测试方便的: 看日志打印的信息,已经选主成功了,但是leader信息是 0000 , rpc server 端是正常的: telnet 192.168.109.128 8100 Trying 192.168.109.128... Connected to 192.168.109.128. Escape character is '^]'. 请帮忙看看这个问题:

错误如下 I0516 11:27:57.592380 32467 ./client/lic_client_main.cpp:76] the group is licenserpc I0516 11:27:57.604532 32467 ./client/lic_client_main.cpp:86] leader.addr=0.0.0.0:0 the leader is 0.0.0.0:0:0 W0516 11:27:57.605209 32467 ./client/lic_client_main.cpp:106] Fail to send request to 0.0.0.0:0:0 : [E111]Fail to connect SocketId=8589934592@0.0.0.0:0@43492: Connection refused [R1][E112]Not connected to 0.0.0.0:0 yet [R2][E112]Not connected to 0.0.0.0:0 yet [R3][E112]Not connected to 0.0.0.0:0 yet

ghost commented 6 years ago

此外, send_request 是运行在子线程里的

chenzhangyi commented 6 years ago

打开192.168.109.128:8100/raft_stats 这个页面确认下raft group是不是正常在工作.