提交 1bcb1098 编写于 作者: H Hongze Cheng

more TDB

上级 f6f6a691
......@@ -72,7 +72,7 @@ int tdbEnvOpen(TENV *pEnv) {
pgSize = pEnv->pgSize;
npage = pEnv->cacheSize / pEnv->pgSize;
ret = pgCacheOpen(&pPgCache, pgSize, npage, pEnv);
ret = pgCacheOpen(&pPgCache, pEnv);
if (ret != 0) {
goto _err;
}
......
......@@ -26,42 +26,48 @@ struct SPage {
typedef TD_DLIST(SPage) SPgList;
struct SPgCache {
TENV * pEnv; // TENV containing this page cache
SRWLatch mutex;
pgsz_t pgsize;
int32_t npage;
SPage * pages;
SPgList freeList;
SPgList lru;
TENV * pEnv; // TENV containing this page cache
pgsz_t pgsize;
int32_t npage;
SPage * pages;
SPgList freeList;
SPgList lru;
struct {
int32_t nbucket;
SPgList *buckets;
} pght; // page hash table
};
static void pgCachePinPage(SPage *pPage);
static void pgCacheUnpinPage(SPage *pPage);
int pgCacheOpen(SPgCache **ppPgCache, pgsz_t pgSize, int32_t npage, TENV *pEnv) {
int pgCacheOpen(SPgCache **ppPgCache, TENV *pEnv) {
SPgCache *pPgCache;
SPage * pPage;
pgsz_t pgSize;
cachesz_t cacheSize;
int32_t npage;
*ppPgCache = NULL;
pgSize = tdbEnvGetPageSize(pEnv);
cacheSize = tdbEnvGetCacheSize(pEnv);
npage = cacheSize / pgSize;
if (!TDB_IS_PGSIZE_VLD(pgSize)) {
return -1;
}
// Allocate the handle
pPgCache = (SPgCache *)calloc(1, sizeof(*pPgCache));
if (pPgCache == NULL) {
return -1;
}
taosInitRWLatch(&(pPgCache->mutex));
pPgCache->pEnv = pEnv;
pPgCache->pgsize = pgSize;
pPgCache->npage = npage;
for (int32_t i = 0; i < npage; i++) {
/* code */
}
#if 0
pPgCache->pages = (SPage *)calloc(npage, sizeof(SPage));
if (pPgCache->pages == NULL) {
pgCacheClose(pPgCache);
......@@ -91,6 +97,7 @@ int pgCacheOpen(SPgCache **ppPgCache, pgsz_t pgSize, int32_t npage, TENV *pEnv)
TD_DLIST_APPEND_WITH_FIELD(&(pPgCache->freeList), pPage, freeNode);
}
#endif
*ppPgCache = pPgCache;
return 0;
......
......@@ -24,7 +24,7 @@ typedef struct SPgCache SPgCache;
typedef struct SPage SPage;
// SPgCache
int pgCacheOpen(SPgCache **ppPgCache, pgsz_t pgSize, int32_t npage, TENV *pEnv);
int pgCacheOpen(SPgCache **ppPgCache, TENV *pEnv);
int pgCacheClose(SPgCache *pPgCache);
SPage *pgCacheFetch(SPgCache *pPgCache, pgid_t pgid);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册