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

taosdata / TDengine / #4829

30 Oct 2025 09:25AM UTC coverage: 49.734% (-11.3%) from 61.071%
#4829

push

travis-ci

web-flow
Merge pull request #33435 from taosdata/3.0

merge 3.0

123072 of 323930 branches covered (37.99%)

Branch coverage included in aggregate %.

7 of 25 new or added lines in 3 files covered. (28.0%)

35232 existing lines in 327 files now uncovered.

172062 of 269495 relevant lines covered (63.85%)

70709785.06 hits per line

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

51.82
/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) {
483,036✔
33
  int32_t code = 0;
483,036✔
34
  if (pMgmt->pData->dnodeId == 0 || pMgmt->pData->clusterId == 0) {
483,036✔
35
    dInfo("set local info, dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId);
104,546!
36
    (void)taosThreadRwlockWrlock(&pMgmt->pData->lock);
104,546✔
37
    pMgmt->pData->dnodeId = pCfg->dnodeId;
104,546✔
38
    pMgmt->pData->clusterId = pCfg->clusterId;
104,546✔
39
    monSetDnodeId(pCfg->dnodeId);
104,546✔
40
    auditSetDnodeId(pCfg->dnodeId);
104,546✔
41
    code = dmWriteEps(pMgmt->pData);
104,546✔
42
    if (code != 0) {
104,546✔
43
      dInfo("failed to set local info, dnodeId:%d clusterId:0x%" PRIx64 " reason:%s", pCfg->dnodeId, pCfg->clusterId,
1,703!
44
            tstrerror(code));
45
    }
46
    (void)taosThreadRwlockUnlock(&pMgmt->pData->lock);
104,546✔
47
  }
48
}
483,036✔
49

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

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

UNCOV
78
  SRpcMsg rpcMsg = {.pCont = pHead,
×
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};
UNCOV
86
  SEpSet  epset = {0};
×
87

UNCOV
88
  (void)dmGetMnodeEpSet(pMgmt->pData, &epset);
×
89

UNCOV
90
  code = rpcSendRequest(pMgmt->msgCb.clientRpc, &epset, &rpcMsg, NULL);
×
UNCOV
91
  if (code != 0) {
×
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) {
530,185✔
97
  int32_t code = 0;
530,185✔
98
  int64_t oldVer = taosAnalyGetVersion();
530,185✔
99
  if (oldVer == newVer) return;
530,185!
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) {
8,084,193✔
137
  const STraceId *trace = &pRsp->info.traceId;
8,084,193✔
138
  dGTrace("status rsp received from mnode, statusSeq:%d code:0x%x", pMgmt->statusSeq, pRsp->code);
8,084,193!
139

140
  if (pRsp->code != 0) {
8,084,193!
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};
8,084,193✔
153
    if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
8,614,378!
154
        tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) {
530,185✔
155
      if (pMgmt->pData->dnodeVer != statusRsp.dnodeVer) {
530,185✔
156
        dGInfo("status rsp received from mnode, statusSeq:%d:%d dnodeVer:%" PRId64 ":%" PRId64, pMgmt->statusSeq,
483,036!
157
               statusRsp.statusSeq, pMgmt->pData->dnodeVer, statusRsp.dnodeVer);
158
        pMgmt->pData->dnodeVer = statusRsp.dnodeVer;
483,036✔
159
        dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg);
483,036✔
160
        dmUpdateEps(pMgmt->pData, statusRsp.pDnodeEps);
483,036✔
161
      }
162
      dmMayShouldUpdateIpWhiteList(pMgmt, statusRsp.ipWhiteVer);
530,185✔
163
      dmMayShouldUpdateAnalyticsFunc(pMgmt, statusRsp.analVer);
530,185✔
164
    }
165
    tFreeSStatusRsp(&statusRsp);
8,084,193✔
166
  }
167
  rpcFreeCont(pRsp->pCont);
8,084,193✔
168
}
8,084,193✔
169

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

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

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

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

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

222
  req.pVloads = tsVinfo.pVloads;
8,091,892✔
223
  tsVinfo.pVloads = NULL;
8,091,892✔
224

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

228
  if (taosThreadMutexUnlock(&pMgmt->pData->statusInfolock) != 0) {
8,091,892!
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);
8,091,892✔
234
  (*pMgmt->getQnodeLoadsFp)(&req.qload);
8,091,892✔
235

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

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

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

255
  SRpcMsg rpcMsg = {.pCont = pHead,
8,091,892✔
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};
8,091,892✔
264

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

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

271
  if (dDebugFlag & DEBUG_TRACE) {
8,091,892✔
272
    char tbuf[512];
158,500✔
273
    dmEpSetToStr(tbuf, sizeof(tbuf), &epSet);
158,500✔
274
    dTrace("send status req to mnode, begin to send rpc msg, statusSeq:%d to %s", pMgmt->statusSeq, tbuf);
158,500!
275
  }
