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

taosdata / TDengine / #4754

25 Sep 2025 05:58AM UTC coverage: 57.946% (-1.0%) from 58.977%
#4754

push

travis-ci

web-flow
enh: taos command line support '-uroot' on windows (#33055)

133189 of 293169 branches covered (45.43%)

Branch coverage included in aggregate %.

201677 of 284720 relevant lines covered (70.83%)

5398749.0 hits per line

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

54.51
/source/dnode/mgmt/mgmt_dnode/src/dmHandle.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 "audit.h"
18
#include "dmInt.h"
19
#include "monitor.h"
20
#include "systable.h"
21
#include "tanalytics.h"
22
#include "tchecksum.h"
23
#include "tutil.h"
24
#include "stream.h"
25

26
extern SConfig *tsCfg;
27

28
SMonVloadInfo tsVinfo = {0};
29
SMnodeLoad    tsMLoad = {0};
30
SDnodeData    tsDnodeData = {0};
31

32
static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) {
9,243✔
33
  int32_t code = 0;
9,243✔
34
  if (pMgmt->pData->dnodeId == 0 || pMgmt->pData->clusterId == 0) {
9,243✔
35
    dInfo("set local info, dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId);
1,910!
36
    (void)taosThreadRwlockWrlock(&pMgmt->pData->lock);
1,910✔
37
    pMgmt->pData->dnodeId = pCfg->dnodeId;
1,910✔
38
    pMgmt->pData->clusterId = pCfg->clusterId;
1,910✔
39
    monSetDnodeId(pCfg->dnodeId);
1,910✔
40
    auditSetDnodeId(pCfg->dnodeId);
1,910✔
41
    code = dmWriteEps(pMgmt->pData);
1,910✔
42
    if (code != 0) {
1,910!
43
      dInfo("failed to set local info, dnodeId:%d clusterId:0x%" PRIx64 " reason:%s", pCfg->dnodeId, pCfg->clusterId,
×
44
            tstrerror(code));
45
    }
46
    (void)taosThreadRwlockUnlock(&pMgmt->pData->lock);
1,910✔
47
  }
48
}
9,243✔
49

50
static void dmMayShouldUpdateIpWhiteList(SDnodeMgmt *pMgmt, int64_t ver) {
9,592✔
51
  int32_t code = 0;
9,592✔
52
  dDebug("ip-white-list on dnode ver: %" PRId64 ", status ver: %" PRId64, pMgmt->pData->ipWhiteVer, ver);
9,592✔
53
  if (pMgmt->pData->ipWhiteVer == ver) {
9,592✔
54
    if (ver == 0) {
9,585✔
55
      dDebug("disable ip-white-list on dnode ver: %" PRId64 ", status ver: %" PRId64, pMgmt->pData->ipWhiteVer, ver);
9,573✔
56
      if (rpcSetIpWhite(pMgmt->msgCb.serverRpc, NULL) != 0) {
9,573!
57
        dError("failed to disable ip white list on dnode");
×
58
      }
59
    }
60
    return;
9,585✔
61
  }
62
  int64_t oldVer = pMgmt->pData->ipWhiteVer;
7✔
63

64
  SRetrieveIpWhiteReq req = {.ipWhiteVer = oldVer};
7✔
65
  int32_t             contLen = tSerializeRetrieveIpWhite(NULL, 0, &req);
7✔
66
  if (contLen < 0) {
7!
67
    dError("failed to serialize ip white list request since: %s", tstrerror(contLen));
×
68
    return;
×
69
  }
70
  void *pHead = rpcMallocCont(contLen);
7✔
71
  contLen = tSerializeRetrieveIpWhite(pHead, contLen, &req);
7✔
72
  if (contLen < 0) {
7!
73
    rpcFreeCont(pHead);
×
74
    dError("failed to serialize ip white list request since:%s", tstrerror(contLen));
×
75
    return;
×
76
  }
77

78
  SRpcMsg rpcMsg = {.pCont = pHead,
7✔
79
                    .contLen = contLen,
80
                    .msgType = TDMT_MND_RETRIEVE_IP_WHITE_DUAL,
81
                    .info.ahandle = 0,
82
                    .info.notFreeAhandle = 1,
83
                    .info.refId = 0,
84
                    .info.noResp = 0,
85
                    .info.handle = 0};
86
  SEpSet  epset = {0};
7✔
87

88
  (void)dmGetMnodeEpSet(pMgmt->pData, &epset);
7✔
89

90
  code = rpcSendRequest(pMgmt->msgCb.clientRpc, &epset, &rpcMsg, NULL);
7✔
91
  if (code != 0) {
7!
92
    dError("failed to send retrieve ip white list request since:%s", tstrerror(code));
×
93
  }
94
}
95

96
static void dmMayShouldUpdateAnalyticsFunc(SDnodeMgmt *pMgmt, int64_t newVer) {
9,592✔
97
  int32_t code = 0;
9,592✔
98
  int64_t oldVer = taosAnalyGetVersion();
9,592✔
99
  if (oldVer == newVer) return;
9,592!
100
  dDebug("analysis on dnode ver:%" PRId64 ", status ver:%" PRId64, oldVer, newVer);
×
101

102
  SRetrieveAnalyticsAlgoReq req = {.dnodeId = pMgmt->pData->dnodeId, .analVer = oldVer};
×
103
  int32_t              contLen = tSerializeRetrieveAnalyticAlgoReq(NULL, 0, &req);
×
104
  if (contLen < 0) {
×
105
    dError("failed to serialize analysis function ver request since %s", tstrerror(contLen));
×
106
    return;
×
107
  }
108

109
  void *pHead = rpcMallocCont(contLen);
×
110
  contLen = tSerializeRetrieveAnalyticAlgoReq(pHead, contLen, &req);
×
111
  if (contLen < 0) {
×
112
    rpcFreeCont(pHead);
×
113
    dError("failed to serialize analysis function ver request since %s", tstrerror(contLen));
×
114
    return;
×
115
  }
116

117
  SRpcMsg rpcMsg = {
×
118
      .pCont = pHead,
119
      .contLen = contLen,
120
      .msgType = TDMT_MND_RETRIEVE_ANAL_ALGO,
121
      .info.ahandle = 0,
122
      .info.refId = 0,
123
      .info.noResp = 0,
124
      .info.handle = 0,
125
  };
126
  SEpSet epset = {0};
×
127

128
  (void)dmGetMnodeEpSet(pMgmt->pData, &epset);
×
129

130
  code = rpcSendRequest(pMgmt->msgCb.clientRpc, &epset, &rpcMsg, NULL);
×
131
  if (code != 0) {
×
132
    dError("failed to send retrieve analysis func ver request since %s", tstrerror(code));
×
133
  }
134
}
135

136
static void dmProcessStatusRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
100,311✔
137
  const STraceId *trace = &pRsp->info.traceId;
100,311✔
138
  dGTrace("status rsp received from mnode, statusSeq:%d code:0x%x", pMgmt->statusSeq, pRsp->code);
100,311!
139

140
  if (pRsp->code != 0) {
100,311!
141
    if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->pData->dropped && pMgmt->pData->dnodeId > 0) {
×
142
      dGInfo("dnode:%d, set to dropped since not exist in mnode, statusSeq:%d", pMgmt->pData->dnodeId,
×
143
             pMgmt->statusSeq);
144
      pMgmt->pData->dropped = 1;
×
145
      if (dmWriteEps(pMgmt->pData) != 0) {
×
146
        dError("failed to write dnode file");
×
147
      }
148
      dInfo("dnode will exit since it is in the dropped state");
×
149
      (void)raise(SIGINT);
×
150
    }
151
  } else {
152
    SStatusRsp statusRsp = {0};
100,311✔
153
    if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
109,903!
154
        tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) {
9,592✔
155
      if (pMgmt->pData->dnodeVer != statusRsp.dnodeVer) {
9,592✔
156
        dGInfo("status rsp received from mnode, statusSeq:%d:%d dnodeVer:%" PRId64 ":%" PRId64, pMgmt->statusSeq,
9,243!
157
               statusRsp.statusSeq, pMgmt->pData->dnodeVer, statusRsp.dnodeVer);
158
        pMgmt->pData->dnodeVer = statusRsp.dnodeVer;
9,243✔
159
        dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg);
9,243✔
160
        dmUpdateEps(pMgmt->pData, statusRsp.pDnodeEps);
9,243✔
161
      }
162
      dmMayShouldUpdateIpWhiteList(pMgmt, statusRsp.ipWhiteVer);
9,592✔
163
      dmMayShouldUpdateAnalyticsFunc(pMgmt, statusRsp.analVer);
9,592✔
164
    }
165
    tFreeSStatusRsp(&statusRsp);
100,311✔
166
  }
167
  rpcFreeCont(pRsp->pCont);
100,311✔
168
}
100,311✔
169

170
void dmSendStatusReq(SDnodeMgmt *pMgmt) {
100,638✔
171
  int32_t    code = 0;
100,638✔
172
  SStatusReq req = {0};
100,638✔
173
  req.timestamp = taosGetTimestampMs();
100,638✔
174
  pMgmt->statusSeq++;
100,638✔
175

176
  dTrace("send status req to mnode, begin to mgnt statusInfolock, statusSeq:%d", pMgmt->statusSeq);
100,638✔
177
  if (taosThreadMutexLock(&pMgmt->pData->statusInfolock) != 0) {
100,638!
178
    dError("failed to lock status info lock");
×
179
    return;
327✔
180
  }
181

182
  dTrace("send status req to mnode, begin to get dnode info, statusSeq:%d", pMgmt->statusSeq);
100,638✔
183
  req.sver = tsVersion;
100,638✔
184
  req.dnodeVer = tsDnodeData.dnodeVer;
100,638✔
185
  req.dnodeId = tsDnodeData.dnodeId;
100,638✔
186
  req.clusterId = tsDnodeData.clusterId;
100,638✔
187
  if (req.clusterId == 0) req.dnodeId = 0;
100,638✔
188
  req.rebootTime = tsDnodeData.rebootTime;
100,638✔
189
  req.updateTime = tsDnodeData.updateTime;
100,638✔
190
  req.numOfCores = tsNumOfCores;
100,638✔
191
  req.numOfSupportVnodes = tsNumOfSupportVnodes;
100,638✔
192
  req.numOfDiskCfg = tsDiskCfgNum;
100,638✔
193
  req.memTotal = tsTotalMemoryKB * 1024;
100,638✔
194
  req.memAvail = req.memTotal - tsQueueMemoryAllowed - tsApplyMemoryAllowed - 16 * 1024 * 1024;
100,638✔
195
  tstrncpy(req.dnodeEp, tsLocalEp, TSDB_EP_LEN);
100,638✔
196
  tstrncpy(req.machineId, tsDnodeData.machineId, TSDB_MACHINE_ID_LEN + 1);
100,638✔
197

198
  req.clusterCfg.statusInterval = tsStatusInterval;
100,638✔
199
  req.clusterCfg.statusIntervalMs = tsStatusIntervalMs;
100,638✔
200
  req.clusterCfg.checkTime = 0;
100,638✔
201
  req.clusterCfg.ttlChangeOnWrite = tsTtlChangeOnWrite;
100,638✔
202
  req.clusterCfg.enableWhiteList = tsEnableWhiteList ? 1 : 0;
100,638✔
203
  req.clusterCfg.encryptionKeyStat = tsEncryptionKeyStat;
100,638✔
204
  req.clusterCfg.encryptionKeyChksum = tsEncryptionKeyChksum;
100,638✔
205
  req.clusterCfg.monitorParas.tsEnableMonitor = tsEnableMonitor;
100,638✔
206
  req.clusterCfg.monitorParas.tsMonitorInterval = tsMonitorInterval;
100,638✔
207
  req.clusterCfg.monitorParas.tsSlowLogScope = tsSlowLogScope;
100,638✔
208
  req.clusterCfg.monitorParas.tsSlowLogMaxLen = tsSlowLogMaxLen;
100,638✔
209
  req.clusterCfg.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold;
100,638✔
210
  tstrncpy(req.clusterCfg.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN);
100,638✔
211
  char timestr[32] = "1970-01-01 00:00:00.00";
100,638✔
212
  if (taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, NULL) !=
100,638!
213
      0) {
214
    dError("failed to parse time since %s", tstrerror(code));
×
215
  }
216
  memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
100,638✔
217
  memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
100,638✔
218
  memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
100,638✔
219

220
  dTrace("send status req to mnode, begin to get vnode loads, statusSeq:%d", pMgmt->statusSeq);
100,638✔
221

222
  req.pVloads = tsVinfo.pVloads;
100,638✔
223
  tsVinfo.pVloads = NULL;
100,638✔
224

225
  dTrace("send status req to mnode, begin to get mnode loads, statusSeq:%d", pMgmt->statusSeq);
100,638✔
226
  req.mload = tsMLoad;
100,638✔
227

228
  if (taosThreadMutexUnlock(&pMgmt->pData->statusInfolock) != 0) {
100,638!
229
    dError("failed to unlock status info lock");
×
230
    return;
×
231
  }
232

233
  dTrace("send status req to mnode, begin to get qnode loads, statusSeq:%d", pMgmt->statusSeq);
100,638✔
234
  (*pMgmt->getQnodeLoadsFp)(&req.qload);
100,638✔
235

236
  req.statusSeq = pMgmt->statusSeq;
100,638✔
237
  req.ipWhiteVer = pMgmt->pData->ipWhiteVer;
100,638✔
238
  req.analVer = taosAnalyGetVersion();
100,638✔
239

240
  int32_t contLen = tSerializeSStatusReq(NULL, 0, &req);
100,638✔
241
  if (contLen < 0) {
100,638!
242
    dError("failed to serialize status req since %s", tstrerror(contLen));
×
243
    return;
×
244
  }
245

246
  void *pHead = rpcMallocCont(contLen);
100,638✔
247
  contLen = tSerializeSStatusReq(pHead, contLen, &req);
100,638✔
248
  if (contLen < 0) {
100,638!
249
    rpcFreeCont(pHead);
×
250
    dError("failed to serialize status req since %s", tstrerror(contLen));
×
251
    return;
×
252
  }
253
  tFreeSStatusReq(&req);
100,638✔
254

255
  SRpcMsg rpcMsg = {.pCont = pHead,
100,638✔
256
                    .contLen = contLen,
257
                    .msgType = TDMT_MND_STATUS,
258
                    .info.ahandle = 0,
259
                    .info.notFreeAhandle = 1,
260
                    .info.refId = 0,
261
                    .info.noResp = 0,
262
                    .info.handle = 0};
263
  SRpcMsg rpcRsp = {0};
100,638✔
264

265
  dDebug("send status req to mnode, dnodeVer:%" PRId64 " statusSeq:%d", req.dnodeVer, req.statusSeq);
100,638✔
266

267
  SEpSet epSet = {0};
100,638✔
268
  int8_t epUpdated = 0;
100,638✔
269
  (void)dmGetMnodeEpSet(pMgmt->pData, &epSet);
100,638✔
270

271
  dTrace("send status req to mnode, begin to send rpc msg, statusSeq:%d", pMgmt->statusSeq);
100,638✔
272
  code = rpcSendRecvWithTimeout(pMgmt->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, &epUpdated, tsStatusSRTimeoutMs);
100,638✔
273
  if (code != 0) {
100,638✔
274
    dError("failed to SendRecv status req with timeout %d since %s", tsStatusSRTimeoutMs, tstrerror(code));
327!
275
    return;
327✔
276
  }
277

278
  if (rpcRsp.code != 0) {
100,311!
279
    dmRotateMnodeEpSet(pMgmt->pData);
×
280
    char tbuf[512];
281
    dmEpSetToStr(tbuf, sizeof(tbuf), &epSet);
×
282
    dInfo("Rotate mnode ep set since failed to SendRecv status req %s, epSet:%s, inUse:%d", tstrerror(rpcRsp.code),
×
283
          tbuf, epSet.inUse);
284
  } else {
285
    if (epUpdated == 1) {
100,311✔
286
      dmSetMnodeEpSet(pMgmt->pData, &epSet);
1,184✔
287
    }
288
  }
289
  dmProcessStatusRsp(pMgmt, &rpcRsp);
100,311✔
290
}
291

292
static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
2,367✔
293
  const STraceId *trace = &pRsp->info.traceId;
2,367✔
294
  int32_t         code = 0;
2,367✔
295
  SConfigRsp      configRsp = {0};
2,367✔
296
  bool            needStop = false;
2,367✔
297

298
  if (pRsp->code != 0) {
2,367!
299
    if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->pData->dropped && pMgmt->pData->dnodeId > 0) {
×
300
      dGInfo("dnode:%d, set to dropped since not exist in mnode", pMgmt->pData->dnodeId);
×
301
      pMgmt->pData->dropped = 1;
×
302
      if (dmWriteEps(pMgmt->pData) != 0) {
×
303
        dError("failed to write dnode file");
×
304
      }
305
      dInfo("dnode will exit since it is in the dropped state");
×
306
      (void)raise(SIGINT);
×
307
    }
308
  } else {
309
    bool needUpdate = false;
2,367✔
310
    if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
4,734!
311
        tDeserializeSConfigRsp(pRsp->pCont, pRsp->contLen, &configRsp) == 0) {
2,367✔
312
      // Try to use cfg from mnode sdb.
313
      if (!configRsp.isVersionVerified) {
2,367✔
314
        uInfo("config version not verified, update config");
1,922!
315
        needUpdate = true;
1,922✔
316
        code = taosPersistGlobalConfig(configRsp.array, pMgmt->path, configRsp.cver);
1,922✔
317
        if (code != TSDB_CODE_SUCCESS) {
1,922✔
318
          dError("failed to persist global config since %s", tstrerror(code));
6!
319
          goto _exit;
6✔
320
        }
321
      }
322
    }
