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

taosdata / TDengine / #5033

24 Apr 2026 11:25AM UTC coverage: 73.058% (-0.02%) from 73.076%
#5033

push

travis-ci

web-flow
merge: from main to 3.0 branch #35224

merge: from main to 3.0 branch[manual-only]

1337 of 1975 new or added lines in 48 files covered. (67.7%)

14198 existing lines in 150 files now uncovered.

275895 of 377640 relevant lines covered (73.06%)

132323361.15 hits per line

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

78.45
/source/dnode/mnode/impl/src/mndCluster.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 "mndCluster.h"
18
#include "audit.h"
19
#include "mndGrant.h"
20
#include "mndPrivilege.h"
21
#include "mndSecurityPolicy.h"
22
#include "mndShow.h"
23
#include "mndTrans.h"
24

25
#define CLUSTER_VER_NUMBE    1
26
#define CLUSTER_RESERVE_SIZE 60
27
int64_t tsExpireTime = 0;
28

29
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
30
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw);
31
static int32_t  mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster);
32
static int32_t  mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster);
33
static int32_t  mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOldCluster, SClusterObj *pNewCluster);
34
static int32_t  mndCreateDefaultCluster(SMnode *pMnode);
35
static int32_t  mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
36
static void     mndCancelGetNextCluster(SMnode *pMnode, void *pIter);
37
static int32_t  mndProcessUptimeTimer(SRpcMsg *pReq);
38
static int32_t  mndProcessConfigClusterReq(SRpcMsg *pReq);
39
static int32_t  mndProcessConfigClusterRsp(SRpcMsg *pReq);
40

41
int32_t mndInitCluster(SMnode *pMnode) {
478,377✔
42
  SSdbTable table = {
478,377✔
43
      .sdbType = SDB_CLUSTER,
44
      .keyType = SDB_KEY_INT64,
45
      .deployFp = (SdbDeployFp)mndCreateDefaultCluster,
46
      .encodeFp = (SdbEncodeFp)mndClusterActionEncode,
47
      .decodeFp = (SdbDecodeFp)mndClusterActionDecode,
48
      .insertFp = (SdbInsertFp)mndClusterActionInsert,
49
      .updateFp = (SdbUpdateFp)mndClusterActionUpdate,
50
      .deleteFp = (SdbDeleteFp)mndClusterActionDelete,
51
  };
52

53
  mndSetMsgHandle(pMnode, TDMT_MND_UPTIME_TIMER, mndProcessUptimeTimer);
478,377✔
54
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER, mndProcessConfigClusterReq);
478,377✔
55
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER_RSP, mndProcessConfigClusterRsp);
478,377✔
56
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndRetrieveClusters);
478,377✔
57
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndCancelGetNextCluster);
478,377✔
58

59
  return sdbSetTable(pMnode->pSdb, table);
478,377✔
60
}
61

62
void mndCleanupCluster(SMnode *pMnode) {}
478,315✔
63

64
int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
168✔
65
  int32_t code = 0;
168✔
66
  SSdb   *pSdb = pMnode->pSdb;
168✔
67

68
  SClusterObj *pCluster = sdbAcquire(pSdb, SDB_CLUSTER, &pMnode->clusterId);
168✔
69
  if (pCluster == NULL) {
168✔
UNCOV
70
    code = terrno;
×
71
    TAOS_RETURN(code);
×
72
  }
73

74
  tstrncpy(clusterName, pCluster->name, len);
168✔
75
  sdbRelease(pSdb, pCluster);
168✔
76
  return 0;
168✔
77
}
78

79
static SClusterObj *mndAcquireCluster(SMnode *pMnode, void **ppIter) {
58,416,696✔
80
  SSdb *pSdb = pMnode->pSdb;
58,416,696✔
81
  void *pIter = NULL;
58,416,696✔
82

83
  while (1) {
84
    SClusterObj *pCluster = NULL;
58,416,696✔
85
    pIter = sdbFetch(pSdb, SDB_CLUSTER, pIter, (void **)&pCluster);
58,416,696✔
86
    if (pIter == NULL) break;
58,416,696✔
87

88
    *ppIter = pIter;
57,489,146✔
89
    return pCluster;
57,489,146✔
90
  }
91

92
  return NULL;
927,550✔
93
}
94

