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

taosdata / TDengine / #5051

13 May 2026 12:00PM UTC coverage: 73.358% (-0.04%) from 73.398%
#5051

push

travis-ci

web-flow
feat: taosdump support stream backup/restore (#35326)

139 of 170 new or added lines in 3 files covered. (81.76%)

714 existing lines in 146 files now uncovered.

281543 of 383795 relevant lines covered (73.36%)

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

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

62
void mndCleanupCluster(SMnode *pMnode) {}
545,287✔
63

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

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

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

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

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

88
    *ppIter = pIter;
62,821,547✔
89
    return pCluster;
62,821,547✔
90
  }
91

92
  return NULL;
1,073,388✔
93
}
94

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

101
int64_t mndGetClusterId(SMnode *pMnode) {
59,579,272✔
102
  int64_t      clusterId = 0;
59,579,272✔
103
  void        *pIter = NULL;
59,579,272✔
104
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
59,579,272✔
105
  if (pCluster != NULL) {
59,579,272✔
106
    clusterId = pCluster->id;
58,525,194✔
107
    mndReleaseCluster(pMnode, pCluster, pIter);
58,525,194✔
108
  }
109

110
  return clusterId;
59,579,272✔
111
}
112

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

122
  return createTime;
2,205,680✔
123
}
124

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

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

144
  return upTime;
1,978,893✔
145
}
146

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

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

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

164
  terrno = 0;
1,543,934✔
165

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

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

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

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

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

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

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

206
  terrno = 0;
679,060✔
207

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

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

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

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

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

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

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

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

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

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

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

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

296
  mndTransDrop(pTrans);
389,843✔
297
  return 0;
389,843✔
298
}
299

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

405
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
125,694✔
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);
125,694✔
412
  return 0;
125,694✔
413
}
414

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

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

441
  if (strncmp(cfgReq.config, GRANT_ACTIVE_CODE, TSDB_DNODE_CONFIG_LEN) == 0) {
5,396✔
442
#ifdef TD_ENTERPRISE
443
    if (0 != (code = mndProcessConfigGrantReq(pMnode, pReq, &cfgReq))) {
1,236✔
444
      goto _exit;
618✔
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 ||
4,160✔
452
             taosStrncasecmp(cfgReq.config, "separation_of_duties", 21) == 0) {
2,912✔
453
#ifdef TD_ENTERPRISE
454
    if (0 != (code = mndProcessConfigSoDReq(pMnode, pReq, &cfgReq))) {
1,456✔
455
      goto _exit;
1,248✔
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,704✔
462
             taosStrncasecmp(cfgReq.config, "mandatory_access_control", 25) == 0) {
208✔
463
#ifdef TD_ENTERPRISE
464
    if (0 != (code = mndProcessConfigMacReq(pMnode, pReq, &cfgReq))) {
2,704✔
465
      goto _exit;
2,288✔
466
    }
467
#else
468
    code = TSDB_CODE_OPS_NOT_SUPPORT;
469
    goto _exit;
470
#endif
471
  } else {
472
    code = TSDB_CODE_OPS_NOT_SUPPORT;
×
473
    goto _exit;
×
474
  }
475

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

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

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