323
    if (needUpdate) {
2,361✔
324
      code = cfgUpdateFromArray(tsCfg, configRsp.array);
1,916✔
325
      if (code != TSDB_CODE_SUCCESS) {
1,916!
326
        dError("failed to update config since %s", tstrerror(code));
×
327
        goto _exit;
×
328
      }
329
      code = setAllConfigs(tsCfg);
1,916✔
330
      if (code != TSDB_CODE_SUCCESS) {
1,916✔
331
        dError("failed to set all configs since %s", tstrerror(code));
24!
332
        goto _exit;
24✔
333
      }
334
    }
335
    code = taosPersistLocalConfig(pMgmt->path);
2,337✔
336
    if (code != TSDB_CODE_SUCCESS) {
2,337!
337
      dError("failed to persist local config since %s", tstrerror(code));
×
338
    }
339
    tsConfigInited = 1;
2,337✔
340
  }
341
_exit:
2,367✔
342
  tFreeSConfigRsp(&configRsp);
2,367✔
343
  rpcFreeCont(pRsp->pCont);
2,367✔
344
  if (needStop) {
2,367!
345
    dmStop();
×
346
  }
347
}
2,367✔
348

349
void dmSendConfigReq(SDnodeMgmt *pMgmt) {
2,369✔
350
  int32_t    code = 0;
2,369✔
351
  SConfigReq req = {0};
2,369✔
352

353
  req.cver = tsdmConfigVersion;
2,369✔
354
  req.forceReadConfig = tsForceReadConfig;
2,369✔
355
  req.array = taosGetGlobalCfg(tsCfg);
2,369✔
356
  dDebug("send config req to mnode, configVersion:%d", req.cver);
2,369✔
357

358
  int32_t contLen = tSerializeSConfigReq(NULL, 0, &req);
2,369✔
359
  if (contLen < 0) {
2,369!
360
    dError("failed to serialize status req since %s", tstrerror(contLen));
×
361
    return;
2✔
362
  }
363

364
  void *pHead = rpcMallocCont(contLen);
2,369✔
365
  if (pHead == NULL) {
2,369!
366
    dError("failed to malloc cont since %s", tstrerror(contLen));
×
367
    return;
×
368
  }
369
  contLen = tSerializeSConfigReq(pHead, contLen, &req);
2,369✔
370
  if (contLen < 0) {
2,369!
371
    rpcFreeCont(pHead);
×
372
    dError("failed to serialize status req since %s", tstrerror(contLen));
×
373
    return;
×
374
  }
375

376
  SRpcMsg rpcMsg = {.pCont = pHead,
2,369✔
377
                    .contLen = contLen,
378
                    .msgType = TDMT_MND_CONFIG,
379
                    .info.ahandle = 0,
380
                    .info.notFreeAhandle = 1,
381
                    .info.refId = 0,
382
                    .info.noResp = 0,
383
                    .info.handle = 0};
384
  SRpcMsg rpcRsp = {0};
2,369✔
385

386
  SEpSet epSet = {0};
2,369✔
387
  int8_t epUpdated = 0;
2,369✔
388
  (void)dmGetMnodeEpSet(pMgmt->pData, &epSet);
2,369✔
389

390
  dDebug("send status req to mnode, statusSeq:%d, begin to send rpc msg", pMgmt->statusSeq);
2,369✔
391
  code = rpcSendRecvWithTimeout(pMgmt->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, &epUpdated, tsStatusSRTimeoutMs);
2,369✔
392
  if (code != 0) {
2,369✔
393
    dError("failed to SendRecv config req with timeout %d since %s", tsStatusSRTimeoutMs, tstrerror(code));
2!
394
    return;
2✔
395
  }
396
  if (rpcRsp.code != 0) {
2,367!
397
    dError("failed to send config req since %s", tstrerror(rpcRsp.code));
×
398
    return;
×
399
  }
400
  dmProcessConfigRsp(pMgmt, &rpcRsp);
2,367✔
401
}
402

403
void dmUpdateStatusInfo(SDnodeMgmt *pMgmt) {
102,560✔
404
  dDebug("begin to get dnode info");
102,560✔
405
  SDnodeData dnodeData = {0};
102,560✔
406
  (void)taosThreadRwlockRdlock(&pMgmt->pData->lock);
102,560✔
407
  dnodeData.dnodeVer = pMgmt->pData->dnodeVer;
102,560✔
408
  dnodeData.dnodeId = pMgmt->pData->dnodeId;
102,560✔
409
  dnodeData.clusterId = pMgmt->pData->clusterId;
102,560✔
410
  dnodeData.rebootTime = pMgmt->pData->rebootTime;
102,560✔
411
  dnodeData.updateTime = pMgmt->pData->updateTime;
102,560✔
412
  tstrncpy(dnodeData.machineId, pMgmt->pData->machineId, TSDB_MACHINE_ID_LEN + 1);
102,560✔
413
  (void)taosThreadRwlockUnlock(&pMgmt->pData->lock);
102,560✔
414

415
  dDebug("begin to get vnode loads");
102,560✔
416
  SMonVloadInfo vinfo = {0};
102,560✔
417
  (*pMgmt->getVnodeLoadsFp)(&vinfo);  // dmGetVnodeLoads
102,560✔
418

419
  dDebug("begin to get mnode loads");
102,560✔
420
  SMonMloadInfo minfo = {0};
102,560✔
421
  (*pMgmt->getMnodeLoadsFp)(&minfo);  // dmGetMnodeLoads
102,560✔
422

423
  dDebug("begin to lock status info");
102,560✔
424
  if (taosThreadMutexLock(&pMgmt->pData->statusInfolock) != 0) {
102,560!
425
    dError("failed to lock status info lock");
×
426
    return;
×
427
  }
428
  tsDnodeData.dnodeVer = dnodeData.dnodeVer;
102,560✔
429
  tsDnodeData.dnodeId = dnodeData.dnodeId;
102,560✔
430
  tsDnodeData.clusterId = dnodeData.clusterId;
102,560✔
431
  tsDnodeData.rebootTime = dnodeData.rebootTime;
102,560✔
432
  tsDnodeData.updateTime = dnodeData.updateTime;
102,560✔
433
  tstrncpy(tsDnodeData.machineId, dnodeData.machineId, TSDB_MACHINE_ID_LEN + 1);
102,560✔
434

435
  if (tsVinfo.pVloads == NULL) {
102,560✔
436
    tsVinfo.pVloads = vinfo.pVloads;
98,798✔
437
    vinfo.pVloads = NULL;
98,798✔
438
  } else {
439
    taosArrayDestroy(vinfo.pVloads);
3,762✔
440
    vinfo.pVloads = NULL;
3,762✔
441
  }
442

443
  tsMLoad = minfo.load;
102,560✔
444

445
  if (taosThreadMutexUnlock(&pMgmt->pData->statusInfolock) != 0) {
102,560!
446
    dError("failed to unlock status info lock");
×
447
    return;
×
448
  }
449
}
450