276
  code = rpcSendRecvWithTimeout(pMgmt->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, &epUpdated, tsStatusSRTimeoutMs);
8,091,892✔
277
  if (code != 0) {
8,091,892✔
278
    dError("failed to SendRecv status req with timeout %d since %s", tsStatusSRTimeoutMs, tstrerror(code));
7,699!
279
    if (code == TSDB_CODE_TIMEOUT_ERROR) {
7,699!
280
      dmRotateMnodeEpSet(pMgmt->pData);
7,699✔
281
      char tbuf[512];
7,699✔
282
      dmEpSetToStr(tbuf, sizeof(tbuf), &epSet);
7,699✔
283
      dInfo("Rotate mnode ep set since failed to SendRecv status req %s, epSet:%s, inUse:%d", tstrerror(rpcRsp.code),
7,699!
284
            tbuf, epSet.inUse);
285
    }
286
    return;
7,699✔
287
  }
288

289
  if (rpcRsp.code != 0) {
8,084,193!
290
    dmRotateMnodeEpSet(pMgmt->pData);
×
291
    char tbuf[512];
×
292
    dmEpSetToStr(tbuf, sizeof(tbuf), &epSet);
×
293
    dInfo("Rotate mnode ep set since failed to SendRecv status req %s, epSet:%s, inUse:%d", tstrerror(rpcRsp.code),
×
294
          tbuf, epSet.inUse);
295
  } else {
296
    if (epUpdated == 1) {
8,084,193✔
297
      dmSetMnodeEpSet(pMgmt->pData, &epSet);
81,473✔
298
    }
299
  }
300
  dmProcessStatusRsp(pMgmt, &rpcRsp);
8,084,193✔
301
}
302

303
static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
140,100✔
304
  const STraceId *trace = &pRsp->info.traceId;
140,100✔
305
  int32_t         code = 0;
140,100✔
306
  SConfigRsp      configRsp = {0};
140,100✔
307
  bool            needStop = false;
140,100✔
308

309
  if (pRsp->code != 0) {
140,100!
310
    if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->pData->dropped && pMgmt->pData->dnodeId > 0) {
×
311
      dGInfo("dnode:%d, set to dropped since not exist in mnode", pMgmt->pData->dnodeId);
×
312
      pMgmt->pData->dropped = 1;
×
313
      if (dmWriteEps(pMgmt->pData) != 0) {
×
314
        dError("failed to write dnode file");
×
315
      }
316
      dInfo("dnode will exit since it is in the dropped state");
×
317
      (void)raise(SIGINT);
×
318
    }
319
  } else {
320
    bool needUpdate = false;
140,100✔
321
    if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
280,200!
322
        tDeserializeSConfigRsp(pRsp->pCont, pRsp->contLen, &configRsp) == 0) {
140,100✔
323
      // Try to use cfg from mnode sdb.
324
      if (!configRsp.isVersionVerified) {
140,100✔
325
        uInfo("config version not verified, update config");
104,546!
326
        needUpdate = true;
104,546✔
327
        code = taosPersistGlobalConfig(configRsp.array, pMgmt->path, configRsp.cver);
104,546✔
328
        if (code != TSDB_CODE_SUCCESS) {
104,546!
UNCOV
329
          dError("failed to persist global config since %s", tstrerror(code));
×
UNCOV
330
          goto _exit;
×
331
        }
332
      }
333
    }
334
    if (needUpdate) {
140,100✔
335
      code = cfgUpdateFromArray(tsCfg, configRsp.array);
104,546✔
336
      if (code != TSDB_CODE_SUCCESS) {
104,546!
337
        dError("failed to update config since %s", tstrerror(code));
×
338
        goto _exit;
×
339
      }
340
      code = setAllConfigs(tsCfg);
104,546✔
341
      if (code != TSDB_CODE_SUCCESS) {
104,546!
UNCOV
342
        dError("failed to set all configs since %s", tstrerror(code));
×
UNCOV
343
        goto _exit;
×
344
      }
345
    }
346
    code = taosPersistLocalConfig(pMgmt->path);
140,100✔
347
    if (code != TSDB_CODE_SUCCESS) {
140,100!
348
      dError("failed to persist local config since %s", tstrerror(code));
×
349
    }
350
    tsConfigInited = 1;
140,100✔
351
  }
352
_exit:
140,100✔
353
  tFreeSConfigRsp(&configRsp);
140,100✔
354
  rpcFreeCont(pRsp->pCont);
140,100✔
355
  if (needStop) {
140,100!
356
    dmStop();
×
357
  }
358
}
140,100✔
359

