• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4933

20 Jan 2026 10:44AM UTC coverage: 66.671% (+0.03%) from 66.646%
#4933

push

travis-ci

web-flow
merge: from main to 3.0 #34340

73 of 178 new or added lines in 9 files covered. (41.01%)

1199 existing lines in 124 files now uncovered.

203121 of 304663 relevant lines covered (66.67%)

132228377.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

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

17
#include "dmMgmt.h"
18
#include "dmUtil.h"
19
#include "mnode.h"
20
#include "osEnv.h"
21
#include "osFile.h"
22
#include "qworker.h"
23
#include "tconfig.h"
24
#include "tconv.h"
25
#include "tglobal.h"
26
#include "tss.h"
27
#include "version.h"
28

29
#ifdef TD_JEMALLOC_ENABLED
30
#define ALLOW_FORBID_FUNC
31
#include "jemalloc/jemalloc.h"
32
#endif
33

34
#include "cus_name.h"
35

36
// clang-format off
37
#define DM_APOLLO_URL    "The apollo string to use when configuring the server, such as: -a 'jsonFile:./tests/cfg.json', cfg.json text can be '{\"fqdn\":\"td1\"}'."
38
#define DM_CFG_DIR       "Configuration directory."
39
#define DM_DMP_CFG       "Dump configuration."
40
#define DM_SDB_INFO      "Dump sdb info."
41
#define DM_ENV_CMD       "The env cmd variable string to use when configuring the server, such as: -e 'TAOS_FQDN=td1'."
42
#define DM_ENV_FILE      "The env variable file path to use when configuring the server, default is './.env', .env text can be 'TAOS_FQDN=td1'."
43
#define DM_MACHINE_CODE  "Get machine code."
44
#define DM_LOG_OUTPUT    "Specify log output. Options:\n\r\t\t\t   stdout, stderr, /dev/null, <directory>, <directory>/<filename>, <filename>\n\r\t\t\t   * If OUTPUT contains an absolute directory, logs will be stored in that directory instead of logDir.\n\r\t\t\t   * If OUTPUT contains a relative directory, logs will be stored in the directory combined with logDir and the relative directory."
45
#define DM_VERSION       "Print program version."
46
#define DM_EMAIL         "<support@taosdata.com>"
47
#define DM_MEM_DBG       "Enable memory debug"
48
#define DM_SET_ENCRYPTKEY  "Set encrypt key. such as: -y 1234567890abcdef, the length should be less or equal to 16."
49

50
// clang-format on
51
static struct {
52
#ifdef WINDOWS
53
  bool winServiceMode;
54
#endif
55
  bool         dumpConfig;
56
  bool         dumpSdb;
57
  bool         deleteTrans;
58
  bool         modifySdb;
59
  char         sdbJsonFile[PATH_MAX];
60
  bool         generateGrant;
61
  bool         memDbg;
62

63
#ifdef USE_SHARED_STORAGE
64
  bool         checkSs;
65
#endif
66

67
  bool         printAuth;
68
  bool         printVersion;
69
  bool         printHelp;
70
  char         envFile[PATH_MAX];
71
  char         apolloUrl[PATH_MAX];
72
  const char **envCmd;
73
  SArray      *pArgs;  // SConfigPair
74
  int64_t      startTime;
75
  bool         generateCode;
76
  char         encryptKey[ENCRYPT_KEY_LEN + 1];
77
} global = {0};
78

79
extern int32_t cryptLoadProviders();
80
static void dmSetDebugFlag(int32_t signum, void *sigInfo, void *context) { (void)taosSetGlobalDebugFlag(143); }
×
81
static void dmSetAssert(int32_t signum, void *sigInfo, void *context) { tsAssert = 1; }
×
82

