Skip to content

Commit c21abcf

Browse files
Mixficsolwuxianrong
andauthored
fix: added some disable command additions to the rename-command (#2540)
* Added some disable command additions to the rename-command * add rename replication test --------- Co-authored-by: wuxianrong <wuxianrong@360.cn>
1 parent 3d62cd6 commit c21abcf

5 files changed

Lines changed: 130 additions & 32 deletions

File tree

conf/pika.conf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,18 +513,19 @@ cache-lfu-decay-time: 1
513513
#
514514
# aclfile : ../conf/users.acl
515515

516+
# (experimental)
516517
# It is possible to change the name of dangerous commands in a shared environment.
517518
# For instance the CONFIG command may be renamed into something Warning: To prevent
518519
# data inconsistency caused by different configuration files, do not use the rename
519520
# command to modify write commands on the primary and secondary servers. If necessary,
520521
# ensure that the configuration files of the primary and secondary servers are consistent
521522
# In addition, when using the command rename, you must not use "" to modify the command,
522-
# for example, rename-command: FLUSHALL "360flushall" is incorrect; instead, use
523-
# rename-command: FLUSHALL 360flushall is correct. After the rename command is executed,
523+
# for example, rename-command: FLUSHDB "360flushdb" is incorrect; instead, use
524+
# rename-command: FLUSHDB 360flushdb is correct. After the rename command is executed,
524525
# it is most appropriate to use a numeric string with uppercase or lowercase letters
525-
# for example: rename-command : FLUSHALL joYAPNXRPmcarcR4ZDgC81TbdkSmLAzRPmcarcR
526+
# for example: rename-command : FLUSHDB joYAPNXRPmcarcR4ZDgC81TbdkSmLAzRPmcarcR
527+
# Warning: Currently only applies to flushdb, slaveof, bgsave, shutdown, config command
528+
# Warning: Ensure that the Settings of rename-command on the master and slave servers are consistent
526529
#
527530
# Example:
528-
#
529-
# rename-command : FLUSHALL 360flushall
530531
# rename-command : FLUSHDB 360flushdb

tests/integration/options.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import (
77
)
88

99
const (
10-
LOCALHOST = "127.0.0.1"
11-
SLAVEPORT = "9231"
12-
MASTERPORT = "9241"
13-
SINGLEADDR = "127.0.0.1:9221"
14-
SLAVEADDR = "127.0.0.1:9231"
15-
MASTERADDR = "127.0.0.1:9241"
16-
RenameADDR = "127.0.0.1:9251"
10+
LOCALHOST = "127.0.0.1"
11+
SLAVEPORT = "9231"
12+
MASTERPORT = "9241"
13+
SLAVERENAMEPORT = "9301"
14+
MASTERRENAMEPORT = "9291"
15+
SINGLEADDR = "127.0.0.1:9221"
16+
SLAVEADDR = "127.0.0.1:9231"
17+
MASTERADDR = "127.0.0.1:9241"
18+
SLAVERENAMEADDR = "127.0.0.1:9301"
19+
MASTERRENAMEADDR = "127.0.0.1:9291"
20+
RenameADDR = "127.0.0.1:9251"
1721

1822
CODISADDR = "127.0.0.1:19000"
1923

tests/integration/renamecommand_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,4 @@ var _ = Describe("Rename Command test", func() {
4040
r = client.Do(ctx, "flushdb")
4141
Expect(r.Val()).NotTo(Equal("OK"))
4242
})
43-
44-
It("should 360FlushAll", func() {
45-
set := client.Set(ctx, "key", "foobar", 0)
46-
Expect(set.Err()).NotTo(HaveOccurred())
47-
Expect(set.Val()).To(Equal("OK"))
48-
49-
bitCount := client.BitCount(ctx, "key", nil)
50-
Expect(bitCount.Err()).NotTo(HaveOccurred())
51-
Expect(bitCount.Val()).To(Equal(int64(26)))
52-
_, err := client.Do(ctx, "360flushall").Result()
53-
Expect(err).NotTo(HaveOccurred())
54-
r := client.Do(ctx, "360flushall")
55-
Expect(r.Val()).To(Equal("OK"))
56-
n, err := client.Exists(ctx, "key").Result()
57-
Expect(err).NotTo(HaveOccurred())
58-
Expect(n).To(Equal(int64(0)))
59-
r = client.Do(ctx, "flushall")
60-
Expect(r.Val()).NotTo(Equal("OK"))
61-
})
6243
})
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package pika_integration
2+
3+
import (
4+
"context"
5+
"log"
6+
"time"
7+
8+
. "github.com/bsm/ginkgo/v2"
9+
. "github.com/bsm/gomega"
10+
"github.com/redis/go-redis/v9"
11+
)
12+
13+
var _ = Describe("should replication rename", func() {
14+
Describe("all replication rename test", func() {
15+
ctx := context.TODO()
16+
var clientSlave *redis.Client
17+
var clientMaster *redis.Client
18+
19+
BeforeEach(func() {
20+
clientMaster = redis.NewClient(PikaOption(MASTERRENAMEADDR))
21+
clientSlave = redis.NewClient(PikaOption(SLAVERENAMEADDR))
22+
cleanEnv(ctx, clientMaster, clientSlave)
23+
if GlobalBefore != nil {
24+
GlobalBefore(ctx, clientMaster)
25+
GlobalBefore(ctx, clientSlave)
26+
}
27+
})
28+
AfterEach(func() {
29+
cleanEnv(ctx, clientMaster, clientSlave)
30+
Expect(clientSlave.Close()).NotTo(HaveOccurred())
31+
Expect(clientMaster.Close()).NotTo(HaveOccurred())
32+
log.Println("Replication test case done")
33+
})
34+
35+
It("Let The slave become a replica of The master ", func() {
36+
infoRes := clientSlave.Info(ctx, "replication")
37+
Expect(infoRes.Err()).NotTo(HaveOccurred())
38+
Expect(infoRes.Val()).To(ContainSubstring("role:master"))
39+
infoRes = clientMaster.Info(ctx, "replication")
40+
Expect(infoRes.Err()).NotTo(HaveOccurred())
41+
Expect(infoRes.Val()).To(ContainSubstring("role:master"))
42+
Expect(clientSlave.Do(ctx, "slaveof", LOCALHOST, SLAVERENAMEPORT).Err()).To(MatchError("ERR The master ip:port and the slave ip:port are the same"))
43+
44+
var count = 0
45+
for {
46+
res := trySlave(ctx, clientSlave, LOCALHOST, MASTERRENAMEPORT)
47+
if res {
48+
break
49+
} else if count > 4 {
50+
break
51+
} else {
52+
cleanEnv(ctx, clientMaster, clientSlave)
53+
count++
54+
}
55+
}
56+
57+
infoRes = clientSlave.Info(ctx, "replication")
58+
Expect(infoRes.Err()).NotTo(HaveOccurred())
59+
Expect(infoRes.Val()).To(ContainSubstring("master_link_status:up"))
60+
61+
infoRes = clientMaster.Info(ctx, "replication")
62+
Expect(infoRes.Err()).NotTo(HaveOccurred())
63+
Expect(infoRes.Val()).To(ContainSubstring("connected_slaves:1"))
64+
65+
slaveWrite := clientSlave.Set(ctx, "foo", "bar", 0)
66+
Expect(slaveWrite.Err()).To(MatchError("ERR Server in read-only"))
67+
log.Println("Replication rename test 1 start")
68+
set := clientMaster.Set(ctx, "x", "y", 0)
69+
Expect(set.Err()).NotTo(HaveOccurred())
70+
Expect(set.Val()).To(Equal("OK"))
71+
set1 := clientMaster.Set(ctx, "a", "b", 0)
72+
Expect(set1.Err()).NotTo(HaveOccurred())
73+
Expect(set1.Val()).To(Equal("OK"))
74+
r1 := clientMaster.Do(ctx, "flushdb")
75+
Expect(r1.Val()).NotTo(Equal("OK"))
76+
time.Sleep(3 * time.Second)
77+
Expect(clientMaster.Do(ctx, "360flushdb").Err()).NotTo(HaveOccurred())
78+
Eventually(func() error {
79+
return clientMaster.Get(ctx, "x").Err()
80+
}, "60s", "100ms").Should(Equal(redis.Nil))
81+
Eventually(func() error {
82+
return clientSlave.Get(ctx, "x").Err()
83+
}, "60s", "100ms").Should(Equal(redis.Nil))
84+
log.Println("Replication rename test 1 success")
85+
86+
})
87+
})
88+
})

tests/integration/start_master_and_slave.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ cp ../conf/pika.conf ./pika_single.conf
66
cp ../conf/pika.conf ./pika_master.conf
77
cp ../conf/pika.conf ./pika_slave.conf
88
cp ../conf/pika.conf ./pika_rename.conf
9+
cp ../conf/pika.conf ./pika_master_rename.conf
10+
cp ../conf/pika.conf ./pika_slave_rename.conf
911
cp ../conf/pika.conf ./pika_acl_both_password.conf
1012
cp ../conf/pika.conf ./pika_acl_only_admin_password.conf
1113
cp ../conf/pika.conf ./pika_has_other_acl_user.conf
@@ -38,7 +40,6 @@ sed -i '' \
3840
-e 's|#daemonize : yes|daemonize : yes|' ./pika_slave.conf
3941

4042
sed -i '' \
41-
-e 's|# rename-command : FLUSHALL 360flushall|rename-command : FLUSHALL 360flushall|' \
4243
-e 's|# rename-command : FLUSHDB 360flushdb|rename-command : FLUSHDB 360flushdb|' \
4344
-e 's|databases : 1|databases : 2|' \
4445
-e 's|port : 9221|port : 9251|' \
@@ -73,6 +74,7 @@ sed -i '' \
7374
-e 's|pidfile : ./pika.pid|pidfile : ./acl2_data/pika.pid|' \
7475
-e 's|db-sync-path : ./dbsync/|db-sync-path : ./acl2_data/dbsync/|' \
7576
-e 's|#daemonize : yes|daemonize : yes|' ./pika_acl_only_admin_password.conf
77+
7678
sed -i '' \
7779
-e 's|requirepass :|requirepass : requirepass|' \
7880
-e 's|masterauth :|masterauth : requirepass|' \
@@ -87,6 +89,26 @@ sed -i '' \
8789
-e 's|#daemonize : yes|daemonize : yes|' ./pika_has_other_acl_user.conf
8890
echo -e '\nuser : limit on >limitpass ~* +@all &*' >> ./pika_has_other_acl_user.conf
8991

