more TDB
This commit is contained in:
parent
f54e38b3f2
commit
665eb2e20a
|
@ -22,11 +22,11 @@ struct SBTree {
|
||||||
SPager * pPager;
|
SPager * pPager;
|
||||||
FKeyComparator kcmpr;
|
FKeyComparator kcmpr;
|
||||||
u8 fanout;
|
u8 fanout;
|
||||||
|
int pageSize;
|
||||||
int maxLocal;
|
int maxLocal;
|
||||||
int minLocal;
|
int minLocal;
|
||||||
int maxLeaf;
|
int maxLeaf;
|
||||||
int minLeaf;
|
int minLeaf;
|
||||||
int nPayload;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SPgHdr {
|
typedef struct SPgHdr {
|
||||||
|
@ -85,6 +85,16 @@ int tdbBtreeOpen(SPgno rtPgno, int keyLen, int valLen, SPager *pPager, FKeyCompa
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
// TODO: pBt->fanout = 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;
|
*ppBt = pBt;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -277,11 +287,11 @@ static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2
|
||||||
return cret;
|
return cret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tdbBtreeZeroPage(SPageHandle *pPage, int flags) {
|
static void tdbBtreeZeroPage(SMemPage *pPage, int flags) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tdbBtreeInitPage(SPageHandle *pPage) {
|
static int tdbBtreeInitPage(SMemPage *pPage) {
|
||||||
// TODO
|
// TODO
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -48,7 +48,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv)
|
||||||
|
|
||||||
pEnv->jfd = -1;
|
pEnv->jfd = -1;
|
||||||
|
|
||||||
ret = tdbPCacheOpen(pageSize, cacheSize, sizeof(SPageHandle), &(pEnv->pCache));
|
ret = tdbPCacheOpen(pageSize, cacheSize, sizeof(SMemPage), &(pEnv->pCache));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,3 +268,5 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
|
||||||
|
|
||||||
return 0;
|
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->jfd = -1;
|
||||||
|
pPager->pageSize = tdbPCacheGetPageSize(pCache);
|
||||||
|
|
||||||
*ppPager = pPager;
|
*ppPager = pPager;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -239,3 +240,5 @@ static int tdbPagerReadPage(SPager *pPager, SPage *pPage) {
|
||||||
}
|
}
|
||||||
return 0;
|
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);
|
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage);
|
||||||
void tdbPCacheFetchFinish(SPCache *pCache, SPage *pPage);
|
void tdbPCacheFetchFinish(SPCache *pCache, SPage *pPage);
|
||||||
void tdbPCacheRelease(SPage *pPage);
|
void tdbPCacheRelease(SPage *pPage);
|
||||||
|
int tdbPCacheGetPageSize(SPCache *pCache);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,17 +21,13 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct __attribute__((__packed__)) {
|
typedef struct __attribute__((__packed__)) {
|
||||||
u8 flags;
|
u16 flags;
|
||||||
u16 nCells;
|
u16 nCells;
|
||||||
u16 cellCont;
|
u16 cellCont;
|
||||||
u16 freeCell;
|
u16 freeCell;
|
||||||
u16 nFree;
|
u16 nFree;
|
||||||
} SPageHdr;
|
} SPageHdr;
|
||||||
|
|
||||||
typedef struct __attribute__((__packed__)) {
|
|
||||||
SPgno nPgno;
|
|
||||||
} SOfPageHdr;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void * pData;
|
void * pData;
|
||||||
SPageHdr *pPageHdr;
|
SPageHdr *pPageHdr;
|
||||||
|
@ -41,7 +37,7 @@ typedef struct {
|
||||||
int vLen;
|
int vLen;
|
||||||
int maxLocal;
|
int maxLocal;
|
||||||
int minLocal;
|
int minLocal;
|
||||||
} SPageHandle;
|
} SMemPage;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ int tdbPagerWrite(SPager *pFile, SPage *pPage);
|
||||||
int tdbPagerAllocPage(SPager *pFile, SPage **ppPage, SPgno *ppgno);
|
int tdbPagerAllocPage(SPager *pFile, SPage **ppPage, SPgno *ppgno);
|
||||||
int tdbPagerBegin(SPager *pFile);
|
int tdbPagerBegin(SPager *pFile);
|
||||||
int tdbPagerCommit(SPager *pFile);
|
int tdbPagerCommit(SPager *pFile);
|
||||||
|
int tdbPagerGetPageSize(SPager *pPager);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue