more TDB
This commit is contained in:
parent
f54e38b3f2
commit
665eb2e20a
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; }
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
int tdbPagerGetPageSize(SPager *pPager) { return pPager->pageSize; }
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue