From 5eb04e9f2b00a37fd22f98f7fb656c45bfb24da1 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 11 Mar 2022 08:21:48 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbPage.c | 3 +++ source/libs/tdb/src/inc/tdbPage.h | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/source/libs/tdb/src/db/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c index 67592002d5..9072b2d146 100644 --- a/source/libs/tdb/src/db/tdbPage.c +++ b/source/libs/tdb/src/db/tdbPage.c @@ -39,8 +39,10 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t) pPage->pageSize = pageSize; if (pageSize < 65536) { pPage->szOffset = 2; + pPage->szPageHdr = sizeof(SPageHdr); } else { pPage->szOffset = 3; + pPage->szPageHdr = sizeof(SLPageHdr); } TDB_INIT_PAGE_LOCK(pPage); @@ -97,6 +99,7 @@ static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) { } else { } + *ppCell = pCell; return 0; } diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index be9e7d205a..ab0d21f0d0 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -22,7 +22,7 @@ extern "C" { typedef u8 SCell; -// Page header +// Page header (pageSize < 65536 (64K)) typedef struct __attribute__((__packed__)) { u16 flags; u16 nCells; @@ -49,6 +49,7 @@ struct SPage { u8 *pData; int pageSize; u8 szOffset; + u8 szPageHdr; pthread_spinlock_t lock; // Fields below used by pager and am SPageHdr *pPageHdr; @@ -69,6 +70,11 @@ struct SPage { }; // Macros +/* For small page */ + +/* For large page */ + +/* For page */ #define TDB_PAGE_CELL_OFFSET_AT(pPage, idx) \ (((pPage)->szOffset == 2) ? ((u16 *)((pPage)->aCellIdx))[idx] \ : ((pPage)->aCellIdx[idx * 3] * 65536 + *(u16 *)((pPage)->aCellIdx + idx * 3 + 1)))