83
static void dmStopDnode(int signum, void *sigInfo, void *context) {
572,035✔
84
  // taosIgnSignal(SIGUSR1);
85
  // taosIgnSignal(SIGUSR2);
86
#ifndef TD_ASTRA
87
  if (taosIgnSignal(SIGTERM) != 0) {
572,035✔
88
    dWarn("failed to ignore signal SIGTERM");
×
89
  }
90
  if (taosIgnSignal(SIGHUP) != 0) {
572,747✔
91
    dWarn("failed to ignore signal SIGHUP");
×
92
  }
93
  if (taosIgnSignal(SIGINT) != 0) {
572,747✔
94
    dWarn("failed to ignore signal SIGINT");
×
95
  }
96
  if (taosIgnSignal(SIGABRT) != 0) {
572,747✔
97
    dWarn("failed to ignore signal SIGABRT");
×
98
  }
99
  if (taosIgnSignal(SIGBREAK) != 0) {
572,747✔
100
    dWarn("failed to ignore signal SIGBREAK");
572,747✔
101
  }
102
#endif
103
  dInfo("shut down signal is %d", signum);
572,747✔
104
#if !defined(WINDOWS) && !defined(TD_ASTRA)
105
  if (sigInfo != NULL) {
572,747✔
106
    dInfo("sender PID:%d cmdline:%s", ((siginfo_t *)sigInfo)->si_pid,
572,747✔
107
        taosGetCmdlineByPID(((siginfo_t *)sigInfo)->si_pid));
108
  }
109
#endif
110

111
  dmStop();
572,747✔
112
}
572,747✔
113

114
void dmStopDaemon() { dmStopDnode(SIGTERM, NULL, NULL); }
×
115

116
void dmLogCrash(int signum, void *sigInfo, void *context) {
×
117
  // taosIgnSignal(SIGTERM);
118
  // taosIgnSignal(SIGHUP);
119
  // taosIgnSignal(SIGINT);
120
  // taosIgnSignal(SIGBREAK);
121

122
#ifndef WINDOWS
123
  if (taosIgnSignal(SIGBUS) != 0) {
×
124
    dWarn("failed to ignore signal SIGBUS");
×
125
  }
126
#endif
127
  if (taosIgnSignal(SIGABRT) != 0) {
×
128
    dWarn("failed to ignore signal SIGABRT");
×
129
  }
130
  if (taosIgnSignal(SIGFPE) != 0) {
×
131
    dWarn("failed to ignore signal SIGABRT");
×
132
  }
133
  if (taosIgnSignal(SIGSEGV) != 0) {
×
134
    dWarn("failed to ignore signal SIGABRT");
×
135
  }
136
#ifdef USE_REPORT
137
  writeCrashLogToFile(signum, sigInfo, CUS_PROMPT "d", dmGetClusterId(), global.startTime);
×
138
#endif
139
#ifdef _TD_DARWIN_64
140
  exit(signum);
141
#elif defined(WINDOWS)
142
  exit(signum);
143
#endif
144
}
×
145

