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

Fix missing to set the cluster node id when loading #1384

Merged
merged 2 commits into from
Apr 14, 2023
Merged
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: 2 additions & 0 deletions src/cluster/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ Status Cluster::LoadClusterNodes(const std::string &file_path) {
return {Status::NotOK, fmt::format("unknown key: {}", key)};
}
}

myid_ = id;
return SetClusterNodes(nodes_info, version, false);
}

Expand Down
15 changes: 11 additions & 4 deletions tests/gocase/integration/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,21 @@ func TestClusterNodes(t *testing.T) {
}

func TestClusterDumpAndLoadClusterNodesInfo(t *testing.T) {
srv1 := util.StartServer(t, map[string]string{"cluster-enabled": "yes"})
srv1 := util.StartServer(t, map[string]string{
"bind": "0.0.0.0",
"cluster-enabled": "yes",
})
defer srv1.Close()
ctx := context.Background()
rdb1 := srv1.NewClient()
defer func() { require.NoError(t, rdb1.Close()) }()
nodeID1 := "07c37dfeb235213a872192d90877d0cd55635b91"
require.NoError(t, rdb1.Do(ctx, "clusterx", "SETNODEID", nodeID1).Err())

srv2 := util.StartServer(t, map[string]string{"cluster-enabled": "yes"})
srv2 := util.StartServer(t, map[string]string{
"bind": "0.0.0.0",
"cluster-enabled": "yes",
})
defer srv2.Close()
rdb2 := srv2.NewClient()
defer func() { require.NoError(t, rdb2.Close()) }()
Expand All @@ -163,7 +169,7 @@ func TestClusterDumpAndLoadClusterNodesInfo(t *testing.T) {
require.Contains(t, nodes, "0-2 4-8193 10000 10002-11002 16381-16383")

newNodeID := "0123456789012345678901234567890123456789"
require.NoError(t, rdb1.Do(ctx, "clusterx", "SETNODEID", newNodeID).Err())
require.NoError(t, rdb2.Do(ctx, "clusterx", "SETNODEID", newNodeID).Err())
srv1.Restart()
slots = rdb1.ClusterSlots(ctx).Val()
require.EqualValues(t, 10000, slots[2].Start)
Expand All @@ -177,7 +183,8 @@ func TestClusterDumpAndLoadClusterNodesInfo(t *testing.T) {
srv1.Restart()
srv2.Restart()
nodes = rdb1.ClusterNodes(ctx).Val()
require.Contains(t, nodes, "1-2 4-8193 10000 10002-11002 16381-16383")

require.Regexp(t, ".*myself,master.*1-2 4-8193 10000 10002-11002 16381-16383.*", nodes)
nodes = rdb2.ClusterNodes(ctx).Val()
require.Contains(t, nodes, "1-2 4-8193 10000 10002-11002 16381-16383")
}
Expand Down
4 changes: 3 additions & 1 deletion tests/gocase/util/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ func StartServerWithCLIOptions(t testing.TB, configs map[string]string, options

addr, err := findFreePort()
require.NoError(t, err)
configs["bind"] = addr.IP.String()
if configs["bind"] == "" {
configs["bind"] = addr.IP.String()
}
configs["port"] = fmt.Sprintf("%d", addr.Port)

dir := *workspace
Expand Down