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

taosdata / TDengine / #4856

17 Nov 2025 09:53AM UTC coverage: 64.286% (+0.2%) from 64.039%
#4856

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

218 of 311 new or added lines in 32 files covered. (70.1%)

4657 existing lines in 112 files now uncovered.

151658 of 235910 relevant lines covered (64.29%)

116320814.6 hits per line

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

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

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

64
  SRetrieveIpWhiteReq req = {.ipWhiteVer = oldVer};
1,696✔
65
  int32_t             contLen = tSerializeRetrieveIpWhite(NULL, 0, &req);
1,696✔
66
  if (contLen < 0) {
1,696✔
67
    dError("failed to serialize ip white list request since: %s", tstrerror(contLen));
×
68
    return;
×
69
  }
70
  void *pHead = rpcMallocCont(contLen);
1,696✔
71
  contLen = tSerializeRetrieveIpWhite(pHead, contLen, &req);
1,696✔
72
  if (contLen < 0) {
1,696✔
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,
1,696✔
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};
1,696✔
87

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

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

140
  if (pRsp->code != 0) {
41,466,550✔
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};
41,466,550✔
153
    if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
43,974,985✔
154
        tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) {
2,508,435✔
155
      if (pMgmt->pData->dnodeVer != statusRsp.dnodeVer) {
2,508,435✔
156
        dGInfo("status rsp received from mnode, statusSeq:%d:%d dnodeVer:%" PRId64 ":%" PRId64, pMgmt->statusSeq,
2,299,226✔
157
               statusRsp.statusSeq, pMgmt->pData->dnodeVer, statusRsp.dnodeVer);
158
        pMgmt->pData->dnodeVer = statusRsp.dnodeVer;
2,299,226✔
159
        dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg);
2,299,226✔
160
        dmUpdateEps(pMgmt->pData, statusRsp.pDnodeEps);
2,299,226✔
161
      }
162
      dmMayShouldUpdateIpWhiteList(pMgmt, statusRsp.ipWhiteVer);
2,508,435✔
163
      dmMayShouldUpdateAnalyticsFunc(pMgmt, statusRsp.analVer);
2,508,435✔
164
    }
165
    tFreeSStatusRsp(&statusRsp);
41,466,550✔
166
  }
167
  rpcFreeCont(pRsp->pCont);
41,466,550✔
168
}
41,466,550✔
169

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

176
  dTrace("send status req to mnode, begin to mgnt statusInfolock, statusSeq:%d", pMgmt->statusSeq);
41,560,350✔
177
  if (taosThreadMutexLock(&pMgmt->pData->statusInfolock) != 0) {
41,560,350✔
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);
41,560,350✔
183
  req.sver = tsVersion;
41,560,350✔
184
  req.dnodeVer = tsDnodeData.dnodeVer;
41,560,350✔
185
  req.dnodeId = tsDnodeData.dnodeId;
41,560,350✔
186
  req.clusterId = tsDnodeData.clusterId;
41,560,350✔
187
  if (req.clusterId == 0) req.dnodeId = 0;
41,560,350✔
188
  req.rebootTime = tsDnodeData.rebootTime;
41,560,350✔
189
  req.updateTime = tsDnodeData.updateTime;
41,560,350✔
190
  req.numOfCores = tsNumOfCores;
41,560,350✔
191
  req.numOfSupportVnodes = tsNumOfSupportVnodes;
41,560,350✔
192
  req.numOfDiskCfg = tsDiskCfgNum;
41,560,350✔
193
  req.memTotal = tsTotalMemoryKB * 1024;
41,560,350✔
194
  req.memAvail = req.memTotal - tsQueueMemoryAllowed - tsApplyMemoryAllowed - 16 * 1024 * 1024;
41,560,350✔
195
  tstrncpy(req.dnodeEp, tsLocalEp, TSDB_EP_LEN);
41,560,350✔
196
  tstrncpy(req.machineId, tsDnodeData.machineId, TSDB_MACHINE_ID_LEN + 1);
41,560,350✔
197

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

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

222
  req.pVloads = tsVinfo.pVloads;
41,560,350✔
223
  tsVinfo.pVloads = NULL;
41,560,350✔
224

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

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

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

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

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

255
  SRpcMsg rpcMsg = {.pCont = pHead,
41,560,350✔
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};
41,560,350✔
264

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

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

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

289
  if (rpcRsp.code != 0) {
41,466,550✔
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) {
41,466,550✔
297
      dmSetMnodeEpSet(pMgmt->pData, &epSet);
236,319✔
298
    }
