• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

taosdata / TDengine / #3610

12 Feb 2025 09:54AM UTC coverage: 54.713% (-8.4%) from 63.066%
#3610

push

travis-ci

web-flow
Merge pull request #29745 from taosdata/fix/TD33664-3.0

fix: --version show information check for 3.0

120957 of 286549 branches covered (42.21%)

Branch coverage included in aggregate %.

190849 of 283342 relevant lines covered (67.36%)

4969786.97 hits per line

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

53.35
/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) {
1,288✔
22
  SDnodeMgmt *pMgmt = param;
1,288✔
23
  int64_t     lastTime = taosGetTimestampMs();
1,288✔
24
  setThreadName("dnode-status");
1,288✔
25

26
  int32_t upTimeCount = 0;
1,288✔
27
  int64_t upTime = 0;
1,288✔
28

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

33
    int64_t curTime = taosGetTimestampMs();
330,676✔
34
    if (curTime < lastTime) lastTime = curTime;
330,676!
35
    float interval = (curTime - lastTime) / 1000.0f;
330,676✔
36
    if (interval >= tsStatusInterval) {
330,676✔
37
      dmSendStatusReq(pMgmt);
66,303✔
38
      lastTime = curTime;
66,303✔
39

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

47
  return NULL;
1,288✔
48
}
49

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

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

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

74
  int32_t upTimeCount = 0;
1,288✔
75
  int64_t upTime = 0;
1,288✔
76

77
  while (1) {
344,772✔
78
    taosMsleep(200);
346,060✔
79
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
346,060!
80

81
    int64_t curTime = taosGetTimestampMs();
344,772✔
82
    if (curTime < lastTime) lastTime = curTime;
344,772!
83
    float interval = (curTime - lastTime) / 1000.0f;
344,772✔
84
    if (interval >= tsStatusInterval) {
344,772✔
85
      dmUpdateStatusInfo(pMgmt);
68,584✔
86
      lastTime = curTime;
68,584✔
87

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

95
  return NULL;
1,288✔
96
}
97

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

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

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

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

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

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

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

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

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

197
  return NULL;
1,288✔
198
}
199

200
static void *dmMonitorThreadFp(void *param) {
1,288✔
201
  SDnodeMgmt *pMgmt = param;
1,288✔
202
  int64_t     lastTime = taosGetTimestampMs();
1,288✔
203
  int64_t     lastTimeForBasic = taosGetTimestampMs();
1,288✔
204
  setThreadName("dnode-monitor");
1,288✔
205

206
  static int32_t TRIM_FREQ = 20;
207
  int32_t        trimCount = 0;
1,288✔
208

209
  while (1) {
345,885✔
210
    taosMsleep(200);
347,173✔
211
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
347,173!
212

213
    int64_t curTime = taosGetTimestampMs();
345,885✔
214

215
    if (curTime < lastTime) lastTime = curTime;
345,885!
216
    float interval = (curTime - lastTime) / 1000.0f;
345,885✔
217
    if (interval >= tsMonitorInterval) {
345,885✔
218
      (*pMgmt->sendMonitorReportFp)();
1,721✔
219
      (*pMgmt->monitorCleanExpiredSamplesFp)();
1,721✔
220
      lastTime = curTime;
1,721✔
221

222
      trimCount = (trimCount + 1) % TRIM_FREQ;
1,721✔
223
      if (trimCount == 0) {
1,721!
224
        taosMemoryTrim(0, NULL);
×
225
      }
226
    }
227
    if (atomic_val_compare_exchange_8(&tsNeedTrim, 1, 0)) {
345,885✔
228
      taosMemoryTrim(0, NULL);
12,945!
229
    }
230
  }
231

232
  return NULL;
1,288✔
233
}
234

235
static void *dmAuditThreadFp(void *param) {
1,288✔
236
  SDnodeMgmt *pMgmt = param;
1,288✔
237
  int64_t     lastTime = taosGetTimestampMs();
1,288✔
238
  setThreadName("dnode-audit");
1,288✔
239

240
  while (1) {
692,158✔
241
    taosMsleep(100);
693,446✔
242
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
693,446!
243

244
    int64_t curTime = taosGetTimestampMs();
692,158✔
245
    if (curTime < lastTime) lastTime = curTime;
692,158!
246
    float interval = curTime - lastTime;
692,158✔
247
    if (interval >= tsAuditInterval) {
692,158✔
248
      (*pMgmt->sendAuditRecordsFp)();
13,227✔
249
      lastTime = curTime;
13,227✔
250
    }
251
  }
252

253
  return NULL;
1,288✔
254
}
255

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

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

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

301
          taosMsleep(sleepTime);
×
302
          loopTimes = 0;
×
303
          continue;
×
304
        }
305
      } else {
306
        dInfo("succeed to send crash report");
×
307
        truncateFile = true;
×
308
      }
309
    } else {
310
      dDebug("no crash info");
×
311
    }
312

313
    taosMemoryFree(pMsg);
×
314

315
    if (pMsg && msgLen > 0) {
×
316
      pMsg = NULL;
×
317
      continue;
×
318
    }
319

320
    if (pFile) {
×
321
      taosReleaseCrashLogFile(pFile, truncateFile);
×
322
      pFile = NULL;
×
323
      truncateFile = false;
×
324
    }
325

326
    taosMsleep(sleepTime);
×
327
    loopTimes = 0;
×
328
  }
329
  taosTelemetryDestroy(&mgt);
×
330

331
  return NULL;
×
332
}
333

334
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
1,288✔
335
  int32_t      code = 0;
1,288✔
336
  TdThreadAttr thAttr;
337
  (void)taosThreadAttrInit(&thAttr);
1,288✔
338
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1,288✔
339
  if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) {
1,288!
340
    code = TAOS_SYSTEM_ERROR(errno);
×
341
    dError("failed to create status thread since %s", tstrerror(code));
×
342
    return code;
×
343
  }
344

345
  (void)taosThreadAttrDestroy(&thAttr);
1,288✔
346
  tmsgReportStartup("dnode-status", "initialized");
1,288✔
347
  return 0;
1,288✔
348
}
349

350
int32_t dmStartConfigThread(SDnodeMgmt *pMgmt) {
1,288✔
351
  int32_t      code = 0;
1,288✔
352
  TdThreadAttr thAttr;
353
  (void)taosThreadAttrInit(&thAttr);
1,288✔
354
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1,288✔
355
  if (taosThreadCreate(&pMgmt->configThread, &thAttr, dmConfigThreadFp, pMgmt) != 0) {
1,288!
356
    code = TAOS_SYSTEM_ERROR(errno);
×
357
    dError("failed to create config thread since %s", tstrerror(code));
×
358
    return code;
×
359
  }
360

361
  (void)taosThreadAttrDestroy(&thAttr);
1,288✔
362
  tmsgReportStartup("config-status", "initialized");
1,288✔
363
  return 0;
1,288✔
364
}
365

366
int32_t dmStartStatusInfoThread(SDnodeMgmt *pMgmt) {
1,288✔
367
  int32_t      code = 0;
1,288✔
368
  TdThreadAttr thAttr;
369
  (void)taosThreadAttrInit(&thAttr);
1,288✔
370
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1,288✔
371
  if (taosThreadCreate(&pMgmt->statusInfoThread, &thAttr, dmStatusInfoThreadFp, pMgmt) != 0) {
1,288!
372
    code = TAOS_SYSTEM_ERROR(errno);
×
373
    dError("failed to create status Info thread since %s", tstrerror(code));
×
374
    return code;
×
375
  }
376

377
  (void)taosThreadAttrDestroy(&thAttr);
1,288✔
378
  tmsgReportStartup("dnode-status-info", "initialized");
1,288✔
379
  return 0;
1,288✔
380
}
381

382
void dmStopStatusThread(SDnodeMgmt *pMgmt) {
1,288✔
383
  if (taosCheckPthreadValid(pMgmt->statusThread)) {
1,288!
384
    (void)taosThreadJoin(pMgmt->statusThread, NULL);
1,288✔
385
    taosThreadClear(&pMgmt->statusThread);
1,288✔
386
  }
387
}
1,288✔
388

389
void dmStopConfigThread(SDnodeMgmt *pMgmt) {
1,288✔
390
  if (taosCheckPthreadValid(pMgmt->configThread)) {
1,288!
391
    (void)taosThreadJoin(pMgmt->configThread, NULL);
1,288✔
392
    taosThreadClear(&pMgmt->configThread);
1,288✔
393
  }
394
}
1,288✔
395

396
void dmStopStatusInfoThread(SDnodeMgmt *pMgmt) {
1,288✔
397
  if (taosCheckPthreadValid(pMgmt->statusInfoThread)) {
1,288!
398
    (void)taosThreadJoin(pMgmt->statusInfoThread, NULL);
1,288✔
399
    taosThreadClear(&pMgmt->statusInfoThread);
1,288✔
400
  }
401
}
1,288✔
402

403
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) {
1,288✔
404
  int32_t      code = 0;
1,288✔
405
  TdThreadAttr thAttr;
406
  (void)taosThreadAttrInit(&thAttr);
1,288✔
407
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1,288✔
408
  if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) {
1,288!
409
    code = TAOS_SYSTEM_ERROR(errno);
×
410
    dError("failed to create notify thread since %s", tstrerror(code));
×
411
    return code;
×
412
  }
413

414
  (void)taosThreadAttrDestroy(&thAttr);
1,288✔
415
  tmsgReportStartup("dnode-notify", "initialized");
1,288✔
416
  return 0;
1,288✔
417
}
418

419
void dmStopNotifyThread(SDnodeMgmt *pMgmt) {
1,288✔
420
  if (taosCheckPthreadValid(pMgmt->notifyThread)) {
1,288!
421
    if (tsem_post(&dmNotifyHdl.sem) != 0) {
1,288!
422
      dError("failed to post notify sem");
×
423
    }
424

425
    (void)taosThreadJoin(pMgmt->notifyThread, NULL);
1,288✔
426
    taosThreadClear(&pMgmt->notifyThread);
1,288✔
427
  }
428
  if (tsem_destroy(&dmNotifyHdl.sem) != 0) {
1,288!
429
    dError("failed to destroy notify sem");
×
430
  }
431
}
1,288✔
432

433
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
1,288✔
434
  int32_t      code = 0;
1,288✔
435
  TdThreadAttr thAttr;
436
  (void)taosThreadAttrInit(&thAttr);
1,288✔
437
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1,288✔
438
  if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) {
1,288!
439
    code = TAOS_SYSTEM_ERROR(errno);
×
440
    dError("failed to create monitor thread since %s", tstrerror(code));
×
441
    return code;
×
442
  }
443

444
  (void)taosThreadAttrDestroy(&thAttr);
1,288✔
445
  tmsgReportStartup("dnode-monitor", "initialized");
1,288✔
446
  return 0;
1,288✔
447
}
448

449
int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
1,288✔
450
  int32_t      code = 0;
1,288✔
451
  TdThreadAttr thAttr;
452
  (void)taosThreadAttrInit(&thAttr);
1,288✔
453
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1,288✔
454
  if (taosThreadCreate(&pMgmt->auditThread, &thAttr, dmAuditThreadFp, pMgmt) != 0) {
1,288!
455
    code = TAOS_SYSTEM_ERROR(errno);
×
456
    dError("failed to create audit thread since %s", tstrerror(code));
×
457
    return code;
×
458
  }
459

460
  (void)taosThreadAttrDestroy(&thAttr);
1,288✔
461
  tmsgReportStartup("dnode-audit", "initialized");
1,288✔
462
  return 0;
1,288✔
463
}
464

465
void dmStopMonitorThread(SDnodeMgmt *pMgmt) {
1,288✔
466
  if (taosCheckPthreadValid(pMgmt->monitorThread)) {
1,288!
467
    (void)taosThreadJoin(pMgmt->monitorThread, NULL);
1,288✔
468
    taosThreadClear(&pMgmt->monitorThread);
1,288✔
469
  }
470
}
1,288✔
471

472
void dmStopAuditThread(SDnodeMgmt *pMgmt) {
1,288✔
473
  if (taosCheckPthreadValid(pMgmt->auditThread)) {
1,288!
474
    (void)taosThreadJoin(pMgmt->auditThread, NULL);
1,288✔
475
    taosThreadClear(&pMgmt->auditThread);
1,288✔
476
  }
477
}
1,288✔
478

479
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
1,288✔
480
  int32_t code = 0;
1,288✔
481
  if (!tsEnableCrashReport) {
1,288!
482
    return 0;
1,288✔
483
  }
484

485
  TdThreadAttr thAttr;
486
  (void)taosThreadAttrInit(&thAttr);
×
487
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
×
488
  if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) {
×
489
    code = TAOS_SYSTEM_ERROR(errno);
×
490
    dError("failed to create crashReport thread since %s", tstrerror(code));
×
491
    return code;
×
492
  }
493

494
  (void)taosThreadAttrDestroy(&thAttr);
×
495
  tmsgReportStartup("dnode-crashReport", "initialized");
×
496
  return 0;
×
497
}
498

499
void dmStopCrashReportThread(SDnodeMgmt *pMgmt) {
1,288✔
500
  if (!tsEnableCrashReport) {
1,288!
501
    return;
1,288✔
502
  }
503

504
  if (taosCheckPthreadValid(pMgmt->crashReportThread)) {
×
505
    (void)taosThreadJoin(pMgmt->crashReportThread, NULL);
×
506
    taosThreadClear(&pMgmt->crashReportThread);
×
507
  }
508
}
509

510
static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
120,733✔
511
  SDnodeMgmt *pMgmt = pInfo->ahandle;
120,733✔
512
  int32_t     code = -1;
120,733✔
513
  STraceId   *trace = &pMsg->info.traceId;
120,733✔
514
  dGTrace("msg:%p, will be processed in dnode queue, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
120,733!
515

516
  switch (pMsg->msgType) {
120,733!
517
    case TDMT_DND_CONFIG_DNODE:
471✔
518
      code = dmProcessConfigReq(pMgmt, pMsg);
471✔
519
      break;
471✔
520
    case TDMT_MND_AUTH_RSP:
×
521
      code = dmProcessAuthRsp(pMgmt, pMsg);
×
522
      break;
×
523
    case TDMT_MND_GRANT_RSP:
×
524
      code = dmProcessGrantRsp(pMgmt, pMsg);
×
525
      break;
×
526
    case TDMT_DND_CREATE_MNODE:
83✔
527
      code = (*pMgmt->processCreateNodeFp)(MNODE, pMsg);
83✔
528
      break;
83✔
529
    case TDMT_DND_DROP_MNODE:
1✔
530
      code = (*pMgmt->processDropNodeFp)(MNODE, pMsg);
1✔
531
      break;
1✔
532
    case TDMT_DND_CREATE_QNODE:
421✔
533
      code = (*pMgmt->processCreateNodeFp)(QNODE, pMsg);
421✔
534
      break;
421✔
535
    case TDMT_DND_DROP_QNODE:
4✔
536
      code = (*pMgmt->processDropNodeFp)(QNODE, pMsg);
4✔
537
      break;
4✔
538
    case TDMT_DND_CREATE_SNODE:
2✔
539
      code = (*pMgmt->processCreateNodeFp)(SNODE, pMsg);
2✔
540
      break;
2✔
541
    case TDMT_DND_DROP_SNODE:
×
542
      code = (*pMgmt->processDropNodeFp)(SNODE, pMsg);
×
543
      break;
×
544
    case TDMT_DND_ALTER_MNODE_TYPE:
998✔
545
      code = (*pMgmt->processAlterNodeTypeFp)(MNODE, pMsg);
998✔
546
      break;
998✔
547
    case TDMT_DND_SERVER_STATUS:
3✔
548
      code = dmProcessServerRunStatus(pMgmt, pMsg);
3✔
549
      break;
3✔
550
    case TDMT_DND_SYSTABLE_RETRIEVE:
484✔
551
      code = dmProcessRetrieve(pMgmt, pMsg);
484✔
552
      break;
484✔
553
    case TDMT_MND_GRANT:
1,472✔
554
      code = dmProcessGrantReq(&pMgmt->pData->clusterId, pMsg);
1,472✔
555
      break;
1,472✔
556
    case TDMT_MND_GRANT_NOTIFY:
116,794✔
557
      code = dmProcessGrantNotify(NULL, pMsg);
116,794✔
558
      break;
116,794✔
559
    case TDMT_DND_CREATE_ENCRYPT_KEY:
×
560
      code = dmProcessCreateEncryptKeyReq(pMgmt, pMsg);
×
561
      break;
×
562
    default:
×
563
      code = TSDB_CODE_MSG_NOT_PROCESSED;
×
564
      dGError("msg:%p, not processed in mgmt queue, reason:%s", pMsg, tstrerror(code));
×
565
      break;
×
566
  }
567

568
  if (IsReq(pMsg)) {
120,733!
569
    if (code != 0 && terrno != 0) code = terrno;
120,733!
570
    SRpcMsg rsp = {
120,733✔
571
        .code = code,
572
        .pCont = pMsg->info.rsp,
120,733✔
573
        .contLen = pMsg->info.rspLen,
120,733✔
574
        .info = pMsg->info,
575
    };
576

577
    code = rpcSendResponse(&rsp);
120,733✔
578
    if (code != 0) {
120,733!
579
      dError("failed to send response since %s", tstrerror(code));
×
580
    }
581
  }
582

583
  dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
120,733✔
584
  rpcFreeCont(pMsg->pCont);
120,733✔
585
  taosFreeQitem(pMsg);
120,733✔
586
}
120,733✔
587

588
int32_t dmStartWorker(SDnodeMgmt *pMgmt) {
1,288✔
589
  int32_t          code = 0;
1,288✔
590
  SSingleWorkerCfg cfg = {
1,288✔
591
      .min = 1,
592
      .max = 1,
593
      .name = "dnode-mgmt",
594
      .fp = (FItem)dmProcessMgmtQueue,
595
      .param = pMgmt,
596
  };
597
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg)) != 0) {
1,288!
598
    dError("failed to start dnode-mgmt worker since %s", tstrerror(code));
×
599
    return code;
×
600
  }
601

602
  dDebug("dnode workers are initialized");
1,288✔
603
  return 0;
1,288✔
604
}
605

606
void dmStopWorker(SDnodeMgmt *pMgmt) {
1,288✔
607
  tSingleWorkerCleanup(&pMgmt->mgmtWorker);
1,288✔
608
  dDebug("dnode workers are closed");
1,288✔
609
}
1,288✔
610

611
int32_t dmPutNodeMsgToMgmtQueue(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
120,733✔
612
  SSingleWorker *pWorker = &pMgmt->mgmtWorker;
120,733✔
613
  dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
120,733✔
614
  return taosWriteQitem(pWorker->queue, pMsg);
120,733✔
615
}
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