451
void dmSendNotifyReq(SDnodeMgmt *pMgmt, SNotifyReq *pReq) {
×
452
  int32_t contLen = tSerializeSNotifyReq(NULL, 0, pReq);
×
453
  if (contLen < 0) {
×
454
    dError("failed to serialize notify req since %s", tstrerror(contLen));
×
455
    return;
×
456
  }
457
  void *pHead = rpcMallocCont(contLen);
×
458
  contLen = tSerializeSNotifyReq(pHead, contLen, pReq);
×
459
  if (contLen < 0) {
×
460
    rpcFreeCont(pHead);
×
461
    dError("failed to serialize notify req since %s", tstrerror(contLen));
×
462
    return;
×
463
  }
464

465
  SRpcMsg rpcMsg = {.pCont = pHead,
×
466
                    .contLen = contLen,
467
                    .msgType = TDMT_MND_NOTIFY,
468
                    .info.ahandle = 0,
469
                    .info.notFreeAhandle = 1,
470
                    .info.refId = 0,
471
                    .info.noResp = 1,
472
                    .info.handle = 0};
473

474
  SEpSet epSet = {0};
×
475
  dmGetMnodeEpSet(pMgmt->pData, &epSet);
×
476
  if (rpcSendRequest(pMgmt->msgCb.clientRpc, &epSet, &rpcMsg, NULL) != 0) {
×
477
    dError("failed to send notify req");
×
478
  }
479
}
480

481
int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
×
482
  dError("auth rsp is received, but not supported yet");
×
483
  return 0;
×
484
}
485

486
int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
×
487
  dError("grant rsp is received, but not supported yet");
×
488
  return 0;
×
489
}
490

491
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
180✔
492
  int32_t       code = 0;
180✔
493
  SDCfgDnodeReq cfgReq = {0};
180✔
494
  SConfig      *pCfg = taosGetCfg();
180✔
495
  SConfigItem  *pItem = NULL;
180✔
496

497
  if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
180!
498
    return TSDB_CODE_INVALID_MSG;
×
499
  }
500
  if (strcasecmp(cfgReq.config, "dataDir") == 0) {
180✔
501
    return taosUpdateTfsItemDisable(pCfg, cfgReq.value, pMgmt->pTfs);
5✔
502
  }
503

504
  dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
175!
505

506
  code = cfgGetAndSetItem(pCfg, &pItem, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_SERVER_CMD, true);
175✔
507
  if (code != 0) {
175✔
508
    if (strncasecmp(cfgReq.config, "resetlog", strlen("resetlog")) == 0) {
2!
509
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, cfgReq.config, true));
2!
510
      return TSDB_CODE_SUCCESS;
2✔
511
    } else {
512
      return code;
×
513
    }
514
  }
515
  if (pItem == NULL) {
173!
516
    return TSDB_CODE_CFG_NOT_FOUND;
×
517
  }
518

