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

taosdata / TDengine / #3610

12 Feb 2025 09:54AM UTC coverage: 54.713% (-8.4%) from 63.066%
#3610

push

travis-ci

web-flow
Merge pull request #29745 from taosdata/fix/TD33664-3.0

fix: --version show information check for 3.0

120957 of 286549 branches covered (42.21%)

Branch coverage included in aggregate %.

190849 of 283342 relevant lines covered (67.36%)

4969786.97 hits per line

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

55.63
/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

25
extern SConfig *tsCfg;
26

27
SMonVloadInfo tsVinfo = {0};
28

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

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

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

75
  SRpcMsg rpcMsg = {.pCont = pHead,
6✔
76
                    .contLen = contLen,
77
                    .msgType = TDMT_MND_RETRIEVE_IP_WHITE,
78
                    .info.ahandle = 0,
79
                    .info.notFreeAhandle = 1,
80
                    .info.refId = 0,
81
                    .info.noResp = 0,
82
                    .info.handle = 0};
83
  SEpSet  epset = {0};
6✔
84

85
  (void)dmGetMnodeEpSet(pMgmt->pData, &epset);
6✔
86

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

93
static void dmMayShouldUpdateAnalFunc(SDnodeMgmt *pMgmt, int64_t newVer) {
2,570✔
94
  int32_t code = 0;
2,570✔
95
  int64_t oldVer = taosAnalGetVersion();
2,570✔
96
  if (oldVer == newVer) return;
2,570!
97
  dDebug("analysis on dnode ver:%" PRId64 ", status ver:%" PRId64, oldVer, newVer);
×
98

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

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

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

125
  (void)dmGetMnodeEpSet(pMgmt->pData, &epset);
×
126

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

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

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

167
void dmSendStatusReq(SDnodeMgmt *pMgmt) {
66,303✔
168
  int32_t    code = 0;
66,303✔
169
  SStatusReq req = {0};
66,303✔
170

171
  dDebug("send status req to mnode, statusSeq:%d, begin to mgnt lock", pMgmt->statusSeq);
66,303✔
172
  (void)taosThreadRwlockRdlock(&pMgmt->pData->lock);
66,303✔
173
  req.sver = tsVersion;
66,303✔
174
  req.dnodeVer = pMgmt->pData->dnodeVer;
66,303✔
175
  req.dnodeId = pMgmt->pData->dnodeId;
66,303✔
176
  req.clusterId = pMgmt->pData->clusterId;
66,303✔
177
  if (req.clusterId == 0) req.dnodeId = 0;
66,303✔
178
  req.rebootTime = pMgmt->pData->rebootTime;
66,303✔
179
  req.updateTime = pMgmt->pData->updateTime;
66,303✔
180
  req.numOfCores = tsNumOfCores;
66,303✔
181
  req.numOfSupportVnodes = tsNumOfSupportVnodes;
66,303✔
182
  req.numOfDiskCfg = tsDiskCfgNum;
66,303✔
183
  req.memTotal = tsTotalMemoryKB * 1024;
66,303✔
184
  req.memAvail = req.memTotal - tsQueueMemoryAllowed - tsApplyMemoryAllowed - 16 * 1024 * 1024;
66,303✔
185
  tstrncpy(req.dnodeEp, tsLocalEp, TSDB_EP_LEN);
66,303✔
186
  tstrncpy(req.machineId, pMgmt->pData->machineId, TSDB_MACHINE_ID_LEN + 1);
66,303✔
187

188
  req.clusterCfg.statusInterval = tsStatusInterval;
66,303✔
189
  req.clusterCfg.checkTime = 0;
66,303✔
190
  req.clusterCfg.ttlChangeOnWrite = tsTtlChangeOnWrite;
66,303✔
191
  req.clusterCfg.enableWhiteList = tsEnableWhiteList ? 1 : 0;
66,303✔
192
  req.clusterCfg.encryptionKeyStat = tsEncryptionKeyStat;
66,303✔
193
  req.clusterCfg.encryptionKeyChksum = tsEncryptionKeyChksum;
66,303✔
194
  req.clusterCfg.monitorParas.tsEnableMonitor = tsEnableMonitor;
66,303✔
195
  req.clusterCfg.monitorParas.tsMonitorInterval = tsMonitorInterval;
66,303✔
196
  req.clusterCfg.monitorParas.tsSlowLogScope = tsSlowLogScope;
66,303✔
197
  req.clusterCfg.monitorParas.tsSlowLogMaxLen = tsSlowLogMaxLen;
66,303✔
198
  req.clusterCfg.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold;
66,303✔
199
  tstrncpy(req.clusterCfg.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN);
66,303✔
200
  char timestr[32] = "1970-01-01 00:00:00.00";
66,303✔
201
  if (taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, NULL) !=
66,303!
202
      0) {
203
    dError("failed to parse time since %s", tstrerror(code));
×
204
  }
205
  memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
66,303✔
206
  memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
66,303✔
207
  memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
66,303✔
208
  (void)taosThreadRwlockUnlock(&pMgmt->pData->lock);
66,303✔
209

210
  dDebug("send status req to mnode, statusSeq:%d, begin to get vnode loads", pMgmt->statusSeq);
66,303✔
211
  if (taosThreadMutexLock(&pMgmt->pData->statusInfolock) != 0) {
66,303!
212
    dError("failed to lock status info lock");
×
213
    return;
357✔
214
  }
215
  req.pVloads = tsVinfo.pVloads;
66,303✔
216
  tsVinfo.pVloads = NULL;
66,303✔
217
  if (taosThreadMutexUnlock(&pMgmt->pData->statusInfolock) != 0) {
66,303!
218
    dError("failed to unlock status info lock");
×
219
    return;
×
220
  }
221

222
  dDebug("send status req to mnode, statusSeq:%d, begin to get mnode loads", pMgmt->statusSeq);
66,303✔
223
  SMonMloadInfo minfo = {0};
66,303✔
224
  (*pMgmt->getMnodeLoadsFp)(&minfo);
66,303✔
225
  req.mload = minfo.load;
66,303✔
226

227
  dDebug("send status req to mnode, statusSeq:%d, begin to get qnode loads", pMgmt->statusSeq);
66,303✔
228
  (*pMgmt->getQnodeLoadsFp)(&req.qload);
66,303✔
229

230
  pMgmt->statusSeq++;
66,303✔
231
  req.statusSeq = pMgmt->statusSeq;
66,303✔
232
  req.ipWhiteVer = pMgmt->pData->ipWhiteVer;
66,303✔
233
  req.analVer = taosAnalGetVersion();
66,303✔
234

235
  int32_t contLen = tSerializeSStatusReq(NULL, 0, &req);
66,303✔
236
  if (contLen < 0) {
66,303!
237
    dError("failed to serialize status req since %s", tstrerror(contLen));
×
238
    return;
×
239
  }
240

241
  void *pHead = rpcMallocCont(contLen);
66,303✔
242
  contLen = tSerializeSStatusReq(pHead, contLen, &req);
66,303✔
243
  if (contLen < 0) {
66,303!
244
    rpcFreeCont(pHead);
×
245
    dError("failed to serialize status req since %s", tstrerror(contLen));
×
246
    return;
×
247
  }
248
  tFreeSStatusReq(&req);
66,303✔
249

250
  SRpcMsg rpcMsg = {.pCont = pHead,
66,303✔
251
                    .contLen = contLen,
252
                    .msgType = TDMT_MND_STATUS,
253
                    .info.ahandle = 0,
254
                    .info.notFreeAhandle = 1,
255
                    .info.refId = 0,
256
                    .info.noResp = 0,
257
                    .info.handle = 0};
258
  SRpcMsg rpcRsp = {0};
66,303✔
259

260
  dTrace("send status req to mnode, dnodeVer:%" PRId64 " statusSeq:%d", req.dnodeVer, req.statusSeq);
66,303✔
261

262
  SEpSet epSet = {0};
66,303✔
263
  int8_t epUpdated = 0;
66,303✔
264
  (void)dmGetMnodeEpSet(pMgmt->pData, &epSet);
66,303✔
265

266
  dDebug("send status req to mnode, statusSeq:%d, begin to send rpc msg", pMgmt->statusSeq);
66,303✔
267
  code =
268
      rpcSendRecvWithTimeout(pMgmt->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, &epUpdated, tsStatusInterval * 5 * 1000);
66,303✔
269
  if (code != 0) {
66,303✔
270
    dError("failed to send status req since %s", tstrerror(code));
357!
271
    return;
357✔
272
  }
273

274
  if (rpcRsp.code != 0) {
65,946!
275
    dmRotateMnodeEpSet(pMgmt->pData);
×
276
    char tbuf[512];
277
    dmEpSetToStr(tbuf, sizeof(tbuf), &epSet);
×
278
    dError("failed to send status req since %s, epSet:%s, inUse:%d", tstrerror(rpcRsp.code), tbuf, epSet.inUse);
×
279
  } else {
280
    if (epUpdated == 1) {
65,946✔
281
      dmSetMnodeEpSet(pMgmt->pData, &epSet);
263✔
282
    }
283
  }
284
  dmProcessStatusRsp(pMgmt, &rpcRsp);
65,946✔
285
}
286

287
static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
1,278✔
288
  const STraceId *trace = &pRsp->info.traceId;
1,278✔
289
  int32_t         code = 0;
1,278✔
290
  SConfigRsp      configRsp = {0};
1,278✔
291
  bool            needStop = false;
1,278✔
292

293
  if (pRsp->code != 0) {
1,278!
294
    if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->pData->dropped && pMgmt->pData->dnodeId > 0) {
×
295
      dGInfo("dnode:%d, set to dropped since not exist in mnode", pMgmt->pData->dnodeId);
×
296
      pMgmt->pData->dropped = 1;
×
297
      if (dmWriteEps(pMgmt->pData) != 0) {
×
298
        dError("failed to write dnode file");
×
299
      }
300
      dInfo("dnode will exit since it is in the dropped state");
×
301
      (void)raise(SIGINT);
×
302
    }
303
  } else {
304
    bool needUpdate = false;
1,278✔
305
    if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
2,556!
306
        tDeserializeSConfigRsp(pRsp->pCont, pRsp->contLen, &configRsp) == 0) {
1,278✔
307
      // Try to use cfg file in current dnode.
308
      if (configRsp.forceReadConfig) {
1,278!
309
        if (configRsp.isConifgVerified) {
×
310
          uInfo("force read config and check config verified");
×
311
          code = taosPersistGlobalConfig(taosGetGlobalCfg(tsCfg), pMgmt->path, configRsp.cver);
×
312
          if (code != TSDB_CODE_SUCCESS) {
×
313
            dError("failed to persist global config since %s", tstrerror(code));
×
314
            goto _exit;
×
315
          }
316
          needUpdate = true;
×
317
        } else {
318
          // log the difference configurations
319
          printConfigNotMatch(configRsp.array);
×
320
          needStop = true;
×
321
          goto _exit;
×
322
        }
323
      }
324
      // Try to use cfg from mnode sdb.
325
      if (!configRsp.isVersionVerified) {
1,278✔
326
        uInfo("config version not verified, update config");
1,057!
327
        needUpdate = true;
1,057✔
328
        code = taosPersistGlobalConfig(configRsp.array, pMgmt->path, configRsp.cver);
1,057✔
329
        if (code != TSDB_CODE_SUCCESS) {
1,057!
330
          dError("failed to persist global config since %s", tstrerror(code));
×
331
          goto _exit;
×
332
        }
333
      }
334
    }
