提交 d907e448 编写于 作者: H Hongze Cheng

refact TDB

上级 71ad7db1
...@@ -19,7 +19,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) ...@@ -19,7 +19,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv)
STEnv *pEnv; STEnv *pEnv;
int dsize; int dsize;
int zsize; int zsize;
u8 * pPtr; u8 *pPtr;
int ret; int ret;
*ppEnv = NULL; *ppEnv = NULL;
...@@ -48,7 +48,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) ...@@ -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, 0, &(pEnv->pCache)); ret = tdbPCacheOpen(pageSize, cacheSize, &(pEnv->pCache));
if (ret < 0) { if (ret < 0) {
return -1; return -1;
} }
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
struct SPCache { struct SPCache {
int pageSize; int pageSize;
int cacheSize; int cacheSize;
int extraSize;
pthread_mutex_t mutex; pthread_mutex_t mutex;
int nFree; int nFree;
SPage *pFree; SPage *pFree;
...@@ -47,7 +46,7 @@ static void tdbPCacheRemovePageFromHash(SPage *pPage); ...@@ -47,7 +46,7 @@ static void tdbPCacheRemovePageFromHash(SPage *pPage);
static void tdbPCacheAddPageToHash(SPage *pPage); static void tdbPCacheAddPageToHash(SPage *pPage);
static void tdbPCacheUnpinPage(SPage *pPage); static void tdbPCacheUnpinPage(SPage *pPage);
int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache) { int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
SPCache *pCache; SPCache *pCache;
void *pPtr; void *pPtr;
SPage *pPgHdr; SPage *pPgHdr;
...@@ -59,7 +58,6 @@ int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache) ...@@ -59,7 +58,6 @@ int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache)
pCache->pageSize = pageSize; pCache->pageSize = pageSize;
pCache->cacheSize = cacheSize; pCache->cacheSize = cacheSize;
pCache->extraSize = extraSize;
if (tdbPCacheOpenImpl(pCache) < 0) { if (tdbPCacheOpenImpl(pCache) < 0) {
free(pCache); free(pCache);
...@@ -244,7 +242,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { ...@@ -244,7 +242,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
pCache->nFree = 0; pCache->nFree = 0;
pCache->pFree = NULL; pCache->pFree = NULL;
for (int i = 0; i < pCache->cacheSize; i++) { for (int i = 0; i < pCache->cacheSize; i++) {
tsize = pCache->pageSize + sizeof(SPage) + pCache->extraSize; tsize = pCache->pageSize + sizeof(SPage);
pPtr = (u8 *)calloc(1, tsize); pPtr = (u8 *)calloc(1, tsize);
if (pPtr == NULL) { if (pPtr == NULL) {
// TODO // TODO
......
...@@ -33,7 +33,7 @@ extern "C" { ...@@ -33,7 +33,7 @@ extern "C" {
SPage *pDirtyNext; \ SPage *pDirtyNext; \
SPager *pPager; SPager *pPager;
int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache); int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache);
int tdbPCacheClose(SPCache *pCache); int tdbPCacheClose(SPCache *pCache);
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage); SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage);
void tdbPCacheRelease(SPage *pPage); void tdbPCacheRelease(SPage *pPage);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册