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

taosdata / TDengine / #3827

01 Apr 2025 11:58AM UTC coverage: 34.049% (-0.03%) from 34.075%
#3827

push

travis-ci

happyguoxy
test:alter gcda dir

148461 of 599532 branches covered (24.76%)

Branch coverage included in aggregate %.

222339 of 489477 relevant lines covered (45.42%)

762087.13 hits per line

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

52.91
/source/dnode/mgmt/mgmt_dnode/src/dmWorker.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

16
#define _DEFAULT_SOURCE
17
#include "dmInt.h"
18
#include "tgrant.h"
19
#include "thttp.h"
20

21
static void *dmStatusThreadFp(void *param) {
70✔
22
  SDnodeMgmt *pMgmt = param;
70✔
23
  int64_t     lastTime = taosGetTimestampMs();
70✔
24
  setThreadName("dnode-status");
70✔
25

26
  int32_t upTimeCount = 0;
70✔
27
  int64_t upTime = 0;
70✔
28

29
  while (1) {
17,260✔
30
    taosMsleep(200);
17,330✔
31
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
17,330!
32

33
    int64_t curTime = taosGetTimestampMs();
17,260✔
34
    if (curTime < lastTime) lastTime = curTime;
17,260!
35
    float interval = (curTime - lastTime) / 1000.0f;
17,260✔
36
    if (interval >= tsStatusInterval) {
17,260✔
37
      dmSendStatusReq(pMgmt);
3,534✔
38
      lastTime = curTime;
3,534✔
39

40
      if ((upTimeCount = ((upTimeCount + 1) & 63)) == 0) {
3,534✔
41
        upTime = taosGetOsUptime() - tsDndStartOsUptime;
32✔
42
        tsDndUpTime = TMAX(tsDndUpTime, upTime);
32✔
43
      }
44
    }
45
  }
46

47
  return NULL;
70✔
48
}
49

50
static void *dmConfigThreadFp(void *param) {
70✔
51
  SDnodeMgmt *pMgmt = param;
70✔
52
  int64_t     lastTime = taosGetTimestampMs();
70✔
53
  setThreadName("dnode-config");
70✔
54
  while (1) {
406✔
55
    taosMsleep(200);
476✔
56
    if (pMgmt->pData->dropped || pMgmt->pData->stopped || tsConfigInited) break;
476!
57

58
    int64_t curTime = taosGetTimestampMs();
406✔
59
    if (curTime < lastTime) lastTime = curTime;
406!
60
    float interval = (curTime - lastTime) / 1000.0f;
406✔
61
    if (interval >= tsStatusInterval) {
406✔
62
      dmSendConfigReq(pMgmt);
83✔
63
      lastTime = curTime;
83✔
64
    }
65
  }
66
  return NULL;
70✔
67
}
68

69
static void *dmStatusInfoThreadFp(void *param) {
70✔
70
  SDnodeMgmt *pMgmt = param;
140✔
71
  int64_t     lastTime = taosGetTimestampMs();
70✔
72
  setThreadName("dnode-status-info");
70✔
73

74
  int32_t upTimeCount = 0;
70✔
75
  int64_t upTime = 0;
70✔
76

77
  while (1) {
18,041✔
78
    taosMsleep(200);
18,111✔
79
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
18,111!
80

81
    int64_t curTime = taosGetTimestampMs();
18,041✔
82
    if (curTime < lastTime) lastTime = curTime;
18,041!
83
    float interval = (curTime - lastTime) / 1000.0f;
18,041✔
84
    if (interval >= tsStatusInterval) {
18,041✔
85
      dmUpdateStatusInfo(pMgmt);
3,645✔
86
      lastTime = curTime;
3,645✔
87

88
      if ((upTimeCount = ((upTimeCount + 1) & 63)) == 0) {
3,645✔
89
        upTime = taosGetOsUptime() - tsDndStartOsUptime;
32✔
90
        tsDndUpTime = TMAX(tsDndUpTime, upTime);
32✔
91
      }
92
    }
93
  }
94

95
  return NULL;
70✔
96
}
97