95
static void mndReleaseCluster(SMnode *pMnode, SClusterObj *pCluster, void *pIter) {
57,489,146✔
96
  SSdb *pSdb = pMnode->pSdb;
57,489,146✔
97
  sdbCancelFetch(pSdb, pIter);
57,489,146✔
98
  sdbRelease(pSdb, pCluster);
57,489,146✔
99
}
57,489,146✔
100

101
int64_t mndGetClusterId(SMnode *pMnode) {
54,595,833✔
102
  int64_t      clusterId = 0;
54,595,833✔
103
  void        *pIter = NULL;
54,595,833✔
104
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
54,595,833✔
105
  if (pCluster != NULL) {
54,595,833✔
106
    clusterId = pCluster->id;
53,683,439✔
107
    mndReleaseCluster(pMnode, pCluster, pIter);
53,683,439✔
108
  }
109

110
  return clusterId;
54,595,833✔
111
}
112

113
int64_t mndGetClusterCreateTime(SMnode *pMnode) {
1,953,253✔
114
  int64_t      createTime = 0;
1,953,253✔
115
  void        *pIter = NULL;
1,953,253✔
116
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
1,953,253✔
117
  if (pCluster != NULL) {
1,953,253✔
118
    createTime = pCluster->createdTime;
1,938,097✔
119
    mndReleaseCluster(pMnode, pCluster, pIter);
1,938,097✔
120
  }
121

122
  return createTime;
1,953,253✔
123
}
124

125
static int32_t mndGetClusterUpTimeImp(SClusterObj *pCluster) {
1,762,551✔
126
#if 0
127
  int32_t upTime = taosGetTimestampSec() - pCluster->updateTime / 1000;
128
  upTime = upTime + pCluster->upTime;
129
  return upTime;
130
#else
131
  return pCluster->upTime;
1,762,551✔
132
#endif
133
}
134

135
int64_t mndGetClusterUpTime(SMnode *pMnode) {
1,760,348✔
136
  int64_t      upTime = 0;
1,760,348✔
137
  void        *pIter = NULL;
1,760,348✔
138
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
1,760,348✔
139
  if (pCluster != NULL) {
1,760,348✔
140
    upTime = mndGetClusterUpTimeImp(pCluster);
1,760,348✔
141
    mndReleaseCluster(pMnode, pCluster, pIter);
1,760,348✔
142
  }
143

144
  return upTime;
1,760,348✔
145
}
146

147
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
1,364,286✔
148
  int32_t code = 0;
1,364,286✔
149
  int32_t lino = 0;
1,364,286✔
150
  terrno = TSDB_CODE_OUT_OF_MEMORY;
1,364,286✔
151

152
  SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, CLUSTER_VER_NUMBE, sizeof(SClusterObj) + CLUSTER_RESERVE_SIZE);
1,364,286✔
153
  if (pRaw == NULL) goto _OVER;
1,364,286✔
154

155
  int32_t dataPos = 0;
1,364,286✔
156
  SDB_SET_INT64(pRaw, dataPos, pCluster->id, _OVER)
1,364,286✔
157
  SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime, _OVER)
1,364,286✔
158
  SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime, _OVER)
1,364,286✔
159
  SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, _OVER)
1,364,286✔
160
  SDB_SET_INT32(pRaw, dataPos, pCluster->upTime, _OVER)
1,364,286✔
161
  SDB_SET_RESERVE(pRaw, dataPos, CLUSTER_RESERVE_SIZE, _OVER)
1,364,286✔
162
  SDB_SET_DATALEN(pRaw, dataPos, _OVER);
1,364,286✔
163

164
  terrno = 0;
1,364,286✔
165

166
_OVER:
1,364,286✔
167
  if (terrno != 0) {
1,364,286✔
UNCOV
168
    mError("cluster:%" PRId64 ", failed to encode to raw:%p since %s", pCluster->id, pRaw, terrstr());
×
169
    sdbFreeRaw(pRaw);
×
170
    return NULL;
×
171
  }
