Skip to content

Commit

Permalink
RESP2REDIS: Refine error reporting from server (#25)
Browse files Browse the repository at this point in the history
The api of RESP writer (which attached to RDB2RESP) is rather simple as it expects a plain iovec. It is not sufficient when it comes to play the RESP against live server such as the case of respToRedisLoader. In case of an error from the server it is desired to report an informative message to the user of the problematic command and key. librdb does have mechanism to report on the problematic command even in case of pipeline of commands but it reports the entire command as a raw data with not distinction down to command and key.

Extend API to pass as well command and key to RESP writer on start of a new RESP command.
(Another motivation to this change is to be aligned with RE Syncer code that expects specific formatted errors)
Refine and optimize ignoreChecksum flag.
  • Loading branch information
moticless authored Oct 26, 2023
1 parent dcc1eff commit 8d916c4
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 109 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# librdb

C library for parsing RDB files.
This is C library for parsing RDB files.

The Parser is implemented in the spirit of SAX parser. It fires off a series of events as
it reads the RDB file from beginning to end, and callbacks to handlers registered on
Expand Down Expand Up @@ -123,9 +123,9 @@ Level0. The same goes between Level2 and Level1 correspondingly.
### Handlers
The **Handlers** represent a set of builtin or user-defined functions that will be called on the
parsed data. Future plan to support built-in Handlers:
* Convert RDB to JSON file handlers. (Status: WIP)
* Convert RDB to RESP protocol handlers. (Status: WIP)
* Memory Analyze (Status: Todo)
* Convert RDB to JSON file handlers.
* Convert RDB to RESP protocol handlers.
* Memory Analyze (TODO)

It is possible to attach to parser more than one set of handlers at the same level.
That is, for a given data at a given level, the parser will call each of the handlers that
Expand Down
2 changes: 1 addition & 1 deletion api/librdb-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ _LIBRDB_API RdbState RDB_getState(RdbParser *p);
/* get number of handlers registered at given level */
_LIBRDB_API int RDB_getNumHandlers(RdbParser *p, RdbHandlersLevel lvl);

/* set the parser to ignore checksum errors */
/* To ignore on checksum error. Else parser return RDB_ERR_CHECKSUM_FAILURE */
_LIBRDB_API void RDB_IgnoreChecksum(RdbParser *p);

/* There could be relatively large strings stored within Redis, which are
Expand Down
20 changes: 18 additions & 2 deletions api/librdb-ext-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,36 @@ _LIBRDB_API RdbxToResp *RDBX_createHandlersToResp(RdbParser *, RdbxToRespConf *)
/****************************************************************
* RESP writer
*
* Create instance for writing RDB to RESP stream.
* Interface to create writer instance for RDB to RESP stream.
*
* Imp by: RDBX_createRespToRedisTcp
* RDBX_createRespToRedisFd
* RDBX_createRespToFileWriter
* <user-defined-writer>
****************************************************************/

/* On start command pass command info. NULL otherwise. */
typedef struct RdbxRespWriterStartCmd {
/* Redis Command name (Ex: "SET", "RESTORE"). Owned by the caller. It is
* constant static string and Valid for ref behind the duration of the call. */
const char *cmd;
/* If key available as part of command. Else empty string.
* Owned by the caller. */
const char *key;
} RdbxRespWriterStartCmd;

typedef struct RdbxRespWriter {
void *ctx;
void (*delete)(void *ctx);

/* return 0 on success. Otherwise 1 */
int (*writev) (void *ctx, struct iovec *ioVec, int iovCnt, int startCmd, int endCmd);
int (*writev) (void *ctx,
struct iovec *ioVec, /* Standard C scatter/gather IO array */
int iovCnt, /* Number of iovec elements */
RdbxRespWriterStartCmd *startCmd, /* If start of RESP command then not NULL. Owned by
* the caller. Valid for the duration of the call. */
int endCmd); /* 1, if this is end of RESP command, 0 otherwise */

int (*flush) (void *ctx);
} RdbxRespWriter;

Expand Down
2 changes: 1 addition & 1 deletion examples/example1.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* The following C file serves as an illustration of how to use the librdb
* library for transforming Redis RDB files into JSON format. If you wish to see
* the various parsing components being invoked in the background, simply set
* the environment variable ENV_VAR_DEBUG_DATA to 1.
* the environment variable LIBRDB_DEBUG_DATA to 1.
*
* $ export LIBRDB_DEBUG_DATA=1
* $ make example
Expand Down
Loading

0 comments on commit 8d916c4

Please sign in to comment.