98
#if defined(TD_ENTERPRISE)
99
SDmNotifyHandle dmNotifyHdl = {.state = 0};
100
#define TIMESERIES_STASH_NUM 5
101
static void *dmNotifyThreadFp(void *param) {
70✔
102
  SDnodeMgmt *pMgmt = param;
70✔
103
  int64_t     lastTime = taosGetTimestampMs();
70✔
104
  setThreadName("dnode-notify");
70✔
105

106
  if (tsem_init(&dmNotifyHdl.sem, 0, 0) != 0) {
70!
107
    return NULL;
×
108
  }
109

110
  // calculate approximate timeSeries per second
111
  int64_t  notifyTimeStamp[TIMESERIES_STASH_NUM];
112
  int64_t  notifyTimeSeries[TIMESERIES_STASH_NUM];
113
  int64_t  approximateTimeSeries = 0;
70✔
114
  uint64_t nTotalNotify = 0;
70✔
115
  int32_t  head, tail = 0;
70✔
116

117
  bool       wait = true;
70✔
118
  int32_t    nDnode = 0;
70✔
119
  int64_t    lastNotify = 0;
70✔
120
  int64_t    lastFetchDnode = 0;
70✔
121
  SNotifyReq req = {0};
70✔
122
  while (1) {
2,775✔
123
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
2,845!
124
    if (wait) tsem_wait(&dmNotifyHdl.sem);
2,775!
125
    atomic_store_8(&dmNotifyHdl.state, 1);
2,775✔
126

127
    int64_t remainTimeSeries = grantRemain(TSDB_GRANT_TIMESERIES);
2,775✔
128
    if (remainTimeSeries == INT64_MAX || remainTimeSeries <= 0) {
2,775!
129
      goto _skip;
2,775✔
130
    }
131
    int64_t current = taosGetTimestampMs();
×
132
    if (current - lastFetchDnode > 1000) {
×
133
      nDnode = dmGetDnodeSize(pMgmt->pData);
×
134
      if (nDnode < 1) nDnode = 1;
×
135
      lastFetchDnode = current;
×
136
    }
137
    if (req.dnodeId == 0 || req.clusterId == 0) {
×
138
      req.dnodeId = pMgmt->pData->dnodeId;
×
139
      req.clusterId = pMgmt->pData->clusterId;
×
140
    }
141

142
    if (current - lastNotify < 10) {
×
143
      int64_t nCmprTimeSeries = approximateTimeSeries / 100;
×
144
      if (nCmprTimeSeries < 1e5) nCmprTimeSeries = 1e5;
×
145
      if (remainTimeSeries > nCmprTimeSeries * 10) {
×
146
        taosMsleep(10);
×
147
      } else if (remainTimeSeries > nCmprTimeSeries * 5) {
×
148
        taosMsleep(5);
×
149
      } else {
150
        taosMsleep(2);
×
151
      }
152
    }
153

154
    SMonVloadInfo vinfo = {0};
×
155
    (*pMgmt->getVnodeLoadsLiteFp)(&vinfo);
×
156
    req.pVloads = vinfo.pVloads;
×
157
    int32_t nVgroup = taosArrayGetSize(req.pVloads);
×
158
    int64_t nTimeSeries = 0;
×
159
    for (int32_t i = 0; i < nVgroup; ++i) {
×
160
      SVnodeLoadLite *vload = TARRAY_GET_ELEM(req.pVloads, i);
×
161
      nTimeSeries += vload->nTimeSeries;
×
162
    }
163
    notifyTimeSeries[tail] = nTimeSeries;
×
164
    notifyTimeStamp[tail] = taosGetTimestampNs();
×
165
    ++nTotalNotify;
×
166

167
    approximateTimeSeries = 0;
×
168
    if (nTotalNotify >= TIMESERIES_STASH_NUM) {
×
169
      head = tail - TIMESERIES_STASH_NUM + 1;
×
170
      if (head < 0) head += TIMESERIES_STASH_NUM;
×
171
      int64_t timeDiff = notifyTimeStamp[tail] - notifyTimeStamp[head];
×
172
      int64_t tsDiff = notifyTimeSeries[tail] - notifyTimeSeries[head];
×
173
      if (tsDiff > 0) {
×
174
        if (timeDiff > 0 && timeDiff < 1e9) {
×
175
          approximateTimeSeries = (double)tsDiff * 1e9 / timeDiff;
×
176
          if ((approximateTimeSeries * nDnode) > remainTimeSeries) {
×
177
            dmSendNotifyReq(pMgmt, &req);
×
178
          }
179
        } else {
180
          dmSendNotifyReq(pMgmt, &req);
×
181
        }
182
      }
183
    } else {
184
      dmSendNotifyReq(pMgmt, &req);
×
185
    }
186
    if (++tail == TIMESERIES_STASH_NUM) tail = 0;
×
187

188
    tFreeSNotifyReq(&req);
×
189
    lastNotify = taosGetTimestampMs();
×
190
  _skip:
2,775✔
191
    if (1 == atomic_val_compare_exchange_8(&dmNotifyHdl.state, 1, 0)) {
2,775!
192
      wait = true;
2,775✔
193
      continue;
2,775✔
194
    }
195
    wait = false;
×
196
  }
197

198
  return NULL;
70✔
199
}
200
#endif
201

