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/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new c4956d6f Allow to retrieve the cluster node id via the CLUSTERX
command (#2194)
c4956d6f is described below
commit c4956d6f52b4d4ea91e19b9efb8d8f0b4788f614
Author: hulk <[email protected]>
AuthorDate: Sun Mar 24 10:15:19 2024 +0800
Allow to retrieve the cluster node id via the CLUSTERX command (#2194)
---
src/commands/cmd_cluster.cc | 6 ++++--
tests/gocase/integration/cluster/cluster_test.go | 9 +++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/commands/cmd_cluster.cc b/src/commands/cmd_cluster.cc
index 99a79f14..bd8de277 100644
--- a/src/commands/cmd_cluster.cc
+++ b/src/commands/cmd_cluster.cc
@@ -122,7 +122,7 @@ class CommandClusterX : public Commander {
Status Parse(const std::vector<std::string> &args) override {
subcommand_ = util::ToLower(args[1]);
- if (args.size() == 2 && (subcommand_ == "version")) return Status::OK();
+ if (args.size() == 2 && (subcommand_ == "version" || subcommand_ ==
"myid")) return Status::OK();
if (subcommand_ == "setnodeid" && args_.size() == 3 && args_[2].size() ==
kClusterNodeIdLen) return Status::OK();
@@ -208,7 +208,7 @@ class CommandClusterX : public Commander {
return Status::OK();
}
- return {Status::RedisParseErr, "CLUSTERX command, CLUSTERX
VERSION|SETNODEID|SETNODES|SETSLOT|MIGRATE"};
+ return {Status::RedisParseErr, "CLUSTERX command, CLUSTERX
VERSION|MYID|SETNODEID|SETNODES|SETSLOT|MIGRATE"};
}
Status Execute(Server *srv, Connection *conn, std::string *output) override {
@@ -248,6 +248,8 @@ class CommandClusterX : public Commander {
} else if (subcommand_ == "version") {
int64_t v = srv->cluster->GetVersion();
*output = redis::BulkString(std::to_string(v));
+ } else if (subcommand_ == "myid") {
+ *output = redis::BulkString(srv->cluster->GetMyId());
} else if (subcommand_ == "migrate") {
if (sync_migrate_) {
sync_migrate_ctx_ = std::make_unique<SyncMigrateContext>(srv, conn,
sync_migrate_timeout_);
diff --git a/tests/gocase/integration/cluster/cluster_test.go
b/tests/gocase/integration/cluster/cluster_test.go
index 695eb33c..97c8ed88 100644
--- a/tests/gocase/integration/cluster/cluster_test.go
+++ b/tests/gocase/integration/cluster/cluster_test.go
@@ -305,6 +305,15 @@ func TestClusterMultiple(t *testing.T) {
require.NoError(t, rdb[i].Do(ctx, "clusterx", "setnodes",
clusterNodes, "1").Err())
}
+ t.Run("check if the node id is correct", func(t *testing.T) {
+ // only node1, node2 and node3 was the member of the cluster
+ for i := 1; i < 4; i++ {
+ myid, err := rdb[i].Do(ctx, "clusterx", "myid").Text()
+ require.NoError(t, err)
+ require.Equal(t, nodeID[i], myid)
+ }
+ })
+
t.Run("cluster info command", func(t *testing.T) {
r := rdb[1].ClusterInfo(ctx).Val()
require.Contains(t, r, "cluster_state:ok")