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

taosdata / TDengine / #4271

10 Jun 2025 09:45AM UTC coverage: 62.985% (+0.002%) from 62.983%
#4271

push

travis-ci

web-flow
Merge pull request #31337 from taosdata/newtest_3.0

fix TD-35057 and TD-35346

158179 of 319671 branches covered (49.48%)

Branch coverage included in aggregate %.

243860 of 318637 relevant lines covered (76.53%)

18624660.26 hits per line

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

66.7
/source/dnode/mnode/impl/src/mndDnode.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 <stdio.h>
18
#include "audit.h"
19
#include "mndCluster.h"
20
#include "mndDb.h"
21
#include "mndDnode.h"
22
#include "mndMnode.h"
23
#include "mndPrivilege.h"
24
#include "mndQnode.h"
25
#include "mndShow.h"
26
#include "mndSnode.h"
27
#include "mndTrans.h"
28
#include "mndUser.h"
29
#include "mndVgroup.h"
30
#include "taos_monitor.h"
31
#include "tconfig.h"
32
#include "tjson.h"
33
#include "tmisce.h"
34
#include "tunit.h"
35

36
#define TSDB_DNODE_VER_NUMBER   2
37
#define TSDB_DNODE_RESERVE_SIZE 40
38

39
static const char *offlineReason[] = {
40
    "",
41
    "status msg timeout",
42
    "status not received",
43
    "version not match",
44
    "dnodeId not match",
45
    "clusterId not match",
46
    "statusInterval not match",
47
    "timezone not match",
48
    "locale not match",
49
    "charset not match",
50
    "ttlChangeOnWrite not match",
51
    "enableWhiteList not match",
52
    "encryptionKey not match",
53
    "monitor not match",
54
    "monitor switch not match",
55
    "monitor interval not match",
56
    "monitor slow log threshold not match",
57
    "monitor slow log sql max len not match",
58
    "monitor slow log scope not match",
59
    "unknown",
60
};
61

62
enum {
63
  DND_ACTIVE_CODE,
64
  DND_CONN_ACTIVE_CODE,
65
};
66

67
enum {
68
  DND_CREATE,
69
  DND_ADD,
70
  DND_DROP,
71
};
72

73
static int32_t  mndCreateDefaultDnode(SMnode *pMnode);
74
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode);
75
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw);
76
static int32_t  mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode);
77
static int32_t  mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode);
78
static int32_t  mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOld, SDnodeObj *pNew);
79
static int32_t  mndProcessDnodeListReq(SRpcMsg *pReq);
80

81
static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq);
82
static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq);
83
static int32_t mndProcessStatusReq(SRpcMsg *pReq);
84
static int32_t mndProcessNotifyReq(SRpcMsg *pReq);
85
static int32_t mndProcessRestoreDnodeReq(SRpcMsg *pReq);
86
static int32_t mndProcessStatisReq(SRpcMsg *pReq);
87
static int32_t mndProcessAuditReq(SRpcMsg *pReq);
88
static int32_t mndProcessUpdateDnodeInfoReq(SRpcMsg *pReq);
89
static int32_t mndProcessCreateEncryptKeyReq(SRpcMsg *pRsp);
90
static int32_t mndProcessCreateEncryptKeyRsp(SRpcMsg *pRsp);
91

92
static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
93
static void    mndCancelGetNextConfig(SMnode *pMnode, void *pIter);
94
static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
95
static void    mndCancelGetNextDnode(SMnode *pMnode, void *pIter);
96

97
#ifdef _GRANT
98
int32_t mndUpdClusterInfo(SRpcMsg *pReq);
99
#else
100
static int32_t mndUpdClusterInfo(SRpcMsg *pReq) { return 0; }
101
#endif
102

103
int32_t mndInitDnode(SMnode *pMnode) {
2,289✔
104
  SSdbTable table = {
2,289✔
105
      .sdbType = SDB_DNODE,
106
      .keyType = SDB_KEY_INT32,
107
      .deployFp = (SdbDeployFp)mndCreateDefaultDnode,
108
      .encodeFp = (SdbEncodeFp)mndDnodeActionEncode,
109
      .decodeFp = (SdbDecodeFp)mndDnodeActionDecode,
110
      .insertFp = (SdbInsertFp)mndDnodeActionInsert,
111
      .updateFp = (SdbUpdateFp)mndDnodeActionUpdate,
112
      .deleteFp = (SdbDeleteFp)mndDnodeActionDelete,
113
  };
114

115
  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_DNODE, mndProcessCreateDnodeReq);
2,289✔
116
  mndSetMsgHandle(pMnode, TDMT_MND_DROP_DNODE, mndProcessDropDnodeReq);
2,289✔
117
  mndSetMsgHandle(pMnode, TDMT_MND_STATUS, mndProcessStatusReq);
2,289✔
118
  mndSetMsgHandle(pMnode, TDMT_MND_NOTIFY, mndProcessNotifyReq);
2,289✔
119
  mndSetMsgHandle(pMnode, TDMT_MND_DNODE_LIST, mndProcessDnodeListReq);
2,289✔
120
  mndSetMsgHandle(pMnode, TDMT_MND_RESTORE_DNODE, mndProcessRestoreDnodeReq);
2,289✔
121
  mndSetMsgHandle(pMnode, TDMT_MND_STATIS, mndProcessStatisReq);
2,289✔
122
  mndSetMsgHandle(pMnode, TDMT_MND_AUDIT, mndProcessAuditReq);
2,289✔
123
  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ENCRYPT_KEY, mndProcessCreateEncryptKeyReq);
2,289✔
124
  mndSetMsgHandle(pMnode, TDMT_DND_CREATE_ENCRYPT_KEY_RSP, mndProcessCreateEncryptKeyRsp);
2,289✔
125
  mndSetMsgHandle(pMnode, TDMT_MND_UPDATE_DNODE_INFO, mndProcessUpdateDnodeInfoReq);
2,289✔
126

127
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndRetrieveConfigs);
2,289✔
128
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndCancelGetNextConfig);
2,289✔
129
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_DNODE, mndRetrieveDnodes);
2,289✔
130
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_DNODE, mndCancelGetNextDnode);
2,289✔
131

132
  return sdbSetTable(pMnode->pSdb, table);
2,289✔
133
}
134

135
void          mndCleanupDnode(SMnode *pMnode) {}
2,288✔
136

137
static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
1,734✔
138
  int32_t  code = -1;
1,734✔
139
  SSdbRaw *pRaw = NULL;
1,734✔
140
  STrans  *pTrans = NULL;
1,734✔
141

142
  SDnodeObj dnodeObj = {0};
1,734✔
143
  dnodeObj.id = 1;
1,734✔
144
  dnodeObj.createdTime = taosGetTimestampMs();
1,734✔
145
  dnodeObj.updateTime = dnodeObj.createdTime;
1,734✔
146
  dnodeObj.port = tsServerPort;
1,734✔
147
  tstrncpy(dnodeObj.fqdn, tsLocalFqdn, TSDB_FQDN_LEN);
1,734✔
148
  dnodeObj.fqdn[TSDB_FQDN_LEN - 1] = 0;
1,734✔
149
  (void)snprintf(dnodeObj.ep, TSDB_EP_LEN - 1, "%s:%u", tsLocalFqdn, tsServerPort);
1,734✔
150
  char *machineId = NULL;
1,734✔
151
  code = tGetMachineId(&machineId);
1,734✔
152
  if (machineId) {
1,734!
153
    (void)memcpy(dnodeObj.machineId, machineId, TSDB_MACHINE_ID_LEN);
1,734✔
154
    taosMemoryFreeClear(machineId);
1,734!
155
  } else {
156
#if defined(TD_ENTERPRISE) && !defined(GRANTS_CFG)
157
    terrno = TSDB_CODE_DNODE_NO_MACHINE_CODE;
×
158
    goto _OVER;
×
159
#endif
160
  }
161

162
  pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, NULL, "create-dnode");
1,734✔
163
  if (pTrans == NULL) {
1,734!
164
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
165
    if (terrno != 0) code = terrno;
×
166
    goto _OVER;
×
167
  }
168
  mInfo("trans:%d, used to create dnode:%s on first deploy", pTrans->id, dnodeObj.ep);
1,734!
169

170
  pRaw = mndDnodeActionEncode(&dnodeObj);
1,734✔
171
  if (pRaw == NULL) {
1,734!
172
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
173
    if (terrno != 0) code = terrno;
×
174
    goto _OVER;
×
175
  }
176
  TAOS_CHECK_GOTO(mndTransAppendCommitlog(pTrans, pRaw), NULL, _OVER);
1,734!
177
  TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_READY), NULL, _OVER);
1,734!
178
  pRaw = NULL;
1,734✔
179

180
  TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
1,734!
181
  code = 0;
1,734✔
182
  (void)mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD,
1,734✔
183
                                   1);  // TODO: check the return value
184

185
_OVER:
1,734✔
186
  mndTransDrop(pTrans);
1,734✔
187
  sdbFreeRaw(pRaw);
1,734✔
188
  return code;
1,734✔
189
}
190

191
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
13,217✔
192
  int32_t code = 0;
13,217✔
193
  int32_t lino = 0;
13,217✔
194
  terrno = TSDB_CODE_OUT_OF_MEMORY;
13,217✔
195

196
  SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE);
13,217✔
197
  if (pRaw == NULL) goto _OVER;
13,217!
198

199
  int32_t dataPos = 0;
13,217✔
200
  SDB_SET_INT32(pRaw, dataPos, pDnode->id, _OVER)
13,217!
201
  SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime, _OVER)
13,217!
202
  SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime, _OVER)
13,217!
203
  SDB_SET_INT16(pRaw, dataPos, pDnode->port, _OVER)
13,217!
204
  SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, _OVER)
13,217!
205
  SDB_SET_BINARY(pRaw, dataPos, pDnode->machineId, TSDB_MACHINE_ID_LEN, _OVER)
13,217!
206
  SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, _OVER)
13,217!
207
  SDB_SET_INT16(pRaw, dataPos, 0, _OVER)  // forward/backward compatible
13,217!
208
  SDB_SET_INT16(pRaw, dataPos, 0, _OVER)  // forward/backward compatible
13,217!
209
  SDB_SET_DATALEN(pRaw, dataPos, _OVER);
13,217!
210

211
  terrno = 0;
13,217✔
212

213
_OVER:
13,217✔
214
  if (terrno != 0) {
13,217!
215
    mError("dnode:%d, failed to encode to raw:%p since %s", pDnode->id, pRaw, terrstr());
×
216
    sdbFreeRaw(pRaw);
×
217
    return NULL;
×
218
  }
219

220
  mTrace("dnode:%d, encode to raw:%p, row:%p", pDnode->id, pRaw, pDnode);
13,217✔
221
  return pRaw;
13,217✔
222
}
223

224
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
10,098✔
225
  int32_t code = 0;
10,098✔
226
  int32_t lino = 0;
10,098✔
227
  terrno = TSDB_CODE_OUT_OF_MEMORY;
10,098✔
228
  SSdbRow   *pRow = NULL;
10,098✔
229
  SDnodeObj *pDnode = NULL;
10,098✔
230

231
  int8_t sver = 0;
10,098✔
232
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
10,098!
233
  if (sver < 1 || sver > TSDB_DNODE_VER_NUMBER) {
10,098!
234
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
235
    goto _OVER;
×
236
  }
237

238
  pRow = sdbAllocRow(sizeof(SDnodeObj));
10,098✔
239
  if (pRow == NULL) goto _OVER;
10,098!
240

241
  pDnode = sdbGetRowObj(pRow);
10,098✔
242
  if (pDnode == NULL) goto _OVER;