146
static void dmSetSignalHandle() {
549,015✔
147
  if (taosSetSignal(SIGUSR1, dmSetDebugFlag) != 0) {
549,015✔
148
    dWarn("failed to set signal SIGUSR1");
×
149
  }
150
  if (taosSetSignal(SIGUSR2, dmSetAssert) != 0) {
549,015✔
151
    dWarn("failed to set signal SIGUSR1");
×
152
  }
153
  if (taosSetSignal(SIGTERM, dmStopDnode) != 0) {
549,015✔
154
    dWarn("failed to set signal SIGUSR1");
×
155
  }
156
  if (taosSetSignal(SIGHUP, dmStopDnode) != 0) {
549,015✔
157
    dWarn("failed to set signal SIGUSR1");
×
158
  }
159
  if (taosSetSignal(SIGINT, dmStopDnode) != 0) {
549,015✔
160
    dWarn("failed to set signal SIGUSR1");
×
161
  }
162
  if (taosSetSignal(SIGBREAK, dmStopDnode) != 0) {
549,015✔
163
    dWarn("failed to set signal SIGUSR1");
549,015✔
164
  }
165
  if (taosSetSignal(SIGABRT, dmLogCrash) != 0) {
549,015✔
166
    dWarn("failed to set signal SIGUSR1");
×
167
  }
168
  if (taosSetSignal(SIGFPE, dmLogCrash) != 0) {
549,015✔
169
    dWarn("failed to set signal SIGUSR1");
×
170
  }
171
  if (taosSetSignal(SIGSEGV, dmLogCrash) != 0) {
549,015✔
172
    dWarn("failed to set signal SIGUSR1");
×
173
  }
174
#ifndef WINDOWS
175
  if (taosSetSignal(SIGTSTP, dmStopDnode) != 0) {
549,015✔
176
    dWarn("failed to set signal SIGUSR1");
×
177
  }
178
  if (taosSetSignal(SIGQUIT, dmStopDnode) != 0) {
549,015✔
179
    dWarn("failed to set signal SIGUSR1");
×
180
  }
181
  if (taosSetSignal(SIGBUS, dmLogCrash) != 0) {
549,015✔
182
    dWarn("failed to set signal SIGUSR1");
×
183
  }
184
#endif
185
}
549,015✔
186

187
extern bool generateNewMeta;
188

189
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
559,605✔
190
  global.startTime = taosGetTimestampMs();
559,605✔
191

192
  int32_t cmdEnvIndex = 0;
559,605✔
193
  if (argc < 2) return 0;
559,605✔
194

195
  global.envCmd = taosMemoryMalloc((argc - 1) * sizeof(char *));
559,605✔
196
  if (global.envCmd == NULL) {
559,605✔
197
    return terrno;
×
198
  }
199
  memset(global.envCmd, 0, (argc - 1) * sizeof(char *));
