diff --git a/source/server/vnode/meta/src/meta.c b/source/server/vnode/meta/src/meta.c index f35de5eb9e895993bbca35ca259d8aae6c7fd4c0..ff8186d1d7327cee908a3ece953779f46f7099d8 100644 --- a/source/server/vnode/meta/src/meta.c +++ b/source/server/vnode/meta/src/meta.c @@ -22,6 +22,7 @@ #include "meta.h" +/* -------------------- Structures -------------------- */ typedef struct STable { uint64_t uid; tstr * name; @@ -46,9 +47,12 @@ struct SMeta { rocksdb_t *tbnameDb; // tbname --> uid rocksdb_t *tagDb; // uid --> tag rocksdb_t *schemaDb; + rocksdb_t *tagIdx; size_t totalUsed; }; +/* -------------------- Methods -------------------- */ + SMeta *metaOpen(SMetaOptions *options) { SMeta *pMeta = NULL; char * err = NULL; @@ -64,21 +68,40 @@ SMeta *metaOpen(SMetaOptions *options) { pMeta->stbList = tdListNew(sizeof(STableObj *)); + // Options + rocksdb_options_t *dbOptions = rocksdb_options_create(); + rocksdb_options_set_create_if_missing(dbOptions, 1); + + taosMkDir("meta"); + // Open tbname DB - rocksdb_options_t *tbnameDbOptions = rocksdb_options_create(); - pMeta->tbnameDb = rocksdb_open(tbnameDbOptions, "tbname_uid_db", &err); + pMeta->tbnameDb = rocksdb_open(dbOptions, "meta/tbname_uid_db", &err); // Open tag DB - pMeta->tagDb = rocksdb_open(tbnameDbOptions, "uid_tag_db", &err); + pMeta->tagDb = rocksdb_open(dbOptions, "meta/uid_tag_db", &err); // Open schema DB - pMeta->schemaDb = rocksdb_open(tbnameDbOptions, "schema_db", &err); + pMeta->schemaDb = rocksdb_open(dbOptions, "meta/schema_db", &err); + + // Open tag index + pMeta->tagIdx = rocksdb_open(dbOptions, "meta/tag_idx_db", &err); + + rocksdb_options_destroy(dbOptions); return pMeta; } void metaClose(SMeta *pMeta) { - // TODO + if (pMeta) { + rocksdb_close(pMeta->tagIdx); + rocksdb_close(pMeta->schemaDb); + rocksdb_close(pMeta->tagDb); + rocksdb_close(pMeta->tbnameDb); + + tdListFree(pMeta->stbList); + taosHashCleanup(pMeta->pTableObjHash); + pthread_rwlock_destroy(&(pMeta->rwLock)); + } } int metaCommit(SMeta *meta) { return 0; } \ No newline at end of file diff --git a/source/server/vnode/meta/test/metaTests.cpp b/source/server/vnode/meta/test/metaTests.cpp index ab204455f21ba17e94de860e6541517dfbfb7e1b..caf77f720ae3f45a40e036c35f141702a2631054 100644 --- a/source/server/vnode/meta/test/metaTests.cpp +++ b/source/server/vnode/meta/test/metaTests.cpp @@ -4,6 +4,9 @@ #include "meta.h" TEST(MetaTest, meta_open_test) { - metaOpen(NULL); - std::cout << "Hello META!" << std::endl; + SMeta *meta = metaOpen(NULL); + std::cout << "Meta is opened!" << std::endl; + + metaClose(meta); + std::cout << "Meta is closed!" << std::endl; } \ No newline at end of file