From 9c984f9a906fa65767008f7657edb513a5110044 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 21 Jan 2022 02:43:10 +0000 Subject: [PATCH] more tdb --- source/libs/tdb/src/db/tdb_mpool.c | 21 +++++++++++++++++++-- source/libs/tdb/src/inc/tdb_inc.h | 2 +- source/libs/tdb/src/inc/tdb_mpool.h | 4 ++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/source/libs/tdb/src/db/tdb_mpool.c b/source/libs/tdb/src/db/tdb_mpool.c index 2c536a8e90..3450f7c582 100644 --- a/source/libs/tdb/src/db/tdb_mpool.c +++ b/source/libs/tdb/src/db/tdb_mpool.c @@ -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; } diff --git a/source/libs/tdb/src/inc/tdb_inc.h b/source/libs/tdb/src/inc/tdb_inc.h index d4c9796e54..885191477c 100644 --- a/source/libs/tdb/src/inc/tdb_inc.h +++ b/source/libs/tdb/src/inc/tdb_inc.h @@ -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}; diff --git a/source/libs/tdb/src/inc/tdb_mpool.h b/source/libs/tdb/src/inc/tdb_mpool.h index d77e14715d..d9ee0bfdcd 100644 --- a/source/libs/tdb/src/inc/tdb_mpool.h +++ b/source/libs/tdb/src/inc/tdb_mpool.h @@ -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 }