tglobal.c 18.7 KB
Newer Older
S
slguan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#define _DEFAULT_SOURCE
#include "os.h"
S
Shengliang Guan 已提交
18

S
slguan 已提交
19 20
#include "taosdef.h"
#include "taoserror.h"
S
Shengliang Guan 已提交
21 22
#include "tcompare.h"
#include "tep.h"
S
slguan 已提交
23
#include "tglobal.h"
S
Shengliang Guan 已提交
24
#include "tlocale.h"
S
Shengliang Guan 已提交
25 26 27 28
#include "tlog.h"
#include "ttimezone.h"
#include "tutil.h"
#include "ulog.h"
S
slguan 已提交
29

H
Hui Li 已提交
30

S
Shengliang Guan 已提交
31
// common
S
Shengliang Guan 已提交
32
int32_t tsMaxShellConns = 50000;
S
Shengliang 已提交
33
int32_t tsMaxConnections = 50000;
S
Shengliang Guan 已提交
34
int32_t tsShellActivityTimer = 3;  // second
H
Haojun Liao 已提交
35
float   tsNumOfThreadsPerCore = 1.0f;
36
int32_t tsNumOfCommitThreads = 4;
37
float   tsRatioOfQueryCores = 1.0f;
S
Shengliang Guan 已提交
38
int8_t  tsDaylight = 0;
S
Shengliang Guan 已提交
39
int8_t  tsEnableCoreFile = 0;
S
Shengliang Guan 已提交
40
int32_t tsMaxBinaryDisplayWidth = 30;
S
Shengliang Guan 已提交
41 42 43
int8_t  tsEnableSlaveQuery = 1;
int8_t  tsEnableAdjustMaster = 1;
int8_t  tsPrintAuth = 0;
S
Shengliang Guan 已提交
44 45 46 47 48 49 50 51
/*
 * denote if the server needs to compress response message at the application layer to client, including query rsp,
 * metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server.
 *
 * 0: all data are compressed
 * -1: all data are not compressed
 * other values: if the message payload size is greater than the tsCompressMsgSize, the message will be compressed.
 */
D
dapan1121 已提交
52
int32_t tsCompressMsgSize = -1;
S
Shengliang Guan 已提交
53

54
/* denote if server needs to compress the retrieved column data before adding to the rpc response message body.
55 56
 * 0: all data are compressed
 * -1: all data are not compressed
57
 * other values: if any retrieved column size is greater than the tsCompressColData, all data will be compressed.
58
 */
59
int32_t tsCompressColData = -1;
60

61 62 63 64 65
/*
 * denote if 3.0 query pattern compatible for 2.0
 */
int32_t tsCompatibleModel = 1;

S
Shengliang Guan 已提交
66
// client
67
int32_t tsMaxWildCardsLen = TSDB_PATTERN_STRING_DEFAULT_LEN;
68 69
int32_t tsMaxRegexStringLen = TSDB_REGEX_STRING_DEFAULT_LEN;

S
Shengliang Guan 已提交
70
int8_t tsTscEnableRecordSql = 0;
S
slguan 已提交
71

S
Shengliang Guan 已提交
72 73 74 75 76 77 78
// the maximum number of results for projection query on super table that are returned from
// one virtual node, to order according to timestamp
int32_t tsMaxNumOfOrderedResults = 100000;

// 10 ms for sliding time, the value will changed in case of time precision changed
int32_t tsMinSlidingTime = 10;

79
// the maxinum number of distict query result
S
Shengliang Guan 已提交
80
int32_t tsMaxNumOfDistinctResults = 1000 * 10000;
81

82 83
// 1 us for interval time range, changed accordingly
int32_t tsMinIntervalTime = 1;
S
Shengliang Guan 已提交
84 85 86 87 88 89 90 91

// 20sec, the maximum value of stream computing delay, changed accordingly
int32_t tsMaxStreamComputDelay = 20000;

// 10sec, the first stream computing delay time after system launched successfully, changed accordingly
int32_t tsStreamCompStartDelay = 10000;

// the stream computing delay time after executing failed, change accordingly
S
Shengliang Guan 已提交
92
int32_t tsRetryStreamCompDelay = 10 * 1000;
S
Shengliang Guan 已提交
93 94

// The delayed computing ration. 10% of the whole computing time window by default.
95
float tsStreamComputDelayRatio = 0.1f;
S
Shengliang Guan 已提交
96 97 98 99

