Skip to content

Commit

Permalink
handle extended_redis_compat
Browse files Browse the repository at this point in the history
Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin committed Jan 15, 2025
1 parent 37263f3 commit 5c2fda5
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ void configSetCommand(client *c) {
err:
if (deny_loading_error) {
/* We give the loading error precedence because it may be handled by clients differently, unlike a plain -ERR. */
addReplyErrorObject(c, shared.loadingerr);
addReplyErrorObject(c, server.extended_redis_compat ? shared.loadingerr_compat : shared.loadingerr);
} else if (invalid_arg_name) {
addReplyErrorFormat(c, "Unknown option or number of arguments for CONFIG SET - '%s'", invalid_arg_name);
} else if (errstr) {
Expand Down
6 changes: 3 additions & 3 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1361,11 +1361,11 @@ void shutdownCommand(client *c) {
if (server.busy_module_yield_flags && server.busy_module_yield_reply) {
addReplyErrorFormat(c, "-BUSY %s", server.busy_module_yield_reply);
} else if (server.busy_module_yield_flags) {
addReplyErrorObject(c, shared.slowmoduleerr);
addReplyErrorObject(c, server.extended_redis_compat ? shared.slowmoduleerr_compat : shared.slowmoduleerr);
} else if (scriptIsEval()) {
addReplyErrorObject(c, shared.slowevalerr);
addReplyErrorObject(c, server.extended_redis_compat ? shared.slowevalerr_compat : shared.slowevalerr);
} else {
addReplyErrorObject(c, shared.slowscripterr);
addReplyErrorObject(c, server.extended_redis_compat ? shared.slowscripterr_compat : shared.slowscripterr);
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ void debugCommand(client *c) {
if (getPositiveLongFromObjectOrReply(c, c->argv[2], &keys, NULL) != C_OK) return;

if (server.loading || server.async_loading) {
addReplyErrorObject(c, shared.loadingerr);
addReplyErrorObject(c, server.extended_redis_compat ? shared.loadingerr_compat : shared.loadingerr);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ int functionsUnregisterEngine(const char *engine_name) {
*/
void functionStatsCommand(client *c) {
if (scriptIsRunning() && scriptIsEval()) {
addReplyErrorObject(c, shared.slowevalerr);
addReplyErrorObject(c, server.extended_redis_compat ? shared.slowevalerr_compat : shared.slowevalerr);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ void scriptKill(client *c, int is_eval) {
}
if (is_eval && !(curr_run_ctx->flags & SCRIPT_EVAL_MODE)) {
/* Kill a function with 'SCRIPT KILL' is not allow */
addReplyErrorObject(c, shared.slowscripterr);
addReplyErrorObject(c, server.extended_redis_compat ? shared.slowscripterr_compat : shared.slowscripterr);
return;
}
if (!is_eval && (curr_run_ctx->flags & SCRIPT_EVAL_MODE)) {
/* Kill an eval with 'FUNCTION KILL' is not allow */
addReplyErrorObject(c, shared.slowevalerr);
addReplyErrorObject(c, server.extended_redis_compat ? shared.slowevalerr_compat : shared.slowevalerr);
return;
}
curr_run_ctx->flags |= SCRIPT_KILLED;
Expand Down
42 changes: 35 additions & 7 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1963,19 +1963,39 @@ void afterSleep(struct aeEventLoop *eventLoop, int numevents) {
* called when the config changes. When the config is phased out, these
* initializations can be moved back inside createSharedObjects() below. */
void createSharedObjectsWithCompat(void) {
const char *name = server.extended_redis_compat ? "Redis" : SERVER_TITLE;
const char *name = SERVER_TITLE;
const char *name_compat = "Redis";

shared.loadingerr = makeObjectShared(createObject(
OBJ_STRING, sdscatfmt(sdsempty(), "-LOADING %s is loading the dataset in memory\r\n", name)));
shared.loadingerr_compat = makeObjectShared(createObject(
OBJ_STRING, sdscatfmt(sdsempty(), "-LOADING %s is loading the dataset in memory\r\n", name_compat)));

shared.slowevalerr = makeObjectShared(createObject(
OBJ_STRING,
sdscatfmt(sdsempty(),
"-BUSY %s is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.\r\n", name)));
shared.slowevalerr_compat = makeObjectShared(createObject(
OBJ_STRING,
sdscatfmt(sdsempty(),
"-BUSY %s is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.\r\n",
name_compat)));

shared.slowscripterr = makeObjectShared(createObject(
OBJ_STRING,
sdscatfmt(sdsempty(),
"-BUSY %s is busy running a script. You can only call FUNCTION KILL or SHUTDOWN NOSAVE.\r\n", name)));
shared.slowscripterr_compat = makeObjectShared(createObject(
OBJ_STRING,
sdscatfmt(sdsempty(),
"-BUSY %s is busy running a script. You can only call FUNCTION KILL or SHUTDOWN NOSAVE.\r\n",
name_compat)));

shared.slowmoduleerr = makeObjectShared(
createObject(OBJ_STRING, sdscatfmt(sdsempty(), "-BUSY %s is busy running a module command.\r\n", name)));
shared.slowmoduleerr_compat = makeObjectShared(
createObject(OBJ_STRING, sdscatfmt(sdsempty(), "-BUSY %s is busy running a module command.\r\n", name_compat)));

shared.bgsaveerr = makeObjectShared(
createObject(OBJ_STRING, sdscatfmt(sdsempty(),
"-MISCONF %s is configured to save RDB snapshots, but it's currently"
Expand All @@ -1984,6 +2004,14 @@ void createSharedObjectsWithCompat(void) {
" writes if RDB snapshotting fails (stop-writes-on-bgsave-error option)."
" Please check the %s logs for details about the RDB error.\r\n",
name, name)));
shared.bgsaveerr_compat = makeObjectShared(
createObject(OBJ_STRING, sdscatfmt(sdsempty(),
"-MISCONF %s is configured to save RDB snapshots, but it's currently"
" unable to persist to disk. Commands that may modify the data set are"
" disabled, because this instance is configured to report errors during"
" writes if RDB snapshotting fails (stop-writes-on-bgsave-error option)."
" Please check the %s logs for details about the RDB error.\r\n",
name, name_compat)));
}

void createSharedObjects(void) {
Expand Down Expand Up @@ -4257,13 +4285,13 @@ int processCommand(client *c) {
/* Loading DB? Return an error if the command has not the
* CMD_LOADING flag. */
if (server.loading && !server.async_loading && is_denyloading_command) {
rejectCommand(c, shared.loadingerr);
rejectCommand(c, server.extended_redis_compat ? shared.loadingerr_compat : shared.loadingerr);
return C_OK;
}

/* During async-loading, block certain commands. */
if (server.async_loading && is_deny_async_loading_command) {
rejectCommand(c, shared.loadingerr);
rejectCommand(c, server.extended_redis_compat ? shared.loadingerr_compat : shared.loadingerr);
return C_OK;
}

Expand All @@ -4278,11 +4306,11 @@ int processCommand(client *c) {
if (server.busy_module_yield_flags && server.busy_module_yield_reply) {
rejectCommandFormat(c, "-BUSY %s", server.busy_module_yield_reply);
} else if (server.busy_module_yield_flags) {
rejectCommand(c, shared.slowmoduleerr);
rejectCommand(c, server.extended_redis_compat ? shared.slowmoduleerr_compat : shared.slowmoduleerr);
} else if (scriptIsEval()) {
rejectCommand(c, shared.slowevalerr);
rejectCommand(c, server.extended_redis_compat ? shared.slowevalerr_compat : shared.slowevalerr);
} else {
rejectCommand(c, shared.slowscripterr);
rejectCommand(c, server.extended_redis_compat ? shared.slowscripterr_compat : shared.slowscripterr);
}
return C_OK;
}
Expand Down Expand Up @@ -4634,7 +4662,7 @@ int writeCommandsDeniedByDiskError(void) {
sds writeCommandsGetDiskErrorMessage(int error_code) {
sds ret = NULL;
if (error_code == DISK_ERROR_TYPE_RDB) {
ret = sdsdup(shared.bgsaveerr->ptr);
ret = sdsdup(server.extended_redis_compat ? shared.bgsaveerr_compat->ptr : shared.bgsaveerr->ptr);
} else {
ret = sdscatfmt(sdsempty(), "-MISCONF Errors writing to the AOF file: %s\r\n",
strerror(server.aof_last_write_errno));
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ struct sharedObjectsStruct {
robj *ok, *err, *emptybulk, *czero, *cone, *pong, *space, *queued, *null[4], *nullarray[4], *emptymap[4],
*emptyset[4], *emptyarray, *wrongtypeerr, *nokeyerr, *syntaxerr, *sameobjecterr, *outofrangeerr, *noscripterr,
*loadingerr, *slowevalerr, *slowscripterr, *slowmoduleerr, *bgsaveerr, *primarydownerr, *roreplicaerr,
*loadingerr_compat, *slowevalerr_compat, *slowscripterr_compat, *slowmoduleerr_compat, *bgsaveerr_compat,
*execaborterr, *noautherr, *noreplicaserr, *busykeyerr, *oomerr, *plus, *messagebulk, *pmessagebulk,
*subscribebulk, *unsubscribebulk, *psubscribebulk, *punsubscribebulk, *del, *unlink, *rpop, *lpop, *lpush,
*rpoplpush, *lmove, *blmove, *zpopmin, *zpopmax, *emptyscan, *multi, *exec, *left, *right, *hset, *srem,
Expand Down

0 comments on commit 5c2fda5

Please sign in to comment.