eBay / NuRaft

C++ implementation of Raft core logic as a replication library
Apache License 2.0
996 stars 236 forks source link

Wrong "src" and "dst" when cs_new<req_msg> #438

Closed Annashuo closed 1 year ago

Annashuo commented 1 year ago

ptr< cmd_result< ptr > > raft_server::add_srv(const srv_config& srv) { ptr buf(srv.serialize()); ptr log( cs_new ( 0, buf, log_val_type::cluster_server ) ); ptr req = cs_new ( (ulong)0, msg_type::add_server_request, 0, 0, (ulong)0, (ulong)0, (ulong)0 ); req->log_entries().push_back(log); return send_msg_to_leader(req); }

When using cs_new in the above code, both the src and dst parameters passed in are 0, is this a bug? Similar code also appears in the functions remove_srv and append_entries_ext.

Annashuo commented 1 year ago

We attempted to modify asio_service and asio_listener to support multiple Raft instances reusing the same port for listening, but found that some req_msg received had src and dst both set to 0. We found in the code that 0 was filled in when creating req_msg in the add_srv, remove_srv, and append_entries_ext interfaces. Could you help fix this issue?

greensky00 commented 1 year ago

req_msg is a shared structure to support various message types, src and dst are not used for those APIs (add_srv, remove_srv, and append_entries_ext). Also, those APIs are locally consumed and don't go through Asio unless auto_forwarding_ is enabled. But even with the auto-forwarding, still src and dst are not used.

If you want to generate a special message for your modified Asio layer, do cs_new<req_msg>(...) outside NuRaft instead of calling those APIs.