360
void dmSendConfigReq(SDnodeMgmt *pMgmt) {
141,133✔
361
  int32_t    code = 0;
141,133✔
362
  SConfigReq req = {0};
141,133✔
363

364
  req.cver = tsdmConfigVersion;
141,133✔
365
  req.forceReadConfig = tsForceReadConfig;
141,133✔
366
  req.array = taosGetGlobalCfg(tsCfg);
141,133✔
367
  dDebug("send config req to mnode, configVersion:%d", req.cver);
141,133✔
368

369
  int32_t contLen = tSerializeSConfigReq(NULL, 0, &req);
141,133✔
370
  if (contLen < 0) {
141,133!
371
    dError("failed to serialize status req since %s", tstrerror(contLen));
×
372
    return;
×
373
  }
374

375
  void *pHead = rpcMallocCont(contLen);
141,133✔
376
  if (pHead == NULL) {
141,133!
377
    dError("failed to malloc cont since %s", tstrerror(contLen));
×
378
    return;
×
379
  }
380
  contLen = tSerializeSConfigReq(pHead, contLen, &req);
141,133✔
381
  if (contLen < 0) {
141,133!
382
    rpcFreeCont(pHead);
×
383
    dError("failed to serialize status req since %s", tstrerror(contLen));
×
384
    return;
×
385
  }
386

387
  SRpcMsg rpcMsg = {.pCont = pHead,
141,133✔
388
                    .contLen = contLen,
389
                    .msgType = TDMT_MND_CONFIG,
390
                    .info.ahandle = 0,
391
                    .info.notFreeAhandle = 1,
392
                    .info.refId = 0,
393
                    .info.noResp = 0,
394
                    .info.handle = 0};
395
  SRpcMsg rpcRsp = {0};
141,133✔
396

397
  SEpSet epSet = {0};
141,133✔
398
  int8_t epUpdated = 0;
141,133✔
399
  (void)dmGetMnodeEpSet(pMgmt->pData, &epSet);
141,133✔
400

401
  dDebug("send config req to mnode, configSeq:%d, begin to send rpc msg", pMgmt->statusSeq);
141,133✔
402
  code = rpcSendRecvWithTimeout(pMgmt->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, &epUpdated, tsStatusSRTimeoutMs);
141,133✔
403
  if (code != 0) {
141,133✔
404
    dError("failed to SendRecv config req with timeout %d since %s", tsStatusSRTimeoutMs, tstrerror(code));
1,033!
405
    return;
1,033✔
406
  }
407
  if (rpcRsp.code != 0) {
140,100!
408
    dError("failed to send config req since %s", tstrerror(rpcRsp.code));
×
409
    return;
×
410
  }
411
  dmProcessConfigRsp(pMgmt, &rpcRsp);
140,100✔
412
}
413

414
void dmUpdateStatusInfo(SDnodeMgmt *pMgmt) {
8,203,900✔
415
  dDebug("begin to get dnode info");
8,203,900✔
416
  SDnodeData dnodeData = {0};
8,203,900✔
417
  (void)taosThreadRwlockRdlock(&pMgmt->pData->lock);
8,203,900✔
418
  dnodeData.dnodeVer = pMgmt->pData->dnodeVer;
8,203,900✔
419
  dnodeData.dnodeId = pMgmt->pData->dnodeId;
8,203,900✔
420
  dnodeData.clusterId = pMgmt->pData->clusterId;
8,203,900✔
421
  dnodeData.rebootTime = pMgmt->pData->rebootTime;
8,203,900✔
422
  dnodeData.updateTime = pMgmt->pData->updateTime;
8,203,900✔
423
  tstrncpy(dnodeData.machineId, pMgmt->pData->machineId, TSDB_MACHINE_ID_LEN + 1);
8,203,900!
424
  (void)taosThreadRwlockUnlock(&pMgmt->pData->lock);
8,203,900✔
425

426
  dDebug("begin to get vnode loads");
8,203,900✔
427
  SMonVloadInfo vinfo = {0};
8,203,900✔
428
  (*pMgmt->getVnodeLoadsFp)(&vinfo);  // dmGetVnodeLoads
8,203,900✔
429

430
  dDebug("begin to get mnode loads");
8,203,900✔
431
  SMonMloadInfo minfo = {0};
8,203,900✔
432
  (*pMgmt->getMnodeLoadsFp)(&minfo);  // dmGetMnodeLoads
8,203,900✔
433

434
  dDebug("begin to lock status info");
8,203,900✔
435
  if (taosThreadMutexLock(&pMgmt->pData->statusInfolock) != 0) {
8,203,900!
436
    dError("failed to lock status info lock");
×
437
    return;
×
438
  }
439
  tsDnodeData.dnodeVer = dnodeData.dnodeVer;
8,203,900✔
440
  tsDnodeData.dnodeId = dnodeData.dnodeId;
8,203,900✔
441
  tsDnodeData.clusterId = dnodeData.clusterId;
8,203,900✔
442
  tsDnodeData.rebootTime = dnodeData.rebootTime;
8,203,900✔
443
  tsDnodeData.updateTime = dnodeData.updateTime;
8,203,900✔
444
  tstrncpy(tsDnodeData.machineId, dnodeData.machineId, TSDB_MACHINE_ID_LEN + 1);
8,203,900!
445

446
  if (tsVinfo.pVloads == NULL) {
8,203,900✔
447
    tsVinfo.pVloads = vinfo.pVloads;
7,961,901✔
448
    vinfo.pVloads = NULL;
7,961,901✔
449
  } else {
450
    taosArrayDestroy(vinfo.pVloads);
241,999✔
451
    vinfo.pVloads = NULL;
241,999✔
452
  }
453

454
  tsMLoad = minfo.load;
8,203,900✔
455

456
  if (taosThreadMutexUnlock(&pMgmt->pData->statusInfolock) != 0) {
8,203,900!
457
    dError("failed to unlock status info lock");
×
458
    return;
×
459
  }
460
}
461

