Skip to content

Commit 0b8cfa7

Browse files
enjoy-binbinxbasel
authored andcommitted
Add paused_reason to INFO CLIENTS (valkey-io#1564)
In valkey-io#1519, we added paused_actions and paused_timeout_milliseconds, it would be helpful if we add the paused_purpose since users also want to know the purpose for the pause. Currently available options: - client_pause: trigger by CLIENT PAUSE command. - shutdown_in_progress: during shutdown, primary waits the replicas to catch up the offset. - failover_in_progress: during failover, primary waits the replica to catch up the offset. - none --------- Signed-off-by: Binbin <[email protected]>
1 parent 2dde701 commit 0b8cfa7

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

src/networking.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4641,12 +4641,30 @@ void flushReplicasOutputBuffers(void) {
46414641
}
46424642
}
46434643

4644-
mstime_t getPausedActionTimeout(uint32_t action) {
4644+
char *getPausedReason(pause_purpose purpose) {
4645+
switch (purpose) {
4646+
case PAUSE_BY_CLIENT_COMMAND:
4647+
return "client_pause";
4648+
case PAUSE_DURING_SHUTDOWN:
4649+
return "shutdown_in_progress";
4650+
case PAUSE_DURING_FAILOVER:
4651+
return "failover_in_progress";
4652+
case NUM_PAUSE_PURPOSES:
4653+
return "none";
4654+
default:
4655+
return "Unknown pause reason";
4656+
}
4657+
}
4658+
4659+
mstime_t getPausedActionTimeout(uint32_t action, pause_purpose *purpose) {
46454660
mstime_t timeout = 0;
4661+
*purpose = NUM_PAUSE_PURPOSES;
46464662
for (int i = 0; i < NUM_PAUSE_PURPOSES; i++) {
46474663
pause_event *p = &(server.client_pause_per_purpose[i]);
4648-
if (p->paused_actions & action && (p->end - server.mstime) > timeout)
4664+
if (p->paused_actions & action && (p->end - server.mstime) > timeout) {
46494665
timeout = p->end - server.mstime;
4666+
*purpose = i;
4667+
}
46504668
}
46514669
return timeout;
46524670
}

src/server.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5695,14 +5695,18 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) {
56955695
getExpensiveClientsInfo(&maxin, &maxout);
56965696
totalNumberOfStatefulKeys(&blocking_keys, &blocking_keys_on_nokey, &watched_keys);
56975697

5698+
pause_purpose purpose;
5699+
char *paused_reason = "none";
56985700
char *paused_actions = "none";
56995701
long long paused_timeout = 0;
57005702
if (server.paused_actions & PAUSE_ACTION_CLIENT_ALL) {
57015703
paused_actions = "all";
5702-
paused_timeout = getPausedActionTimeout(PAUSE_ACTION_CLIENT_ALL);
5704+
paused_timeout = getPausedActionTimeout(PAUSE_ACTION_CLIENT_ALL, &purpose);
5705+
paused_reason = getPausedReason(purpose);
57035706
} else if (server.paused_actions & PAUSE_ACTION_CLIENT_WRITE) {
57045707
paused_actions = "write";
5705-
paused_timeout = getPausedActionTimeout(PAUSE_ACTION_CLIENT_WRITE);
5708+
paused_timeout = getPausedActionTimeout(PAUSE_ACTION_CLIENT_WRITE, &purpose);
5709+
paused_reason = getPausedReason(purpose);
57065710
}
57075711

57085712
if (sections++) info = sdscat(info, "\r\n");
@@ -5722,6 +5726,7 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) {
57225726
"total_watched_keys:%lu\r\n", watched_keys,
57235727
"total_blocking_keys:%lu\r\n", blocking_keys,
57245728
"total_blocking_keys_on_nokey:%lu\r\n", blocking_keys_on_nokey,
5729+
"paused_reason:%s\r\n", paused_reason,
57255730
"paused_actions:%s\r\n", paused_actions,
57265731
"paused_timeout_milliseconds:%lld\r\n", paused_timeout));
57275732
}

src/server.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2734,7 +2734,8 @@ void pauseActions(pause_purpose purpose, mstime_t end, uint32_t actions);
27342734
void unpauseActions(pause_purpose purpose);
27352735
uint32_t isPausedActions(uint32_t action_bitmask);
27362736
uint32_t isPausedActionsWithUpdate(uint32_t action_bitmask);
2737-
mstime_t getPausedActionTimeout(uint32_t action);
2737+
char *getPausedReason(pause_purpose purpose);
2738+
mstime_t getPausedActionTimeout(uint32_t action, pause_purpose *purpose);
27382739
void updatePausedActions(void);
27392740
void unblockPostponedClients(void);
27402741
void processEventsWhileBlocked(void);

tests/unit/pause.tcl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
start_server {tags {"pause network"}} {
2-
test "Test check paused_actions in info stats" {
2+
test "Test check paused info in info clients" {
3+
assert_equal [s paused_reason] "none"
34
assert_equal [s paused_actions] "none"
45
assert_equal [s paused_timeout_milliseconds] 0
56

67
r client PAUSE 10000 WRITE
8+
assert_equal [s paused_reason] "client_pause"
79
assert_equal [s paused_actions] "write"
810
after 1000
911
set timeout [s paused_timeout_milliseconds]
@@ -13,9 +15,14 @@ start_server {tags {"pause network"}} {
1315
r multi
1416
r client PAUSE 1000 ALL
1517
r info clients
16-
assert_match "*paused_actions:all*" [r exec]
18+
set res [r exec]
19+
assert_match "*paused_reason:client_pause*" $res
20+
assert_match "*paused_actions:all*" $res
1721

1822
r client unpause
23+
assert_equal [s paused_reason] "none"
24+
assert_equal [s paused_actions] "none"
25+
assert_equal [s paused_timeout_milliseconds] 0
1926
}
2027

2128
test "Test read commands are not blocked by client pause" {
@@ -408,3 +415,18 @@ start_server {tags {"pause network"}} {
408415
# Make sure we unpause at the end
409416
r client unpause
410417
}
418+
419+
start_cluster 1 1 {tags {"external:skip cluster pause network"}} {
420+
test "Test check paused info during the cluster failover in info clients" {
421+
assert_equal [s 0 paused_reason] "none"
422+
assert_equal [s 0 paused_actions] "none"
423+
assert_equal [s 0 paused_timeout_milliseconds] 0
424+
425+
R 1 cluster failover
426+
wait_for_log_messages 0 {"*Manual failover requested by replica*"} 0 10 1000
427+
428+
assert_equal [s 0 paused_reason] "failover_in_progress"
429+
assert_equal [s 0 paused_actions] "write"
430+
assert_morethan [s 0 paused_timeout_milliseconds] 0
431+
}
432+
}

0 commit comments

Comments
 (0)