92+
sed -i '' \
93+
-e 's|# rename-command : FLUSHDB 360flushdb|rename-command : FLUSHDB 360flushdb|' \
94+
-e 's|port : 9221|port : 9291|' \
95+
-e 's|log-path : ./log/|log-path : ./master_rename_data/log/|' \
96+
-e 's|db-path : ./db/|db-path : ./master_rename_data/db/|' \
97+
-e 's|dump-path : ./dump/|dump-path : ./master_rename_data/dump/|' \
98+
-e 's|pidfile : ./pika.pid|pidfile : ./master_rename_data/pika.pid|' \
99+
-e 's|db-sync-path : ./dbsync/|db-sync-path : ./master_rename_data/dbsync/|' \
100+
-e 's|#daemonize : yes|daemonize : yes|' ./pika_master_rename.conf
101+
102+
sed -i '' \
103+
-e 's|# rename-command : FLUSHDB 360flushdb|rename-command : FLUSHDB 360flushdb|' \
104+
-e 's|port : 9221|port : 9301|' \
105+
-e 's|log-path : ./log/|log-path : ./slave_rename_data/log/|' \
106+
-e 's|db-path : ./db/|db-path : ./slave_rename_data/db/|' \
107+
-e 's|dump-path : ./dump/|dump-path : ./slave_rename_data/dump/|' \
108+
-e 's|pidfile : ./pika.pid|pidfile : ./slave_rename_data/pika.pid|' \
109+
-e 's|db-sync-path : ./dbsync/|db-sync-path : ./slave_rename_data/dbsync/|' \
110+
-e 's|#daemonize : yes|daemonize : yes|' ./pika_slave_rename.conf
111+
90112
# Start three nodes
91113
./pika -c ./pika_single.conf
92114
./pika -c ./pika_master.conf
@@ -95,5 +117,7 @@ echo -e '\nuser : limit on >limitpass ~* +@all &*' >> ./pika_has_other_acl_user.
95117
./pika -c ./pika_acl_both_password.conf
96118
./pika -c ./pika_acl_only_admin_password.conf
97119
./pika -c ./pika_has_other_acl_user.conf
120+
./pika -c ./pika_master_rename.conf
121+
./pika -c ./pika_slave_rename.conf
98122
#ensure both master and slave are ready
99123
sleep 10

0 commit comments

Comments
 (0)