202
#ifdef USE_MONITOR
203
static void *dmMonitorThreadFp(void *param) {
70✔
204
  SDnodeMgmt *pMgmt = param;
70✔
205
  int64_t     lastTime = taosGetTimestampMs();
70✔
206
  int64_t     lastTimeForBasic = taosGetTimestampMs();
70✔
207
  setThreadName("dnode-monitor");
70✔
208

209
  static int32_t TRIM_FREQ = 20;
210
  int32_t        trimCount = 0;
70✔
211

212
  while (1) {
18,086✔
213
    taosMsleep(200);
18,156✔
214
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
18,156!
215

216
    int64_t curTime = taosGetTimestampMs();
18,086✔
217

218
    if (curTime < lastTime) lastTime = curTime;
18,086!
219
    float interval = (curTime - lastTime) / 1000.0f;
18,086✔
220
    if (interval >= tsMonitorInterval) {
18,086✔
221
      (*pMgmt->sendMonitorReportFp)();
101✔
222
      (*pMgmt->monitorCleanExpiredSamplesFp)();
101✔
223
      lastTime = curTime;
101✔
224

225
      trimCount = (trimCount + 1) % TRIM_FREQ;
101✔
226
      if (trimCount == 0) {
101!
227
        taosMemoryTrim(0, NULL);
×
228
      }
229
    }
230
    if (atomic_val_compare_exchange_8(&tsNeedTrim, 1, 0)) {
18,086✔
231
      taosMemoryTrim(0, NULL);
649!
232
    }
233
  }
234

235
  return NULL;
70✔
236
}
237
#endif
238
#ifdef USE_AUDIT
239
static void *dmAuditThreadFp(void *param) {
70✔
240
  SDnodeMgmt *pMgmt = param;
70✔
241
  int64_t     lastTime = taosGetTimestampMs();
70✔
242
  setThreadName("dnode-audit");
70✔
243

244
  while (1) {
35,844✔
245
    taosMsleep(100);
35,914✔
246
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
35,914!
247

248
    int64_t curTime = taosGetTimestampMs();
35,844✔
249
    if (curTime < lastTime) lastTime = curTime;
35,844!
250
    float interval = curTime - lastTime;
35,844✔
251
    if (interval >= tsAuditInterval) {
35,844✔
252
      (*pMgmt->sendAuditRecordsFp)();
716✔
253
      lastTime = curTime;
716✔
254
    }
255
  }
256

257
  return NULL;
70✔
258
}
259
#endif
260
#ifdef USE_REPORT
261
static void *dmCrashReportThreadFp(void *param) {
×
262
  int32_t     code = 0;
×
263
  SDnodeMgmt *pMgmt = param;
×
264
  int64_t     lastTime = taosGetTimestampMs();
×
265
  setThreadName("dnode-crashReport");
×
266
  char filepath[PATH_MAX] = {0};
×
267
  snprintf(filepath, sizeof(filepath), "%s%s.taosdCrashLog", tsLogDir, TD_DIRSEP);
×
268
  char     *pMsg = NULL;
×
269
  int64_t   msgLen = 0;
×
270
  TdFilePtr pFile = NULL;
×
271
  bool      truncateFile = false;
×
272
  int32_t   sleepTime = 200;
×
273
  int32_t   reportPeriodNum = 3600 * 1000 / sleepTime;
×
274
  int32_t   loopTimes = reportPeriodNum;
×
275

276
  STelemAddrMgmt mgt = {0};
×
277
  code = taosTelemetryMgtInit(&mgt, tsTelemServer);
×
278
  if (code != 0) {
×
279
    dError("failed to init telemetry since %s", tstrerror(code));
×
280
    return NULL;
×
281
  }
282
  code = initCrashLogWriter();
×
283
  if (code != 0) {
×
284
    dError("failed to init crash log writer since %s", tstrerror(code));
×
285
    return NULL;
×
286
  }
287

288
  while (1) {
289
    checkAndPrepareCrashInfo();
×
290
    if ((pMgmt->pData->dropped || pMgmt->pData->stopped) && reportThreadSetQuit()) {
×
291
      break;
×
292
    }
293
    if (loopTimes++ < reportPeriodNum) {
×
294
      taosMsleep(sleepTime);
×
295
      if(loopTimes < 0) loopTimes = reportPeriodNum;
×
296
      continue;
×
297
    }
298
    taosReadCrashInfo(filepath, &pMsg, &msgLen, &pFile);
×
299
    if (pMsg && msgLen > 0) {
×
300
      if (taosSendTelemReport(&mgt, tsSvrCrashReportUri, tsTelemPort, pMsg, msgLen, HTTP_FLAT) != 0) {
×
301
        dError("failed to send crash report");
×
302
        if (pFile) {
×
303
          taosReleaseCrashLogFile(pFile, false);
×
304
          pFile = NULL;
×
305

306
          taosMsleep(sleepTime);
×
307
          loopTimes = 0;
×
308
          continue;
×
309
        }
310
      } else {
311
        dInfo("succeed to send crash report");
×
312
        truncateFile = true;
×
313
      }
314
    } else {
315
      dInfo("no crash info was found");
×
316
    }
317

318
    taosMemoryFree(pMsg);
×
319

320
    if (pMsg && msgLen > 0) {
×
321
      pMsg = NULL;
×
322
      continue;
×
323
    }
324

325
    if (pFile) {
×
326
      taosReleaseCrashLogFile(pFile, truncateFile);
×
327
      pFile = NULL;
×
328
      truncateFile = false;
×
329
    }
330

331
    taosMsleep(sleepTime);
×
332
    loopTimes = 0;
×
333
  }
334
  taosTelemetryDestroy(&mgt);
×
335

336
  return NULL;
×
337
}
338
#endif
339

