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

taosdata / TDengine / #5035

24 Apr 2026 11:25AM UTC coverage: 73.06% (+0.002%) from 73.058%
#5035

push

travis-ci

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

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

1344 of 1975 new or added lines in 48 files covered. (68.05%)

14127 existing lines in 142 files now uncovered.

275902 of 377640 relevant lines covered (73.06%)

132208813.58 hits per line

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

79.46
/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) {
497,199✔
42
  SSdbTable table = {
497,199✔
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);
497,199✔
54
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER, mndProcessConfigClusterReq);
497,199✔
55
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER_RSP, mndProcessConfigClusterRsp);
497,199✔
56
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndRetrieveClusters);
497,199✔
57
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndCancelGetNextCluster);
497,199✔
58

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

62
void mndCleanupCluster(SMnode *pMnode) {}
497,130✔
63

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

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

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

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

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

88
    *ppIter = pIter;
58,703,398✔
89
    return pCluster;
58,703,398✔
90
  }
91

92
  return NULL;
971,619✔
93
}
94

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

101
int64_t mndGetClusterId(SMnode *pMnode) {
55,715,151✔
102
  int64_t      clusterId = 0;
55,715,151✔
103
  void        *pIter = NULL;
55,715,151✔
104
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
55,715,151✔
105
  if (pCluster != NULL) {
55,715,151✔
106
    clusterId = pCluster->id;
54,760,277✔
107
    mndReleaseCluster(pMnode, pCluster, pIter);
54,760,277✔
108
  }
109

110
  return clusterId;
55,715,151✔
111
}
112

113
int64_t mndGetClusterCreateTime(SMnode *pMnode) {
2,019,902✔
114
  int64_t      createTime = 0;
2,019,902✔
115
  void        *pIter = NULL;
2,019,902✔
116
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
2,019,902✔
117
  if (pCluster != NULL) {
2,019,902✔
118
    createTime = pCluster->createdTime;
2,003,157✔
119
    mndReleaseCluster(pMnode, pCluster, pIter);
2,003,157✔
120
  }
121

122
  return createTime;
2,019,902✔
123
}
124

125
static int32_t mndGetClusterUpTimeImp(SClusterObj *pCluster) {
1,836,557✔
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,836,557✔
132
#endif
133
}
134

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

144
  return upTime;
1,833,940✔
145
}
146

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

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

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

164
  terrno = 0;
1,413,448✔
165

166
_OVER:
1,413,448✔
167
  if (terrno != 0) {
1,413,448✔
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,413,448✔
174
  return pRaw;
1,413,448✔
175
}
176

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

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

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

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

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

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

206
  terrno = 0;
604,460✔
207

208
_OVER:
604,460✔
209
  if (terrno != 0) {
604,460✔
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);
604,460✔
217
  return pRow;
604,460✔
218
}
219

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

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

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

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

245
  int32_t code = taosGetSystemUUIDLen(clusterObj.name, TSDB_CLUSTER_ID_LEN);
357,261✔
246
  if (code != 0) {
357,261✔
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);
357,261✔
252
  clusterObj.id = (clusterObj.id >= 0 ? clusterObj.id : -clusterObj.id);
357,261✔
253
  pMnode->clusterId = clusterObj.id;
357,261✔
254
  mInfo("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name);
357,261✔
255

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

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

269
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-cluster");
357,261✔
270
  if (pTrans == NULL) {
357,261✔
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);
357,261✔
277

278
  if ((code = mndTransAppendCommitlog(pTrans, pRaw)) != 0) {
357,261✔
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);
357,261✔
284
  if (code != 0) {
357,261✔
UNCOV
285
    sdbFreeRaw(pRaw);
×
286
    mndTransDrop(pTrans);
×
287
    TAOS_RETURN(code);
×
288
  }
289

290
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
357,261✔
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);
357,261✔
297
  return 0;
357,261✔
298
}
299

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

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

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

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

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

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

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

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

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

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

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

