提交 0c1a9706 编写于 作者: H hzcheng

more

上级 83edc110
...@@ -5,3 +5,7 @@ project(tsdb) ...@@ -5,3 +5,7 @@ project(tsdb)
add_subdirectory(common) add_subdirectory(common)
add_subdirectory(tsdb) add_subdirectory(tsdb)
enable_testing()
add_subdirectory(tests)
\ No newline at end of file
...@@ -46,6 +46,7 @@ typedef char * SDataCols; ...@@ -46,6 +46,7 @@ typedef char * SDataCols;
// ----------------- Data column structure // ----------------- Data column structure
// ---- operation on SDataRow; // ---- operation on SDataRow;
#define TD_DATA_ROW_HEADER_SIZE sizeof(int32_t)
#define TD_DATAROW_LEN(pDataRow) (*(int32_t *)(pDataRow)) #define TD_DATAROW_LEN(pDataRow) (*(int32_t *)(pDataRow))
#define TD_DATAROW_DATA(pDataRow) ((pDataRow) + sizeof(int32_t)) #define TD_DATAROW_DATA(pDataRow) ((pDataRow) + sizeof(int32_t))
...@@ -63,5 +64,9 @@ typedef char * SDataCols; ...@@ -63,5 +64,9 @@ typedef char * SDataCols;
#define TD_DATACOLS_NPOINTS(pDataCols) (*(int32_t *)(pDataCols + sizeof(int32_t))) #define TD_DATACOLS_NPOINTS(pDataCols) (*(int32_t *)(pDataCols + sizeof(int32_t)))
// ---- // ----
/**
* Get the maximum
*/
int32_t tdGetMaxDataRowSize(SSchema *pSchema);
#endif // _TD_DATA_FORMAT_H_ #endif // _TD_DATA_FORMAT_H_
#include <stdlib.h> #include <stdlib.h>
#include "dataformat.h" #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
add_subdirectory(common)
add_subdirectory(tsdb)
\ No newline at end of file
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
#include <gtest/gtest.h>
#include "dataformat.h"
TEST(commonDataTests, createDataRow) {
EXPECT_EQ(1, 2/2);
}
\ No newline at end of file
#include <gtest/gtest.h>
#include <stdlib.h>
#include <stdio.h>
#include "schema.h"
TEST(commonSchemaTests, createSchema) {
EXPECT_EQ(1, 2/2);
}
\ No newline at end of file
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
#include <gtest/gtest.h>
#include <stdlib.h>
#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
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
typedef struct { typedef struct {
int64_t skey; // start key int64_t skey; // start key
int64_t ekey; // end key int64_t ekey; // end key
int32_t numOfRows // numOfRows int32_t numOfRows; // numOfRows
} STableCacheInfo; } STableCacheInfo;
typedef struct _tsdb_cache_block { typedef struct _tsdb_cache_block {
......
#include <pthread.h> #include <pthread.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
// #include "taosdef.h" // #include "taosdef.h"
// #include "disk.h" // #include "disk.h"
#include "tsdbFile.h"
#include "tsdb.h" #include "tsdb.h"
#include "tsdbCache.h" #include "tsdbCache.h"
#include "tsdbMeta.h" #include "tsdbMeta.h"
...@@ -33,6 +38,11 @@ typedef struct STSDBRepo { ...@@ -33,6 +38,11 @@ typedef struct STSDBRepo {
// Check the correctness of the TSDB configuration // Check the correctness of the TSDB configuration
static int32_t tsdbCheckCfg(STSDBCfg *pCfg) { 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 // TODO
return 0; return 0;
} }
...@@ -42,6 +52,7 @@ tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error) { ...@@ -42,6 +52,7 @@ tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error) {
err = tsdbCheckCfg(pCfg); err = tsdbCheckCfg(pCfg);
if (err != 0) { if (err != 0) {
// TODO: deal with the error here // TODO: deal with the error here
return NULL;
} }
STSDBRepo *pRepo = (STSDBRepo *)malloc(sizeof(STSDBRepo)); STSDBRepo *pRepo = (STSDBRepo *)malloc(sizeof(STSDBRepo));
...@@ -65,6 +76,12 @@ tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error) { ...@@ -65,6 +76,12 @@ tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error) {
return NULL; 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; return (tsdb_repo_t *)pRepo;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册