10,098!
243

244
  int32_t dataPos = 0;
10,098✔
245
  SDB_GET_INT32(pRaw, dataPos, &pDnode->id, _OVER)
10,098!
246
  SDB_GET_INT64(pRaw, dataPos, &pDnode->createdTime, _OVER)
10,098!
247
  SDB_GET_INT64(pRaw, dataPos, &pDnode->updateTime, _OVER)
10,098!
248
  SDB_GET_INT16(pRaw, dataPos, &pDnode->port, _OVER)
10,098!
249
  SDB_GET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, _OVER)
10,098!
250
  SDB_GET_BINARY(pRaw, dataPos, pDnode->machineId, TSDB_MACHINE_ID_LEN, _OVER)
10,098!
251
  SDB_GET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, _OVER)
10,098!
252
  if (sver > 1) {
10,098!
253
    int16_t keyLen = 0;
10,098✔
254
    SDB_GET_INT16(pRaw, dataPos, &keyLen, _OVER)
10,098!
255
    SDB_GET_BINARY(pRaw, dataPos, NULL, keyLen, _OVER)
10,098!
256
    SDB_GET_INT16(pRaw, dataPos, &keyLen, _OVER)
10,098!
257
    SDB_GET_BINARY(pRaw, dataPos, NULL, keyLen, _OVER)
10,098!
258
  }
259

260
  terrno = 0;
10,098✔
261
  if (tmsgUpdateDnodeInfo(&pDnode->id, NULL, pDnode->fqdn, &pDnode->port)) {
10,098!
262
    mInfo("dnode:%d, endpoint changed", pDnode->id);
×
263
  }
264

265
_OVER:
10,098✔
266
  if (terrno != 0) {
10,098!
267
    mError("dnode:%d, failed to decode from raw:%p since %s", pDnode == NULL ? 0 : pDnode->id, pRaw, terrstr());
×
268
    taosMemoryFreeClear(pRow);
×
269
    return NULL;
×
270
  }
271

272
  mTrace("dnode:%d, decode from raw:%p, row:%p ep:%s:%u", pDnode->id, pRaw, pDnode, pDnode->fqdn, pDnode->port);
10,098✔
273
  return pRow;
10,098✔
274
}
275

276
static int32_t mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode) {
4,073✔
277
  mTrace("dnode:%d, perform insert action, row:%p", pDnode->id, pDnode);
4,073✔
278
  pDnode->offlineReason = DND_REASON_STATUS_NOT_RECEIVED;
4,073✔
279

280
  char ep[TSDB_EP_LEN] = {0};
4,073✔
281
  (void)snprintf(ep, TSDB_EP_LEN - 1, "%s:%u", pDnode->fqdn, pDnode->port);
4,073✔
282
  tstrncpy(pDnode->ep, ep, TSDB_EP_LEN);
4,073✔
283
  return 0;
4,073✔
284
}
285

286
static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) {
10,097✔
287
  mTrace("dnode:%d, perform delete action, row:%p", pDnode->id, pDnode);
10,097✔
288
  return 0;
10,097✔
289
}
290

291
static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOld, SDnodeObj *pNew) {
5,996✔
292
  mTrace("dnode:%d, perform update action, old row:%p new row:%p", pOld->id, pOld, pNew);
5,996✔
293
  pOld->updateTime = pNew->updateTime;
5,996✔
294
#if defined(TD_ENTERPRISE) || defined(TD_ASTRA_TODO)
295
  tstrncpy(pOld->machineId, pNew->machineId, TSDB_MACHINE_ID_LEN + 1);
5,996✔
296
#endif
297
  return 0;
5,996✔
298
}
299

300
SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId) {
21,451,013✔
301
  SSdb      *pSdb = pMnode->pSdb;
21,451,013✔
302
  SDnodeObj *pDnode = sdbAcquire(pSdb, SDB_DNODE, &dnodeId);
21,451,013✔
303
  if (pDnode == NULL) {
21,461,879✔
304
    if (terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
467✔
305
      terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
101✔
306
    } else if (terrno == TSDB_CODE_SDB_OBJ_CREATING) {
366!
307
      terrno = TSDB_CODE_MND_DNODE_IN_CREATING;
×
308
    } else if (terrno == TSDB_CODE_SDB_OBJ_DROPPING) {
366!
309
      terrno = TSDB_CODE_MND_DNODE_IN_DROPPING;
366✔
310
    } else {
311
      terrno = TSDB_CODE_APP_ERROR;
×
312
      mFatal("dnode:%d, failed to acquire db since %s", dnodeId, terrstr());
×
313
    }
314
  }
315

316
  return pDnode;
21,461,739✔
317
}
318

319
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode) {
21,078,412✔
320
  SSdb *pSdb = pMnode->pSdb;
21,078,412✔
321
  sdbRelease(pSdb, pDnode);
21,078,412✔
322
}
21,079,528✔
323

324
SEpSet mndGetDnodeEpset(SDnodeObj *pDnode) {
32,521✔
325
  SEpSet epSet = {0};
32,521✔
326
  terrno = addEpIntoEpSet(&epSet, pDnode->fqdn, pDnode->port);
32,521✔
327
  return epSet;
32,521✔
328
}
329

330
SEpSet mndGetDnodeEpsetById(SMnode *pMnode, int32_t dnodeId) {
×
331
  SEpSet     epSet = {0};
×
332
  SDnodeObj *pDnode = mndAcquireDnode(pMnode, dnodeId);
×
333
  if (!pDnode) return epSet;
×
334

335
  epSet = mndGetDnodeEpset(pDnode);
×
336

337
  mndReleaseDnode(pMnode, pDnode);
×
338
  return epSet;
×
339
}
340

341
static SDnodeObj *mndAcquireDnodeByEp(SMnode *pMnode, char *pEpStr) {
4,298✔
342
  SSdb *pSdb = pMnode->pSdb;
4,298✔
343

344
  void *pIter = NULL;
4,298✔
345
  while (1) {
4,824✔
346
    SDnodeObj *pDnode = NULL;
9,122✔
347
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
9,122✔
348
    if (pIter == NULL) break;
9,122✔
349

350
    if (taosStrncasecmp(pEpStr, pDnode->ep, TSDB_EP_LEN) == 0) {
7,549✔
351
      sdbCancelFetch(pSdb, pIter);
2,725✔
352
      return pDnode;
2,725✔
353
    }
354

355
    sdbRelease(pSdb, pDnode);
4,824✔
356
  }
357

358
  terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
1,573✔
359
  return NULL;
1,573✔
360
}
361

362
static SDnodeObj *mndAcquireDnodeAllStatusByEp(SMnode *pMnode, char *pEpStr) {
268✔
363
  SSdb *pSdb = pMnode->pSdb;
268✔
364

365
  void *pIter = NULL;
268✔
366
  while (1) {
268✔
367
    SDnodeObj *pDnode = NULL;
536✔
368
    ESdbStatus objStatus = 0;
536✔
369
    pIter = sdbFetchAll(pSdb, SDB_DNODE, pIter, (void **)&pDnode, &objStatus, true);
536✔
370
    if (pIter == NULL) break;
536!
371

372
    if (taosStrncasecmp(pEpStr, pDnode->ep, TSDB_EP_LEN) == 0) {
536✔
373
      sdbCancelFetch(pSdb, pIter);
268✔
374
      return pDnode;
268✔
375
    }
376

377
    sdbRelease(pSdb, pDnode);
268✔
378
  }
379

380
  return NULL;
×
381
}
382

383
int32_t mndGetDnodeSize(SMnode *pMnode) {
491,297✔
384
  SSdb *pSdb = pMnode->pSdb;
491,297✔
385
  return sdbGetSize(pSdb, SDB_DNODE);
491,297✔
386
}
387

388
int32_t mndGetDbSize(SMnode *pMnode) {
×
389
  SSdb *pSdb = pMnode->pSdb;
×
390
  return sdbGetSize(pSdb, SDB_DB);
×
391
}
392

393
bool mndIsDnodeOnline(SDnodeObj *pDnode, int64_t curMs) {
1,465,850✔
394
  int64_t interval = TABS(pDnode->lastAccessTime - curMs);
1,465,850✔
395
  if (interval > 5000 * (int64_t)tsStatusInterval) {
1,465,850✔
396
    if (pDnode->rebootTime > 0 && pDnode->offlineReason == DND_REASON_ONLINE) {
9,128✔
397
      pDnode->offlineReason = DND_REASON_STATUS_MSG_TIMEOUT;
185✔
398
    }
399
    return false;
9,128✔
400
  }
401
  return true;
1,456,722✔
402
}
403

