more TDB
This commit is contained in:
parent
f44954b326
commit
f77d33dcb1
|
@ -16,7 +16,7 @@
|
||||||
#include "tdbInt.h"
|
#include "tdbInt.h"
|
||||||
|
|
||||||
struct STDb {
|
struct STDb {
|
||||||
char * dbname; // dbname;
|
char dbname[TDB_MAX_DBNAME_LEN];
|
||||||
SBTree * pBt; // current access method (may extend)
|
SBTree * pBt; // current access method (may extend)
|
||||||
SPgFile * pPgFile; // backend page file this DB is using
|
SPgFile * pPgFile; // backend page file this DB is using
|
||||||
TENV * pEnv; // TENV containing the DB
|
TENV * pEnv; // TENV containing the DB
|
||||||
|
@ -63,16 +63,44 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
|
||||||
SPgFile * pPgFile;
|
SPgFile * pPgFile;
|
||||||
SPgCache *pPgCache;
|
SPgCache *pPgCache;
|
||||||
SBTree * pBt;
|
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(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
|
// check the DB name
|
||||||
if (pEnv == NULL) {
|
dbNameLen = 0;
|
||||||
// if ((ret = tdbEnvOpen(&pEnv)) != 0) {
|
if (dbname) {
|
||||||
// return -1;
|
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;
|
pDb->pEnv = pEnv;
|
||||||
|
|
||||||
// register DB to ENV
|
// register DB to ENV
|
||||||
|
@ -104,6 +132,7 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pDb->pBt = pBt;
|
pDb->pBt = pBt;
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,3 +125,5 @@ int tdbEnvCommit(TENV *pEnv) {
|
||||||
// TODO
|
// TODO
|
||||||
return 0;
|
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);
|
static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData);
|
||||||
|
|
||||||
int pgFileOpen(SPgFile **ppPgFile, const char *fname, SPgCache *pPgCache) {
|
int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv) {
|
||||||
SPgFile *pPgFile;
|
SPgFile * pPgFile;
|
||||||
|
SPgCache *pPgCache;
|
||||||
|
|
||||||
*ppPgFile = NULL;
|
*ppPgFile = NULL;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const char* tdbEnvGetRootDir(TENV* pEnv);
|
||||||
SPgFile* tdbEnvGetPageFile(TENV* pEnv, const uint8_t fileid[]);
|
SPgFile* tdbEnvGetPageFile(TENV* pEnv, const uint8_t fileid[]);
|
||||||
SPgCache* tdbEnvGetPgCache(TENV* pEnv);
|
SPgCache* tdbEnvGetPgCache(TENV* pEnv);
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,9 @@ typedef pgsz_t pgoff_t;
|
||||||
// cache
|
// cache
|
||||||
#define TDB_DEFAULT_CACHE_SIZE (256 * 4096) // 1M
|
#define TDB_DEFAULT_CACHE_SIZE (256 * 4096) // 1M
|
||||||
|
|
||||||
|
// dbname
|
||||||
|
#define TDB_MAX_DBNAME_LEN 24
|
||||||
|
|
||||||
// tdb_log
|
// tdb_log
|
||||||
#define tdbError(var)
|
#define tdbError(var)
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct SPgFile {
|
||||||
TDB * pDb; // For a SPgFile for multiple databases, this is the <dbname, pgno> mapping DB.
|
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);
|
int pgFileClose(SPgFile *pPgFile);
|
||||||
|
|
||||||
SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno);
|
SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno);
|
||||||
|
|
Loading…
Reference in New Issue