From 1bcb109800bcdd6d10a17900efc265dd3cadfc40 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 15 Feb 2022 07:01:30 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbEnv.c | 2 +- source/libs/tdb/src/db/tdbPgCache.c | 35 +++++++++++++++++----------- source/libs/tdb/src/inc/tdbPgCache.h | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 9cecd82987..9eb7a74b1e 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 273b1abe4b..c62db61746 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 791d5148fc..5bcac688af 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); -- GitLab