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

taosdata / TDengine / #3845

11 Apr 2025 06:14AM UTC coverage: 62.585% (+18.7%) from 43.852%
#3845

push

travis-ci

web-flow
Merge pull request #30758 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

154461 of 315259 branches covered (48.99%)

Branch coverage included in aggregate %.

63 of 80 new or added lines in 9 files covered. (78.75%)

3223 existing lines in 85 files now uncovered.

240073 of 315138 relevant lines covered (76.18%)

18471065.7 hits per line

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

64.33
/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) {
1,764✔
104
  SSdbTable table = {
1,764✔
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);
1,764✔
116
  mndSetMsgHandle(pMnode, TDMT_MND_DROP_DNODE, mndProcessDropDnodeReq);
1,764✔
117
  mndSetMsgHandle(pMnode, TDMT_MND_STATUS, mndProcessStatusReq);
1,764✔
118
  mndSetMsgHandle(pMnode, TDMT_MND_NOTIFY, mndProcessNotifyReq);
1,764✔
119
  mndSetMsgHandle(pMnode, TDMT_MND_DNODE_LIST, mndProcessDnodeListReq);
1,764✔
120
  mndSetMsgHandle(pMnode, TDMT_MND_RESTORE_DNODE, mndProcessRestoreDnodeReq);
1,764✔
121
  mndSetMsgHandle(pMnode, TDMT_MND_STATIS, mndProcessStatisReq);
1,764✔
122
  mndSetMsgHandle(pMnode, TDMT_MND_AUDIT, mndProcessAuditReq);
1,764✔
123
  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ENCRYPT_KEY, mndProcessCreateEncryptKeyReq);
1,764✔
124
  mndSetMsgHandle(pMnode, TDMT_DND_CREATE_ENCRYPT_KEY_RSP, mndProcessCreateEncryptKeyRsp);
1,764✔
125
  mndSetMsgHandle(pMnode, TDMT_MND_UPDATE_DNODE_INFO, mndProcessUpdateDnodeInfoReq);
1,764✔
126

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

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

135
SIpWhiteList *mndCreateIpWhiteOfDnode(SMnode *pMnode);
136
SIpWhiteList *mndAddIpWhiteOfDnode(SIpWhiteList *pIpWhiteList, char *fqdn);
137
SIpWhiteList *mndRmIpWhiteOfDnode(SIpWhiteList *pIpWhiteList, char *fqdn);
138
void          mndCleanupDnode(SMnode *pMnode) {}
1,763✔
139

140
static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
1,274✔
141
  int32_t  code = -1;
1,274✔
142
  SSdbRaw *pRaw = NULL;
1,274✔
143
  STrans  *pTrans = NULL;
1,274✔
144

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

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

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

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

188
_OVER:
1,274✔
189
  mndTransDrop(pTrans);
1,274✔
190
  sdbFreeRaw(pRaw);
1,274✔
191
  return code;
1,274✔
192
}
193

194
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
10,302✔
195
  int32_t code = 0;
10,302✔
196
  int32_t lino = 0;
10,302✔
197
  terrno = TSDB_CODE_OUT_OF_MEMORY;
10,302✔
198

199
  SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE);
10,302✔
200
  if (pRaw == NULL) goto _OVER;
10,302!
201

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

214
  terrno = 0;
10,302✔
215

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

223
  mTrace("dnode:%d, encode to raw:%p, row:%p", pDnode->id, pRaw, pDnode);
10,302✔
224
  return pRaw;
10,302✔
225
}
226

227
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
8,181✔
228
  int32_t code = 0;
8,181✔
229
  int32_t lino = 0;
8,181✔
230
  terrno = TSDB_CODE_OUT_OF_MEMORY;
8,181✔
231
  SSdbRow   *pRow = NULL;
8,181✔
232
  SDnodeObj *pDnode = NULL;
8,181✔
233

234
  int8_t sver = 0;
8,181✔
235
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
8,181!
236
  if (sver < 1 || sver > TSDB_DNODE_VER_NUMBER) {
8,181!
237
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
238
    goto _OVER;
×
239
  }
240

241
  pRow = sdbAllocRow(sizeof(SDnodeObj));
8,181✔
242
  if (pRow == NULL) goto _OVER;
8,181!
243

244
  pDnode = sdbGetRowObj(pRow);
8,181✔
245
  if (pDnode == NULL) goto _OVER;
8,181!
246

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

263
  terrno = 0;
8,181✔
264
  if (tmsgUpdateDnodeInfo(&pDnode->id, NULL, pDnode->fqdn, &pDnode->port)) {
8,181!
265
    mInfo("dnode:%d, endpoint changed", pDnode->id);
×
266
  }
267

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

275
  mTrace("dnode:%d, decode from raw:%p, row:%p ep:%s:%u", pDnode->id, pRaw, pDnode, pDnode->fqdn, pDnode->port);
8,181✔
276
  return pRow;
8,181✔
277
}
278

279
static int32_t mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode) {
3,456✔
280
  mTrace("dnode:%d, perform insert action, row:%p", pDnode->id, pDnode);
3,456✔
281
  pDnode->offlineReason = DND_REASON_STATUS_NOT_RECEIVED;
3,456✔
282

283
  char ep[TSDB_EP_LEN] = {0};
3,456✔
284
  (void)snprintf(ep, TSDB_EP_LEN - 1, "%s:%u", pDnode->fqdn, pDnode->port);
3,456✔
285
  tstrncpy(pDnode->ep, ep, TSDB_EP_LEN);
3,456✔
286
  return 0;
3,456✔
287
}
288

289
static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) {
8,180✔
290
  mTrace("dnode:%d, perform delete action, row:%p", pDnode->id, pDnode);
8,180✔
291
  return 0;
8,180✔
292
}
293

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

303
SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId) {
21,213,598✔
304
  SSdb      *pSdb = pMnode->pSdb;
21,213,598✔
305
  SDnodeObj *pDnode = sdbAcquire(pSdb, SDB_DNODE, &dnodeId);
21,213,598✔
306
  if (pDnode == NULL) {
21,218,480✔
307
    if (terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
661✔
308
      terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
43✔
309
    } else if (terrno == TSDB_CODE_SDB_OBJ_CREATING) {
618!
310
      terrno = TSDB_CODE_MND_DNODE_IN_CREATING;
×
311
    } else if (terrno == TSDB_CODE_SDB_OBJ_DROPPING) {
618!
312
      terrno = TSDB_CODE_MND_DNODE_IN_DROPPING;
618✔
313
    } else {
314
      terrno = TSDB_CODE_APP_ERROR;
×
315
      mFatal("dnode:%d, failed to acquire db since %s", dnodeId, terrstr());
×
316
    }
317
  }
318

319
  return pDnode;
21,218,439✔
320
}
321

322
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode) {
20,872,849✔
323
  SSdb *pSdb = pMnode->pSdb;
20,872,849✔
324
  sdbRelease(pSdb, pDnode);
20,872,849✔
325
}
20,874,297✔
326

327
SEpSet mndGetDnodeEpset(SDnodeObj *pDnode) {
26,875✔
328
  SEpSet epSet = {0};
26,875✔
329
  terrno = addEpIntoEpSet(&epSet, pDnode->fqdn, pDnode->port);
26,875✔
330
  return epSet;
26,875✔
331
}
332

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

338
  epSet = mndGetDnodeEpset(pDnode);
×
339

