提交 9c984f9a 编写于 作者: H Hongze Cheng

more tdb

上级 2f2b7d2f
......@@ -143,13 +143,30 @@ int tdbMPoolFileClose(TDB_MPFILE *mpf) {
return 0;
}
int tdbMPoolFileGet(TDB_MPFILE *mpf, pgno_t pgid, void *addr) {
#define MPF_GET_PAGE_BUCKETID(fileid, pgno, nbuckets) \
({ \
uint64_t *tmp = (uint64_t *)fileid; \
(tmp[0] + tmp[1] + tmp[2] + (pgno)) % (nbuckets); \
})
int tdbMPoolFileGet(TDB_MPFILE *mpf, pgno_t pgno, void *addr) {
pg_t * pagep;
TDB_MPOOL *mp;
pg_list_t *pglist;
mp = mpf->mp;
// get page in the cache
pglist = mp->pgtab.hashtab + MPF_GET_PAGE_BUCKETID(mpf->fileid, pgno, mp->pgtab.nbucket);
pagep = TD_DLIST_HEAD(pglist);
while (pagep) {
if (memcmp(mpf->fileid, pagep->pgid.fileid, TDB_FILE_ID_LEN) == 0 && pgno == pagep->pgid.pgno) {
break;
}
pagep = TD_DLIST_NODE_NEXT_WITH_FIELD(pagep, hash);
}
if (pagep) {
// page is found in the page table
// todo: pin the page and return
......@@ -173,7 +190,7 @@ int tdbMPoolFileGet(TDB_MPFILE *mpf, pgno_t pgid, void *addr) {
return 0;
}
int tdbMPoolFilePut(TDB_MPOOL *mpf, pgno_t pgid, void *addr) {
int tdbMPoolFilePut(TDB_MPOOL *mpf, pgno_t pgno, void *addr) {
// TODO
return 0;
}
......
......@@ -34,7 +34,7 @@ typedef int32_t pgno_t;
// pgid_t
typedef struct {
uint8_t fileid[TDB_FILE_ID_LEN];
pgno_t pgid;
pgno_t pgno;
} pgid_t;
#define TDB_IVLD_PGID (pgid_t){0, TDB_IVLD_PGNO};
......
......@@ -80,8 +80,8 @@ int tdbMPoolClose(TDB_MPOOL *mp);
// TDB_MPFILE
int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp);
int tdbMPoolFileClose(TDB_MPFILE *mpf);
int tdbMPoolFileGet(TDB_MPFILE *mpf, pgno_t pgid, void *addr);
int tdbMPoolFilePut(TDB_MPOOL *mpf, pgno_t pgid, void *addr);
int tdbMPoolFileGet(TDB_MPFILE *mpf, pgno_t pgno, void *addr);
int tdbMPoolFilePut(TDB_MPOOL *mpf, pgno_t pgno, void *addr);
#ifdef __cplusplus
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册