335
    if (needUpdate) {
1,278✔
336
      code = cfgUpdateFromArray(tsCfg, configRsp.array);
1,057✔
337
      if (code != TSDB_CODE_SUCCESS) {
1,057!
338
        dError("failed to update config since %s", tstrerror(code));
×
339
        goto _exit;
×
340
      }
341
      code = setAllConfigs(tsCfg);
1,057✔
342
      if (code != TSDB_CODE_SUCCESS) {
1,057!
343
        dError("failed to set all configs since %s", tstrerror(code));
×
344
        goto _exit;
×
345
      }
346
    }
347
    code = taosPersistLocalConfig(pMgmt->path);
1,278✔
348
    if (code != TSDB_CODE_SUCCESS) {
1,278!
349
      dError("failed to persist local config since %s", tstrerror(code));
×
350
    }
351
    tsConfigInited = 1;
1,278✔
352
  }
353
_exit:
1,278✔
354
  tFreeSConfigRsp(&configRsp);
1,278✔
355
  rpcFreeCont(pRsp->pCont);
1,278✔
356
  if (needStop) {
1,278!
357
    dmStop();
×
358
  }
359
}
1,278✔
360

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

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

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

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

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

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

402
  dDebug("send status req to mnode, statusSeq:%d, begin to send rpc msg", pMgmt->statusSeq);
