tglobal.c 16.5 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
int8_t  tsDaylight = 0;
S
Shengliang Guan 已提交
33
int32_t tsMaxBinaryDisplayWidth = 30;
S
Shengliang Guan 已提交
34 35 36
int8_t  tsEnableSlaveQuery = 1;
int8_t  tsEnableAdjustMaster = 1;
int8_t  tsPrintAuth = 0;
S
Shengliang Guan 已提交
37 38 39 40 41 42 43 44
/*
 * 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 已提交
45
int32_t tsCompressMsgSize = -1;
S
Shengliang Guan 已提交
46

47
/* denote if server needs to compress the retrieved column data before adding to the rpc response message body.
48 49
 * 0: all data are compressed
 * -1: all data are not compressed
50
 * other values: if any retrieved column size is greater than the tsCompressColData, all data will be compressed.
51
 */
52
int32_t tsCompressColData = -1;
53

54 55 56 57 58
/*
 * denote if 3.0 query pattern compatible for 2.0
 */
int32_t tsCompatibleModel = 1;

S
Shengliang Guan 已提交
59
// client
60
int32_t tsMaxWildCardsLen = TSDB_PATTERN_STRING_DEFAULT_LEN;
61 62
int32_t tsMaxRegexStringLen = TSDB_REGEX_STRING_DEFAULT_LEN;

S
Shengliang Guan 已提交
63
int8_t tsTscEnableRecordSql = 0;
S
slguan 已提交
64

S
Shengliang Guan 已提交
65 66 67 68 69 70 71
// 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;

72
// the maxinum number of distict query result
S
Shengliang Guan 已提交
73
int32_t tsMaxNumOfDistinctResults = 1000 * 10000;
74

75 76
// 1 us for interval time range, changed accordingly
int32_t tsMinIntervalTime = 1;
S
Shengliang Guan 已提交
77 78 79 80 81 82 83 84

// 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 已提交
85
int32_t tsRetryStreamCompDelay = 10 * 1000;
S
Shengliang Guan 已提交
86 87

// The delayed computing ration. 10% of the whole computing time window by default.
88
float tsStreamComputDelayRatio = 0.1f;
S
Shengliang Guan 已提交
89 90 91 92

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

H
Haojun Liao 已提交
93 94 95 96 97
// 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;
98
int64_t tsQueryBufferSizeBytes = -1;
H
Haojun Liao 已提交
99

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

103
// last_row(*), first(*), last_row(ts, col1, col2) query, the result fields will be the original column name
S
Shengliang Guan 已提交
104 105 106 107
int8_t tsKeepOriginalColumnName = 0;

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

S
Shengliang Guan 已提交
109
// tsdb config
Y
yihaoDeng 已提交
110 111 112
// For backward compatibility
bool tsdbForceKeepFile = false;

S
Shengliang Guan 已提交
113 114 115 116 117 118
/*
 * minimum scale for whole system, millisecond by default
 * for TSDB_TIME_PRECISION_MILLI: 86400000L
 *     TSDB_TIME_PRECISION_MICRO: 86400000000L
 *     TSDB_TIME_PRECISION_NANO:  86400000000000L
 */
119
int64_t tsTickPerDay[] = {86400000L, 86400000000L, 86400000000000L};
S
Shengliang Guan 已提交
120 121

// system info
S
Shengliang Guan 已提交
122
int32_t  tsTotalMemoryMB = 0;
123
uint32_t tsVersion = 0;
S
slguan 已提交
124

T
tickduan 已提交
125 126 127
//
// lossy compress 6
//
S
Shengliang Guan 已提交
128 129 130 131 132 133 134 135
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 已提交
136

137

S
Shengliang Guan 已提交
138 139 140
int32_t (*monStartSystemFp)() = NULL;
void (*monStopSystemFp)() = NULL;
void (*monExecuteSQLFp)(char *sql) = NULL;
141

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

S
slguan 已提交
144 145 146
static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT;


S
Shengliang Guan 已提交
147
int32_t taosCfgDynamicOptions(char *msg) {
S
config  
Shengliang Guan 已提交
148
  #if 0
S
Shengliang Guan 已提交
149 150 151
  char   *option, *value;
  int32_t olen, vlen;
  int32_t vint = 0;
S
slguan 已提交
152 153

  paGetToken(msg, &option, &olen);
S
Shengliang Guan 已提交
154
  if (olen == 0) return -1;
S
slguan 已提交
155 156 157 158 159 160 161 162

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

163
  uInfo("change dynamic option: %s, value: %d", option, vint);
S
slguan 已提交
164 165 166

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

S
Shengliang Guan 已提交
170
    int32_t cfgLen = (int32_t)strlen(cfg->option);
171
    if (cfgLen != olen) continue;
T
tickduan 已提交
172 173 174 175 176 177
    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 已提交
178

S
slguan 已提交
179
    if (strncasecmp(cfg->option, "monitor", olen) == 0) {
180
      if (1 == vint) {
S
Shengliang Guan 已提交
181 182
        if (monStartSystemFp) {
          (*monStartSystemFp)();
183
          uInfo("monitor is enabled");
184 185
        } else {
          uError("monitor can't be updated, for monitor not initialized");
186 187
        }
      } else {
S
Shengliang Guan 已提交
188 189
        if (monStopSystemFp) {
          (*monStopSystemFp)();
190
          uInfo("monitor is disabled");
191 192
        } else {
          uError("monitor can't be updated, for monitor not initialized");
193 194
        }
      }
S
Shengliang Guan 已提交
195
      return 0;
S
slguan 已提交
196
    }
Y
yihaoDeng 已提交
197
    if (strncasecmp(cfg->option, "debugFlag", olen) == 0) {
S
Shengliang Guan 已提交
198
      taosSetAllDebugFlag();
Y
yihaoDeng 已提交
199
    }
S
Shengliang Guan 已提交
200
    return 0;
S
slguan 已提交
201 202 203 204
  }

  if (strncasecmp(option, "resetlog", 8) == 0) {
    taosResetLog();
205
    taosPrintCfg();
S
Shengliang Guan 已提交
206
    return 0;
S
slguan 已提交
207 208 209
  }

  if (strncasecmp(option, "resetQueryCache", 15) == 0) {
S
Shengliang Guan 已提交
210 211
    if (monExecuteSQLFp) {
      (*monExecuteSQLFp)("resetQueryCache");
212 213 214 215
      uInfo("resetquerycache is executed");
    } else {
      uError("resetquerycache can't be executed, for monitor not started");
    }
S
slguan 已提交
216 217
  }

S
config  
Shengliang Guan 已提交
218
#endif
S
slguan 已提交
219 220 221
  return false;
}

S
Shengliang Guan 已提交
222 223 224 225 226 227
// 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 已提交
228 229

#ifndef _STORAGE
S
Shengliang Guan 已提交
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
// 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 已提交
245
#endif
S
TD-1767  
Shengliang Guan 已提交
246

S
config  
Shengliang Guan 已提交
247

S
TD-1767  
Shengliang Guan 已提交
248

249
static void doInitGlobalConfig(void) {
S
TD-1057  
Shengliang Guan 已提交
250
  osInit();
S
TD-1652  
Shengliang Guan 已提交
251
  srand(taosSafeRand());
S
config  
Shengliang Guan 已提交
252
#if 0
S
slguan 已提交
253
  SGlobalCfg cfg = {0};
S
Shengliang Guan 已提交
254

S
slguan 已提交
255 256

  cfg.option = "dataDir";
S
slguan 已提交
257
  cfg.ptr = tsDataDir;
S
TD-1767  
Shengliang Guan 已提交
258
  cfg.valType = TAOS_CFG_VTYPE_DATA_DIRCTORY;
S
slguan 已提交
259 260 261 262 263
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
  cfg.minValue = 0;
  cfg.maxValue = 0;
  cfg.ptrLength = TSDB_FILENAME_LEN;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
264
  taosAddConfigOption(cfg);
S
slguan 已提交
265 266


267 268 269 270
  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 已提交
271 272
  cfg.minValue = 10 * 10000;
  cfg.maxValue = 10000 * 10000;
273 274
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
275
  taosAddConfigOption(cfg);
H
Hui Li 已提交
276

S
slguan 已提交
277 278 279 280 281 282 283 284
  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;
285
  taosAddConfigOption(cfg);
S
slguan 已提交
286 287 288 289 290

  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 已提交
291
  cfg.minValue = 1;
S
slguan 已提交
292 293 294
  cfg.maxValue = 1000000;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_MS;
295
  taosAddConfigOption(cfg);
S
slguan 已提交
296 297 298 299 300 301 302 303 304

  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;
305
  taosAddConfigOption(cfg);
S
slguan 已提交
306 307 308 309 310 311 312 313 314

  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;
315
  taosAddConfigOption(cfg);
S
slguan 已提交
316 317

  cfg.option = "retryStreamCompDelay";
318
  cfg.ptr = &tsRetryStreamCompDelay;
S
slguan 已提交
319 320 321 322 323 324 325
  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;

326
  taosAddConfigOption(cfg);
S
slguan 已提交
327 328 329 330
  cfg.option = "streamCompDelayRatio";
  cfg.ptr = &tsStreamComputDelayRatio;
  cfg.valType = TAOS_CFG_VTYPE_FLOAT;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
331 332
  cfg.minValue = 0.1f;
  cfg.maxValue = 0.9f;
S
slguan 已提交
333 334
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
335
  taosAddConfigOption(cfg);
S
slguan 已提交
336 337 338 339 340 341

  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 已提交
342
  cfg.maxValue = 100000000.0f;
S
slguan 已提交
343 344
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
345
  taosAddConfigOption(cfg);
S
slguan 已提交
346

347 348
  cfg.option = "compressColData";
  cfg.ptr = &tsCompressColData;
349 350 351 352
  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;
353 354
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
355
  taosAddConfigOption(cfg);
356

357 358
  cfg.option = "maxWildCardsLength";
  cfg.ptr = &tsMaxWildCardsLen;
359 360 361
  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;
362
  cfg.maxValue = TSDB_MAX_FIELD_LEN;
363 364
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_BYTE;
365
  taosAddConfigOption(cfg);
366

367 368 369 370 371 372 373 374
  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;
375
  taosAddConfigOption(cfg);
376

S
slguan 已提交
377 378 379 380 381 382 383 384
  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;
385
  taosAddConfigOption(cfg);
S
slguan 已提交
386

H
Haojun Liao 已提交
387 388 389 390 391
  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 已提交
392
  cfg.maxValue = 500000000000.0f;
H
Haojun Liao 已提交
393 394
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_BYTE;
395
  taosAddConfigOption(cfg);
H
Haojun Liao 已提交
396

H
Haojun Liao 已提交
397 398
  cfg.option = "retrieveBlockingModel";
  cfg.ptr = &tsRetrieveBlockingModel;
399 400 401 402 403 404
  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;
405
  taosAddConfigOption(cfg);
406

407 408
  cfg.option = "keepColumnName";
  cfg.ptr = &tsKeepOriginalColumnName;
S
Shengliang Guan 已提交
409
  cfg.valType = TAOS_CFG_VTYPE_INT8;
410 411 412 413 414
  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;
415
  taosAddConfigOption(cfg);
416

S
slguan 已提交
417

S
TD-2498  
Shengliang Guan 已提交
418 419 420

  cfg.option = "slaveQuery";
  cfg.ptr = &tsEnableSlaveQuery;
S
Shengliang Guan 已提交
421 422 423 424 425 426
  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;
427
  taosAddConfigOption(cfg);
S
Shengliang Guan 已提交
428

S
slguan 已提交
429

S
TD-1520  
Shengliang Guan 已提交
430

431
  cfg.option = "enableRecordSql";
S
slguan 已提交
432
  cfg.ptr = &tsTscEnableRecordSql;
S
Shengliang Guan 已提交
433
  cfg.valType = TAOS_CFG_VTYPE_INT8;
S
slguan 已提交
434 435 436 437 438
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
  cfg.minValue = 0;
  cfg.maxValue = 1;
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
439
  taosAddConfigOption(cfg);
S
slguan 已提交
440

441 442 443 444 445
  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;
446
  cfg.maxValue = 65536;
447 448
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
449
  taosAddConfigOption(cfg);
450 451 452 453 454 455 456

  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 已提交
457
  cfg.ptrLength = PATH_MAX;
458
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
459
  taosAddConfigOption(cfg);
460

S
Shengliang Guan 已提交
461
  // enable kill long query
462 463 464 465 466 467 468 469
  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;
470
  taosAddConfigOption(cfg);
471

T
tickduan 已提交
472
#ifdef TD_TSZ
T
tickduan 已提交
473
  // lossy compress
T
tickduan 已提交
474
  cfg.option = "lossyColumns";
T
tickduan 已提交
475 476 477 478 479 480 481
  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;
482
  taosAddConfigOption(cfg);
T
tickduan 已提交
483 484 485 486 487

  cfg.option = "fPrecision";
  cfg.ptr = &fPrecision;
  cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
T
tickduan 已提交
488
  cfg.minValue = MIN_FLOAT;
S
config  
Shengliang Guan 已提交
489
  cfg.maxValue = 100000;
T
tickduan 已提交
490 491
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
T
tickduan 已提交
492

493
  taosAddConfigOption(cfg);
T
tickduan 已提交
494 495 496 497 498

  cfg.option = "dPrecision";
  cfg.ptr = &dPrecision;
  cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
  cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
S
config  
Shengliang Guan 已提交
499 500
  cfg.minValue = 100000;
  cfg.maxValue = 0;
T
tickduan 已提交
501 502
  cfg.ptrLength = 0;
  cfg.unitType = TAOS_CFG_UTYPE_NONE;
503
  taosAddConfigOption(cfg);
T
tickduan 已提交
504

T
tickduan 已提交
505 506
  cfg.option = "maxRange";
  cfg.ptr = &maxRange;
T
tickduan 已提交
507 508 509 510 511 512
  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;
513
  taosAddConfigOption(cfg);
T
tickduan 已提交
514

T
tickduan 已提交
515
  cfg.option = "range";
T
tickduan 已提交
516
  cfg.ptr = &curRange;
T
tickduan 已提交
517 518 519 520 521 522
  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;
523
  taosAddConfigOption(cfg);
524 525
  assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM);
#else
S
Shengliang Guan 已提交
526
  // assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM - 5);
527
#endif
S
config  
Shengliang Guan 已提交
528 529

#endif
S
slguan 已提交
530 531
}

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

534 535 536 537
/*
 * alter dnode 1 balance "vnode:1-dnode:2"
 */

S
Shengliang Guan 已提交
538
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId) {
539
  int len = (int)strlen(option);
540 541 542 543 544 545 546 547 548 549 550 551 552 553
  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 已提交
554 555 556
  *vnodeId = strtol(option + 6, NULL, 10);
  *dnodeId = strtol(option + pos + 6, NULL, 10);
  if (*vnodeId <= 1 || *dnodeId <= 0) {
557 558 559 560
    return false;
  }

  return true;
561
}