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

more TDB

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