diff --git a/source/libs/tdb/src/db/btree.c b/source/libs/tdb/src/db/btree.c index 400d91514d..3174bfa0b9 100644 --- a/source/libs/tdb/src/db/btree.c +++ b/source/libs/tdb/src/db/btree.c @@ -26,6 +26,14 @@ typedef struct { pgsz_t offset; } SBtIdx; +// Btree page header definition +typedef struct { + uint8_t flags; + uint16_t ncells; + pgsz_t pldOffset; // payload offset + /* TODO */ +} SBtPgHdr; + static int btreeCreate(SBTree **pBt); static int btreeDestroy(SBTree *pBt); static int btreeCursorMoveToChild(SBtCursor *pBtCur, pgno_t pgno); @@ -69,9 +77,10 @@ int btreeCursorClose(SBtCursor *pBtCur) { } int btreeCursorMoveTo(SBtCursor *pBtCur, int kLen, const void *pKey) { - SPage *pPage; - pgno_t childPgno; - int idx; + SPage * pPage; + SBtPgHdr *pBtPgHdr; + pgno_t childPgno; + int idx; // 1. Move the cursor to the root page diff --git a/source/libs/tdb/src/inc/pgfile.h b/source/libs/tdb/src/inc/pgfile.h index f2dba417f6..5a42199c53 100644 --- a/source/libs/tdb/src/inc/pgfile.h +++ b/source/libs/tdb/src/inc/pgfile.h @@ -20,6 +20,18 @@ extern "C" { #endif +typedef struct __attribute__((__packed__)) { + char hdrInfo[16]; // info string + pgsz_t szPage; // page size of current file + int32_t cno; // commit number counter + pgno_t freePgno; // freelist page number + uint8_t resv[100]; // reserved space +} SPgFileHdr; + +#define TDB_PG_FILE_HDR_SIZE 128 + +TD_STATIC_ASSERT(sizeof(SPgFileHdr) == TDB_PG_FILE_HDR_SIZE, "Page file header size if not 128"); + struct SPgFile { char * fname; // backend file name uint8_t fileid[TDB_FILE_ID_LEN]; // file id diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 5b95e16203..2f9cd5af4c 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -93,12 +93,16 @@ typedef TD_DLIST(SPgFile) SPgFileList; } \ } while (0) -#include "btree.h" -#include "pgcache.h" -#include "pgfile.h" -#include "tdbEnv.h" #include "tdbUtil.h" +#include "btree.h" + +#include "pgcache.h" + +#include "pgfile.h" + +#include "tdbEnv.h" + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index ccd3d0b793..2eeda286ec 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -20,6 +20,12 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 201112L +#define TD_STATIC_ASSERT(op, info) static_assert(op, info) +#else +#define TD_STATIC_ASSERT(op, info) +#endif + #define TDB_ROUND8(x) (((x) + 7) & ~7) int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique);