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

taosdata / TDengine / #4982

12 Mar 2026 05:32AM UTC coverage: 68.587% (+0.1%) from 68.488%
#4982

push

travis-ci

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

merge: from main to 3.0 branch

279 of 443 new or added lines in 34 files covered. (62.98%)

2352 existing lines in 132 files now uncovered.

212163 of 309332 relevant lines covered (68.59%)

135254549.82 hits per line

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

77.85
/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 "audit.h"
18
#include "mndCluster.h"
19
#include "mndGrant.h"
20
#include "mndPrivilege.h"
21
#include "mndShow.h"
22
#include "mndTrans.h"
23

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

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

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

52
  mndSetMsgHandle(pMnode, TDMT_MND_UPTIME_TIMER, mndProcessUptimeTimer);
428,932✔
53
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER, mndProcessConfigClusterReq);
428,932✔
54
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER_RSP, mndProcessConfigClusterRsp);
428,932✔
55
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndRetrieveClusters);
428,932✔
56
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndCancelGetNextCluster);
428,932✔
57

58
  return sdbSetTable(pMnode->pSdb, table);
428,932✔
59
}
60

61
void mndCleanupCluster(SMnode *pMnode) {}
428,869✔
62

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

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

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

78
static SClusterObj *mndAcquireCluster(SMnode *pMnode, void **ppIter) {
44,536,323✔
79
  SSdb *pSdb = pMnode->pSdb;
44,536,323✔
80
  void *pIter = NULL;
44,536,323✔
81

82
  while (1) {
83
    SClusterObj *pCluster = NULL;
44,536,323✔
84
    pIter = sdbFetch(pSdb, SDB_CLUSTER, pIter, (void **)&pCluster);
44,536,323✔
85
    if (pIter == NULL) break;
44,536,323✔
86

87
    *ppIter = pIter;
43,700,807✔
88
    return pCluster;
43,700,807✔
89
  }
90

91
  return NULL;
835,516✔
92
}
93

94
static void mndReleaseCluster(SMnode *pMnode, SClusterObj *pCluster, void *pIter) {
43,700,807✔
95
  SSdb *pSdb = pMnode->pSdb;
43,700,807✔
96
  sdbCancelFetch(pSdb, pIter);
43,700,807✔
97
  sdbRelease(pSdb, pCluster);
43,700,807✔
98
}
43,700,807✔
99

100
int64_t mndGetClusterId(SMnode *pMnode) {
41,195,384✔
101
  int64_t      clusterId = 0;
41,195,384✔
102
  void        *pIter = NULL;
41,195,384✔
103
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
41,195,384✔
104
  if (pCluster != NULL) {
41,195,384✔
105
    clusterId = pCluster->id;
40,374,061✔
106
    mndReleaseCluster(pMnode, pCluster, pIter);
40,374,061✔
107
  }
108

109
  return clusterId;
41,195,384✔
110
}
111

112
int64_t mndGetClusterCreateTime(SMnode *pMnode) {
1,759,823✔
113
  int64_t      createTime = 0;
1,759,823✔
114
  void        *pIter = NULL;
1,759,823✔
115
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
1,759,823✔
116
  if (pCluster != NULL) {
1,759,823✔
117
    createTime = pCluster->createdTime;
1,745,630✔
118
    mndReleaseCluster(pMnode, pCluster, pIter);
1,745,630✔
119
  }
120

121
  return createTime;
1,759,823✔
122
}
123

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

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

143
  return upTime;
1,493,342✔
144
}
145

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

151
  SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, CLUSTER_VER_NUMBE, sizeof(SClusterObj) + CLUSTER_RESERVE_SIZE);
1,220,806✔
152
  if (pRaw == NULL) goto _OVER;
1,220,806✔
153

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

163
  terrno = 0;
1,220,806✔
164

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

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

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

183
  int8_t sver = 0;
520,654✔
184
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
520,654✔
185

186
  if (sver != CLUSTER_VER_NUMBE) {
520,654✔
187
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
188
    goto _OVER;
×
189
  }
190

191
  pRow = sdbAllocRow(sizeof(SClusterObj));
520,654✔
192
  if (pRow == NULL) goto _OVER;
520,654✔
193

194
  pCluster = sdbGetRowObj(pRow);
520,654✔
195
  if (pCluster == NULL) goto _OVER;
520,654✔
196

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

205
  terrno = 0;
520,654✔
206

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

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

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

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

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

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

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

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

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

266
  mInfo("cluster:%" PRId64 ", will be created when deploying, raw:%p", clusterObj.id, pRaw);
308,490✔
267

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

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

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

295
  mndTransDrop(pTrans);
308,490✔
296
  return 0;
308,490✔
297
}
298

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

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

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

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

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

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

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

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

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

341
    sdbRelease(pSdb, pCluster);
2,070✔
342
    numOfRows++;
2,070✔
343
  }
344

345
  pShow->numOfRows += numOfRows;
2,070✔
346

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

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

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

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

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

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

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

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

410
  mndTransDrop(pTrans);
86,826✔
411
  return 0;
86,826✔
412
}
413

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

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

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

440
  if (strncmp(cfgReq.config, GRANT_ACTIVE_CODE, TSDB_DNODE_CONFIG_LEN) == 0) {
948✔
441
#ifdef TD_ENTERPRISE
442
    if (0 != (code = mndProcessConfigGrantReq(pMnode, pReq, &cfgReq))) {
948✔
443
      goto _exit;
474✔
444
    }
445
#else
446
    code = TSDB_CODE_OPS_NOT_SUPPORT;
447
    goto _exit;
448
#endif
449
  } else {
450
    code = TSDB_CODE_OPS_NOT_SUPPORT;
×
451
    goto _exit;
×
452
  }
453

454
  if (tsAuditLevel >= AUDIT_LEVEL_CLUSTER) {
474✔
455
    int64_t tse = taosGetTimestampMs();
474✔
456
    double  duration = (double)(tse - tss);
474✔
457
    duration = duration / 1000;
474✔
458
    {  // audit
459
      auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql,
474✔
460
                  TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1), duration, 0);
474✔
461
    }
462
  }
463

464
_exit:
948✔
465
  tFreeSMCfgClusterReq(&cfgReq);
948✔
466
  if (code != 0) {
948✔
467
    mError("cluster: failed to config:%s %s since %s", cfgReq.config, cfgReq.value, tstrerror(code));
474✔
468
  } else {
469
    mInfo("cluster: success to config:%s %s", cfgReq.config, cfgReq.value);
474✔
470
  }
471
  TAOS_RETURN(code);
948✔
472
}
473

474
int32_t mndProcessConfigClusterRsp(SRpcMsg *pRsp) {
×
475
  mInfo("config rsp from cluster");
×
476
  return 0;
×
477
}
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