more TDB
This commit is contained in:
parent
f44954b326
commit
f77d33dcb1
|
@ -16,7 +16,7 @@
|
|||
#include "tdbInt.h"
|
||||
|
||||
struct STDb {
|
||||
char * dbname; // dbname;
|
||||
char dbname[TDB_MAX_DBNAME_LEN];
|
||||
SBTree * pBt; // current access method (may extend)
|
||||
SPgFile * pPgFile; // backend page file this DB is using
|
||||
TENV * pEnv; // TENV containing the DB
|
||||
|
@ -63,16 +63,44 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
|
|||
SPgFile * pPgFile;
|
||||
SPgCache *pPgCache;
|
||||
SBTree * pBt;
|
||||
bool fileExist;
|
||||
size_t dbNameLen;
|
||||
char dbfname[128]; // TODO: make this as a macro or malloc on the heap
|
||||
|
||||
ASSERT(pDb != NULL);
|
||||
ASSERT(fname != NULL);
|
||||
// TODO: Here we simply put an assert here. In the future, make `pEnv`
|
||||
// can be set as NULL.
|
||||
ASSERT(pEnv != NULL);
|
||||
|
||||
// Create a default ENV if pEnv is not set
|
||||
if (pEnv == NULL) {
|
||||
// if ((ret = tdbEnvOpen(&pEnv)) != 0) {
|
||||
// return -1;
|
||||
// }
|
||||
// check the DB name
|
||||
dbNameLen = 0;
|
||||
if (dbname) {
|
||||
dbNameLen = strlen(dbname);
|
||||
if (dbNameLen >= TDB_MAX_DBNAME_LEN) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pDb->dbname, dbname, dbNameLen);
|
||||
}
|
||||
|
||||
pDb->dbname[dbNameLen] = '\0';
|
||||
|
||||
// open pPgFile or get from the env
|
||||
snprintf(dbfname, 128, "%s/%s", tdbEnvGetRootDir(pEnv), fname);
|
||||
fileExist = (tdbCheckFileAccess(fname, TDB_F_OK) == 0);
|
||||
if (fileExist) {
|
||||
// TODO
|
||||
} else {
|
||||
ret = pgFileOpen(&pPgFile, dbfname, pEnv);
|
||||
if (ret != 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
// Create and open the page file
|
||||
}
|
||||
|
||||
#if 0
|
||||
pDb->pEnv = pEnv;
|
||||
|
||||
// register DB to ENV
|
||||
|
@ -104,6 +132,7 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
|
|||
}
|
||||
|
||||
pDb->pBt = pBt;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -124,4 +124,6 @@ int tdbEnvBeginTxn(TENV *pEnv) {
|
|||
int tdbEnvCommit(TENV *pEnv) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const char *tdbEnvGetRootDir(TENV *pEnv) { return pEnv->rootDir; }
|
||||
|
|
|
@ -17,8 +17,9 @@
|
|||
|
||||
static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData);
|
||||
|
||||
int pgFileOpen(SPgFile **ppPgFile, const char *fname, SPgCache *pPgCache) {
|
||||
SPgFile *pPgFile;
|
||||
int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv) {
|
||||
SPgFile * pPgFile;
|
||||
SPgCache *pPgCache;
|
||||
|
||||
*ppPgFile = NULL;
|
||||
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
SPgFile* tdbEnvGetPageFile(TENV* pEnv, const uint8_t fileid[]);
|
||||
SPgCache* tdbEnvGetPgCache(TENV* pEnv);
|
||||
const char* tdbEnvGetRootDir(TENV* pEnv);
|
||||
SPgFile* tdbEnvGetPageFile(TENV* pEnv, const uint8_t fileid[]);
|
||||
SPgCache* tdbEnvGetPgCache(TENV* pEnv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -76,6 +76,9 @@ typedef pgsz_t pgoff_t;
|
|||
// cache
|
||||
#define TDB_DEFAULT_CACHE_SIZE (256 * 4096) // 1M
|
||||
|
||||
// dbname
|
||||
#define TDB_MAX_DBNAME_LEN 24
|
||||
|
||||
// tdb_log
|
||||
#define tdbError(var)
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ struct SPgFile {
|
|||
TDB * pDb; // For a SPgFile for multiple databases, this is the <dbname, pgno> mapping DB.
|
||||
};
|
||||
|
||||
int pgFileOpen(SPgFile **ppPgFile, const char *fname, SPgCache *pPgCache);
|
||||
int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv);
|
||||
int pgFileClose(SPgFile *pPgFile);
|
||||
|
||||
SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno);
|
||||
|
|
Loading…
Reference in New Issue