1,375✔
403
  code =
404
      rpcSendRecvWithTimeout(pMgmt->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, &epUpdated, tsStatusInterval * 5 * 1000);
1,375✔
405
  if (code != 0) {
1,375✔
406
    dError("failed to send status req since %s", tstrerror(code));
97!
407
    return;
97✔
408
  }
409
  if (rpcRsp.code != 0) {
1,278!
410
    dError("failed to send config req since %s", tstrerror(rpcRsp.code));
×
411
    return;
×
412
  }
413
  dmProcessConfigRsp(pMgmt, &rpcRsp);
1,278✔
414
}
415

416
void dmUpdateStatusInfo(SDnodeMgmt *pMgmt) {
68,584✔
417
  SMonVloadInfo vinfo = {0};
68,584✔
418
  dDebug("begin to get vnode loads");
68,584✔
419
  (*pMgmt->getVnodeLoadsFp)(&vinfo);
68,584✔
420
  dDebug("begin to lock status info");
68,584✔
421
  if (taosThreadMutexLock(&pMgmt->pData->statusInfolock) != 0) {
68,584!
422
    dError("failed to lock status info lock");
×
423
    return;
×
424
  }
425
  if (tsVinfo.pVloads == NULL) {
68,584✔
426
    tsVinfo.pVloads = vinfo.pVloads;
65,503✔
427
    vinfo.pVloads = NULL;
65,503✔
428
  } else {
429
    taosArrayDestroy(vinfo.pVloads);
3,081✔
430
    vinfo.pVloads = NULL;
3,081✔
431
  }
432
  if (taosThreadMutexUnlock(&pMgmt->pData->statusInfolock) != 0) {
68,584!
433
    dError("failed to unlock status info lock");
×
434
    return;
×
435
  }
436
}
437

438
void dmSendNotifyReq(SDnodeMgmt *pMgmt, SNotifyReq *pReq) {
×
439
  int32_t contLen = tSerializeSNotifyReq(NULL, 0, pReq);
×
440
  if (contLen < 0) {
×
441
    dError("failed to serialize notify req since %s", tstrerror(contLen));
×
442
    return;
×
443
  }
444
  void *pHead = rpcMallocCont(contLen);
×
445
  contLen = tSerializeSNotifyReq(pHead, contLen, pReq);
×
446
  if (contLen < 0) {
×
447
    rpcFreeCont(pHead);
×
448
    dError("failed to serialize notify req since %s", tstrerror(contLen));
×
449
    return;
×
450
  }
451

452
  SRpcMsg rpcMsg = {.pCont = pHead,
×
453
                    .contLen = contLen,
454
                    .msgType = TDMT_MND_NOTIFY,
455
                    .info.ahandle = 0,
456
                    .info.notFreeAhandle = 1,
457
                    .info.refId = 0,
458
                    .info.noResp = 1,
459
                    .info.handle = 0};
460

461
  SEpSet epSet = {0};
×
462
  dmGetMnodeEpSet(pMgmt->pData, &epSet);
×
463
  if (rpcSendRequest(pMgmt->msgCb.clientRpc, &epSet, &rpcMsg, NULL) != 0) {
×
464
    dError("failed to send notify req");
×
465
  }
466
}
467

468
int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
×
469
  dError("auth rsp is received, but not supported yet");
×
470
  return 0;
×
471
}
472

473
int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
×
474
  dError("grant rsp is received, but not supported yet");
×
475
  return 0;
×
476
}
477

478
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
471✔
479
  int32_t       code = 0;
471✔
480
  SDCfgDnodeReq cfgReq = {0};
471✔
481
  SConfig      *pCfg = taosGetCfg();
471✔
482
  SConfigItem  *pItem = NULL;
471✔
483

484
  if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
471!
485
    return TSDB_CODE_INVALID_MSG;
×
486
  }
