You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by hu...@apache.org on 2023/04/12 07:48:40 UTC
[incubator-kvrocks] branch unstable updated: Add cluster section into the info command (#1379)
This is an automated email from the ASF dual-hosted git repository.
hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new d1e52d3d Add cluster section into the info command (#1379)
d1e52d3d is described below
commit d1e52d3d12cc3e66d8f82ac94f49f2895bfd9f91
Author: Binbin <bi...@qq.com>
AuthorDate: Wed Apr 12 15:48:32 2023 +0800
Add cluster section into the info command (#1379)
Currently, the Redis Info cluster command only has cluster_enabled,
a value of 0 or 1 indicates whether the cluster mode is enabled.
---------
Co-authored-by: Yaroslav <to...@gmail.com>
---
src/server/server.cc | 16 ++++++++++++++++
src/server/server.h | 1 +
tests/gocase/unit/info/info_test.go | 13 +++++++++++++
3 files changed, 30 insertions(+)
diff --git a/src/server/server.cc b/src/server/server.cc
index 3cb71903..5cf8528c 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -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
@@ -1110,6 +1119,13 @@ void Server::GetInfo(const std::string &ns, const std::string §ion, std::str
string_stream << commands_stats_info;
}
+ if (all || section == "cluster") {
+ std::string cluster_info;
+ GetClusterInfo(&cluster_info);
+ if (section_cnt++) string_stream << "\r\n";
+ string_stream << cluster_info;
+ }
+
// In keyspace section, we access DB, so we can't do that when loading
if (!is_loading_ && (all || section == "keyspace")) {
KeyNumStats stats;
diff --git a/src/server/server.h b/src/server/server.h
index 30b07e76..395d5e50 100644
--- a/src/server/server.h
+++ b/src/server/server.h
@@ -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 §ion, std::string *info);
std::string GetRocksDBStatsJson() const;
ReplState GetReplicationState();
diff --git a/tests/gocase/unit/info/info_test.go b/tests/gocase/unit/info/info_test.go
index 1cb23652..3b2821c8 100644
--- a/tests/gocase/unit/info/info_test.go
+++ b/tests/gocase/unit/info/info_test.go
@@ -31,6 +31,11 @@ import (
)
func TestInfo(t *testing.T) {
+ srv0 := util.StartServer(t, map[string]string{"cluster-enabled": "yes"})
+ defer func() { srv0.Close() }()
+ rdb0 := srv0.NewClient()
+ defer func() { require.NoError(t, rdb0.Close()) }()
+
srv := util.StartServer(t, map[string]string{})
defer srv.Close()
@@ -88,4 +93,12 @@ func TestInfo(t *testing.T) {
require.GreaterOrEqual(t, lastBgsaveTimeSec, 0)
require.Less(t, lastBgsaveTimeSec, 3)
})
+
+ t.Run("get cluster information by INFO - cluster not enabled", func(t *testing.T) {
+ require.Equal(t, "0", util.FindInfoEntry(rdb, "cluster_enabled", "cluster"))
+ })
+
+ t.Run("get cluster information by INFO - cluster enabled", func(t *testing.T) {
+ require.Equal(t, "1", util.FindInfoEntry(rdb0, "cluster_enabled", "cluster"))
+ })
}