diff --git a/conf/pika.conf b/conf/pika.conf index 3123b60fe5..1c3227f927 100644 --- a/conf/pika.conf +++ b/conf/pika.conf @@ -513,6 +513,7 @@ cache-lfu-decay-time: 1 # # aclfile : ../conf/users.acl +# (experimental) # It is possible to change the name of dangerous commands in a shared environment. # For instance the CONFIG command may be renamed into something Warning: To prevent # data inconsistency caused by different configuration files, do not use the rename @@ -520,13 +521,11 @@ cache-lfu-decay-time: 1 # ensure that the configuration files of the primary and secondary servers are consistent # In addition, when using the command rename, you must not use "" to modify the command, # for example, rename-command: FLUSHDB "360flushdb" is incorrect; instead, use -# rename-command: FLUSHDB 360flushdb is correct. After the rename command is executed, +# rename-command: FLUSHALL 360flushdb is correct. After the rename command is executed, # it is most appropriate to use a numeric string with uppercase or lowercase letters # for example: rename-command : FLUSHDB joYAPNXRPmcarcR4ZDgC81TbdkSmLAzRPmcarcR # -# Warning: setnx, setex, psetex, expire, pexpire, pexpireat, flushall, padding command -# cannot use rename-command change command name -# +# Warning: Currently only applies to flushdb, slaveof, bgsave, shutdown, config command # Example: # # rename-command : FLUSHDB 360flushdb diff --git a/tests/integration/options.go b/tests/integration/options.go index a0eb32c474..f799d23e37 100644 --- a/tests/integration/options.go +++ b/tests/integration/options.go @@ -7,13 +7,17 @@ import ( ) const ( - LOCALHOST = "127.0.0.1" - SLAVEPORT = "9231" - MASTERPORT = "9241" - SINGLEADDR = "127.0.0.1:9221" - SLAVEADDR = "127.0.0.1:9231" - MASTERADDR = "127.0.0.1:9241" - RenameADDR = "127.0.0.1:9251" + LOCALHOST = "127.0.0.1" + SLAVEPORT = "9231" + MASTERPORT = "9241" + SLAVERENAMEPORT = "9301" + MASTERRENAMEPORT = "9291" + SINGLEADDR = "127.0.0.1:9221" + SLAVEADDR = "127.0.0.1:9231" + MASTERADDR = "127.0.0.1:9241" + SLAVERENAMEADDR = "127.0.0.1:9301" + MASTERRENAMEADDR = "127.0.0.1:9291" + RenameADDR = "127.0.0.1:9251" CODISADDR = "127.0.0.1:19000" diff --git a/tests/integration/renamecommand_test.go b/tests/integration/renamecommand_test.go index 6c098152a2..1c50c9e38a 100644 --- a/tests/integration/renamecommand_test.go +++ b/tests/integration/renamecommand_test.go @@ -40,5 +40,4 @@ var _ = Describe("Rename Command test", func() { r = client.Do(ctx, "flushdb") Expect(r.Val()).NotTo(Equal("OK")) }) - }) diff --git a/tests/integration/replication_rename_test.go b/tests/integration/replication_rename_test.go new file mode 100644 index 0000000000..7facab8dc1 --- /dev/null +++ b/tests/integration/replication_rename_test.go @@ -0,0 +1,88 @@ +package pika_integration + +import ( + "context" + "log" + "time" + + . "github.com/bsm/ginkgo/v2" + . "github.com/bsm/gomega" + "github.com/redis/go-redis/v9" +) + +var _ = Describe("should replication rename", func() { + Describe("all replication rename test", func() { + ctx := context.TODO() + var clientSlave *redis.Client + var clientMaster *redis.Client + + BeforeEach(func() { + clientMaster = redis.NewClient(PikaOption(MASTERRENAMEADDR)) + clientSlave = redis.NewClient(PikaOption(SLAVERENAMEADDR)) + cleanEnv(ctx, clientMaster, clientSlave) + if GlobalBefore != nil { + GlobalBefore(ctx, clientMaster) + GlobalBefore(ctx, clientSlave) + } + }) + AfterEach(func() { + cleanEnv(ctx, clientMaster, clientSlave) + Expect(clientSlave.Close()).NotTo(HaveOccurred()) + Expect(clientMaster.Close()).NotTo(HaveOccurred()) + log.Println("Replication test case done") + }) + + It("Let The slave become a replica of The master ", func() { + infoRes := clientSlave.Info(ctx, "replication") + Expect(infoRes.Err()).NotTo(HaveOccurred()) + Expect(infoRes.Val()).To(ContainSubstring("role:master")) + infoRes = clientMaster.Info(ctx, "replication") + Expect(infoRes.Err()).NotTo(HaveOccurred()) + Expect(infoRes.Val()).To(ContainSubstring("role:master")) + Expect(clientSlave.Do(ctx, "slaveof", LOCALHOST, SLAVERENAMEPORT).Err()).To(MatchError("ERR The master ip:port and the slave ip:port are the same")) + + var count = 0 + for { + res := trySlave(ctx, clientSlave, LOCALHOST, MASTERRENAMEPORT) + if res { + break + } else if count > 4 { + break + } else { + cleanEnv(ctx, clientMaster, clientSlave) + count++ + } + } + + infoRes = clientSlave.Info(ctx, "replication") + Expect(infoRes.Err()).NotTo(HaveOccurred()) + Expect(infoRes.Val()).To(ContainSubstring("master_link_status:up")) + + infoRes = clientMaster.Info(ctx, "replication") + Expect(infoRes.Err()).NotTo(HaveOccurred()) + Expect(infoRes.Val()).To(ContainSubstring("connected_slaves:1")) + + slaveWrite := clientSlave.Set(ctx, "foo", "bar", 0) + Expect(slaveWrite.Err()).To(MatchError("ERR Server in read-only")) + log.Println("Replication rename test 1 start") + set := clientMaster.Set(ctx, "x", "y", 0) + Expect(set.Err()).NotTo(HaveOccurred()) + Expect(set.Val()).To(Equal("OK")) + set1 := clientMaster.Set(ctx, "a", "b", 0) + Expect(set1.Err()).NotTo(HaveOccurred()) + Expect(set1.Val()).To(Equal("OK")) + r1 := clientMaster.Do(ctx, "flushdb") + Expect(r1.Val()).NotTo(Equal("OK")) + time.Sleep(3 * time.Second) + Expect(clientMaster.Do(ctx, "360flushdb").Err()).NotTo(HaveOccurred()) + Eventually(func() error { + return clientMaster.Get(ctx, "x").Err() + }, "60s", "100ms").Should(Equal(redis.Nil)) + Eventually(func() error { + return clientSlave.Get(ctx, "x").Err() + }, "60s", "100ms").Should(Equal(redis.Nil)) + log.Println("Replication rename test 1 success") + + }) + }) +}) diff --git a/tests/integration/server_test.go b/tests/integration/server_test.go index c836ff1c55..b5c98dd1cc 100644 --- a/tests/integration/server_test.go +++ b/tests/integration/server_test.go @@ -24,6 +24,20 @@ var _ = Describe("Server", func() { }) Describe("server", func() { + It("Cmd Select", func() { + r, e := client.Set(ctx, "key", "foobar", 0).Result() + Expect(e).NotTo(HaveOccurred()) + Expect(r).To(Equal("OK")) + + get := client.Get(ctx, "key") + Expect(get.Err()).NotTo(HaveOccurred()) + Expect(get.Val()).To(Equal("foobar")) + + client.Do(ctx, "select", "1") + Eventually(func() error { + return client.Get(ctx, "key").Err() + }, "10s", "100ms").Should(Equal(redis.Nil)) + }) It("should Auth", func() { cmds, err := client.Pipelined(ctx, func(pipe redis.Pipeliner) error { pipe.Auth(ctx, "112121") diff --git a/tests/integration/start_master_and_slave.sh b/tests/integration/start_master_and_slave.sh index 853ea13f4c..cf5b52fa0f 100755 --- a/tests/integration/start_master_and_slave.sh +++ b/tests/integration/start_master_and_slave.sh @@ -6,6 +6,8 @@ cp ../conf/pika.conf ./pika_single.conf cp ../conf/pika.conf ./pika_master.conf cp ../conf/pika.conf ./pika_slave.conf cp ../conf/pika.conf ./pika_rename.conf +cp ../conf/pika.conf ./pika_master_rename.conf +cp ../conf/pika.conf ./pika_slave_rename.conf cp ../conf/pika.conf ./pika_acl_both_password.conf cp ../conf/pika.conf ./pika_acl_only_admin_password.conf cp ../conf/pika.conf ./pika_has_other_acl_user.conf @@ -72,6 +74,7 @@ sed -i '' \ -e 's|pidfile : ./pika.pid|pidfile : ./acl2_data/pika.pid|' \ -e 's|db-sync-path : ./dbsync/|db-sync-path : ./acl2_data/dbsync/|' \ -e 's|#daemonize : yes|daemonize : yes|' ./pika_acl_only_admin_password.conf + sed -i '' \ -e 's|requirepass :|requirepass : requirepass|' \ -e 's|masterauth :|masterauth : requirepass|' \ @@ -86,6 +89,26 @@ sed -i '' \ -e 's|#daemonize : yes|daemonize : yes|' ./pika_has_other_acl_user.conf echo -e '\nuser : limit on >limitpass ~* +@all &*' >> ./pika_has_other_acl_user.conf +sed -i '' \ + -e 's|# rename-command : FLUSHDB 360flushdb|rename-command : FLUSHDB 360flushdb|' \ + -e 's|port : 9221|port : 9291|' \ + -e 's|log-path : ./log/|log-path : ./master_rename_data/log/|' \ + -e 's|db-path : ./db/|db-path : ./master_rename_data/db/|' \ + -e 's|dump-path : ./dump/|dump-path : ./master_rename_data/dump/|' \ + -e 's|pidfile : ./pika.pid|pidfile : ./master_rename_data/pika.pid|' \ + -e 's|db-sync-path : ./dbsync/|db-sync-path : ./master_rename_data/dbsync/|' \ + -e 's|#daemonize : yes|daemonize : yes|' ./pika_master_rename.conf + +sed -i '' \ + -e 's|# rename-command : FLUSHDB 360flushdb|rename-command : FLUSHDB 360flushdb|' \ + -e 's|port : 9221|port : 9301|' \ + -e 's|log-path : ./log/|log-path : ./slave_rename_data/log/|' \ + -e 's|db-path : ./db/|db-path : ./slave_rename_data/db/|' \ + -e 's|dump-path : ./dump/|dump-path : ./slave_rename_data/dump/|' \ + -e 's|pidfile : ./pika.pid|pidfile : ./slave_rename_data/pika.pid|' \ + -e 's|db-sync-path : ./dbsync/|db-sync-path : ./slave_rename_data/dbsync/|' \ + -e 's|#daemonize : yes|daemonize : yes|' ./pika_slave_rename.conf + # Start three nodes ./pika -c ./pika_single.conf ./pika -c ./pika_master.conf @@ -94,5 +117,7 @@ echo -e '\nuser : limit on >limitpass ~* +@all &*' >> ./pika_has_other_acl_user. ./pika -c ./pika_acl_both_password.conf ./pika -c ./pika_acl_only_admin_password.conf ./pika -c ./pika_has_other_acl_user.conf +./pika -c ./pika_master_rename.conf +./pika -c ./pika_slave_rename.conf #ensure both master and slave are ready sleep 10 \ No newline at end of file