From ac1cc5a6e15bd73bbb7ee9eff950850fdc69a31a Mon Sep 17 00:00:00 2001 From: Oran Agra Date: Mon, 15 Aug 2022 21:41:44 +0300 Subject: Trim rdb loading code for pre-release formats (#11058) The initial module format introduced in 4.0 RC1 and was changed in RC2 The initial function format introduced in 7.0 RC1 and changed in RC3 --- src/rdb.c | 102 +++++++++++++++++--------------------------------------------- 1 file changed, 28 insertions(+), 74 deletions(-) (limited to 'src/rdb.c') diff --git a/src/rdb.c b/src/rdb.c index 993a123c0..77499c39e 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -2605,7 +2605,10 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { raxStop(&ri_cg_pel); } } - } else if (rdbtype == RDB_TYPE_MODULE || rdbtype == RDB_TYPE_MODULE_2) { + } else if (rdbtype == RDB_TYPE_MODULE_PRE_GA) { + rdbReportCorruptRDB("Pre-release module format not supported"); + return NULL; + } else if (rdbtype == RDB_TYPE_MODULE_2) { uint64_t moduleid = rdbLoadLen(rdb,NULL); if (rioGetReadError(rdb)) { rdbReportReadError("Short read module id"); @@ -2613,7 +2616,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { } moduleType *mt = moduleTypeLookupModuleByID(moduleid); - if (rdbCheckMode && rdbtype == RDB_TYPE_MODULE_2) { + if (rdbCheckMode) { char name[10]; moduleTypeNameByID(name,moduleid); return rdbLoadCheckModuleValue(rdb,name); @@ -2629,7 +2632,6 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { robj keyobj; initStaticStringObject(keyobj,key); moduleInitIOContext(io,mt,rdb,&keyobj,dbid); - io.ver = (rdbtype == RDB_TYPE_MODULE) ? 1 : 2; /* Call the rdb_load method of the module providing the 10 bit * encoding version in the lower 10 bits of the module ID. */ void *ptr = mt->rdb_load(&io,moduleid&1023); @@ -2639,24 +2641,22 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { } /* Module v2 serialization has an EOF mark at the end. */ - if (io.ver == 2) { - uint64_t eof = rdbLoadLen(rdb,NULL); - if (eof == RDB_LENERR) { - if (ptr) { - o = createModuleObject(mt,ptr); /* creating just in order to easily destroy */ - decrRefCount(o); - } - return NULL; + uint64_t eof = rdbLoadLen(rdb,NULL); + if (eof == RDB_LENERR) { + if (ptr) { + o = createModuleObject(mt,ptr); /* creating just in order to easily destroy */ + decrRefCount(o); } - if (eof != RDB_MODULE_OPCODE_EOF) { - rdbReportCorruptRDB("The RDB file contains module data for the module '%s' that is not terminated by " - "the proper module value EOF marker", moduleTypeModuleName(mt)); - if (ptr) { - o = createModuleObject(mt,ptr); /* creating just in order to easily destroy */ - decrRefCount(o); - } - return NULL; + return NULL; + } + if (eof != RDB_MODULE_OPCODE_EOF) { + rdbReportCorruptRDB("The RDB file contains module data for the module '%s' that is not terminated by " + "the proper module value EOF marker", moduleTypeModuleName(mt)); + if (ptr) { + o = createModuleObject(mt,ptr); /* creating just in order to easily destroy */ + decrRefCount(o); } + return NULL; } if (ptr == NULL) { @@ -2794,62 +2794,14 @@ void rdbLoadProgressCallback(rio *r, const void *buf, size_t len) { * * The lib_ctx argument is also optional. If NULL is given, only verify rdb * structure with out performing the actual functions loading. */ -int rdbFunctionLoad(rio *rdb, int ver, functionsLibCtx* lib_ctx, int type, int rdbflags, sds *err) { +int rdbFunctionLoad(rio *rdb, int ver, functionsLibCtx* lib_ctx, int rdbflags, sds *err) { UNUSED(ver); sds error = NULL; sds final_payload = NULL; int res = C_ERR; - if (type == RDB_OPCODE_FUNCTION) { - /* RDB that was generated on versions 7.0 rc1 and 7.0 rc2 has another - * an old format that contains the library name, engine and description. - * To support this format we must read those values. */ - sds name = NULL; - sds engine_name = NULL; - sds desc = NULL; - sds blob = NULL; - uint64_t has_desc; - - if (!(name = rdbGenericLoadStringObject(rdb, RDB_LOAD_SDS, NULL))) { - error = sdsnew("Failed loading library name"); - goto cleanup; - } - - if (!(engine_name = rdbGenericLoadStringObject(rdb, RDB_LOAD_SDS, NULL))) { - error = sdsnew("Failed loading engine name"); - goto cleanup; - } - - if ((has_desc = rdbLoadLen(rdb, NULL)) == RDB_LENERR) { - error = sdsnew("Failed loading library description indicator"); - goto cleanup; - } - - if (has_desc && !(desc = rdbGenericLoadStringObject(rdb, RDB_LOAD_SDS, NULL))) { - error = sdsnew("Failed loading library description"); - goto cleanup; - } - - if (!(blob = rdbGenericLoadStringObject(rdb, RDB_LOAD_SDS, NULL))) { - error = sdsnew("Failed loading library blob"); - goto cleanup; - } - /* Translate old format (versions 7.0 rc1 and 7.0 rc2) to new format. - * The new format has the library name and engine inside the script payload. - * Add those parameters to the original script payload (ignore the description if exists). */ - final_payload = sdscatfmt(sdsempty(), "#!%s name=%s\n%s", engine_name, name, blob); -cleanup: - if (name) sdsfree(name); - if (engine_name) sdsfree(engine_name); - if (desc) sdsfree(desc); - if (blob) sdsfree(blob); - if (error) goto done; - } else if (type == RDB_OPCODE_FUNCTION2) { - if (!(final_payload = rdbGenericLoadStringObject(rdb, RDB_LOAD_SDS, NULL))) { - error = sdsnew("Failed loading library payload"); - goto done; - } - } else { - serverPanic("Bad function type was given to rdbFunctionLoad"); + if (!(final_payload = rdbGenericLoadStringObject(rdb, RDB_LOAD_SDS, NULL))) { + error = sdsnew("Failed loading library payload"); + goto done; } if (lib_ctx) { @@ -3070,7 +3022,6 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin RedisModuleIO io; moduleInitIOContext(io,mt,rdb,NULL,-1); - io.ver = 2; /* Call the rdb_load method of the module providing the 10 bit * encoding version in the lower 10 bits of the module ID. */ int rc = mt->aux_load(&io,moduleid&1023, when); @@ -3095,9 +3046,12 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin decrRefCount(aux); continue; /* Read next opcode. */ } - } else if (type == RDB_OPCODE_FUNCTION || type == RDB_OPCODE_FUNCTION2) { + } else if (type == RDB_OPCODE_FUNCTION_PRE_GA) { + rdbReportCorruptRDB("Pre-release function format not supported."); + exit(1); + } else if (type == RDB_OPCODE_FUNCTION2) { sds err = NULL; - if (rdbFunctionLoad(rdb, rdbver, rdb_loading_ctx->functions_lib_ctx, type, rdbflags, &err) != C_OK) { + if (rdbFunctionLoad(rdb, rdbver, rdb_loading_ctx->functions_lib_ctx, rdbflags, &err) != C_OK) { serverLog(LL_WARNING,"Failed loading library, %s", err); sdsfree(err); goto eoferr; -- cgit v1.2.1