more
This commit is contained in:
parent
83edc110fe
commit
0c1a970642
|
@ -5,3 +5,7 @@ project(tsdb)
|
||||||
add_subdirectory(common)
|
add_subdirectory(common)
|
||||||
|
|
||||||
add_subdirectory(tsdb)
|
add_subdirectory(tsdb)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
add_subdirectory(tests)
|
|
@ -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;
|
||||||
#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_
|
||||||
|
|
|
@ -1,3 +1,32 @@
|
||||||
#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;
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
add_subdirectory(common)
|
||||||
|
|
||||||
|
add_subdirectory(tsdb)
|
|
@ -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
|
||||||
|
)
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "dataformat.h"
|
||||||
|
|
||||||
|
TEST(commonDataTests, createDataRow) {
|
||||||
|
EXPECT_EQ(1, 2/2);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "schema.h"
|
||||||
|
|
||||||
|
TEST(commonSchemaTests, createSchema) {
|
||||||
|
EXPECT_EQ(1, 2/2);
|
||||||
|
}
|
|
@ -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
|
||||||
|
)
|
|
@ -0,0 +1,15 @@
|
||||||
|
#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);
|
||||||
|
}
|
|
@ -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 {
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
#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 {
|
||||||
|
|
||||||
// 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) {
|
||||||
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) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue