提交 3bda636b 编写于 作者: H Hongze Cheng

more TDB

上级 1cee13b0
...@@ -343,25 +343,28 @@ static int tdbBtreeOpenImpl(SBTree *pBt) { ...@@ -343,25 +343,28 @@ static int tdbBtreeOpenImpl(SBTree *pBt) {
return 0; return 0;
} }
static int tdbBtreeZeroPage(SPage *pPage, void *arg) { static int tdbBtreeInitPage(SPage *pPage, void *arg) {
u16 flags;
SBTree *pBt; SBTree *pBt;
u16 flags;
flags = ((SBtreeZeroPageArg *)arg)->flags; pBt = (SBTree *)arg;
pBt = ((SBtreeZeroPageArg *)arg)->pBt;
flags = TDB_PAGE_FLAGS(pPage);
if (TDB_BTREE_PAGE_IS_LEAF(flags)) {
pPage->szAmHdr = 0;
} else {
pPage->szAmHdr = sizeof(SBtPageHdr);
}
pPage->pPageHdr = pPage->pData; pPage->pPageHdr = pPage->pData;
pPage->pCellIdx = (u8 *)(&(pPage->pPageHdr[1])); pPage->pAmHdr = pPage->pPageHdr + pPage->szPageHdr;
pPage->pCellIdx = pPage->pAmHdr + pPage->szAmHdr;
// Init the page header pPage->pFreeStart = pPage->pCellIdx + pPage->szOffset * TDB_PAGE_NCELLS(pPage);
TDB_PAGE_FLAGS_SET(pPage, flags); pPage->pFreeEnd = pPage->pData + TDB_PAGE_CCELLS(pPage);
TDB_PAGE_NCELLS_SET(pPage, 0); pPage->pPageFtr = (SPageFtr *)(pPage->pData + pPage->pageSize - sizeof(SPageFtr));
TDB_PAGE_CCELLS_SET(pPage, pBt->pageSize);
TDB_PAGE_FCELL_SET(pPage, 0);
TDB_PAGE_NFREE_SET(pPage, 0);
TDB_BTREE_ASSERT_FLAG(flags); TDB_BTREE_ASSERT_FLAG(flags);
// Init other fields
if (TDB_BTREE_PAGE_IS_LEAF(flags)) { if (TDB_BTREE_PAGE_IS_LEAF(flags)) {
pPage->kLen = pBt->keyLen; pPage->kLen = pBt->keyLen;
pPage->vLen = pBt->valLen; pPage->vLen = pBt->valLen;
...@@ -377,34 +380,28 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { ...@@ -377,34 +380,28 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) {
return 0; return 0;
} }
static int tdbBtreeInitPage(SPage *pPage, void *arg) { static int tdbBtreeZeroPage(SPage *pPage, void *arg) {
SBTree *pBt;
u16 flags; u16 flags;
SBTree *pBt;
pBt = (SBTree *)arg; flags = ((SBtreeZeroPageArg *)arg)->flags;
pBt = ((SBtreeZeroPageArg *)arg)->pBt;
flags = TDB_PAGE_FLAGS(pPage);
pPage->pPageHdr = pPage->pData; pPage->pPageHdr = pPage->pData;
pPage->pCellIdx = pPage->pPageHdr + pPage->szPageHdr;
TDB_BTREE_ASSERT_FLAG(flags); // Init the page header
TDB_PAGE_FLAGS_SET(pPage, flags);
TDB_PAGE_NCELLS_SET(pPage, 0);
TDB_PAGE_CCELLS_SET(pPage, pBt->pageSize - sizeof(SPageFtr));
TDB_PAGE_FCELL_SET(pPage, 0);
TDB_PAGE_NFREE_SET(pPage, 0);
// Init other fields tdbBtreeInitPage(pPage, (void *)pBt);
if (TDB_BTREE_PAGE_IS_LEAF(flags)) {
pPage->kLen = pBt->keyLen;
pPage->vLen = pBt->valLen;
pPage->maxLocal = pBt->maxLeaf;
pPage->minLocal = pBt->minLeaf;
} else {
pPage->kLen = pBt->keyLen;
pPage->vLen = sizeof(SPgno);
pPage->maxLocal = pBt->maxLocal;
pPage->minLocal = pBt->minLocal;
}
return 0; return 0;
} }
#ifndef TDB_BTREE_BALANCE #ifndef TDB_BTREE_BALANCE
typedef struct { typedef struct {
SBTree *pBt; SBTree *pBt;
......
...@@ -46,13 +46,14 @@ typedef struct __attribute__((__packed__)) { ...@@ -46,13 +46,14 @@ typedef struct __attribute__((__packed__)) {
} SPageFtr; } SPageFtr;
struct SPage { struct SPage {
pthread_spinlock_t lock;
u8 *pData; u8 *pData;
int pageSize; int pageSize;
u8 szOffset; u8 szOffset;
u8 szPageHdr; u8 szPageHdr;
u8 szFreeCell; u8 szFreeCell;
pthread_spinlock_t lock;
// Fields below used by pager and am // Fields below used by pager and am
u8 szAmHdr;
u8 *pPageHdr; u8 *pPageHdr;
u8 *pAmHdr; u8 *pAmHdr;
u8 *pCellIdx; u8 *pCellIdx;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册