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

taosdata / TDengine / #3558

17 Dec 2024 06:05AM UTC coverage: 59.778% (+1.6%) from 58.204%
#3558

push

travis-ci

web-flow
Merge pull request #29179 from taosdata/merge/mainto3.0

merge: form main to 3.0 branch

132787 of 287595 branches covered (46.17%)

Branch coverage included in aggregate %.

104 of 191 new or added lines in 5 files covered. (54.45%)

6085 existing lines in 168 files now uncovered.

209348 of 284746 relevant lines covered (73.52%)

8164844.48 hits per line

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

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

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

29
  while (1) {
418,239✔
30
    taosMsleep(200);
420,118✔
31
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
420,118!
32

33
    int64_t curTime = taosGetTimestampMs();
418,239✔
34
    if (curTime < lastTime) lastTime = curTime;
418,239!
35
    float interval = (curTime - lastTime) / 1000.0f;
418,239✔
36
    if (interval >= tsStatusInterval) {
418,239✔
37
      dmSendStatusReq(pMgmt);
83,281✔
38
      lastTime = curTime;
83,281✔
39

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

47
  return NULL;
1,879✔
48
}
49

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

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

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

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

77
  while (1) {
428,782✔
78
    taosMsleep(200);
430,661✔
79
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
430,661!
80

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

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

95
  return NULL;
1,879✔
96
}
97

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

105
  if (tsem_init(&dmNotifyHdl.sem, 0, 0) != 0) {
1,879!
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,879✔
113
  uint64_t nTotalNotify = 0;
1,879✔
114
  int32_t  head, tail = 0;
1,879✔
115

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

126
    int64_t remainTimeSeries = grantRemain(TSDB_GRANT_TIMESERIES);
1,887✔
127
    if (remainTimeSeries == INT64_MAX || remainTimeSeries <= 0) {
1,887!
128
      goto _skip;
1,887✔
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,887✔
190
    if (1 == atomic_val_compare_exchange_8(&dmNotifyHdl.state, 1, 0)) {
1,887!
191
      wait = true;
1,887✔
192
      continue;
1,887✔
193
    }
UNCOV
194
    wait = false;
×
195
  }
196

197
  return NULL;
1,879✔
198
}
199

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

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

209
  while (1) {
428,424✔
210
    taosMsleep(200);
430,303✔
211
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
430,303!
212

213
    int64_t curTime = taosGetTimestampMs();
428,424✔
214

215
    if (curTime < lastTime) lastTime = curTime;
428,424!
216
    float interval = (curTime - lastTime) / 1000.0f;
428,424✔
217
    if (interval >= tsMonitorInterval) {
428,424✔
218
      (*pMgmt->sendMonitorReportFp)();
2,245✔
219
      (*pMgmt->monitorCleanExpiredSamplesFp)();
2,245✔
220
      lastTime = curTime;
2,245✔
221

222
      trimCount = (trimCount + 1) % TRIM_FREQ;
2,245✔
223
      if (trimCount == 0) {
2,245✔
224
        taosMemoryTrim(0, NULL);
19!
225
      }
226
    }
227
    if (atomic_val_compare_exchange_8(&tsNeedTrim, 1, 0)) {
428,424✔
228
      taosMemoryTrim(0, NULL);
15,986!
229
    }
230
  }
231

232
  return NULL;
1,879✔
233
}
234

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

240
  while (1) {
858,096✔
241
    taosMsleep(100);
859,975✔
242
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
859,975!
243

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

253
  return NULL;
1,879✔
254
}
255

256
static void *dmCrashReportThreadFp(void *param) {
×
NEW
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;
×
NEW
269
  int32_t   loopTimes = reportPeriodNum;
×
270

NEW
271
  STelemAddrMgmt mgt = {0};
×
NEW
272
  code = taosTelemetryMgtInit(&mgt, tsTelemServer);
×
NEW
273
  if (code != 0) {
×
NEW
274
    dError("failed to init telemetry since %s", tstrerror(code));
×
NEW
275
    return NULL;
×
276
  }
277

278
  while (1) {
279
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
×
280
    if (loopTimes++ < reportPeriodNum) {
×
281
      taosMsleep(sleepTime);
×
282
      continue;
×
283
    }
284

285
    taosReadCrashInfo(filepath, &pMsg, &msgLen, &pFile);
×
286
    if (pMsg && msgLen > 0) {
×
NEW
287
      if (taosSendTelemReport(&mgt, tsSvrCrashReportUri, tsTelemPort, pMsg, msgLen, HTTP_FLAT) != 0) {
×
288
        dError("failed to send crash report");
×
289
        if (pFile) {
×
290
          taosReleaseCrashLogFile(pFile, false);
×
291
          pFile = NULL;
×
292

293
          taosMsleep(sleepTime);
×
294
          loopTimes = 0;
×
295
          continue;
×
296
        }
297
      } else {
298
        dInfo("succeed to send crash report");
×
299
        truncateFile = true;
×
300
      }
301
    } else {
302
      dDebug("no crash info");
×
303
    }
304

305
    taosMemoryFree(pMsg);
×
306

307
    if (pMsg && msgLen > 0) {
×
308
      pMsg = NULL;
×
309
      continue;
×
310
    }
311

312
    if (pFile) {
×
313
      taosReleaseCrashLogFile(pFile, truncateFile);
×
314
      pFile = NULL;
×
315
      truncateFile = false;
×
316
    }
317

318
    taosMsleep(sleepTime);
×
319
    loopTimes = 0;
×
320
  }
NEW
321
  taosTelemetryDestroy(&mgt);
×
322

323
  return NULL;
×
324
}
325

326
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
1,879✔
327
  int32_t      code = 0;
1,879✔
328
  TdThreadAttr thAttr;
329
  (void)taosThreadAttrInit(&thAttr);
1,879✔
330
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1,879✔
331
  if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) {
1,879!
332
    code = TAOS_SYSTEM_ERROR(errno);
×
333
    dError("failed to create status thread since %s", tstrerror(code));
×
334
    return code;
×
335
  }
336

337
  (void)taosThreadAttrDestroy(&thAttr);
1,879✔
338
  tmsgReportStartup("dnode-status", "initialized");
1,879✔
339
  return 0;
1,879✔
340
}
341

342
int32_t dmStartConfigThread(SDnodeMgmt *pMgmt) {
1,879✔
343
  int32_t      code = 0;
1,879✔
344
  TdThreadAttr thAttr;
345
  (void)taosThreadAttrInit(&thAttr);
1,879✔
346
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_DETACHED);
1,879✔
347
  if (taosThreadCreate(&pMgmt->configThread, &thAttr, dmConfigThreadFp, pMgmt) != 0) {
1,879!
348
    code = TAOS_SYSTEM_ERROR(errno);
×
349
    dError("failed to create config thread since %s", tstrerror(code));
×
350
    return code;
×
351
  }
352

353
  (void)taosThreadAttrDestroy(&thAttr);
1,879✔
354
  tmsgReportStartup("config-status", "initialized");
1,879✔
355
  return 0;
1,879✔
356
}
357

358
int32_t dmStartStatusInfoThread(SDnodeMgmt *pMgmt) {
1,879✔
359
  int32_t      code = 0;
1,879✔
360
  TdThreadAttr thAttr;
361
  (void)taosThreadAttrInit(&thAttr);
1,879✔
362
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1,879✔
363
  if (taosThreadCreate(&pMgmt->statusInfoThread, &thAttr, dmStatusInfoThreadFp, pMgmt) != 0) {
1,879!
364
    code = TAOS_SYSTEM_ERROR(errno);
×
365
    dError("failed to create status Info thread since %s", tstrerror(code));
×
366
    return code;
×
367
  }
368

369
  (void)taosThreadAttrDestroy(&thAttr);
1,879✔
370
  tmsgReportStartup("dnode-status-info", "initialized");
1,879✔
371
  return 0;
1,879✔
372
}
373

374
void dmStopStatusThread(SDnodeMgmt *pMgmt) {
1,879✔
375
  if (taosCheckPthreadValid(pMgmt->statusThread)) {
1,879!
376
    (void)taosThreadJoin(pMgmt->statusThread, NULL);
1,879✔
377
    taosThreadClear(&pMgmt->statusThread);
1,879✔
378
  }
379
}
1,879✔
380

381
void dmStopStatusInfoThread(SDnodeMgmt *pMgmt) {
1,879✔
382
  if (taosCheckPthreadValid(pMgmt->statusInfoThread)) {
1,879!
383
    (void)taosThreadJoin(pMgmt->statusInfoThread, NULL);
1,879✔
384
    taosThreadClear(&pMgmt->statusInfoThread);
1,879✔
385
  }
386
}
1,879✔
387

388
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) {
1,879✔
389
  int32_t      code = 0;
1,879✔
390
  TdThreadAttr thAttr;
391
  (void)taosThreadAttrInit(&thAttr);
1,879✔
392
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1,879✔
393
  if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) {
1,879!
394
    code = TAOS_SYSTEM_ERROR(errno);
×
395
    dError("failed to create notify thread since %s", tstrerror(code));
×
396
    return code;
×
397
  }
398

399
  (void)taosThreadAttrDestroy(&thAttr);
1,879✔
400
  tmsgReportStartup("dnode-notify", "initialized");
1,879✔
401
  return 0;
1,879✔
402
}
403

404
void dmStopNotifyThread(SDnodeMgmt *pMgmt) {
1,879✔
405
  if (taosCheckPthreadValid(pMgmt->notifyThread)) {
1,879!
406
    if (tsem_post(&dmNotifyHdl.sem) != 0) {
1,879!
407
      dError("failed to post notify sem");
×
408
    }
409

410
    (void)taosThreadJoin(pMgmt->notifyThread, NULL);
1,879✔
411
    taosThreadClear(&pMgmt->notifyThread);
1,879✔
412
  }
413
  if (tsem_destroy(&dmNotifyHdl.sem) != 0) {
1,879!
414
    dError("failed to destroy notify sem");
×
415
  }
416
}
1,879✔
417

418
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
1,879✔
419
  int32_t      code = 0;
1,879✔
420
  TdThreadAttr thAttr;
421
  (void)taosThreadAttrInit(&thAttr);
1,879✔
422
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1,879✔
423
  if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) {
1,879!
424
    code = TAOS_SYSTEM_ERROR(errno);
×
425
    dError("failed to create monitor thread since %s", tstrerror(code));
×
426
    return code;
×
427
  }
428

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

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

445
  (void)taosThreadAttrDestroy(&thAttr);
1,879✔
446
  tmsgReportStartup("dnode-audit", "initialized");
1,879✔
447
  return 0;
1,879✔
448
}
449

450
void dmStopMonitorThread(SDnodeMgmt *pMgmt) {
1,879✔
451
  if (taosCheckPthreadValid(pMgmt->monitorThread)) {
1,879!
452
    (void)taosThreadJoin(pMgmt->monitorThread, NULL);
1,879✔
453
    taosThreadClear(&pMgmt->monitorThread);
1,879✔
454
  }
455
}
1,879✔
456

457
void dmStopAuditThread(SDnodeMgmt *pMgmt) {
1,879✔
458
  if (taosCheckPthreadValid(pMgmt->auditThread)) {
1,879!
459
    (void)taosThreadJoin(pMgmt->auditThread, NULL);
1,879✔
460
    taosThreadClear(&pMgmt->auditThread);
1,879✔
461
  }
462
}
1,879✔
463

464
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
1,879✔
465
  int32_t code = 0;
1,879✔
466
  if (!tsEnableCrashReport) {
1,879!
467
    return 0;
1,879✔
468
  }
469

470
  TdThreadAttr thAttr;
471
  (void)taosThreadAttrInit(&thAttr);
×
472
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
×
473
  if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) {
×
474
    code = TAOS_SYSTEM_ERROR(errno);
×
475
    dError("failed to create crashReport thread since %s", tstrerror(code));
×
476
    return code;
×
477
  }
478

479
  (void)taosThreadAttrDestroy(&thAttr);
×
480
  tmsgReportStartup("dnode-crashReport", "initialized");
×
481
  return 0;
×
482
}
483

484
void dmStopCrashReportThread(SDnodeMgmt *pMgmt) {
1,879✔
485
  if (!tsEnableCrashReport) {
1,879!
486
    return;
1,879✔
487
  }
488

489
  if (taosCheckPthreadValid(pMgmt->crashReportThread)) {
×
490
    (void)taosThreadJoin(pMgmt->crashReportThread, NULL);
×
491
    taosThreadClear(&pMgmt->crashReportThread);
×
492
  }
493
}
494

495
static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
189,805✔
496
  SDnodeMgmt *pMgmt = pInfo->ahandle;
189,805✔
497
  int32_t     code = -1;
189,805✔
498
  STraceId   *trace = &pMsg->info.traceId;
189,805✔
499
  dGTrace("msg:%p, will be processed in dnode queue, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
189,805!
500

501
  switch (pMsg->msgType) {
189,805!
502
    case TDMT_DND_CONFIG_DNODE:
530✔
503
      code = dmProcessConfigReq(pMgmt, pMsg);
530✔
504
      break;
530✔
505
    case TDMT_MND_AUTH_RSP:
×
506
      code = dmProcessAuthRsp(pMgmt, pMsg);
×
507
      break;
×
508
    case TDMT_MND_GRANT_RSP:
×
509
      code = dmProcessGrantRsp(pMgmt, pMsg);
×
510
      break;
×
511
    case TDMT_DND_CREATE_MNODE:
145✔
512
      code = (*pMgmt->processCreateNodeFp)(MNODE, pMsg);
145✔
513
      break;
145✔
514
    case TDMT_DND_DROP_MNODE:
6✔
515
      code = (*pMgmt->processDropNodeFp)(MNODE, pMsg);
6✔
516
      break;
6✔
517
    case TDMT_DND_CREATE_QNODE:
438✔
518
      code = (*pMgmt->processCreateNodeFp)(QNODE, pMsg);
438✔
519
      break;
438✔
520
    case TDMT_DND_DROP_QNODE:
6✔
521
      code = (*pMgmt->processDropNodeFp)(QNODE, pMsg);
6✔
522
      break;
6✔
523
    case TDMT_DND_CREATE_SNODE:
18✔
524
      code = (*pMgmt->processCreateNodeFp)(SNODE, pMsg);
18✔
525
      break;
18✔
526
    case TDMT_DND_DROP_SNODE:
4✔
527
      code = (*pMgmt->processDropNodeFp)(SNODE, pMsg);
4✔
528
      break;
4✔
529
    case TDMT_DND_ALTER_MNODE_TYPE:
646✔
530
      code = (*pMgmt->processAlterNodeTypeFp)(MNODE, pMsg);
646✔
531
      break;
646✔
532
    case TDMT_DND_SERVER_STATUS:
3✔
533
      code = dmProcessServerRunStatus(pMgmt, pMsg);
3✔
534
      break;
3✔
535
    case TDMT_DND_SYSTABLE_RETRIEVE:
4,814✔
536
      code = dmProcessRetrieve(pMgmt, pMsg);
4,814✔
537
      break;
4,814✔
538
    case TDMT_MND_GRANT:
1,929✔
539
      code = dmProcessGrantReq(&pMgmt->pData->clusterId, pMsg);
1,929✔
540
      break;
1,929✔
541
    case TDMT_MND_GRANT_NOTIFY:
181,266✔
542
      code = dmProcessGrantNotify(NULL, pMsg);
181,266✔
543
      break;
181,266✔
544
    case TDMT_DND_CREATE_ENCRYPT_KEY:
×
545
      code = dmProcessCreateEncryptKeyReq(pMgmt, pMsg);
×
546
      break;
×
547
    default:
×
548
      code = TSDB_CODE_MSG_NOT_PROCESSED;
×
549
      dGError("msg:%p, not processed in mgmt queue, reason:%s", pMsg, tstrerror(code));
×
550
      break;
×
551
  }
552

553
  if (IsReq(pMsg)) {
189,805!
554
    if (code != 0 && terrno != 0) code = terrno;
189,805✔
555
    SRpcMsg rsp = {
189,805✔
556
        .code = code,
557
        .pCont = pMsg->info.rsp,
189,805✔
558
        .contLen = pMsg->info.rspLen,
189,805✔
559
        .info = pMsg->info,
560
    };
561

562
    code = rpcSendResponse(&rsp);
189,805✔
563
    if (code != 0) {
189,805!
564
      dError("failed to send response since %s", tstrerror(code));
×
565
    }
566
  }
567

568
  dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
189,805✔
569
  rpcFreeCont(pMsg->pCont);
189,805✔
570
  taosFreeQitem(pMsg);
189,805✔
571
}
189,805✔
572

573
int32_t dmStartWorker(SDnodeMgmt *pMgmt) {
1,879✔
574
  int32_t          code = 0;
1,879✔
575
  SSingleWorkerCfg cfg = {
1,879✔
576
      .min = 1,
577
      .max = 1,
578
      .name = "dnode-mgmt",
579
      .fp = (FItem)dmProcessMgmtQueue,
580
      .param = pMgmt,
581
  };
582
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg)) != 0) {
1,879!
583
    dError("failed to start dnode-mgmt worker since %s", tstrerror(code));
×
584
    return code;
×
585
  }
586

587
  dDebug("dnode workers are initialized");
1,879✔
588
  return 0;
1,879✔
589
}
590

591
void dmStopWorker(SDnodeMgmt *pMgmt) {
1,879✔
592
  tSingleWorkerCleanup(&pMgmt->mgmtWorker);
1,879✔
593
  dDebug("dnode workers are closed");
1,879✔
594
}
1,879✔
595

596
int32_t dmPutNodeMsgToMgmtQueue(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
189,765✔
597
  SSingleWorker *pWorker = &pMgmt->mgmtWorker;
189,765✔
598
  dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
189,765✔
599
  return taosWriteQitem(pWorker->queue, pMsg);
189,765✔
600
}
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