int32_t tsProjectExecInterval = 10000;   // every 10sec, the projection will be executed once
int64_t tsMaxRetentWindow = 24 * 3600L;  // maximum time window tolerance

H
Haojun Liao 已提交
100 101 102 103 104
// the maximum allowed query buffer size during query processing for each data node.
// -1 no limit (default)
// 0  no query allowed, queries are disabled
// positive value (in MB)
int32_t tsQueryBufferSize = -1;
105
int64_t tsQueryBufferSizeBytes = -1;
H
Haojun Liao 已提交
106

H
Haojun Liao 已提交
107 108
// in retrieve blocking model, the retrieve threads will wait for the completion of the query processing.
int32_t tsRetrieveBlockingModel = 0;
109

110
// last_row(*), first(*), last_row(ts, col1, col2) query, the result fields will be the original column name
S
Shengliang Guan 已提交
111 112 113 114
int8_t tsKeepOriginalColumnName = 0;

// long query death-lock
int8_t tsDeadLockKillQuery = 0;
115

S
Shengliang Guan 已提交
116
// tsdb config
Y
yihaoDeng 已提交
117 118 119
// For backward compatibility
bool tsdbForceKeepFile = false;

S
Shengliang Guan 已提交
120 121 122 123 124 125
/*
 * minimum scale for whole system, millisecond by default
 * for TSDB_TIME_PRECISION_MILLI: 86400000L
 *     TSDB_TIME_PRECISION_MICRO: 86400000000L
 *     TSDB_TIME_PRECISION_NANO:  86400000000000L
 */
126
int64_t tsTickPerDay[] = {86400000L, 86400000000L, 86400000000000L};
S
Shengliang Guan 已提交
127 128

// system info
S
Shengliang Guan 已提交
129 130 131 132 133 134 135 136
float    tsTotalTmpDirGB = 0;
float    tsTotalDataDirGB = 0;
float    tsAvailTmpDirectorySpace = 0;
float    tsAvailDataDirGB = 0;
float    tsUsedDataDirGB = 0;
float    tsReservedTmpDirectorySpace = 1.0f;
float    tsMinimalDataDirGB = 2.0f;
int32_t  tsTotalMemoryMB = 0;
137
uint32_t tsVersion = 0;
S
slguan 已提交
138

T
tickduan 已提交
139 140 141
//
// lossy compress 6
//
S
Shengliang Guan 已提交
142 143 144 145 146 147 148 149
char tsLossyColumns[32] = "";  // "float|double" means all float and double columns can be lossy compressed.  set empty
                               // can close lossy compress.
// below option can take effect when tsLossyColumns not empty
double   tsFPrecision = 1E-8;                   // float column precision
double   tsDPrecision = 1E-16;                  // double column precision
uint32_t tsMaxRange = 500;                      // max range
uint32_t tsCurRange = 100;                      // range
char     tsCompressor[32] = "ZSTD_COMPRESSOR";  // ZSTD_COMPRESSOR or GZIP_COMPRESSOR
T
tickduan 已提交
150

151

S
Shengliang Guan 已提交
152 153 154
int32_t (*monStartSystemFp)() = NULL;
void (*monStopSystemFp)() = NULL;
void (*monExecuteSQLFp)(char *sql) = NULL;
155

S
Shengliang Guan 已提交
156 157
char *qtypeStr[] = {"rpc", "fwd", "wal", "cq", "query"};

S
slguan 已提交
158 159 160
static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT;


