diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 9cecd829871b3f245e005bf43c97d5a4c04e86cc..9eb7a74b1e3b5931c4cc15dc651efdbd6460994b 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -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; } diff --git a/source/libs/tdb/src/db/tdbPgCache.c b/source/libs/tdb/src/db/tdbPgCache.c index 273b1abe4bd9fa4b2d283b187e82a60d6a1ff175..c62db61746a30d0c03ec318393c78682aa696e5f 100644 --- a/source/libs/tdb/src/db/tdbPgCache.c +++ b/source/libs/tdb/src/db/tdbPgCache.c @@ -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; diff --git a/source/libs/tdb/src/inc/tdbPgCache.h b/source/libs/tdb/src/inc/tdbPgCache.h index 791d5148fc3adafcc603f4e399f86af99301e3f6..5bcac688af45ad13fc360a2426d7fc0219d15a35 100644 --- a/source/libs/tdb/src/inc/tdbPgCache.h +++ b/source/libs/tdb/src/inc/tdbPgCache.h @@ -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);