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

taosdata / TDengine / #5058

17 May 2026 01:15AM UTC coverage: 73.387% (-0.02%) from 73.406%
#5058

push

travis-ci

web-flow
feat (TDgpt): Dynamic Model Synchronization Enhancements (#35344)

* refactor: do some internal refactor.

* fix: fix multiprocess sync issue.

* feat: add dynamic anomaly detection and forecasting services

* fix: log error message for undeploying model in exception handling

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: handle undeploy when model exists only on disk

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/286aafa0-c3ce-4c27-b803-2707571e9dc1

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: guard dynamic registry concurrent access

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: tighten service list locking scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: restore prophet support and update tests per review feedback

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: improve test name and move copy inside lock scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* Potential fix for pull request finding

Co-au... (continued)

281656 of 383795 relevant lines covered (73.39%)

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

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

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

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

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

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

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

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

88
    *ppIter = pIter;
62,714,138✔
89
    return pCluster;
62,714,138✔
90
  }
91

92
  return NULL;
1,072,950✔
93
}
94

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

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

110
  return clusterId;
59,515,670✔
111
}
112

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

122
  return createTime;
2,197,468✔
123
}
124

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

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

144
  return upTime;
1,964,827✔
145
}
146

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

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

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

164
  terrno = 0;
1,526,452✔
165

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

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

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

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

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

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

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

206
  terrno = 0;
655,147✔
207

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

411
  mndTransDrop(pTrans);
103,715✔
412
  return 0;
103,715✔
413
}
414

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

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

441
  if (strncmp(cfgReq.config, GRANT_ACTIVE_CODE, TSDB_DNODE_CONFIG_LEN) == 0) {
5,408✔
442
#ifdef TD_ENTERPRISE
443
    if (0 != (code = mndProcessConfigGrantReq(pMnode, pReq, &cfgReq))) {
1,248✔
444
      goto _exit;
624✔
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,248✔
477
    int64_t tse = taosGetTimestampMs();
1,248✔
478
    double  duration = (double)(tse - tss);
1,248✔
479
    duration = duration / 1000;
1,248✔
480
    {  // audit
481
      auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql,
1,248✔
482
                  TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1), duration, 0);
1,248✔
483
    }
484
  }
485

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