340
  mndReleaseDnode(pMnode, pDnode);
×
341
  return epSet;
×
342
}
343

344
static SDnodeObj *mndAcquireDnodeByEp(SMnode *pMnode, char *pEpStr) {
3,118✔
345
  SSdb *pSdb = pMnode->pSdb;
3,118✔
346

347
  void *pIter = NULL;
3,118✔
348
  while (1) {
4,087✔
349
    SDnodeObj *pDnode = NULL;
7,205✔
350
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
7,205✔
351
    if (pIter == NULL) break;
7,205✔
352

353
    if (taosStrncasecmp(pEpStr, pDnode->ep, TSDB_EP_LEN) == 0) {
6,194✔
354
      sdbCancelFetch(pSdb, pIter);
2,107✔
355
      return pDnode;
2,107✔
356
    }
357

358
    sdbRelease(pSdb, pDnode);
4,087✔
359
  }
360

361
  terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
1,011✔
362
  return NULL;
1,011✔
363
}
364

365
static SDnodeObj *mndAcquireDnodeAllStatusByEp(SMnode *pMnode, char *pEpStr) {
362✔
366
  SSdb *pSdb = pMnode->pSdb;
362✔
367

368
  void *pIter = NULL;
362✔
369
  while (1) {
362✔
370
    SDnodeObj *pDnode = NULL;
724✔
371
    ESdbStatus objStatus = 0;
724✔
372
    pIter = sdbFetchAll(pSdb, SDB_DNODE, pIter, (void **)&pDnode, &objStatus, true);
724✔
373
    if (pIter == NULL) break;
724!
374

375
    if (taosStrncasecmp(pEpStr, pDnode->ep, TSDB_EP_LEN) == 0) {
724✔
376
      sdbCancelFetch(pSdb, pIter);
362✔
377
      return pDnode;
362✔
378
    }
379

380
    sdbRelease(pSdb, pDnode);
362✔
381
  }
382

383
  return NULL;
×
384
}
385

386
int32_t mndGetDnodeSize(SMnode *pMnode) {
669,390✔
387
  SSdb *pSdb = pMnode->pSdb;
669,390✔
388
  return sdbGetSize(pSdb, SDB_DNODE);
669,390✔
389
}
390

391
int32_t mndGetDbSize(SMnode *pMnode) {
×
392
  SSdb *pSdb = pMnode->pSdb;
×
393
  return sdbGetSize(pSdb, SDB_DB);
×
394
}
395

396
bool mndIsDnodeOnline(SDnodeObj *pDnode, int64_t curMs) {
1,629,847✔
397
  int64_t interval = TABS(pDnode->lastAccessTime - curMs);
1,629,847✔
398
  if (interval > 5000 * (int64_t)tsStatusInterval) {
1,629,847✔
399
    if (pDnode->rebootTime > 0 && pDnode->offlineReason == DND_REASON_ONLINE) {
7,389✔
400
      pDnode->offlineReason = DND_REASON_STATUS_MSG_TIMEOUT;
140✔
401
    }
402
    return false;
7,389✔
403
  }
404
  return true;
1,622,458✔
405
}
406

