tglobal.c 19.8 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 33 34 35
int32_t tsRpcTimer = 300;
int32_t tsRpcMaxTime = 600;  // seconds;
int32_t tsRpcForceTcp = 1;   // disable this, means query, show command use udp protocol as default
int32_t tsMaxShellConns = 50000;
S
Shengliang 已提交
36
int32_t tsMaxConnections = 50000;
S
Shengliang Guan 已提交
37
int32_t tsShellActivityTimer = 3;  // second
H
Haojun Liao 已提交
38
float   tsNumOfThreadsPerCore = 1.0f;
39
int32_t tsNumOfCommitThreads = 4;
40
float   tsRatioOfQueryCores = 1.0f;
S
Shengliang Guan 已提交
41
int8_t  tsDaylight = 0;
S
Shengliang Guan 已提交
42
int8_t  tsEnableCoreFile = 0;
S
Shengliang Guan 已提交
43
int32_t tsMaxBinaryDisplayWidth = 30;
S
Shengliang Guan 已提交
44 45 46
int8_t  tsEnableSlaveQuery = 1;
int8_t  tsEnableAdjustMaster = 1;
int8_t  tsPrintAuth = 0;
S
Shengliang Guan 已提交
47 48 49 50 51 52 53 54
/*
 * 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 已提交
55
int32_t tsCompressMsgSize = -1;
S
Shengliang Guan 已提交
56

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

64 65 66 67 68
/*
 * denote if 3.0 query pattern compatible for 2.0
 */
int32_t tsCompatibleModel = 1;

S
Shengliang Guan 已提交
69
// client
70
int32_t tsMaxWildCardsLen = TSDB_PATTERN_STRING_DEFAULT_LEN;
71 72
int32_t tsMaxRegexStringLen = TSDB_REGEX_STRING_DEFAULT_LEN;

S
Shengliang Guan 已提交
73
int8_t tsTscEnableRecordSql = 0;
S
slguan 已提交
74

S
Shengliang Guan 已提交
75 76 77 78 79 80 81
// 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;

82
// the maxinum number of distict query result
S
Shengliang Guan 已提交
83
int32_t tsMaxNumOfDistinctResults = 1000 * 10000;
84

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

// 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 已提交
95
int32_t tsRetryStreamCompDelay = 10 * 1000;
S
Shengliang Guan 已提交
96 97

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

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

H
Haojun Liao 已提交
103 104 105 106 107
// 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;
108
int64_t tsQueryBufferSizeBytes = -1;
H
Haojun Liao 已提交
109

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

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

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

S
Shengliang Guan 已提交
119
// tsdb config
Y
yihaoDeng 已提交
120 121 122
// For backward compatibility
bool tsdbForceKeepFile = false;

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

// system info
S
Shengliang Guan 已提交
132 133 134 135 136 137 138 139
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;
140
uint32_t tsVersion = 0;
S
slguan 已提交
141

T
tickduan 已提交
142 143 144
//
// lossy compress 6
//
S
Shengliang Guan 已提交
145 146 147 148 149 150 151 152
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 已提交
153

154

S
Shengliang Guan 已提交
155 156 157
int32_t (*monStartSystemFp)() = NULL;
void (*monStopSystemFp)() = NULL;
void (*monExecuteSQLFp)(char *sql) = NULL;
158

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

S
slguan 已提交
161 162 163
static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT;


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

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

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

180
  uInfo("change dynamic option: %s, value: %d", option, vint);
S
slguan 已提交
181 182 183

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

S
Shengliang Guan 已提交
187
    int32_t cfgLen = (int32_t)strlen(cfg->option);
188
    if (cfgLen != olen) continue;
T
tickduan 已提交
189 190 191 192 193 194
    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 已提交
195

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

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

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

S
config  
Shengliang Guan 已提交
235
#endif
S
slguan 已提交
236 237 238
  return false;
}

S
Shengliang Guan 已提交
239 240 241 242 243 244
// 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 已提交
245 246

#ifndef _STORAGE
S
Shengliang Guan 已提交
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
// 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 已提交
262
#endif
S
TD-1767  
Shengliang Guan 已提交
263

S
config  
Shengliang Guan 已提交
264

S
TD-1767  
Shengliang Guan 已提交
265

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

S
slguan 已提交
272 273

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


284 285 286 287
  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 已提交
288 289
  cfg.minValue = 10 * 10000;
  cfg.maxValue = 10000 * 10000;
290 291
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
292
  taosAddConfigOption(cfg);
H
Hui Li 已提交
293

S
slguan 已提交
294 295
  // timer
  cfg.option = "maxTmrCtrl";
S
Shengliang Guan 已提交
296
  cfg.ptr = &tsMaxTmrCtrl;
S
slguan 已提交
297 298 299 300 301 302
  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;
303
  taosAddConfigOption(cfg);
