This commit is contained in:
Hongze Cheng 2022-02-28 06:33:37 +00:00
parent 50a8637464
commit 59e7f147c3
4 changed files with 24 additions and 7 deletions

View File

@ -24,6 +24,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
STDb * pDb;
SPFile *pFile;
int ret;
char fFullName[TDB_FILENAME_LEN];
*ppDb = NULL;
@ -35,6 +36,15 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
// pDb->pEnv
pDb->pEnv = pEnv;
pFile = tdbEnvGetPFile(pEnv, fname);
if (pFile == NULL) {
snprintf(fFullName, TDB_FILENAME_LEN, "%s/%s", pEnv->rootDir, fname);
ret = tdbPFileOpen(pEnv->pCache, fFullName, &pFile);
if (ret < 0) {
return -1;
}
}
// pDb->pBt
ret = tdbBtreeOpen(&(pDb->pBt));
if (ret < 0) {

View File

@ -15,13 +15,6 @@
#include "tdbInt.h"
struct STEnv {
char * rootDir;
char * jfname;
int jfd;
SPCache *pCache;
};
int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) {
STEnv *pEnv;
int dsize;
@ -69,4 +62,9 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv)
int tdbEnvClose(STEnv *pEnv) {
// TODO
return 0;
}
SPFile *tdbEnvGetPFile(STEnv *pEnv, const char *fname) {
// TODO
return NULL;
}

View File

@ -21,10 +21,18 @@ extern "C" {
#endif
typedef struct STEnv STEnv;
struct STEnv {
char * rootDir;
char * jfname;
int jfd;
SPCache *pCache;
};
int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv);
int tdbEnvClose(STEnv *pEnv);
SPFile *tdbEnvGetPFile(STEnv *pEnv, const char *fname);
#ifdef __cplusplus
}
#endif

View File

@ -124,6 +124,7 @@ typedef TD_DLIST_NODE(SPgFile) SPgFileListNode;
typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
#define TDB_JOURNAL_NAME "tdb.journal"
#define TDB_FILENAME_LEN 128
#include "tdbUtil.h"