519
  if (taosStrncasecmp(cfgReq.config, "syncTimeout", 128) == 0) {
173!
520
    char value[10] = {0};
×
521
    if (sscanf(cfgReq.value, "%d", &tsSyncTimeout) != 1) {
×
522
      tsSyncTimeout = 0;
×
523
    }
524

525
    if (tsSyncTimeout > 0) {
×
526
      SConfigItem *pItemTmp = NULL;
×
527
      char         tmp[10] = {0};
×
528

529
      sprintf(tmp, "%d", tsSyncTimeout);
×
530
      TAOS_CHECK_RETURN(
×
531
          cfgGetAndSetItem(pCfg, &pItemTmp, "arbSetAssignedTimeoutMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
532
      if (pItemTmp == NULL) {
×
533
        return TSDB_CODE_CFG_NOT_FOUND;
×
534
      }
535

536
      sprintf(tmp, "%d", tsSyncTimeout / 4);
×
537
      TAOS_CHECK_RETURN(
×
538
          cfgGetAndSetItem(pCfg, &pItemTmp, "arbHeartBeatIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
539
      if (pItemTmp == NULL) {
×
540
        return TSDB_CODE_CFG_NOT_FOUND;
×
541
      }
542
      TAOS_CHECK_RETURN(
×
543
          cfgGetAndSetItem(pCfg, &pItemTmp, "arbCheckSyncIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
544
      if (pItemTmp == NULL) {
×
545
        return TSDB_CODE_CFG_NOT_FOUND;
×
546
      }
547

548
      sprintf(tmp, "%d", (tsSyncTimeout - tsSyncTimeout / 4) / 2);
×
549
      TAOS_CHECK_RETURN(
×
550
          cfgGetAndSetItem(pCfg, &pItemTmp, "syncVnodeElectIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
551
      if (pItemTmp == NULL) {
×
552
        return TSDB_CODE_CFG_NOT_FOUND;
×
553
      }
554
      TAOS_CHECK_RETURN(
×
555
          cfgGetAndSetItem(pCfg, &pItemTmp, "syncMnodeElectIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
556
      if (pItemTmp == NULL) {
×
557
        return TSDB_CODE_CFG_NOT_FOUND;
×
558
      }
559
      TAOS_CHECK_RETURN(cfgGetAndSetItem(pCfg, &pItemTmp, "statusTimeoutMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
×
560
      if (pItemTmp == NULL) {
×
561
        return TSDB_CODE_CFG_NOT_FOUND;
×
562
      }
563

564
      sprintf(tmp, "%d", (tsSyncTimeout - tsSyncTimeout / 4) / 4);
×
565
      TAOS_CHECK_RETURN(cfgGetAndSetItem(pCfg, &pItemTmp, "statusSRTimeoutMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
×
566
      if (pItemTmp == NULL) {
×
567
        return TSDB_CODE_CFG_NOT_FOUND;
×
568
      }
569

570
      sprintf(tmp, "%d", (tsSyncTimeout - tsSyncTimeout / 4) / 8);
×
571
      TAOS_CHECK_RETURN(
×
572
          cfgGetAndSetItem(pCfg, &pItemTmp, "syncVnodeHeartbeatIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
573
      if (pItemTmp == NULL) {
×
574
        return TSDB_CODE_CFG_NOT_FOUND;
×
575
      }
576
      TAOS_CHECK_RETURN(
×
577
          cfgGetAndSetItem(pCfg, &pItemTmp, "syncMnodeHeartbeatIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
578
      if (pItemTmp == NULL) {
×
579
        return TSDB_CODE_CFG_NOT_FOUND;
×
580
      }
581
      TAOS_CHECK_RETURN(cfgGetAndSetItem(pCfg, &pItemTmp, "statusIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
×
582
      if (pItemTmp == NULL) {
×
583
        return TSDB_CODE_CFG_NOT_FOUND;
×
584
      }
585

586
      dInfo("change syncTimeout, GetAndSetItem, option:%s, value:%s, tsSyncTimeout:%d", cfgReq.config, cfgReq.value,
×
587
            tsSyncTimeout);
588
    }
589
  }
590

591
  if (!isConifgItemLazyMode(pItem)) {
173✔
592
    TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, cfgReq.config, true));
172!
593

594
    if (taosStrncasecmp(cfgReq.config, "syncTimeout", 128) == 0) {
172!
595
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "arbSetAssignedTimeoutMs", true));
×
596
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "arbHeartBeatIntervalMs", true));
×
597
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "arbCheckSyncIntervalMs", true));
×
598

599
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "syncVnodeElectIntervalMs", true));
×
600
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "syncMnodeElectIntervalMs", true));
×
601
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "syncVnodeHeartbeatIntervalMs", true));
×
602
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "syncMnodeHeartbeatIntervalMs", true));
×
603

604
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "statusTimeoutMs", true));
×
605
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "statusSRTimeoutMs", true));
×
606
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "statusIntervalMs", true));
×
607

608
      dInfo("change syncTimeout, DynamicOptions, option:%s, value:%s, tsSyncTimeout:%d", cfgReq.config, cfgReq.value,
×
609
            tsSyncTimeout);
610
    }
611
  }
612

613
  if (pItem->category == CFG_CATEGORY_GLOBAL) {
173✔
614
    code = taosPersistGlobalConfig(taosGetGlobalCfg(pCfg), pMgmt->path, tsdmConfigVersion);
44✔
615
    if (code != TSDB_CODE_SUCCESS) {
44!
616
      dError("failed to persist global config since %s", tstrerror(code));
×
617
    }
618
  } else {
619
    code = taosPersistLocalConfig(pMgmt->path);
129✔
620
    if (code != TSDB_CODE_SUCCESS) {
129!
621
      dError("failed to persist local config since %s", tstrerror(code));
×
622
    }
623
  }
624

625
  if (taosStrncasecmp(cfgReq.config, "syncTimeout", 128) == 0) {
173!
626
    dInfo("finished change syncTimeout, option:%s, value:%s", cfgReq.config, cfgReq.value);
×
627

628
    (*pMgmt->setMnodeSyncTimeoutFp)();
×
629
    (*pMgmt->setVnodeSyncTimeoutFp)();
×
630
  }
631

632
  if (taosStrncasecmp(cfgReq.config, "syncVnodeElectIntervalMs", 128) == 0 ||
173!
633
      taosStrncasecmp(cfgReq.config, "syncVnodeHeartbeatIntervalMs", 128) == 0) {
173!
634
    (*pMgmt->setVnodeSyncTimeoutFp)();
×
635
  }
636

637
  if (taosStrncasecmp(cfgReq.config, "syncMnodeElectIntervalMs", 128) == 0 ||
173!
638
      taosStrncasecmp(cfgReq.config, "syncMnodeHeartbeatIntervalMs", 128) == 0) {
173!
639
    (*pMgmt->setMnodeSyncTimeoutFp)();
×
640
  }
641

642
  if (cfgReq.version > 0) {
173✔
643
    tsdmConfigVersion = cfgReq.version;
94✔
644
  }
645
  return code;
173✔
646
}
647

648
int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
5✔
649
#ifdef TD_ENTERPRISE
650
  int32_t       code = 0;
5✔
651
  SDCfgDnodeReq cfgReq = {0};
5✔
652
  if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
5!
653
    code = TSDB_CODE_INVALID_MSG;
×
654
    goto _exit;
×
655
  }
656

657
  code = dmUpdateEncryptKey(cfgReq.value, true);
5✔
658
  if (code == 0) {
5!
659
    tsEncryptionKeyChksum = taosCalcChecksum(0, cfgReq.value, strlen(cfgReq.value));
5✔
660
    tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
5✔
661
    tstrncpy(tsEncryptKey, cfgReq.value, ENCRYPT_KEY_LEN + 1);
5✔
662
  }
663

664
_exit:
×
665
  pMsg->code = code;
5✔
666
  pMsg->info.rsp = NULL;
5✔
667
  pMsg->info.rspLen = 0;
5✔
668
  return code;
5✔
669
#else
670
  return 0;
671
#endif
672
}
673

674
static void dmGetServerRunStatus(SDnodeMgmt *pMgmt, SServerStatusRsp *pStatus) {
4✔
675
  pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_OK;
4✔
676
  pStatus->details[0] = 0;
4✔
677

678
  SMonMloadInfo minfo = {0};
4✔
679
  (*pMgmt->getMnodeLoadsFp)(&minfo);
4✔
680
  if (minfo.isMnode &&
4!
681
      (minfo.load.syncState == TAOS_SYNC_STATE_ERROR || minfo.load.syncState == TAOS_SYNC_STATE_OFFLINE)) {
4!
682
    pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_DEGRADED;
×
683
    snprintf(pStatus->details, sizeof(pStatus->details), "mnode sync state is %s", syncStr(minfo.load.syncState));
×
684
    return;
×
685
  }
686

687
  SMonVloadInfo vinfo = {0};
4✔
688
  (*pMgmt->getVnodeLoadsFp)(&vinfo);
4✔
689
  for (int32_t i = 0; i < taosArrayGetSize(vinfo.pVloads); ++i) {
12✔
690
    SVnodeLoad *pLoad = taosArrayGet(vinfo.pVloads, i);
8✔
691
    if (pLoad->syncState == TAOS_SYNC_STATE_ERROR || pLoad->syncState == TAOS_SYNC_STATE_OFFLINE) {
8!
692
      pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_DEGRADED;
×
693
      snprintf(pStatus->details, sizeof(pStatus->details), "vnode:%d sync state is %s", pLoad->vgId,
×
694
               syncStr(pLoad->syncState));
×
695
      break;
×
696
    }
697
  }
698

699
  taosArrayDestroy(vinfo.pVloads);
4✔
700
}
701

702
int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
4✔
703
  int32_t code = 0;
4✔
704
  dDebug("server run status req is received");
4!
705
  SServerStatusRsp statusRsp = {0};
4✔
706
  dmGetServerRunStatus(pMgmt, &statusRsp);
4✔
707

708
  pMsg->info.rsp = NULL;
4✔
709
  pMsg->info.rspLen = 0;
4✔
710

711
  SRpcMsg rspMsg = {.info = pMsg->info};
4✔
712
  int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
4✔
713
  if (rspLen < 0) {
4!
714
    return TSDB_CODE_OUT_OF_MEMORY;
×
715
    // rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
716
    // return rspMsg.code;
717
  }
718

719
  void *pRsp = rpcMallocCont(rspLen);
4✔
720
  if (pRsp == NULL) {
4!
721
    return terrno;
×
722
    // rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
723
    // return rspMsg.code;
724
  }
725

726
  rspLen = tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
4✔
727
  if (rspLen < 0) {
4!
728
    return TSDB_CODE_INVALID_MSG;
×
729
  }
730

731
  pMsg->info.rsp = pRsp;
4✔
732
  pMsg->info.rspLen = rspLen;
4✔
733
  return 0;
4✔
734
}
735

736
int32_t dmBuildVariablesBlock(SSDataBlock **ppBlock) {
284✔
737
  int32_t code = 0;
284✔
738

739
  SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
284!
740
  if (pBlock == NULL) {
284!
741
    return terrno;
×
742
  }
743

744
  size_t size = 0;
284✔
745

746
  const SSysTableMeta *pMeta = NULL;
284✔
747
  getInfosDbMeta(&pMeta, &size);
284✔
748

749
  int32_t index = 0;
284✔
750
  for (int32_t i = 0; i < size; ++i) {
5,680!
751
    if (strcmp(pMeta[i].name, TSDB_INS_TABLE_DNODE_VARIABLES) == 0) {
5,680✔
752
      index = i;
284✔
753
      break;
284✔
754
    }
755
  }
756

757
  pBlock->pDataBlock = taosArrayInit(pMeta[index].colNum, sizeof(SColumnInfoData));
284✔
758
  if (pBlock->pDataBlock == NULL) {
284!
759
    code = terrno;
×
760
    goto _exit;
×
761
  }
762

763
  for (int32_t i = 0; i < pMeta[index].colNum; ++i) {
1,988✔
764
    SColumnInfoData colInfoData = {0};
1,704✔
765
    colInfoData.info.colId = i + 1;
1,704✔
766
    colInfoData.info.type = pMeta[index].schema[i].type;
1,704✔
767
    colInfoData.info.bytes = pMeta[index].schema[i].bytes;
1,704✔
768
    if (taosArrayPush(pBlock->pDataBlock, &colInfoData) == NULL) {
3,408!
769
      code = terrno;
×
770
      goto _exit;
×
771
    }
772
  }
773

774
  pBlock->info.hasVarCol = true;
284✔
775
_exit:
284✔
776
  if (code != 0) {
284!
777
    blockDataDestroy(pBlock);
×
778
  } else {
779
    *ppBlock = pBlock;
284✔
780
  }
781
  return code;
284✔
782
}
783

784
int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) {
284✔
785
  int32_t code = dumpConfToDataBlock(pBlock, 1, NULL);
284✔
786
  if (code != 0) {
284!
787
    return code;
×
788
  }
789

790
  SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
284✔
791
  if (pColInfo == NULL) {
284!
792
    return TSDB_CODE_OUT_OF_RANGE;
×
793
  }
794

795
  return colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, false);
284✔
796
}
797

798
int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
284✔
799
  int32_t           size = 0;
284✔
800
  int32_t           rowsRead = 0;
