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

Add cluster section into the info command #1379

Merged
merged 4 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions src/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,15 @@ void Server::GetCommandsStatsInfo(std::string *info) {
*info = string_stream.str();
}

void Server::GetClusterInfo(std::string *info) {
std::ostringstream string_stream;

string_stream << "# Cluster\r\n";
string_stream << "cluster_enabled:" << config_->cluster_enabled << "\r\n";

*info = string_stream.str();
}

// WARNING: we must not access DB(i.e. RocksDB) when server is loading since
// DB is closed and the pointer is invalid. Server may crash if we access DB during loading.
// If you add new fields which access DB into INFO command output, make sure
Expand Down Expand Up @@ -1151,6 +1160,13 @@ void Server::GetInfo(const std::string &ns, const std::string &section, std::str
string_stream << rocksdb_info;
}

if (all || section == "cluster") {
std::string cluster_info;
GetClusterInfo(&cluster_info);
if (section_cnt++) string_stream << "\r\n";
string_stream << cluster_info;
}

*info = string_stream.str();
}

Expand Down
1 change: 1 addition & 0 deletions src/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class Server {
void GetReplicationInfo(std::string *info);
void GetRoleInfo(std::string *info);
void GetCommandsStatsInfo(std::string *info);
void GetClusterInfo(std::string *info);
void GetInfo(const std::string &ns, const std::string &section, std::string *info);
std::string GetRocksDBStatsJson() const;
ReplState GetReplicationState();
Expand Down
4 changes: 4 additions & 0 deletions tests/gocase/unit/info/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,8 @@ func TestInfo(t *testing.T) {
require.GreaterOrEqual(t, lastBgsaveTimeSec, 0)
require.Less(t, lastBgsaveTimeSec, 3)
})

t.Run("get cluster information by INFO", func(t *testing.T) {
require.Equal(t, "0", util.FindInfoEntry(rdb, "cluster_enabled", "cluster"))
})
enjoy-binbin marked this conversation as resolved.
Show resolved Hide resolved
}