diff --git a/CMakeLists.txt b/CMakeLists.txt index 65d1e133d77018d1b940927d5414b3723af2ba7f..f27f5f1672dd78da3031c7907cd21f2f05ad361c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ if(${BUILD_WITH_LEVELDB}) endif(${BUILD_WITH_LEVELDB}) ## rocksdb -option(BUILD_WITH_ROCKSDB "If build with rocksdb" OFF) +option(BUILD_WITH_ROCKSDB "If build with rocksdb" ON) if(${BUILD_WITH_ROCKSDB}) cat("${CMAKE_SUPPORT_DIR}/rocksdb_CMakeLists.txt.in" ${DEPS_TMP_FILE}) endif(${BUILD_WITH_ROCKSDB}) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index e28651824a4ecb2bc24b75f08d4b186dde87b456..05c154af8620d6e34945d18847aeb16cef11e915 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -48,6 +48,7 @@ endif(${BUILD_WITH_LEVELDB}) if(${BUILD_WITH_ROCKSDB}) option(WITH_TESTS "" OFF) option(WITH_BENCHMARK_TOOLS "" OFF) + option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" OFF) add_subdirectory(rocksdb) target_include_directories( rocksdb diff --git a/include/common/trow.h b/include/common/trow.h index be4b7af32a7d92d313b7fdec83a2bceb600ec827..6094425bbf3d65524d97f3228872578a56ac2b2c 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -20,6 +20,13 @@ extern "C" { #endif +typedef struct SRow SRow; + +#define rowType(r) +#define rowLen(r) +#define rowVersion(r) +#define rowNCols(r) + #ifdef __cplusplus } #endif diff --git a/source/server/vnode/CMakeLists.txt b/source/server/vnode/CMakeLists.txt index 20b50bf24425296a9074f614d4c2a548e8e1a339..5e11e4556798d5ed56776b69ebf530617fa27f6e 100644 --- a/source/server/vnode/CMakeLists.txt +++ b/source/server/vnode/CMakeLists.txt @@ -3,7 +3,7 @@ add_subdirectory(tq) add_subdirectory(tsdb) aux_source_directory(src VNODE_SRC) -add_library(vnode ${VNODE_SRC}) +add_library(vnode STATIC ${VNODE_SRC}) target_include_directories( vnode PUBLIC "${CMAKE_SOURCE_DIR}/include/server/vnode" diff --git a/source/server/vnode/meta/CMakeLists.txt b/source/server/vnode/meta/CMakeLists.txt index 832e13a15502ac2c07520706b2e54583ae03a5ca..113bcd5d6f3ed87e2befd43a295f49a1321c05b4 100644 --- a/source/server/vnode/meta/CMakeLists.txt +++ b/source/server/vnode/meta/CMakeLists.txt @@ -1,5 +1,5 @@ aux_source_directory(src META_SRC) -add_library(meta ${META_SRC}) +add_library(meta STATIC ${META_SRC}) target_include_directories( meta PUBLIC "${CMAKE_SOURCE_DIR}/include/server/vnode/meta" @@ -8,4 +8,9 @@ target_include_directories( target_link_libraries( meta PUBLIC common -) \ No newline at end of file +) +target_link_libraries(meta PUBLIC rocksdb) + +# if(${BUILD_TEST}) +# add_subdirectory(test) +# endif(${BUILD_TEST}) diff --git a/source/server/vnode/meta/src/meta.c b/source/server/vnode/meta/src/meta.c index d05fa1754f0e4db75cf761dc89bbca641d3ad686..f35de5eb9e895993bbca35ca259d8aae6c7fd4c0 100644 --- a/source/server/vnode/meta/src/meta.c +++ b/source/server/vnode/meta/src/meta.c @@ -13,6 +13,72 @@ * along with this program. If not, see . */ +#include + +#include "thash.h" +#include "tlist.h" +#include "tlockfree.h" +#include "ttypes.h" + #include "meta.h" +typedef struct STable { + uint64_t uid; + tstr * name; + uint64_t suid; + SArray * schema; +} STable; + +typedef struct STableObj { + bool pin; + uint64_t ref; + SRWLatch latch; + uint64_t offset; + SList * ctbList; // child table list + STable * pTable; +} STableObj; + +struct SMeta { + pthread_rwlock_t rwLock; + + SHashObj * pTableObjHash; // uid --> STableObj + SList * stbList; // super table list + rocksdb_t *tbnameDb; // tbname --> uid + rocksdb_t *tagDb; // uid --> tag + rocksdb_t *schemaDb; + size_t totalUsed; +}; + +SMeta *metaOpen(SMetaOptions *options) { + SMeta *pMeta = NULL; + char * err = NULL; + + pMeta = (SMeta *)calloc(1, sizeof(*pMeta)); + if (pMeta == NULL) { + return NULL; + } + + pthread_rwlock_init(&(pMeta->rwLock), NULL); + + pMeta->pTableObjHash = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + + pMeta->stbList = tdListNew(sizeof(STableObj *)); + + // Open tbname DB + rocksdb_options_t *tbnameDbOptions = rocksdb_options_create(); + pMeta->tbnameDb = rocksdb_open(tbnameDbOptions, "tbname_uid_db", &err); + + // Open tag DB + pMeta->tagDb = rocksdb_open(tbnameDbOptions, "uid_tag_db", &err); + + // Open schema DB + pMeta->schemaDb = rocksdb_open(tbnameDbOptions, "schema_db", &err); + + return pMeta; +} + +void metaClose(SMeta *pMeta) { + // TODO +} + int metaCommit(SMeta *meta) { return 0; } \ No newline at end of file diff --git a/source/server/vnode/meta/test/CMakeLists.txt b/source/server/vnode/meta/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ca82d3fb8344212d1da7a1209559e4413cd9398a --- /dev/null +++ b/source/server/vnode/meta/test/CMakeLists.txt @@ -0,0 +1,18 @@ +add_executable(metaTest "") +target_sources(metaTest + PRIVATE + "../src/meta.c" + "metaTests.cpp" +) +target_include_directories(metaTest + PUBLIC + "${CMAKE_SOURCE_DIR}/include/server/vnode/meta" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) +target_link_libraries(metaTest + os + util + common + rocksdb + gtest_main +) \ 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 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c62ae0aa0224a6724839fe41fe692f2b1dae37d6 100644 --- a/source/server/vnode/meta/test/metaTests.cpp +++ b/source/server/vnode/meta/test/metaTests.cpp @@ -0,0 +1,8 @@ +#include +#include + +#include "meta.h" + +TEST(MetaTest, meta_open_test) { + std::cout << "Hello META!" << std::endl; +} \ No newline at end of file