提交 4ecbe41d 编写于 作者: H Hongze Cheng

adjust some code

上级 110703f9
......@@ -101,7 +101,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S
// pBt->kcmpr
pBt->kcmpr = kcmpr ? kcmpr : tdbDefaultKeyCmprFn;
// pBt->pageSize
pBt->pageSize = tdbPagerGetPageSize(pPager);
pBt->pageSize = pPager->pageSize;
// pBt->maxLocal
pBt->maxLocal = tdbPageCapacity(pBt->pageSize, sizeof(SIntHdr)) / 4;
// pBt->minLocal: Should not be allowed smaller than 15, which is [nPayload][nKey][nData]
......
......@@ -19,6 +19,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv) {
TENV *pEnv;
int dsize;
int zsize;
int tsize;
u8 *pPtr;
int ret;
......@@ -53,6 +54,14 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv) {
return -1;
}
pEnv->nHash = 8;
tsize = sizeof(SPager *) * pEnv->nHash;
pEnv->pagerHash = TDB_REALLOC(pEnv->pagerHash, tsize);
if (pEnv->pagerHash == NULL) {
return -1;
}
memset(pEnv->pagerHash, 0, tsize);
mkdir(rootDir, 0755);
*ppEnv = pEnv;
......@@ -65,21 +74,31 @@ int tdbEnvClose(TENV *pEnv) {
}
int tdbBegin(TENV *pEnv) {
// TODO
ASSERT(0);
return 0;
}
int tdbCommit(TENV *pEnv) {
// TODO
SPager *pPager;
pPager = pEnv->pagerList;
while (pPager) {
tdbPagerCommit(pPager);
}
return 0;
}
int tdbRollback(TENV *pEnv) {
// TODO
ASSERT(0);
return 0;
}
SPager *tdbEnvGetPager(TENV *pEnv, const char *fname) {
// TODO
return NULL;
}
static void tdbEnvAddPager(TENV *pEnv, SPager *pPager) {
}
\ No newline at end of file
......@@ -15,20 +15,6 @@
#include "tdbInt.h"
struct SPager {
char *dbFileName;
char *jFileName;
int pageSize;
uint8_t fid[TDB_FILE_ID_LEN];
tdb_fd_t fd;
tdb_fd_t jfd;
SPCache *pCache;
SPgno dbFileSize;
SPgno dbOrigSize;
SPage *pDirty;
u8 inTran;
};
typedef struct __attribute__((__packed__)) {
u8 hdrString[16];
u16 pageSize;
......@@ -229,8 +215,6 @@ static int tdbPagerReadPage(SPager *pPager, SPage *pPage) {
return 0;
}
int tdbPagerGetPageSize(SPager *pPager) { return pPager->pageSize; }
int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg) {
SPage *pPage;
SPgid pgid;
......
......@@ -20,11 +20,16 @@
extern "C" {
#endif
#define TDB_PAGER_ENV_FIELDS \
SPager *pNext; \
SPager *pHashNext;
typedef struct STEnv {
char *rootDir;
char *jfname;
int jfd;
SPCache *pCache;
SPager *pagerList;
int nHash;
SPager **pagerHash;
} TENV;
......
......@@ -20,13 +20,26 @@
extern "C" {
#endif
struct SPager {
char *dbFileName;
char *jFileName;
int pageSize;
uint8_t fid[TDB_FILE_ID_LEN];
tdb_fd_t fd;
tdb_fd_t jfd;
SPCache *pCache;
SPgno dbFileSize;
SPgno dbOrigSize;
SPage *pDirty;
u8 inTran;
};
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager);
int tdbPagerClose(SPager *pPager);
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate);
int tdbPagerWrite(SPager *pPager, SPage *pPage);
int tdbPagerBegin(SPager *pPager);
int tdbPagerCommit(SPager *pPager);
int tdbPagerGetPageSize(SPager *pPager);
int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg);
int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg);
void tdbPagerReturnPage(SPager *pPager, SPage *pPage);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册