diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index a0c9939ad9..00bef20b90 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -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) { diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 3481472b33..bc5a20a2cb 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -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; } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/source/libs/tdb/src/inc/tdbEnv.h index 29eae40c46..3969eae576 100644 --- a/source/libs/tdb/src/inc/tdbEnv.h +++ b/source/libs/tdb/src/inc/tdbEnv.h @@ -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 diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index e764c65e72..a11e6d830f 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -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"