559,605✔
200
  for (int32_t i = 1; i < argc; ++i) {
1,119,319✔
201
    if (strcmp(argv[i], "-c") == 0) {
559,727✔
202
      if (i < argc - 1) {
559,209✔
203
        if (strlen(argv[++i]) >= PATH_MAX) {
559,196✔
204
          printf("config file path overflow");
×
205
          return TSDB_CODE_INVALID_CFG;
×
206
        }
207
        tstrncpy(configDir, argv[i], PATH_MAX);
559,196✔
208
      } else {
209
        printf("'-c' requires a parameter, default is %s\n", configDir);
13✔
210
        return TSDB_CODE_INVALID_CFG;
13✔
211
      }
212
    } else if (strcmp(argv[i], "-a") == 0) {
518✔
213
      if (i < argc - 1) {
41✔
214
        if (strlen(argv[++i]) >= PATH_MAX) {
41✔
215
          printf("apollo url overflow");
×
216
          return TSDB_CODE_INVALID_CFG;
×
217
        }
218
        tstrncpy(global.apolloUrl, argv[i], PATH_MAX);
41✔
219
      } else {
220
        printf("'-a' requires a parameter\n");
×
221
        return TSDB_CODE_INVALID_CFG;
×
222
      }
223
    } else if (strcmp(argv[i], "-s") == 0) {
477✔
224
      global.dumpSdb = true;
56✔
225
    } else if (strcmp(argv[i], "-dTxn") == 0) {
421✔
226
      global.deleteTrans = true;
×
227
    } else if (strcmp(argv[i], "-mSdb") == 0) {
421✔
228
      global.modifySdb = true;
×
229
      if (i < argc - 1) {
×
230
        i++;
×
231
        if (strlen(argv[i]) >= PATH_MAX) {
×
232
          printf("sdb.json file path is too long\n");
×
233
          return TSDB_CODE_INVALID_CFG;
×
234
        }
235
        tstrncpy(global.sdbJsonFile, argv[i], PATH_MAX);
×
236
      } else {
237
        printf("'-mSdb' requires sdb.json file path\n");
×
238
        return TSDB_CODE_INVALID_CFG;
×
239
      }
240
    } else if (strcmp(argv[i], "-r") == 0) {
421✔
241
      generateNewMeta = true;
×
242
    } else if (strcmp(argv[i], "-E") == 0) {
421✔
243
      if (i < argc - 1) {
13✔
244
        if (strlen(argv[++i]) >= PATH_MAX) {
13✔
245
          printf("env file path overflow");
×
246
          return TSDB_CODE_INVALID_CFG;
×
247
        }
248
        tstrncpy(global.envFile, argv[i], PATH_MAX);
13✔
249
      } else {
250
        printf("'-E' requires a parameter\n");
×
251
        return TSDB_CODE_INVALID_CFG;
×
252
      }
253
    } else if (strcmp(argv[i], "-k") == 0) {
408✔
254
      global.generateGrant = true;
41✔
255
#if defined(LINUX)
256
    } else if (strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--log-output") == 0 ||
367✔
257
               strncmp(argv[i], "--log-output=", 13) == 0) {
367✔
258
      if ((i < argc - 1) || ((i == argc - 1) && strncmp(argv[i], "--log-output=", 13) == 0)) {
28✔
259
        int32_t     klen = strlen(argv[i]);
14✔
260
        int32_t     vlen = klen < 13 ? strlen(argv[++i]) : klen - 13;
14✔
261
        const char *val = argv[i];
14✔
262
        if (klen >= 13) val += 13;
14✔
263
        if (vlen <= 0 || vlen >= PATH_MAX) {
14✔
264
          printf("failed to set log output since invalid vlen:%d, valid range: [1, %d)\n", vlen, PATH_MAX);
×
265
          return TSDB_CODE_INVALID_CFG;
×
266
        }
267
        tsLogOutput = taosMemoryMalloc(PATH_MAX);
14✔
268
        if (!tsLogOutput) {
14✔
269
          printf("failed to set log output: '%s' since %s\n", val, tstrerror(terrno));
×
270
          return terrno;
×
271
        }
272
        if (taosExpandDir(val, tsLogOutput, PATH_MAX) != 0) {
14✔
273
          printf("failed to expand log output: '%s' since %s\n", val, tstrerror(terrno));
×
274
          return terrno;
×
275
        }
276
      } else {
277
        printf("'%s' requires a parameter\n", argv[i]);
×
278
        return TSDB_CODE_INVALID_CFG;
×
279
      }
280
#endif
281
    } else if (strcmp(argv[i], "-y") == 0) {
353✔
282
      global.generateCode = true;
×
283
      if (i < argc - 1) {
×
284
        int32_t len = strlen(argv[++i]);
×
285
        if (len < ENCRYPT_KEY_LEN_MIN) {
×
286
          printf("ERROR: Encrypt key should be at least %d characters\n", ENCRYPT_KEY_LEN_MIN);
×
287
          return TSDB_CODE_INVALID_CFG;
×
288
        }
289
        if (len > ENCRYPT_KEY_LEN) {
×
290
          printf("ERROR: Encrypt key overflow, it should be at most %d characters\n", ENCRYPT_KEY_LEN);
×
291
          return TSDB_CODE_INVALID_CFG;
×
292
        }
293
        tstrncpy(global.encryptKey, argv[i], ENCRYPT_KEY_LEN + 1);
×
294
      } else {
295
        printf("'-y' requires a parameter\n");
×
296
        return TSDB_CODE_INVALID_CFG;
×
297
      }
298
    } else if (strcmp(argv[i], "-C") == 0) {
353✔
299
      global.dumpConfig = true;
41✔
300
    } else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
312✔
301
      global.printVersion = true;
204✔
302
#ifdef WINDOWS
303
    } else if (strcmp(argv[i], "--win_service") == 0) {
304
      global.winServiceMode = true;
305
#endif
306
    } else if (strcmp(argv[i], "-e") == 0) {
108✔
307
      global.envCmd[cmdEnvIndex] = argv[++i];
26✔
308
      cmdEnvIndex++;
26✔
309
    } else if (strcmp(argv[i], "-dm") == 0) {
82✔
310
      global.memDbg = true;
13✔
311
#ifdef USE_SHARED_STORAGE
312
    } else if (strcmp(argv[i], "--checkss") == 0) {
69✔
313
      global.checkSs = true;
×
314
#endif
315
    } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--usage") == 0 ||