S
slguan 已提交
304 305 306 307 308 309 310 311 312

  cfg.option = "rpcTimer";
  cfg.ptr = &tsRpcTimer;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
  cfg.minValue = 100;
  cfg.maxValue = 3000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_MS;
313
  taosAddConfigOption(cfg);
S
slguan 已提交
314

张宏权 已提交
315 316 317 318 319 320 321 322
  cfg.option = "rpcForceTcp";
  cfg.ptr = &tsRpcForceTcp;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
  cfg.minValue = 0;
  cfg.maxValue = 1;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
323
  taosAddConfigOption(cfg);
张宏权 已提交
324

S
slguan 已提交
325 326 327 328 329 330 331 332
  cfg.option = "rpcMaxTime";
  cfg.ptr = &tsRpcMaxTime;
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
  cfg.minValue = 100;
  cfg.maxValue = 7200;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_SECOND;
333
  taosAddConfigOption(cfg);
S
slguan 已提交
334 335 336 337 338 339 340 341 342 343


  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;
344
  taosAddConfigOption(cfg);
S
slguan 已提交
345 346 347 348 349

  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 已提交
350
  cfg.minValue = 1;
S
slguan 已提交
351 352 353
  cfg.maxValue = 1000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_MS;
354
  taosAddConfigOption(cfg);
S
slguan 已提交
355 356 357 358 359 360 361 362 363

  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;
364
  taosAddConfigOption(cfg);
S
slguan 已提交
365 366 367 368 369 370 371 372 373

  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;
374
  taosAddConfigOption(cfg);
S
slguan 已提交
375 376

  cfg.option = "retryStreamCompDelay";
377
  cfg.ptr = &tsRetryStreamCompDelay;
S
slguan 已提交
378 379 380 381 382 383 384
  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;

385
  taosAddConfigOption(cfg);
S
slguan 已提交
386 387 388 389
  cfg.option = "streamCompDelayRatio";
  cfg.ptr = &tsStreamComputDelayRatio;
  cfg.valType = TAOS_CFG_VTYPE_FLOAT;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
390 391
  cfg.minValue = 0.1f;
  cfg.maxValue = 0.9f;
S
slguan 已提交
392 393
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
394
  taosAddConfigOption(cfg);
S
slguan 已提交
395 396 397 398 399 400

  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 已提交
401
  cfg.maxValue = 100000000.0f;
S
slguan 已提交
402 403
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
404
  taosAddConfigOption(cfg);
S
slguan 已提交
405

406 407
  cfg.option = "compressColData";
  cfg.ptr = &tsCompressColData;
408 409 410 411
  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;
412 413
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
414
  taosAddConfigOption(cfg);
415

416 417
  cfg.option = "maxWildCardsLength";
  cfg.ptr = &tsMaxWildCardsLen;
418 419 420
  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;
421
  cfg.maxValue = TSDB_MAX_FIELD_LEN;
422 423
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_BYTE;
424
  taosAddConfigOption(cfg);
425

426 427 428 429 430 431 432 433
  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;
434
  taosAddConfigOption(cfg);
435

S
slguan 已提交
436 437 438 439 440 441 442 443
  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;
444
  taosAddConfigOption(cfg);
S
slguan 已提交
445

H
Haojun Liao 已提交
446 447 448 449 450
  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 已提交
451
  cfg.maxValue = 500000000000.0f;
H
Haojun Liao 已提交
452 453
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_BYTE;
454
  taosAddConfigOption(cfg);
H
Haojun Liao 已提交
455

H
Haojun Liao 已提交
456 457
  cfg.option = "retrieveBlockingModel";
  cfg.ptr = &tsRetrieveBlockingModel;
458 459 460 461 462 463
  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;
464
  taosAddConfigOption(cfg);
465

466 467
  cfg.option = "keepColumnName";
  cfg.ptr = &tsKeepOriginalColumnName;
S
Shengliang Guan 已提交
468
  cfg.valType = TAOS_CFG_VTYPE_INT8;
469 470 471 472 473
  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;
474
  taosAddConfigOption(cfg);
475

S
slguan 已提交
476

477 478
  cfg.option = "maxConnections";
  cfg.ptr = &tsMaxConnections;
S
slguan 已提交
479 480
  cfg.valType = TAOS_CFG_VTYPE_INT32;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
481
  cfg.minValue = 1;
482
  cfg.maxValue = 100000;
S
slguan 已提交
483 484
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
485
  taosAddConfigOption(cfg);
S
slguan 已提交
486 487 488 489 490

  cfg.option = "minimalLogDirGB";
  cfg.ptr = &tsMinimalLogDirGB;
  cfg.valType = TAOS_CFG_VTYPE_FLOAT;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
491
  cfg.minValue = 0.001f;
S
slguan 已提交
492 493 494
  cfg.maxValue = 10000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_GB;
495
  taosAddConfigOption(cfg);
S
slguan 已提交
496 497

  cfg.option = "minimalTmpDirGB";
H
Haojun Liao 已提交
498
  cfg.ptr = &tsReservedTmpDirectorySpace;
