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

[WIP] feat: persist the cluster-enabled status in rocksdb #1465

Closed
wants to merge 4 commits into from
Closed
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
18 changes: 12 additions & 6 deletions tests/gocase/integration/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,17 @@ func TestClusterNodes(t *testing.T) {

t.Run("enable/disable the persist cluster nodes", func(t *testing.T) {
require.NoError(t, rdb.ConfigSet(ctx, "persist-cluster-nodes-enabled", "yes").Err())
srv.Restart()
srv.Restart(nil)
require.EqualValues(t, "2", rdb.Do(ctx, "clusterx", "version").Val())

require.NoError(t, rdb.ConfigSet(ctx, "persist-cluster-nodes-enabled", "no").Err())
srv.Restart()
srv.Restart(nil)
require.EqualValues(t, "-1", rdb.Do(ctx, "clusterx", "version").Val())

require.NoError(t, rdb.ConfigSet(ctx, "persist-cluster-nodes-enabled", "no").Err())
srv.Restart(map[string]string{
"cluster-enabled": "no",
})
require.EqualValues(t, "-1", rdb.Do(ctx, "clusterx", "version").Val())

// reset the cluster topology to avoid breaking other test cases
Expand Down Expand Up @@ -159,7 +165,7 @@ func TestClusterDumpAndLoadClusterNodesInfo(t *testing.T) {
require.NoError(t, rdb1.Do(ctx, "clusterx", "SETNODES", clusterNodes, "1").Err())
require.NoError(t, rdb2.Do(ctx, "clusterx", "SETNODES", clusterNodes, "1").Err())

srv1.Restart()
srv1.Restart(nil)
slots := rdb1.ClusterSlots(ctx).Val()
require.Len(t, slots, 5)
require.EqualValues(t, 10000, slots[2].Start)
Expand All @@ -170,7 +176,7 @@ func TestClusterDumpAndLoadClusterNodesInfo(t *testing.T) {

newNodeID := "0123456789012345678901234567890123456789"
require.NoError(t, rdb2.Do(ctx, "clusterx", "SETNODEID", newNodeID).Err())
srv1.Restart()
srv1.Restart(nil)
slots = rdb1.ClusterSlots(ctx).Val()
require.EqualValues(t, 10000, slots[2].Start)
require.EqualValues(t, 10000, slots[2].End)
Expand All @@ -180,8 +186,8 @@ func TestClusterDumpAndLoadClusterNodesInfo(t *testing.T) {
require.NoError(t, rdb2.Do(ctx, "clusterx", "setslot", "0", "node", nodeID2, "2").Err())
require.NoError(t, rdb1.Do(ctx, "clusterx", "setslot", "0", "node", nodeID2, "2").Err())

srv1.Restart()
srv2.Restart()
srv1.Restart(nil)
srv2.Restart(nil)
nodes = rdb1.ClusterNodes(ctx).Val()

require.Regexp(t, ".*myself,master.*1-2 4-8193 10000 10002-11002 16381-16383.*", nodes)
Expand Down
2 changes: 1 addition & 1 deletion tests/gocase/integration/replication/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func TestReplicationWithLimitSpeed(t *testing.T) {

// Restart master server, let the slave try to full sync with master again,
// because slave already received some SST files, so we will skip them.
master.Restart()
master.Restart(nil)
masterClient.Close()
masterClient = master.NewClient()

Expand Down
2 changes: 1 addition & 1 deletion tests/gocase/integration/rsid/rsid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestRSIDMasterAndReplicaYes(t *testing.T) {
t.Run("replica can partially re-sync again after restarting", func(t *testing.T) {
require.NoError(t, rdbC.ConfigRewrite(ctx).Err())

srvC.Restart()
srvC.Restart(nil)
rdbC := srvC.NewClient()
defer func() { require.NoError(t, rdbC.Close()) }()
util.WaitForSync(t, rdbC)
Expand Down
17 changes: 16 additions & 1 deletion tests/gocase/util/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -113,7 +114,7 @@ func (s *KvrocksServer) close(keepDir bool) {
s.clean(keepDir)
}

func (s *KvrocksServer) Restart() {
func (s *KvrocksServer) Restart(configs map[string]string) {
s.close(true)

b := *binPath
Expand All @@ -125,6 +126,20 @@ func (s *KvrocksServer) Restart() {
require.NoError(s.t, err)
defer func() { require.NoError(s.t, f.Close()) }()

if configs != nil {
tempFile, err := ioutil.TempFile(dir, "kvrocks-conf-tmp-*")
require.NoError(s.t, err)

for k, v := range configs {
s.configs[k] = v
_, err := tempFile.WriteString(fmt.Sprintf("%s %s\n", k, v))
require.NoError(s.t, err)
}

tempFile.Close()
os.Rename(tempFile.Name(), "kvrocks.conf")
}

cmd.Args = append(cmd.Args, "-c", f.Name())

stdout, err := os.Create(filepath.Join(dir, "stdout"))
Expand Down