69✔
316
               strcmp(argv[i], "-?") == 0) {
×
317
      global.printHelp = true;
69✔
318
    } else {
319
      printf("taosd: invalid option: %s\n", argv[i]);
×
320
      printf("Try `taosd --help' or `taosd --usage' for more information.\n");
×
321
      return TSDB_CODE_INVALID_CFG;
×
322
    }
323
  }
324

325
  return 0;
559,592✔
326
}
327

328
static void dmPrintArgs(int32_t argc, char const *argv[]) {
559,238✔
329
  char path[1024] = {0};
559,238✔
330
  taosGetCwd(path, sizeof(path));
559,238✔
331

332
  char args[1024] = {0};
559,238✔
333
  if (argc > 0) {
559,238✔
334
    int32_t arglen = tsnprintf(args, sizeof(args), "%s", argv[0]);
559,238✔
335
    for (int32_t i = 1; i < argc; ++i) {
1,677,781✔
336
      arglen = arglen + tsnprintf(args + arglen, sizeof(args) - arglen, " %s", argv[i]);
1,118,543✔
337
    }
338
  }
339

340
  dInfo("startup path:%s args:%s", path, args);
559,238✔
341
}
559,238✔
342

343
static void dmGenerateGrant() { mndGenerateMachineCode(); }
41✔
344

345
static void dmPrintVersion() {
204✔
346
  printf("%s\n%sd version: %s compatible_version: %s\n", TD_PRODUCT_NAME, CUS_PROMPT, td_version,
204✔
347
         td_compatible_version);
348
  printf("git: %s\n", td_gitinfo);
204✔
349
#ifdef TD_ENTERPRISE
350
  printf("gitOfInternal: %s\n", td_gitinfoOfInternal);
204✔
351
#endif
352
  printf("build: %s\n", td_buildinfo);
204✔
353
}
204✔
354

355
static void dmPrintHelp() {
69✔
356
  char indent[] = "  ";
69✔
357
  printf("Usage: %sd [OPTION...] \n\n", CUS_PROMPT);
69✔
358
  printf("%s%s%s%s\n", indent, "-a,", indent, DM_APOLLO_URL);
69✔
359
  printf("%s%s%s%s\n", indent, "-c,", indent, DM_CFG_DIR);
69✔
360
  printf("%s%s%s%s\n", indent, "-s,", indent, DM_SDB_INFO);
69✔
361
  printf("%s%s%s%s\n", indent, "-C,", indent, DM_DMP_CFG);
69✔
362
  printf("%s%s%s%s\n", indent, "-e,", indent, DM_ENV_CMD);
69✔
363
  printf("%s%s%s%s\n", indent, "-E,", indent, DM_ENV_FILE);
69✔
364
  printf("%s%s%s%s\n", indent, "-k,", indent, DM_MACHINE_CODE);
69✔
365
#if defined(LINUX)
366
  printf("%s%s%s%s\n", indent, "-o, --log-output=OUTPUT", indent, DM_LOG_OUTPUT);
69✔
367
#endif
368
  printf("%s%s%s%s\n", indent, "-y,", indent, DM_SET_ENCRYPTKEY);
69✔
369
  printf("%s%s%s%s\n", indent, "-dm,", indent, DM_MEM_DBG);
69✔
370
  printf("%s%s%s%s\n", indent, "-V,", indent, DM_VERSION);
69✔
371

372
  printf("\n\nReport bugs to %s.\n", DM_EMAIL);
69✔
373
}
69✔
374

375
static void dmDumpCfg() {
41✔
376
  SConfig *pCfg = taosGetCfg();
41✔
377
  cfgDumpCfg(pCfg, 0, true);
41✔
378
}
41✔
379

380

381
#ifdef USE_SHARED_STORAGE
382
static int32_t dmCheckSs() {
×
383
  int32_t  code = 0;
×
384
  (void)printf("\n");
×
385
  
386
  if (!tsSsEnabled) {
×
387
    printf("shared storage is disabled (ssEnabled is 0), please enable it and try again.\n");
×
388
    return TSDB_CODE_OPS_NOT_SUPPORT;
×
389
  }
390

391
  code = tssInit();
×
392
  if (code != 0) {
×
393
    printf("failed to initialize shared storage, error code=%d.\n", code);
×
394
    return code;
×
395
  }
396

397
  code = tssCreateDefaultInstance();
×
398
  if (code != 0) {
×
399
    printf("failed to create default shared storage instance, error code=%d.\n", code);
×
400
    (void)tssUninit();
×
401
    return code;
×
402
  }
403

404
  (void)printf("shared storage configuration\n");
×
405
  (void)printf("=================================================================\n");
×
406
  tssPrintDefaultConfig();
×
407
  (void)printf("=================================================================\n");
×
408
  code = tssCheckDefaultInstance(0);
×
409
  (void)printf("=================================================================\n");
×
410

411
  if (code == TSDB_CODE_SUCCESS){
×
412
    printf("shared storage configuration check finished successfully.\n");
×
413
  } else {
414
    printf("shared storage configuration check finished with error.\n");
×
415
  }
416

417
  (void)tssCloseDefaultInstance();
×
418
  (void)tssUninit();
×
419

420
  return code;
×
421
}
422
#endif
423

424
static int32_t dmInitLog() {
559,278✔
425
  const char *logName = CUS_PROMPT "dlog";
559,278✔
426

427
  TAOS_CHECK_RETURN(taosInitLogOutput(&logName));
559,278✔
428

429
  return taosCreateLog(logName, 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0);
559,264✔
430
}
431

432
static void taosCleanupArgs() {
559,508✔
433
  if (global.envCmd != NULL) taosMemoryFreeClear(global.envCmd);
559,508✔
434
}
559,508✔
435

