more TDB
This commit is contained in:
parent
2f320dc23b
commit
f3d1bd4340
|
@ -16,7 +16,7 @@
|
|||
#include "tdbInt.h"
|
||||
|
||||
struct SBTree {
|
||||
pgno_t rootPage;
|
||||
pgno_t root;
|
||||
// TODO
|
||||
};
|
||||
|
||||
|
|
|
@ -125,13 +125,19 @@ int pgCacheClose(SPgCache *pPgCache) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#define PG_CACHE_HASH(fileid, pgno) \
|
||||
({ \
|
||||
uint64_t *tmp = (uint64_t *)(fileid); \
|
||||
(tmp[0] + tmp[1] + tmp[2] + (pgno)); \
|
||||
})
|
||||
|
||||
SPage *pgCacheFetch(SPgCache *pPgCache, pgid_t pgid) {
|
||||
SPage * pPage;
|
||||
SPgFile *pPgFile;
|
||||
SPgList *pBucket;
|
||||
|
||||
// 1. Search the page hash table SPgCache.pght
|
||||
pBucket = pPgCache->pght.buckets + ((0 /*TODO*/) % pPgCache->pght.nbucket);
|
||||
pBucket = pPgCache->pght.buckets + (PG_CACHE_HASH(pgid.fileid, pgid.pgno) % pPgCache->pght.nbucket);
|
||||
pPage = TD_DLIST_HEAD(pBucket);
|
||||
while (pPage && tdbCmprPgId(&(pPage->pgid), &pgid)) {
|
||||
pPage = TD_DLIST_NODE_NEXT_WITH_FIELD(pPage, pghtNode);
|
||||
|
|
|
@ -76,7 +76,11 @@ SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno) {
|
|||
memcpy(pgid.fileid, pPgFile->fileid, TDB_FILE_ID_LEN);
|
||||
pgid.pgno = pgno;
|
||||
|
||||
pPage = pgCacheFetch(pPgCache, pgid);
|
||||
if (pgno > pPgFile->pgFileSize) {
|
||||
// TODO
|
||||
} else {
|
||||
pPage = pgCacheFetch(pPgCache, pgid);
|
||||
}
|
||||
|
||||
return pPage;
|
||||
}
|
||||
|
|
|
@ -15,59 +15,7 @@
|
|||
|
||||
#include "tdbInt.h"
|
||||
|
||||
// static int tdbOpenImpl(TDB *dbp);
|
||||
|
||||
// int tdbOpen(TDB **dbpp, const char *fname, const char *dbname, uint32_t flags) {
|
||||
// TDB * dbp;
|
||||
// TDB_MPFILE *mpf;
|
||||
// uint8_t fileid[TDB_FILE_ID_LEN];
|
||||
|
||||
// if ((dbp = (TDB *)calloc(1, sizeof(*dbp))) == NULL) {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// if ((dbp->fname = strdup(fname)) == NULL) {
|
||||
// free(dbp);
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// if ((dbname) && ((dbp->dbname = strdup(dbname)) == NULL)) {
|
||||
// free(dbp->fname);
|
||||
// free(dbp);
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// // if (tdbGnrtFileID(fname, fileid) < 0) {
|
||||
// // // todo
|
||||
// // return -1;
|
||||
// // }
|
||||
|
||||
// // TODO: mpf = tdbGetMPFileByID(fileid);
|
||||
// if (mpf == NULL) {
|
||||
// // todoerr: maybe we need to create one
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// if (tdbOpenImpl(dbp) < 0) {
|
||||
// // todoerr
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// *dbpp = dbp;
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// int tdbClose(TDB *dbp, uint32_t flags) {
|
||||
// // TODO
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// static int tdbOpenImpl(TDB *dbp) {
|
||||
// if (dbp->dbname == NULL) {
|
||||
// // todo: open the DB as a master DB
|
||||
// } else {
|
||||
// // todo: open the DB as a sub-db
|
||||
// }
|
||||
// // TODO
|
||||
// return 0;
|
||||
// }
|
||||
struct STDb {
|
||||
// TODO
|
||||
SBTree *pBt;
|
||||
};
|
||||
|
|
|
@ -23,6 +23,12 @@ extern "C" {
|
|||
typedef struct SBTree SBTree;
|
||||
typedef struct SBtCursor SBtCursor;
|
||||
|
||||
// SBTree
|
||||
int btreeOpen(SBTree **ppBt);
|
||||
int btreeClose(SBTree *pBt);
|
||||
|
||||
// SBtCursor
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue