Skip to content

Commit

Permalink
Callback native ziplist instead of redundant convert to listpack
Browse files Browse the repository at this point in the history
  • Loading branch information
moticless committed Jul 26, 2023
1 parent afea136 commit d994164
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 130 deletions.
7 changes: 4 additions & 3 deletions api/librdb-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ typedef enum RdbRes {
RDB_ERR_NOT_SUPPORTED_RDB_ENCODING_TYPE,
RDB_ERR_UNKNOWN_RDB_ENCODING_TYPE,
RDB_ERR_QUICK_LIST_INTEG_CHECK,
RDB_ERR_ZIP_LIST_INTEG_CHECK,
RDB_ERR_STRING_INVALID_STATE,
RDB_ERR_PLAIN_LIST_INVALID_STATE,
RDB_ERR_QUICK_LIST_INVALID_STATE,
RDB_ERR_ZIP_LIST_INVALID_STATE,
RDB_ERR_ZIP_LIST_INTEG_CHECK,
RDB_ERR_INVALID_BULK_ALLOC_TYPE,
RDB_ERR_INVALID_BULK_CLONE_REQUEST,
RDB_ERR_INVALID_BULK_LENGTH_REQUEST,
Expand Down Expand Up @@ -193,8 +193,9 @@ typedef struct RdbHandlersRawCallbacks {
typedef struct RdbHandlersStructCallbacks {
HANDLERS_COMMON_CALLBACKS
RdbRes (*handleStringValue)(RdbParser *p, void *userData, RdbBulk str);
RdbRes (*handleQListNode)(RdbParser *p, void *userData, RdbBulk listNode);
RdbRes (*handlePlainNode)(RdbParser *p, void *userData, RdbBulk node);
RdbRes (*handleListLP)(RdbParser *p, void *userData, RdbBulk listPack);
RdbRes (*handleListZL)(RdbParser *p, void *userData, RdbBulk ziplist);
RdbRes (*handleListNode)(RdbParser *p, void *userData, RdbBulk node);

/*** TODO: RdbHandlersStructCallbacks: handlerHashListPack, handleSetIntset, handleZsetListPack, handleFunction ***/
RdbRes (*handlerHashListPack)(RdbParser *p, void *userData, RdbBulk hash);
Expand Down
17 changes: 14 additions & 3 deletions src/ext/handlersFilterKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ static RdbRes filterHandlingList(RdbParser *p, void *userData, RdbBulk str) {

/*** Handling struct ***/

static RdbRes filterHandlingQListNode(RdbParser *p, void *userData, RdbBulk listNode) {
static RdbRes filterHandlingListLP(RdbParser *p, void *userData, RdbBulk listNode) {
UNUSED(p, listNode);
return ((RdbxFilterKey *) userData)->cbReturnValue;
}

static RdbRes filterHandlingListZL(RdbParser *p, void *userData, RdbBulk listNode) {
UNUSED(p, listNode);
return ((RdbxFilterKey *) userData)->cbReturnValue;
}

static RdbRes filterHandlingListNode(RdbParser *p, void *userData, RdbBulk str) {
UNUSED(p, str);
return ((RdbxFilterKey *) userData)->cbReturnValue;
}

/*** Handling raw ***/

static RdbRes filterHandlingFrag(RdbParser *p, void *userData, RdbBulk frag) {
Expand Down Expand Up @@ -105,8 +115,9 @@ RdbxFilterKey *RDBX_createHandlersFilterKey(RdbParser *p,

if (RDB_getNumHandlers(p, RDB_LEVEL_STRUCT)>0) {
callbacks.structCb.handleStringValue = filterHandlingString;
callbacks.structCb.handleQListNode = filterHandlingQListNode;
callbacks.structCb.handlePlainNode = filterHandlingList;
callbacks.structCb.handleListLP = filterHandlingListLP;
callbacks.structCb.handleListZL = filterHandlingListZL;
callbacks.structCb.handleListNode = filterHandlingListNode;
RDB_createHandlersStruct(p, &callbacks.structCb, ctx, deleteFilterKeyCtx);
}

Expand Down
33 changes: 3 additions & 30 deletions src/ext/handlersToJson.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,34 +277,6 @@ static RdbRes handlingList(RdbParser *p, void *userData, RdbBulk str) {

/*** Handling struct ***/

static RdbRes handlingQListNode(RdbParser *p, void *userData, RdbBulk listNode) {
RdbxToJson *ctx = userData;

if (ctx->state == R2J_IN_KEY) {

/* output json part */
ouput_fprintf(ctx, "[");
outputQuotedEscaping(ctx, listNode, RDB_bulkLen(p, listNode));

/* update new state */
ctx->state = R2J_IN_LIST;

} else if (ctx->state == R2J_IN_LIST) {

/* output json part */
ouput_fprintf(ctx, ",");
outputQuotedEscaping(ctx, listNode, RDB_bulkLen(p, listNode));

/* state unchanged */

} else {
RDB_reportError(p, (RdbRes) RDBX_ERR_R2J_INVALID_STATE,
"handlingList(): Invalid state value: %d", ctx->state);
return (RdbRes) RDBX_ERR_R2J_INVALID_STATE;
}

return RDB_OK;
}

/*** Handling raw ***/

Expand Down Expand Up @@ -352,8 +324,9 @@ RdbxToJson *RDBX_createHandlersToJson(RdbParser *p, const char *filename, RdbxTo
RDB_createHandlersData(p, &callbacks.dataCb, ctx, deleteRdbToJsonCtx);
} else if (ctx->conf.level == RDB_LEVEL_STRUCT) {
callbacks.structCb.handleStringValue = handlingString;
callbacks.structCb.handleQListNode = handlingQListNode;
callbacks.structCb.handlePlainNode = handlingList;
callbacks.structCb.handleListLP = handlingList;
callbacks.structCb.handleListZL = handlingList;
callbacks.structCb.handleListNode = handlingList;
RDB_createHandlersStruct(p, &callbacks.structCb, ctx, deleteRdbToJsonCtx);
} else if (ctx->conf.level == RDB_LEVEL_RAW) {
callbacks.rawCb.handleFrag = handlingFrag;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/bulkAlloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ int bulkPoolIsNewNextAllocDbg(RdbParser *p) {
return (pool->writeIdx == pool->readIdx) ? 1 : 0;
}

void bulkPoolAssertFlushedDbg(RdbParser *p) {
BulkPool *pool = p->cache;
assert(pool->writeIdx == 0);
}

static inline BulkInfo *bulkPoolEnqueue(BulkPool *pool) {
pool->writeIdx += 1;
if (unlikely(pool->writeIdx == pool->queueSize)) {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/bulkAlloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ void bulkPoolRelease(RdbParser *p);
BulkInfo *bulkPoolAlloc(RdbParser *p, size_t len, AllocTypeRq typeRq, char *refBuf);
void bulkPoolFlush(RdbParser *p);
void bulkPoolRollback(RdbParser *p);
void bulkPoolPrintDbg(RdbParser *p);
int bulkPoolIsNewNextAllocDbg(RdbParser *p);

/*** BulkUnmanaged ***/
void bulkUnmanagedAlloc(RdbParser *p, size_t len, AllocUnmngTypeRq rq, char *refBuf, BulkInfo *bi);
Expand All @@ -79,4 +77,9 @@ void bulkUnmanagedFree(RdbParser *p, BulkInfo *binfo);
/* cloning RdbBulk */
RdbBulkCopy bulkClone(RdbParser *p, BulkInfo *binfo);

/* debug */
void bulkPoolPrintDbg(RdbParser *p);
int bulkPoolIsNewNextAllocDbg(RdbParser *p);
void bulkPoolAssertFlushedDbg(RdbParser *p);

#endif /*BULK_ALLOC_H*/
Loading

0 comments on commit d994164

Please sign in to comment.