diff --git a/source/libs/tdb/src/db/btree.c b/source/libs/tdb/src/db/btree.c index 3ed6667c92..c38a6db8c2 100644 --- a/source/libs/tdb/src/db/btree.c +++ b/source/libs/tdb/src/db/btree.c @@ -28,10 +28,13 @@ typedef struct { // Btree page header definition typedef struct __attribute__((__packed__)) { - uint8_t flags; - uint16_t ncells; - pgsz_t pldOffset; // payload offset - /* TODO */ + uint8_t flag; // page flag + int32_t vlen; // value length of current page, TDB_VARIANT_LEN for variant length + uint16_t nPayloads; // number of total payloads + pgoff_t freeOff; // free payload offset + pgsz_t fragSize; // total fragment size + pgoff_t offPayload; // payload offset + pgno_t rChildPgno; // right most child page number } SBtPgHdr; typedef int (*BtreeCmprFn)(const void *, const void *); @@ -88,7 +91,7 @@ int btreeCursorMoveTo(SBtCursor *pBtCur, int kLen, const void *pKey) { SPgFile * pPgFile; pgno_t childPgno; pgno_t rootPgno; - int nPayload; + int nPayloads; void * pPayload; BtreeCmprFn cmpFn; @@ -109,11 +112,11 @@ int btreeCursorMoveTo(SBtCursor *pBtCur, int kLen, const void *pKey) { pPage = pBtCur->pPage; pBtPgHdr = BTREE_PAGE_HDR(pPage); - nPayload = pBtPgHdr->ncells; + nPayloads = pBtPgHdr->nPayloads; // Binary search the page lidx = 0; - ridx = nPayload - 1; + ridx = nPayloads - 1; midx = (lidx + ridx) >> 1; for (;;) { // get the payload ptr at midx diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 18ab940517..cc79ccaf39 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -70,6 +70,9 @@ typedef int32_t frame_id_t; #define TDB_DEFAULT_PGSIZE 4096 #define TDB_IS_PGSIZE_VLD(s) (((s) >= TDB_MIN_PGSIZE) && ((s) <= TDB_MAX_PGSIZE)) +// pgoff_t +typedef pgsz_t pgoff_t; + // cache #define TDB_DEFAULT_CACHE_SIZE (256 * 1024) // 256K @@ -93,15 +96,17 @@ typedef TD_DLIST(SPgFile) SPgFileList; } \ } while (0) -#define TDB_VARIANT_LEN -1 +#define TDB_VARIANT_LEN (int32_t) - 1 +// page payload format +// + + [key] + [value] #define TDB_DECODE_PAYLOAD(pPayload, keyLen, pKey, valLen, pVal) \ do { \ if ((keyLen) == TDB_VARIANT_LEN) { \ - /* TODO */ \ + /* TODO: decode the keyLen */ \ } \ if ((valLen) == TDB_VARIANT_LEN) { \ - /* TODO */ \ + /* TODO: decode the valLen */ \ } \ /* TODO */ \ } while (0)