From 05b8df0f4883ff7130c2b15b49343d3948cb74f2 Mon Sep 17 00:00:00 2001 From: moticless Date: Mon, 4 Sep 2023 21:05:52 +0300 Subject: [PATCH] RDB2RESP: Remove SELECT command exclusion flag from API --- api/librdb-ext-api.h | 25 ++++++++++++++----------- src/ext/handlersToResp.c | 2 +- test/test_rdb_to_resp.c | 12 ++++++++++++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/api/librdb-ext-api.h b/api/librdb-ext-api.h index 7d8d4f4..b424ff4 100644 --- a/api/librdb-ext-api.h +++ b/api/librdb-ext-api.h @@ -64,11 +64,11 @@ typedef enum RdbxToJsonEnc { } RdbxToJsonEnc; typedef struct RdbxToJsonConf { - RdbHandlersLevel level; - RdbxToJsonEnc encoding; - int includeAuxField; - int includeFunc; - int flatten; /* 0=db hirarchy preserved 1=flatten json */ + RdbHandlersLevel level; /* Parsing depth (raw, structures or data-types) */ + RdbxToJsonEnc encoding; /* Encoding format for the resulting JSON */ + int includeAuxField; /* Set to include auxiliary fields in JSON output */ + int includeFunc; /* Set to include functions in JSON output */ + int flatten; /* Set to create a flattened JSON structure */ } RdbxToJsonConf; _LIBRDB_API RdbxToJson *RDBX_createHandlersToJson(RdbParser *p, @@ -92,8 +92,11 @@ _LIBRDB_API RdbxFilterKey *RDBX_createHandlersFilterKey(RdbParser *p, ****************************************************************/ typedef struct RdbxToRespConf { + /* delKeyBeforeWrite - will add preceding DEL command before each new key. If + * the keys are created with RESTORE commands, then instead of sending another + * DEL command, it will be optimized by attaching `REPLACE` flag to the + * RESTORE command. */ int delKeyBeforeWrite; - int applySelectDbCmds; /* if not configured SELECT commands, all keys will be flatten into a single db */ /* If supportRestore, then data-types will be translated to RESTORE with * raw data instead of data-types commands. This is a performance optimization @@ -121,7 +124,7 @@ _LIBRDB_API RdbxToResp *RDBX_createHandlersToResp(RdbParser *, RdbxToRespConf *) * Used by: RDBX_createRespToRedisTcp * RDBX_createRespToRedisFd * RDBX_createRespToFileWriter - * + * ****************************************************************/ typedef struct RdbxRespWriter { @@ -129,7 +132,7 @@ typedef struct RdbxRespWriter { void (*delete)(void *ctx); /* return 0 on success. Otherwise 1 */ - int (*writev) (void *ctx, struct iovec *ioVec, int count, int startCmd, int endCmd); + int (*writev) (void *ctx, struct iovec *ioVec, int iovCnt, int startCmd, int endCmd); int (*flush) (void *ctx); } RdbxRespWriter; @@ -139,17 +142,17 @@ _LIBRDB_API void RDBX_attachRespWriter(RdbxToResp *rdbToResp, RdbxRespWriter *wr /**************************************************************** * Create RESP to File Writer * - * If provided path is NULL then write stdout + * If provided path is NULL then write to stdout ****************************************************************/ _LIBRDB_API RdbxRespToFileWriter *RDBX_createRespToFileWriter(RdbParser *p, RdbxToResp *rdbToResp, const char* filepath); /**************************************************************** - * Create RESP to Redis TCP connection + * Create RESP to Redis TCP/FD connection * * Can configure pipeline depth of transmitted RESP commands. Set - * to 0 if to use default. + * to 0 to use default. ****************************************************************/ _LIBRDB_API RdbxRespToRedisLoader *RDBX_createRespToRedisTcp(RdbParser *p, RdbxToResp *rdbToResp, diff --git a/src/ext/handlersToResp.c b/src/ext/handlersToResp.c index a53823f..09dd149 100644 --- a/src/ext/handlersToResp.c +++ b/src/ext/handlersToResp.c @@ -509,7 +509,7 @@ _LIBRDB_API RdbxToResp *RDBX_createHandlersToResp(RdbParser *p, RdbxToRespConf * RdbHandlersDataCallbacks dataCb; memset(&dataCb, 0, sizeof(RdbHandlersDataCallbacks)); dataCb.handleStartRdb = toRespStartRdb; - dataCb.handleNewDb = (ctx->conf.applySelectDbCmds) ? toRespNewDb : NULL; + dataCb.handleNewDb = toRespNewDb; dataCb.handleNewKey = toRespNewKey; dataCb.handleEndKey = toRespEndKey; dataCb.handleStringValue = toRespString; diff --git a/test/test_rdb_to_resp.c b/test/test_rdb_to_resp.c index 8c0c974..163fe24 100644 --- a/test/test_rdb_to_resp.c +++ b/test/test_rdb_to_resp.c @@ -2,6 +2,16 @@ #include #include "test_common.h" + /* To enhance the clarity of our tests and keep expected outputs concise, a + * filter is defined to remove the initial SELECT command that precedes all + * RESP outputs when parsing RDB to RESP */ +RdbRes dontPropHandleNewDb(RdbParser *p, void *userData, int dbnum) { + UNUSED(p, userData, dbnum); + return RDB_OK_DONT_PROPAGATE; +} + +RdbHandlersDataCallbacks filterSelectCmd = {.handleNewDb = dontPropHandleNewDb}; + /* This group of tests only partially check the RESP protocol output of * the parser by comparing the prefix of the output rather than maintaining * hardcoded and non-readable payload in the test. It is sufficient because test @@ -35,6 +45,8 @@ static void testRdbToRespCommon(const char *rdbfilename, assert_non_null(RDBX_createReaderFile(p, rdbfile)); assert_non_null(rdbToResp = RDBX_createHandlersToResp(p, conf)); assert_non_null(writer = RDBX_createRespToFileWriter(p, rdbToResp, respfile)); + assert_non_null(RDB_createHandlersData(p, &filterSelectCmd, NULL, NULL)); + while ((status = RDB_parse(p)) == RDB_STATUS_WAIT_MORE_DATA); assert_int_equal( status, RDB_STATUS_OK);