340
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
70✔
341
  int32_t      code = 0;
70✔
342
  TdThreadAttr thAttr;
343
  (void)taosThreadAttrInit(&thAttr);
70✔
344
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
70✔
345
#ifdef TD_COMPACT_OS
346
  (void)taosThreadAttrSetStackSize(&thAttr, STACK_SIZE_SMALL);
347
#endif
348
  if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) {
70!
349
    code = TAOS_SYSTEM_ERROR(ERRNO);
×
350
    dError("failed to create status thread since %s", tstrerror(code));
×
351
    return code;
×
352
  }
353

354
  (void)taosThreadAttrDestroy(&thAttr);
70✔
355
  tmsgReportStartup("dnode-status", "initialized");
70✔
356
  return 0;
70✔
357
}
358

359
int32_t dmStartConfigThread(SDnodeMgmt *pMgmt) {
70✔
360
  int32_t      code = 0;
70✔
361
  TdThreadAttr thAttr;
362
  (void)taosThreadAttrInit(&thAttr);
70✔
363
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
70✔
364
#ifdef TD_COMPACT_OS
365
  (void)taosThreadAttrSetStackSize(&thAttr, STACK_SIZE_SMALL);
366
#endif
367
  if (taosThreadCreate(&pMgmt->configThread, &thAttr, dmConfigThreadFp, pMgmt) != 0) {
70!
368
    code = TAOS_SYSTEM_ERROR(ERRNO);
×
369
    dError("failed to create config thread since %s", tstrerror(code));
×
370
    return code;
×
371
  }
372

373
  (void)taosThreadAttrDestroy(&thAttr);
70✔
374
  tmsgReportStartup("config-status", "initialized");
70✔
375
  return 0;
70✔
376
}
377