404
static void mndGetDnodeEps(SMnode *pMnode, SArray *pDnodeEps) {
10,592✔
405
  SSdb *pSdb = pMnode->pSdb;
10,592✔
406

407
  int32_t numOfEps = 0;
10,592✔
408
  void   *pIter = NULL;
10,592✔
409
  while (1) {
30,908✔
410
    SDnodeObj *pDnode = NULL;
41,500✔
411
    ESdbStatus objStatus = 0;
41,500✔
412
    pIter = sdbFetchAll(pSdb, SDB_DNODE, pIter, (void **)&pDnode, &objStatus, true);
41,500✔
413
    if (pIter == NULL) break;
41,500✔
414

415
    SDnodeEp dnodeEp = {0};
30,908✔
416
    dnodeEp.id = pDnode->id;
30,908✔
417
    dnodeEp.ep.port = pDnode->port;
30,908✔
418
    tstrncpy(dnodeEp.ep.fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
30,908✔
419
    sdbRelease(pSdb, pDnode);
30,908✔
420

421
    dnodeEp.isMnode = 0;
30,908✔
422
    if (mndIsMnode(pMnode, pDnode->id)) {
30,908✔
423
      dnodeEp.isMnode = 1;
14,700✔
424
    }
425
    if (taosArrayPush(pDnodeEps, &dnodeEp) == NULL) {
30,908!
426
      mError("failed to put ep into array, but continue at this call");
×
427
    }
428
  }
429
}
10,592✔
430

431
int32_t mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo) {
61,942✔
432
  SSdb   *pSdb = pMnode->pSdb;
61,942✔
433
  int32_t code = 0;
61,942✔
434

435
  int32_t numOfEps = 0;
61,942✔
436
  void   *pIter = NULL;
61,942✔
437
  while (1) {
277,000✔
438
    SDnodeObj *pDnode = NULL;
338,942✔
439
    ESdbStatus objStatus = 0;
338,942✔
440
    pIter = sdbFetchAll(pSdb, SDB_DNODE, pIter, (void **)&pDnode, &objStatus, true);
338,942✔
441
    if (pIter == NULL) break;
338,942✔
442

443
    SDnodeInfo dInfo;
444
    dInfo.id = pDnode->id;
277,000✔
445
    dInfo.ep.port = pDnode->port;
277,000✔
446
    dInfo.offlineReason = pDnode->offlineReason;
277,000✔
447
    tstrncpy(dInfo.ep.fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
277,000✔
448
    sdbRelease(pSdb, pDnode);
277,000✔
449
    if (mndIsMnode(pMnode, pDnode->id)) {
277,000✔
450
      dInfo.isMnode = 1;
82,621✔
451
    } else {
452
      dInfo.isMnode = 0;
194,379✔
453
    }
454

455
    if (taosArrayPush(pDnodeInfo, &dInfo) == NULL) {
277,000!
456
      code = terrno;
×
457
      sdbCancelFetch(pSdb, pIter);
×
458
      break;
×
459
    }
460
  }
461
  TAOS_RETURN(code);
61,942✔
462
}
463

464
#define CHECK_MONITOR_PARA(para, err)                                                                    \
465
  if (pCfg->monitorParas.para != para) {                                                                 \
466
    mError("dnode:%d, para:%d inconsistent with cluster:%d", pDnode->id, pCfg->monitorParas.para, para); \
467
    terrno = err;                                                                                        \
468
    return err;                                                                                          \
469
  }
470

471
static int32_t mndCheckClusterCfgPara(SMnode *pMnode, SDnodeObj *pDnode, const SClusterCfg *pCfg) {
10,592✔
472
  CHECK_MONITOR_PARA(tsEnableMonitor, DND_REASON_STATUS_MONITOR_SWITCH_NOT_MATCH);
10,592!
473
  CHECK_MONITOR_PARA(tsMonitorInterval, DND_REASON_STATUS_MONITOR_INTERVAL_NOT_MATCH);
10,592!
474
  CHECK_MONITOR_PARA(tsSlowLogThreshold, DND_REASON_STATUS_MONITOR_SLOW_LOG_THRESHOLD_NOT_MATCH);
10,592!
475
  CHECK_MONITOR_PARA(tsSlowLogMaxLen, DND_REASON_STATUS_MONITOR_SLOW_LOG_SQL_MAX_LEN_NOT_MATCH);
10,592!
476
  CHECK_MONITOR_PARA(tsSlowLogScope, DND_REASON_STATUS_MONITOR_SLOW_LOG_SCOPE_NOT_MATCH);
10,592!
477

478
  if (0 != taosStrcasecmp(pCfg->monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb)) {
10,592!
479
    mError("dnode:%d, tsSlowLogExceptDb:%s inconsistent with cluster:%s", pDnode->id,
×
480
           pCfg->monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb);
481
    terrno = TSDB_CODE_DNODE_INVALID_MONITOR_PARAS;
×
482
    return DND_REASON_STATUS_MONITOR_NOT_MATCH;
×
483
  }
484

485
  if (pCfg->statusInterval != tsStatusInterval) {
10,592!
486
    mError("dnode:%d, statusInterval:%d inconsistent with cluster:%d", pDnode->id, pCfg->statusInterval,
×
487
           tsStatusInterval);
488
    terrno = TSDB_CODE_DNODE_INVALID_STATUS_INTERVAL;
×
489
    return DND_REASON_STATUS_INTERVAL_NOT_MATCH;
×
490
  }
491

492
  if ((0 != taosStrcasecmp(pCfg->timezone, tsTimezoneStr)) && (pMnode->checkTime != pCfg->checkTime)) {
10,592!
493
    mError("dnode:%d, timezone:%s checkTime:%" PRId64 " inconsistent with cluster %s %" PRId64, pDnode->id,
×
494
           pCfg->timezone, pCfg->checkTime, tsTimezoneStr, pMnode->checkTime);
495
    terrno = TSDB_CODE_DNODE_INVALID_TIMEZONE;
×
496
    return DND_REASON_TIME_ZONE_NOT_MATCH;
×
497
  }
498

499
  if (0 != taosStrcasecmp(pCfg->locale, tsLocale)) {
10,592!
500
    mError("dnode:%d, locale:%s inconsistent with cluster:%s", pDnode->id, pCfg->locale, tsLocale);
×
501
    terrno = TSDB_CODE_DNODE_INVALID_LOCALE;
×
502
    return DND_REASON_LOCALE_NOT_MATCH;
×
503
  }
504

505
  if (0 != taosStrcasecmp(pCfg->charset, tsCharset)) {
10,592!
506
    mError("dnode:%d, charset:%s inconsistent with cluster:%s", pDnode->id, pCfg->charset, tsCharset);
×
507
    terrno = TSDB_CODE_DNODE_INVALID_CHARSET;
×
508
    return DND_REASON_CHARSET_NOT_MATCH;
×
509
  }
510

511
  if (pCfg->ttlChangeOnWrite != tsTtlChangeOnWrite) {
10,592!
512
    mError("dnode:%d, ttlChangeOnWrite:%d inconsistent with cluster:%d", pDnode->id, pCfg->ttlChangeOnWrite,
×
513
           tsTtlChangeOnWrite);
514
    terrno = TSDB_CODE_DNODE_INVALID_TTL_CHG_ON_WR;
×
515
    return DND_REASON_TTL_CHANGE_ON_WRITE_NOT_MATCH;
×
516
  }
517
  int8_t enable = tsEnableWhiteList ? 1 : 0;
10,592✔
518
  if (pCfg->enableWhiteList != enable) {
10,592!
519
    mError("dnode:%d, enableWhiteList:%d inconsistent with cluster:%d", pDnode->id, pCfg->enableWhiteList, enable);
×
520
    terrno = TSDB_CODE_DNODE_INVALID_EN_WHITELIST;
×
521
    return DND_REASON_ENABLE_WHITELIST_NOT_MATCH;
×
522
  }
523

524
  if (!atomic_load_8(&pMnode->encryptMgmt.encrypting) &&
10,592!
525
      (pCfg->encryptionKeyStat != tsEncryptionKeyStat || pCfg->encryptionKeyChksum != tsEncryptionKeyChksum)) {
10,592!
526
    mError("dnode:%d, encryptionKey:%" PRIi8 "-%u inconsistent with cluster:%" PRIi8 "-%u", pDnode->id,
×
527
           pCfg->encryptionKeyStat, pCfg->encryptionKeyChksum, tsEncryptionKeyStat, tsEncryptionKeyChksum);
528
    terrno = pCfg->encryptionKeyChksum ? TSDB_CODE_DNODE_INVALID_ENCRYPTKEY : TSDB_CODE_DNODE_NO_ENCRYPT_KEY;
×
529
    return DND_REASON_ENCRYPTION_KEY_NOT_MATCH;
×
530
  }
531

532
  return DND_REASON_ONLINE;
10,592✔
533
}
534

535
double calcAppliedRate(int64_t currentCount, int64_t lastCount, int64_t currentTimeMs, int64_t lastTimeMs) {
175✔
536
  if ((currentTimeMs <= lastTimeMs) || (currentCount <= lastCount)) {
175!
537
    return 0.0;
18✔
538
  }
539

540
  int64_t deltaCount = currentCount - lastCount;
157✔
541
  int64_t deltaMs = currentTimeMs - lastTimeMs;
157✔
542
  double  rate = (double)deltaCount / (double)deltaMs;
157✔
543
  return rate;
157✔
544
}
545

546
static bool mndUpdateVnodeState(int32_t vgId, SVnodeGid *pGid, SVnodeLoad *pVload) {
662,090✔
547
  bool stateChanged = false;
662,090✔
548
  bool roleChanged = pGid->syncState != pVload->syncState ||
1,982,586✔
549
                     (pVload->syncTerm != -1 && pGid->syncTerm != pVload->syncTerm) ||
1,308,640!
550
                     pGid->roleTimeMs != pVload->roleTimeMs;
646,550✔
551

552
  if (pVload->syncCommitIndex > pVload->syncAppliedIndex) {
662,090✔
553
    if (pGid->lastSyncAppliedIndexUpdateTime == 0) {
313✔
554
      pGid->lastSyncAppliedIndexUpdateTime = taosGetTimestampMs();
131✔
555
    } else if (pGid->syncAppliedIndex != pVload->syncAppliedIndex) {
182✔
556
      int64_t currentTimeMs = taosGetTimestampMs();
175✔
557
      pGid->appliedRate = calcAppliedRate(pVload->syncAppliedIndex, pGid->syncAppliedIndex, currentTimeMs,
175✔
558
                                          pGid->lastSyncAppliedIndexUpdateTime);
559

560
      pGid->lastSyncAppliedIndexUpdateTime = currentTimeMs;
175✔
561
    }
562
  }
563

564
  pGid->syncAppliedIndex = pVload->syncAppliedIndex;
662,090✔
565
  pGid->syncCommitIndex = pVload->syncCommitIndex;
662,090✔
566
  pGid->bufferSegmentUsed = pVload->bufferSegmentUsed;
662,090✔
567
  pGid->bufferSegmentSize = pVload->bufferSegmentSize;
662,090✔
568
  if (roleChanged || pGid->syncRestore != pVload->syncRestore || pGid->syncCanRead != pVload->syncCanRead ||
662,090!
569
      pGid->startTimeMs != pVload->startTimeMs) {
645,442!
570
    mInfo(
16,648!
571
        "vgId:%d, state changed by status msg, old state:%s restored:%d canRead:%d new state:%s restored:%d "
572
        "canRead:%d, dnode:%d",
573
        vgId, syncStr(pGid->syncState), pGid->syncRestore, pGid->syncCanRead, syncStr(pVload->syncState),
574
        pVload->syncRestore, pVload->syncCanRead, pGid->dnodeId);
575
    pGid->syncState = pVload->syncState;
16,648✔
576
    pGid->syncTerm = pVload->syncTerm;
16,648✔
577
    pGid->syncRestore = pVload->syncRestore;
16,648✔
578
    pGid->syncCanRead = pVload->syncCanRead;
16,648✔
579
    pGid->startTimeMs = pVload->startTimeMs;
16,648✔
580
    pGid->roleTimeMs = pVload->roleTimeMs;
16,648✔
581
    stateChanged = true;
16,648✔
582
  }
583
  return stateChanged;
662,090✔
584
}
585

586
static bool mndUpdateMnodeState(SMnodeObj *pObj, SMnodeLoad *pMload) {
77,181✔
587
  bool stateChanged = false;
77,181✔
588
  bool roleChanged = pObj->syncState != pMload->syncState ||
229,290✔
589
                     (pMload->syncTerm != -1 && pObj->syncTerm != pMload->syncTerm) ||
152,064!
590
                     pObj->roleTimeMs != pMload->roleTimeMs;
74,883✔
591
  if (roleChanged || pObj->syncRestore != pMload->syncRestore) {
77,181✔
592
    mInfo("dnode:%d, mnode syncState from %s to %s, restoreState from %d to %d, syncTerm from %" PRId64 " to %" PRId64,
2,363!
593
          pObj->id, syncStr(pObj->syncState), syncStr(pMload->syncState), pObj->syncRestore, pMload->syncRestore,
594
          pObj->syncTerm, pMload->syncTerm);
595
    pObj->syncState = pMload->syncState;
2,363✔
596
    pObj->syncTerm = pMload->syncTerm;
2,363✔
597
    pObj->syncRestore = pMload->syncRestore;
2,363✔
598
    pObj->roleTimeMs = pMload->roleTimeMs;
2,363✔
599
    stateChanged = true;
2,363✔
600
  }
601
  return stateChanged;
77,181✔
602
}
603

604
extern char   *tsMonFwUri;
605
extern char   *tsMonSlowLogUri;
606
static int32_t mndProcessStatisReq(SRpcMsg *pReq) {
6,656✔
607
  SMnode    *pMnode = pReq->info.node;
6,656✔
608
  SStatisReq statisReq = {0};
6,656✔
609
  int32_t    code = -1;
6,656✔
610

611
  TAOS_CHECK_RETURN(tDeserializeSStatisReq(pReq->pCont, pReq->contLen, &statisReq));
6,656!
612

613
  if (tsMonitorLogProtocol) {
6,656!
614
    mInfo("process statis req,\n %s", statisReq.pCont);
×
615
  }
616

617
  if (statisReq.type == MONITOR_TYPE_COUNTER) {
6,656✔
618
    monSendContent(statisReq.pCont, tsMonFwUri);
5,147✔
619
  } else if (statisReq.type == MONITOR_TYPE_SLOW_LOG) {
1,509!
620
    monSendContent(statisReq.pCont, tsMonSlowLogUri);
1,509✔
621
  }
622

623
  tFreeSStatisReq(&statisReq);
6,656✔
624
  return 0;
6,656✔
625
}
626

627
static int32_t mndProcessAuditReq(SRpcMsg *pReq) {
57,372✔
628
  mTrace("process audit req:%p", pReq);
57,372✔
629
  if (tsEnableAudit && tsEnableAuditDelete) {
57,373!
630
    SMnode   *pMnode = pReq->info.node;
57,372✔
631
    SAuditReq auditReq = {0};
57,372✔
632

633
    TAOS_CHECK_RETURN(tDeserializeSAuditReq(pReq->pCont, pReq->contLen, &auditReq));
57,372!
634

635
    mDebug("received audit req:%s, %s, %s, %s", auditReq.operation, auditReq.db, auditReq.table, auditReq.pSql);
57,372✔
636

637
    auditAddRecord(pReq, pMnode->clusterId, auditReq.operation, auditReq.db, auditReq.table, auditReq.pSql,
57,372✔
638
                   auditReq.sqlLen);
639

640
    tFreeSAuditReq(&auditReq);
57,371✔
641
  }
642
  return 0;
57,372✔
643
}
644

645
static int32_t mndUpdateDnodeObj(SMnode *pMnode, SDnodeObj *pDnode) {
4,728✔
646
  int32_t       code = 0, lino = 0;
4,728✔
647
  SDnodeInfoReq infoReq = {0};
4,728✔
648
  int32_t       contLen = 0;
4,728✔
649
  void         *pReq = NULL;
4,728✔
650

651
  infoReq.dnodeId = pDnode->id;
4,728✔
652
  tstrncpy(infoReq.machineId, pDnode->machineId, TSDB_MACHINE_ID_LEN + 1);
4,728✔
653

654
  if ((contLen = tSerializeSDnodeInfoReq(NULL, 0, &infoReq)) <= 0) {
4,728!
655
    TAOS_RETURN(contLen ? contLen : TSDB_CODE_OUT_OF_MEMORY);
×
656
  }
657
  pReq = rpcMallocCont(contLen);
4,728✔
658
  if (pReq == NULL) {
4,728!
659
    TAOS_RETURN(terrno);
×
660
  }
661

662
  if ((contLen = tSerializeSDnodeInfoReq(pReq, contLen, &infoReq)) <= 0) {
4,728!
663
    code = contLen;
×
664
    goto _exit;
×
665
  }
666

667
  SRpcMsg rpcMsg = {.msgType = TDMT_MND_UPDATE_DNODE_INFO, .pCont = pReq, .contLen = contLen};
4,728✔
668
  TAOS_CHECK_EXIT(tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg));
4,728!
669
_exit:
4,728✔
670
  if (code < 0) {
4,728!
671
    mError("dnode:%d, failed to update dnode info since %s", pDnode->id, tstrerror(code));
×
672
  }
673
  TAOS_RETURN(code);
4,728✔
674
}
675