462
void dmSendNotifyReq(SDnodeMgmt *pMgmt, SNotifyReq *pReq) {
×
463
  int32_t contLen = tSerializeSNotifyReq(NULL, 0, pReq);
×
464
  if (contLen < 0) {
×
465
    dError("failed to serialize notify req since %s", tstrerror(contLen));
×
466
    return;
×
467
  }
468
  void *pHead = rpcMallocCont(contLen);
×
469
  contLen = tSerializeSNotifyReq(pHead, contLen, pReq);
×
470
  if (contLen < 0) {
×
471
    rpcFreeCont(pHead);
×
472
    dError("failed to serialize notify req since %s", tstrerror(contLen));
×
473
    return;
×
474
  }
475

476
  SRpcMsg rpcMsg = {.pCont = pHead,
×
477
                    .contLen = contLen,
478
                    .msgType = TDMT_MND_NOTIFY,
479
                    .info.ahandle = 0,
480
                    .info.notFreeAhandle = 1,
481
                    .info.refId = 0,
482
                    .info.noResp = 1,
483
                    .info.handle = 0};
484

485
  SEpSet epSet = {0};
×
486
  dmGetMnodeEpSet(pMgmt->pData, &epSet);
×
487
  if (rpcSendRequest(pMgmt->msgCb.clientRpc, &epSet, &rpcMsg, NULL) != 0) {
×
488
    dError("failed to send notify req");
×
489
  }
490
}
491

492
int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
×
493
  dError("auth rsp is received, but not supported yet");
×
494
  return 0;
×
495
}
496

497
int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
×
498
  dError("grant rsp is received, but not supported yet");
×
499
  return 0;
×
500
}
501

502
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
10,961✔
503
  int32_t       code = 0;
10,961✔
504
  SDCfgDnodeReq cfgReq = {0};
10,961✔
505
  SConfig      *pCfg = taosGetCfg();
10,961✔
506
  SConfigItem  *pItem = NULL;
10,961✔
507

508
  if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
10,961!
509
    return TSDB_CODE_INVALID_MSG;
×
510
  }
511
  if (strcasecmp(cfgReq.config, "dataDir") == 0) {
10,961✔
512
    return taosUpdateTfsItemDisable(pCfg, cfgReq.value, pMgmt->pTfs);
948✔
513
  }
514

515
  dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
10,013!
516

517
  code = cfgGetAndSetItem(pCfg, &pItem, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_SERVER_CMD, true);
10,013✔
518
  if (code != 0) {
10,013!
UNCOV
519
    if (strncasecmp(cfgReq.config, "resetlog", strlen("resetlog")) == 0) {
×
UNCOV
520
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, cfgReq.config, true));
×
UNCOV
521
      return TSDB_CODE_SUCCESS;
×
522
    } else {
523
      return code;
×
524
    }
525
  }
526
  if (pItem == NULL) {
10,013!
527
    return TSDB_CODE_CFG_NOT_FOUND;
×
528
  }
529