S
slguan 已提交
499 500
  cfg.valType = TAOS_CFG_VTYPE_FLOAT;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
501
  cfg.minValue = 0.001f;
S
slguan 已提交
502 503 504
  cfg.maxValue = 10000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_GB;
505
  taosAddConfigOption(cfg);
S
slguan 已提交
506 507 508 509 510

  cfg.option = "minimalDataDirGB";
  cfg.ptr = &tsMinimalDataDirGB;
  cfg.valType = TAOS_CFG_VTYPE_FLOAT;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
511
  cfg.minValue = 0.001f;
S
slguan 已提交
512 513 514
  cfg.maxValue = 10000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_GB;
515
  taosAddConfigOption(cfg);
S
TD-2498  
Shengliang Guan 已提交
516 517 518

  cfg.option = "slaveQuery";
  cfg.ptr = &tsEnableSlaveQuery;
S
Shengliang Guan 已提交
519 520 521 522 523 524
  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;
525
  taosAddConfigOption(cfg);
S
Shengliang Guan 已提交
526

S
slguan 已提交
527

S
TD-1520  
Shengliang Guan 已提交
528

529
  cfg.option = "enableRecordSql";
S
slguan 已提交
530
  cfg.ptr = &tsTscEnableRecordSql;
S
Shengliang Guan 已提交
531
  cfg.valType = TAOS_CFG_VTYPE_INT8;
S
slguan 已提交
532 533 534 535 536
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
  cfg.minValue = 0;
  cfg.maxValue = 1;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
537
  taosAddConfigOption(cfg);
S
slguan 已提交
538 539 540

  cfg.option = "enableCoreFile";
  cfg.ptr = &tsEnableCoreFile;
S
Shengliang Guan 已提交
541
  cfg.valType = TAOS_CFG_VTYPE_INT8;
S
slguan 已提交
542 543 544 545 546
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
  cfg.minValue = 0;
  cfg.maxValue = 1;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
547
  taosAddConfigOption(cfg);
S
slguan 已提交
548

549 550 551 552 553 554

  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;
555
  cfg.maxValue = 65536;
556 557
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
558
  taosAddConfigOption(cfg);
559 560 561 562 563 564 565

  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 已提交
566
  cfg.ptrLength = PATH_MAX;
567
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
568
  taosAddConfigOption(cfg);
569

S
Shengliang Guan 已提交
570
  // enable kill long query
571 572 573 574 575 576 577 578
  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;
579
  taosAddConfigOption(cfg);
580

T
tickduan 已提交
581
#ifdef TD_TSZ
T
tickduan 已提交
582
  // lossy compress
T
tickduan 已提交
583
  cfg.option = "lossyColumns";
T
tickduan 已提交
584 585 586 587 588 589 590
  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;
591
  taosAddConfigOption(cfg);
T
tickduan 已提交
592 593 594 595 596

  cfg.option = "fPrecision";
  cfg.ptr = &fPrecision;
  cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
T
tickduan 已提交
597
  cfg.minValue = MIN_FLOAT;
S
config  
Shengliang Guan 已提交
598
  cfg.maxValue = 100000;
T
tickduan 已提交
599 600
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
T
tickduan 已提交
601

602
  taosAddConfigOption(cfg);
T
tickduan 已提交
603 604 605 606 607

  cfg.option = "dPrecision";
  cfg.ptr = &dPrecision;
  cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
S
config  
Shengliang Guan 已提交
608 609
  cfg.minValue = 100000;
  cfg.maxValue = 0;
T
tickduan 已提交
610 611
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
612
  taosAddConfigOption(cfg);
T
tickduan 已提交
613

T
tickduan 已提交
614 615
  cfg.option = "maxRange";
  cfg.ptr = &maxRange;
T
tickduan 已提交
616 617 618 619 620 621
  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;
622
  taosAddConfigOption(cfg);
T
tickduan 已提交
623

T
tickduan 已提交
624
  cfg.option = "range";
T
tickduan 已提交
625
  cfg.ptr = &curRange;
T
tickduan 已提交
626 627 628 629 630 631
  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;
632
  taosAddConfigOption(cfg);
633 634
  assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM);
#else
S
Shengliang Guan 已提交
635
  // assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM - 5);
636
#endif
S
config  
Shengliang Guan 已提交
637 638

#endif
S
slguan 已提交
639 640
}

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

643 644 645 646
/*
 * alter dnode 1 balance "vnode:1-dnode:2"
 */

S
Shengliang Guan 已提交
647
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId) {
648
  int len = (int)strlen(option);
649 650 651 652 653 654 655 656 657 658 659 660 661 662
  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 已提交
663 664 665
  *vnodeId = strtol(option + 6, NULL, 10);
  *dnodeId = strtol(option + pos + 6, NULL, 10);
  if (*vnodeId <= 1 || *dnodeId <= 0) {
666 667 668 669
    return false;
  }

  return true;
670
}