提交 665eb2e2 编写于 作者: H Hongze Cheng

more TDB

上级 f54e38b3
......@@ -22,11 +22,11 @@ struct SBTree {
SPager * pPager;
FKeyComparator kcmpr;
u8 fanout;
int pageSize;
int maxLocal;
int minLocal;
int maxLeaf;
int minLeaf;
int nPayload;
};
typedef struct SPgHdr {
......@@ -85,6 +85,16 @@ int tdbBtreeOpen(SPgno rtPgno, int keyLen, int valLen, SPager *pPager, FKeyCompa
ASSERT(0);
// TODO: pBt->fanout = 0;
}
// pBt->pageSize
pBt->pageSize = tdbPagerGetPageSize(pPager);
// pBt->maxLocal
pBt->maxLocal = (pBt->pageSize - sizeof(SPageHdr)) / pBt->fanout;
// pBt->minLocal
pBt->minLocal = (pBt->pageSize - sizeof(SPageHdr)) / pBt->fanout / 2;
// pBt->maxLeaf
pBt->maxLeaf = pBt->pageSize - sizeof(SPageHdr);
// pBt->minLeaf
pBt->minLeaf = pBt->minLocal;
*ppBt = pBt;
return 0;
......@@ -277,11 +287,11 @@ static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2
return cret;
}
static void tdbBtreeZeroPage(SPageHandle *pPage, int flags) {
static void tdbBtreeZeroPage(SMemPage *pPage, int flags) {
// TODO
}
static int tdbBtreeInitPage(SPageHandle *pPage) {
static int tdbBtreeInitPage(SMemPage *pPage) {
// TODO
return 0;
}
\ No newline at end of file
......@@ -48,7 +48,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv)
pEnv->jfd = -1;
ret = tdbPCacheOpen(pageSize, cacheSize, sizeof(SPageHandle), &(pEnv->pCache));
ret = tdbPCacheOpen(pageSize, cacheSize, sizeof(SMemPage), &(pEnv->pCache));
if (ret < 0) {
return -1;
}
......
......@@ -267,4 +267,6 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
pCache->lru.pLruPrev = &(pCache->lru);
return 0;
}
\ No newline at end of file
}
int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; }
\ No newline at end of file
......@@ -87,6 +87,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
}
pPager->jfd = -1;
pPager->pageSize = tdbPCacheGetPageSize(pCache);
*ppPager = pPager;
return 0;
......@@ -238,4 +239,6 @@ static int tdbPagerReadPage(SPager *pPager, SPage *pPage) {
return -1;
}
return 0;
}
\ No newline at end of file
}
int tdbPagerGetPageSize(SPager *pPager) { return pPager->pageSize; }
\ No newline at end of file
......@@ -45,6 +45,7 @@ int tdbPCacheClose(SPCache *pCache);
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage);
void tdbPCacheFetchFinish(SPCache *pCache, SPage *pPage);
void tdbPCacheRelease(SPage *pPage);
int tdbPCacheGetPageSize(SPCache *pCache);
#ifdef __cplusplus
}
......
......@@ -21,17 +21,13 @@ extern "C" {
#endif
typedef struct __attribute__((__packed__)) {
u8 flags;
u16 flags;
u16 nCells;
u16 cellCont;
u16 freeCell;
u16 nFree;
} SPageHdr;
typedef struct __attribute__((__packed__)) {
SPgno nPgno;
} SOfPageHdr;
typedef struct {
void * pData;
SPageHdr *pPageHdr;
......@@ -41,7 +37,7 @@ typedef struct {
int vLen;
int maxLocal;
int minLocal;
} SPageHandle;
} SMemPage;
#ifdef __cplusplus
}
......
......@@ -28,6 +28,7 @@ int tdbPagerWrite(SPager *pFile, SPage *pPage);
int tdbPagerAllocPage(SPager *pFile, SPage **ppPage, SPgno *ppgno);
int tdbPagerBegin(SPager *pFile);
int tdbPagerCommit(SPager *pFile);
int tdbPagerGetPageSize(SPager *pPager);
#ifdef __cplusplus
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册