487
  if (strcasecmp(cfgReq.config, "dataDir") == 0) {
471!
488
    return taosUpdateTfsItemDisable(pCfg, cfgReq.value, pMgmt->pTfs);
×
489
  }
490

491
  dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
471!
492

493
  code = cfgGetAndSetItem(pCfg, &pItem, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_SERVER_CMD, true);
471✔
494
  if (code != 0) {
471!
495
    if (strncasecmp(cfgReq.config, "resetlog", strlen("resetlog")) == 0) {
×
496
      TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, cfgReq.config, true));
×
497
      return TSDB_CODE_SUCCESS;
×
498
    } else {
499
      return code;
×
500
    }
501
  }
502
  if (pItem == NULL) {
471!
503
    return TSDB_CODE_CFG_NOT_FOUND;
×
504
  }
505
  if (!isConifgItemLazyMode(pItem)) {
471✔
506
    TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, cfgReq.config, true));
357!
507
  }
508

509
  if (pItem->category == CFG_CATEGORY_GLOBAL) {
471✔
510
    code = taosPersistGlobalConfig(taosGetGlobalCfg(pCfg), pMgmt->path, tsdmConfigVersion);
398✔
511
    if (code != TSDB_CODE_SUCCESS) {
398!
512
      dError("failed to persist global config since %s", tstrerror(code));
×
513
    }
514
  } else {
515
    code = taosPersistLocalConfig(pMgmt->path);
73✔
516
    if (code != TSDB_CODE_SUCCESS) {
73!
517
      dError("failed to persist local config since %s", tstrerror(code));
×
518
    }
519
  }
520
  if (cfgReq.version > 0) {
471✔
521
    tsdmConfigVersion = cfgReq.version;
464✔
522
  }
523
  return code;
471✔
524
}
525

526
int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
×
527
#ifdef TD_ENTERPRISE
528
  int32_t       code = 0;
×
529
  SDCfgDnodeReq cfgReq = {0};
×
530
  if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
×
531
    code = TSDB_CODE_INVALID_MSG;
×
532
    goto _exit;
×
533
  }
534

535
  code = dmUpdateEncryptKey(cfgReq.value, true);
×
536
  if (code == 0) {
×
537
    tsEncryptionKeyChksum = taosCalcChecksum(0, cfgReq.value, strlen(cfgReq.value));
×
538
    tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
×
539
    tstrncpy(tsEncryptKey, cfgReq.value, ENCRYPT_KEY_LEN + 1);
×
540
  }
541

542
_exit:
×
543
  pMsg->code = code;
×
544
  pMsg->info.rsp = NULL;
×
545
  pMsg->info.rspLen = 0;
×
546
  return code;
×
547
#else
548
  return 0;
549
#endif
550
}
551

552
static void dmGetServerRunStatus(SDnodeMgmt *pMgmt, SServerStatusRsp *pStatus) {
3✔
553
  pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_OK;
3✔
554
  pStatus->details[0] = 0;
3✔
555

556
  SMonMloadInfo minfo = {0};
3✔
557
  (*pMgmt->getMnodeLoadsFp)(&minfo);
3✔
558
  if (minfo.isMnode &&
3!
559
      (minfo.load.syncState == TAOS_SYNC_STATE_ERROR || minfo.load.syncState == TAOS_SYNC_STATE_OFFLINE)) {
3!
560
    pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_DEGRADED;
×
561
    snprintf(pStatus->details, sizeof(pStatus->details), "mnode sync state is %s", syncStr(minfo.load.syncState));
×
562
    return;
×
563
  }
564

565
  SMonVloadInfo vinfo = {0};
3✔
566
  (*pMgmt->getVnodeLoadsFp)(&vinfo);
3✔
567
  for (int32_t i = 0; i < taosArrayGetSize(vinfo.pVloads); ++i) {
7✔
568
    SVnodeLoad *pLoad = taosArrayGet(vinfo.pVloads, i);
4✔
569
    if (pLoad->syncState == TAOS_SYNC_STATE_ERROR || pLoad->syncState == TAOS_SYNC_STATE_OFFLINE) {
4!
570
      pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_DEGRADED;
×
571
      snprintf(pStatus->details, sizeof(pStatus->details), "vnode:%d sync state is %s", pLoad->vgId,
×
572
               syncStr(pLoad->syncState));
×
573
      break;
×
574
    }
575
  }
576

577
  taosArrayDestroy(vinfo.pVloads);
3✔
578
}
579