530
  if (taosStrncasecmp(cfgReq.config, "syncTimeout", 128) == 0) {
10,013!
531
    char value[10] = {0};
×
532
    if (sscanf(cfgReq.value, "%d", &tsSyncTimeout) != 1) {
×
533
      tsSyncTimeout = 0;
×
534
    }
535

536
    if (tsSyncTimeout > 0) {
×
537
      SConfigItem *pItemTmp = NULL;
×
538
      char         tmp[10] = {0};
×
539

540
      sprintf(tmp, "%d", tsSyncTimeout);
×
541
      TAOS_CHECK_RETURN(
×
542
          cfgGetAndSetItem(pCfg, &pItemTmp, "arbSetAssignedTimeoutMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
543
      if (pItemTmp == NULL) {
×
544
        return TSDB_CODE_CFG_NOT_FOUND;
×
545
      }
546

547
      sprintf(tmp, "%d", tsSyncTimeout / 4);
×
548
      TAOS_CHECK_RETURN(
×
549
          cfgGetAndSetItem(pCfg, &pItemTmp, "arbHeartBeatIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
550
      if (pItemTmp == NULL) {
×
551
        return TSDB_CODE_CFG_NOT_FOUND;
×
552
      }
553
      TAOS_CHECK_RETURN(
×
554
          cfgGetAndSetItem(pCfg, &pItemTmp, "arbCheckSyncIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
555
      if (pItemTmp == NULL) {
×
556
        return TSDB_CODE_CFG_NOT_FOUND;
×
557
      }
558

559
      sprintf(tmp, "%d", (tsSyncTimeout - tsSyncTimeout / 4) / 2);
×
560
      TAOS_CHECK_RETURN(
×
561
          cfgGetAndSetItem(pCfg, &pItemTmp, "syncVnodeElectIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
562
      if (pItemTmp == NULL) {
×
563
        return TSDB_CODE_CFG_NOT_FOUND;
×
564
      }
565
      TAOS_CHECK_RETURN(
×
566
          cfgGetAndSetItem(pCfg, &pItemTmp, "syncMnodeElectIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
567
      if (pItemTmp == NULL) {
×
568
        return TSDB_CODE_CFG_NOT_FOUND;
×
569
      }
570
      TAOS_CHECK_RETURN(cfgGetAndSetItem(pCfg, &pItemTmp, "statusTimeoutMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
×
571
      if (pItemTmp == NULL) {
×
572
        return TSDB_CODE_CFG_NOT_FOUND;
×
573
      }
574

575
      sprintf(tmp, "%d", (tsSyncTimeout - tsSyncTimeout / 4) / 4);
×
576
      TAOS_CHECK_RETURN(cfgGetAndSetItem(pCfg, &pItemTmp, "statusSRTimeoutMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
×
577
      if (pItemTmp == NULL) {
×
578
        return TSDB_CODE_CFG_NOT_FOUND;
×
579
      }
580

581
      sprintf(tmp, "%d", (tsSyncTimeout - tsSyncTimeout / 4) / 8);
×
582
      TAOS_CHECK_RETURN(
×
583
          cfgGetAndSetItem(pCfg, &pItemTmp, "syncVnodeHeartbeatIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
584
      if (pItemTmp == NULL) {
×
585
        return TSDB_CODE_CFG_NOT_FOUND;
×
586
      }
587
      TAOS_CHECK_RETURN(
×
588
          cfgGetAndSetItem(pCfg, &pItemTmp, "syncMnodeHeartbeatIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
589
      if (pItemTmp == NULL) {
×
590
        return TSDB_CODE_CFG_NOT_FOUND;
×
591
      }
592
      TAOS_CHECK_RETURN(cfgGetAndSetItem(pCfg, &pItemTmp, "statusIntervalMs", tmp, CFG_STYPE_ALTER_SERVER_CMD, true));
×
593
      if (pItemTmp == NULL) {
×
594
        return TSDB_CODE_CFG_NOT_FOUND;
×
595
      }
596

597
      dInfo("change syncTimeout, GetAndSetItem, option:%s, value:%s, tsSyncTimeout:%d", cfgReq.config, cfgReq.value,
×
598
            tsSyncTimeout);
599
    }
600
  }
601

602
  if (!isConifgItemLazyMode(pItem)) {
10,013✔
603
    TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, cfgReq.config, true));
9,734!
604

605
    if (taosStrncasecmp(cfgReq.config, "syncTimeout", 128) == 0) {
9,734!
606
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "arbSetAssignedTimeoutMs", true));
×
607
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "arbHeartBeatIntervalMs", true));
×
608
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "arbCheckSyncIntervalMs", true));
×
609

610
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "syncVnodeElectIntervalMs", true));
×
611
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "syncMnodeElectIntervalMs", true));
×
612
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "syncVnodeHeartbeatIntervalMs", true));
×
613
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "syncMnodeHeartbeatIntervalMs", true));
×
614

615
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "statusTimeoutMs", true));
×
616
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "statusSRTimeoutMs", true));
×
617
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, "statusIntervalMs", true));
×
618

619
      dInfo("change syncTimeout, DynamicOptions, option:%s, value:%s, tsSyncTimeout:%d", cfgReq.config, cfgReq.value,
×
620
            tsSyncTimeout);
621
    }
622
  }
623

624
  if (pItem->category == CFG_CATEGORY_GLOBAL) {
10,013✔
625
    code = taosPersistGlobalConfig(taosGetGlobalCfg(pCfg), pMgmt->path, tsdmConfigVersion);
839✔
626
    if (code != TSDB_CODE_SUCCESS) {
839!
627
      dError("failed to persist global config since %s", tstrerror(code));
×
628
    }
629
  } else {
630
    code = taosPersistLocalConfig(pMgmt->path);
9,174✔
631
    if (code != TSDB_CODE_SUCCESS) {
9,174!
632
      dError("failed to persist local config since %s", tstrerror(code));
×
633
    }
634
  }