676
static int32_t mndProcessUpdateDnodeInfoReq(SRpcMsg *pReq) {
4,724✔
677
  int32_t       code = 0, lino = 0;
4,724✔
678
  SMnode       *pMnode = pReq->info.node;
4,724✔
679
  SDnodeInfoReq infoReq = {0};
4,724✔
680
  SDnodeObj    *pDnode = NULL;
4,724✔
681
  STrans       *pTrans = NULL;
4,724✔
682
  SSdbRaw      *pCommitRaw = NULL;
4,724✔
683

684
  TAOS_CHECK_EXIT(tDeserializeSDnodeInfoReq(pReq->pCont, pReq->contLen, &infoReq));
4,724!
685

686
  pDnode = mndAcquireDnode(pMnode, infoReq.dnodeId);
4,724✔
687
  if (pDnode == NULL) {
4,724!
688
    TAOS_CHECK_EXIT(terrno);
×
689
  }
690

691
  pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, NULL, "update-dnode-obj");
4,724✔
692
  if (pTrans == NULL) {
4,724!
693
    TAOS_CHECK_EXIT(terrno);
×
694
  }
695

696
  pDnode->updateTime = taosGetTimestampMs();
4,724✔
697

698
  if ((pCommitRaw = mndDnodeActionEncode(pDnode)) == NULL) {
4,724!
699
    TAOS_CHECK_EXIT(terrno);
×
700
  }
701
  if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
4,724!
702
    mError("trans:%d, failed to append commit log since %s", pTrans->id, tstrerror(code));
×
703
    TAOS_CHECK_EXIT(code);
×
704
  }
705
  TAOS_CHECK_EXIT(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
4,724!
706
  pCommitRaw = NULL;
4,724✔
707

708
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
4,724!
709
    mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
×
710
    TAOS_CHECK_EXIT(code);
×
711
  }
712

713
_exit:
4,724✔
714
  mndReleaseDnode(pMnode, pDnode);
4,724✔
715
  if (code != 0) {
4,724!
716
    mError("dnode:%d, failed to update dnode info at line %d since %s", infoReq.dnodeId, lino, tstrerror(code));
×
717
  }
718
  mndTransDrop(pTrans);
4,724✔
719
  sdbFreeRaw(pCommitRaw);
4,724✔
720
  TAOS_RETURN(code);
4,724✔
721
}
722

723
static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
117,000✔
724
  SMnode    *pMnode = pReq->info.node;
117,000✔
725
  SStatusReq statusReq = {0};
117,000✔
726
  SDnodeObj *pDnode = NULL;
117,000✔
727
  int32_t    code = -1;
117,000✔
728

729
  TAOS_CHECK_GOTO(tDeserializeSStatusReq(pReq->pCont, pReq->contLen, &statusReq), NULL, _OVER);
117,000!
730

731
  int64_t clusterid = mndGetClusterId(pMnode);
117,000✔
732
  if (statusReq.clusterId != 0 && statusReq.clusterId != clusterid) {
117,000!
733
    code = TSDB_CODE_MND_DNODE_DIFF_CLUSTER;
×
734
    mWarn("dnode:%d, %s, its clusterid:%" PRId64 " differ from current clusterid:%" PRId64 ", code:0x%x",
×
735
          statusReq.dnodeId, statusReq.dnodeEp, statusReq.clusterId, clusterid, code);
736
    goto _OVER;
×
737
  }
738

739
  if (statusReq.dnodeId == 0) {
117,000✔
740
    pDnode = mndAcquireDnodeByEp(pMnode, statusReq.dnodeEp);
3,462✔
741
    if (pDnode == NULL) {
3,462✔
742
      mInfo("dnode:%s, not created yet", statusReq.dnodeEp);
743!
743
      code = TSDB_CODE_MND_RETURN_VALUE_NULL;
743✔
744
      if (terrno != 0) code = terrno;
743!
745
      goto _OVER;
743✔
746
    }
747
  } else {
748
    pDnode = mndAcquireDnode(pMnode, statusReq.dnodeId);
113,538✔
749
    if (pDnode == NULL) {
113,538✔
750
      int32_t err = terrno;
347✔
751
      pDnode = mndAcquireDnodeByEp(pMnode, statusReq.dnodeEp);
347✔
752
      if (pDnode != NULL) {
347✔
753
        pDnode->offlineReason = DND_REASON_DNODE_ID_NOT_MATCH;
6✔
754
        terrno = err;
6✔
755
        goto _OVER;
6✔
756
      }
757

758
      mError("dnode:%d, %s not exist, code:0x%x", statusReq.dnodeId, statusReq.dnodeEp, err);
341!
759
      if (err == TSDB_CODE_MND_DNODE_NOT_EXIST) {
341✔
760
        terrno = err;
73✔
761
        goto _OVER;
73✔
762
      } else {
763
        pDnode = mndAcquireDnodeAllStatusByEp(pMnode, statusReq.dnodeEp);
268✔
764
        if (pDnode == NULL) goto _OVER;
268!
765
      }
766
    }
767
  }
768

769
  pMnode->ipWhiteVer = mndGetIpWhiteVer(pMnode);
116,178✔
770

771
  int64_t analVer = sdbGetTableVer(pMnode->pSdb, SDB_ANODE);
116,178✔
772
  int64_t dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE) + sdbGetTableVer(pMnode->pSdb, SDB_MNODE);
116,178✔
773
  int64_t curMs = taosGetTimestampMs();
116,178✔
774
  bool    online = mndIsDnodeOnline(pDnode, curMs);
116,178✔
775
  bool    dnodeChanged = (statusReq.dnodeVer == 0) || (statusReq.dnodeVer != dnodeVer);
116,178✔
776
  bool    reboot = (pDnode->rebootTime != statusReq.rebootTime);
116,178✔
777
  bool    supportVnodesChanged = pDnode->numOfSupportVnodes != statusReq.numOfSupportVnodes;
116,178✔
778
  bool    encryptKeyChanged = pDnode->encryptionKeyChksum != statusReq.clusterCfg.encryptionKeyChksum;
116,178✔
779
  bool    enableWhiteListChanged = statusReq.clusterCfg.enableWhiteList != (tsEnableWhiteList ? 1 : 0);
116,178✔
780
  bool    analVerChanged = (analVer != statusReq.analVer);
116,178✔
781
  bool    needCheck = !online || dnodeChanged || reboot || supportVnodesChanged || analVerChanged ||
113,189!
782
                   pMnode->ipWhiteVer != statusReq.ipWhiteVer || encryptKeyChanged || enableWhiteListChanged;
229,367!
783
  const STraceId *trace = &pReq->info.traceId;
116,178✔
784
  char            timestamp[TD_TIME_STR_LEN] = {0};
116,178✔
785
  if (mDebugFlag & DEBUG_TRACE) (void)formatTimestampLocal(timestamp, statusReq.timestamp, TSDB_TIME_PRECISION_MILLI);
116,178✔
786
  mGTrace(
116,178!
787
      "dnode:%d, status received, accessTimes:%d check:%d online:%d reboot:%d changed:%d statusSeq:%d "
788
      "timestamp:%s",
789
      pDnode->id, pDnode->accessTimes, needCheck, online, reboot, dnodeChanged, statusReq.statusSeq, timestamp);
790

791
  if (reboot) {
116,178✔
792
    tsGrantHBInterval = GRANT_HEART_BEAT_MIN;
3,027✔
793
  }
794

795
  for (int32_t v = 0; v < taosArrayGetSize(statusReq.pVloads); ++v) {
782,094✔
796
    SVnodeLoad *pVload = taosArrayGet(statusReq.pVloads, v);
665,916✔
797

798
    SVgObj *pVgroup = mndAcquireVgroup(pMnode, pVload->vgId);
665,916✔
799
    if (pVgroup != NULL) {
665,916✔
800
      if (pVload->syncState == TAOS_SYNC_STATE_LEADER || pVload->syncState == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
662,178!
801
        pVgroup->cacheUsage = pVload->cacheUsage;
617,026✔
802
        pVgroup->numOfCachedTables = pVload->numOfCachedTables;
617,026✔
803
        pVgroup->numOfTables = pVload->numOfTables;
617,026✔
804
        pVgroup->numOfTimeSeries = pVload->numOfTimeSeries;
617,026✔
805
        pVgroup->totalStorage = pVload->totalStorage;
617,026✔
806
        pVgroup->compStorage = pVload->compStorage;
617,026✔
807
        pVgroup->pointsWritten = pVload->pointsWritten;
617,026✔
808
      }
809
      bool stateChanged = false;
662,178✔
810
      for (int32_t vg = 0; vg < pVgroup->replica; ++vg) {
723,234✔
811
        SVnodeGid *pGid = &pVgroup->vnodeGid[vg];
723,146✔
812
        if (pGid->dnodeId == statusReq.dnodeId) {
723,146✔
813
          if (pVload->startTimeMs == 0) {
662,090!
814
            pVload->startTimeMs = statusReq.rebootTime;
×
815
          }
816
          if (pVload->roleTimeMs == 0) {
662,090!
817
            pVload->roleTimeMs = statusReq.rebootTime;
×
818
          }
819
          stateChanged = mndUpdateVnodeState(pVgroup->vgId, pGid, pVload);
662,090✔
820
          break;
662,090✔
821
        }
822
      }
823
      if (stateChanged) {
662,178✔
824
        SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName);
16,648✔
825
        if (pDb != NULL && pDb->stateTs != curMs) {
16,648✔
826
          mInfo("db:%s, stateTs changed by status msg, old stateTs:%" PRId64 " new stateTs:%" PRId64, pDb->name,
9,803!
827
                pDb->stateTs, curMs);
828
          pDb->stateTs = curMs;
9,803✔
829
        }
830
        mndReleaseDb(pMnode, pDb);
16,648✔
831
      }
832
    }
