From c32ae00cb88b9363711f80fbc4ad3923f028ac63 Mon Sep 17 00:00:00 2001 From: John Sully Date: Fri, 19 Apr 2019 19:57:11 -0400 Subject: [PATCH] Add version override command for users that need compatibility with Redis Former-commit-id: 5a78a3bc46335a844490fe00e657d68313680cbe --- src/config.cpp | 7 +++++++ src/debug.cpp | 2 +- src/networking.cpp | 2 +- src/rdb.cpp | 2 +- src/redis-cli.c | 2 +- src/release.c | 2 +- src/server.cpp | 8 ++++---- src/version.h | 3 ++- 8 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index a702a5645..51a47482c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -34,6 +34,8 @@ #include #include +const char *KEYDB_SET_VERSION = KEYDB_REAL_VERSION; + /*----------------------------------------------------------------------------- * Config file name-value maps. *----------------------------------------------------------------------------*/ @@ -859,6 +861,9 @@ void loadServerConfigFromString(char *config) { if ((server.enable_multimaster = yesnotoi(argv[1])) == -1) { err = "argument must be 'yes' or 'no'"; goto loaderr; } + } else if (!strcasecmp(argv[0], "version-override") && argc == 2) { + KEYDB_SET_VERSION = zstrdup(argv[1]); + serverLog(LL_WARNING, "Warning version is overriden to: %s\n", KEYDB_SET_VERSION); } else { err = "Bad directive or wrong number of arguments"; goto loaderr; } @@ -1413,6 +1418,7 @@ void configGetCommand(client *c) { config_get_string_field("pidfile",server.pidfile); config_get_string_field("slave-announce-ip",server.slave_announce_ip); config_get_string_field("replica-announce-ip",server.slave_announce_ip); + config_get_string_field("version-override",KEYDB_SET_VERSION); /* Numerical values */ config_get_numerical_field("maxmemory",server.maxmemory); @@ -2378,6 +2384,7 @@ int rewriteConfig(char *path) { rewriteConfigYesNoOption(state,"dynamic-hz",server.dynamic_hz,CONFIG_DEFAULT_DYNAMIC_HZ); rewriteConfigYesNoOption(state,"active-replica",server.fActiveReplica,CONFIG_DEFAULT_ACTIVE_REPLICA); rewriteConfigYesNoOption(state,"multi-master",server.enable_multimaster,CONFIG_DEFAULT_ENABLE_MULTIMASTER); + rewriteConfigStringOption(state, "version-override",KEYDB_SET_VERSION,KEYDB_REAL_VERSION); /* Rewrite Sentinel config if in Sentinel mode. */ if (server.sentinel_mode) rewriteConfigSentinelOption(state); diff --git a/src/debug.cpp b/src/debug.cpp index edcc1c631..c0c26369a 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -1362,7 +1362,7 @@ void sigsegvHandler(int sig, siginfo_t *info, void *secret) { bugReportStart(); serverLog(LL_WARNING, - "Redis %s crashed by signal: %d", REDIS_VERSION, sig); + "Redis %s crashed by signal: %d", KEYDB_REAL_VERSION, sig); if (eip != NULL) { serverLog(LL_WARNING, "Crashed running the instruction at: %p", eip); diff --git a/src/networking.cpp b/src/networking.cpp index 88cc7afb2..d15629fac 100644 --- a/src/networking.cpp +++ b/src/networking.cpp @@ -2557,7 +2557,7 @@ void helloCommand(client *c) { addReplyBulkCString(c,"redis"); addReplyBulkCString(c,"version"); - addReplyBulkCString(c,REDIS_VERSION); + addReplyBulkCString(c,KEYDB_SET_VERSION); addReplyBulkCString(c,"proto"); addReplyLongLong(c,3); diff --git a/src/rdb.cpp b/src/rdb.cpp index 12bbc8333..be8b382dc 100644 --- a/src/rdb.cpp +++ b/src/rdb.cpp @@ -1074,7 +1074,7 @@ int rdbSaveInfoAuxFields(rio *rdb, int flags, rdbSaveInfo *rsi) { int aof_preamble = (flags & RDB_SAVE_AOF_PREAMBLE) != 0; /* Add a few fields about the state when the RDB was created. */ - if (rdbSaveAuxFieldStrStr(rdb,"redis-ver",REDIS_VERSION) == -1) return -1; + if (rdbSaveAuxFieldStrStr(rdb,"redis-ver",KEYDB_REAL_VERSION) == -1) return -1; if (rdbSaveAuxFieldStrInt(rdb,"redis-bits",redis_bits) == -1) return -1; if (rdbSaveAuxFieldStrInt(rdb,"ctime",time(NULL)) == -1) return -1; if (rdbSaveAuxFieldStrInt(rdb,"used-mem",zmalloc_used_memory()) == -1) return -1; diff --git a/src/redis-cli.c b/src/redis-cli.c index 40c8501fe..ab3de2e73 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -282,7 +282,7 @@ static int helpEntriesLen; static sds cliVersion(void) { sds version; - version = sdscatprintf(sdsempty(), "%s", REDIS_VERSION); + version = sdscatprintf(sdsempty(), "%s", KEYDB_REAL_VERSION); /* Add git commit and working tree status when available */ if (strtoll(redisGitSHA1(),NULL,16)) { diff --git a/src/release.c b/src/release.c index 4e59c7474..a5a334f30 100644 --- a/src/release.c +++ b/src/release.c @@ -46,7 +46,7 @@ char *redisGitDirty(void) { } uint64_t redisBuildId(void) { - char *buildid = REDIS_VERSION REDIS_BUILD_ID REDIS_GIT_DIRTY REDIS_GIT_SHA1; + char *buildid = KEYDB_REAL_VERSION REDIS_BUILD_ID REDIS_GIT_DIRTY REDIS_GIT_SHA1; return crc64(0,(unsigned char*)buildid,strlen(buildid)); } diff --git a/src/server.cpp b/src/server.cpp index 355e1e0b3..7e8275d2d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3988,7 +3988,7 @@ sds genRedisInfoString(const char *section) { "lru_clock:%ld\r\n" "executable:%s\r\n" "config_file:%s\r\n", - REDIS_VERSION, + KEYDB_SET_VERSION, redisGitSHA1(), strtol(redisGitDirty(),NULL,10) > 0, (unsigned long long) redisBuildId(), @@ -4587,7 +4587,7 @@ void daemonize(void) { void version(void) { printf("Redis server v=%s sha=%s:%d malloc=%s bits=%d build=%llx\n", - REDIS_VERSION, + KEYDB_REAL_VERSION, redisGitSHA1(), atoi(redisGitDirty()) > 0, ZMALLOC_LIB, @@ -4637,7 +4637,7 @@ void redisAsciiArt(void) { ); } else { snprintf(buf,1024*16,ascii_logo, - REDIS_VERSION, + KEYDB_REAL_VERSION, redisGitSHA1(), strtol(redisGitDirty(),NULL,10) > 0, (sizeof(long) == 8) ? "64" : "32", @@ -5051,7 +5051,7 @@ int main(int argc, char **argv) { serverLog(LL_WARNING, "oO0OoO0OoO0Oo KeyDB is starting oO0OoO0OoO0Oo"); serverLog(LL_WARNING, "KeyDB version=%s, bits=%d, commit=%s, modified=%d, pid=%d, just started", - REDIS_VERSION, + KEYDB_REAL_VERSION, (sizeof(long) == 8) ? 64 : 32, redisGitSHA1(), strtol(redisGitDirty(),NULL,10) > 0, diff --git a/src/version.h b/src/version.h index 553767641..489a16290 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1,2 @@ -#define REDIS_VERSION "0.9.2" +#define KEYDB_REAL_VERSION "0.9.2" +extern const char *KEYDB_SET_VERSION; // Unlike real version, this can be overriden by the config \ No newline at end of file