635

636
  if (taosStrncasecmp(cfgReq.config, "syncTimeout", 128) == 0) {
10,013!
637
    dInfo("finished change syncTimeout, option:%s, value:%s", cfgReq.config, cfgReq.value);
×
638

639
    (*pMgmt->setMnodeSyncTimeoutFp)();
×
640
    (*pMgmt->setVnodeSyncTimeoutFp)();
×
641
  }
642

643
  if (taosStrncasecmp(cfgReq.config, "syncVnodeElectIntervalMs", 128) == 0 ||
10,013!
644
      taosStrncasecmp(cfgReq.config, "syncVnodeHeartbeatIntervalMs", 128) == 0) {
10,013!
645
    (*pMgmt->setVnodeSyncTimeoutFp)();
×
646
  }
647

648
  if (taosStrncasecmp(cfgReq.config, "syncMnodeElectIntervalMs", 128) == 0 ||
10,013!
649
      taosStrncasecmp(cfgReq.config, "syncMnodeHeartbeatIntervalMs", 128) == 0) {
10,013!
650
    (*pMgmt->setMnodeSyncTimeoutFp)();
×
651
  }
652

653
  if (cfgReq.version > 0) {
10,013✔
654
    tsdmConfigVersion = cfgReq.version;
839✔
655
  }
656
  return code;
10,013✔
657
}
658

659
int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
1,403✔
660
#ifdef TD_ENTERPRISE
661
  int32_t       code = 0;
1,403✔
662
  SDCfgDnodeReq cfgReq = {0};
1,403✔
663
  if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
1,403!
664
    code = TSDB_CODE_INVALID_MSG;
×
665
    goto _exit;
×
666
  }
667

668
  code = dmUpdateEncryptKey(cfgReq.value, true);
1,403✔
669
  if (code == 0) {
1,403!
670
    tsEncryptionKeyChksum = taosCalcChecksum(0, cfgReq.value, strlen(cfgReq.value));
1,403✔
671
    tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
1,403✔
672
    tstrncpy(tsEncryptKey, cfgReq.value, ENCRYPT_KEY_LEN + 1);
1,403!
673
  }
674

675
_exit:
1,403✔
676
  pMsg->code = code;
1,403✔
677
  pMsg->info.rsp = NULL;
1,403✔
678
  pMsg->info.rspLen = 0;
1,403✔
679
  return code;
1,403✔
680
#else
681
  return 0;
682
#endif
683
}
684

685
static void dmGetServerRunStatus(SDnodeMgmt *pMgmt, SServerStatusRsp *pStatus) {
462✔
686
  pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_OK;
462✔
687
  pStatus->details[0] = 0;
462✔
688

689
  SMonMloadInfo minfo = {0};
462✔
690
  (*pMgmt->getMnodeLoadsFp)(&minfo);
462✔
691
  if (minfo.isMnode &&
462!
692
      (minfo.load.syncState == TAOS_SYNC_STATE_ERROR || minfo.load.syncState == TAOS_SYNC_STATE_OFFLINE)) {
462!
693
    pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_DEGRADED;
×
694
    snprintf(pStatus->details, sizeof(pStatus->details), "mnode sync state is %s", syncStr(minfo.load.syncState));
×
695
    return;
×
696
  }
697

698
  SMonVloadInfo vinfo = {0};
462✔
699
  (*pMgmt->getVnodeLoadsFp)(&vinfo);
462✔
700
  for (int32_t i = 0; i < taosArrayGetSize(vinfo.pVloads); ++i) {
1,386✔
701
    SVnodeLoad *pLoad = taosArrayGet(vinfo.pVloads, i);
924✔
702
    if (pLoad->syncState == TAOS_SYNC_STATE_ERROR || pLoad->syncState == TAOS_SYNC_STATE_OFFLINE) {
924!
703
      pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_DEGRADED;
×
704
      snprintf(pStatus->details, sizeof(pStatus->details), "vnode:%d sync state is %s", pLoad->vgId,
×
705
               syncStr(pLoad->syncState));
×
706
      break;
×
707
    }
708
  }
709

710
  taosArrayDestroy(vinfo.pVloads);
462✔
711
}
712

713
int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
462✔
714
  int32_t code = 0;
462✔
715
  dDebug("server run status req is received");
462!
716
  SServerStatusRsp statusRsp = {0};
462✔
717
  dmGetServerRunStatus(pMgmt, &statusRsp);
462✔
718

719
  pMsg->info.rsp = NULL;
462✔
720
  pMsg->info.rspLen = 0;
462✔
721

722
  SRpcMsg rspMsg = {.info = pMsg->info};
462✔
723
  int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
462✔
724
  if (rspLen < 0) {
462!
725
    return TSDB_CODE_OUT_OF_MEMORY;
×
726
    // rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
727
    // return rspMsg.code;
728
  }
729

730
  void *pRsp = rpcMallocCont(rspLen);
462✔
731
  if (pRsp == NULL) {
462!
732
    return terrno;
×
733
    // rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
734
    // return rspMsg.code;
735
  }
736

737
  rspLen = tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
462✔
738
  if (rspLen < 0) {
462!
739
    return TSDB_CODE_INVALID_MSG;
×
740
  }
741

742
  pMsg->info.rsp = pRsp;
462✔
743
  pMsg->info.rspLen = rspLen;
462✔
744
  return 0;
462✔
745
}
746

747
int32_t dmBuildVariablesBlock(SSDataBlock **ppBlock) {
6,103✔
748
  int32_t code = 0;
6,103✔
749

750
  SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
6,103!
751
  if (pBlock == NULL) {
6,103!
752
    return terrno;
×
753
  }
754

755
  size_t size = 0;
6,103✔
756

757
  const SSysTableMeta *pMeta = NULL;
6,103✔
758
  getInfosDbMeta(&pMeta, &size);
6,103✔
759

760
  int32_t index = 0;
6,103✔
761
  for (int32_t i = 0; i < size; ++i) {
122,060!
762
    if (strcmp(pMeta[i].name, TSDB_INS_TABLE_DNODE_VARIABLES) == 0) {
122,060!
763
      index = i;
6,103✔
764
      break;
6,103✔
765
    }
766
  }
767

768
  pBlock->pDataBlock = taosArrayInit(pMeta[index].colNum, sizeof(SColumnInfoData));
6,103✔
769
  if (pBlock->pDataBlock == NULL) {
6,103!
770
    code = terrno;
×
771
    goto _exit;
×
772
  }
773

774
  for (int32_t i = 0; i < pMeta[index].colNum; ++i) {
42,721✔
775
    SColumnInfoData colInfoData = {0};
36,618✔
776
    colInfoData.info.colId = i + 1;
36,618✔
777
    colInfoData.info.type = pMeta[index].schema[i].type;
36,618✔
778
    colInfoData.info.bytes = pMeta[index].schema[i].bytes;
36,618✔
779
    if (taosArrayPush(pBlock->pDataBlock, &colInfoData) == NULL) {
73,236!
780
      code = terrno;
×
781
      goto _exit;
×
782
    }
783
  }
784

785
  pBlock->info.hasVarCol = true;
6,103✔
786
_exit:
6,103✔
787
  if (code != 0) {
6,103!
788
    blockDataDestroy(pBlock);
×
789
  } else {
790
    *ppBlock = pBlock;
6,103✔
791
  }
792
  return code;
6,103✔
793
}
794

795
int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) {
6,103✔
796
  int32_t code = dumpConfToDataBlock(pBlock, 1, NULL);
6,103✔
797
  if (code != 0) {
6,103!
798
    return code;
×
799
  }
800

801
  SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
6,103✔
802
  if (pColInfo == NULL) {
6,103!
803
    return TSDB_CODE_OUT_OF_RANGE;
×
804
  }
805

806
  return colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, 1, false);
6,103✔
807
}
808

809
int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
6,103✔
810
  int32_t           size = 0;
6,103✔
811
  int32_t           rowsRead = 0;
6,103✔
812
  int32_t           code = 0;
6,103✔
813
  SRetrieveTableReq retrieveReq = {0};
6,103✔
814
  if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
6,103!
815
    return TSDB_CODE_INVALID_MSG;
×
816
  }
817
  dInfo("retrieve table:%s, user:%s, compactId:%" PRId64, retrieveReq.tb, retrieveReq.user, retrieveReq.compactId);
6,103!
818
#if 0
819
  if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
820
    code = TSDB_CODE_MND_NO_RIGHTS;
821
    return code;
822
  }
823
#endif
824
  if (strcasecmp(retrieveReq.tb, TSDB_INS_TABLE_DNODE_VARIABLES)) {
6,103!
825
    return TSDB_CODE_INVALID_MSG;
×
826
  }
827

828
  SSDataBlock *pBlock = NULL;
6,103✔
829
  if ((code = dmBuildVariablesBlock(&pBlock)) != 0) {
6,103!
830
    return code;
×
831
  }
832

833
  code = dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
6,103✔
834
  if (code != 0) {
6,103!
835
    blockDataDestroy(pBlock);
×
836
    return code;
×
837
  }
838

839
  size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
6,103✔
840
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
6,103✔
841
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * numOfCols + dataEncodeBufSize;
6,103✔
842

843
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
6,103✔
844
  if (pRsp == NULL) {
6,103!
845
    code = terrno;
×
846
    dError("failed to retrieve data since %s", tstrerror(code));
×
847
    blockDataDestroy(pBlock);
×
848
    return code;
×
849
  }
850

851
  char *pStart = pRsp->data;
6,103✔
852
  *(int32_t *)pStart = htonl(numOfCols);
6,103✔
853
  pStart += sizeof(int32_t);  // number of columns
6,103✔
854

855
  for (int32_t i = 0; i < numOfCols; ++i) {
42,721✔
856
    SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
36,618✔
857
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, i);
36,618✔
858

859
    pSchema->bytes = htonl(pColInfo->info.bytes);
36,618✔
860
    pSchema->colId = htons(pColInfo->info.colId);
36,618✔
861
    pSchema->type = pColInfo->info.type;
36,618✔
862

863
    pStart += sizeof(SSysTableSchema);
36,618✔
864
  }
865

866
  int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, numOfCols);
6,103✔
867
  if (len < 0) {
6,103!
868
    dError("failed to retrieve data since %s", tstrerror(code));
×
869
    blockDataDestroy(pBlock);
×
870
    rpcFreeCont(pRsp);
×
871
    return terrno;
×
872
  }
873

874
  pRsp->numOfRows = htonl(pBlock->info.rows);
6,103✔
875
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
6,103✔
876
  pRsp->completed = 1;
6,103✔
877
  pMsg->info.rsp = pRsp;
6,103✔
878
  pMsg->info.rspLen = size;
6,103✔
879
  dDebug("dnode variables retrieve completed");
6,103!
880

881
  blockDataDestroy(pBlock);
6,103✔
882
  return TSDB_CODE_SUCCESS;
6,103✔
883
}
884

885
int32_t dmProcessStreamHbRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
2,879,738✔
886
  SMStreamHbRspMsg rsp = {0};
2,879,738✔
887
  int32_t          code = 0;
2,879,738✔
888
  SDecoder         decoder;
2,879,372✔
889
  char*            msg = POINTER_SHIFT(pMsg->pCont, sizeof(SStreamMsgGrpHeader));
2,879,738✔
890
  int32_t          len = pMsg->contLen - sizeof(SStreamMsgGrpHeader);
2,879,738✔
891
  int64_t          currTs = taosGetTimestampMs();
2,879,738✔
892

893
  if (pMsg->code) {
2,879,738✔
894
    return streamHbHandleRspErr(pMsg->code, currTs);
7,758✔
895
  }
896

897
  tDecoderInit(&decoder, (uint8_t*)msg, len);
2,871,980✔
898
  code = tDecodeStreamHbRsp(&decoder, &rsp);
2,871,980✔
899
  if (code < 0) {
2,871,980!
900
    code = TSDB_CODE_INVALID_MSG;
×
901
    tDeepFreeSMStreamHbRspMsg(&rsp);
×
902
    tDecoderClear(&decoder);
×
903
    dError("fail to decode stream hb rsp msg, error:%s", tstrerror(code));
×
904
    return streamHbHandleRspErr(code, currTs);
×
905
  }
906

907
  tDecoderClear(&decoder);
2,871,980✔
908

909
  return streamHbProcessRspMsg(&rsp);
2,871,980✔
910
}
911

912

913
SArray *dmGetMsgHandles() {
140,952✔
914
  int32_t code = -1;
140,952✔
915
  SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle));
140,952✔
916
  if (pArray == NULL) {
140,952!
917
    return NULL;
×
918
  }
919

920
  // Requests handled by DNODE
921
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
922
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
923
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_QNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
924
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_QNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
925
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_SNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
926
  if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_SNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
927
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_SNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
928
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_BNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
929
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_BNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
930
  if (dmSetMgmtHandle(pArray, TDMT_DND_CONFIG_DNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
931
  if (dmSetMgmtHandle(pArray, TDMT_DND_SERVER_STATUS, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
932
  if (dmSetMgmtHandle(pArray, TDMT_DND_SYSTABLE_RETRIEVE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
933
  if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_MNODE_TYPE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
934
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_ENCRYPT_KEY, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
935
  if (dmSetMgmtHandle(pArray, TDMT_MND_STREAM_HEARTBEAT_RSP, dmPutMsgToStreamMgmtQueue, 0) == NULL) goto _OVER;
140,952!
936

937
  // Requests handled by MNODE
938
  if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
939
  if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT_NOTIFY, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
940
  if (dmSetMgmtHandle(pArray, TDMT_MND_AUTH_RSP, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
140,952!
941

942
  code = 0;
140,952✔
943

944
_OVER:
140,952✔
945
  if (code != 0) {
140,952!
946
    taosArrayDestroy(pArray);
×
947
    return NULL;
×
948
  } else {
949
    return pArray;
140,952✔
950
  }
951
}
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