833

834
    mndReleaseVgroup(pMnode, pVgroup);
665,916✔
835
  }
836

837
  SMnodeObj *pObj = mndAcquireMnode(pMnode, pDnode->id);
116,178✔
838
  if (pObj != NULL) {
116,178✔
839
    if (statusReq.mload.roleTimeMs == 0) {
77,181✔
840
      statusReq.mload.roleTimeMs = statusReq.rebootTime;
2,089✔
841
    }
842
    (void)mndUpdateMnodeState(pObj, &statusReq.mload);
77,181✔
843
    mndReleaseMnode(pMnode, pObj);
77,181✔
844
  }
845

846
  SQnodeObj *pQnode = mndAcquireQnode(pMnode, statusReq.qload.dnodeId);
116,178✔
847
  if (pQnode != NULL) {
116,178✔
848
    pQnode->load = statusReq.qload;
42,160✔
849
    mndReleaseQnode(pMnode, pQnode);
42,160✔
850
  }
851

852
  if (needCheck) {
116,178✔
853
    if (statusReq.sver != tsVersion) {
10,592!
854
      if (pDnode != NULL) {
×
855
        pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH;
×
856
      }
857
      mError("dnode:%d, status msg version:%d not match cluster:%d", statusReq.dnodeId, statusReq.sver, tsVersion);
×
858
      terrno = TSDB_CODE_VERSION_NOT_COMPATIBLE;
×
859
      goto _OVER;
×
860
    }
861

862
    if (statusReq.dnodeId == 0) {
10,592✔
863
      mInfo("dnode:%d, %s first access, clusterId:%" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId);
2,719!
864
    } else {
865
      if (statusReq.clusterId != pMnode->clusterId) {
7,873!
866
        if (pDnode != NULL) {
×
867
          pDnode->offlineReason = DND_REASON_CLUSTER_ID_NOT_MATCH;
×
868
        }
869
        mError("dnode:%d, clusterId %" PRId64 " not match exist %" PRId64, pDnode->id, statusReq.clusterId,
×
870
               pMnode->clusterId);
871
        terrno = TSDB_CODE_MND_INVALID_CLUSTER_ID;
×
872
        goto _OVER;
×
873
      }
874
    }
875

876
    // Verify whether the cluster parameters are consistent when status change from offline to ready
877
    pDnode->offlineReason = mndCheckClusterCfgPara(pMnode, pDnode, &statusReq.clusterCfg);
10,592✔
878
    if (pDnode->offlineReason != 0) {
10,592!
879
      mError("dnode:%d, cluster cfg inconsistent since:%s", pDnode->id, offlineReason[pDnode->offlineReason]);
×
880
      if (terrno == 0) terrno = TSDB_CODE_MND_INVALID_CLUSTER_CFG;
×
881
      goto _OVER;
×
882
    }
883

884
    if (!online) {
10,592✔
885
      mInfo("dnode:%d, from offline to online, memory avail:%" PRId64 " total:%" PRId64 " cores:%.2f", pDnode->id,
2,989!
886
            statusReq.memAvail, statusReq.memTotal, statusReq.numOfCores);
887
    } else {
888
      mInfo("dnode:%d, send dnode epset, online:%d dnodeVer:%" PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online,
7,603!
889
            statusReq.dnodeVer, dnodeVer, reboot);
890
    }
891

892
    pDnode->rebootTime = statusReq.rebootTime;
10,592✔
893
    pDnode->numOfCores = statusReq.numOfCores;
10,592✔
894
    pDnode->numOfSupportVnodes = statusReq.numOfSupportVnodes;
10,592✔
895
    pDnode->numOfDiskCfg = statusReq.numOfDiskCfg;
10,592✔
896
    pDnode->memAvail = statusReq.memAvail;
10,592✔
897
    pDnode->memTotal = statusReq.memTotal;
10,592✔
898
    pDnode->encryptionKeyStat = statusReq.clusterCfg.encryptionKeyStat;
10,592✔
899
    pDnode->encryptionKeyChksum = statusReq.clusterCfg.encryptionKeyChksum;
10,592✔
900
    if (memcmp(pDnode->machineId, statusReq.machineId, TSDB_MACHINE_ID_LEN) != 0) {
10,592✔
901
      tstrncpy(pDnode->machineId, statusReq.machineId, TSDB_MACHINE_ID_LEN + 1);
4,728✔
902
      if ((terrno = mndUpdateDnodeObj(pMnode, pDnode)) != 0) {
4,728!
903
        goto _OVER;
×
904
      }
905
    }
906

907
    SStatusRsp statusRsp = {0};
10,592✔
908
    statusRsp.statusSeq++;
10,592✔
909
    statusRsp.analVer = analVer;
10,592✔
910
    statusRsp.dnodeVer = dnodeVer;
10,592✔
911
    statusRsp.dnodeCfg.dnodeId = pDnode->id;
10,592✔
912
    statusRsp.dnodeCfg.clusterId = pMnode->clusterId;
10,592✔
913
    statusRsp.pDnodeEps = taosArrayInit(mndGetDnodeSize(pMnode), sizeof(SDnodeEp));
10,592✔
914
    if (statusRsp.pDnodeEps == NULL) {
10,592!
915
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
916
      goto _OVER;
×
917
    }
918

919
    mndGetDnodeEps(pMnode, statusRsp.pDnodeEps);
10,592✔
920
    statusRsp.ipWhiteVer = pMnode->ipWhiteVer;
10,592✔
921

922
    int32_t contLen = tSerializeSStatusRsp(NULL, 0, &statusRsp);
10,592✔
923
    void   *pHead = rpcMallocCont(contLen);
10,592✔
924
    contLen = tSerializeSStatusRsp(pHead, contLen, &statusRsp);
10,592✔
925
    taosArrayDestroy(statusRsp.pDnodeEps);
10,592✔
926
    if (contLen < 0) {
10,592!
927
      code = contLen;
×
928
      goto _OVER;
×
929
    }
930

931
    pReq->info.rspLen = contLen;
10,592✔
932
    pReq->info.rsp = pHead;
10,592✔
933
  }
934

935
  pDnode->accessTimes++;
116,178✔
936
  pDnode->lastAccessTime = curMs;
116,178✔
937
  code = 0;
116,178✔
938

939
_OVER:
117,000✔
940
  mndReleaseDnode(pMnode, pDnode);
117,000✔
941
  taosArrayDestroy(statusReq.pVloads);
117,000✔
942
  return mndUpdClusterInfo(pReq);
117,000✔
943
}
944

945
static int32_t mndProcessNotifyReq(SRpcMsg *pReq) {
×
946
  SMnode    *pMnode = pReq->info.node;
×
947
  SNotifyReq notifyReq = {0};
×
948
  int32_t    code = 0;
×
949

950
  if ((code = tDeserializeSNotifyReq(pReq->pCont, pReq->contLen, &notifyReq)) != 0) {
×
951
    terrno = code;
×
952
    goto _OVER;
×
953
  }
954

955
  int64_t clusterid = mndGetClusterId(pMnode);
×
956
  if (notifyReq.clusterId != 0 && notifyReq.clusterId != clusterid) {
×
957
    code = TSDB_CODE_MND_DNODE_DIFF_CLUSTER;
×
958
    mWarn("dnode:%d, its clusterid:%" PRId64 " differ from current cluster:%" PRId64 " since %s", notifyReq.dnodeId,
×
959
          notifyReq.clusterId, clusterid, tstrerror(code));
960
    goto _OVER;
×
961
  }
962

963
  int32_t nVgroup = taosArrayGetSize(notifyReq.pVloads);
×
964
  for (int32_t v = 0; v < nVgroup; ++v) {
×
965
    SVnodeLoadLite *pVload = taosArrayGet(notifyReq.pVloads, v);
×
966

967
    SVgObj *pVgroup = mndAcquireVgroup(pMnode, pVload->vgId);
×
968
    if (pVgroup != NULL) {
×
969
      pVgroup->numOfTimeSeries = pVload->nTimeSeries;
×
970
      mndReleaseVgroup(pMnode, pVgroup);
×
971
    }
972
  }
973
  code = mndUpdClusterInfo(pReq);
×
974
_OVER:
×
975
  tFreeSNotifyReq(&notifyReq);
×
976
  return code;
×
977
}
978

979
static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pCreate) {
489✔
980
  int32_t  code = -1;
489✔
981
  SSdbRaw *pRaw = NULL;
489✔
982
  STrans  *pTrans = NULL;
489✔
983

984
  SDnodeObj dnodeObj = {0};
489✔
985
  dnodeObj.id = sdbGetMaxId(pMnode->pSdb, SDB_DNODE);
489✔
986
  dnodeObj.createdTime = taosGetTimestampMs();
489✔
987
  dnodeObj.updateTime = dnodeObj.createdTime;
489✔
988
  dnodeObj.port = pCreate->port;
489✔
989
  tstrncpy(dnodeObj.fqdn, pCreate->fqdn, TSDB_FQDN_LEN);
489✔
990
  (void)snprintf(dnodeObj.ep, TSDB_EP_LEN - 1, "%s:%u", pCreate->fqdn, pCreate->port);
489✔
991

992
  pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_GLOBAL, pReq, "create-dnode");
489✔
993
  if (pTrans == NULL) {
489!
994
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
995
    if (terrno != 0) code = terrno;
×
996
    goto _OVER;
×
997
  }
998
  mInfo("trans:%d, used to create dnode:%s", pTrans->id, dnodeObj.ep);
489!
999
  TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
489!
1000

1001
  pRaw = mndDnodeActionEncode(&dnodeObj);
489✔
1002
  if (pRaw == NULL) {
489!
1003
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
1004
    if (terrno != 0) code = terrno;
×
1005
    goto _OVER;
×
1006
  }
1007
  TAOS_CHECK_GOTO(mndTransAppendCommitlog(pTrans, pRaw), NULL, _OVER);
489!
1008
  TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_READY), NULL, _OVER);
489!
1009
  pRaw = NULL;
489✔
1010

1011
  TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
489!
1012
  code = 0;
489✔
1013

1014
  (void)mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, dnodeObj.fqdn, IP_WHITE_ADD,
489✔
1015
                                   1);  // TODO: check the return value
1016
_OVER:
489✔
1017
  mndTransDrop(pTrans);
489✔
1018
  sdbFreeRaw(pRaw);
489✔
1019
  return code;
489✔
1020
}
1021