284✔
801
  int32_t           code = 0;
284✔
802
  SRetrieveTableReq retrieveReq = {0};
284✔
803
  if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
284!
804
    return TSDB_CODE_INVALID_MSG;
×
805
  }
806
  dInfo("retrieve table:%s, user:%s, compactId:%" PRId64, retrieveReq.tb, retrieveReq.user, retrieveReq.compactId);
284!
807
#if 0
808
  if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
809
    code = TSDB_CODE_MND_NO_RIGHTS;
810
    return code;
811
  }
812
#endif
813
  if (strcasecmp(retrieveReq.tb, TSDB_INS_TABLE_DNODE_VARIABLES)) {
284!
814
    return TSDB_CODE_INVALID_MSG;
×
815
  }
816

817
  SSDataBlock *pBlock = NULL;
284✔
818
  if ((code = dmBuildVariablesBlock(&pBlock)) != 0) {
284!
819
    return code;
×
820
  }
821

822
  code = dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
284✔
823
  if (code != 0) {
284!
824
    blockDataDestroy(pBlock);
×
825
    return code;
×
826
  }
827

828
  size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
284✔
829
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
284✔
830
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * numOfCols + dataEncodeBufSize;
284✔
831

832
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
284✔
833
  if (pRsp == NULL) {
284!
834
    code = terrno;
×
835
    dError("failed to retrieve data since %s", tstrerror(code));
×
836
    blockDataDestroy(pBlock);
×
837
    return code;
×
838
  }
839

840
  char *pStart = pRsp->data;
284✔
841
  *(int32_t *)pStart = htonl(numOfCols);
284✔
842
  pStart += sizeof(int32_t);  // number of columns
284✔
843

844
  for (int32_t i = 0; i < numOfCols; ++i) {
1,988✔
845
    SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
1,704✔
846
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, i);
1,704✔
847

848
    pSchema->bytes = htonl(pColInfo->info.bytes);
1,704✔
849
    pSchema->colId = htons(pColInfo->info.colId);
1,704✔
850
    pSchema->type = pColInfo->info.type;
1,704✔
851

852
    pStart += sizeof(SSysTableSchema);
1,704✔
853
  }
854

855
  int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, numOfCols);
284✔
856
  if (len < 0) {
284!
857
    dError("failed to retrieve data since %s", tstrerror(code));
×
858
    blockDataDestroy(pBlock);
×
859
    rpcFreeCont(pRsp);
×
860
    return terrno;
×
861
  }
862

863
  pRsp->numOfRows = htonl(pBlock->info.rows);
284✔
864
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
284✔
865
  pRsp->completed = 1;
284✔
866
  pMsg->info.rsp = pRsp;
284✔
867
  pMsg->info.rspLen = size;
284✔
868
  dDebug("dnode variables retrieve completed");
284!
869

870
  blockDataDestroy(pBlock);
284✔
871
  return TSDB_CODE_SUCCESS;
284✔
872
}
873

874
int32_t dmProcessStreamHbRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
34,264✔
875
  SMStreamHbRspMsg rsp = {0};
34,264✔
876
  int32_t          code = 0;
34,264✔
877
  SDecoder         decoder;
878
  char*            msg = POINTER_SHIFT(pMsg->pCont, sizeof(SStreamMsgGrpHeader));
34,264✔
879
  int32_t          len = pMsg->contLen - sizeof(SStreamMsgGrpHeader);
34,264✔
880
  int64_t          currTs = taosGetTimestampMs();
34,264✔
881

882
  if (pMsg->code) {
34,264✔
883
    return streamHbHandleRspErr(pMsg->code, currTs);
463✔
884
  }
885

886
  tDecoderInit(&decoder, (uint8_t*)msg, len);
33,801✔
887
  code = tDecodeStreamHbRsp(&decoder, &rsp);
33,801✔
888
  if (code < 0) {
33,801!
889
    code = TSDB_CODE_INVALID_MSG;
×
890
    tDeepFreeSMStreamHbRspMsg(&rsp);
×
891
    tDecoderClear(&decoder);
×
892
    dError("fail to decode stream hb rsp msg, error:%s", tstrerror(code));
×
893
    return streamHbHandleRspErr(code, currTs);
×
894
  }
895

896
  tDecoderClear(&decoder);
33,801✔
897

898
  return streamHbProcessRspMsg(&rsp);
33,801✔
899
}
900

901

902
SArray *dmGetMsgHandles() {
2,382✔
903
  int32_t code = -1;
2,382✔
904
  SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle));
2,382✔
905
  if (pArray == NULL) {
2,382!
906
    return NULL;
×
907
  }
908

909
  // Requests handled by DNODE
910
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
911
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
912
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_QNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
913
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_QNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
914
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_SNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
915
  if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_SNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
916
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_SNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
917
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_BNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
918
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_BNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
919
  if (dmSetMgmtHandle(pArray, TDMT_DND_CONFIG_DNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
920
  if (dmSetMgmtHandle(pArray, TDMT_DND_SERVER_STATUS, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
921
  if (dmSetMgmtHandle(pArray, TDMT_DND_SYSTABLE_RETRIEVE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
922
  if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_MNODE_TYPE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
923
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_ENCRYPT_KEY, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
924
  if (dmSetMgmtHandle(pArray, TDMT_MND_STREAM_HEARTBEAT_RSP, dmPutMsgToStreamMgmtQueue, 0) == NULL) goto _OVER;
2,382!
925

926
  // Requests handled by MNODE
927
  if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
928
  if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT_NOTIFY, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
929
  if (dmSetMgmtHandle(pArray, TDMT_MND_AUTH_RSP, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
2,382!
930

931
  code = 0;
2,382✔
932

933
_OVER:
2,382✔
934
  if (code != 0) {
2,382!
935
    taosArrayDestroy(pArray);
×
936
    return NULL;
×
937
  } else {
938
    return pArray;
2,382✔
939
  }
940
}
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