more TDB
This commit is contained in:
parent
f6f6a69160
commit
1bcb109800
|
@ -72,7 +72,7 @@ int tdbEnvOpen(TENV *pEnv) {
|
||||||
|
|
||||||
pgSize = pEnv->pgSize;
|
pgSize = pEnv->pgSize;
|
||||||
npage = pEnv->cacheSize / pEnv->pgSize;
|
npage = pEnv->cacheSize / pEnv->pgSize;
|
||||||
ret = pgCacheOpen(&pPgCache, pgSize, npage, pEnv);
|
ret = pgCacheOpen(&pPgCache, pEnv);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,42 +26,48 @@ struct SPage {
|
||||||
|
|
||||||
typedef TD_DLIST(SPage) SPgList;
|
typedef TD_DLIST(SPage) SPgList;
|
||||||
struct SPgCache {
|
struct SPgCache {
|
||||||
TENV * pEnv; // TENV containing this page cache
|
TENV * pEnv; // TENV containing this page cache
|
||||||
SRWLatch mutex;
|
pgsz_t pgsize;
|
||||||
pgsz_t pgsize;
|
int32_t npage;
|
||||||
int32_t npage;
|
SPage * pages;
|
||||||
SPage * pages;
|
SPgList freeList;
|
||||||
SPgList freeList;
|
SPgList lru;
|
||||||
SPgList lru;
|
|
||||||
struct {
|
struct {
|
||||||
int32_t nbucket;
|
int32_t nbucket;
|
||||||
SPgList *buckets;
|
SPgList *buckets;
|
||||||
} pght; // page hash table
|
} pght; // page hash table
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void pgCachePinPage(SPage *pPage);
|
static void pgCachePinPage(SPage *pPage);
|
||||||
static void pgCacheUnpinPage(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;
|
SPgCache *pPgCache;
|
||||||
SPage * pPage;
|
SPage * pPage;
|
||||||
|
pgsz_t pgSize;
|
||||||
|
cachesz_t cacheSize;
|
||||||
|
int32_t npage;
|
||||||
|
|
||||||
*ppPgCache = NULL;
|
*ppPgCache = NULL;
|
||||||
|
pgSize = tdbEnvGetPageSize(pEnv);
|
||||||
|
cacheSize = tdbEnvGetCacheSize(pEnv);
|
||||||
|
npage = cacheSize / pgSize;
|
||||||
|
|
||||||
if (!TDB_IS_PGSIZE_VLD(pgSize)) {
|
// Allocate the handle
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pPgCache = (SPgCache *)calloc(1, sizeof(*pPgCache));
|
pPgCache = (SPgCache *)calloc(1, sizeof(*pPgCache));
|
||||||
if (pPgCache == NULL) {
|
if (pPgCache == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosInitRWLatch(&(pPgCache->mutex));
|
pPgCache->pEnv = pEnv;
|
||||||
pPgCache->pgsize = pgSize;
|
pPgCache->pgsize = pgSize;
|
||||||
pPgCache->npage = npage;
|
pPgCache->npage = npage;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < npage; i++) {
|
||||||
|
/* code */
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
pPgCache->pages = (SPage *)calloc(npage, sizeof(SPage));
|
pPgCache->pages = (SPage *)calloc(npage, sizeof(SPage));
|
||||||
if (pPgCache->pages == NULL) {
|
if (pPgCache->pages == NULL) {
|
||||||
pgCacheClose(pPgCache);
|
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);
|
TD_DLIST_APPEND_WITH_FIELD(&(pPgCache->freeList), pPage, freeNode);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
*ppPgCache = pPgCache;
|
*ppPgCache = pPgCache;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -24,7 +24,7 @@ typedef struct SPgCache SPgCache;
|
||||||
typedef struct SPage SPage;
|
typedef struct SPage SPage;
|
||||||
|
|
||||||
// SPgCache
|
// SPgCache
|
||||||
int pgCacheOpen(SPgCache **ppPgCache, pgsz_t pgSize, int32_t npage, TENV *pEnv);
|
int pgCacheOpen(SPgCache **ppPgCache, TENV *pEnv);
|
||||||
int pgCacheClose(SPgCache *pPgCache);
|
int pgCacheClose(SPgCache *pPgCache);
|
||||||
|
|
||||||
SPage *pgCacheFetch(SPgCache *pPgCache, pgid_t pgid);
|
SPage *pgCacheFetch(SPgCache *pPgCache, pgid_t pgid);
|
||||||
|
|
Loading…
Reference in New Issue