1022
static int32_t mndProcessDnodeListReq(SRpcMsg *pReq) {
7,558✔
1023
  SMnode       *pMnode = pReq->info.node;
7,558✔
1024
  SSdb         *pSdb = pMnode->pSdb;
7,558✔
1025
  SDnodeObj    *pObj = NULL;
7,558✔
1026
  void         *pIter = NULL;
7,558✔
1027
  SDnodeListRsp rsp = {0};
7,558✔
1028
  int32_t       code = -1;
7,558✔
1029

1030
  rsp.dnodeList = taosArrayInit(5, sizeof(SDNodeAddr));
7,558✔
1031
  if (NULL == rsp.dnodeList) {
7,558!
1032
    mError("failed to alloc epSet while process dnode list req");
×
1033
    code = terrno;
×
1034
    goto _OVER;
×
1035
  }
1036

1037
  while (1) {
7,894✔
1038
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pObj);
15,452✔
1039
    if (pIter == NULL) break;
15,452✔
1040

1041
    SDNodeAddr dnodeAddr = {0};
7,894✔
1042
    dnodeAddr.nodeId = pObj->id;
7,894✔
1043
    dnodeAddr.epSet.numOfEps = 1;
7,894✔
1044
    tstrncpy(dnodeAddr.epSet.eps[0].fqdn, pObj->fqdn, TSDB_FQDN_LEN);
7,894✔
1045
    dnodeAddr.epSet.eps[0].port = pObj->port;
7,894✔
1046

1047
    if (taosArrayPush(rsp.dnodeList, &dnodeAddr) == NULL) {
15,788!
1048
      if (terrno != 0) code = terrno;
×
1049
      sdbRelease(pSdb, pObj);
×
1050
      sdbCancelFetch(pSdb, pIter);
×
1051
      goto _OVER;
×
1052
    }
1053

1054
    sdbRelease(pSdb, pObj);
7,894✔
1055
  }
1056

1057
  int32_t rspLen = tSerializeSDnodeListRsp(NULL, 0, &rsp);
7,558✔
1058
  void   *pRsp = rpcMallocCont(rspLen);
7,558✔
1059
  if (pRsp == NULL) {
7,558!
1060
    code = terrno;
×
1061
    goto _OVER;
×
1062
  }
1063

1064
  if ((rspLen = tSerializeSDnodeListRsp(pRsp, rspLen, &rsp)) <= 0) {
7,558!
1065
    code = rspLen;
×
1066
    goto _OVER;
×
1067
  }
1068

1069
  pReq->info.rspLen = rspLen;
7,558✔
1070
  pReq->info.rsp = pRsp;
7,558✔
1071
  code = 0;
7,558✔
1072

1073
_OVER:
7,558✔
1074

1075
  if (code != 0) {
7,558!
1076
    mError("failed to get dnode list since %s", tstrerror(code));
×
1077
  }
1078

1079
  tFreeSDnodeListRsp(&rsp);
7,558✔
1080

1081
  TAOS_RETURN(code);
7,558✔
1082
}
1083

1084
void getSlowLogScopeString(int32_t scope, char *result) {
1,443✔
1085
  if (scope == SLOW_LOG_TYPE_NULL) {
1,443!
1086
    (void)strncat(result, "NONE", 64);
×
1087
    return;
×
1088
  }
1089
  while (scope > 0) {
5,762✔
1090
    if (scope & SLOW_LOG_TYPE_QUERY) {
4,319✔
1091
      (void)strncat(result, "QUERY", 64);
1,444✔
1092
      scope &= ~SLOW_LOG_TYPE_QUERY;
1,444✔
1093
    } else if (scope & SLOW_LOG_TYPE_INSERT) {
2,875✔
1094
      (void)strncat(result, "INSERT", 64);
1,438✔
1095
      scope &= ~SLOW_LOG_TYPE_INSERT;
1,438✔
1096
    } else if (scope & SLOW_LOG_TYPE_OTHERS) {
1,437!
1097
      (void)strncat(result, "OTHERS", 64);
1,437✔
1098
      scope &= ~SLOW_LOG_TYPE_OTHERS;
1,437✔
1099
    } else {
1100
      (void)printf("invalid slow log scope:%d", scope);
×
1101
      return;
×
1102
    }
1103

1104
    if (scope > 0) {
4,319✔
1105
      (void)strncat(result, "|", 64);
2,874✔
1106
    }
1107
  }
1108
}
1109

1110
static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) {
490✔
1111
  SMnode         *pMnode = pReq->info.node;
490✔
1112
  int32_t         code = -1;
490✔
1113
  SDnodeObj      *pDnode = NULL;
490✔
1114
  SCreateDnodeReq createReq = {0};
490✔
1115
  int32_t         lino = 0;
490✔
1116

1117
  if ((code = grantCheck(TSDB_GRANT_DNODE)) != 0 || (code = grantCheck(TSDB_GRANT_CPU_CORES)) != 0) {
490!
1118
    goto _OVER;
×
1119
  }
1120

1121
  code = tDeserializeSCreateDnodeReq(pReq->pCont, pReq->contLen, &createReq);
490✔
1122
  TAOS_CHECK_GOTO(code, &lino, _OVER);
490!
1123

1124
  mInfo("dnode:%s:%d, start to create", createReq.fqdn, createReq.port);
490!
1125
  code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_DNODE);
490✔
1126
  TAOS_CHECK_GOTO(code, &lino, _OVER);
490✔
1127

1128
  if (createReq.fqdn[0] == 0 || createReq.port <= 0 || createReq.port > UINT16_MAX) {
489!
1129
    code = TSDB_CODE_MND_INVALID_DNODE_EP;
×
1130
    goto _OVER;
×
1131
  }
1132
  // code = taosValidFqdn(tsEnableIpv6, createReq.fqdn);
1133
  // if (code != 0) {
1134
  //   mError("ipv6 flag %d, the local FQDN %s does not resolve to the ip address since %s", tsEnableIpv6, tsLocalFqdn,
1135
  //          tstrerror(code));
1136
  //   goto _OVER;
1137
  // }
1138

1139
  char ep[TSDB_EP_LEN];
1140
  (void)snprintf(ep, TSDB_EP_LEN, "%s:%d", createReq.fqdn, createReq.port);
489✔
1141
  pDnode = mndAcquireDnodeByEp(pMnode, ep);
489✔
1142
  if (pDnode != NULL) {
489!
1143
    code = TSDB_CODE_MND_DNODE_ALREADY_EXIST;
×
1144
    goto _OVER;
×
1145
  }
1146

1147
  code = mndCreateDnode(pMnode, pReq, &createReq);
489✔
1148
  if (code == 0) {
489!
1149
    code = TSDB_CODE_ACTION_IN_PROGRESS;
489✔
1150
    tsGrantHBInterval = 5;
489✔
1151
  }
1152

1153
  char obj[200] = {0};
489✔
1154
  (void)tsnprintf(obj, sizeof(obj), "%s:%d", createReq.fqdn, createReq.port);
489✔
1155

1156
  auditRecord(pReq, pMnode->clusterId, "createDnode", "", obj, createReq.sql, createReq.sqlLen);
489✔
1157

1158
_OVER:
490✔
1159
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
490!
1160
    mError("dnode:%s:%d, failed to create since %s", createReq.fqdn, createReq.port, tstrerror(code));
1!
1161
  }
1162

1163
  mndReleaseDnode(pMnode, pDnode);
490✔
1164
  tFreeSCreateDnodeReq(&createReq);
490✔
1165
  TAOS_RETURN(code);
490✔
1166
}
1167

1168
extern int32_t mndProcessRestoreDnodeReqImpl(SRpcMsg *pReq);
1169

1170
int32_t mndProcessRestoreDnodeReq(SRpcMsg *pReq) { return mndProcessRestoreDnodeReqImpl(pReq); }
7✔
1171

1172
#ifndef TD_ENTERPRISE
1173
int32_t mndProcessRestoreDnodeReqImpl(SRpcMsg *pReq) { return 0; }
1174
#endif
1175

1176
static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMnodeObj *pMObj, SQnodeObj *pQObj,
24✔
1177
                            SSnodeObj *pSObj, int32_t numOfVnodes, bool force, bool unsafe) {
1178
  int32_t  code = -1;
24✔
1179
  SSdbRaw *pRaw = NULL;
24✔
1180
  STrans  *pTrans = NULL;
24✔
1181
  int32_t  lino = 0;
24✔
1182

1183
  pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "drop-dnode");
24✔
1184
  if (pTrans == NULL) {
24!
1185
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
1186
    if (terrno != 0) code = terrno;
×
1187
    goto _OVER;
×
1188
  }
1189
  mndTransSetGroupParallel(pTrans);
24✔
1190
  mInfo("trans:%d, used to drop dnode:%d, force:%d", pTrans->id, pDnode->id, force);
24!
1191
  TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), &lino, _OVER);
24!
1192

1193
  pRaw = mndDnodeActionEncode(pDnode);
24✔
1194
  if (pRaw == NULL) {
24!
1195
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
1196
    if (terrno != 0) code = terrno;
×
1197
    goto _OVER;
×
1198
  }
1199
  TAOS_CHECK_GOTO(mndTransAppendGroupRedolog(pTrans, pRaw, -1), &lino, _OVER);
24!
1200
  TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_DROPPING), &lino, _OVER);
24!
1201
  pRaw = NULL;
24✔
1202

1203
  pRaw = mndDnodeActionEncode(pDnode);
24✔
1204
  if (pRaw == NULL) {
24!
1205
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
1206
    if (terrno != 0) code = terrno;
×
1207
    goto _OVER;
×
1208
  }
1209
  TAOS_CHECK_GOTO(mndTransAppendCommitlog(pTrans, pRaw), &lino, _OVER);
24!
1210
  TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED), &lino, _OVER);
24!
1211
  pRaw = NULL;
24✔
1212

1213
  if (pMObj != NULL) {
24✔
1214
    mInfo("trans:%d, mnode on dnode:%d will be dropped", pTrans->id, pDnode->id);
4!
1215
    TAOS_CHECK_GOTO(mndSetDropMnodeInfoToTrans(pMnode, pTrans, pMObj, force), &lino, _OVER);
4!
1216
  }
1217

1218
  if (pQObj != NULL) {
24✔
1219
    mInfo("trans:%d, qnode on dnode:%d will be dropped", pTrans->id, pDnode->id);
3!
1220
    TAOS_CHECK_GOTO(mndSetDropQnodeInfoToTrans(pMnode, pTrans, pQObj, force), &lino, _OVER);
3!
1221
  }
1222

1223
  if (pSObj != NULL) {
24✔
1224
    mInfo("trans:%d, snode on dnode:%d will be dropped", pTrans->id, pDnode->id);
3!
1225
    TAOS_CHECK_GOTO(mndSetDropSnodeInfoToTrans(pMnode, pTrans, pSObj, force), &lino, _OVER);
3!
1226
  }
1227

1228
  if (numOfVnodes > 0) {
24✔
1229
    mInfo("trans:%d, %d vnodes on dnode:%d will be dropped", pTrans->id, numOfVnodes, pDnode->id);
14!
1230
    TAOS_CHECK_GOTO(mndSetMoveVgroupsInfoToTrans(pMnode, pTrans, pDnode->id, force, unsafe), NULL, _OVER);
14✔
1231
  }
1232

1233
  TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), &lino, _OVER);
23!
1234

1235
  code = 0;
23✔
1236

1237
_OVER:
24✔
1238
  if (code != 0) mError("dnode:%d, failed to drop dnode at line:%d since %s", pDnode->id, lino, tstrerror(code));
24!
1239
  mndTransDrop(pTrans);
24✔
1240
  sdbFreeRaw(pRaw);
24✔
1241
  TAOS_RETURN(code);
24✔
1242
}
1243