436
#ifdef TAOSD_INTEGRATED
437
int dmStartDaemon(int argc, char const *argv[]) {
438
#else
439
int main(int argc, char const *argv[]) {
559,605✔
440
#endif
441
  int32_t code = 0;
559,605✔
442
#ifdef TD_JEMALLOC_ENABLED
443
  bool jeBackgroundThread = true;
444
  mallctl("background_thread", NULL, NULL, &jeBackgroundThread, sizeof(bool));
445
#endif
446
  if (!taosCheckSystemIsLittleEnd()) {
559,605✔
447
    printf("failed to start since on non-little-end machines\n");
×
448
    return -1;
×
449
  }
450

451
  if ((code = dmParseArgs(argc, argv)) != 0) {
559,605✔
452
    // printf("failed to start since parse args error\n");
453
    taosCleanupArgs();
13✔
454
    return code;
13✔
455
  }
456

457
#ifdef WINDOWS
458
  int mainWindows(int argc, char **argv);
459
  if (global.winServiceMode) {
460
    stratWindowsService(mainWindows);
461
  } else {
462
    return mainWindows(argc, argv);
463
  }
464
  return 0;
465
}
466
int mainWindows(int argc, char **argv) {
467
  int32_t code = 0;
468
#endif
469

470
  if (global.generateGrant) {
559,592✔
471
    dmGenerateGrant();
41✔
472
    taosCleanupArgs();
×
473
    return 0;
×
474
  }
475

476
  if (global.printHelp) {
559,551✔
477
    dmPrintHelp();
69✔
478
    taosCleanupArgs();
69✔
479
    return 0;
69✔
480
  }
481

482
  if (global.printVersion) {
559,482✔
483
    dmPrintVersion();
204✔
484
    taosCleanupArgs();
204✔
485
    return 0;
204✔
486
  }
487

488
#if defined(LINUX)
489
  if (global.memDbg) {
559,278✔
490
    code = taosMemoryDbgInit();
13✔
491
    if (code) {
13✔
492
      printf("failed to init memory dbg, error:%s\n", tstrerror(code));
×
493
      return code;
×
494
    }
495
    tsAsyncLog = false;
13✔
496
    printf("memory dbg enabled\n");
13✔
497
  }
498
#endif
499
  if (global.generateCode) {
559,278✔
500
    bool toLogFile = false;
×
501
    if ((code = taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs)) != 0) {
×
502
      encryptError("failed to generate encrypt code since dataDir can not be set from cfg file,reason:%s",
×
503
                   tstrerror(code));
504
      return code;
×
505
    };
506
    TdFilePtr pFile;
×
507
    if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) {
×
508
      encryptError("failed to generate encrypt code since taosd is running, please stop it first, reason:%s",
×
509
                   tstrerror(code));
510
      return code;
×
511
    }
512
    int ret = dmUpdateEncryptKey(global.encryptKey, toLogFile);
×
513
    if (taosCloseFile(&pFile) != 0) {
×
514
      encryptError("failed to close file:%p", pFile);
×
515
    }
516
    taosCloseLog();
×
517
    taosCleanupArgs();
×
518
    return ret;
×
519
  }
520

521
  if ((code = dmInitLog()) != 0) {
559,278✔
522
    printf("failed to start since init log error\n");
40✔
523
    taosCleanupArgs();
40✔
524
    return code;
40✔
525
  }
526

527
  dmPrintArgs(argc, argv);
559,238✔
528
  if ((code = taosPreLoadCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0)) != 0) {
559,238✔
NEW
529
    dError("failed to start since pre load config error");
×
NEW
530
    taosCloseLog();
×
NEW
531
    taosCleanupArgs();
×
NEW
532
    return code;
×
533
  }
534

535
  if ((code = dmGetEncryptKey()) != 0) {
559,238✔
NEW
536
    dError("failed to start since failed to get encrypt key");
×
NEW
537
    taosCloseLog();
×
NEW
538
    taosCleanupArgs();
×
NEW
539
    return code;
×
540
  };
541

542
  if ((code = tryLoadCfgFromDataDir(tsCfg)) != 0) {
559,238✔
NEW
543
    dError("failed to start since try load config from data dir error");
×
NEW
544
    taosCloseLog();
×
NEW
545
    taosCleanupArgs();
×
NEW
546
    return code;
×
547
  }
548

549
  if ((code = taosApplyCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0)) != 0) {
559,238✔
NEW
550
    dError("failed to start since apply config error");
×
551
    taosCloseLog();
×
552
    taosCleanupArgs();
×
553
    return code;
×
554
  }
555

556
  if ((code = taosMemoryPoolInit(qWorkerRetireJobs, qWorkerRetireJob)) != 0) {
559,238✔
557
    dError("failed to init memPool, error:0x%x", code);
×
558
    taosCloseLog();
×
559
    taosCleanupArgs();
×
560
    return code;
×
561
  }
562

563
#ifndef DISALLOW_NCHAR_WITHOUT_ICONV
564
  if ((tsCharsetCxt = taosConvInit(tsCharset)) == NULL) {
559,238✔
565
    dError("failed to init conv");
×
566
    taosCloseLog();
×
567
    taosCleanupArgs();
×
568
    return code;
×
569
  }
