From dfa8e5be9b8428774386bad4025966162db65479 Mon Sep 17 00:00:00 2001 From: hzcheng Date: Fri, 17 Apr 2020 14:09:52 +0800 Subject: [PATCH] TD-100 --- src/inc/tsdb.h | 1 + src/tsdb/src/tsdbMain.c | 31 +++++++++++++++++++------------ src/vnode/src/vnodeMain.c | 1 + 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index f2d0b6b0c8..7bb6365865 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -46,6 +46,7 @@ typedef struct { // --------- TSDB REPOSITORY CONFIGURATION DEFINITION typedef struct { int8_t precision; + int8_t compression; int32_t tsdbId; int32_t maxTables; // maximum number of tables this repository can have int32_t daysPerFile; // day per file sharding policy diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 263c09f16c..fd01e8ce71 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -12,15 +12,16 @@ #include #include -// #include "taosdef.h" -// #include "disk.h" #include "os.h" #include "talgo.h" #include "tsdb.h" #include "tsdbMain.h" +#include "tscompression.h" #define TSDB_DEFAULT_PRECISION TSDB_PRECISION_MILLI // default precision #define IS_VALID_PRECISION(precision) (((precision) >= TSDB_PRECISION_MILLI) && ((precision) <= TSDB_PRECISION_NANO)) +#define TSDB_DEFAULT_COMPRESSION TWO_STAGE_COMP +#define IS_VALID_COMPRESSION(compression) (((compression) >= NO_COMPRESSION) && ((compression) <= TWO_STAGE_COMP)) #define TSDB_MIN_ID 0 #define TSDB_MAX_ID INT_MAX #define TSDB_MIN_TABLES 10 @@ -83,6 +84,7 @@ void tsdbSetDefaultCfg(STsdbCfg *pCfg) { pCfg->maxRowsPerFileBlock = -1; pCfg->keep = -1; pCfg->maxCacheSize = -1; + pCfg->compression = TWO_STAGE_COMP; } /** @@ -547,6 +549,13 @@ static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) { if (!IS_VALID_PRECISION(pCfg->precision)) return -1; } + // Check compression + if (pCfg->compression == -1) { + pCfg->compression = TSDB_DEFAULT_COMPRESSION; + } else { + if (!IS_VALID_COMPRESSION(pCfg->compression)) return -1; + } + // Check tsdbId if (pCfg->tsdbId < 0) return -1; @@ -841,16 +850,14 @@ static void *tsdbCommitData(void *arg) { } // Create a write helper for commit data - SHelperCfg hcfg = { - .type = TSDB_WRITE_HELPER, - .maxTables = pCfg->maxTables, - .maxRowSize = pMeta->maxRowBytes, - .maxRows = pCfg->maxRowsPerFileBlock, - .maxCols = pMeta->maxCols, - .minRowsPerFileBlock = pCfg->minRowsPerFileBlock, - .maxRowsPerFileBlock = pCfg->maxRowsPerFileBlock, - .compress = 2 // TODO make it a configuration - }; + SHelperCfg hcfg = {.type = TSDB_WRITE_HELPER, + .maxTables = pCfg->maxTables, + .maxRowSize = pMeta->maxRowBytes, + .maxRows = pCfg->maxRowsPerFileBlock, + .maxCols = pMeta->maxCols, + .minRowsPerFileBlock = pCfg->minRowsPerFileBlock, + .maxRowsPerFileBlock = pCfg->maxRowsPerFileBlock, + .compress = pCfg->compression}; if (tsdbInitHelper(&whelper, &hcfg) < 0) goto _exit; if ((pDataCols = tdNewDataCols(pMeta->maxRowBytes, pMeta->maxCols, pCfg->maxRowsPerFileBlock)) == NULL) goto _exit; diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 7ec9b0fef7..33c979aa2e 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -88,6 +88,7 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { STsdbCfg tsdbCfg = {0}; tsdbCfg.precision = pVnodeCfg->cfg.precision; + tsdbCfg.compression = -1; tsdbCfg.tsdbId = pVnodeCfg->cfg.vgId; tsdbCfg.maxTables = pVnodeCfg->cfg.maxSessions; tsdbCfg.daysPerFile = pVnodeCfg->cfg.daysPerFile; -- GitLab