more TDB
This commit is contained in:
parent
123dc0cd11
commit
3989a061c6
|
@ -1,5 +1,5 @@
|
||||||
set(META_DB_IMPL_LIST "BDB" "TDB")
|
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})
|
set_property(CACHE META_DB_IMPL PROPERTY STRINGS ${META_DB_IMPL_LIST})
|
||||||
|
|
||||||
if(META_DB_IMPL IN_LIST META_DB_IMPL_LIST)
|
if(META_DB_IMPL IN_LIST META_DB_IMPL_LIST)
|
||||||
|
|
|
@ -22,16 +22,21 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct STDb TDB;
|
typedef struct STDb TDB;
|
||||||
typedef struct STDbEnv TENV;
|
typedef struct STDbEnv TENV;
|
||||||
|
typedef struct STDbCurosr TDBC;
|
||||||
|
|
||||||
// TEVN
|
// TEVN
|
||||||
|
int tdbEnvOpen(TENV **ppEnv);
|
||||||
|
int tdbEnvClose(TENV *pEnv);
|
||||||
|
|
||||||
// TDB
|
// TDB
|
||||||
int tdbCreate(TDB **ppDb);
|
int tdbCreate(TDB **ppDb);
|
||||||
int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv);
|
int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv);
|
||||||
int tdbClose(TDB *pDb);
|
int tdbClose(TDB *pDb);
|
||||||
|
|
||||||
|
// TDBC
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData);
|
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;
|
SPgFile *pPgFile;
|
||||||
|
|
||||||
*ppPgFile = NULL;
|
*ppPgFile = NULL;
|
||||||
|
|
|
@ -42,8 +42,11 @@ static int tdbDestroy(TDB *pDb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) {
|
int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) {
|
||||||
TDB *pDb;
|
TDB * pDb;
|
||||||
int ret;
|
int ret;
|
||||||
|
uint8_t fileid[TDB_FILE_ID_LEN];
|
||||||
|
SPgFile * pPgFile;
|
||||||
|
SPgCache *pPgCache;
|
||||||
|
|
||||||
// Create DB if DB handle is not created yet
|
// Create DB if DB handle is not created yet
|
||||||
if (ppDb == NULL) {
|
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
|
// Create a default ENV if pEnv is not set
|
||||||
if (pEnv == NULL) {
|
if (pEnv == NULL) {
|
||||||
// if ((ret = tenvOpen(&pEnv)) != 0) {
|
if ((ret = tdbEnvOpen(&pEnv)) != 0) {
|
||||||
// return -1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,3 +22,20 @@ struct STDbEnv {
|
||||||
} pgfht; // page file hash table;
|
} pgfht; // page file hash table;
|
||||||
SPgCache pgc; // page cache
|
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); }
|
|
@ -30,7 +30,7 @@ struct SPgFile {
|
||||||
pgno_t pgFileSize;
|
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);
|
int pgFileClose(SPgFile *pPgFile);
|
||||||
|
|
||||||
SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno);
|
SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno);
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SPgFile* tdbEnvGetPageFile(TENV* pEnv, const uint8_t fileid[]);
|
||||||
|
SPgCache* tdbEnvGetPgCache(TENV* pEnv);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue