Skip to content

Commit

Permalink
RDB2RESP: Remove SELECT command exclusion flag from API
Browse files Browse the repository at this point in the history
  • Loading branch information
moticless committed Sep 5, 2023
1 parent 7acc4d3 commit a8e9167
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
25 changes: 14 additions & 11 deletions api/librdb-ext-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -121,15 +124,15 @@ _LIBRDB_API RdbxToResp *RDBX_createHandlersToResp(RdbParser *, RdbxToRespConf *)
* Used by: RDBX_createRespToRedisTcp
* RDBX_createRespToRedisFd
* RDBX_createRespToFileWriter
* <user-defined-handlers>
* <user-defined-writer>
****************************************************************/

typedef struct RdbxRespWriter {
void *ctx;
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;

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ext/handlersToResp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions test/test_rdb_to_resp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
#include <malloc.h>
#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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit a8e9167

Please sign in to comment.