407
static void mndGetDnodeEps(SMnode *pMnode, SArray *pDnodeEps) {
8,292✔
408
  SSdb *pSdb = pMnode->pSdb;
8,292✔
409

410
  int32_t numOfEps = 0;
8,292✔
411
  void   *pIter = NULL;
8,292✔
412
  while (1) {
27,267✔
413
    SDnodeObj *pDnode = NULL;
35,559✔
414
    ESdbStatus objStatus = 0;
35,559✔
415
    pIter = sdbFetchAll(pSdb, SDB_DNODE, pIter, (void **)&pDnode, &objStatus, true);
35,559✔
416
    if (pIter == NULL) break;
35,559✔
417

418
    SDnodeEp dnodeEp = {0};
27,267✔
419
    dnodeEp.id = pDnode->id;
27,267✔
420
    dnodeEp.ep.port = pDnode->port;
27,267✔
421
    tstrncpy(dnodeEp.ep.fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
27,267✔
422
    sdbRelease(pSdb, pDnode);
27,267✔
423

424
    dnodeEp.isMnode = 0;
27,267✔
425
    if (mndIsMnode(pMnode, pDnode->id)) {
27,267✔
426
      dnodeEp.isMnode = 1;
12,131✔
427
    }
428
    if (taosArrayPush(pDnodeEps, &dnodeEp) == NULL) {
27,267!
429
      mError("failed to put ep into array, but continue at this call");
×
430
    }
431
  }
432
}
8,292✔
433

434
int32_t mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo) {
88,454✔
435
  SSdb   *pSdb = pMnode->pSdb;
88,454✔
436
  int32_t code = 0;
88,454✔
437

438
  int32_t numOfEps = 0;
88,454✔
439
  void   *pIter = NULL;
88,454✔
440
  while (1) {
373,602✔
441
    SDnodeObj *pDnode = NULL;
462,056✔
442
    ESdbStatus objStatus = 0;
462,056✔
443
    pIter = sdbFetchAll(pSdb, SDB_DNODE, pIter, (void **)&pDnode, &objStatus, true);
462,056✔
444
    if (pIter == NULL) break;
462,056✔
445

446
    SDnodeInfo dInfo;
447
    dInfo.id = pDnode->id;
373,602✔
448
    dInfo.ep.port = pDnode->port;
373,602✔
449
    dInfo.offlineReason = pDnode->offlineReason;
373,602✔
450
    tstrncpy(dInfo.ep.fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
373,602✔
451
    sdbRelease(pSdb, pDnode);
373,602✔
452
    if (mndIsMnode(pMnode, pDnode->id)) {
373,602✔
453
      dInfo.isMnode = 1;
107,231✔
454
    } else {
455
      dInfo.isMnode = 0;
266,371✔
456
    }
457

458
    if (taosArrayPush(pDnodeInfo, &dInfo) == NULL) {
373,602!
459
      code = terrno;
×
460
      sdbCancelFetch(pSdb, pIter);
×
461
      break;
×
462
    }
463
  }
464
  TAOS_RETURN(code);
88,454✔
465
}
466

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

474
static int32_t mndCheckClusterCfgPara(SMnode *pMnode, SDnodeObj *pDnode, const SClusterCfg *pCfg) {
8,292✔
475
  CHECK_MONITOR_PARA(tsEnableMonitor, DND_REASON_STATUS_MONITOR_SWITCH_NOT_MATCH);
8,292!
476
  CHECK_MONITOR_PARA(tsMonitorInterval, DND_REASON_STATUS_MONITOR_INTERVAL_NOT_MATCH);
8,292!
477
  CHECK_MONITOR_PARA(tsSlowLogThreshold, DND_REASON_STATUS_MONITOR_SLOW_LOG_THRESHOLD_NOT_MATCH);
8,292!
478
  CHECK_MONITOR_PARA(tsSlowLogMaxLen, DND_REASON_STATUS_MONITOR_SLOW_LOG_SQL_MAX_LEN_NOT_MATCH);
8,292!
479
  CHECK_MONITOR_PARA(tsSlowLogScope, DND_REASON_STATUS_MONITOR_SLOW_LOG_SCOPE_NOT_MATCH);
8,292!
480

481
  if (0 != taosStrcasecmp(pCfg->monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb)) {
8,292!
482
    mError("dnode:%d, tsSlowLogExceptDb:%s inconsistent with cluster:%s", pDnode->id,
×
483
           pCfg->monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb);
484
    terrno = TSDB_CODE_DNODE_INVALID_MONITOR_PARAS;
×
485
    return DND_REASON_STATUS_MONITOR_NOT_MATCH;
×
486
  }
487

488
  if (pCfg->statusInterval != tsStatusInterval) {
8,292!
489
    mError("dnode:%d, statusInterval:%d inconsistent with cluster:%d", pDnode->id, pCfg->statusInterval,
×
490
           tsStatusInterval);
491
    terrno = TSDB_CODE_DNODE_INVALID_STATUS_INTERVAL;
×
492
    return DND_REASON_STATUS_INTERVAL_NOT_MATCH;
×
493
  }
494

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

502
  if (0 != taosStrcasecmp(pCfg->locale, tsLocale)) {
8,292!
503
    mError("dnode:%d, locale:%s inconsistent with cluster:%s", pDnode->id, pCfg->locale, tsLocale);
×
504
    terrno = TSDB_CODE_DNODE_INVALID_LOCALE;
×
505
    return DND_REASON_LOCALE_NOT_MATCH;
×
506
  }
507

508
  if (0 != taosStrcasecmp(pCfg->charset, tsCharset)) {
8,292!
509
    mError("dnode:%d, charset:%s inconsistent with cluster:%s", pDnode->id, pCfg->charset, tsCharset);
×
510
    terrno = TSDB_CODE_DNODE_INVALID_CHARSET;
×
511
    return DND_REASON_CHARSET_NOT_MATCH;
×
512
  }
513

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

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

535
  return DND_REASON_ONLINE;
8,292✔
536
}
537

538
double calcAppliedRate(int64_t currentCount, int64_t lastCount, int64_t currentTimeMs, int64_t lastTimeMs) {
127✔
539
  if ((currentTimeMs <= lastTimeMs) || (currentCount <= lastCount)) {
127!
540
    return 0.0;
12✔
541
  }
542

543
  int64_t deltaCount = currentCount - lastCount;
115✔
544
  int64_t deltaMs = currentTimeMs - lastTimeMs;
115✔
545
  double  rate = (double)deltaCount / (double)deltaMs;
115✔
546
  return rate;
115✔
547
}
548

549
static bool mndUpdateVnodeState(int32_t vgId, SVnodeGid *pGid, SVnodeLoad *pVload) {
1,060,271✔
550
  bool stateChanged = false;
1,060,271✔
551
  bool roleChanged = pGid->syncState != pVload->syncState ||
3,177,561✔
552
                     (pVload->syncTerm != -1 && pGid->syncTerm != pVload->syncTerm) ||
2,108,023!
553
                     pGid->roleTimeMs != pVload->roleTimeMs;
1,047,752✔
554

555
  if (pVload->syncCommitIndex > pVload->syncAppliedIndex) {
1,060,271✔
556
    if (pGid->lastSyncAppliedIndexUpdateTime == 0) {
243✔
557
      pGid->lastSyncAppliedIndexUpdateTime = taosGetTimestampMs();
114✔
558
    } else if (pGid->syncAppliedIndex != pVload->syncAppliedIndex) {
129✔
559
      int64_t currentTimeMs = taosGetTimestampMs();
127✔
560
      pGid->appliedRate = calcAppliedRate(pVload->syncAppliedIndex, pGid->syncAppliedIndex, currentTimeMs,
127✔
561
                                          pGid->lastSyncAppliedIndexUpdateTime);
562

563
      pGid->lastSyncAppliedIndexUpdateTime = currentTimeMs;
127✔
564
    }
565
  }
566

567
  pGid->syncAppliedIndex = pVload->syncAppliedIndex;
1,060,271✔
568
  pGid->syncCommitIndex = pVload->syncCommitIndex;
1,060,271✔
569
  if (roleChanged || pGid->syncRestore != pVload->syncRestore || pGid->syncCanRead != pVload->syncCanRead ||
1,060,271!
570
      pGid->startTimeMs != pVload->startTimeMs) {
1,046,760!
571
    mInfo(
13,511!
572
        "vgId:%d, state changed by status msg, old state:%s restored:%d canRead:%d new state:%s restored:%d "
573
        "canRead:%d, dnode:%d",
574
        vgId, syncStr(pGid->syncState), pGid->syncRestore, pGid->syncCanRead, syncStr(pVload->syncState),
575
        pVload->syncRestore, pVload->syncCanRead, pGid->dnodeId);
576
    pGid->syncState = pVload->syncState;
13,511✔
577
    pGid->syncTerm = pVload->syncTerm;
13,511✔
578
    pGid->syncRestore = pVload->syncRestore;
13,511✔
579
    pGid->syncCanRead = pVload->syncCanRead;
13,511✔
580
    pGid->startTimeMs = pVload->startTimeMs;
13,511✔
581
    pGid->roleTimeMs = pVload->roleTimeMs;
13,511✔
582
    stateChanged = true;
13,511✔
583
  }
584
  return stateChanged;
1,060,271✔
585
}
586

587
static bool mndUpdateMnodeState(SMnodeObj *pObj, SMnodeLoad *pMload) {
79,750✔
588
  bool stateChanged = false;
79,750✔
589
  bool roleChanged = pObj->syncState != pMload->syncState ||
237,645✔
590
                     (pMload->syncTerm != -1 && pObj->syncTerm != pMload->syncTerm) ||
157,860!
591
                     pObj->roleTimeMs != pMload->roleTimeMs;
78,110✔
592
  if (roleChanged || pObj->syncRestore != pMload->syncRestore) {
79,750✔
593
    mInfo("dnode:%d, mnode syncState from %s to %s, restoreState from %d to %d, syncTerm from %" PRId64 " to %" PRId64,
1,710!
594
          pObj->id, syncStr(pObj->syncState), syncStr(pMload->syncState), pObj->syncRestore, pMload->syncRestore,
595
          pObj->syncTerm, pMload->syncTerm);
596
    pObj->syncState = pMload->syncState;
1,710✔
597
    pObj->syncTerm = pMload->syncTerm;
1,710✔
598
    pObj->syncRestore = pMload->syncRestore;
1,710✔
599
    pObj->roleTimeMs = pMload->roleTimeMs;
1,710✔
600
    stateChanged = true;
1,710✔
601
  }
602
  return stateChanged;
79,750✔
603
}
604

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

612
  TAOS_CHECK_RETURN(tDeserializeSStatisReq(pReq->pCont, pReq->contLen, &statisReq));
12,444!
613

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

618
  if (statisReq.type == MONITOR_TYPE_COUNTER) {
12,444✔
619
    monSendContent(statisReq.pCont, tsMonFwUri);
9,439✔
620
  } else if (statisReq.type == MONITOR_TYPE_SLOW_LOG) {
3,005!
621
    monSendContent(statisReq.pCont, tsMonSlowLogUri);
3,005✔
622
  }
623

624
  tFreeSStatisReq(&statisReq);
12,444✔
625
  return 0;
12,444✔
626
}
627

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

634
    TAOS_CHECK_RETURN(tDeserializeSAuditReq(pReq->pCont, pReq->contLen, &auditReq));
83,780!
635

636
    mDebug("received audit req:%s, %s, %s, %s", auditReq.operation, auditReq.db, auditReq.table, auditReq.pSql);
83,781✔
637