348
_OVER:
2,617✔
349
  if (code != 0) {
2,617✔
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,617✔
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) {
101,394✔
362
  SMnode      *pMnode = pReq->info.node;
101,394✔
363
  SClusterObj  clusterObj = {0};
101,394✔
364
  void        *pIter = NULL;
101,394✔
365
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
101,394✔
366
  if (pCluster != NULL) {
101,394✔
367
    (void)memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
101,394✔
368
    clusterObj.upTime += tsUptimeInterval;
101,394✔
369
    mndReleaseCluster(pMnode, pCluster, pIter);
101,394✔
370
  }
371

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

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

385
  SSdbRaw *pCommitRaw = mndClusterActionEncode(&clusterObj);
101,394✔
386
  if (pCommitRaw == NULL) {
101,394✔
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) {
101,394✔
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);
101,394✔
399
  if (code != 0) {
101,394✔
UNCOV
400
    sdbFreeRaw(pCommitRaw);
×
401
    mndTransDrop(pTrans);
×
402
    TAOS_RETURN(code);
×
403
  }
404

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

411
  mndTransDrop(pTrans);
101,010✔
412
  return 0;
101,010✔
413
}
414

415
int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
4,630✔
416
  int32_t         code = 0;
4,630✔
417
  SMnode         *pMnode = pReq->info.node;
4,630✔
418
  SMCfgClusterReq cfgReq = {0};
4,630✔
419
  int64_t         tss = taosGetTimestampMs();
4,630✔
420
  if (tDeserializeSMCfgClusterReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) {
4,630✔
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,630✔
426
  if ((code = mndCheckOperPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_CONFIG_CLUSTER)) != 0) {
4,630✔
UNCOV
427
    goto _exit;
×
428
  }
429

430
  SClusterObj  clusterObj = {0};
4,630✔
431
  void        *pIter = NULL;
4,630✔
432
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
4,630✔
433
  if (!pCluster || pCluster->id <= 0) {
4,630✔
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,630✔
439
  mndReleaseCluster(pMnode, pCluster, pIter);
4,630✔
440

441
  if (strncmp(cfgReq.config, GRANT_ACTIVE_CODE, TSDB_DNODE_CONFIG_LEN) == 0) {
4,630✔
442
#ifdef TD_ENTERPRISE
443
    if (0 != (code = mndProcessConfigGrantReq(pMnode, pReq, &cfgReq))) {
1,050✔
444
      goto _exit;
525✔
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,580✔
452
             taosStrncasecmp(cfgReq.config, "separation_of_duties", 21) == 0) {
2,506✔
453
#ifdef TD_ENTERPRISE
454
    if (0 != (code = mndProcessConfigSoDReq(pMnode, pReq, &cfgReq))) {
1,253✔
455
      goto _exit;
1,074✔
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,327✔
462
             taosStrncasecmp(cfgReq.config, "mandatory_access_control", 25) == 0) {
179✔
463
#ifdef TD_ENTERPRISE
464
    if (0 != (code = mndProcessConfigMacReq(pMnode, pReq, &cfgReq))) {
2,327✔
465
      goto _exit;
1,969✔
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) {
1,062✔
477
    int64_t tse = taosGetTimestampMs();
1,062✔
478
    double  duration = (double)(tse - tss);
1,062✔
479
    duration = duration / 1000;
1,062✔
480
    {  // audit
481
      auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql,
1,062✔
482
                  TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1), duration, 0);
1,062✔
483
    }
484
  }
485

486
_exit:
4,630✔
487
  tFreeSMCfgClusterReq(&cfgReq);
4,630✔
488
  if (code != 0) {
4,630✔
489
    mError("cluster: failed to config:%s %s since %s", cfgReq.config, cfgReq.value, tstrerror(code));
3,568✔
490
  } else {
491
    mInfo("cluster: success to config:%s %s", cfgReq.config, cfgReq.value);
1,062✔
492
  }
493
  TAOS_RETURN(code);
4,630✔
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