more TDB
This commit is contained in:
parent
03eaa648d6
commit
4e8f8445de
|
@ -39,9 +39,16 @@ struct SBTree {
|
||||||
u8 *pTmp;
|
u8 *pTmp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define TDB_BTREE_PAGE_COMMON_HDR u8 flags;
|
||||||
|
|
||||||
typedef struct __attribute__((__packed__)) {
|
typedef struct __attribute__((__packed__)) {
|
||||||
SPgno rChild;
|
TDB_BTREE_PAGE_COMMON_HDR
|
||||||
} SBtPageHdr;
|
} SLeafHdr;
|
||||||
|
|
||||||
|
typedef struct __attribute__((__packed__)) {
|
||||||
|
TDB_BTREE_PAGE_COMMON_HDR;
|
||||||
|
SPgno pgno; // right-most child
|
||||||
|
} SIntHdr;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u16 flags;
|
u16 flags;
|
||||||
|
@ -220,7 +227,7 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p
|
||||||
|
|
||||||
if (TDB_PAGE_TOTAL_CELLS(pCur->pPage) == 0) {
|
if (TDB_PAGE_TOTAL_CELLS(pCur->pPage) == 0) {
|
||||||
// Current page is empty
|
// Current page is empty
|
||||||
ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pCur->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF));
|
// ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pCur->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +272,7 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move downward or break
|
// Move downward or break
|
||||||
u16 flags = TDB_PAGE_FLAGS(pPage);
|
u16 flags = 0; // TODO: TDB_PAGE_FLAGS(pPage);
|
||||||
u8 leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
u8 leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
||||||
if (leaf) {
|
if (leaf) {
|
||||||
pCur->idx = midx;
|
pCur->idx = midx;
|
||||||
|
@ -279,7 +286,7 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p
|
||||||
if (midx == nCells - 1) {
|
if (midx == nCells - 1) {
|
||||||
/* Move to right-most child */
|
/* Move to right-most child */
|
||||||
pCur->idx = midx + 1;
|
pCur->idx = midx + 1;
|
||||||
tdbBtCursorMoveToChild(pCur, ((SBtPageHdr *)(pPage->pAmHdr))->rChild);
|
// tdbBtCursorMoveToChild(pCur, ((SBtPageHdr *)(pPage->pAmHdr))->rChild);
|
||||||
} else {
|
} else {
|
||||||
// TODO: reset cd as uninitialized
|
// TODO: reset cd as uninitialized
|
||||||
pCur->idx = midx + 1;
|
pCur->idx = midx + 1;
|
||||||
|
@ -388,12 +395,12 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
|
||||||
// TODO: here has problem
|
// TODO: here has problem
|
||||||
flags = TDB_PAGE_FLAGS(pPage);
|
flags = 0; // TODO: TDB_PAGE_FLAGS(pPage);
|
||||||
isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
||||||
if (isLeaf) {
|
if (isLeaf) {
|
||||||
szAmHdr = 0;
|
szAmHdr = sizeof(SLeafHdr);
|
||||||
} else {
|
} else {
|
||||||
szAmHdr = sizeof(SBtPageHdr);
|
szAmHdr = sizeof(SIntHdr);
|
||||||
}
|
}
|
||||||
pPage->xCellSize = NULL; // TODO
|
pPage->xCellSize = NULL; // TODO
|
||||||
|
|
||||||
|
@ -427,14 +434,14 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) {
|
||||||
isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
||||||
|
|
||||||
if (isLeaf) {
|
if (isLeaf) {
|
||||||
szAmHdr = 0;
|
szAmHdr = sizeof(SLeafHdr);
|
||||||
} else {
|
} else {
|
||||||
szAmHdr = sizeof(SBtPageHdr);
|
szAmHdr = sizeof(SIntHdr);
|
||||||
}
|
}
|
||||||
pPage->xCellSize = NULL; // TODO
|
pPage->xCellSize = NULL; // TODO
|
||||||
|
|
||||||
tdbPageZero(pPage, szAmHdr);
|
tdbPageZero(pPage, szAmHdr);
|
||||||
TDB_PAGE_FLAGS_SET(pPage, flags);
|
// TDB_PAGE_FLAGS_SET(pPage, flags);
|
||||||
|
|
||||||
if (isLeaf) {
|
if (isLeaf) {
|
||||||
pPage->kLen = pBt->keyLen;
|
pPage->kLen = pBt->keyLen;
|
||||||
|
@ -522,7 +529,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
((SBtPageHdr *)pRoot->pAmHdr)[0].rChild = pgnoChild;
|
// TODO: ((SBtPageHdr *)pRoot->pAmHdr)[0].rChild = pgnoChild;
|
||||||
|
|
||||||
*ppChild = pChild;
|
*ppChild = pChild;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -566,7 +573,7 @@ static int tdbBtreeBalanceStep1(SBtreeBalanceHelper *pBlh) {
|
||||||
i = pBlh->nOld - 1;
|
i = pBlh->nOld - 1;
|
||||||
|
|
||||||
if (idxStart + i == nCells) {
|
if (idxStart + i == nCells) {
|
||||||
pgno = ((SBtPageHdr *)(pParent->pAmHdr))[0].rChild;
|
// pgno = ((SBtPageHdr *)(pParent->pAmHdr))[0].rChild;
|
||||||
} else {
|
} else {
|
||||||
pCell = tdbPageGetCell(pParent, idxStart + i);
|
pCell = tdbPageGetCell(pParent, idxStart + i);
|
||||||
// TODO: no need to decode the payload part, and even the kLen, vLen part
|
// TODO: no need to decode the payload part, and even the kLen, vLen part
|
||||||
|
@ -676,7 +683,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
|
||||||
int ret;
|
int ret;
|
||||||
SBtreeBalanceHelper blh;
|
SBtreeBalanceHelper blh;
|
||||||
|
|
||||||
ASSERT(!TDB_BTREE_PAGE_IS_LEAF(TDB_PAGE_FLAGS(pParent)));
|
// ASSERT(!TDB_BTREE_PGE_IS_LEAF(TDB_PAGE_FLAGS(pParent)));
|
||||||
|
|
||||||
blh.pBt = pBt;
|
blh.pBt = pBt;
|
||||||
blh.pParent = pParent;
|
blh.pParent = pParent;
|
||||||
|
@ -748,7 +755,7 @@ static int tdbBtreeBalance(SBtCursor *pCur) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
iPage = pCur->iPage;
|
iPage = pCur->iPage;
|
||||||
pPage = pCur->pPage;
|
pPage = pCur->pPage;
|
||||||
flags = TDB_PAGE_FLAGS(pPage);
|
flags = 0; // TODO: TDB_PAGE_FLAGS(pPage);
|
||||||
leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
||||||
root = TDB_BTREE_PAGE_IS_ROOT(flags);
|
root = TDB_BTREE_PAGE_IS_ROOT(flags);
|
||||||
|
|
||||||
|
@ -842,7 +849,7 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
|
||||||
|
|
||||||
nPayload = 0;
|
nPayload = 0;
|
||||||
nHeader = 0;
|
nHeader = 0;
|
||||||
flags = TDB_PAGE_FLAGS(pPage);
|
flags = 0; // TODO: TDB_PAGE_FLAGS(pPage);
|
||||||
leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
||||||
|
|
||||||
// 1. Encode Header part
|
// 1. Encode Header part
|
||||||
|
@ -911,7 +918,7 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
nHeader = 0;
|
nHeader = 0;
|
||||||
flags = TDB_PAGE_FLAGS(pPage);
|
flags = 0; // TODO: TDB_PAGE_FLAGS(pPage);
|
||||||
leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
||||||
|
|
||||||
// Clear the state of decoder
|
// Clear the state of decoder
|
||||||
|
|
|
@ -27,9 +27,11 @@ typedef struct {
|
||||||
int szOffset;
|
int szOffset;
|
||||||
int szPageHdr;
|
int szPageHdr;
|
||||||
int szFreeCell;
|
int szFreeCell;
|
||||||
|
#if 0
|
||||||
// flags
|
// flags
|
||||||
u16 (*getFlags)(SPage *);
|
u16 (*getFlags)(SPage *);
|
||||||
void (*setFlags)(SPage *, u16);
|
void (*setFlags)(SPage *, u16);
|
||||||
|
#endif
|
||||||
// cell number
|
// cell number
|
||||||
int (*getCellNum)(SPage *);
|
int (*getCellNum)(SPage *);
|
||||||
void (*setCellNum)(SPage *, int);
|
void (*setCellNum)(SPage *, int);
|
||||||
|
@ -79,9 +81,11 @@ struct SPage {
|
||||||
TDB_PCACHE_PAGE
|
TDB_PCACHE_PAGE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* For page */
|
/* For page */
|
||||||
#define TDB_PAGE_FLAGS(pPage) (*(pPage)->pPageMethods->getFlags)(pPage)
|
#define TDB_PAGE_FLAGS(pPage) (*(pPage)->pPageMethods->getFlags)(pPage)
|
||||||
#define TDB_PAGE_FLAGS_SET(pPage, FLAGS) (*(pPage)->pPageMethods->setFlags)(pPage, FLAGS)
|
#define TDB_PAGE_FLAGS_SET(pPage, FLAGS) (*(pPage)->pPageMethods->setFlags)(pPage, FLAGS)
|
||||||
|
#endif
|
||||||
|
|
||||||
// For page lock
|
// For page lock
|
||||||
#define P_LOCK_SUCC 0
|
#define P_LOCK_SUCC 0
|
||||||
|
|
|
@ -399,9 +399,11 @@ typedef struct __attribute__((__packed__)) {
|
||||||
u16 nxOffset;
|
u16 nxOffset;
|
||||||
} SFreeCell;
|
} SFreeCell;
|
||||||
|
|
||||||
|
#if 0
|
||||||
// flags
|
// flags
|
||||||
static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].flags; }
|
static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].flags; }
|
||||||
static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdr *)(pPage->pPageHdr))[0].flags = flags; }
|
static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdr *)(pPage->pPageHdr))[0].flags = flags; }
|
||||||
|
#endif
|
||||||
|
|
||||||
// cellNum
|
// cellNum
|
||||||
static inline int getPageCellNum(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].cellNum; }
|
static inline int getPageCellNum(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].cellNum; }
|
||||||
|
@ -456,11 +458,13 @@ static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SPageMethods pageMethods = {
|
SPageMethods pageMethods = {
|
||||||
2, // szOffset
|
2, // szOffset
|
||||||
sizeof(SPageHdr), // szPageHdr
|
sizeof(SPageHdr), // szPageHdr
|
||||||
sizeof(SFreeCell), // szFreeCell
|
sizeof(SFreeCell), // szFreeCell
|
||||||
|
#if 0
|
||||||
getPageFlags, // getPageFlags
|
getPageFlags, // getPageFlags
|
||||||
setPageFlags, // setFlagsp
|
setPageFlags, // setFlagsp
|
||||||
|
#endif
|
||||||
getPageCellNum, // getCellNum
|
getPageCellNum, // getCellNum
|
||||||
setPageCellNum, // setCellNum
|
setPageCellNum, // setCellNum
|
||||||
getPageCellBody, // getCellBody
|
getPageCellBody, // getCellBody
|
||||||
|
|
|
@ -28,9 +28,11 @@ typedef struct __attribute__((__packed__)) {
|
||||||
u8 nxOffset[3];
|
u8 nxOffset[3];
|
||||||
} SFreeCellL;
|
} SFreeCellL;
|
||||||
|
|
||||||
|
#if 0
|
||||||
// flags
|
// flags
|
||||||
static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdrL *)(pPage->pPageHdr))[0].flags; }
|
static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdrL *)(pPage->pPageHdr))[0].flags; }
|
||||||
static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdrL *)(pPage->pPageHdr))[0].flags = flags; }
|
static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdrL *)(pPage->pPageHdr))[0].flags = flags; }
|
||||||
|
#endif
|
||||||
|
|
||||||
// cellNum
|
// cellNum
|
||||||
static inline int getPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); }
|
static inline int getPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); }
|
||||||
|
@ -80,11 +82,13 @@ static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SPageMethods pageLargeMethods = {
|
SPageMethods pageLargeMethods = {
|
||||||
3, // szOffset
|
3, // szOffset
|
||||||
sizeof(SPageHdrL), // szPageHdr
|
sizeof(SPageHdrL), // szPageHdr
|
||||||
sizeof(SFreeCellL), // szFreeCell
|
sizeof(SFreeCellL), // szFreeCell
|
||||||
|
#if 0
|
||||||
getPageFlags, // getPageFlags
|
getPageFlags, // getPageFlags
|
||||||
setPageFlags, // setFlagsp
|
setPageFlags, // setFlagsp
|
||||||
|
#endif
|
||||||
getPageCellNum, // getCellNum
|
getPageCellNum, // getCellNum
|
||||||
setPageCellNum, // setCellNum
|
setPageCellNum, // setCellNum
|
||||||
getPageCellBody, // getCellBody
|
getPageCellBody, // getCellBody
|
||||||
|
|
Loading…
Reference in New Issue