diff --git a/source/dnode/vnode/meta/src/metaCache.c b/source/dnode/vnode/meta/src/metaCache.c index 1e848d434e37510bdda8871668c68c694cf087c4..9166f1724aa479d153f641976dc0a1cdf01dd06a 100644 --- a/source/dnode/vnode/meta/src/metaCache.c +++ b/source/dnode/vnode/meta/src/metaCache.c @@ -18,9 +18,20 @@ int metaOpenCache(SMeta *pMeta) { // TODO + if (pMeta->options.lruCacheSize) { + pMeta->pCache = rocksdb_cache_create_lru(pMeta->options.lruCacheSize); + if (pMeta->pCache == NULL) { + // TODO: handle error + return -1; + } + } + return 0; } void metaCloseCache(SMeta *pMeta) { - // TODO + if (pMeta->pCache) { + rocksdb_cache_destroy(pMeta->pCache); + pMeta->pCache = NULL; + } } \ No newline at end of file diff --git a/source/dnode/vnode/meta/src/metaDB.c b/source/dnode/vnode/meta/src/metaDB.c index 5c3d9d0a02b605b4a8806562c6b8b40ab024d1d8..2fcf424971836d45c4c46004e893489bdd25ab99 100644 --- a/source/dnode/vnode/meta/src/metaDB.c +++ b/source/dnode/vnode/meta/src/metaDB.c @@ -17,78 +17,10 @@ #include "metaDef.h" int metaOpenDB(SMeta *pMeta) { -#if 0 - char * err = NULL; - rocksdb_options_t *dbOptions; - rocksdb_options_t *idxOptions; + /* TODO */ - // Create LRU cache - if (pMeta->options.lruCacheSize) { - pMeta->metaDB.pCache = rocksdb_cache_create_lru(pMeta->options.lruCacheSize); - if (pMeta->metaDB.pCache == NULL) { - // TODO: handle error - return -1; - } - } - - // Open raw data DB --------------------------- - dbOptions = rocksdb_options_create(); - if (dbOptions == NULL) { - // TODO: handle error - return -1; - } - - if (pMeta->metaDB.pCache) { - rocksdb_options_set_row_cache(dbOptions, pMeta->metaDB.pCache); - } - - pMeta->metaDB.pDB = rocksdb_open(dbOptions, "db", &err); - if (pMeta->metaDB.pDB == NULL) { - // TODO: handle error - return -1; - } - - rocksdb_options_destroy(dbOptions); - - // Open index DB --------------------------- - idxOptions = rocksdb_options_create(); - if (idxOptions == NULL) { - // TODO: handle error - return -1; - } - - if (pMeta->metaDB.pCache) { - rocksdb_options_set_row_cache(dbOptions, pMeta->metaDB.pCache); - } - - pMeta->metaDB.pIdx = rocksdb_open(idxOptions, "index", &err); - if (pMeta->metaDB.pIdx == NULL) { - // TODO: handle error - rocksdb_close(pMeta->metaDB.pDB); - return -1; - } - - rocksdb_options_destroy(idxOptions); - -#endif return 0; } void metaCloseDB(SMeta *pMeta) { /* TODO */ -#if 0 - // Close index DB - if (pMeta->metaDB.pIdx) { - rocksdb_close(pMeta->metaDB.pIdx); - } - - // Close raw data DB - if (pMeta->metaDB.pDB) { - rocksdb_close(pMeta->metaDB.pDB); - } - - // Destroy cache - if (pMeta->metaDB.pCache) { - rocksdb_cache_destroy(pMeta->metaDB.pCache); - } -#endif } \ No newline at end of file diff --git a/source/dnode/vnode/meta/src/metaIdx.c b/source/dnode/vnode/meta/src/metaIdx.c index f04489d21eba4bd33561f00f1c8ad8e5e222f2db..786b2d101811d6a4ef40e4eb34f471098eb2751f 100644 --- a/source/dnode/vnode/meta/src/metaIdx.c +++ b/source/dnode/vnode/meta/src/metaIdx.c @@ -13,11 +13,36 @@ * along with this program. If not, see . */ -#include "metaIdx.h" +#include "meta.h" +#include "metaDef.h" int metaOpenIdx(SMeta *pMeta) { - /* TODO */ + char idxDir[128]; // TODO + char * err = NULL; + rocksdb_options_t *options = rocksdb_options_create(); + + // TODO + sprintf(idxDir, "%s/index", pMeta->path); + + if (pMeta->pCache) { + rocksdb_options_set_row_cache(options, pMeta->pCache); + } + + pMeta->pIdx = rocksdb_open(options, idxDir, &err); + if (pMeta->pIdx == NULL) { + // TODO: handle error + rocksdb_options_destroy(options); + return -1; + } + + rocksdb_options_destroy(options); + return 0; } -void metaCloseIdx(SMeta *pMeta) { /* TODO */ } \ No newline at end of file +void metaCloseIdx(SMeta *pMeta) { /* TODO */ + if (pMeta->pIdx) { + rocksdb_close(pMeta->pIdx); + pMeta->pIdx = NULL; + } +} \ No newline at end of file diff --git a/source/dnode/vnode/meta/src/metaMain.c b/source/dnode/vnode/meta/src/metaMain.c index 5ffcfb86cba4161519aa874546a795fa61bebca0..000b10a1266e84504c2cbf41c5d15dd8afaed506 100644 --- a/source/dnode/vnode/meta/src/metaMain.c +++ b/source/dnode/vnode/meta/src/metaMain.c @@ -22,6 +22,8 @@ static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions); static void metaFree(SMeta *pMeta); +static int metaOpenImpl(SMeta *pMeta); +static void metaCloseImpl(SMeta *pMeta); SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) { SMeta *pMeta = NULL; @@ -47,26 +49,9 @@ SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) { // Create META path (TODO) taosMkDir(path); - // Open meta cache - if (metaOpenCache(pMeta) < 0) { - // TODO: handle error - return NULL; - } - - // Open meta db - if (metaOpenDB(pMeta) < 0) { - // TODO: handle error - return NULL; - } - - // Open meta index - if (metaOpenIdx(pMeta) < 0) { - // TODO: handle error - return NULL; - } - - // Open meta table uid generator - if (metaOpenUidGnrt(pMeta) < 0) { + // Open meta + if (metaOpenImpl(pMeta) < 0) { + metaFree(pMeta); return NULL; } @@ -75,10 +60,7 @@ SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) { void metaClose(SMeta *pMeta) { if (pMeta) { - metaCloseUidGnrt(pMeta); - metaCloseIdx(pMeta); - metaCloseDB(pMeta); - metaCloseCache(pMeta); + metaCloseImpl(pMeta); metaFree(pMeta); } } @@ -113,6 +95,45 @@ static void metaFree(SMeta *pMeta) { } } +static int metaOpenImpl(SMeta *pMeta) { + // Open meta cache + if (metaOpenCache(pMeta) < 0) { + // TODO: handle error + metaCloseImpl(pMeta); + return -1; + } + + // Open meta db + if (metaOpenDB(pMeta) < 0) { + // TODO: handle error + metaCloseImpl(pMeta); + return -1; + } + + // Open meta index + if (metaOpenIdx(pMeta) < 0) { + // TODO: handle error + metaCloseImpl(pMeta); + return -1; + } + + // Open meta table uid generator + if (metaOpenUidGnrt(pMeta) < 0) { + // TODO: handle error + metaCloseImpl(pMeta); + return -1; + } + + return 0; +} + +static void metaCloseImpl(SMeta *pMeta) { + metaCloseUidGnrt(pMeta); + metaCloseIdx(pMeta); + metaCloseDB(pMeta); + metaCloseCache(pMeta); +} + // OLD ------------------------------------------------------------------- #if 0 static int metaCreateSuperTable(SMeta *pMeta, const char *tbname, const SSuperTableOpts *pSuperTableOpts);