S
Shengliang Guan 已提交
161
int32_t taosCfgDynamicOptions(char *msg) {
S
config  
Shengliang Guan 已提交
162
  #if 0
S
Shengliang Guan 已提交
163 164 165
  char   *option, *value;
  int32_t olen, vlen;
  int32_t vint = 0;
S
slguan 已提交
166 167

  paGetToken(msg, &option, &olen);
S
Shengliang Guan 已提交
168
  if (olen == 0) return -1;
S
slguan 已提交
169 170 171 172 173 174 175 176

  paGetToken(option + olen + 1, &value, &vlen);
  if (vlen == 0)
    vint = 135;
  else {
    vint = atoi(value);
  }

177
  uInfo("change dynamic option: %s, value: %d", option, vint);
S
slguan 已提交
178 179 180

  for (int32_t i = 0; i < tsGlobalConfigNum; ++i) {
    SGlobalCfg *cfg = tsGlobalConfig + i;
S
Shengliang Guan 已提交
181
    // if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue;
S
Shengliang Guan 已提交
182
    if (cfg->valType != TAOS_CFG_VTYPE_INT32 && cfg->valType != TAOS_CFG_VTYPE_INT8) continue;
S
Shengliang Guan 已提交
183

S
Shengliang Guan 已提交
184
    int32_t cfgLen = (int32_t)strlen(cfg->option);
185
    if (cfgLen != olen) continue;
T
tickduan 已提交
186 187 188 189 190 191
    if (strncasecmp(option, cfg->option, olen) != 0) continue;
    if (cfg->valType == TAOS_CFG_VTYPE_INT32) {
      *((int32_t *)cfg->ptr) = vint;
    } else {
      *((int8_t *)cfg->ptr) = (int8_t)vint;
    }
T
tickduan 已提交
192

S
slguan 已提交
193
    if (strncasecmp(cfg->option, "monitor", olen) == 0) {
194
      if (1 == vint) {
S
Shengliang Guan 已提交
195 196
        if (monStartSystemFp) {
          (*monStartSystemFp)();
197
          uInfo("monitor is enabled");
198 199
        } else {
          uError("monitor can't be updated, for monitor not initialized");
200 201
        }
      } else {
S
Shengliang Guan 已提交
202 203
        if (monStopSystemFp) {
          (*monStopSystemFp)();
204
          uInfo("monitor is disabled");
205 206
        } else {
          uError("monitor can't be updated, for monitor not initialized");
207 208
        }
      }
S
Shengliang Guan 已提交
209
      return 0;
S
slguan 已提交
210
    }
Y
yihaoDeng 已提交
211
    if (strncasecmp(cfg->option, "debugFlag", olen) == 0) {
S
Shengliang Guan 已提交
212
      taosSetAllDebugFlag();
Y
yihaoDeng 已提交
213
    }
S
Shengliang Guan 已提交
214
    return 0;
S
slguan 已提交
215 216 217 218
  }

  if (strncasecmp(option, "resetlog", 8) == 0) {
    taosResetLog();
219
    taosPrintCfg();
S
Shengliang Guan 已提交
220
    return 0;
S
slguan 已提交
221 222 223
  }

  if (strncasecmp(option, "resetQueryCache", 15) == 0) {
S
Shengliang Guan 已提交
224 225
    if (monExecuteSQLFp) {
      (*monExecuteSQLFp)("resetQueryCache");
226 227 228 229
      uInfo("resetquerycache is executed");
    } else {
      uError("resetquerycache can't be executed, for monitor not started");
    }
S
slguan 已提交
230 231
  }

S
config  
Shengliang Guan 已提交
232
#endif
S
slguan 已提交
233 234 235
  return false;
}

S
Shengliang Guan 已提交
236 237 238 239 240 241
// void taosAddDataDir(int index, char *v1, int level, int primary) {
//   tstrncpy(tsDiskCfg[index].dir, v1, TSDB_FILENAME_LEN);
//   tsDiskCfg[index].level = level;
//   tsDiskCfg[index].primary = primary;
//   uTrace("dataDir:%s, level:%d primary:%d is configured", v1, level, primary);
// }
S
TD-1767  
Shengliang Guan 已提交
242 243

#ifndef _STORAGE
S
Shengliang Guan 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
// void taosReadDataDirCfg(char *v1, char *v2, char *v3) {
//   if (tsDiskCfgNum == 1) {
//     SDiskCfg *cfg = &tsDiskCfg[0];
//     uInfo("dataDir:%s, level:%d primary:%d is replaced by %s", cfg->dir, cfg->level, cfg->primary, v1);
//   }
//   taosAddDataDir(0, v1, 0, 1);
//   tsDiskCfgNum = 1;
// }

// void taosPrintDataDirCfg() {
//   for (int i = 0; i < tsDiskCfgNum; ++i) {
//     SDiskCfg *cfg = &tsDiskCfg[i];
//     uInfo(" dataDir: %s", cfg->dir);
//   }
// }
S
TD-1767  
Shengliang Guan 已提交
259
#endif
S
TD-1767  
Shengliang Guan 已提交
260

S
config  
Shengliang Guan 已提交
261

S
TD-1767  
Shengliang Guan 已提交
262

