Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete librdb API to include all data types CB declarations #6

Merged
merged 11 commits into from
Jun 29, 2023
Merged
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lib:
$(MAKE) -C examples -f Makefile all

clean:
$(MAKE) -C deps -f Makefile clean
$(MAKE) -C src/lib -f Makefile clean
$(MAKE) -C src/ext -f Makefile clean
$(MAKE) -C src/cli -f Makefile clean
Expand Down
94 changes: 79 additions & 15 deletions api/librdb-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ extern "C" {
/****************************************************************
* Incomplete structures for compiler checks but opaque access
****************************************************************/

typedef char *RdbBulk;
typedef char *RdbBulkCopy;

typedef struct RdbReader RdbReader;
typedef struct RdbParser RdbParser;
typedef struct RdbHandlers RdbHandlers;
typedef struct RdbMemAlloc RdbMemAlloc;
typedef struct rax rax; /* redis DS */

/****************************************************************
* Enums & Typedefs
Expand Down Expand Up @@ -124,11 +124,38 @@ typedef enum RdbBulkAllocType {

typedef struct RdbKeyInfo {
long long expiretime;
uint64_t lru_idle;
int lfu_freq;
uint64_t lru_idle; /* TODO: support lru_idle */
int lfu_freq; /* TODO: support lfu_freq */
int opcode;
} RdbKeyInfo;

typedef struct RdbStreamID {
uint64_t ms;
uint64_t seq;
} RdbStreamID;

typedef struct RdbStreamMeta {
moticless marked this conversation as resolved.
Show resolved Hide resolved
uint64_t length; /* Current number of elements inside this stream. */
uint64_t entriesAdded; /* All time count of elements added. */
RdbStreamID *firstID;
RdbStreamID *lastID;
RdbStreamID *maxDeletedEntryID;
} RdbStreamMeta;

typedef struct RdbStreamPendingEntry {
long long deliveryTime;
uint64_t deliveryCount;
} RdbStreamPendingEntry;

typedef struct RdbStreamGroupMeta {
RdbStreamID lastId;
} RdbStreamGroupMeta;

typedef struct RdbStreamConsumerMeta {
long long activeTime;
long long seenTime;
} RdbStreamConsumerMeta;

/* misc function pointer typedefs */
typedef RdbStatus (*RdbReaderFunc) (RdbParser *p, void *readerData, void *buf, size_t len);
typedef void (*RdbFreeFunc) (RdbParser *p, void *obj);
Expand All @@ -155,26 +182,51 @@ typedef struct RdbHandlersRawCallbacks {
RdbRes (*handleBegin)(RdbParser *p, void *userData, size_t size);
RdbRes (*handleFrag)(RdbParser *p, void *userData, RdbBulk frag);
RdbRes (*handleEnd)(RdbParser *p, void *userData);
// RdbRes (*handleBeginModuleAux)(RdbParser *p, void *userData, RdbBulk name, int encver, int when);

/*** TODO: RdbHandlersRawCallbacks: handleBeginModuleAux ***/
RdbRes (*handleBeginModuleAux)(RdbParser *p, void *userData, RdbBulk name, int encver, int when);

} RdbHandlersRawCallbacks;

typedef struct RdbHandlersStructCallbacks {
HANDLERS_COMMON_CALLBACKS
RdbRes (*handleStringValue)(RdbParser *p, void *userData, RdbBulk str);
RdbRes (*handlerQListNode)(RdbParser *p, void *userData, RdbBulk listNode);
RdbRes (*handlerPlainNode)(RdbParser *p, void *userData, RdbBulk node);
/* ... TBD ... */
RdbRes (*handleQListNode)(RdbParser *p, void *userData, RdbBulk listNode);
RdbRes (*handlePlainNode)(RdbParser *p, void *userData, RdbBulk node);

/*** TODO: RdbHandlersStructCallbacks: handlerHashListPack, handleSetIntset, handleZsetListPack, handleFunction ***/
RdbRes (*handlerHashListPack)(RdbParser *p, void *userData, RdbBulk hash);
RdbRes (*handleSetIntset)(RdbParser *p, void *userData, RdbBulk intSet);
RdbRes (*handleSetListPack)(RdbParser *p, void *userData, RdbBulk listpack);
RdbRes (*handleSetZip)(RdbParser *p, void *userData, RdbBulk listpack);
RdbRes (*handleZsetListPack)(RdbParser *p, void *userData, RdbBulk zset);
RdbRes (*handleFunction)(RdbParser *p, void *userData, RdbBulk func);
/*** TODO: RdbHandlersStructCallbacks: stream stuff ... ***/
RdbRes (*handleStreamListPack)(RdbParser *p, void *userData, RdbBulk nodekey, RdbBulk listpack);

} RdbHandlersStructCallbacks;