299
  }
300
  dmProcessStatusRsp(pMgmt, &rpcRsp);
41,466,550✔
301
}
302

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

309
  if (pRsp->code != 0) {
649,664✔
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;
649,664✔
321
    if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
1,299,328✔
322
        tDeserializeSConfigRsp(pRsp->pCont, pRsp->contLen, &configRsp) == 0) {
649,664✔
323
      // Try to use cfg from mnode sdb.
324
      if (!configRsp.isVersionVerified) {
649,664✔
325
        uInfo("config version not verified, update config");
487,125✔
326
        needUpdate = true;
487,125✔
327
        code = taosPersistGlobalConfig(configRsp.array, pMgmt->path, configRsp.cver);
487,125✔
328
        if (code != TSDB_CODE_SUCCESS) {
487,125✔
329
          dError("failed to persist global config since %s", tstrerror(code));
×
330
          goto _exit;
×
331
        }
332
      }
333
    }
334
    if (needUpdate) {
649,664✔
335
      code = cfgUpdateFromArray(tsCfg, configRsp.array);
487,125✔
336
      if (code != TSDB_CODE_SUCCESS) {
487,125✔
337
        dError("failed to update config since %s", tstrerror(code));
×
338
        goto _exit;
×
339
      }
340
      code = setAllConfigs(tsCfg);
487,125✔
341
      if (code != TSDB_CODE_SUCCESS) {
487,125✔
342
        dError("failed to set all configs since %s", tstrerror(code));
×
343
        goto _exit;
×
344
      }
345
    }
346
    code = taosPersistLocalConfig(pMgmt->path);
649,664✔
347
    if (code != TSDB_CODE_SUCCESS) {
649,664✔
348
      dError("failed to persist local config since %s", tstrerror(code));
×
349
    }
350
    tsConfigInited = 1;
649,664✔
351
  }
352
_exit:
649,664✔
353
  tFreeSConfigRsp(&configRsp);
649,664✔
354
  rpcFreeCont(pRsp->pCont);
649,664✔
355
  if (needStop) {
649,664✔
356
    dmStop();
×
357
  }
358
}
649,664✔
359

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

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

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

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

387
  SRpcMsg rpcMsg = {.pCont = pHead,
649,664✔
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};
649,664✔
396

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

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

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

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

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

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

446
  if (tsVinfo.pVloads == NULL) {
42,189,746✔
447
    tsVinfo.pVloads = vinfo.pVloads;
41,010,865✔
448
    vinfo.pVloads = NULL;
41,010,865✔
449
  } else {
450
    taosArrayDestroy(vinfo.pVloads);
1,178,881✔
451
    vinfo.pVloads = NULL;
1,178,881✔
452
  }
453

454
  tsMLoad = minfo.load;
42,189,746✔
455

456
  if (taosThreadMutexUnlock(&pMgmt->pData->statusInfolock) != 0) {
42,189,746✔
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) {
184,166✔
503
  int32_t       code = 0;
184,166✔
504
  SDCfgDnodeReq cfgReq = {0};
184,166✔
505
  SConfig      *pCfg = taosGetCfg();
184,166✔
506
  SConfigItem  *pItem = NULL;
184,166✔
507

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

515
  dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
183,657✔
516

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

530
  if (taosStrncasecmp(cfgReq.config, "syncTimeout", 128) == 0) {
183,211✔
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)) {
183,211✔
603
    TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, cfgReq.config, true));
163,339✔
604

605
    if (taosStrncasecmp(cfgReq.config, "syncTimeout", 128) == 0) {
163,339✔
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) {
183,211✔
625
    code = taosPersistGlobalConfig(taosGetGlobalCfg(pCfg), pMgmt->path, tsdmConfigVersion);
119,879✔
626
    if (code != TSDB_CODE_SUCCESS) {
119,879✔
627
      dError("failed to persist global config since %s", tstrerror(code));
×
628
    }
629
  } else {
630
    code = taosPersistLocalConfig(pMgmt->path);
63,332✔
631
    if (code != TSDB_CODE_SUCCESS) {
63,332✔
632
      dError("failed to persist local config since %s", tstrerror(code));
×
633
    }
634
  }
635

636
  if (taosStrncasecmp(cfgReq.config, "syncTimeout", 128) == 0) {
183,211✔
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 ||
183,211✔
644
      taosStrncasecmp(cfgReq.config, "syncVnodeHeartbeatIntervalMs", 128) == 0) {
183,211✔
645
    (*pMgmt->setVnodeSyncTimeoutFp)();
×
646
  }
647

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

653
  if (cfgReq.version > 0) {
183,211✔
654
    tsdmConfigVersion = cfgReq.version;
133,967✔
655
  }
656
  return code;
183,211✔
657
}
658

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

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

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

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

689
  SMonMloadInfo minfo = {0};
993✔
690
  (*pMgmt->getMnodeLoadsFp)(&minfo);
993✔
691
  if (minfo.isMnode &&
993✔
692
      (minfo.load.syncState == TAOS_SYNC_STATE_ERROR || minfo.load.syncState == TAOS_SYNC_STATE_OFFLINE)) {
993✔
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};
993✔
699
  (*pMgmt->getVnodeLoadsFp)(&vinfo);
993✔
700
  for (int32_t i = 0; i < taosArrayGetSize(vinfo.pVloads); ++i) {
2,979✔
701
    SVnodeLoad *pLoad = taosArrayGet(vinfo.pVloads, i);
1,986✔
702
    if (pLoad->syncState == TAOS_SYNC_STATE_ERROR || pLoad->syncState == TAOS_SYNC_STATE_OFFLINE) {
1,986✔
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);
993✔
711
}
712

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

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

722
  SRpcMsg rspMsg = {.info = pMsg->info};
993✔
723
  int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
993✔
724
  if (rspLen < 0) {
993✔
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);
993✔
731
  if (pRsp == NULL) {
993✔
732
    return terrno;
×
733
    // rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
734
    // return rspMsg.code;
735
  }
736

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

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

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

750
  SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
67,694✔
751
  if (pBlock == NULL) {
67,694✔
752
    return terrno;
×
753
  }
754

755
  size_t size = 0;
67,694✔
756

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

760
  int32_t index = 0;
67,694✔
761
  for (int32_t i = 0; i < size; ++i) {
1,353,880✔
762
    if (strcmp(pMeta[i].name, TSDB_INS_TABLE_DNODE_VARIABLES) == 0) {
1,353,880✔
763
      index = i;
67,694✔
764
      break;
67,694✔
765
    }
766
  }
767

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

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

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

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

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

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

809
int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
67,694✔
810
  int32_t           size = 0;
67,694✔
811
  int32_t           rowsRead = 0;
67,694✔
812
  int32_t           code = 0;
67,694✔
813
  SRetrieveTableReq retrieveReq = {0};
67,694✔
814
  if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
67,694✔
815
    return TSDB_CODE_INVALID_MSG;
×
816
  }
817
  dInfo("retrieve table:%s, user:%s, compactId:%" PRId64, retrieveReq.tb, retrieveReq.user, retrieveReq.compactId);
67,694✔
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)) {
67,694✔
825
    return TSDB_CODE_INVALID_MSG;
×
826
  }
827

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

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

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

843
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
67,694✔
844
  if (pRsp == NULL) {
67,694✔
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;
67,694✔
852
  *(int32_t *)pStart = htonl(numOfCols);
67,694✔
853
  pStart += sizeof(int32_t);  // number of columns
67,694✔
854

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

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

863
    pStart += sizeof(SSysTableSchema);
406,164✔
864
  }
865

866
  int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, numOfCols);
67,694✔
867
  if (len < 0) {
67,694✔
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);
67,694✔
875
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
67,694✔
876
  pRsp->completed = 1;
67,694✔
877
  pMsg->info.rsp = pRsp;
67,694✔
878
  pMsg->info.rspLen = size;
67,694✔
879
  dDebug("dnode variables retrieve completed");
67,694✔
880

881
  blockDataDestroy(pBlock);
67,694✔
882
  return TSDB_CODE_SUCCESS;
67,694✔
883
}
884

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

893
  if (pMsg->code) {
14,713,144✔
894
    return streamHbHandleRspErr(pMsg->code, currTs);
195,276✔
895
  }
896

897
  tDecoderInit(&decoder, (uint8_t*)msg, len);
14,517,868✔
898
  code = tDecodeStreamHbRsp(&decoder, &rsp);
14,517,868✔
899
  if (code < 0) {
14,517,868✔
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);
14,517,868✔
908

909
  return streamHbProcessRspMsg(&rsp);
14,517,868✔
910
}
911

912

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

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

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

942
  code = 0;
655,120✔
943

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