Skip to content

Commit

Permalink
Add new flag in CLIENT LIST for import-source client (valkey-io#1398)
Browse files Browse the repository at this point in the history
- Add new flag "I" in `CLIENT LIST` for import-source client
- Add `DEBUG_CONFIG` for import-mode
- Allow import-source status to be turned off when import-mode is off

Fixes valkey-io#1350 and
valkey-io#1185 (comment).

---------

Signed-off-by: lvyanqi.lyq <[email protected]>
Signed-off-by: Yanqi Lv <[email protected]>
Co-authored-by: Viktor Söderqvist <[email protected]>
Co-authored-by: Binbin <[email protected]>
  • Loading branch information
3 people authored and vudiep411 committed Dec 15, 2024
1 parent 4fe5edf commit 61f4b6e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -3209,7 +3209,7 @@ standardConfig static_configs[] = {
createBoolConfig("enable-debug-assert", NULL, IMMUTABLE_CONFIG | HIDDEN_CONFIG, server.enable_debug_assert, 0, NULL, NULL),
createBoolConfig("cluster-slot-stats-enabled", NULL, MODIFIABLE_CONFIG, server.cluster_slot_stats_enabled, 0, NULL, NULL),
createBoolConfig("hide-user-data-from-log", NULL, MODIFIABLE_CONFIG, server.hide_user_data_from_log, 1, NULL, NULL),
createBoolConfig("import-mode", NULL, MODIFIABLE_CONFIG, server.import_mode, 0, NULL, NULL),
createBoolConfig("import-mode", NULL, DEBUG_CONFIG | MODIFIABLE_CONFIG, server.import_mode, 0, NULL, NULL),

/* String Configs */
createStringConfig("aclfile", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, server.acl_filename, "", NULL, NULL),
Expand Down
3 changes: 2 additions & 1 deletion src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -3340,6 +3340,7 @@ sds catClientInfoString(sds s, client *client, int hide_user_data) {
if (client->flag.readonly) *p++ = 'r';
if (client->flag.no_evict) *p++ = 'e';
if (client->flag.no_touch) *p++ = 'T';
if (client->flag.import_source) *p++ = 'I';
if (p == flags) *p++ = 'N';
*p++ = '\0';

Expand Down Expand Up @@ -4101,7 +4102,7 @@ void clientCommand(client *c) {
addReply(c, shared.ok);
} else if (!strcasecmp(c->argv[1]->ptr, "import-source")) {
/* CLIENT IMPORT-SOURCE ON|OFF */
if (!server.import_mode) {
if (!server.import_mode && strcasecmp(c->argv[2]->ptr, "off")) {
addReplyError(c, "Server is not in import mode");
return;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/expire.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,19 @@ start_server {tags {"expire"}} {
assert_equal [r debug set-active-expire 1] {OK}
} {} {needs:debug}

test {import-source can be closed when import-mode is off} {
r config set import-mode no
assert_error "ERR Server is not in import mode" {r client import-source on}

r config set import-mode yes
assert_equal [r client import-source on] {OK}
assert_match {*flags=I*} [r client list id [r client id]]

r config set import-mode no
assert_equal [r client import-source off] {OK}
assert_match {*flags=N*} [r client list id [r client id]]
}

test {Import mode should forbid active expiration} {
r flushall

Expand Down

0 comments on commit 61f4b6e

Please sign in to comment.