提交 d352819f 编写于 作者: H hzcheng

refactor code

上级 798d2171
......@@ -32,6 +32,24 @@ extern "C" {
typedef void tsdb_repo_t; // use void to hide implementation details from outside
// --------- TSDB REPOSITORY CONFIGURATION DEFINITION
typedef struct {
int8_t precision;
int32_t tsdbId;
int32_t maxTables; // maximum number of tables this repository can have
int32_t daysPerFile; // day per file sharding policy
int32_t minRowsPerFileBlock; // minimum rows per file block
int32_t maxRowsPerFileBlock; // maximum rows per file block
int32_t keep; // day of data to keep
int64_t maxCacheSize; // maximum cache size this TSDB can use
} STsdbCfg;
void tsdbSetDefaultCfg(STsdbCfg *pCfg);
STsdbCfg *tsdbCreateDefaultCfg();
void tsdbFreeCfg(STsdbCfg *pCfg);
// --------- TSDB REPOSITORY DEFINITION
typedef struct {
int64_t uid; // the unique table ID
int32_t tid; // the table ID in the repository.
......@@ -55,18 +73,6 @@ typedef struct {
enum { TSDB_PRECISION_MILLI, TSDB_PRECISION_MICRO, TSDB_PRECISION_NANO };
// the TSDB repository configuration
typedef struct {
int8_t precision;
int32_t tsdbId;
int32_t maxTables; // maximum number of tables this repository can have
int32_t daysPerFile; // day per file sharding policy
int32_t minRowsPerFileBlock; // minimum rows per file block
int32_t maxRowsPerFileBlock; // maximum rows per file block
int32_t keep; // day of data to keep
int64_t maxCacheSize; // maximum cache size this TSDB can use
} STsdbCfg;
// the TSDB repository info
typedef struct STsdbRepoInfo {
STsdbCfg tsdbCfg;
......@@ -100,16 +106,6 @@ typedef struct {
int64_t tableTotalDiskSize; // In bytes
} STableInfo;
/**
* Create a configuration for TSDB default
* @return a pointer to a configuration. the configuration must call tsdbFreeCfg to free memory after usage
*/
STsdbCfg *tsdbCreateDefaultCfg();
/**
* Free
*/
void tsdbFreeCfg(STsdbCfg *pCfg);
/**
* Create a new TSDB repository
......
......@@ -82,9 +82,11 @@ static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlock *pBlock);
#define TSDB_IS_REPO_ACTIVE(pRepo) ((pRepo)->state == TSDB_REPO_STATE_ACTIVE)
#define TSDB_IS_REPO_CLOSED(pRepo) ((pRepo)->state == TSDB_REPO_STATE_CLOSED)
STsdbCfg *tsdbCreateDefaultCfg() {
STsdbCfg *pCfg = (STsdbCfg *)malloc(sizeof(STsdbCfg));
if (pCfg == NULL) return NULL;
/**
* Set the default TSDB configuration
*/
void tsdbSetDefaultCfg(STsdbCfg *pCfg) {
if (pCfg == NULL) return;
pCfg->precision = -1;
pCfg->tsdbId = 0;
......@@ -94,6 +96,18 @@ STsdbCfg *tsdbCreateDefaultCfg() {
pCfg->maxRowsPerFileBlock = -1;
pCfg->keep = -1;
pCfg->maxCacheSize = -1;
}
/**
* Create a configuration for TSDB default
* @return a pointer to a configuration. the configuration object
* must call tsdbFreeCfg to free memory after usage
*/
STsdbCfg *tsdbCreateDefaultCfg() {
STsdbCfg *pCfg = (STsdbCfg *)malloc(sizeof(STsdbCfg));
if (pCfg == NULL) return NULL;
tsdbSetDefaultCfg(pCfg);
return pCfg;
}
......
......@@ -5,52 +5,30 @@
#include "dataformat.h"
#include "tsdbMeta.h"
TEST(TsdbTest, createTable) {
STsdbMeta *pMeta = tsdbCreateMeta(100);
ASSERT_NE(pMeta, nullptr);
STableCfg config;
config.tableId.tid = 0;
config.tableId.uid = 98868728187539L;
config.numOfCols = 5;
config.schema = tdNewSchema(config.numOfCols);
for (int i = 0; i < schemaNCols(config.schema); i++) {
STColumn *pCol = tdNewCol(TSDB_DATA_TYPE_BIGINT, i, 0);
tdColCpy(schemaColAt(config.schema, i), pCol);
tdFreeCol(pCol);
}
config.tagValues = nullptr;
tsdbCreateTableImpl(pMeta, &config);
STable *pTable = tsdbGetTableByUid(pMeta, config.tableId.uid);
ASSERT_NE(pTable, nullptr);
}
TEST(TsdbTest, createRepo) {
STsdbCfg *pCfg = tsdbCreateDefaultCfg();
STsdbCfg config;
// Create a tsdb repository
tsdb_repo_t *pRepo = tsdbCreateRepo("/root/mnt/test/vnode0", pCfg, NULL);
tsdbSetDefaultCfg(&config);
tsdb_repo_t *pRepo = tsdbCreateRepo("/home/ubuntu/work/ttest/vnode0", &config, NULL);
ASSERT_NE(pRepo, nullptr);
tsdbFreeCfg(pCfg);
// create a normal table in this repository
STableCfg config;
config.tableId.tid = 0;
config.tableId.uid = 98868728187539L;
config.numOfCols = 5;
config.schema = tdNewSchema(config.numOfCols);
STColumn *pCol = tdNewCol(TSDB_DATA_TYPE_TIMESTAMP, 0, 0);
tdColCpy(schemaColAt(config.schema, 0), pCol);
tdFreeCol(pCol);
for (int i = 1; i < schemaNCols(config.schema); i++) {
pCol = tdNewCol(TSDB_DATA_TYPE_BIGINT, i, 0);
tdColCpy(schemaColAt(config.schema, i), pCol);
tdFreeCol(pCol);
}
// // create a normal table in this repository
// STableCfg config;
// config.tableId.tid = 0;
// config.tableId.uid = 98868728187539L;
// config.numOfCols = 5;
// config.schema = tdNewSchema(config.numOfCols);
// STColumn *pCol = tdNewCol(TSDB_DATA_TYPE_TIMESTAMP, 0, 0);
// tdColCpy(schemaColAt(config.schema, 0), pCol);
// tdFreeCol(pCol);
// for (int i = 1; i < schemaNCols(config.schema); i++) {
// pCol = tdNewCol(TSDB_DATA_TYPE_BIGINT, i, 0);
// tdColCpy(schemaColAt(config.schema, i), pCol);
// tdFreeCol(pCol);
// }
tsdbCreateTable(pRepo, &config);
// tsdbCreateTable(pRepo, &config);
// Write some data
// int32_t size = sizeof(SSubmitMsg) + sizeof(SSubmitBlock) + tdMaxRowDataBytes(config.schema) * 10 + sizeof(int32_t);
......@@ -89,6 +67,28 @@ TEST(TsdbTest, createRepo) {
// tdFreeDataRow(row);
tdFreeSchema(config.schema);
tsdbDropRepo(pRepo);
}
\ No newline at end of file
// tdFreeSchema(config.schema);
// tsdbDropRepo(pRepo);
}
TEST(TsdbTest, DISABLED_createTable) {
STsdbMeta *pMeta = tsdbCreateMeta(100);
ASSERT_NE(pMeta, nullptr);
STableCfg config;
config.tableId.tid = 0;
config.tableId.uid = 98868728187539L;
config.numOfCols = 5;
config.schema = tdNewSchema(config.numOfCols);
for (int i = 0; i < schemaNCols(config.schema); i++) {
STColumn *pCol = tdNewCol(TSDB_DATA_TYPE_BIGINT, i, 0);
tdColCpy(schemaColAt(config.schema, i), pCol);
tdFreeCol(pCol);
}
config.tagValues = nullptr;
tsdbCreateTableImpl(pMeta, &config);
STable *pTable = tsdbGetTableByUid(pMeta, config.tableId.uid);
ASSERT_NE(pTable, nullptr);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册