638
    auditAddRecord(pReq, pMnode->clusterId, auditReq.operation, auditReq.db, auditReq.table, auditReq.pSql,
83,781✔
639
                   auditReq.sqlLen);
640

641
    tFreeSAuditReq(&auditReq);
83,778✔
642
  }
643
  return 0;
83,781✔
644
}
645

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

652
  infoReq.dnodeId = pDnode->id;
3,484✔
653
  tstrncpy(infoReq.machineId, pDnode->machineId, TSDB_MACHINE_ID_LEN + 1);
3,484✔
654

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

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

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

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

685
  TAOS_CHECK_EXIT(tDeserializeSDnodeInfoReq(pReq->pCont, pReq->contLen, &infoReq));
3,482!
686

687
  pDnode = mndAcquireDnode(pMnode, infoReq.dnodeId);
3,482✔
688
  if (pDnode == NULL) {
3,482✔
689
    TAOS_CHECK_EXIT(terrno);
1!
690
  }
691

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

697
  pDnode->updateTime = taosGetTimestampMs();
3,481✔
698

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

709
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
3,481✔
710
    mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
2!
711
    TAOS_CHECK_EXIT(code);
2!
712
  }
713

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

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

730
  TAOS_CHECK_GOTO(tDeserializeSStatusReq(pReq->pCont, pReq->contLen, &statusReq), NULL, _OVER);
139,914!
731

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

740
  if (statusReq.dnodeId == 0) {
139,874✔
741
    pDnode = mndAcquireDnodeByEp(pMnode, statusReq.dnodeEp);
2,279✔
742
    if (pDnode == NULL) {
2,279✔
743
      mInfo("dnode:%s, not created yet", statusReq.dnodeEp);
175!
744
      code = TSDB_CODE_MND_RETURN_VALUE_NULL;
175✔
745
      if (terrno != 0) code = terrno;
175!
746
      goto _OVER;
175✔
747
    }
748
  } else {
749
    pDnode = mndAcquireDnode(pMnode, statusReq.dnodeId);
137,595✔
750
    if (pDnode == NULL) {
137,595✔
751
      int32_t err = terrno;
390✔
752
      pDnode = mndAcquireDnodeByEp(pMnode, statusReq.dnodeEp);
390✔
753
      if (pDnode != NULL) {
390✔
754
        pDnode->offlineReason = DND_REASON_DNODE_ID_NOT_MATCH;
3✔
755
        terrno = err;
3✔
756
        goto _OVER;
3✔
757
      }
758

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

770
  pMnode->ipWhiteVer = mndGetIpWhiteVer(pMnode);
139,671✔
771

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

792
  if (reboot) {
139,671✔
793
    tsGrantHBInterval = GRANT_HEART_BEAT_MIN;
2,358✔
794
  }
795

796
  for (int32_t v = 0; v < taosArrayGetSize(statusReq.pVloads); ++v) {
1,202,488✔
797
    SVnodeLoad *pVload = taosArrayGet(statusReq.pVloads, v);
1,062,817✔
798

799
    SVgObj *pVgroup = mndAcquireVgroup(pMnode, pVload->vgId);
1,062,817✔
800
    if (pVgroup != NULL) {
1,062,817✔
801
      if (pVload->syncState == TAOS_SYNC_STATE_LEADER || pVload->syncState == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
1,060,294!
802
        pVgroup->cacheUsage = pVload->cacheUsage;
1,020,973✔
803
        pVgroup->numOfCachedTables = pVload->numOfCachedTables;
1,020,973✔
804
        pVgroup->numOfTables = pVload->numOfTables;
1,020,973✔
805
        pVgroup->numOfTimeSeries = pVload->numOfTimeSeries;
1,020,973✔
806
        pVgroup->totalStorage = pVload->totalStorage;
1,020,973✔
807
        pVgroup->compStorage = pVload->compStorage;
1,020,973✔
808
        pVgroup->pointsWritten = pVload->pointsWritten;
1,020,973✔
809
      }
810
      bool stateChanged = false;
1,060,294✔
811
      for (int32_t vg = 0; vg < pVgroup->replica; ++vg) {
1,113,695✔
812
        SVnodeGid *pGid = &pVgroup->vnodeGid[vg];
1,113,672✔
813
        if (pGid->dnodeId == statusReq.dnodeId) {
1,113,672✔
814
          if (pVload->startTimeMs == 0) {
1,060,271!
815
            pVload->startTimeMs = statusReq.rebootTime;
×
816
          }
817
          if (pVload->roleTimeMs == 0) {
1,060,271!
818
            pVload->roleTimeMs = statusReq.rebootTime;
×
819
          }
820
          stateChanged = mndUpdateVnodeState(pVgroup->vgId, pGid, pVload);
1,060,271✔
821
          break;
1,060,271✔
822
        }
823
      }
824
      if (stateChanged) {
1,060,294✔
825
        SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName);
13,511✔
826
        if (pDb != NULL && pDb->stateTs != curMs) {
13,511✔
827
          mInfo("db:%s, stateTs changed by status msg, old stateTs:%" PRId64 " new stateTs:%" PRId64, pDb->name,
8,243!
828
                pDb->stateTs, curMs);
829
          pDb->stateTs = curMs;
8,243✔
830
        }
831
        mndReleaseDb(pMnode, pDb);
13,511✔
832
      }
833
    }
834

835
    mndReleaseVgroup(pMnode, pVgroup);
1,062,817✔
836
  }
837

838
  SMnodeObj *pObj = mndAcquireMnode(pMnode, pDnode->id);
139,671✔
839
  if (pObj != NULL) {
139,671✔
840
    if (statusReq.mload.roleTimeMs == 0) {
79,750✔
841
      statusReq.mload.roleTimeMs = statusReq.rebootTime;
1,508✔
842
    }
843
    (void)mndUpdateMnodeState(pObj, &statusReq.mload);
79,750✔
844
    mndReleaseMnode(pMnode, pObj);
79,750✔
845
  }
846

847
  SQnodeObj *pQnode = mndAcquireQnode(pMnode, statusReq.qload.dnodeId);
139,671✔
848
  if (pQnode != NULL) {
139,671✔
849
    pQnode->load = statusReq.qload;
80,713✔
850
    mndReleaseQnode(pMnode, pQnode);
80,713✔
851
  }
852

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

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

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

885
    if (!online) {
8,292✔
886
      mInfo("dnode:%d, from offline to online, memory avail:%" PRId64 " total:%" PRId64 " cores:%.2f", pDnode->id,
2,309!
887
            statusReq.memAvail, statusReq.memTotal, statusReq.numOfCores);
888
    } else {
889
      mInfo("dnode:%d, send dnode epset, online:%d dnodeVer:%" PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online,
5,983!
890
            statusReq.dnodeVer, dnodeVer, reboot);
891
    }
892

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

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

920
    mndGetDnodeEps(pMnode, statusRsp.pDnodeEps);
8,292✔
921
    statusRsp.ipWhiteVer = pMnode->ipWhiteVer;
8,292✔
922

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

932
    pReq->info.rspLen = contLen;
8,292✔
933
    pReq->info.rsp = pHead;
8,292✔
934
  }
935

936
  pDnode->accessTimes++;
139,671✔
937
  pDnode->lastAccessTime = curMs;
139,671✔
938
  code = 0;
139,671✔
939

940
_OVER:
139,914✔
941
  mndReleaseDnode(pMnode, pDnode);
139,914✔
942
  taosArrayDestroy(statusReq.pVloads);
139,914✔
943
  return mndUpdClusterInfo(pReq);
139,914✔
944
}
945

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1055
    sdbRelease(pSdb, pObj);
7,842✔
1056
  }
1057

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

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

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

1074
_OVER:
7,524✔
1075

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

1080
  tFreeSDnodeListRsp(&rsp);
7,524✔
1081

1082
  TAOS_RETURN(code);
7,524✔
1083
}
1084

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

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

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

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

1121
  TAOS_CHECK_GOTO(tDeserializeSCreateDnodeReq(pReq->pCont, pReq->contLen, &createReq), NULL, _OVER);
449!
1122

1123
  mInfo("dnode:%s:%d, start to create", createReq.fqdn, createReq.port);
449!
1124
  TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_DNODE), NULL, _OVER);
449✔
1125

1126
  if (createReq.fqdn[0] == 0 || createReq.port <= 0 || createReq.port > UINT16_MAX) {
448!
1127
    code = TSDB_CODE_MND_INVALID_DNODE_EP;
×
UNCOV
1128
    goto _OVER;
×
1129
  }
1130

1131
  char ep[TSDB_EP_LEN];
1132
  (void)snprintf(ep, TSDB_EP_LEN, "%s:%d", createReq.fqdn, createReq.port);
448✔
1133
  pDnode = mndAcquireDnodeByEp(pMnode, ep);
448✔
1134
  if (pDnode != NULL) {
448!
1135
    code = TSDB_CODE_MND_DNODE_ALREADY_EXIST;
×
UNCOV
1136
    goto _OVER;
×
1137
  }
1138

1139
  code = mndCreateDnode(pMnode, pReq, &createReq);
448✔
1140
  if (code == 0) {
448!
1141
    code = TSDB_CODE_ACTION_IN_PROGRESS;
448✔
1142
    tsGrantHBInterval = 5;
448✔
1143
  }
1144

1145
  char obj[200] = {0};
448✔
1146
  (void)tsnprintf(obj, sizeof(obj), "%s:%d", createReq.fqdn, createReq.port);
448✔
1147

1148
  auditRecord(pReq, pMnode->clusterId, "createDnode", "", obj, createReq.sql, createReq.sqlLen);
448✔
1149

1150
_OVER:
449✔
1151
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
449!
1152
    mError("dnode:%s:%d, failed to create since %s", createReq.fqdn, createReq.port, tstrerror(code));
1!
1153
  }
1154

1155
  mndReleaseDnode(pMnode, pDnode);
449✔
1156
  tFreeSCreateDnodeReq(&createReq);
449✔
1157
  TAOS_RETURN(code);
449✔
1158
}
1159

1160
extern int32_t mndProcessRestoreDnodeReqImpl(SRpcMsg *pReq);
1161

1162
int32_t mndProcessRestoreDnodeReq(SRpcMsg *pReq) { return mndProcessRestoreDnodeReqImpl(pReq); }
8✔
1163

1164
#ifndef TD_ENTERPRISE
1165
int32_t mndProcessRestoreDnodeReqImpl(SRpcMsg *pReq) { return 0; }
1166
#endif
1167

1168
static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMnodeObj *pMObj, SQnodeObj *pQObj,
23✔
1169
                            SSnodeObj *pSObj, int32_t numOfVnodes, bool force, bool unsafe) {
1170
  int32_t  code = -1;
23✔
1171
  SSdbRaw *pRaw = NULL;
23✔
1172
  STrans  *pTrans = NULL;
23✔
1173

1174
  pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "drop-dnode");
23✔
1175
  if (pTrans == NULL) {
23!
1176
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
1177
    if (terrno != 0) code = terrno;
×
UNCOV
1178
    goto _OVER;
×
1179
  }
1180
  mndTransSetSerial(pTrans);
23✔
1181
  mInfo("trans:%d, used to drop dnode:%d, force:%d", pTrans->id, pDnode->id, force);
23!
1182
  TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
23!
1183

1184
  pRaw = mndDnodeActionEncode(pDnode);
23✔
1185
  if (pRaw == NULL) {
23!
1186
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
1187
    if (terrno != 0) code = terrno;
×
UNCOV
1188
    goto _OVER;
×
1189
  }
1190
  TAOS_CHECK_GOTO(mndTransAppendRedolog(pTrans, pRaw), NULL, _OVER);
23!
1191
  TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_DROPPING), NULL, _OVER);
23!
1192
  pRaw = NULL;
23✔
1193

1194
  pRaw = mndDnodeActionEncode(pDnode);
23✔
1195
  if (pRaw == NULL) {
23!
1196
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
1197
    if (terrno != 0) code = terrno;
×
UNCOV
1198
    goto _OVER;
×
1199
  }
1200
  TAOS_CHECK_GOTO(mndTransAppendCommitlog(pTrans, pRaw), NULL, _OVER);
23!
1201
  TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED), NULL, _OVER);
23!
1202
  pRaw = NULL;
23✔
1203

1204
  if (pMObj != NULL) {
23✔
1205
    mInfo("trans:%d, mnode on dnode:%d will be dropped", pTrans->id, pDnode->id);
4!
1206
    TAOS_CHECK_GOTO(mndSetDropMnodeInfoToTrans(pMnode, pTrans, pMObj, force), NULL, _OVER);
4!
1207
  }
1208

1209
  if (pQObj != NULL) {
23✔
1210
    mInfo("trans:%d, qnode on dnode:%d will be dropped", pTrans->id, pDnode->id);
3!
1211
    TAOS_CHECK_GOTO(mndSetDropQnodeInfoToTrans(pMnode, pTrans, pQObj, force), NULL, _OVER);
3!
1212
  }
1213

1214
  if (pSObj != NULL) {
23✔
1215
    mInfo("trans:%d, snode on dnode:%d will be dropped", pTrans->id, pDnode->id);
3!
1216
    TAOS_CHECK_GOTO(mndSetDropSnodeInfoToTrans(pMnode, pTrans, pSObj, force), NULL, _OVER);
3!
1217
  }
1218

1219
  if (numOfVnodes > 0) {
23✔
1220
    mInfo("trans:%d, %d vnodes on dnode:%d will be dropped", pTrans->id, numOfVnodes, pDnode->id);
16!
1221
    TAOS_CHECK_GOTO(mndSetMoveVgroupsInfoToTrans(pMnode, pTrans, pDnode->id, force, unsafe), NULL, _OVER);
16✔
1222
  }
1223

1224
  TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
21!
1225

1226
  (void)mndUpdateIpWhiteForAllUser(pMnode, TSDB_DEFAULT_USER, pDnode->fqdn, IP_WHITE_DROP,
21✔
1227
                                   1);  // TODO: check the return value
1228
  code = 0;
21✔
1229

1230
_OVER:
23✔
1231
  mndTransDrop(pTrans);
23✔
1232
  sdbFreeRaw(pRaw);
23✔
1233
  TAOS_RETURN(code);
23✔
1234
}
1235

1236
static bool mndIsEmptyDnode(SMnode *pMnode, int32_t dnodeId) {
25✔
1237
  bool       isEmpty = false;
25✔
1238
  SMnodeObj *pMObj = NULL;
25✔
1239
  SQnodeObj *pQObj = NULL;
25✔
1240
  SSnodeObj *pSObj = NULL;
25✔
1241

1242
  pQObj = mndAcquireQnode(pMnode, dnodeId);
25✔
1243
  if (pQObj) goto _OVER;
25✔
1244

1245
  pSObj = mndAcquireSnode(pMnode, dnodeId);
21✔
1246
  if (pSObj) goto _OVER;
21!
1247

1248
  pMObj = mndAcquireMnode(pMnode, dnodeId);
21✔
1249
  if (pMObj) goto _OVER;
21✔
1250

1251
  int32_t numOfVnodes = mndGetVnodesNum(pMnode, dnodeId);
19✔
1252
  if (numOfVnodes > 0) goto _OVER;
19✔
1253

1254
  isEmpty = true;
4✔
1255
_OVER:
25✔
1256
  mndReleaseMnode(pMnode, pMObj);
25✔
1257
  mndReleaseQnode(pMnode, pQObj);
25✔
1258
  mndReleaseSnode(pMnode, pSObj);
25✔
1259
  return isEmpty;
25✔
1260
}
1261

1262
static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) {
31✔
1263
  SMnode       *pMnode = pReq->info.node;
31✔
1264
  int32_t       code = -1;
31✔
1265
  SDnodeObj    *pDnode = NULL;
31✔
1266
  SMnodeObj    *pMObj = NULL;
31✔
1267
  SQnodeObj    *pQObj = NULL;
31✔
1268
  SSnodeObj    *pSObj = NULL;
31✔
1269
  SDropDnodeReq dropReq = {0};
31✔
1270

1271
  TAOS_CHECK_GOTO(tDeserializeSDropDnodeReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER);
31!
1272

1273
  mInfo("dnode:%d, start to drop, ep:%s:%d, force:%s, unsafe:%s", dropReq.dnodeId, dropReq.fqdn, dropReq.port,
31!
1274
        dropReq.force ? "true" : "false", dropReq.unsafe ? "true" : "false");
1275
  TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE), NULL, _OVER);
31✔
1276

1277
  bool force = dropReq.force;
30✔
1278
  if (dropReq.unsafe) {
30✔
1279
    force = true;
1✔
1280
  }
1281

1282
  pDnode = mndAcquireDnode(pMnode, dropReq.dnodeId);
30✔
1283
  if (pDnode == NULL) {
30✔
1284
    int32_t err = terrno;
1✔
1285
    char    ep[TSDB_EP_LEN + 1] = {0};
1✔
1286
    (void)snprintf(ep, sizeof(ep), dropReq.fqdn, dropReq.port);
1✔
1287
    pDnode = mndAcquireDnodeByEp(pMnode, ep);
1✔
1288
    if (pDnode == NULL) {
1!
1289
      code = err;
1✔
1290
      goto _OVER;
1✔
1291
    }
1292
  }
1293

1294
  pQObj = mndAcquireQnode(pMnode, dropReq.dnodeId);
29✔
1295
  pSObj = mndAcquireSnode(pMnode, dropReq.dnodeId);
29✔
1296
  pMObj = mndAcquireMnode(pMnode, dropReq.dnodeId);
29✔
1297
  if (pMObj != NULL) {
29✔
1298
    if (sdbGetSize(pMnode->pSdb, SDB_MNODE) <= 1) {
9✔
1299
      code = TSDB_CODE_MND_TOO_FEW_MNODES;
2✔
1300
      goto _OVER;
2✔
1301
    }
1302
    if (pMnode->selfDnodeId == dropReq.dnodeId) {
7✔
1303
      code = TSDB_CODE_MND_CANT_DROP_LEADER;
2✔
1304
      goto _OVER;
2✔
1305
    }
1306
  }
1307

1308
  int32_t numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id);
25✔
1309
  bool    isonline = mndIsDnodeOnline(pDnode, taosGetTimestampMs());
25✔
1310

1311
  if (isonline && force) {
25!
1312
    code = TSDB_CODE_DNODE_ONLY_USE_WHEN_OFFLINE;
×
UNCOV
1313
    mError("dnode:%d, failed to drop since %s, vnodes:%d mnode:%d qnode:%d snode:%d", pDnode->id, tstrerror(code),
×
1314
           numOfVnodes, pMObj != NULL, pQObj != NULL, pSObj != NULL);
UNCOV
1315
    goto _OVER;
×
1316
  }
1317

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

1326
  code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes, force, dropReq.unsafe);
23✔
1327
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
23✔
1328

1329
  char obj1[30] = {0};
23✔
1330
  (void)tsnprintf(obj1, sizeof(obj1), "%d", dropReq.dnodeId);
23✔
1331

1332
  auditRecord(pReq, pMnode->clusterId, "dropDnode", "", obj1, dropReq.sql, dropReq.sqlLen);
23✔
1333

1334
_OVER:
31✔
1335
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
31!
1336
    mError("dnode:%d, failed to drop since %s", dropReq.dnodeId, tstrerror(code));
10!
1337
  }
1338

1339
  mndReleaseDnode(pMnode, pDnode);
31✔
1340
  mndReleaseMnode(pMnode, pMObj);
31✔
1341
  mndReleaseQnode(pMnode, pQObj);
31✔
1342
  mndReleaseSnode(pMnode, pSObj);
31✔
1343
  tFreeSDropDnodeReq(&dropReq);
31✔
1344
  TAOS_RETURN(code);
31✔
1345
}
1346

1347
static int32_t mndProcessCreateEncryptKeyReqImpl(SRpcMsg *pReq, int32_t dnodeId, SDCfgDnodeReq *pDcfgReq) {
×
1348
  int32_t code = 0;
×
1349
  SMnode *pMnode = pReq->info.node;
×
1350
  SSdb   *pSdb = pMnode->pSdb;
×
1351
  void   *pIter = NULL;
×
UNCOV
1352
  int8_t  encrypting = 0;
×
1353

UNCOV
1354
  const STraceId *trace = &pReq->info.traceId;
×
1355

1356
  int32_t klen = strlen(pDcfgReq->value);
×
1357
  if (klen > ENCRYPT_KEY_LEN || klen < ENCRYPT_KEY_LEN_MIN) {
×
1358
    code = TSDB_CODE_DNODE_INVALID_ENCRYPT_KLEN;
×
UNCOV
1359
    mGError("msg:%p, failed to create encrypt_key since invalid key length:%d, valid range:[%d, %d]", pReq, klen,
×
1360
            ENCRYPT_KEY_LEN_MIN, ENCRYPT_KEY_LEN);
UNCOV
1361
    goto _exit;
×
1362
  }
1363

1364
  if (0 != (encrypting = atomic_val_compare_exchange_8(&pMnode->encryptMgmt.encrypting, 0, 1))) {
×
1365
    code = TSDB_CODE_QRY_DUPLICATED_OPERATION;
×
1366
    mGWarn("msg:%p, failed to create encrypt key since %s, encrypting:%" PRIi8, pReq, tstrerror(code), encrypting);
×
UNCOV
1367
    goto _exit;
×
1368
  }
1369

1370
  if (tsEncryptionKeyStat == ENCRYPT_KEY_STAT_SET || tsEncryptionKeyStat == ENCRYPT_KEY_STAT_LOADED) {
×
1371
    atomic_store_8(&pMnode->encryptMgmt.encrypting, 0);
×
1372
    code = TSDB_CODE_QRY_DUPLICATED_OPERATION;
×
UNCOV
1373
    mGWarn("msg:%p, failed to create encrypt key since %s, stat:%" PRIi8 ", checksum:%u", pReq, tstrerror(code),
×
1374
           tsEncryptionKeyStat, tsEncryptionKeyChksum);
UNCOV
1375
    goto _exit;
×
1376
  }
1377

1378
  atomic_store_16(&pMnode->encryptMgmt.nEncrypt, 0);
×
1379
  atomic_store_16(&pMnode->encryptMgmt.nSuccess, 0);
×
UNCOV
1380
  atomic_store_16(&pMnode->encryptMgmt.nFailed, 0);
×
1381

1382
  while (1) {
×
1383
    SDnodeObj *pDnode = NULL;
×
1384
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
×
1385
    if (pIter == NULL) break;
×
1386
    if (pDnode->offlineReason != DND_REASON_ONLINE) {
×
UNCOV
1387
      mGWarn("msg:%p, don't send create encrypt_key req since dnode:%d in offline state:%s", pReq, pDnode->id,
×
1388
             offlineReason[pDnode->offlineReason]);
1389
      sdbRelease(pSdb, pDnode);
×
UNCOV
1390
      continue;
×
1391
    }
1392

1393
    if (dnodeId == -1 || pDnode->id == dnodeId || dnodeId == 0) {
×
1394
      SEpSet  epSet = mndGetDnodeEpset(pDnode);
×
1395
      int32_t bufLen = tSerializeSDCfgDnodeReq(NULL, 0, pDcfgReq);
×
UNCOV
1396
      void   *pBuf = rpcMallocCont(bufLen);
×
1397

1398
      if (pBuf != NULL) {
×
1399
        if ((bufLen = tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq)) <= 0) {
×
1400
          code = bufLen;
×
1401
          sdbRelease(pSdb, pDnode);
×
UNCOV
1402
          goto _exit;
×
1403
        }
1404
        SRpcMsg rpcMsg = {.msgType = TDMT_DND_CREATE_ENCRYPT_KEY, .pCont = pBuf, .contLen = bufLen};
×
1405
        if (0 == tmsgSendReq(&epSet, &rpcMsg)) {
×
UNCOV
1406
          (void)atomic_add_fetch_16(&pMnode->encryptMgmt.nEncrypt, 1);
×
1407
        }
1408
      }
1409
    }
1410

UNCOV
1411
    sdbRelease(pSdb, pDnode);
×
1412
  }