172

173
  mTrace("cluster:%" PRId64 ", encode to raw:%p, row:%p", pCluster->id, pRaw, pCluster);
1,364,286✔
174
  return pRaw;
1,364,286✔
175
}
176

177
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
586,555✔
178
  int32_t code = 0;
586,555✔
179
  int32_t lino = 0;
586,555✔
180
  terrno = TSDB_CODE_OUT_OF_MEMORY;
586,555✔
181
  SClusterObj *pCluster = NULL;
586,555✔
182
  SSdbRow     *pRow = NULL;
586,555✔
183

184
  int8_t sver = 0;
586,555✔
185
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
586,555✔
186

187
  if (sver != CLUSTER_VER_NUMBE) {
586,555✔
UNCOV
188
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
189
    goto _OVER;
×
190
  }
191

192
  pRow = sdbAllocRow(sizeof(SClusterObj));
586,555✔
193
  if (pRow == NULL) goto _OVER;
586,555✔
194

195
  pCluster = sdbGetRowObj(pRow);
586,555✔
196
  if (pCluster == NULL) goto _OVER;
586,555✔
197

198
  int32_t dataPos = 0;
586,555✔
199
  SDB_GET_INT64(pRaw, dataPos, &pCluster->id, _OVER)
586,555✔
200
  SDB_GET_INT64(pRaw, dataPos, &pCluster->createdTime, _OVER)
586,555✔
201
  SDB_GET_INT64(pRaw, dataPos, &pCluster->updateTime, _OVER)
586,555✔
202
  SDB_GET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, _OVER)
586,555✔
203
  SDB_GET_INT32(pRaw, dataPos, &pCluster->upTime, _OVER)
586,555✔
204
  SDB_GET_RESERVE(pRaw, dataPos, CLUSTER_RESERVE_SIZE, _OVER)
586,555✔
205

206
  terrno = 0;
586,555✔
207

208
_OVER:
586,555✔
209
  if (terrno != 0) {
586,555✔
UNCOV
210
    mError("cluster:%" PRId64 ", failed to decode from raw:%p since %s", pCluster == NULL ? 0 : pCluster->id, pRaw,
×
211
           terrstr());
UNCOV
212
    taosMemoryFreeClear(pRow);
×
213
    return NULL;
×
214
  }
215

216
  mTrace("cluster:%" PRId64 ", decode from raw:%p, row:%p", pCluster->id, pRaw, pCluster);
586,555✔
217
  return pRow;
586,555✔
218
}
219

220
static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster) {
478,361✔
221
  mTrace("cluster:%" PRId64 ", perform insert action, row:%p", pCluster->id, pCluster);
478,361✔
222
  pSdb->pMnode->clusterId = pCluster->id;
478,361✔
223
  pCluster->updateTime = taosGetTimestampMs();
478,361✔
224
  return 0;
478,361✔
225
}
226

227
static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) {
586,509✔
228
  mTrace("cluster:%" PRId64 ", perform delete action, row:%p", pCluster->id, pCluster);
586,509✔
229
  return 0;
586,509✔
230
}
231

232
static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOld, SClusterObj *pNew) {
108,194✔
233
  mTrace("cluster:%" PRId64 ", perform update action, old row:%p new row:%p, uptime from %d to %d", pOld->id, pOld,
108,194✔
234
         pNew, pOld->upTime, pNew->upTime);
235
  pOld->upTime = pNew->upTime;
108,194✔
236
  pOld->updateTime = taosGetTimestampMs();
108,194✔
237
  return 0;
108,194✔
238
}
239

240
static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
346,159✔
241
  SClusterObj clusterObj = {0};
346,159✔
242
  clusterObj.createdTime = taosGetTimestampMs();
346,159✔
243
  clusterObj.updateTime = clusterObj.createdTime;
346,159✔
244

245
  int32_t code = taosGetSystemUUIDLen(clusterObj.name, TSDB_CLUSTER_ID_LEN);