378
int32_t dmStartStatusInfoThread(SDnodeMgmt *pMgmt) {
70✔
379
  int32_t      code = 0;
70✔
380
  TdThreadAttr thAttr;
381
  (void)taosThreadAttrInit(&thAttr);
70✔
382
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
70✔
383
#ifdef TD_COMPACT_OS
384
  (void)taosThreadAttrSetStackSize(&thAttr, STACK_SIZE_SMALL);
385
#endif
386
  if (taosThreadCreate(&pMgmt->statusInfoThread, &thAttr, dmStatusInfoThreadFp, pMgmt) != 0) {
70!
387
    code = TAOS_SYSTEM_ERROR(ERRNO);
×
388
    dError("failed to create status Info thread since %s", tstrerror(code));
×
389
    return code;
×
390
  }
391

392
  (void)taosThreadAttrDestroy(&thAttr);
70✔
393
  tmsgReportStartup("dnode-status-info", "initialized");
70✔
394
  return 0;
70✔
395
}
396

397
void dmStopStatusThread(SDnodeMgmt *pMgmt) {
70✔
398
  if (taosCheckPthreadValid(pMgmt->statusThread)) {
70!
399
    (void)taosThreadJoin(pMgmt->statusThread, NULL);
70✔
400
    taosThreadClear(&pMgmt->statusThread);
70✔
401
  }
402
}
70✔
403

404
void dmStopConfigThread(SDnodeMgmt *pMgmt) {
70✔
405
  if (taosCheckPthreadValid(pMgmt->configThread)) {
70!
406
    (void)taosThreadJoin(pMgmt->configThread, NULL);
70✔
407
    taosThreadClear(&pMgmt->configThread);
70✔
408
  }
409
}
70✔
410

411
void dmStopStatusInfoThread(SDnodeMgmt *pMgmt) {
70✔
412
  if (taosCheckPthreadValid(pMgmt->statusInfoThread)) {
70!
413
    (void)taosThreadJoin(pMgmt->statusInfoThread, NULL);
70✔
414
    taosThreadClear(&pMgmt->statusInfoThread);
70✔
415
  }
416
}
70✔
417
#ifdef TD_ENTERPRISE
418
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) {
70✔
419
  int32_t      code = 0;
70✔
420
  TdThreadAttr thAttr;
421
  (void)taosThreadAttrInit(&thAttr);
70✔
422
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
70✔
423
  if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) {
70!
424
    code = TAOS_SYSTEM_ERROR(ERRNO);
×
425
    dError("failed to create notify thread since %s", tstrerror(code));
×
426
    return code;
×
427
  }
428

429
  (void)taosThreadAttrDestroy(&thAttr);
70✔
430
  tmsgReportStartup("dnode-notify", "initialized");
70✔
431
  return 0;
70✔
432
}
433

434
void dmStopNotifyThread(SDnodeMgmt *pMgmt) {
70✔
435
  if (taosCheckPthreadValid(pMgmt->notifyThread)) {
70!
436
    if (tsem_post(&dmNotifyHdl.sem) != 0) {
70!
437
      dError("failed to post notify sem");
×
438
    }
439

440
    (void)taosThreadJoin(pMgmt->notifyThread, NULL);
70✔
441
    taosThreadClear(&pMgmt->notifyThread);
70✔
442
  }
443
  if (tsem_destroy(&dmNotifyHdl.sem) != 0) {
70!
444
    dError("failed to destroy notify sem");
×
445
  }
446
}
70✔
447
#endif
448
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
70✔
449
  int32_t      code = 0;
70✔
450
#ifdef USE_MONITOR
451
  TdThreadAttr thAttr;
452
  (void)taosThreadAttrInit(&thAttr);
70✔
453
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
70✔
454
  if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) {
70!
455
    code = TAOS_SYSTEM_ERROR(ERRNO);
×
456
    dError("failed to create monitor thread since %s", tstrerror(code));
×
457
    return code;
×
458
  }
459

460
  (void)taosThreadAttrDestroy(&thAttr);
70✔
461
  tmsgReportStartup("dnode-monitor", "initialized");
