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

taosdata / TDengine / #3621

22 Feb 2025 11:44AM UTC coverage: 2.037% (-61.5%) from 63.573%
#3621

push

travis-ci

web-flow
Merge pull request #29874 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

0 of 174 new or added lines in 18 files covered. (0.0%)

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 hits per line

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

0.0
/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

UNCOV
40
int32_t mndInitCluster(SMnode *pMnode) {
×
UNCOV
41
  SSdbTable table = {
×
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

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

UNCOV
58
  return sdbSetTable(pMnode->pSdb, table);
×
59
}
60

UNCOV
61
void mndCleanupCluster(SMnode *pMnode) {}
×
62

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

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

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

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

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

UNCOV
87
    *ppIter = pIter;
×
UNCOV
88
    return pCluster;
×
89
  }
90

UNCOV
91
  return NULL;
×
92
}
93

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

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

UNCOV
109
  return clusterId;
×
110
}
111

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

UNCOV
121
  return createTime;
×
122
}
123

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

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

UNCOV
143
  return upTime;
×
144
}
145

UNCOV
146
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
×
UNCOV
147
  int32_t code = 0;
×
UNCOV
148
  int32_t lino = 0;
×
UNCOV
149
  terrno = TSDB_CODE_OUT_OF_MEMORY;
×
150

UNCOV
151
  SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, CLUSTER_VER_NUMBE, sizeof(SClusterObj) + CLUSTER_RESERVE_SIZE);
×
UNCOV
152
  if (pRaw == NULL) goto _OVER;
×
153

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

UNCOV
163
  terrno = 0;
×
164

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

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

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

UNCOV
183
  int8_t sver = 0;
×
UNCOV
184
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
×
185

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

UNCOV
191
  pRow = sdbAllocRow(sizeof(SClusterObj));
×
UNCOV
192
  if (pRow == NULL) goto _OVER;
×
193

UNCOV
194
  pCluster = sdbGetRowObj(pRow);
×
UNCOV
195
  if (pCluster == NULL) goto _OVER;
×
196

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

UNCOV
205
  terrno = 0;
×
206

UNCOV
207
_OVER:
×
UNCOV
208
  if (terrno != 0) {
×
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

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

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

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

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

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

UNCOV
244
  int32_t code = taosGetSystemUUIDLen(clusterObj.name, TSDB_CLUSTER_ID_LEN);
×
UNCOV
245
  if (code != 0) {
×
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

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

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

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

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

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

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

UNCOV
295
  mndTransDrop(pTrans);
×
UNCOV
296
  return 0;
×
297
}
298

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

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

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

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

UNCOV
319
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
UNCOV
320
    COL_DATA_SET_VAL_GOTO(buf, false, pCluster, _OVER);
×
321

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

UNCOV
326
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
UNCOV
327
    COL_DATA_SET_VAL_GOTO((const char *)&pCluster->createdTime, false, pCluster, _OVER);
×
328

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

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

UNCOV
341
    sdbRelease(pSdb, pCluster);
×
UNCOV
342
    numOfRows++;
×
343
  }
344

UNCOV
345
  pShow->numOfRows += numOfRows;
×
346

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

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

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

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

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

UNCOV
384
  SSdbRaw *pCommitRaw = mndClusterActionEncode(&clusterObj);
×
UNCOV
385
  if (pCommitRaw == NULL) {
×
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

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

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

UNCOV
410
  mndTransDrop(pTrans);
×
UNCOV
411
  return 0;
×
412
}
413

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

423
  mInfo("cluster: start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
×
424
  if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_CLUSTER)) != 0) {
×
425
    goto _exit;
×
426
  }
427

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

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

453
  {  // audit
454
    auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql,
×
455
                TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1));
×
456
  }
457
_exit:
×
458
  tFreeSMCfgClusterReq(&cfgReq);
×
459
  if (code != 0) {
×
460
    mError("cluster: failed to config:%s %s since %s", cfgReq.config, cfgReq.value, tstrerror(code));
×
461
  } else {
462
    mInfo("cluster: success to config:%s %s", cfgReq.config, cfgReq.value);
×
463
  }
464
  TAOS_RETURN(code);
×
465
}
466

467
int32_t mndProcessConfigClusterRsp(SRpcMsg *pRsp) {
×
468
  mInfo("config rsp from cluster");
×
469
  return 0;
×
470
}
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