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

taosdata / TDengine / #4937

23 Jan 2026 09:40AM UTC coverage: 66.794% (+0.05%) from 66.746%
#4937

push

travis-ci

web-flow
fix: case failuer caused by the modification of the error description (#34391)

204171 of 305671 relevant lines covered (66.79%)

127025939.33 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) {
399,101✔
41
  SSdbTable table = {
399,101✔
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);
399,101✔
53
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER, mndProcessConfigClusterReq);
399,101✔
54
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_CLUSTER_RSP, mndProcessConfigClusterRsp);
399,101✔
55
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndRetrieveClusters);
399,101✔
56
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CLUSTER, mndCancelGetNextCluster);
399,101✔
57

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

61
void mndCleanupCluster(SMnode *pMnode) {}
399,041✔
62

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

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

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

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

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

87
    *ppIter = pIter;
45,247,735✔
88
    return pCluster;
45,247,735✔
89
  }
90

91
  return NULL;
780,156✔
92
}
93

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

100
int64_t mndGetClusterId(SMnode *pMnode) {
42,843,476✔
101
  int64_t      clusterId = 0;
42,843,476✔
102
  void        *pIter = NULL;
42,843,476✔
103
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
42,843,476✔
104
  if (pCluster != NULL) {
42,843,476✔
105
    clusterId = pCluster->id;
42,077,409✔
106
    mndReleaseCluster(pMnode, pCluster, pIter);
42,077,409✔
107
  }
108

109
  return clusterId;
42,843,476✔
110
}
111

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

121
  return createTime;
1,645,463✔
122
}
123

124
static int32_t mndGetClusterUpTimeImp(SClusterObj *pCluster) {
1,452,235✔
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,452,235✔
131
#endif
132
}
133

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

143
  return upTime;
1,450,591✔
144
}
145

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

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

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

163
  terrno = 0;
1,134,125✔
164

165
_OVER:
1,134,125✔
166
  if (terrno != 0) {
1,134,125✔
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,134,125✔
173
  return pRaw;
1,134,125✔
174
}
175

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

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

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

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

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

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

205
  terrno = 0;
491,474✔
206

207
_OVER:
491,474✔
208
  if (terrno != 0) {
491,474✔
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);
491,474✔
216
  return pRow;
491,474✔
217
}
218

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

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

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

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

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

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

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

268
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-cluster");
284,828✔
269
  if (pTrans == NULL) {
284,828✔
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);
284,828✔
276

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

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

295
  mndTransDrop(pTrans);
284,828✔
296
  return 0;
284,828✔
297
}
298

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

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

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

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

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

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

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

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

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

341
    sdbRelease(pSdb, pCluster);
1,644✔
342
    numOfRows++;
1,644✔
343
  }
344

345
  pShow->numOfRows += numOfRows;
1,644✔
346

347
_OVER:
1,644✔
348
  if (code != 0) {
1,644✔
349
    mError("failed to retrieve cluster info at line %d since %s", lino, tstrerror(code));
×
350
    TAOS_RETURN(code);
×
351
  }
352
  return numOfRows;
1,644✔
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) {
87,563✔
361
  SMnode      *pMnode = pReq->info.node;
87,563✔
362
  SClusterObj  clusterObj = {0};
87,563✔
363
  void        *pIter = NULL;
87,563✔
364
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
87,563✔
365
  if (pCluster != NULL) {
87,563✔
366
    (void)memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
87,563✔
367
    clusterObj.upTime += tsUptimeInterval;
87,563✔
368
    mndReleaseCluster(pMnode, pCluster, pIter);
87,563✔
369
  }
370

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

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

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

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

410
  mndTransDrop(pTrans);
87,563✔
411
  return 0;
87,563✔
412
}
413

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

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

440
  if (strncmp(cfgReq.config, GRANT_ACTIVE_CODE, TSDB_DNODE_CONFIG_LEN) == 0) {
798✔
441
#ifdef TD_ENTERPRISE
442
    if (0 != (code = mndProcessConfigGrantReq(pMnode, pReq, &cfgReq))) {
798✔
443
      goto _exit;
399✔
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) {
399✔
455
    int64_t tse = taosGetTimestampMs();
399✔
456
    double  duration = (double)(tse - tss);
399✔
457
    duration = duration / 1000;
399✔
458
    {  // audit
459
      auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql,
399✔
460
                  TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1), duration, 0);
399✔
461
    }
462
  }
463

464
_exit:
798✔
465
  tFreeSMCfgClusterReq(&cfgReq);
798✔
466
  if (code != 0) {
798✔
467
    mError("cluster: failed to config:%s %s since %s", cfgReq.config, cfgReq.value, tstrerror(code));
399✔
468
  } else {
469
    mInfo("cluster: success to config:%s %s", cfgReq.config, cfgReq.value);
399✔
470
  }
471
  TAOS_RETURN(code);
798✔
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