346,159✔
246
  if (code != 0) {
346,159✔
UNCOV
247
    tstrncpy(clusterObj.name, "tdengine3.0", sizeof(clusterObj.name));
×
248
    mError("failed to get name from system, set to default val %s", clusterObj.name);
×
249
  }
250

251
  clusterObj.id = mndGenerateUid(clusterObj.name, TSDB_CLUSTER_ID_LEN);
346,159✔
252
  clusterObj.id = (clusterObj.id >= 0 ? clusterObj.id : -clusterObj.id);
346,159✔
253
  pMnode->clusterId = clusterObj.id;
346,159✔
254
  mInfo("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name);
346,159✔
255

256
  SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj);
346,159✔
257
  if (pRaw == NULL) {
346,159✔
UNCOV
258
    code = terrno;
×
259
    TAOS_RETURN(code);
×
260
  }
261
  code = sdbSetRawStatus(pRaw, SDB_STATUS_READY);
346,159✔
262
  if (code != 0) {
346,159✔
UNCOV
263
    sdbFreeRaw(pRaw);
×
264
    TAOS_RETURN(code);
×
265
  }
266

267
  mInfo("cluster:%" PRId64 ", will be created when deploying, raw:%p", clusterObj.id, pRaw);
346,159✔
268

269
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-cluster");
346,159✔
270
  if (pTrans == NULL) {
346,159✔
UNCOV
271
    sdbFreeRaw(pRaw);
×
272
    mError("cluster:%" PRId64 ", failed to create since %s", clusterObj.id, terrstr());
×
273
    code = terrno;
×
274
    TAOS_RETURN(code);
×
275
  }
276
  mInfo("trans:%d, used to create cluster:%" PRId64, pTrans->id, clusterObj.id);
346,159✔
277

278
  if ((code = mndTransAppendCommitlog(pTrans, pRaw)) != 0) {
346,159✔
UNCOV
279
    mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
×
280
    mndTransDrop(pTrans);
×
281
    TAOS_RETURN(code);
×
282
  }
283
  code = sdbSetRawStatus(pRaw, SDB_STATUS_READY);
346,159✔
284
  if (code != 0) {
346,159✔
UNCOV
285
    sdbFreeRaw(pRaw);
×
286
    mndTransDrop(pTrans);
×
287
    TAOS_RETURN(code);
×
288
  }
289

290
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
346,159✔
UNCOV
291
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
292
    mndTransDrop(pTrans);
×
293
    TAOS_RETURN(code);
×
294
  }
295

296
  mndTransDrop(pTrans);
346,159✔
297
  return 0;
346,159✔
298
}
299

300
static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
2,203✔
301
  SMnode      *pMnode = pMsg->info.node;
2,203✔
302
  SSdb        *pSdb = pMnode->pSdb;
2,203✔
303
  int32_t      code = 0;
2,203✔
304
  int32_t      lino = 0;
2,203✔
305
  int32_t      numOfRows = 0;
2,203✔
306
  int32_t      cols = 0;
2,203✔
307
  SClusterObj *pCluster = NULL;
2,203✔
308