typedef struct RdbHandlersDataCallbacks {
HANDLERS_COMMON_CALLBACKS
RdbRes (*handleStringValue)(RdbParser *p, void *userData, RdbBulk str);
RdbRes (*handleListElement)(RdbParser *p, void *userData, RdbBulk str);
// RdbRes (*handleSetElement)(RdbParser *p, void *userData, RdbBulk str, unsigned long sizeHint);
// RdbRes (*handleZsetElement)(RdbParser *p, void *userData, RdbBulk str, double score, unsigned long sizeHint);
// RdbRes (*handleHashElement)(RdbParser *p, void *userData, RdbBulk field, RdbBulk value, unsigned long sizeHint);
// RdbRes (*handleModuleDatatype)(RdbParser *p, void *userData, RdbBulk value);
/* ... TBD ... */

/*** TODO: RdbHandlersDataCallbacks: handleHashElement, handleSetElement, handleZsetElement ***/
RdbRes (*handleHashElement)(RdbParser *p, void *userData, RdbBulk field, RdbBulk elm, uint64_t totalNumElm);
RdbRes (*handleSetElement)(RdbParser *p, void *userData, RdbBulk elm, uint64_t totalNumElm);
RdbRes (*handleZsetElement)(RdbParser *p, void *userData, RdbBulk elm, double score, uint64_t totalNumElm);

/*** TODO: RdbHandlersDataCallbacks: stream stuff ... ***/

RdbRes (*handleStreamMetadata)(RdbParser *p, void *userData, RdbStreamMeta *meta);
RdbRes (*handleStreamElement)(RdbParser *p, void *userData, RdbStreamID *id, RdbBulk field, RdbBulk value, uint64_t totalNumElm);

RdbRes (*handleStreamNewCGroup)(RdbParser *p, void *userData, RdbBulk grpName, RdbStreamGroupMeta *meta);
RdbRes (*handleStreamCGroupPendingEntry)(RdbParser *p, void *userData, RdbStreamPendingEntry *pendingEntry);

RdbRes (*handleStreamNewConsumer)(RdbParser *p, void *userData, RdbBulk consName, RdbStreamConsumerMeta *meta);
RdbRes (*handleStreamConsumerPendingEntry)(RdbParser *p, void *userData, RdbStreamPendingEntry *pendingEntry);

} RdbHandlersDataCallbacks;

/****************************************************************
Expand Down Expand Up @@ -391,9 +443,9 @@ int RDB_isRefBulk(RdbParser *p, RdbBulk b);
* Some of the more advanced configuration might require parsing different data
* types at different levels of the parser.
*
* The callbacks that are common to all levels and not related to current key
* parsing (lookup HANDLERS_COMMON_CALLBACKS), if registered at different levels
* then all of them will be called, one by one, starting from level 0.
* The callbacks that are common to all levels (lookup HANDLERS_COMMON_CALLBACKS),
* if registered at different levels then all of them will be called, one by one,
* starting from level 0.
*
* As for the callbacks of RDB object types, each level has its own way to
* handle the data with distinct set of callbacks interfaces. In case of multiple
Expand All @@ -416,6 +468,18 @@ typedef enum RdbDataType {
/* Can be called at any point along parsing (Useful after parsing source rdb version) */
_LIBRDB_API void RDB_handleByLevel(RdbParser *p, RdbDataType t, RdbHandlersLevel lvl, unsigned int flags);

/*****************************************************************
* LIBRDB Versioning
*
* Follows the semantic semver versioning convention
*****************************************************************/

#define RDB_MAJOR_VERSION 255
#define RDB_MINOR_VERSION 255
#define RDB_PATCH_VERSION 255

_LIBRDB_API const char* RDB_getLibVersion(int* major, int* minor, int* patch);

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions api/librdb-ext-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ _LIBRDB_API RdbxFilterKey *RDBX_createHandlersFilterKey(RdbParser *p,
****************************************************************/

typedef struct RdbxToRespConf {
/* todo: support the option of expire, del, select db */
/* TODO: support the option of expire, del, select db */

/* If supportRestore, then data-types will be translated to RESTORE with
* raw data instead of data-types commands. This is a performance, version
* (specific) aligned, optimization */
int supportRestore;

/* todo: support rdb2resp del key before write */
/* TODO: support rdb2resp del key before write */
int delKeyBeforeWrite;
int skipAuxField;
int applySelectDbCmds;
Expand Down
22 changes: 22 additions & 0 deletions deps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# deps
The purpose of this folder is to provide the necessary dependencies for the librdb parser.
Currently, it includes only redis subfolder, which contains a subset of files from the Redis
repository that have been slightly adapted for reuse by librdb.

As the librdb library evolves, it might require additional dependencies apart from the redis
subfolder. In such cases, new subfolders may be added under the deps directory to
accommodate these dependencies.

# librdb dependencies

## redis
The redis subfolder contains a modified subset of files from the Redis repository. These
files have been slightly adapted and used by librdb parser. In the future, there is a
possibility that the librdb library will be integrated into the Redis repository. If this
integration occurs, the contents of this deps folder will reflect part of the required
dependencies and changes needed for the integration.

To upgrade, use as base reference specified version in version.h file, though it shouldn't
update so often (Otherwise, consider in the future having better methodology to consume
and upgrade redis code).

27 changes: 27 additions & 0 deletions deps/redis/endianconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,30 @@ uint64_t intrev64(uint64_t v) {
memrev64(&v);
return v;
}

#ifdef REDIS_TEST
#include <stdio.h>

#define UNUSED(x) (void)(x)
int endianconvTest(int argc, char *argv[], int flags) {
char buf[32];

UNUSED(argc);
UNUSED(argv);
UNUSED(flags);

sprintf(buf,"ciaoroma");
memrev16(buf);
printf("%s\n", buf);

sprintf(buf,"ciaoroma");
memrev32(buf);
printf("%s\n", buf);

sprintf(buf,"ciaoroma");
memrev64(buf);
printf("%s\n", buf);

return 0;
}
#endif
5 changes: 5 additions & 0 deletions deps/redis/endianconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#ifndef __ENDIANCONV_H
#define __ENDIANCONV_H

//#include "config.h"
#include <stdint.h>

void memrev16(void *p);
Expand Down Expand Up @@ -70,4 +71,8 @@ uint64_t intrev64(uint64_t v);
#define ntohu64(v) intrev64(v)
#endif

#ifdef REDIS_TEST
int endianconvTest(int argc, char *argv[], int flags);
#endif

#endif
Loading