70✔
462
#endif
463
  return 0;
70✔
464
}
465

466
int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
70✔
467
  int32_t      code = 0;
70✔
468
#ifdef USE_AUDIT  
469
  TdThreadAttr thAttr;
470
  (void)taosThreadAttrInit(&thAttr);
70✔
471
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
70✔
472
  if (taosThreadCreate(&pMgmt->auditThread, &thAttr, dmAuditThreadFp, pMgmt) != 0) {
70!
473
    code = TAOS_SYSTEM_ERROR(ERRNO);
×
474
    dError("failed to create audit thread since %s", tstrerror(code));
×
475
    return code;
×
476
  }
477

478
  (void)taosThreadAttrDestroy(&thAttr);
70✔
479
  tmsgReportStartup("dnode-audit", "initialized");
70✔
480
#endif  
481
  return 0;
70✔
482
}
483

484
void dmStopMonitorThread(SDnodeMgmt *pMgmt) {
70✔
485
#ifdef USE_MONITOR
486
  if (taosCheckPthreadValid(pMgmt->monitorThread)) {
70!
487
    (void)taosThreadJoin(pMgmt->monitorThread, NULL);
70✔
488
    taosThreadClear(&pMgmt->monitorThread);
70✔
489
  }
490
#endif
491
}
70✔
492

493
void dmStopAuditThread(SDnodeMgmt *pMgmt) {
70✔
494
#ifdef USE_AUDIT
495
  if (taosCheckPthreadValid(pMgmt->auditThread)) {
70!
496
    (void)taosThreadJoin(pMgmt->auditThread, NULL);
70✔
497
    taosThreadClear(&pMgmt->auditThread);
70✔
498
  }
499
#endif
500
}
70✔
501

502
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
70✔
503
  int32_t code = 0;
70✔
504
#ifdef USE_REPORT
505
  if (!tsEnableCrashReport) {
70!
506
    return 0;
70✔
507
  }
508

509
  TdThreadAttr thAttr;
510
  (void)taosThreadAttrInit(&thAttr);
×
511
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
×
512
  if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) {
×
513
    code = TAOS_SYSTEM_ERROR(ERRNO);
×
514
    dError("failed to create crashReport thread since %s", tstrerror(code));
×
515
    return code;
×
516
  }
517

518
  (void)taosThreadAttrDestroy(&thAttr);
×
519
  tmsgReportStartup("dnode-crashReport", "initialized");
×
520
#endif
521
  return 0;
×
522
}
523

524
void dmStopCrashReportThread(SDnodeMgmt *pMgmt) {
70✔
525
#ifdef USE_REPORT
526
  if (!tsEnableCrashReport) {
70!
527
    return;
70✔
528
  }
529

530
  if (taosCheckPthreadValid(pMgmt->crashReportThread)) {
×
531
    (void)taosThreadJoin(pMgmt->crashReportThread, NULL);
×
532
    taosThreadClear(&pMgmt->crashReportThread);
×
533
  }
534
#endif
535
}
536

537
static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
8,286✔
538
  SDnodeMgmt *pMgmt = pInfo->ahandle;
8,286✔
539
  int32_t     code = -1;
8,286✔
540
  STraceId   *trace = &pMsg->info.traceId;