1413

1414
  if (atomic_load_16(&pMnode->encryptMgmt.nEncrypt) <= 0) {
×
UNCOV
1415
    atomic_store_8(&pMnode->encryptMgmt.encrypting, 0);
×
1416
  }
1417

1418
_exit:
×
1419
  if (code != 0) {
×
UNCOV
1420
    if (terrno == 0) terrno = code;
×
1421
  }
UNCOV
1422
  return code;
×
1423
}
1424

1425
static int32_t mndProcessCreateEncryptKeyReq(SRpcMsg *pReq) {
×
UNCOV
1426
  int32_t code = 0;
×
1427

1428
#if defined(TD_ENTERPRISE) || defined(TD_ASTRA_TODO)
1429
  SMnode       *pMnode = pReq->info.node;
×
1430
  SMCfgDnodeReq cfgReq = {0};
×
UNCOV
1431
  TAOS_CHECK_RETURN(tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq));
×
1432

1433
  if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE)) != 0) {
×
1434
    tFreeSMCfgDnodeReq(&cfgReq);
×
UNCOV
1435
    TAOS_RETURN(code);
×
1436
  }
1437
  const STraceId *trace = &pReq->info.traceId;
×
1438
  SDCfgDnodeReq   dcfgReq = {0};
×
1439
  if (strncasecmp(cfgReq.config, "encrypt_key", 12) == 0) {
×
1440
    tstrncpy(dcfgReq.config, cfgReq.config, sizeof(dcfgReq.config));
×
1441
    tstrncpy(dcfgReq.value, cfgReq.value, sizeof(dcfgReq.value));
×
1442
    tFreeSMCfgDnodeReq(&cfgReq);
×
UNCOV
1443
    return mndProcessCreateEncryptKeyReqImpl(pReq, cfgReq.dnodeId, &dcfgReq);
×
1444
  } else {
1445
    code = TSDB_CODE_PAR_INTERNAL_ERROR;
×
1446
    tFreeSMCfgDnodeReq(&cfgReq);
×
UNCOV
1447
    TAOS_RETURN(code);
×
1448
  }
1449

1450
#else
1451
  TAOS_RETURN(code);
1452
#endif
1453
}
1454

1455
static int32_t mndProcessCreateEncryptKeyRsp(SRpcMsg *pRsp) {
×
1456
  SMnode *pMnode = pRsp->info.node;
×
1457
  int16_t nSuccess = 0;
×
UNCOV
1458
  int16_t nFailed = 0;
×
1459

1460
  if (0 == pRsp->code) {
×
UNCOV
1461
    nSuccess = atomic_add_fetch_16(&pMnode->encryptMgmt.nSuccess, 1);
×
1462
  } else {
UNCOV
1463
    nFailed = atomic_add_fetch_16(&pMnode->encryptMgmt.nFailed, 1);
×
1464
  }
1465

1466
  int16_t nReq = atomic_load_16(&pMnode->encryptMgmt.nEncrypt);
×
UNCOV
1467
  bool    finished = nSuccess + nFailed >= nReq;
×
1468

1469
  if (finished) {
×
UNCOV
1470
    atomic_store_8(&pMnode->encryptMgmt.encrypting, 0);
×
1471
  }
1472

1473
  const STraceId *trace = &pRsp->info.traceId;
×
UNCOV
1474
  mGInfo("msg:%p, create encrypt key rsp, nReq:%" PRIi16 ", nSucess:%" PRIi16 ", nFailed:%" PRIi16 ", %s", pRsp, nReq,
×
1475
         nSuccess, nFailed, finished ? "encrypt done" : "in encrypting");
1476

UNCOV
1477
  return 0;
×
1478
}
1479

1480
static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
1,446✔
1481
  SMnode *pMnode = pReq->info.node;
1,446✔
1482
  int32_t totalRows = 0;
1,446✔
1483
  int32_t numOfRows = 0;
1,446✔
1484
  char   *cfgOpts[TSDB_CONFIG_NUMBER] = {0};
1,446✔
1485
  char    cfgVals[TSDB_CONFIG_NUMBER][TSDB_CONFIG_VALUE_LEN + 1] = {0};
1,446✔
1486
  char   *pWrite = NULL;
1,446✔
1487
  int32_t cols = 0;
1,446✔
1488
  int32_t code = 0;
1,446✔
1489
  int32_t lino = 0;
1,446✔
1490

1491
  cfgOpts[totalRows] = "statusInterval";
1,446✔
1492
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsStatusInterval);
1,446✔
1493
  totalRows++;
1,446✔
1494

1495
  cfgOpts[totalRows] = "timezone";
1,446✔
1496
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", tsTimezoneStr);
1,446✔
1497
  totalRows++;
1,446✔
1498

1499
  cfgOpts[totalRows] = "locale";
1,446✔
1500
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", tsLocale);
1,446✔
1501
  totalRows++;
1,446✔
1502

1503
  cfgOpts[totalRows] = "charset";
1,446✔
1504
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", tsCharset);
1,446✔
1505
  totalRows++;
1,446✔
1506

1507
  cfgOpts[totalRows] = "monitor";
1,446✔
1508
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsEnableMonitor);
1,446✔
1509
  totalRows++;
1,446✔
1510

1511
  cfgOpts[totalRows] = "monitorInterval";
1,446✔
1512
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsMonitorInterval);
1,446✔
1513
  totalRows++;
1,446✔
1514

1515
  cfgOpts[totalRows] = "slowLogThreshold";
1,446✔
1516
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsSlowLogThreshold);
1,446✔
1517
  totalRows++;
1,446✔
1518

1519
  cfgOpts[totalRows] = "slowLogMaxLen";
1,446✔
1520
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsSlowLogMaxLen);
1,446✔
1521
  totalRows++;
1,446✔
1522

1523
  char scopeStr[64] = {0};
1,446✔
1524
  getSlowLogScopeString(tsSlowLogScope, scopeStr);
1,446✔
1525
  cfgOpts[totalRows] = "slowLogScope";
1,446✔
1526
  (void)snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", scopeStr);
1,446✔
1527
  totalRows++;
1,446✔
1528

1529
  char buf[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
1,446✔
1530
  char bufVal[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};
1,446✔
1531

1532
  for (int32_t i = 0; i < totalRows; i++) {
14,397✔
1533
    cols = 0;
12,959✔
1534

1535
    STR_WITH_MAXSIZE_TO_VARSTR(buf, cfgOpts[i], TSDB_CONFIG_OPTION_LEN);
12,959✔
1536
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
12,959✔
1537
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)buf, false), &lino, _OVER);
12,958!
1538

1539
    STR_WITH_MAXSIZE_TO_VARSTR(bufVal, cfgVals[i], TSDB_CONFIG_VALUE_LEN);
12,961✔
1540
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
12,961✔
1541
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)bufVal, false), &lino, _OVER);
12,955!
1542

1543
    numOfRows++;
12,951✔
1544
  }
1545

1546
_OVER:
1,438✔
1547
  if (code != 0) mError("failed to retrieve configs at line:%d since %s", lino, tstrerror(code));
1,438!
1548
  pShow->numOfRows += numOfRows;
1,445✔
1549
  return numOfRows;
1,445✔
1550
}
1551

UNCOV
1552
static void mndCancelGetNextConfig(SMnode *pMnode, void *pIter) {}
×
1553

1554
static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
7,408✔
1555
  SMnode    *pMnode = pReq->info.node;
7,408✔
1556
  SSdb      *pSdb = pMnode->pSdb;
7,408✔
1557
  int32_t    numOfRows = 0;
7,408✔
1558
  int32_t    cols = 0;
7,408✔
1559
  ESdbStatus objStatus = 0;
7,408✔
1560
  SDnodeObj *pDnode = NULL;
7,408✔
1561
  int64_t    curMs = taosGetTimestampMs();
7,412✔
1562
  char       buf[TSDB_EP_LEN + VARSTR_HEADER_SIZE];
1563
  int32_t    code = 0;
7,412✔
1564
  int32_t    lino = 0;
7,412✔
1565

1566
  while (numOfRows < rows) {
17,469✔
1567
    pShow->pIter = sdbFetchAll(pSdb, SDB_DNODE, pShow->pIter, (void **)&pDnode, &objStatus, true);
17,463✔
1568
    if (pShow->pIter == NULL) break;
17,471✔
1569
    bool online = mndIsDnodeOnline(pDnode, curMs);
10,052✔
1570

1571
    cols = 0;
10,046✔
1572

1573
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,046✔
1574
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pDnode->id, false), pDnode, &lino, _OVER);
10,037!
1575

1576
    STR_WITH_MAXSIZE_TO_VARSTR(buf, pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
10,033✔
1577

1578
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,033✔
1579
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, buf, false), pDnode, &lino, _OVER);
10,026!
1580

1581
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,042✔
1582
    int16_t id = mndGetVnodesNum(pMnode, pDnode->id);
10,038✔
1583
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&id, false), pDnode, &lino, _OVER);
10,047!
1584

1585
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,043✔
1586
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pDnode->numOfSupportVnodes, false), pDnode,
10,038!
1587
                        &lino, _OVER);
1588

1589
    const char *status = "ready";
10,037✔
1590
    if (objStatus == SDB_STATUS_CREATING) status = "creating";
10,037!
1591
    if (objStatus == SDB_STATUS_DROPPING) status = "dropping";
10,037!
1592
    if (!online) {
10,037✔
1593
      if (objStatus == SDB_STATUS_CREATING)
441!
UNCOV
1594
        status = "creating*";
×
1595
      else if (objStatus == SDB_STATUS_DROPPING)
441!
UNCOV
1596
        status = "dropping*";
×
1597
      else
1598
        status = "offline";
441✔
1599
    }
1600

1601
    STR_TO_VARSTR(buf, status);
10,037✔
1602
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,037✔
1603
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, buf, false), pDnode, &lino, _OVER);
10,038!
1604

1605
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,046✔
1606
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pDnode->createdTime, false), pDnode, &lino,
10,038!
1607
                        _OVER);
1608

1609
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,035✔
1610
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pDnode->rebootTime, false), pDnode, &lino,
10,030!
1611
                        _OVER);
1612

1613
    char *b = taosMemoryCalloc(VARSTR_HEADER_SIZE + strlen(offlineReason[pDnode->offlineReason]) + 1, 1);
10,044!
1614
    STR_TO_VARSTR(b, online ? "" : offlineReason[pDnode->offlineReason]);
10,056✔
1615

1616
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,056✔
1617
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, b, false), pDnode, &lino, _OVER);
10,048!
1618
    taosMemoryFreeClear(b);
10,044!
1619

1620
#ifdef TD_ENTERPRISE
1621
    STR_TO_VARSTR(buf, pDnode->machineId);
10,047✔
1622
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
10,047✔
1623
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, buf, false), pDnode, &lino, _OVER);
10,045!
1624
#endif
1625

1626
    numOfRows++;
10,046✔
1627
    sdbRelease(pSdb, pDnode);
10,046✔
1628
  }
1629

1630
_OVER:
6✔
1631
  if (code != 0) mError("failed to retrieve dnodes at line:%d since %s", lino, tstrerror(code));
7,425!
1632

1633
  pShow->numOfRows += numOfRows;
7,419✔
1634
  return numOfRows;
7,419✔
1635
}
1636

1637
static void mndCancelGetNextDnode(SMnode *pMnode, void *pIter) {
×
1638
  SSdb *pSdb = pMnode->pSdb;
×
1639
  sdbCancelFetchByType(pSdb, pIter, SDB_DNODE);
×
UNCOV
1640
}
×
1641

1642
SArray *mndGetAllDnodeFqdns(SMnode *pMnode) {
2,360✔
1643
  SDnodeObj *pObj = NULL;
2,360✔
1644
  void      *pIter = NULL;
2,360✔
1645
  SSdb      *pSdb = pMnode->pSdb;
2,360✔
1646
  SArray    *fqdns = taosArrayInit(4, sizeof(void *));
2,360✔
1647
  while (1) {
2,350✔
1648
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pObj);
4,710✔
1649
    if (pIter == NULL) break;
4,710✔
1650

1651
    char *fqdn = taosStrdup(pObj->fqdn);
2,350!
1652
    if (taosArrayPush(fqdns, &fqdn) == NULL) {
2,350!
UNCOV
1653
      mError("failed to fqdn into array, but continue at this time");
×
1654
    }
1655
    sdbRelease(pSdb, pObj);
2,350✔
1656
  }
1657
  return fqdns;
2,360✔
1658
}
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