From 15b8a7f55a7417e6694e67486a801d158cbf2c07 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 3 Nov 2021 10:34:53 +0800 Subject: [PATCH] more --- source/dnode/vnode/meta/src/metaCache.c | 13 ++++- source/dnode/vnode/meta/src/metaDB.c | 70 +------------------------ source/dnode/vnode/meta/src/metaIdx.c | 31 +++++++++-- source/dnode/vnode/meta/src/metaMain.c | 69 +++++++++++++++--------- 4 files changed, 86 insertions(+), 97 deletions(-) diff --git a/source/dnode/vnode/meta/src/metaCache.c b/source/dnode/vnode/meta/src/metaCache.c index 1e848d434e..9166f1724a 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 5c3d9d0a02..2fcf424971 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 f04489d21e..786b2d1018 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 5ffcfb86cb..000b10a126 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); -- GitLab