580
int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
3✔
581
  int32_t code = 0;
3✔
582
  dDebug("server run status req is received");
3!
583
  SServerStatusRsp statusRsp = {0};
3✔
584
  dmGetServerRunStatus(pMgmt, &statusRsp);
3✔
585

586
  pMsg->info.rsp = NULL;
3✔
587
  pMsg->info.rspLen = 0;
3✔
588

589
  SRpcMsg rspMsg = {.info = pMsg->info};
3✔
590
  int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
3✔
591
  if (rspLen < 0) {
3!
592
    return TSDB_CODE_OUT_OF_MEMORY;
×
593
    // rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
594
    // return rspMsg.code;
595
  }
596

597
  void *pRsp = rpcMallocCont(rspLen);
3✔
598
  if (pRsp == NULL) {
3!
599
    return terrno;
×
600
    // rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
601
    // return rspMsg.code;
602
  }
603

604
  rspLen = tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
3✔
605
  if (rspLen < 0) {
3!
606
    return TSDB_CODE_INVALID_MSG;
×
607
  }
608

609
  pMsg->info.rsp = pRsp;
3✔
610
  pMsg->info.rspLen = rspLen;
3✔
611
  return 0;
3✔
612
}
613

614
int32_t dmBuildVariablesBlock(SSDataBlock **ppBlock) {
484✔
615
  int32_t code = 0;
484✔
616

617
  SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
484!
618
  if (pBlock == NULL) {
484!
619
    return terrno;
×
620
  }
621

622
  size_t size = 0;
484✔
623

624
  const SSysTableMeta *pMeta = NULL;
484✔
625
  getInfosDbMeta(&pMeta, &size);
484✔
626

627
  int32_t index = 0;
484✔
628
  for (int32_t i = 0; i < size; ++i) {
8,712!
629
    if (strcmp(pMeta[i].name, TSDB_INS_TABLE_DNODE_VARIABLES) == 0) {
8,712✔
630
      index = i;
484✔
631
      break;
484✔
632
    }
633
  }
634

635
  pBlock->pDataBlock = taosArrayInit(pMeta[index].colNum, sizeof(SColumnInfoData));
484✔
636
  if (pBlock->pDataBlock == NULL) {
484!
637
    code = terrno;
×
638
    goto _exit;
×
639
  }
640

641
  for (int32_t i = 0; i < pMeta[index].colNum; ++i) {
3,388✔
642
    SColumnInfoData colInfoData = {0};
2,904✔
643
    colInfoData.info.colId = i + 1;
2,904✔
644
    colInfoData.info.type = pMeta[index].schema[i].type;
2,904✔
645
    colInfoData.info.bytes = pMeta[index].schema[i].bytes;
2,904✔
646
    if (taosArrayPush(pBlock->pDataBlock, &colInfoData) == NULL) {
5,808!
647
      code = terrno;
×
648
      goto _exit;
×
649
    }
650
  }
651

652
  pBlock->info.hasVarCol = true;
484✔
653
_exit:
484✔
654
  if (code != 0) {
484!
655
    blockDataDestroy(pBlock);
×
656
  } else {
657
    *ppBlock = pBlock;
484✔
658
  }
659
  return code;
484✔
660
}
661

662
int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) {
484✔
663
  int32_t code = dumpConfToDataBlock(pBlock, 1);
484✔
664
  if (code != 0) {
484!
665
    return code;
×
666
  }
667

668
  SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
484✔
669
  if (pColInfo == NULL) {
484!
670
    return TSDB_CODE_OUT_OF_RANGE;
×
671
  }
672

673
  return colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, false);
484✔
674
}
675

676
int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
484✔
677
  int32_t           size = 0;
484✔
678
  int32_t           rowsRead = 0;
484✔
679
  int32_t           code = 0;
484✔
680
  SRetrieveTableReq retrieveReq = {0};
484✔
681
  if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
484!
682
    return TSDB_CODE_INVALID_MSG;
×
683
  }
