more tdb
This commit is contained in:
parent
2394e0e0ff
commit
9f3d9db127
|
@ -16,6 +16,7 @@
|
|||
#include "tdb_mpool.h"
|
||||
|
||||
static int tdbGnrtFileID(const char *fname, uint8_t *fileid);
|
||||
static void tdbMpoolRegFile(TDB_MPOOL *mp, TDB_MPFILE *mpf);
|
||||
|
||||
int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) {
|
||||
TDB_MPOOL *mp = NULL;
|
||||
|
@ -118,6 +119,9 @@ int tdbMPoolFileOpen(TDB_MPFILE **mpfp, const char *fname, TDB_MPOOL *mp) {
|
|||
goto _err;
|
||||
}
|
||||
|
||||
// Register current MPF to MP
|
||||
tdbMpoolRegFile(mp, mpf);
|
||||
|
||||
*mpfp = mpf;
|
||||
return 0;
|
||||
|
||||
|
@ -138,6 +142,41 @@ int tdbMPoolFileClose(TDB_MPFILE *mpf) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tdbMPoolFileGet(TDB_MPFILE *mpf, pgno_t pgid, void *addr) {
|
||||
pg_t * pagep;
|
||||
TDB_MPOOL *mp;
|
||||
|
||||
mp = mpf->mp;
|
||||
|
||||
// get page in the cache
|
||||
if (pagep) {
|
||||
// page is found in the page table
|
||||
// todo: pin the page and return
|
||||
*(void **)addr = pagep->data;
|
||||
return 0;
|
||||
} else {
|
||||
// page not found
|
||||
pagep = TD_DLIST_HEAD(&mp->freeList);
|
||||
if (pagep) {
|
||||
// TD_DLIST_POP(&(mp->freeList), pagep);
|
||||
} else {
|
||||
// no page found in the freelist, need to evict
|
||||
// pagep = tdbMpoolEvict(mp);
|
||||
if (pagep) {
|
||||
} else {
|
||||
// TODO: Cannot find a page to evict
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbMPoolFilePut(TDB_MPOOL *mpf, pgno_t pgid, void *addr) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tdbGnrtFileID(const char *fname, uint8_t *fileid) {
|
||||
struct stat statbuf;
|
||||
|
||||
|
@ -153,3 +192,7 @@ static int tdbGnrtFileID(const char *fname, uint8_t *fileid) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tdbMpoolRegFile(TDB_MPOOL *mp, TDB_MPFILE *mpf) {
|
||||
// TODO
|
||||
}
|
|
@ -51,6 +51,10 @@ struct TDB_MPOOL {
|
|||
int32_t nbucket;
|
||||
pg_list_t *hashtab;
|
||||
} pgtab; // page table, hash<pgid_t, pg_t>
|
||||
struct {
|
||||
int32_t nbucket;
|
||||
TD_DLIST(TDB_MPFILE) hashtab[8];
|
||||
} mpftab;
|
||||
};
|
||||
|
||||
#define MP_PAGE_AT(mp, idx) (mp)->pages[idx]
|
||||
|
@ -60,6 +64,7 @@ struct TDB_MPFILE {
|
|||
int fd; // fd
|
||||
uint8_t fileid[TDB_FILE_ID_LEN]; // file ID
|
||||
TDB_MPOOL *mp; // underlying memory pool
|
||||
TD_DLIST_NODE(TDB_MPFILE);
|
||||
};
|
||||
|
||||
/*=================================================== Exposed apis ==================================================*/
|
||||
|
|
Loading…
Reference in New Issue