309
  while (numOfRows < rows) {
4,406✔
310
    pShow->pIter = sdbFetch(pSdb, SDB_CLUSTER, pShow->pIter, (void **)&pCluster);
4,406✔
311
    if (pShow->pIter == NULL) break;
4,406✔
312

313
    cols = 0;
2,203✔
314
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2,203✔
315
    COL_DATA_SET_VAL_GOTO((const char *)&pCluster->id, false, pCluster, pShow->pIter, _OVER);
2,203✔
316

317
    char buf[tListLen(pCluster->name) + VARSTR_HEADER_SIZE] = {0};
2,203✔
318
    STR_WITH_MAXSIZE_TO_VARSTR(buf, pCluster->name, pShow->pMeta->pSchemas[cols].bytes);
2,203✔
319

320
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2,203✔
321
    COL_DATA_SET_VAL_GOTO(buf, false, pCluster, pShow->pIter, _OVER);
2,203✔
322

323
    int32_t upTime = mndGetClusterUpTimeImp(pCluster);
2,203✔
324
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2,203✔
325
    COL_DATA_SET_VAL_GOTO((const char *)&upTime, false, pCluster, pShow->pIter, _OVER);
2,203✔
326

327
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2,203✔
328
    COL_DATA_SET_VAL_GOTO((const char *)&pCluster->createdTime, false, pCluster, pShow->pIter, _OVER);
2,203✔
329

330
    char ver[12] = {0};
2,203✔
331
    STR_WITH_MAXSIZE_TO_VARSTR(ver, tsVersionName, pShow->pMeta->pSchemas[cols].bytes);
2,203✔
332
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2,203✔
333
    COL_DATA_SET_VAL_GOTO((const char *)ver, false, pCluster, pShow->pIter, _OVER);
2,203✔
334

335
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2,203✔
336
    if (tsExpireTime <= 0) {
2,203✔
UNCOV
337
      colDataSetNULL(pColInfo, numOfRows);
×
338
    } else {
339
      COL_DATA_SET_VAL_GOTO((const char *)&tsExpireTime, false, pCluster, pShow->pIter, _OVER);
2,203✔
340
    }
341

342
    sdbRelease(pSdb, pCluster);
2,203✔
343
    numOfRows++;
2,203✔
344
  }
345

346
  pShow->numOfRows += numOfRows;
2,203✔
347

348
_OVER:
2,203✔
349
  if (code != 0) {
2,203✔
UNCOV
350
    mError("failed to retrieve cluster info at line %d since %s", lino, tstrerror(code));
×
351
    TAOS_RETURN(code);
×
352
  }
353
  return numOfRows;
2,203✔
354
}
355

UNCOV
356
static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter) {
×
357
  SSdb *pSdb = pMnode->pSdb;
×
358
  sdbCancelFetchByType(pSdb, pIter, SDB_CLUSTER);
×
359
}
×
360

361
static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) {
102,998✔
362
  SMnode      *pMnode = pReq->info.node;
102,998✔
363
  SClusterObj  clusterObj = {0};
102,998✔
364
  void        *pIter = NULL;
102,998✔
365
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
102,998✔
366
  if (pCluster != NULL) {
102,998✔
367
    (void)memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
102,998✔
368
    clusterObj.upTime += tsUptimeInterval;
102,998✔
369
    mndReleaseCluster(pMnode, pCluster, pIter);
102,998✔
370
  }
371

372
  if (clusterObj.id <= 0) {
102,998✔
UNCOV
373
    mError("can't get cluster info while update uptime");
×
374
    return 0;
×
375
  }
376

377
  int32_t code = 0;
102,998✔
378
  mInfo("update cluster uptime to %d", clusterObj.upTime);
102,998✔
379
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "update-uptime");
102,998✔
380
  if (pTrans == NULL) {
102,998✔
UNCOV
381
    code = terrno;
×
382
    TAOS_RETURN(code);
×
383
  }
384

385
  SSdbRaw *pCommitRaw = mndClusterActionEncode(&clusterObj);
102,998✔
386
  if (pCommitRaw == NULL) {
102,998✔
UNCOV
387
    mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
×
388
    mndTransDrop(pTrans);
×
389
    code = terrno;
×
390
    TAOS_RETURN(code);
×
391
  }
392

393
  if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
102,998✔
UNCOV
394
    mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
×
395
    mndTransDrop(pTrans);
×
396
    TAOS_RETURN(code);
×
397
  }
398
  code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
102,998✔
399
  if (code != 0) {
102,998✔
UNCOV
400
    sdbFreeRaw(pCommitRaw);
×
401
    mndTransDrop(pTrans);
×
402
    TAOS_RETURN(code);
×
403
  }
404

405
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
102,998✔
UNCOV
406
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
UNCOV
407
    mndTransDrop(pTrans);
×
UNCOV
408
    TAOS_RETURN(code);
×
409
  }
410

411
  mndTransDrop(pTrans);
102,998✔
412
  return 0;
102,998✔
413
}
414

415
int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
4,264✔
416
  int32_t         code = 0;
4,264✔
417
  SMnode         *pMnode = pReq->info.node;
4,264✔
418
  SMCfgClusterReq cfgReq = {0};