570
#endif
571

572
#ifdef USE_SHARED_STORAGE
573
  if (global.checkSs) {
559,238✔
574
    code = dmCheckSs();
×
575
    taosCleanupCfg();
×
576
    taosCloseLog();
×
577
    taosCleanupArgs();
×
578
    taosConvDestroy();
×
579
    return code;
×
580
  }
581
#endif
582

583
  if (global.dumpConfig) {
559,238✔
584
    dmDumpCfg();
41✔
585
    taosCleanupCfg();
41✔
586
    taosCloseLog();
41✔
587
    taosCleanupArgs();
41✔
588
    taosConvDestroy();
41✔
589
    return 0;
41✔
590
  }
591

592
  if (global.dumpSdb) {
559,197✔
593
    int32_t code = 0;
56✔
594
    tsSkipKeyCheckMode = true;  // Set global flag to skip key check mode
56✔
595
    TAOS_CHECK_RETURN(mndDumpSdb());
56✔
596
    taosCleanupCfg();
×
597
    taosCloseLog();
×
598
    taosCleanupArgs();
×
599
    taosConvDestroy();
×
600
    return 0;
×
601
  }
602

603
  if (global.deleteTrans) {
559,141✔
604
    int32_t   code = 0;
×
605
    TdFilePtr pFile;
×
606
    if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) {
×
607
      printf("failed to generate encrypt code since taosd is running, please stop it first, reason:%s",
×
608
             tstrerror(code));
609
      return code;
×
610
    }
611

612
    TAOS_CHECK_RETURN(mndDeleteTrans());
×
613
    taosCleanupCfg();
×
614
    taosCloseLog();
×
615
    taosCleanupArgs();
×
616
    taosConvDestroy();
×
617
    return 0;
×
618
  }
619

620
  if (global.modifySdb) {
559,141✔
621
    int32_t   code = 0;
×
622
    TdFilePtr pFile;
×
623
    if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) {
×
624
      printf("failed to modify sdb since taosd is running, please stop it first, reason:%s", tstrerror(code));
×
625
      return code;
×
626
    }
627

628
    TAOS_CHECK_RETURN(mndModifySdb(global.sdbJsonFile));
×
629
    taosCleanupCfg();
×
630
    taosCloseLog();
×
631
    taosCleanupArgs();
×
632
    taosConvDestroy();
×
633
    return 0;
×
634
  }
635

636
  osSetProcPath(argc, (char **)argv);
559,141✔
637
  taosCleanupArgs();
559,141✔
638

639
  if (tsEncryptExtDir[0] != '\0') {
559,141✔
640
#if defined(TD_ENTERPRISE) && defined(LINUX)
641
    if ((code = cryptLoadProviders()) != 0) {
×
642
      dError("failed to load encrypt providers since %s", tstrerror(code));
×
643
      taosCloseLog();
×
644
      taosCleanupArgs();
×
645
      return code;
×
646
    }
647
#endif
648
  }
649

650
  if ((code = dmInit()) != 0) {
559,141✔
651
    if (code == TSDB_CODE_NOT_FOUND) {
10,126✔
652
      dError("Initialization of dnode failed because your current operating system is not supported. For more information and supported platforms, please visit https://docs.taosdata.com/reference/supported/.");
×
653
    } else {
654
      dError("failed to init dnode since %s", tstrerror(code));
10,126✔
655
    }
656

657
    taosCleanupCfg();
10,126✔
658
    taosCloseLog();
10,126✔
659
    taosConvDestroy();
10,126✔
660
    return code;
10,126✔
661
  }
662

663
  dInfo("start to init service");
549,015✔
664
  dmSetSignalHandle();
549,015✔
665

666
  code = dmRun();
549,015✔
667
  dInfo("shutting down the service");
549,015✔
668

669
  dmCleanup();
549,015✔
670
  return code;
549,015✔
671
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc