提交 2f320dc2 编写于 作者: H Hongze Cheng

more TDB

上级 add314fa
......@@ -19,6 +19,7 @@ struct SPage {
pgid_t pgid; // page id
frame_id_t frameid; // frame id
SPgListNode freeNode; // for SPgCache.freeList
SPgListNode pghtNode; // for pght
uint8_t * pData; // real data
};
......@@ -36,6 +37,8 @@ struct SPgCache {
} pght; // page hash table
};
static void pgCachePinPage(SPage *pPage);
int pgCacheCreate(SPgCache **ppPgCache, pgsize_t pgSize, int32_t npage) {
SPgCache *pPgCache;
SPage * pPage;
......@@ -123,13 +126,37 @@ int pgCacheClose(SPgCache *pPgCache) {
}
SPage *pgCacheFetch(SPgCache *pPgCache, pgid_t pgid) {
SPage *pPage;
SPage * pPage;
SPgFile *pPgFile;
SPgList *pBucket;
// 1. Search the page hash table SPgCache.pght
pBucket = pPgCache->pght.buckets + ((0 /*TODO*/) % pPgCache->pght.nbucket);
pPage = TD_DLIST_HEAD(pBucket);
while (pPage && tdbCmprPgId(&(pPage->pgid), &pgid)) {
pPage = TD_DLIST_NODE_NEXT_WITH_FIELD(pPage, pghtNode);
}
if (pPage) {
// Page is found, pin the page (TODO) and return the page
pgCachePinPage(pPage);
return pPage;
}
// TODO
// 1. Check if the page is cached
return NULL;
}
int pgCacheRelease(SPage *pPage) {
// TODO
return 0;
}
static void pgCachePinPage(SPage *pPage) {
// TODO
}
static void pgCacheUnpinPage(SPage *pPage) {
// TODO
}
\ No newline at end of file
......@@ -38,8 +38,28 @@ typedef struct {
uint8_t fileid[TDB_FILE_ID_LEN];
pgno_t pgno;
} pgid_t;
#define TDB_IVLD_PGID (pgid_t){0, TDB_IVLD_PGNO};
static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) {
pgid_t *pgid1 = (pgid_t *)p1;
pgid_t *pgid2 = (pgid_t *)p2;
int rcode;
rcode = memcmp(pgid1->fileid, pgid2->fileid, TDB_FILE_ID_LEN);
if (rcode) {
return rcode;
} else {
if (pgid1->pgno > pgid2->pgno) {
return 1;
} else if (pgid1->pgno < pgid2->pgno) {
return -1;
} else {
return 0;
}
}
}
// framd_id_t
typedef int32_t frame_id_t;
......@@ -51,14 +71,14 @@ typedef int32_t pgsize_t;
#define TDB_IS_PGSIZE_VLD(s) (((s) >= TDB_MIN_PGSIZE) && ((s) <= TDB_MAX_PGSIZE))
// cache
#define TDB_DEFAULT_CACHE_SIZE (256 * 1024) // 256K
#define TDB_DEFAULT_CACHE_SIZE (256 * 1024) // 256K
// tdb_log
#define tdbError(var)
#include "btree.h"
#include "pgcache.h"
#include "pgfile.h"
#include "btree.h"
// tdb util
int tdbGnrtFileID(const char *fname, uint8_t *fileid);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册