1244
static bool mndIsEmptyDnode(SMnode *pMnode, int32_t dnodeId) {
×
1245
  bool       isEmpty = false;
×
1246
  SMnodeObj *pMObj = NULL;
×
1247
  SQnodeObj *pQObj = NULL;
×
1248
  SSnodeObj *pSObj = NULL;
×
1249

1250
  pQObj = mndAcquireQnode(pMnode, dnodeId);
×
1251
  if (pQObj) goto _OVER;
×
1252

1253
  pSObj = mndAcquireSnode(pMnode, dnodeId);
×
1254
  if (pSObj) goto _OVER;
×
1255

1256
  pMObj = mndAcquireMnode(pMnode, dnodeId);
×
1257
  if (pMObj) goto _OVER;
×
1258

1259
  int32_t numOfVnodes = mndGetVnodesNum(pMnode, dnodeId);
×
1260
  if (numOfVnodes > 0) goto _OVER;
×
1261

1262
  isEmpty = true;
×
1263
_OVER:
×
1264
  mndReleaseMnode(pMnode, pMObj);
×
1265
  mndReleaseQnode(pMnode, pQObj);
×
1266
  mndReleaseSnode(pMnode, pSObj);
×
1267
  return isEmpty;
×
1268
}
1269

1270
static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) {
29✔
1271
  SMnode       *pMnode = pReq->info.node;
29✔
1272
  int32_t       code = -1;
29✔
1273
  SDnodeObj    *pDnode = NULL;
29✔
1274
  SMnodeObj    *pMObj = NULL;
29✔
1275
  SQnodeObj    *pQObj = NULL;
29✔
1276
  SSnodeObj    *pSObj = NULL;
29✔
1277
  SDropDnodeReq dropReq = {0};
29✔
1278

1279
  TAOS_CHECK_GOTO(tDeserializeSDropDnodeReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER);
29!
1280

1281
  mInfo("dnode:%d, start to drop, ep:%s:%d, force:%s, unsafe:%s", dropReq.dnodeId, dropReq.fqdn, dropReq.port,
29!
1282
        dropReq.force ? "true" : "false", dropReq.unsafe ? "true" : "false");
1283
  TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE), NULL, _OVER);
29✔
1284

1285
  bool force = dropReq.force;
28✔
1286
  if (dropReq.unsafe) {
28✔
1287
    force = true;
1✔
1288
  }
1289

1290
  pDnode = mndAcquireDnode(pMnode, dropReq.dnodeId);
28✔
1291
  if (pDnode == NULL) {
28!
1292
    int32_t err = terrno;
×
1293
    char    ep[TSDB_EP_LEN + 1] = {0};
×
1294
    (void)snprintf(ep, sizeof(ep), dropReq.fqdn, dropReq.port);
×
1295
    pDnode = mndAcquireDnodeByEp(pMnode, ep);
×
1296
    if (pDnode == NULL) {
×
1297
      code = err;
×
1298
      goto _OVER;
×
1299
    }
1300
  }
1301

1302
  pQObj = mndAcquireQnode(pMnode, dropReq.dnodeId);
28✔
1303
  pSObj = mndAcquireSnode(pMnode, dropReq.dnodeId);
28✔
1304
  pMObj = mndAcquireMnode(pMnode, dropReq.dnodeId);
28✔
1305
  if (pMObj != NULL) {
28✔
1306
    if (sdbGetSize(pMnode->pSdb, SDB_MNODE) <= 1) {
8✔
1307
      code = TSDB_CODE_MND_TOO_FEW_MNODES;
1✔
1308
      goto _OVER;
1✔
1309
    }
1310
    if (pMnode->selfDnodeId == dropReq.dnodeId) {
7✔
1311
      code = TSDB_CODE_MND_CANT_DROP_LEADER;
2✔
1312
      goto _OVER;
2✔
1313
    }
1314
  }
1315

1316
  int32_t numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id);
25✔
1317
  bool    isonline = mndIsDnodeOnline(pDnode, taosGetTimestampMs());
25✔
1318

1319
  if (isonline && force) {
25!
1320
    code = TSDB_CODE_DNODE_ONLY_USE_WHEN_OFFLINE;
×
1321
    mError("dnode:%d, failed to drop since %s, vnodes:%d mnode:%d qnode:%d snode:%d", pDnode->id, tstrerror(code),
×
1322
           numOfVnodes, pMObj != NULL, pQObj != NULL, pSObj != NULL);
1323
    goto _OVER;
×
1324
  }
1325

1326
  bool    vnodeOffline = false;
25✔
1327
  void   *pIter = NULL;
25✔
1328
  int32_t vgId = -1;
25✔
1329
  while (1) {
37✔
1330
    SVgObj *pVgroup = NULL;
62✔
1331
    pIter = sdbFetch(pMnode->pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
62✔
1332
    if (pIter == NULL) break;
62✔
1333

1334
    for (int32_t i = 0; i < pVgroup->replica; ++i) {
118✔
1335
      if (pVgroup->vnodeGid[i].dnodeId == pDnode->id) {
81✔
1336
        if (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_OFFLINE) {
30✔
1337
          vgId = pVgroup->vgId;
3✔
1338
          vnodeOffline = true;
3✔
1339
          break;
3✔
1340
        }
1341
      }
1342
    }
1343

1344
    sdbRelease(pMnode->pSdb, pVgroup);
40✔
1345

1346
    if (vnodeOffline) {
40✔
1347
      sdbCancelFetch(pMnode->pSdb, pIter);
3✔
1348
      break;
3✔
1349
    }
1350
  }
1351

1352
  if (vnodeOffline && !force) {
25✔
1353
    code = TSDB_CODE_VND_VNODE_OFFLINE;
1✔
1354
    mError("dnode:%d, failed to drop since vgId:%d is offline, vnodes:%d mnode:%d qnode:%d snode:%d", pDnode->id, vgId,
1!
1355
           numOfVnodes, pMObj != NULL, pQObj != NULL, pSObj != NULL);
1356
    goto _OVER;
1✔
1357
  }
1358

1359
  code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes, force, dropReq.unsafe);
24✔
1360
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
24✔
1361

1362
  char obj1[30] = {0};
24✔
1363
  (void)tsnprintf(obj1, sizeof(obj1), "%d", dropReq.dnodeId);
24✔
1364

1365
  auditRecord(pReq, pMnode->clusterId, "dropDnode", "", obj1, dropReq.sql, dropReq.sqlLen);
24✔
1366

1367
_OVER:
29✔
1368
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
29!
1369
    mError("dnode:%d, failed to drop since %s", dropReq.dnodeId, tstrerror(code));
6!
1370
  }
1371

1372
  mndReleaseDnode(pMnode, pDnode);
29✔
1373
  mndReleaseMnode(pMnode, pMObj);
29✔
1374
  mndReleaseQnode(pMnode, pQObj);
29✔
1375
  mndReleaseSnode(pMnode, pSObj);
29✔
1376
  tFreeSDropDnodeReq(&dropReq);
29✔
1377
  TAOS_RETURN(code);
29✔
1378
}
1379

1380
static int32_t mndProcessCreateEncryptKeyReqImpl(SRpcMsg *pReq, int32_t dnodeId, SDCfgDnodeReq *pDcfgReq) {
1✔
1381
  int32_t code = 0;
1✔
1382
  SMnode *pMnode = pReq->info.node;
1✔
1383
  SSdb   *pSdb = pMnode->pSdb;
1✔
1384
  void   *pIter = NULL;
1✔
1385
  int8_t  encrypting = 0;
1✔
1386

1387
  const STraceId *trace = &pReq->info.traceId;
1✔
1388

1389
  int32_t klen = strlen(pDcfgReq->value);
1✔
1390
  if (klen > ENCRYPT_KEY_LEN || klen < ENCRYPT_KEY_LEN_MIN) {
1!
1391
    code = TSDB_CODE_DNODE_INVALID_ENCRYPT_KLEN;
×
1392
    mGError("msg:%p, failed to create encrypt_key since invalid key length:%d, valid range:[%d, %d]", pReq, klen,
×
1393
            ENCRYPT_KEY_LEN_MIN, ENCRYPT_KEY_LEN);
1394
    goto _exit;
×
1395
  }
1396

1397
  if (0 != (encrypting = atomic_val_compare_exchange_8(&pMnode->encryptMgmt.encrypting, 0, 1))) {
1!
1398
    code = TSDB_CODE_QRY_DUPLICATED_OPERATION;
×
1399
    mGWarn("msg:%p, failed to create encrypt key since %s, encrypting:%" PRIi8, pReq, tstrerror(code), encrypting);
×
1400
    goto _exit;
×
1401
  }
1402

1403
  if (tsEncryptionKeyStat == ENCRYPT_KEY_STAT_SET || tsEncryptionKeyStat == ENCRYPT_KEY_STAT_LOADED) {
1!
1404
    atomic_store_8(&pMnode->encryptMgmt.encrypting, 0);
×
1405
    code = TSDB_CODE_QRY_DUPLICATED_OPERATION;
×
1406
    mGWarn("msg:%p, failed to create encrypt key since %s, stat:%" PRIi8 ", checksum:%u", pReq, tstrerror(code),
×
1407
           tsEncryptionKeyStat, tsEncryptionKeyChksum);
1408
    goto _exit;
×
1409
  }
1410

1411
  atomic_store_16(&pMnode->encryptMgmt.nEncrypt, 0);
1✔
1412
  atomic_store_16(&pMnode->encryptMgmt.nSuccess, 0);
1✔
1413
  atomic_store_16(&pMnode->encryptMgmt.nFailed, 0);
1✔
1414

1415
  while (1) {
1✔
1416
    SDnodeObj *pDnode = NULL;
2✔
1417
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
2✔
1418
    if (pIter == NULL) break;
2✔
1419
    if (pDnode->offlineReason != DND_REASON_ONLINE) {
1!
1420
      mGWarn("msg:%p, don't send create encrypt_key req since dnode:%d in offline state:%s", pReq, pDnode->id,
×
1421
             offlineReason[pDnode->offlineReason]);
1422
      sdbRelease(pSdb, pDnode);
×
1423
      continue;
×
1424
    }
1425

1426
    if (dnodeId == -1 || pDnode->id == dnodeId || dnodeId == 0) {
1!
1427
      SEpSet  epSet = mndGetDnodeEpset(pDnode);
1✔
1428
      int32_t bufLen = tSerializeSDCfgDnodeReq(NULL, 0, pDcfgReq);
1✔
1429
      void   *pBuf = rpcMallocCont(bufLen);
1✔
1430

1431
      if (pBuf != NULL) {
1!
1432
        if ((bufLen = tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq)) <= 0) {
1!
1433
          code = bufLen;
×
1434
          sdbRelease(pSdb, pDnode);
×
1435
          goto _exit;
×
1436
        }
1437
        SRpcMsg rpcMsg = {.msgType = TDMT_DND_CREATE_ENCRYPT_KEY, .pCont = pBuf, .contLen = bufLen};
1✔
1438
        if (0 == tmsgSendReq(&epSet, &rpcMsg)) {
1!
1439
          (void)atomic_add_fetch_16(&pMnode->encryptMgmt.nEncrypt, 1);
1✔
1440
        }
1441
      }
1442
    }
1443

1444
    sdbRelease(pSdb, pDnode);
1✔
1445
  }
1446

1447
  if (atomic_load_16(&pMnode->encryptMgmt.nEncrypt) <= 0) {
1!
1448
    atomic_store_8(&pMnode->encryptMgmt.encrypting, 0);
×
1449
  }
1450

1451
_exit:
1✔
1452
  if (code != 0) {
1!
1453
    if (terrno == 0) terrno = code;
×
1454
  }
1455
  return code;
1✔
1456
}
1457

1458
static int32_t mndProcessCreateEncryptKeyReq(SRpcMsg *pReq) {
1✔
1459
  int32_t code = 0;
1✔
1460

1461
#if defined(TD_ENTERPRISE) || defined(TD_ASTRA_TODO)
1462
  SMnode       *pMnode = pReq->info.node;
1✔
1463
  SMCfgDnodeReq cfgReq = {0};
1✔
1464
  TAOS_CHECK_RETURN(tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq));
