Commit 5c8f7cd5 authored by Crystal Chua's avatar Crystal Chua
Browse files

add raft_leader_info command to always display output of current leader

parent 2dae2a20
Pipeline #347503 passed with stages
in 31 minutes
......@@ -83,6 +83,7 @@ struct cmdMapInit {
redis_cmd_map["raft_handshake"] = {RedisCommand::RAFT_HANDSHAKE, CommandType::RAFT};
redis_cmd_map["raft_append_entries"] = {RedisCommand::RAFT_APPEND_ENTRIES, CommandType::RAFT};
redis_cmd_map["raft_info"] = {RedisCommand::RAFT_INFO, CommandType::RAFT};
redis_cmd_map["raft_leader_info"] = {RedisCommand::RAFT_LEADER_INFO, CommandType::RAFT};
redis_cmd_map["raft_request_vote"] = {RedisCommand::RAFT_REQUEST_VOTE, CommandType::RAFT};
redis_cmd_map["raft_fetch"] = {RedisCommand::RAFT_FETCH, CommandType::RAFT};
redis_cmd_map["raft_checkpoint"] = {RedisCommand::RAFT_CHECKPOINT, CommandType::RAFT};
......
......@@ -87,6 +87,7 @@ enum class RedisCommand {
RAFT_HANDSHAKE,
RAFT_APPEND_ENTRIES,
RAFT_INFO,
RAFT_LEADER_INFO,
RAFT_REQUEST_VOTE,
RAFT_FETCH,
RAFT_CHECKPOINT,
......
......@@ -49,6 +49,17 @@ LinkStatus RaftDispatcher::dispatch(Connection *conn, RedisRequest &req) {
return conn->statusVector(this->info().toVector());
}
case RedisCommand::RAFT_LEADER_INFO: {
// safe, read-only request, does not need authorization
RaftStateSnapshotPtr snapshot = state.getSnapshot();
if(snapshot->status != RaftStatus::LEADER) {
if(snapshot->leader.empty()) {
return conn->err("unavailable");
}
return conn->moved(0, snapshot->leader);
}
return conn->statusVector(this->info().toVector());
}
case RedisCommand::RAFT_FETCH_LAST: {
// safe, read-only request, does not need authorization
if(req.size() != 2 && req.size() != 3) return conn->errArgs(req[0]);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment