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

taosdata / TDengine / #3638

11 Mar 2025 12:59PM UTC coverage: 3.066% (-18.3%) from 21.409%
#3638

push

travis-ci

web-flow
Merge pull request #30118 from taosdata/wl30

udpate ci workflow

5914 of 287117 branches covered (2.06%)

Branch coverage included in aggregate %.

11588 of 283747 relevant lines covered (4.08%)

142.17 hits per line

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

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

26
  int32_t upTimeCount = 0;
×
27
  int64_t upTime = 0;
×
28

29
  while (1) {
×
30
    taosMsleep(200);
×
31
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
×
32

33
    int64_t curTime = taosGetTimestampMs();
×
34
    if (curTime < lastTime) lastTime = curTime;
×
35
    float interval = (curTime - lastTime) / 1000.0f;
×
36
    if (interval >= tsStatusInterval) {
×
37
      dmSendStatusReq(pMgmt);
×
38
      lastTime = curTime;
×
39

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

47
  return NULL;
×
48
}
49

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

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

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

74
  int32_t upTimeCount = 0;
×
75
  int64_t upTime = 0;
×
76

77
  while (1) {
×
78
    taosMsleep(200);
×
79
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
×
80

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

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

95
  return NULL;
×
96
}
97

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

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

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

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

197
  return NULL;
×
198
}
199

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

206
  static int32_t TRIM_FREQ = 20;
207
  int32_t        trimCount = 0;
×
208

209
  while (1) {
×
210
    taosMsleep(200);
×
211
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
×
212

213
    int64_t curTime = taosGetTimestampMs();
×
214

215
    if (curTime < lastTime) lastTime = curTime;
×
216
    float interval = (curTime - lastTime) / 1000.0f;
×
217
    if (interval >= tsMonitorInterval) {
×
218
      (*pMgmt->sendMonitorReportFp)();
×
219
      (*pMgmt->monitorCleanExpiredSamplesFp)();
×
220
      lastTime = curTime;
×
221

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

232
  return NULL;
×
233
}
234

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

240
  while (1) {
×
241
    taosMsleep(100);
×
242
    if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
×
243

244
    int64_t curTime = taosGetTimestampMs();
×
245
    if (curTime < lastTime) lastTime = curTime;
×
246
    float interval = curTime - lastTime;
×
247
    if (interval >= tsAuditInterval) {
×
248
      (*pMgmt->sendAuditRecordsFp)();
×
249
      lastTime = curTime;
×
250
    }
251
  }
252

253
  return NULL;
×
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
      dInfo("no crash info was found");
×
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) {
×
335
  int32_t      code = 0;
×
336
  TdThreadAttr thAttr;
337
  (void)taosThreadAttrInit(&thAttr);
×
338
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
×
339
  if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) {
×
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);
×
346
  tmsgReportStartup("dnode-status", "initialized");
×
347
  return 0;
×
348
}
349

350
int32_t dmStartConfigThread(SDnodeMgmt *pMgmt) {
×
351
  int32_t      code = 0;
×
352
  TdThreadAttr thAttr;
353
  (void)taosThreadAttrInit(&thAttr);
×
354
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
×
355
  if (taosThreadCreate(&pMgmt->configThread, &thAttr, dmConfigThreadFp, pMgmt) != 0) {
×
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);
×
362
  tmsgReportStartup("config-status", "initialized");
×
363
  return 0;
×
364
}
365

366
int32_t dmStartStatusInfoThread(SDnodeMgmt *pMgmt) {
×
367
  int32_t      code = 0;
×
368
  TdThreadAttr thAttr;
369
  (void)taosThreadAttrInit(&thAttr);
×
370
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
×
371
  if (taosThreadCreate(&pMgmt->statusInfoThread, &thAttr, dmStatusInfoThreadFp, pMgmt) != 0) {
×
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);
×
378
  tmsgReportStartup("dnode-status-info", "initialized");
×
379
  return 0;
×
380
}
381

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

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

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

403
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) {
×
404
  int32_t      code = 0;
×
405
  TdThreadAttr thAttr;
406
  (void)taosThreadAttrInit(&thAttr);
×
407
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
×
408
  if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) {
×
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);
×
415
  tmsgReportStartup("dnode-notify", "initialized");
×
416
  return 0;
×
417
}
418

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

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

433
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
×
434
  int32_t      code = 0;
×
435
  TdThreadAttr thAttr;
436
  (void)taosThreadAttrInit(&thAttr);
×
437
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
×
438
  if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) {
×
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);
×
445
  tmsgReportStartup("dnode-monitor", "initialized");
×
446
  return 0;
×
447
}
448

449
int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
×
450
  int32_t      code = 0;
×
451
  TdThreadAttr thAttr;
452
  (void)taosThreadAttrInit(&thAttr);
×
453
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
×
454
  if (taosThreadCreate(&pMgmt->auditThread, &thAttr, dmAuditThreadFp, pMgmt) != 0) {
×
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);
×
461
  tmsgReportStartup("dnode-audit", "initialized");
×
462
  return 0;
×
463
}
464

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

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

479
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
×
480
  int32_t code = 0;
×
481
  if (!tsEnableCrashReport) {
×
482
    return 0;
×
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) {
×
500
  if (!tsEnableCrashReport) {
×
501
    return;
×
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) {
×
511
  SDnodeMgmt *pMgmt = pInfo->ahandle;
×
512
  int32_t     code = -1;
×
513
  STraceId   *trace = &pMsg->info.traceId;
×
514
  dGTrace("msg:%p, will be processed in dnode queue, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
×
515

516
  switch (pMsg->msgType) {
×
517
    case TDMT_DND_CONFIG_DNODE:
×
518
      code = dmProcessConfigReq(pMgmt, pMsg);
×
519
      break;
×
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:
×
527
      code = (*pMgmt->processCreateNodeFp)(MNODE, pMsg);
×
528
      break;
×
529
    case TDMT_DND_DROP_MNODE:
×
530
      code = (*pMgmt->processDropNodeFp)(MNODE, pMsg);
×
531
      break;
×
532
    case TDMT_DND_CREATE_QNODE:
×
533
      code = (*pMgmt->processCreateNodeFp)(QNODE, pMsg);
×
534
      break;
×
535
    case TDMT_DND_DROP_QNODE:
×
536
      code = (*pMgmt->processDropNodeFp)(QNODE, pMsg);
×
537
      break;
×
538
    case TDMT_DND_CREATE_SNODE:
×
539
      code = (*pMgmt->processCreateNodeFp)(SNODE, pMsg);
×
540
      break;
×
541
    case TDMT_DND_DROP_SNODE:
×
542
      code = (*pMgmt->processDropNodeFp)(SNODE, pMsg);
×
543
      break;
×
544
    case TDMT_DND_ALTER_MNODE_TYPE:
×
545
      code = (*pMgmt->processAlterNodeTypeFp)(MNODE, pMsg);
×
546
      break;
×
547
    case TDMT_DND_SERVER_STATUS:
×
548
      code = dmProcessServerRunStatus(pMgmt, pMsg);
×
549
      break;
×
550
    case TDMT_DND_SYSTABLE_RETRIEVE:
×
551
      code = dmProcessRetrieve(pMgmt, pMsg);
×
552
      break;
×
553
    case TDMT_MND_GRANT:
×
554
      code = dmProcessGrantReq(&pMgmt->pData->clusterId, pMsg);
×
555
      break;
×
556
    case TDMT_MND_GRANT_NOTIFY:
×
557
      code = dmProcessGrantNotify(NULL, pMsg);
×
558
      break;
×
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)) {
×
569
    if (code != 0 && terrno != 0) code = terrno;
×
570
    SRpcMsg rsp = {
×
571
        .code = code,
572
        .pCont = pMsg->info.rsp,
×
573
        .contLen = pMsg->info.rspLen,
×
574
        .info = pMsg->info,
575
    };
576

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

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

588
int32_t dmStartWorker(SDnodeMgmt *pMgmt) {
×
589
  int32_t          code = 0;
×
590
  SSingleWorkerCfg cfg = {
×
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) {
×
598
    dError("failed to start dnode-mgmt worker since %s", tstrerror(code));
×
599
    return code;
×
600
  }
601

602
  dDebug("dnode workers are initialized");
×
603
  return 0;
×
604
}
605

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

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