This commit is contained in:
Hongze Cheng 2022-02-09 11:40:44 +00:00
parent 123dc0cd11
commit 3989a061c6
7 changed files with 59 additions and 12 deletions

View File

@ -1,5 +1,5 @@
set(META_DB_IMPL_LIST "BDB" "TDB")
set(META_DB_IMPL "BDB" CACHE STRING "Use BDB as the default META implementation")
set(META_DB_IMPL "TDB" CACHE STRING "Use BDB as the default META implementation")
set_property(CACHE META_DB_IMPL PROPERTY STRINGS ${META_DB_IMPL_LIST})
if(META_DB_IMPL IN_LIST META_DB_IMPL_LIST)

View File

@ -22,16 +22,21 @@
extern "C" {
#endif
typedef struct STDb TDB;
typedef struct STDbEnv TENV;
typedef struct STDb TDB;
typedef struct STDbEnv TENV;
typedef struct STDbCurosr TDBC;
// TEVN
int tdbEnvOpen(TENV **ppEnv);
int tdbEnvClose(TENV *pEnv);
// TDB
int tdbCreate(TDB **ppDb);
int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv);
int tdbClose(TDB *pDb);
// TDBC
#ifdef __cplusplus
}
#endif

View File

@ -17,7 +17,7 @@
static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData);
int pgFileOpen(const char *fname, SPgCache *pPgCache, SPgFile **ppPgFile) {
int pgFileOpen(SPgFile **ppPgFile, const char *fname, SPgCache *pPgCache) {
SPgFile *pPgFile;
*ppPgFile = NULL;

View File

@ -42,8 +42,11 @@ static int tdbDestroy(TDB *pDb) {
}
int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) {
TDB *pDb;
int ret;
TDB * pDb;
int ret;
uint8_t fileid[TDB_FILE_ID_LEN];
SPgFile * pPgFile;
SPgCache *pPgCache;
// Create DB if DB handle is not created yet
if (ppDb == NULL) {
@ -56,12 +59,31 @@ int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) {
// Create a default ENV if pEnv is not set
if (pEnv == NULL) {
// if ((ret = tenvOpen(&pEnv)) != 0) {
// return -1;
// }
if ((ret = tdbEnvOpen(&pEnv)) != 0) {
return -1;
}
}
/* TODO */
pDb->pEnv = pEnv;
// register DB to ENV
ASSERT(fname != NULL);
// Check if file exists (TODO)
// Check if the SPgFile already opened
pPgFile = tdbEnvGetPageFile(pEnv, fileid);
if (pPgFile == NULL) {
pPgCache = tdbEnvGetPgCache(pEnv);
if ((ret = pgFileOpen(&pPgFile, fname, pPgCache)) != 0) {
return -1;
}
}
pDb->pPgFile = pPgFile;
// open the access method (TODO)
return 0;
}

View File

@ -21,4 +21,21 @@ struct STDbEnv {
struct {
} pgfht; // page file hash table;
SPgCache pgc; // page cache
};
};
int tdbEnvOpen(TENV **ppEnv) {
// TODO
return 0;
}
int tdbEnvClose(TENV *pEnv) {
// TODO
return 0;
}
SPgFile *tdbEnvGetPageFile(TENV *pEnv, const uint8_t fileid[]) {
// TODO
return NULL;
}
SPgCache *tdbEnvGetPgCache(TENV *pEnv) { return &(pEnv->pgc); }

View File

@ -30,7 +30,7 @@ struct SPgFile {
pgno_t pgFileSize;
};
int pgFileOpen(const char *fname, SPgCache *pPgCache, SPgFile **ppPgFile);
int pgFileOpen(SPgFile **ppPgFile, const char *fname, SPgCache *pPgCache);
int pgFileClose(SPgFile *pPgFile);
SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno);

View File

@ -20,6 +20,9 @@
extern "C" {
#endif
SPgFile* tdbEnvGetPageFile(TENV* pEnv, const uint8_t fileid[]);
SPgCache* tdbEnvGetPgCache(TENV* pEnv);
#ifdef __cplusplus
}
#endif