4,264✔
419
  int64_t         tss = taosGetTimestampMs();
4,264✔
420
  if (tDeserializeSMCfgClusterReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) {
4,264✔
UNCOV
421
    code = TSDB_CODE_INVALID_MSG;
×
422
    TAOS_RETURN(code);
×
423
  }
424

425
  mInfo("cluster: start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
4,264✔
426
  if ((code = mndCheckOperPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_CONFIG_CLUSTER)) != 0) {
4,264✔
UNCOV
427
    goto _exit;
×
428
  }
429

430
  SClusterObj  clusterObj = {0};
4,264✔
431
  void        *pIter = NULL;
4,264✔
432
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
4,264✔
433
  if (!pCluster || pCluster->id <= 0) {
4,264✔
UNCOV
434
    code = TSDB_CODE_APP_IS_STARTING;
×
435
    if (pCluster) mndReleaseCluster(pMnode, pCluster, pIter);
×
436
    goto _exit;
×
437
  }
438
  (void)memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
4,264✔
439
  mndReleaseCluster(pMnode, pCluster, pIter);
4,264✔
440

441
  if (strncmp(cfgReq.config, GRANT_ACTIVE_CODE, TSDB_DNODE_CONFIG_LEN) == 0) {
4,264✔
442
#ifdef TD_ENTERPRISE
443
    if (0 != (code = mndProcessConfigGrantReq(pMnode, pReq, &cfgReq))) {
984✔
444
      goto _exit;
492✔
445
    }
446
#else
447
    code = TSDB_CODE_OPS_NOT_SUPPORT;
448
    goto _exit;
449
#endif
450

451
  } else if (taosStrncasecmp(cfgReq.config, "SoD", 4) == 0 ||
3,280✔
452
             taosStrncasecmp(cfgReq.config, "separation_of_duties", 21) == 0) {
2,296✔
453
#ifdef TD_ENTERPRISE
454
    if (0 != (code = mndProcessConfigSoDReq(pMnode, pReq, &cfgReq))) {
1,148✔
455
      goto _exit;
984✔
456
    }
457
#else
458
    code = TSDB_CODE_OPS_NOT_SUPPORT;
459
    goto _exit;
460
#endif
461
  } else if (taosStrncasecmp(cfgReq.config, "MAC", 4) == 0 ||
2,132✔
462
             taosStrncasecmp(cfgReq.config, "mandatory_access_control", 25) == 0) {
164✔
463
#ifdef TD_ENTERPRISE
464
    if (0 != (code = mndProcessConfigMacReq(pMnode, pReq, &cfgReq))) {
2,132✔
465
      goto _exit;
1,804✔
466
    }
467
#else
468
    code = TSDB_CODE_OPS_NOT_SUPPORT;
469
    goto _exit;
470
#endif
471
  } else {
UNCOV
472
    code = TSDB_CODE_OPS_NOT_SUPPORT;
×
UNCOV
473
    goto _exit;
×
474
  }
475

476
  if (tsAuditLevel >= AUDIT_LEVEL_CLUSTER) {
984✔
477
    int64_t tse = taosGetTimestampMs();
984✔
478
    double  duration = (double)(tse - tss);
984✔
479
    duration = duration / 1000;
984✔
480
    {  // audit
481
      auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql,
984✔
482
                  TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1), duration, 0);
984✔
483
    }
484
  }
485

486
_exit:
4,264✔
487
  tFreeSMCfgClusterReq(&cfgReq);
4,264✔
488
  if (code != 0) {
4,264✔
489
    mError("cluster: failed to config:%s %s since %s", cfgReq.config, cfgReq.value, tstrerror(code));
3,280✔
490
  } else {
491
    mInfo("cluster: success to config:%s %s", cfgReq.config, cfgReq.value);
984✔
492
  }
493
  TAOS_RETURN(code);
4,264✔
494
}
495

UNCOV
496
int32_t mndProcessConfigClusterRsp(SRpcMsg *pRsp) {
×
UNCOV
497
  mInfo("config rsp from cluster");
×
UNCOV
498
  return 0;
×
499
}
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