From 0c1a9706426c9e76c498d1583c1a26c2ca47531c Mon Sep 17 00:00:00 2001 From: hzcheng Date: Tue, 18 Feb 2020 13:43:35 +0000 Subject: [PATCH] more --- src/vnode/CMakeLists.txt | 6 +++- src/vnode/common/inc/dataformat.h | 5 ++++ src/vnode/common/src/dataformat.c | 29 ++++++++++++++++++++ src/vnode/tests/CMakeLists.txt | 3 ++ src/vnode/tests/common/CMakeLists.txt | 14 ++++++++++ src/vnode/tests/common/commonDataTests.cpp | 7 +++++ src/vnode/tests/common/commonSChemaTests.cpp | 9 ++++++ src/vnode/tests/tsdb/CMakeLists.txt | 13 +++++++++ src/vnode/tests/tsdb/tsdbTests.cpp | 15 ++++++++++ src/vnode/tsdb/inc/tsdbCache.h | 2 +- src/vnode/tsdb/src/tsdb.c | 17 ++++++++++++ 11 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/vnode/tests/CMakeLists.txt create mode 100644 src/vnode/tests/common/CMakeLists.txt create mode 100644 src/vnode/tests/common/commonDataTests.cpp create mode 100644 src/vnode/tests/common/commonSChemaTests.cpp create mode 100644 src/vnode/tests/tsdb/CMakeLists.txt create mode 100644 src/vnode/tests/tsdb/tsdbTests.cpp diff --git a/src/vnode/CMakeLists.txt b/src/vnode/CMakeLists.txt index 92270a886f..5acf0483ec 100644 --- a/src/vnode/CMakeLists.txt +++ b/src/vnode/CMakeLists.txt @@ -4,4 +4,8 @@ project(tsdb) add_subdirectory(common) -add_subdirectory(tsdb) \ No newline at end of file +add_subdirectory(tsdb) + +enable_testing() + +add_subdirectory(tests) \ No newline at end of file diff --git a/src/vnode/common/inc/dataformat.h b/src/vnode/common/inc/dataformat.h index dd8766f96a..b0389955fb 100644 --- a/src/vnode/common/inc/dataformat.h +++ b/src/vnode/common/inc/dataformat.h @@ -46,6 +46,7 @@ typedef char * SDataCols; // ----------------- Data column structure // ---- operation on SDataRow; +#define TD_DATA_ROW_HEADER_SIZE sizeof(int32_t) #define TD_DATAROW_LEN(pDataRow) (*(int32_t *)(pDataRow)) #define TD_DATAROW_DATA(pDataRow) ((pDataRow) + sizeof(int32_t)) @@ -63,5 +64,9 @@ typedef char * SDataCols; #define TD_DATACOLS_NPOINTS(pDataCols) (*(int32_t *)(pDataCols + sizeof(int32_t))) // ---- +/** + * Get the maximum + */ +int32_t tdGetMaxDataRowSize(SSchema *pSchema); #endif // _TD_DATA_FORMAT_H_ diff --git a/src/vnode/common/src/dataformat.c b/src/vnode/common/src/dataformat.c index f0a2cefc21..f09ea1445b 100644 --- a/src/vnode/common/src/dataformat.c +++ b/src/vnode/common/src/dataformat.c @@ -1,3 +1,32 @@ #include #include "dataformat.h" + +int32_t tdGetMaxDataRowSize(SSchema *pSchema) { + int32_t nbytes = 0; + + for (int32_t i = 0; i < TD_SCHEMA_NCOLS(pSchema); i++) + { + SColumn *pCol = TD_SCHEMA_COLUMN_AT(pSchema, i); + td_datatype_t type = TD_COLUMN_TYPE(pCol); + + nbytes += rowDataLen[type]; + + switch (type) + { + case TD_DATATYPE_VARCHAR: + nbytes += TD_COLUMN_BYTES(pCol); + break; + case TD_DATATYPE_NCHAR: + nbytes += 4 * TD_COLUMN_BYTES(pCol); + break; + case TD_DATATYPE_BINARY: + nbytes += TD_COLUMN_BYTES(pCol); + break; + } + } + + nbytes += TD_DATA_ROW_HEADER_SIZE; + + return nbytes; +} \ No newline at end of file diff --git a/src/vnode/tests/CMakeLists.txt b/src/vnode/tests/CMakeLists.txt new file mode 100644 index 0000000000..786fa9a66f --- /dev/null +++ b/src/vnode/tests/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(common) + +add_subdirectory(tsdb) \ No newline at end of file diff --git a/src/vnode/tests/common/CMakeLists.txt b/src/vnode/tests/common/CMakeLists.txt new file mode 100644 index 0000000000..093768be1a --- /dev/null +++ b/src/vnode/tests/common/CMakeLists.txt @@ -0,0 +1,14 @@ +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) + +message(STATUS "COMMON: ${SOURCE_LIST}") + +add_executable(commonTests ${SOURCE_LIST}) + +target_link_libraries(commonTests gtest gtest_main pthread common) + +add_test( + NAME + unit + COMMAND + ${CMAKE_CURRENT_BINARY_DIR}/commonTests +) \ No newline at end of file diff --git a/src/vnode/tests/common/commonDataTests.cpp b/src/vnode/tests/common/commonDataTests.cpp new file mode 100644 index 0000000000..7becb8699c --- /dev/null +++ b/src/vnode/tests/common/commonDataTests.cpp @@ -0,0 +1,7 @@ +#include + +#include "dataformat.h" + +TEST(commonDataTests, createDataRow) { + EXPECT_EQ(1, 2/2); +} \ No newline at end of file diff --git a/src/vnode/tests/common/commonSChemaTests.cpp b/src/vnode/tests/common/commonSChemaTests.cpp new file mode 100644 index 0000000000..44fd384b61 --- /dev/null +++ b/src/vnode/tests/common/commonSChemaTests.cpp @@ -0,0 +1,9 @@ +#include +#include +#include + +#include "schema.h" + +TEST(commonSchemaTests, createSchema) { + EXPECT_EQ(1, 2/2); +} \ No newline at end of file diff --git a/src/vnode/tests/tsdb/CMakeLists.txt b/src/vnode/tests/tsdb/CMakeLists.txt new file mode 100644 index 0000000000..a942dd917e --- /dev/null +++ b/src/vnode/tests/tsdb/CMakeLists.txt @@ -0,0 +1,13 @@ +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) + +message(STATUS "TSDB: ${SOURCE_LIST}") + +add_executable(tsdbTests ${SOURCE_LIST}) +target_link_libraries(tsdbTests gtest gtest_main pthread tsdb) + +add_test( + NAME + unit + COMMAND + ${CMAKE_CURRENT_BINARY_DIR}/tsdbTests +) \ No newline at end of file diff --git a/src/vnode/tests/tsdb/tsdbTests.cpp b/src/vnode/tests/tsdb/tsdbTests.cpp new file mode 100644 index 0000000000..b3e6e22dad --- /dev/null +++ b/src/vnode/tests/tsdb/tsdbTests.cpp @@ -0,0 +1,15 @@ +#include +#include + +#include "tsdb.h" + +TEST(TsdbTest, createTsdbRepo) { + STSDBCfg *pCfg = (STSDBCfg *)malloc(sizeof(STSDBCfg)); + + pCfg->rootDir = "/var/lib/taos/"; + + int32_t err_num = 0; + + tsdb_repo_t *pRepo = tsdbCreateRepo(pCfg, &err_num); + ASSERT_EQ(pRepo, NULL); +} \ No newline at end of file diff --git a/src/vnode/tsdb/inc/tsdbCache.h b/src/vnode/tsdb/inc/tsdbCache.h index 049cdc0847..b439be08aa 100644 --- a/src/vnode/tsdb/inc/tsdbCache.h +++ b/src/vnode/tsdb/inc/tsdbCache.h @@ -10,7 +10,7 @@ typedef struct { int64_t skey; // start key int64_t ekey; // end key - int32_t numOfRows // numOfRows + int32_t numOfRows; // numOfRows } STableCacheInfo; typedef struct _tsdb_cache_block { diff --git a/src/vnode/tsdb/src/tsdb.c b/src/vnode/tsdb/src/tsdb.c index 7e13e3183a..031dd135c6 100644 --- a/src/vnode/tsdb/src/tsdb.c +++ b/src/vnode/tsdb/src/tsdb.c @@ -1,9 +1,14 @@ #include #include #include +#include +#include +#include +#include // #include "taosdef.h" // #include "disk.h" +#include "tsdbFile.h" #include "tsdb.h" #include "tsdbCache.h" #include "tsdbMeta.h" @@ -33,6 +38,11 @@ typedef struct STSDBRepo { // Check the correctness of the TSDB configuration static int32_t tsdbCheckCfg(STSDBCfg *pCfg) { + if (pCfg->rootDir == NULL) return -1; + + if (access(pCfg->rootDir, F_OK|R_OK|W_OK) == -1) { + return -1; + } // TODO return 0; } @@ -42,6 +52,7 @@ tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error) { err = tsdbCheckCfg(pCfg); if (err != 0) { // TODO: deal with the error here + return NULL; } STSDBRepo *pRepo = (STSDBRepo *)malloc(sizeof(STSDBRepo)); @@ -65,6 +76,12 @@ tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error) { return NULL; } + // Create the Meta data file and data directory + + char *pTsdbMetaFName = tsdbGetFileName(pCfg->rootDir, "tsdb", TSDB_FILE_TYPE_META); + // int fd = open(pTsdbMetaFName, ) + // if (open) + return (tsdb_repo_t *)pRepo; } -- GitLab