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

taosdata / TDengine / #4808

16 Oct 2025 11:40AM UTC coverage: 57.938% (-0.6%) from 58.524%
#4808

push

travis-ci

web-flow
fix(tref): increase TSDB_REF_OBJECTS from 100 to 2000 for improved reference handling (#33281)

137662 of 303532 branches covered (45.35%)

Branch coverage included in aggregate %.

209234 of 295200 relevant lines covered (70.88%)

4035326.15 hits per line

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

54.74
/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) {
7,675✔
33
  int32_t code = 0;
7,675✔
34
  if (pMgmt->pData->dnodeId == 0 || pMgmt->pData->clusterId == 0) {
7,675✔
35
    dInfo("set local info, dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId);
1,376!
36
    (void)taosThreadRwlockWrlock(&pMgmt->pData->lock);
1,376✔
37
    pMgmt->pData->dnodeId = pCfg->dnodeId;
1,376✔
38
    pMgmt->pData->clusterId = pCfg->clusterId;
1,376✔
39
    monSetDnodeId(pCfg->dnodeId);
1,376✔
40
    auditSetDnodeId(pCfg->dnodeId);
1,376✔
41
    code = dmWriteEps(pMgmt->pData);
1,376✔
42
    if (code != 0) {
1,376!
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,376✔
47
  }
48
}
7,675✔
49

50
static void dmMayShouldUpdateIpWhiteList(SDnodeMgmt *pMgmt, int64_t ver) {
8,062✔
51
  int32_t code = 0;
8,062✔
52
  dDebug("ip-white-list on dnode ver: %" PRId64 ", status ver: %" PRId64, pMgmt->pData->ipWhiteVer, ver);
8,062✔
53
  if (pMgmt->pData->ipWhiteVer == ver) {
8,062✔
54
    if (ver == 0) {
8,055✔
55
      dDebug("disable ip-white-list on dnode ver: %" PRId64 ", status ver: %" PRId64, pMgmt->pData->ipWhiteVer, ver);
8,043✔
56
      if (rpcSetIpWhite(pMgmt->msgCb.serverRpc, NULL) != 0) {
8,043!
57
        dError("failed to disable ip white list on dnode");
×
58
      }
59
    }
60
    return;
8,055✔
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) {
8,062✔
97
  int32_t code = 0;
8,062✔
98
  int64_t oldVer = taosAnalyGetVersion();
8,062✔
99
  if (oldVer == newVer) return;
8,062!
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) {
85,547✔
137
  const STraceId *trace = &pRsp->info.traceId;
85,547✔
138
  dGTrace("status rsp received from mnode, statusSeq:%d code:0x%x", pMgmt->statusSeq, pRsp->code);
85,547!
139

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

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

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

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

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

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

222
  req.pVloads = tsVinfo.pVloads;
85,841✔
223
  tsVinfo.pVloads = NULL;
85,841✔
224

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

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

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

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

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

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

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

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

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

289
  if (rpcRsp.code != 0) {
85,547!
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) {
85,547✔
297
      dmSetMnodeEpSet(pMgmt->pData, &epSet);
1,288✔
298
    }
299
  }
300
  dmProcessStatusRsp(pMgmt, &rpcRsp);
85,547✔
301
}
302

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

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

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

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

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

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

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

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

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

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

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

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

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

446
  if (tsVinfo.pVloads == NULL) {
87,751✔
447
    tsVinfo.pVloads = vinfo.pVloads;
84,527✔
448
    vinfo.pVloads = NULL;
84,527✔
449
  } else {
450
    taosArrayDestroy(vinfo.pVloads);
3,224✔
451
    vinfo.pVloads = NULL;
3,224✔
452
  }
453

454
  tsMLoad = minfo.load;
87,751✔
455

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

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

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

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

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

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

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

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

653
  if (cfgReq.version > 0) {
192✔
654
    tsdmConfigVersion = cfgReq.version;
99✔
655
  }
656
  return code;
192✔
657
}
658

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

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

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

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

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

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

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

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

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

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

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

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

755
  size_t size = 0;
270✔
756

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

863
    pStart += sizeof(SSysTableSchema);
1,620✔
864
  }
865

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

881
  blockDataDestroy(pBlock);
270✔
882
  return TSDB_CODE_SUCCESS;
270✔
883
}
884

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

893
  if (pMsg->code) {
30,392✔
894
    return streamHbHandleRspErr(pMsg->code, currTs);
478✔
895
  }
896

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

909
  return streamHbProcessRspMsg(&rsp);
29,914✔
910
}
911

912

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

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

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

942
  code = 0;
1,809✔
943

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