263
static void doInitGlobalConfig(void) {
S
TD-1057  
Shengliang Guan 已提交
264
  osInit();
S
TD-1652  
Shengliang Guan 已提交
265
  srand(taosSafeRand());
S
config  
Shengliang Guan 已提交
266
#if 0
S
slguan 已提交
267
  SGlobalCfg cfg = {0};
S
Shengliang Guan 已提交
268

S
slguan 已提交
269 270

  cfg.option = "dataDir";
S
slguan 已提交
271
  cfg.ptr = tsDataDir;
S
TD-1767  
Shengliang Guan 已提交
272
  cfg.valType = TAOS_CFG_VTYPE_DATA_DIRCTORY;
S
slguan 已提交
273 274 275 276 277
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
  cfg.minValue = 0;
  cfg.maxValue = 0;
  cfg.ptrLength = TSDB_FILENAME_LEN;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
278
  taosAddConfigOption(cfg);
S
slguan 已提交
279 280


281 282 283 284
  cfg.option = "maxNumOfDistinctRes";
  cfg.ptr = &tsMaxNumOfDistinctResults;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
S
Shengliang Guan 已提交
285 286
  cfg.minValue = 10 * 10000;
  cfg.maxValue = 10000 * 10000;
287 288
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
289
  taosAddConfigOption(cfg);
H
Hui Li 已提交
290

S
slguan 已提交
291 292
  // timer
  cfg.option = "maxTmrCtrl";
S
Shengliang Guan 已提交
293
  cfg.ptr = &tsMaxTmrCtrl;
S
slguan 已提交
294 295 296 297 298 299
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = 8;
  cfg.maxValue = 2048;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
300
  taosAddConfigOption(cfg);
S
slguan 已提交
301 302 303 304 305 306 307 308 309

  cfg.option = "minSlidingTime";
  cfg.ptr = &tsMinSlidingTime;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = 10;
  cfg.maxValue = 1000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_MS;
310
  taosAddConfigOption(cfg);
S
slguan 已提交
311 312 313 314 315

  cfg.option = "minIntervalTime";
  cfg.ptr = &tsMinIntervalTime;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
H
Haojun Liao 已提交
316
  cfg.minValue = 1;
S
slguan 已提交
317 318 319
  cfg.maxValue = 1000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_MS;
320
  taosAddConfigOption(cfg);
S
slguan 已提交
321 322 323 324 325 326 327 328 329

  cfg.option = "maxStreamCompDelay";
  cfg.ptr = &tsMaxStreamComputDelay;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = 10;
  cfg.maxValue = 1000000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_MS;
330
  taosAddConfigOption(cfg);
S
slguan 已提交
331 332 333 334 335 336 337 338 339

  cfg.option = "maxFirstStreamCompDelay";
  cfg.ptr = &tsStreamCompStartDelay;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = 1000;
  cfg.maxValue = 1000000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_MS;
340
  taosAddConfigOption(cfg);
S
slguan 已提交
341 342

  cfg.option = "retryStreamCompDelay";
343
  cfg.ptr = &tsRetryStreamCompDelay;
S
slguan 已提交
344 345 346 347 348 349 350
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = 10;
  cfg.maxValue = 1000000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_MS;

351
  taosAddConfigOption(cfg);
S
slguan 已提交
352 353 354 355
  cfg.option = "streamCompDelayRatio";
  cfg.ptr = &tsStreamComputDelayRatio;
  cfg.valType = TAOS_CFG_VTYPE_FLOAT;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
356 357
  cfg.minValue = 0.1f;
  cfg.maxValue = 0.9f;
S
slguan 已提交
358 359
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
360
  taosAddConfigOption(cfg);
S
slguan 已提交
361 362 363 364 365 366

  cfg.option = "compressMsgSize";
  cfg.ptr = &tsCompressMsgSize;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = -1;
D
dapan1121 已提交
367
  cfg.maxValue = 100000000.0f;
S
slguan 已提交
368 369
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
370
  taosAddConfigOption(cfg);
S
slguan 已提交
371

372 373
  cfg.option = "compressColData";
  cfg.ptr = &tsCompressColData;
374 375 376 377
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = -1;
  cfg.maxValue = 100000000.0f;
378 379
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
380
  taosAddConfigOption(cfg);
381

382 383
  cfg.option = "maxWildCardsLength";
  cfg.ptr = &tsMaxWildCardsLen;
384 385 386
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = 0;
387
  cfg.maxValue = TSDB_MAX_FIELD_LEN;
388 389
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_BYTE;
390
  taosAddConfigOption(cfg);
391

392 393 394 395 396 397 398 399
  cfg.option = "maxRegexStringLen";
  cfg.ptr = &tsMaxRegexStringLen;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = 0;
  cfg.maxValue = TSDB_MAX_FIELD_LEN;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_BYTE;
400
  taosAddConfigOption(cfg);
401

S
slguan 已提交
402 403 404 405 406 407 408 409
  cfg.option = "maxNumOfOrderedRes";
  cfg.ptr = &tsMaxNumOfOrderedResults;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = TSDB_MAX_SQL_LEN;
  cfg.maxValue = TSDB_MAX_ALLOWED_SQL_LEN;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
410
  taosAddConfigOption(cfg);
S
slguan 已提交
411

H
Haojun Liao 已提交
412 413 414 415 416
  cfg.option = "queryBufferSize";
  cfg.ptr = &tsQueryBufferSize;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = -1;
H
Haojun Liao 已提交
417
  cfg.maxValue = 500000000000.0f;
H
Haojun Liao 已提交
418 419
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_BYTE;
420
  taosAddConfigOption(cfg);
H
Haojun Liao 已提交
421

H
Haojun Liao 已提交
422 423
  cfg.option = "retrieveBlockingModel";
  cfg.ptr = &tsRetrieveBlockingModel;
424 425 426 427 428 429
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = 0;
  cfg.maxValue = 1;
  cfg.ptrLength = 1;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
430
  taosAddConfigOption(cfg);
431

432 433
  cfg.option = "keepColumnName";
  cfg.ptr = &tsKeepOriginalColumnName;
S
Shengliang Guan 已提交
434
  cfg.valType = TAOS_CFG_VTYPE_INT8;
435 436 437 438 439
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
  cfg.minValue = 0;
  cfg.maxValue = 1;
  cfg.ptrLength = 1;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
440
  taosAddConfigOption(cfg);
441

S
slguan 已提交
442

443 444
  cfg.option = "maxConnections";
  cfg.ptr = &tsMaxConnections;
S
slguan 已提交
445 446
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
447
  cfg.minValue = 1;
448
  cfg.maxValue = 100000;
S
slguan 已提交
449 450
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
451
  taosAddConfigOption(cfg);
S
slguan 已提交
452 453 454 455 456

  cfg.option = "minimalLogDirGB";
  cfg.ptr = &tsMinimalLogDirGB;
  cfg.valType = TAOS_CFG_VTYPE_FLOAT;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
457
  cfg.minValue = 0.001f;
S
slguan 已提交
458 459 460
  cfg.maxValue = 10000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_GB;
461
  taosAddConfigOption(cfg);
S
slguan 已提交
462 463

  cfg.option = "minimalTmpDirGB";
H
Haojun Liao 已提交
464
  cfg.ptr = &tsReservedTmpDirectorySpace;
S
slguan 已提交
465 466
  cfg.valType = TAOS_CFG_VTYPE_FLOAT;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
467
  cfg.minValue = 0.001f;
S
slguan 已提交
468 469 470
  cfg.maxValue = 10000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_GB;
471
  taosAddConfigOption(cfg);
S
slguan 已提交
472 473 474 475 476

  cfg.option = "minimalDataDirGB";
  cfg.ptr = &tsMinimalDataDirGB;
  cfg.valType = TAOS_CFG_VTYPE_FLOAT;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
477
  cfg.minValue = 0.001f;
S
slguan 已提交
478 479 480
  cfg.maxValue = 10000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_GB;
481
  taosAddConfigOption(cfg);
S
TD-2498  
Shengliang Guan 已提交
482 483 484

  cfg.option = "slaveQuery";
  cfg.ptr = &tsEnableSlaveQuery;
S
Shengliang Guan 已提交
485 486 487 488 489 490
  cfg.valType = TAOS_CFG_VTYPE_INT8;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = 0;
  cfg.maxValue = 1;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
491
  taosAddConfigOption(cfg);
S
Shengliang Guan 已提交
492

S
slguan 已提交
493

S
TD-1520  
Shengliang Guan 已提交
494

495
  cfg.option = "enableRecordSql";
S
slguan 已提交
496
  cfg.ptr = &tsTscEnableRecordSql;
S
Shengliang Guan 已提交
497
  cfg.valType = TAOS_CFG_VTYPE_INT8;
S
slguan 已提交
498 499 500 501 502
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
  cfg.minValue = 0;
  cfg.maxValue = 1;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
503
  taosAddConfigOption(cfg);
S
slguan 已提交
504 505 506

  cfg.option = "enableCoreFile";
  cfg.ptr = &tsEnableCoreFile;
S
Shengliang Guan 已提交
507
  cfg.valType = TAOS_CFG_VTYPE_INT8;
S
slguan 已提交
508 509 510 511 512
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
  cfg.minValue = 0;
  cfg.maxValue = 1;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
513
  taosAddConfigOption(cfg);
S
slguan 已提交
514

515 516 517 518 519 520

  cfg.option = "maxBinaryDisplayWidth";
  cfg.ptr = &tsMaxBinaryDisplayWidth;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
  cfg.minValue = 1;
521
  cfg.maxValue = 65536;
522 523
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
524
  taosAddConfigOption(cfg);
525 526 527 528 529 530 531

  cfg.option = "tempDir";
  cfg.ptr = tsTempDir;
  cfg.valType = TAOS_CFG_VTYPE_STRING;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
  cfg.minValue = 0;
  cfg.maxValue = 0;
S
Shengliang Guan 已提交
532
  cfg.ptrLength = PATH_MAX;
533
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
534
  taosAddConfigOption(cfg);
535

S
Shengliang Guan 已提交
536
  // enable kill long query
537 538 539 540 541 542 543 544
  cfg.option = "deadLockKillQuery";
  cfg.ptr = &tsDeadLockKillQuery;
  cfg.valType = TAOS_CFG_VTYPE_INT8;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
  cfg.minValue = 0;
  cfg.maxValue = 1;
  cfg.ptrLength = 1;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
545
  taosAddConfigOption(cfg);
546

T
tickduan 已提交
547
#ifdef TD_TSZ
T
tickduan 已提交
548
  // lossy compress
T
tickduan 已提交
549
  cfg.option = "lossyColumns";
T
tickduan 已提交
550 551 552 553 554 555 556
  cfg.ptr = lossyColumns;
  cfg.valType = TAOS_CFG_VTYPE_STRING;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
  cfg.minValue = 0;
  cfg.maxValue = 0;
  cfg.ptrLength = tListLen(lossyColumns);
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
557
  taosAddConfigOption(cfg);
T
tickduan 已提交
558 559 560 561 562

  cfg.option = "fPrecision";
  cfg.ptr = &fPrecision;
  cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
T
tickduan 已提交
563
  cfg.minValue = MIN_FLOAT;
S
config  
Shengliang Guan 已提交
564
  cfg.maxValue = 100000;
T
tickduan 已提交
565 566
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
T
tickduan 已提交
567

568
  taosAddConfigOption(cfg);
T
tickduan 已提交
569 570 571 572 573

  cfg.option = "dPrecision";
  cfg.ptr = &dPrecision;
  cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
S
config  
Shengliang Guan 已提交
574 575
  cfg.minValue = 100000;
  cfg.maxValue = 0;
T
tickduan 已提交
576 577
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
578
  taosAddConfigOption(cfg);
T
tickduan 已提交
579

T
tickduan 已提交
580 581
  cfg.option = "maxRange";
  cfg.ptr = &maxRange;
T
tickduan 已提交
582 583 584 585 586 587
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
  cfg.minValue = 0;
  cfg.maxValue = 65536;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
588
  taosAddConfigOption(cfg);
T
tickduan 已提交
589

T
tickduan 已提交
590
  cfg.option = "range";
T
tickduan 已提交
591
  cfg.ptr = &curRange;
T
tickduan 已提交
592 593 594 595 596 597
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
  cfg.minValue = 0;
  cfg.maxValue = 65536;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
598
  taosAddConfigOption(cfg);
599 600
  assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM);
#else
S
Shengliang Guan 已提交
601
  // assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM - 5);
602
#endif
S
config  
Shengliang Guan 已提交
603 604

#endif
S
slguan 已提交
605 606
}

S
Shengliang Guan 已提交
607
void taosInitGlobalCfg() { pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig); }
S
slguan 已提交
608

609 610 611 612
/*
 * alter dnode 1 balance "vnode:1-dnode:2"
 */

S
Shengliang Guan 已提交
613
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId) {
614
  int len = (int)strlen(option);
615 616 617 618 619 620 621 622 623 624 625 626 627 628
  if (strncasecmp(option, "vnode:", 6) != 0) {
    return false;
  }

  int pos = 0;
  for (; pos < len; ++pos) {
    if (option[pos] == '-') break;
  }

  if (++pos >= len) return false;
  if (strncasecmp(option + pos, "dnode:", 6) != 0) {
    return false;
  }

S
Shengliang Guan 已提交
629 630 631
  *vnodeId = strtol(option + 6, NULL, 10);
  *dnodeId = strtol(option + pos + 6, NULL, 10);
  if (*vnodeId <= 1 || *dnodeId <= 0) {
632 633 634 635
    return false;
  }

  return true;
636
}