refact TDB

This commit is contained in:
Hongze Cheng 2022-02-15 06:40:55 +00:00
parent 3ccb52e424
commit f6f6a69160
3 changed files with 28 additions and 26 deletions

View File

@ -14,6 +14,32 @@
*/
#include "tdbInt.h"
typedef TD_DLIST_NODE(SPage) SPgListNode;
struct SPage {
pgid_t pgid; // page id
frame_id_t frameid; // frame id
SPgListNode freeNode; // for SPgCache.freeList
SPgListNode pghtNode; // for pght
SPgListNode lruNode; // for LRU
uint8_t * pData; // real data
};
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;
struct {
int32_t nbucket;
SPgList *buckets;
} pght; // page hash table
};
static void pgCachePinPage(SPage *pPage);
static void pgCacheUnpinPage(SPage *pPage);

View File

@ -86,7 +86,8 @@ SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno) {
if (1 /*Page is cached, no need to load from file*/) {
return pPage;
} else {
if (pgFileRead(pPgFile, pgno, pPage->pData) < 0) {
// TODO: handle error
if (pgFileRead(pPgFile, pgno, (void *)pPage) < 0) {
// todoerr
}
return pPage;

View File

@ -32,31 +32,6 @@ int pgCacheRelease(SPage *pPage);
// SPage
typedef TD_DLIST_NODE(SPage) SPgListNode;
struct SPage {
pgid_t pgid; // page id
frame_id_t frameid; // frame id
SPgListNode freeNode; // for SPgCache.freeList
SPgListNode pghtNode; // for pght
SPgListNode lruNode; // for LRU
uint8_t * pData; // real data
};
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;
struct {
int32_t nbucket;
SPgList *buckets;
} pght; // page hash table
};
#ifdef __cplusplus
}
#endif