684
  dInfo("retrieve table:%s, user:%s, compactId:%" PRId64, retrieveReq.tb, retrieveReq.user, retrieveReq.compactId);
484!
685
#if 0
686
  if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
687
    code = TSDB_CODE_MND_NO_RIGHTS;
688
    return code;
689
  }
690
#endif
691
  if (strcasecmp(retrieveReq.tb, TSDB_INS_TABLE_DNODE_VARIABLES)) {
484!
692
    return TSDB_CODE_INVALID_MSG;
×
693
  }
694

695
  SSDataBlock *pBlock = NULL;
484✔
696
  if ((code = dmBuildVariablesBlock(&pBlock)) != 0) {
484!
697
    return code;
×
698
  }
699

700
  code = dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
484✔
701
  if (code != 0) {
484!
702
    blockDataDestroy(pBlock);
×
703
    return code;
×
704
  }
705

706
  size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
484✔
707
  size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
484✔
708
  size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * numOfCols + dataEncodeBufSize;
484✔
709

710
  SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
484✔
711
  if (pRsp == NULL) {
484!
712
    code = terrno;
×
713
    dError("failed to retrieve data since %s", tstrerror(code));
×
714
    blockDataDestroy(pBlock);
×
715
    return code;
×
716
  }
717

718
  char *pStart = pRsp->data;
484✔
719
  *(int32_t *)pStart = htonl(numOfCols);
484✔
720
  pStart += sizeof(int32_t);  // number of columns
484✔
721

722
  for (int32_t i = 0; i < numOfCols; ++i) {
3,388✔
723
    SSysTableSchema *pSchema = (SSysTableSchema *)pStart;
2,904✔
724
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, i);
2,904✔
725

726
    pSchema->bytes = htonl(pColInfo->info.bytes);
2,904✔
727
    pSchema->colId = htons(pColInfo->info.colId);
2,904✔
728
    pSchema->type = pColInfo->info.type;
2,904✔
729

730
    pStart += sizeof(SSysTableSchema);
2,904✔
731
  }
732

733
  int32_t len = blockEncode(pBlock, pStart, dataEncodeBufSize, numOfCols);
484✔
734
  if (len < 0) {
484!
735
    dError("failed to retrieve data since %s", tstrerror(code));
×
736
    blockDataDestroy(pBlock);
×
737
    rpcFreeCont(pRsp);
×
738
    return terrno;
×
739
  }
740

741
  pRsp->numOfRows = htonl(pBlock->info.rows);
484✔
742
  pRsp->precision = TSDB_TIME_PRECISION_MILLI;  // millisecond time precision
484✔
743
  pRsp->completed = 1;
484✔
744
  pMsg->info.rsp = pRsp;
484✔
745
  pMsg->info.rspLen = size;
484✔
746
  dDebug("dnode variables retrieve completed");
484!
747

748
  blockDataDestroy(pBlock);
484✔
749
  return TSDB_CODE_SUCCESS;
484✔
750
}
751

752
SArray *dmGetMsgHandles() {
1,290✔
753
  int32_t code = -1;
1,290✔
754
  SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle));
1,290✔
755
  if (pArray == NULL) {
1,290!
756
    return NULL;
×
757
  }
758

759
  // Requests handled by DNODE
760
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
761
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
762
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_QNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
763
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_QNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
764
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_SNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
765
  if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_SNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
766
  if (dmSetMgmtHandle(pArray, TDMT_DND_CONFIG_DNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
767
  if (dmSetMgmtHandle(pArray, TDMT_DND_SERVER_STATUS, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
768
  if (dmSetMgmtHandle(pArray, TDMT_DND_SYSTABLE_RETRIEVE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
769
  if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_MNODE_TYPE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
770
  if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_ENCRYPT_KEY, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
771

772
  // Requests handled by MNODE
773
  if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
774
  if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT_NOTIFY, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
775
  if (dmSetMgmtHandle(pArray, TDMT_MND_AUTH_RSP, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
1,290!
776

777
  code = 0;
1,290✔
778

779
_OVER:
1,290✔
780
  if (code != 0) {
1,290!
781
    taosArrayDestroy(pArray);
×
782
    return NULL;
×
783
  } else {
784
    return pArray;
1,290✔
785
  }
786
}
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