8,286✔
541
  dGTrace("msg:%p, will be processed in dnode queue, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
8,286!
542

543
  switch (pMsg->msgType) {
8,286!
544
    case TDMT_DND_CONFIG_DNODE:
3✔
545
      code = dmProcessConfigReq(pMgmt, pMsg);
3✔
546
      break;
3✔
547
    case TDMT_MND_AUTH_RSP:
×
548
      code = dmProcessAuthRsp(pMgmt, pMsg);
×
549
      break;
×
550
    case TDMT_MND_GRANT_RSP:
×
551
      code = dmProcessGrantRsp(pMgmt, pMsg);
×
552
      break;
×
553
    case TDMT_DND_CREATE_MNODE:
4✔
554
      code = (*pMgmt->processCreateNodeFp)(MNODE, pMsg);
4✔
555
      break;
4✔
556
    case TDMT_DND_DROP_MNODE:
×
557
      code = (*pMgmt->processDropNodeFp)(MNODE, pMsg);
×
558
      break;
×
559
    case TDMT_DND_CREATE_QNODE:
10✔
560
      code = (*pMgmt->processCreateNodeFp)(QNODE, pMsg);
10✔
561
      break;
10✔
562
    case TDMT_DND_DROP_QNODE:
7✔
563
      code = (*pMgmt->processDropNodeFp)(QNODE, pMsg);
7✔
564
      break;
7✔
565
    case TDMT_DND_CREATE_SNODE:
1✔
566
      code = (*pMgmt->processCreateNodeFp)(SNODE, pMsg);
1✔
567
      break;
1✔
568
    case TDMT_DND_DROP_SNODE:
×
569
      code = (*pMgmt->processDropNodeFp)(SNODE, pMsg);
×
570
      break;
×
571
    case TDMT_DND_ALTER_MNODE_TYPE:
38✔
572
      code = (*pMgmt->processAlterNodeTypeFp)(MNODE, pMsg);
38✔
573
      break;
38✔
574
    case TDMT_DND_SERVER_STATUS:
1✔
575
      code = dmProcessServerRunStatus(pMgmt, pMsg);
1✔
576
      break;
1✔
577
    case TDMT_DND_SYSTABLE_RETRIEVE:
2✔
578
      code = dmProcessRetrieve(pMgmt, pMsg);
2✔
579
      break;
2✔
580
    case TDMT_MND_GRANT:
69✔
581
      code = dmProcessGrantReq(&pMgmt->pData->clusterId, pMsg);
69✔
582
      break;
69✔
583
    case TDMT_MND_GRANT_NOTIFY:
8,151✔
584
      code = dmProcessGrantNotify(NULL, pMsg);
8,151✔
585
      break;
8,151✔
586
    case TDMT_DND_CREATE_ENCRYPT_KEY:
×
587
      code = dmProcessCreateEncryptKeyReq(pMgmt, pMsg);
×
588
      break;
×
589
    default:
×
590
      code = TSDB_CODE_MSG_NOT_PROCESSED;
×
591
      dGError("msg:%p, not processed in mgmt queue, reason:%s", pMsg, tstrerror(code));
×
592
      break;
×
593
  }
594

595
  if (IsReq(pMsg)) {
8,286!
596
    if (code != 0 && terrno != 0) code = terrno;
8,286✔
597
    SRpcMsg rsp = {
8,286✔
598
        .code = code,
599
        .pCont = pMsg->info.rsp,
8,286✔
600
        .contLen = pMsg->info.rspLen,
8,286✔
601
        .info = pMsg->info,
602
    };
603

604
    code = rpcSendResponse(&rsp);
8,286✔
605
    if (code != 0) {
8,286!
606
      dError("failed to send response since %s", tstrerror(code));
×
607
    }
608
  }
609

610
  dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
8,286✔
611
  rpcFreeCont(pMsg->pCont);
8,286✔
612
  taosFreeQitem(pMsg);
8,286✔
613
}
8,286✔
614

615
int32_t dmStartWorker(SDnodeMgmt *pMgmt) {
133✔
616
  int32_t          code = 0;
133✔
617
  SSingleWorkerCfg cfg = {
133✔
618
      .min = 1,
619
      .max = 1,
620
      .name = "dnode-mgmt",
621
      .fp = (FItem)dmProcessMgmtQueue,
622
      .param = pMgmt,
623
  };
624
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg)) != 0) {
133!
625
    dError("failed to start dnode-mgmt worker since %s", tstrerror(code));
×
626
    return code;
×
627
  }
628

629
  dDebug("dnode workers are initialized");
133✔
630
  return 0;
133✔
631
}
632

633
void dmStopWorker(SDnodeMgmt *pMgmt) {
70✔
634
  tSingleWorkerCleanup(&pMgmt->mgmtWorker);
70✔
635
  dDebug("dnode workers are closed");
70✔
636
}
70✔
637

638
int32_t dmPutNodeMsgToMgmtQueue(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
8,286✔
639
  SSingleWorker *pWorker = &pMgmt->mgmtWorker;
8,286✔
640
  dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
8,286✔
641
  return taosWriteQitem(pWorker->queue, pMsg);
8,286✔
642
}
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