提交 d352819f 编写于 作者: H hzcheng

refactor code

上级 798d2171
...@@ -32,6 +32,24 @@ extern "C" { ...@@ -32,6 +32,24 @@ extern "C" {
typedef void tsdb_repo_t; // use void to hide implementation details from outside 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 { typedef struct {
int64_t uid; // the unique table ID int64_t uid; // the unique table ID
int32_t tid; // the table ID in the repository. int32_t tid; // the table ID in the repository.
...@@ -55,18 +73,6 @@ typedef struct { ...@@ -55,18 +73,6 @@ typedef struct {
enum { TSDB_PRECISION_MILLI, TSDB_PRECISION_MICRO, TSDB_PRECISION_NANO }; 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 // the TSDB repository info
typedef struct STsdbRepoInfo { typedef struct STsdbRepoInfo {
STsdbCfg tsdbCfg; STsdbCfg tsdbCfg;
...@@ -100,16 +106,6 @@ typedef struct { ...@@ -100,16 +106,6 @@ typedef struct {
int64_t tableTotalDiskSize; // In bytes int64_t tableTotalDiskSize; // In bytes
} STableInfo; } 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 * Create a new TSDB repository
......
...@@ -82,9 +82,11 @@ static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlock *pBlock); ...@@ -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_ACTIVE(pRepo) ((pRepo)->state == TSDB_REPO_STATE_ACTIVE)
#define TSDB_IS_REPO_CLOSED(pRepo) ((pRepo)->state == TSDB_REPO_STATE_CLOSED) #define TSDB_IS_REPO_CLOSED(pRepo) ((pRepo)->state == TSDB_REPO_STATE_CLOSED)
STsdbCfg *tsdbCreateDefaultCfg() { /**
STsdbCfg *pCfg = (STsdbCfg *)malloc(sizeof(STsdbCfg)); * Set the default TSDB configuration
if (pCfg == NULL) return NULL; */
void tsdbSetDefaultCfg(STsdbCfg *pCfg) {
if (pCfg == NULL) return;
pCfg->precision = -1; pCfg->precision = -1;
pCfg->tsdbId = 0; pCfg->tsdbId = 0;
...@@ -94,6 +96,18 @@ STsdbCfg *tsdbCreateDefaultCfg() { ...@@ -94,6 +96,18 @@ STsdbCfg *tsdbCreateDefaultCfg() {
pCfg->maxRowsPerFileBlock = -1; pCfg->maxRowsPerFileBlock = -1;
pCfg->keep = -1; pCfg->keep = -1;
pCfg->maxCacheSize = -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; return pCfg;
} }
......
...@@ -5,52 +5,30 @@ ...@@ -5,52 +5,30 @@
#include "dataformat.h" #include "dataformat.h"
#include "tsdbMeta.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) { TEST(TsdbTest, createRepo) {
STsdbCfg *pCfg = tsdbCreateDefaultCfg(); STsdbCfg config;
// Create a tsdb repository // 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); ASSERT_NE(pRepo, nullptr);
tsdbFreeCfg(pCfg);
// create a normal table in this repository // // create a normal table in this repository
STableCfg config; // STableCfg config;
config.tableId.tid = 0; // config.tableId.tid = 0;
config.tableId.uid = 98868728187539L; // config.tableId.uid = 98868728187539L;
config.numOfCols = 5; // config.numOfCols = 5;
config.schema = tdNewSchema(config.numOfCols); // config.schema = tdNewSchema(config.numOfCols);
STColumn *pCol = tdNewCol(TSDB_DATA_TYPE_TIMESTAMP, 0, 0); // STColumn *pCol = tdNewCol(TSDB_DATA_TYPE_TIMESTAMP, 0, 0);
tdColCpy(schemaColAt(config.schema, 0), pCol); // tdColCpy(schemaColAt(config.schema, 0), pCol);
tdFreeCol(pCol); // tdFreeCol(pCol);
for (int i = 1; i < schemaNCols(config.schema); i++) { // for (int i = 1; i < schemaNCols(config.schema); i++) {
pCol = tdNewCol(TSDB_DATA_TYPE_BIGINT, i, 0); // pCol = tdNewCol(TSDB_DATA_TYPE_BIGINT, i, 0);
tdColCpy(schemaColAt(config.schema, i), pCol); // tdColCpy(schemaColAt(config.schema, i), pCol);
tdFreeCol(pCol); // tdFreeCol(pCol);
} // }
tsdbCreateTable(pRepo, &config); // tsdbCreateTable(pRepo, &config);
// Write some data // Write some data
// int32_t size = sizeof(SSubmitMsg) + sizeof(SSubmitBlock) + tdMaxRowDataBytes(config.schema) * 10 + sizeof(int32_t); // int32_t size = sizeof(SSubmitMsg) + sizeof(SSubmitBlock) + tdMaxRowDataBytes(config.schema) * 10 + sizeof(int32_t);
...@@ -89,6 +67,28 @@ TEST(TsdbTest, createRepo) { ...@@ -89,6 +67,28 @@ TEST(TsdbTest, createRepo) {
// tdFreeDataRow(row); // tdFreeDataRow(row);
tdFreeSchema(config.schema); // tdFreeSchema(config.schema);
tsdbDropRepo(pRepo); // tsdbDropRepo(pRepo);
} }
\ No newline at end of file
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.
先完成此消息的编辑!
想要评论请 注册