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

taosdata / TDengine / #4930

16 Jan 2026 02:32AM UTC coverage: 66.716% (-0.007%) from 66.723%
#4930

push

travis-ci

web-flow
enh: interp supports using non-null prev/next values to fill (#34236)

281 of 327 new or added lines in 11 files covered. (85.93%)

1747 existing lines in 129 files now uncovered.

203203 of 304580 relevant lines covered (66.72%)

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

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

61
void mndCleanupCluster(SMnode *pMnode) {}
416,810✔
62

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

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

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

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

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

87
    *ppIter = pIter;
48,119,147✔
88
    return pCluster;
48,119,147✔
89
  }
90

91
  return NULL;
821,201✔
92
}
93

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

100
int64_t mndGetClusterId(SMnode *pMnode) {
45,637,664✔
101
  int64_t      clusterId = 0;
45,637,664✔
102
  void        *pIter = NULL;
45,637,664✔
103
  SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
45,637,664✔
104
  if (pCluster != NULL) {
45,637,664✔
105
    clusterId = pCluster->id;
44,831,599✔
106
    mndReleaseCluster(pMnode, pCluster, pIter);
44,831,599✔
107
  }
108

109
  return clusterId;
45,637,664✔
110
}
111

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

121
  return createTime;
1,712,649✔
122
}
123

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

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

143
  return upTime;
1,502,748✔
144
}
145

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

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

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

163
  terrno = 0;
1,173,751✔
164

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

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

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

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

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

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

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

205
  terrno = 0;
506,047✔
206

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

404
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
86,459✔
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,459✔
411
  return 0;
86,459✔
412
}
413

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

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

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

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