Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
68a8d0b4
Unverified
Commit
68a8d0b4
authored
Jan 19, 2022
by
Wen Hui
Committed by
GitHub
Jan 19, 2022
Browse files
Add sentinel config set test case (#10114)
parent
72e1b5de
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/sentinel.c
View file @
68a8d0b4
...
@@ -402,7 +402,7 @@ void sentinelStartFailover(sentinelRedisInstance *master);
...
@@ -402,7 +402,7 @@ void sentinelStartFailover(sentinelRedisInstance *master);
void
sentinelDiscardReplyCallback
(
redisAsyncContext
*
c
,
void
*
reply
,
void
*
privdata
);
void
sentinelDiscardReplyCallback
(
redisAsyncContext
*
c
,
void
*
reply
,
void
*
privdata
);
int
sentinelSendSlaveOf
(
sentinelRedisInstance
*
ri
,
const
sentinelAddr
*
addr
);
int
sentinelSendSlaveOf
(
sentinelRedisInstance
*
ri
,
const
sentinelAddr
*
addr
);
char
*
sentinelVoteLeader
(
sentinelRedisInstance
*
master
,
uint64_t
req_epoch
,
char
*
req_runid
,
uint64_t
*
leader_epoch
);
char
*
sentinelVoteLeader
(
sentinelRedisInstance
*
master
,
uint64_t
req_epoch
,
char
*
req_runid
,
uint64_t
*
leader_epoch
);
void
sentinelFlushConfig
(
void
);
int
sentinelFlushConfig
(
void
);
void
sentinelGenerateInitialMonitorEvents
(
void
);
void
sentinelGenerateInitialMonitorEvents
(
void
);
int
sentinelSendPing
(
sentinelRedisInstance
*
ri
);
int
sentinelSendPing
(
sentinelRedisInstance
*
ri
);
int
sentinelForceHelloUpdateForMaster
(
sentinelRedisInstance
*
master
);
int
sentinelForceHelloUpdateForMaster
(
sentinelRedisInstance
*
master
);
...
@@ -2243,7 +2243,7 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) {
...
@@ -2243,7 +2243,7 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) {
* configuration file to make sure changes are committed to disk.
* configuration file to make sure changes are committed to disk.
*
*
* On failure the function logs a warning on the Redis log. */
* On failure the function logs a warning on the Redis log. */
void
sentinelFlushConfig
(
void
)
{
int
sentinelFlushConfig
(
void
)
{
int
fd
=
-
1
;
int
fd
=
-
1
;
int
saved_hz
=
server
.
hz
;
int
saved_hz
=
server
.
hz
;
int
rewrite_status
;
int
rewrite_status
;
...
@@ -2256,11 +2256,13 @@ void sentinelFlushConfig(void) {
...
@@ -2256,11 +2256,13 @@ void sentinelFlushConfig(void) {
if
((
fd
=
open
(
server
.
configfile
,
O_RDONLY
))
==
-
1
)
goto
werr
;
if
((
fd
=
open
(
server
.
configfile
,
O_RDONLY
))
==
-
1
)
goto
werr
;
if
(
fsync
(
fd
)
==
-
1
)
goto
werr
;
if
(
fsync
(
fd
)
==
-
1
)
goto
werr
;
if
(
close
(
fd
)
==
EOF
)
goto
werr
;
if
(
close
(
fd
)
==
EOF
)
goto
werr
;
return
;
serverLog
(
LL_NOTICE
,
"Sentinel new configuration saved on disk"
);
return
C_OK
;
werr:
werr:
serverLog
(
LL_WARNING
,
"WARNING: Sentinel was not able to save the new configuration on disk!!!: %s"
,
strerror
(
errno
));
serverLog
(
LL_WARNING
,
"WARNING: Sentinel was not able to save the new configuration on disk!!!: %s"
,
strerror
(
errno
));
if
(
fd
!=
-
1
)
close
(
fd
);
if
(
fd
!=
-
1
)
close
(
fd
);
return
C_ERR
;
}
}
/* ====================== hiredis connection handling ======================= */
/* ====================== hiredis connection handling ======================= */
...
@@ -4316,8 +4318,10 @@ void sentinelSetCommand(client *c) {
...
@@ -4316,8 +4318,10 @@ void sentinelSetCommand(client *c) {
break
;
break
;
}
}
}
}
if
(
changes
&&
sentinelFlushConfig
()
==
C_ERR
)
{
if
(
changes
)
sentinelFlushConfig
();
addReplyErrorFormat
(
c
,
"Failed to save Sentinel new configuration on disk"
);
return
;
}
addReply
(
c
,
shared
.
ok
);
addReply
(
c
,
shared
.
ok
);
return
;
return
;
...
@@ -4325,7 +4329,10 @@ badfmt: /* Bad format errors */
...
@@ -4325,7 +4329,10 @@ badfmt: /* Bad format errors */
addReplyErrorFormat
(
c
,
"Invalid argument '%s' for SENTINEL SET '%s'"
,
addReplyErrorFormat
(
c
,
"Invalid argument '%s' for SENTINEL SET '%s'"
,
(
char
*
)
c
->
argv
[
badarg
]
->
ptr
,
option
);
(
char
*
)
c
->
argv
[
badarg
]
->
ptr
,
option
);
seterr:
seterr:
if
(
changes
)
sentinelFlushConfig
();
if
(
changes
&&
sentinelFlushConfig
()
==
C_ERR
)
{
addReplyErrorFormat
(
c
,
"Failed to save Sentinel new configuration on disk"
);
return
;
}
return
;
return
;
}
}
...
...
tests/sentinel/tests/03-runtime-reconf.tcl
View file @
68a8d0b4
# Test runtime reconfiguration command SENTINEL SET.
# Test runtime reconfiguration command SENTINEL SET.
source
"../tests/includes/init-tests.tcl"
set num_sentinels
[
llength $::sentinel_instances
]
test
"Set parameters in normal case"
{
set info
[
S 0 SENTINEL master mymaster
]
set origin_quorum
[
dict get $info quorum
]
set origin_down_after_milliseconds
[
dict get $info down-after-milliseconds
]
set update_quorum
[
expr $origin_quorum+1
]
set update_down_after_milliseconds
[
expr $origin_down_after_milliseconds+1000
]
assert_equal
[
S 0 SENTINEL SET mymaster quorum $update_quorum
]
"OK"
assert_equal
[
S 0 SENTINEL SET mymaster down-after-milliseconds $update_down_after_milliseconds
]
"OK"
set update_info
[
S 0 SENTINEL master mymaster
]
assert
{[
dict get $update_info quorum
]
!= $origin_quorum
}
assert
{[
dict get $update_info down-after-milliseconds
]
!= $origin_down_after_milliseconds
}
#restore to origin config parameters
assert_equal
[
S 0 SENTINEL SET mymaster quorum $origin_quorum
]
"OK"
assert_equal
[
S 0 SENTINEL SET mymaster down-after-milliseconds $origin_down_after_milliseconds
]
"OK"
}
test
"Set parameters in normal case with bad format"
{
set info
[
S 0 SENTINEL master mymaster
]
set origin_down_after_milliseconds
[
dict get $info down-after-milliseconds
]
assert_error
"ERR Invalid argument '-20' for SENTINEL SET 'down-after-milliseconds'*"
{
S 0 SENTINEL SET mymaster down-after-milliseconds -20
}
assert_error
"ERR Invalid argument 'abc' for SENTINEL SET 'down-after-milliseconds'*"
{
S 0 SENTINEL SET mymaster down-after-milliseconds
"abc"
}
set current_info
[
S 0 SENTINEL master mymaster
]
assert
{[
dict get $current_info down-after-milliseconds
]
== $origin_down_after_milliseconds
}
}
test
"Sentinel Set with other error situations"
{
# non-existing script
assert_error
"ERR Notification script seems non existing*"
{
S 0 SENTINEL SET mymaster notification-script test.txt
}
# wrong parameter number
assert_error
"ERR wrong number of arguments for 'set' command or subcommand"
{
S 0 SENTINEL SET mymaster fakeoption
}
# unknown parameter option
assert_error
"ERR Unknown option or number of arguments for SENTINEL SET 'fakeoption'"
{
S 0 SENTINEL SET mymaster fakeoption fakevalue
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment