Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] Build test lab..... #64

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class NuRaftMesgConan(ConanFile):
name = "nuraft_mesg"
version = "2.1.2"
version = "2.2.2"

homepage = "https://github.com/eBay/nuraft_mesg"
description = "A gRPC service for NuRAFT"
Expand Down
1 change: 1 addition & 0 deletions include/nuraft_mesg/mesg_state_mgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class repl_service_ctx {
// we do not own this pointer. Use this only if the life cycle of the pointer is well known
nuraft::raft_server* _server;
bool is_raft_leader() const;
std::string_view raft_leader_id() const;

// return a list of replica configs for the peers of the raft group
void get_cluster_config(std::list< replica_config >& cluster_config) const;
Expand Down
11 changes: 11 additions & 0 deletions src/lib/repl_service_ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ repl_service_ctx::repl_service_ctx(nuraft::raft_server* server) : _server(server

bool repl_service_ctx::is_raft_leader() const { return _server->is_leader(); }

std::string_view repl_service_ctx::raft_leader_id() const {
// when adding member to raft, the id recorded in raft is a hash
// of passed-in id (new_id in add_member()), the new_id was stored
// in endpoint field.
if (!_server)
return std::string_view();
if (auto leader = _server->get_srv_config(_server->get_leader()); nullptr != leader)
return leader->get_endpoint();
return std::string_view();
}

void repl_service_ctx::get_cluster_config(std::list< replica_config >& cluster_config) const {
auto const& srv_configs = _server->get_config()->get_servers();
for (auto const& srv_config : srv_configs) {
Expand Down
1 change: 1 addition & 0 deletions src/tests/data_service_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ TEST_F(DataServiceFixture, BasicTest2) {
auto repl_ctx = sm1->get_repl_context();

EXPECT_TRUE(repl_ctx && repl_ctx->is_raft_leader());
EXPECT_TRUE(repl_ctx && repl_ctx->raft_leader_id() == to_string(app_1_->id_));
std::list< nuraft_mesg::replica_config > cluster_config;
repl_ctx->get_cluster_config(cluster_config);
EXPECT_EQ(cluster_config.size(), 3u);
Expand Down