1!
1465

1466
  if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE)) != 0) {
1!
1467
    tFreeSMCfgDnodeReq(&cfgReq);
×
1468
    TAOS_RETURN(code);
×
1469
  }
1470
  const STraceId *trace = &pReq->info.traceId;
1✔
1471
  SDCfgDnodeReq   dcfgReq = {0};
1✔
1472
  if (strncasecmp(cfgReq.config, "encrypt_key", 12) == 0) {
1!
1473
    tstrncpy(dcfgReq.config, cfgReq.config, sizeof(dcfgReq.config));
1✔
1474
    tstrncpy(dcfgReq.value, cfgReq.value, sizeof(dcfgReq.value));
1✔
1475
    tFreeSMCfgDnodeReq(&cfgReq);
1✔
1476
    return mndProcessCreateEncryptKeyReqImpl(pReq, cfgReq.dnodeId, &dcfgReq);
1✔
1477
  } else {
1478
    code = TSDB_CODE_PAR_INTERNAL_ERROR;
×
1479
    tFreeSMCfgDnodeReq(&cfgReq);
×
1480
    TAOS_RETURN(code);
×
1481
  }
1482

1483
#else
1484
  TAOS_RETURN(code);
1485
#endif
1486
}
1487

1488
static int32_t mndProcessCreateEncryptKeyRsp(SRpcMsg *pRsp) {
1✔
1489
  SMnode *pMnode = pRsp->info.node;
1✔
1490
  int16_t nSuccess = 0;
1✔
1491
  int16_t nFailed = 0;
1✔
1492

1493
  if (0 == pRsp->code) {
1!
1494
    nSuccess = atomic_add_fetch_16(&pMnode->encryptMgmt.nSuccess, 1);
1✔
1495
  } else {
1496
    nFailed = atomic_add_fetch_16(&pMnode->encryptMgmt.nFailed, 1);
×
1497
  }
1498

1499
  int16_t nReq = atomic_load_16(&pMnode->encryptMgmt.nEncrypt);
1✔
1500
  bool    finished = nSuccess + nFailed >= nReq;
1✔
1501

1502
  if (finished) {
1!
1503
    atomic_store_8(&pMnode->encryptMgmt.encrypting, 0);
1✔
1504
  }
1505

1506
  const STraceId *trace = &pRsp->info.traceId;
1✔
1507
  mGInfo("msg:%p, create encrypt key rsp, nReq:%" PRIi16 ", nSucess:%" PRIi16 ", nFailed:%" PRIi16 ", %s", pRsp, nReq,
1!
1508
         nSuccess, nFailed, finished ? "encrypt done" : "in encrypting");
1509

1510
  return 0;
1✔
1511
}
1512

1513
static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
1,443✔
1514
  SMnode *pMnode = pReq->info.node;
1,443✔
1515
  int32_t totalRows = 0;
1,443✔
1516
  int32_t numOfRows = 0;
1,443✔
1517
  char   *cfgOpts[TSDB_CONFIG_NUMBER] = {0};
1,443✔
1518
  char    cfgVals[TSDB_CONFIG_NUMBER][TSDB_CONFIG_VALUE_LEN + 1] = {0};
1,443✔
1519
  char   *pWrite = NULL;
1,443✔
1520
  int32_t cols = 0;
1,443✔
1521
  int32_t code = 0;
1,443✔
1522
  int32_t lino = 0;
1,443✔
1523

1524
  cfgOpts[totalRows] = "statusInterval";
1,443✔
1525
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsStatusInterval);
1,443✔
1526
  totalRows++;
1,443✔
1527

1528
  cfgOpts[totalRows] = "timezone";
1,443✔
1529
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", tsTimezoneStr);
1,443✔
1530
  totalRows++;
1,443✔
1531

1532
  cfgOpts[totalRows] = "locale";
1,443✔
1533
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", tsLocale);
1,443✔
1534
  totalRows++;
1,443✔
1535

1536
  cfgOpts[totalRows] = "charset";
1,443✔
1537
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", tsCharset);
1,443✔
1538
  totalRows++;
1,443✔
1539

1540
  cfgOpts[totalRows] = "monitor";
1,443✔
1541
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsEnableMonitor);
1,443✔
1542
  totalRows++;
1,443✔
1543

1544
  cfgOpts[totalRows] = "monitorInterval";
1,443✔
1545
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsMonitorInterval);
1,443✔
1546
  totalRows++;
1,443✔
1547

1548
  cfgOpts[totalRows] = "slowLogThreshold";
1,443✔
1549
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsSlowLogThreshold);
1,443✔
1550
  totalRows++;
1,443✔
1551

1552
  cfgOpts[totalRows] = "slowLogMaxLen";
1,443✔
1553
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsSlowLogMaxLen);
1,443✔
1554
  totalRows++;
1,443✔
1555

1556
  char scopeStr[64] = {0};
1,443✔
1557
  getSlowLogScopeString(tsSlowLogScope, scopeStr);
1,443✔
1558
  cfgOpts[totalRows] = "slowLogScope";
1,444✔
1559
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", scopeStr);
1,444✔
1560
  totalRows++;
1,444✔
1561

1562
  char buf[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
1,444✔
1563
  char bufVal[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};
1,444✔
1564

1565
  for (int32_t i = 0; i < totalRows; i++) {
14,270✔
1566
    cols = 0;
12,848✔
1567

1568
    STR_WITH_MAXSIZE_TO_VARSTR(buf, cfgOpts[i], TSDB_CONFIG_OPTION_LEN);
12,848✔
1569
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
12,848✔
1570
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)buf, false), &lino, _OVER);
12,604!
1571

1572
    STR_WITH_MAXSIZE_TO_VARSTR(bufVal, cfgVals[i], TSDB_CONFIG_VALUE_LEN);
12,864✔
1573
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
12,864✔
1574
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)bufVal, false), &lino, _OVER);
12,621!
1575

1576
    numOfRows++;
12,826✔
1577
  }
1578

1579
_OVER:
1,422✔
1580
  if (code != 0) mError("failed to retrieve configs at line:%d since %s", lino, tstrerror(code));
1,422!
1581
  pShow->numOfRows += numOfRows;
1,442✔
1582
  return numOfRows;
1,442✔
1583
}
1584

1585
static void mndCancelGetNextConfig(SMnode *pMnode, void *pIter) {}
×
1586

1587
static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
7,681✔
1588
  SMnode    *pMnode = pReq->info.node;
7,681✔
1589
  SSdb      *pSdb = pMnode->pSdb;
7,681✔
1590
  int32_t    numOfRows = 0;
7,681✔
1591
  int32_t    cols = 0;
7,681✔
1592
  ESdbStatus objStatus = 0;
7,681✔
1593
  SDnodeObj *pDnode = NULL;
7,681✔
1594
  int64_t    curMs = taosGetTimestampMs();
7,680✔
1595
  char       buf[TSDB_EP_LEN + VARSTR_HEADER_SIZE];
1596
  int32_t    code = 0;
7,680✔
1597
  int32_t    lino = 0;
7,680✔
1598

1599
  while (numOfRows < rows) {
18,138✔
1600
    pShow->pIter = sdbFetchAll(pSdb, SDB_DNODE, pShow->pIter, (void **)&pDnode, &objStatus, true);
18,136✔
1601
    if (pShow->pIter == NULL) break;
18,146✔
1602
    bool online = mndIsDnodeOnline(pDnode, curMs);
10,457✔
1603

1604
    cols = 0;
10,450✔
1605

1606
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,450✔
1607
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pDnode->id, false), pDnode, &lino, _OVER);
10,448!
1608

1609
    STR_WITH_MAXSIZE_TO_VARSTR(buf, pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
10,439✔
1610

1611
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,439✔
1612
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, buf, false), pDnode, &lino, _OVER);
10,439!
1613

1614
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,451✔
1615
    int16_t id = mndGetVnodesNum(pMnode, pDnode->id);
10,445✔
1616
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&id, false), pDnode, &lino, _OVER);
10,457!
1617

1618
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,456✔
1619
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pDnode->numOfSupportVnodes, false), pDnode,
10,454!
1620
                        &lino, _OVER);
1621

1622
    const char *status = "ready";
10,450✔
1623
    if (objStatus == SDB_STATUS_CREATING) status = "creating";
10,450!
1624
    if (objStatus == SDB_STATUS_DROPPING) status = "dropping";
10,450!
1625
    if (!online) {
10,450✔
1626
      if (objStatus == SDB_STATUS_CREATING)
531!
1627
        status = "creating*";
×
1628
      else if (objStatus == SDB_STATUS_DROPPING)
531!
1629
        status = "dropping*";
×
1630
      else
1631
        status = "offline";
531✔
1632
    }
1633

1634
    STR_TO_VARSTR(buf, status);
10,450✔
1635
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,450✔
1636
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, buf, false), pDnode, &lino, _OVER);
10,449!
1637

1638
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,447✔
1639
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pDnode->createdTime, false), pDnode, &lino,
10,447!
1640
                        _OVER);
1641

1642
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,447✔
1643
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pDnode->rebootTime, false), pDnode, &lino,
10,444!
1644
                        _OVER);
1645

1646
    char *b = taosMemoryCalloc(VARSTR_HEADER_SIZE + strlen(offlineReason[pDnode->offlineReason]) + 1, 1);
10,445!
1647
    STR_TO_VARSTR(b, online ? "" : offlineReason[pDnode->offlineReason]);
10,459✔
1648

1649
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,459✔
1650
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, b, false), pDnode, &lino, _OVER);
10,454!
1651
    taosMemoryFreeClear(b);
10,454!
1652

1653
#ifdef TD_ENTERPRISE
1654
    STR_TO_VARSTR(buf, pDnode->machineId);
10,453✔
1655
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,453✔
1656
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, buf, false), pDnode, &lino, _OVER);
10,451!
1657
#endif
1658

1659
    numOfRows++;
10,450✔
1660
    sdbRelease(pSdb, pDnode);
10,450✔
1661
  }
1662

1663
_OVER:
2✔
1664
  if (code != 0) mError("failed to retrieve dnodes at line:%d since %s", lino, tstrerror(code));
7,691!
1665

1666
  pShow->numOfRows += numOfRows;
7,689✔
1667
  return numOfRows;
7,689✔
1668
}
1669

1670
static void mndCancelGetNextDnode(SMnode *pMnode, void *pIter) {
×
1671
  SSdb *pSdb = pMnode->pSdb;
×
1672
  sdbCancelFetchByType(pSdb, pIter, SDB_DNODE);
×
1673
}
×
1674

1675
SArray *mndGetAllDnodeFqdns(SMnode *pMnode) {
3,044✔
1676
  SDnodeObj *pObj = NULL;
3,044✔
1677
  void      *pIter = NULL;
3,044✔
1678
  SSdb      *pSdb = pMnode->pSdb;
3,044✔
1679
  SArray    *fqdns = taosArrayInit(4, sizeof(void *));
3,044✔
1680
  while (1) {
2,629✔
1681
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pObj);
5,673✔
1682
    if (pIter == NULL) break;
5,673✔
1683

1684
    char *fqdn = taosStrdup(pObj->fqdn);
2,629!
1685
    if (taosArrayPush(fqdns, &fqdn) == NULL) {
2,629!
1686
      mError("failed to fqdn into array, but continue at this time");
×
1687
    }
1688
    sdbRelease(pSdb, pObj);
2,629✔
1689
  }
1690
  return fqdns;
3,044✔
1691
}
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