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

taosdata / TDengine / #4943

30 Jan 2026 06:19AM UTC coverage: 66.718% (-0.07%) from 66.788%
#4943

push

travis-ci

web-flow
merge: from main to 3.0 #34453

1122 of 2018 new or added lines in 72 files covered. (55.6%)

823 existing lines in 156 files now uncovered.

204811 of 306978 relevant lines covered (66.72%)

123993567.34 hits per line

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

58.16
/source/dnode/mnode/impl/src/mndConfig.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 "mndConfig.h"
19
#include "mndDnode.h"
20
#include "mndMnode.h"
21
#include "mndPrivilege.h"
22
#include "mndSync.h"
23
#include "mndTrans.h"
24
#include "mndUser.h"
25
#include "tutil.h"
26
#include "tcompare.h"
27

28
#define CFG_VER_NUMBER    1
29
#define CFG_RESERVE_SIZE  63
30
#define CFG_ALTER_TIMEOUT 3 * 1000
31

32
// Sync timeout ratio constants
33
#define SYNC_TIMEOUT_DIVISOR       4
34
#define SYNC_TIMEOUT_ELECT_DIVISOR 2
35
#define SYNC_TIMEOUT_SR_DIVISOR    4
36
#define SYNC_TIMEOUT_HB_DIVISOR    8
37

38
extern SConfig *tsCfg;
39

40
static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pInMCfgReq, int32_t optLen, int32_t *pOutValue);
41
static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq);
42
static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq);
43
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp);
44
static int32_t mndProcessConfigReq(SRpcMsg *pReq);
45
static int32_t mndInitWriteCfg(SMnode *pMnode);
46
static int32_t mndSendRebuildReq(SMnode *pMnode);
47
static int32_t mndTryRebuildConfigSdbRsp(SRpcMsg *pRsp);
48
static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array);
49
static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq);
50
static void    cfgArrayCleanUp(SArray *array);
51
static void    cfgObjArrayCleanUp(SArray *array);
52
int32_t        compareSConfigItemArrays(SMnode *pMnode, const SArray *dArray, SArray *diffArray);
53

54
static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype,
55
                                    int32_t tsmmConfigVersion);
56
static int32_t mndConfigUpdateTransWithDnode(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype,
57
                                             int32_t tsmmConfigVersion, int32_t dnodeId, SDCfgDnodeReq *pDcfgReq);
58
static int32_t mndFindConfigsToAdd(SMnode *pMnode, SArray *addArray);
59
static int32_t mndFindConfigsToDelete(SMnode *pMnode, SArray *deleteArray);
60
static int32_t mndExecuteConfigSyncTrans(SMnode *pMnode, SArray *addArray, SArray *deleteArray);
61

62
int32_t mndSetCreateConfigCommitLogs(STrans *pTrans, SConfigObj *obj);
63
int32_t mndSetDeleteConfigCommitLogs(STrans *pTrans, SConfigObj *item);
64
int32_t mndSetCreateConfigPrepareLogs(STrans *pTrans, SConfigObj *obj);
65

66
int32_t mndInitConfig(SMnode *pMnode) {
402,259✔
67
  int32_t   code = 0;
402,259✔
68
  SSdbTable table = {.sdbType = SDB_CFG,
402,259✔
69
                     .keyType = SDB_KEY_BINARY,
70
                     .encodeFp = (SdbEncodeFp)mnCfgActionEncode,
71
                     .decodeFp = (SdbDecodeFp)mndCfgActionDecode,
72
                     .insertFp = (SdbInsertFp)mndCfgActionInsert,
73
                     .updateFp = (SdbUpdateFp)mndCfgActionUpdate,
74
                     .deleteFp = (SdbDeleteFp)mndCfgActionDelete,
75
                     .deployFp = (SdbDeployFp)mndCfgActionDeploy,
76
                     .afterRestoredFp = (SdbAfterRestoredFp)mndCfgActionAfterRestored};
77

78
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG, mndProcessConfigReq);
402,259✔
79
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeReq);
402,259✔
80
  mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndTransProcessRsp);
402,259✔
81
  mndSetMsgHandle(pMnode, TDMT_MND_SHOW_VARIABLES, mndProcessShowVariablesReq);
402,259✔
82
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_SDB, mndTryRebuildConfigSdb);
402,259✔
83
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_SDB_RSP, mndTryRebuildConfigSdbRsp);
402,259✔
84

85
  return sdbSetTable(pMnode->pSdb, table);
402,259✔
86
}
87

88
SSdbRaw *mnCfgActionEncode(SConfigObj *obj) {
120,646,205✔
89
  int32_t  code = 0;
120,646,205✔
90
  int32_t  lino = 0;
120,646,205✔
91
  void    *buf = NULL;
120,646,205✔
92
  SSdbRaw *pRaw = NULL;
120,646,205✔
93

94
  SEncoder encoder;
120,607,217✔
95
  tEncoderInit(&encoder, NULL, 0);
120,646,205✔
96
  if ((code = tEncodeSConfigObj(&encoder, obj)) < 0) {
120,646,205✔
97
    tEncoderClear(&encoder);
×
98
    TSDB_CHECK_CODE(code, lino, _over);
×
99
  }
100

101
  int32_t tlen = encoder.pos;
120,646,205✔
102
  tEncoderClear(&encoder);
120,646,205✔
103

104
  int32_t size = sizeof(int32_t) + tlen;
120,646,205✔
105
  pRaw = sdbAllocRaw(SDB_CFG, CFG_VER_NUMBER, size);
120,646,205✔
106
  TSDB_CHECK_NULL(pRaw, code, lino, _over, terrno);
120,646,205✔
107

108
  buf = taosMemoryMalloc(tlen);
120,646,205✔
109
  TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
120,646,205✔
110

111
  tEncoderInit(&encoder, buf, tlen);
120,646,205✔
112
  if ((code = tEncodeSConfigObj(&encoder, obj)) < 0) {
120,646,205✔
113
    tEncoderClear(&encoder);
×
114
    TSDB_CHECK_CODE(code, lino, _over);
×
115
  }
116

117
  tEncoderClear(&encoder);
120,646,205✔
118

119
  int32_t dataPos = 0;
120,646,205✔
120
  SDB_SET_INT32(pRaw, dataPos, tlen, _over);
120,646,205✔
121
  SDB_SET_BINARY(pRaw, dataPos, buf, tlen, _over);
120,646,205✔
122
  SDB_SET_DATALEN(pRaw, dataPos, _over);
120,646,205✔
123

124
_over:
120,646,205✔
125
  taosMemoryFreeClear(buf);
120,646,205✔
126
  if (code != TSDB_CODE_SUCCESS) {
120,646,205✔
127
    mError("cfg:%s, failed to encode to raw:%p at line:%d since %s", obj->name, pRaw, lino, tstrerror(code));
×
128
    sdbFreeRaw(pRaw);
×
129
    terrno = code;
×
130
    return NULL;
×
131
  }
132

133
  terrno = 0;
120,646,205✔
134
  mTrace("cfg:%s, encode to raw:%p, row:%p", obj->name, pRaw, obj);
120,646,205✔
135
  return pRaw;
120,646,205✔
136
}
137

138
SSdbRow *mndCfgActionDecode(SSdbRaw *pRaw) {
45,948,344✔
139
  int32_t     code = 0;
45,948,344✔
140
  int32_t     lino = 0;
45,948,344✔
141
  SSdbRow    *pRow = NULL;
45,948,344✔
142
  SConfigObj *pObj = NULL;
45,948,344✔
143
  void       *buf = NULL;
45,948,344✔
144
  int8_t      sver = 0;
45,948,344✔
145
  int32_t     tlen;
45,928,394✔
146
  int32_t     dataPos = 0;
45,948,344✔
147

148
  code = sdbGetRawSoftVer(pRaw, &sver);
45,948,344✔
149
  TSDB_CHECK_CODE(code, lino, _over);
45,948,344✔
150

151
  if (sver != CFG_VER_NUMBER) {
45,948,344✔
152
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
153
    goto _over;
×
154
  }
155

156
  pRow = sdbAllocRow(sizeof(SConfigObj));
45,948,344✔
157
  TSDB_CHECK_NULL(pRow, code, lino, _over, terrno);
45,948,344✔
158

159
  pObj = sdbGetRowObj(pRow);
45,948,344✔
160
  TSDB_CHECK_NULL(pObj, code, lino, _over, terrno);
45,948,344✔
161

162
  SDB_GET_INT32(pRaw, dataPos, &tlen, _over);
45,948,344✔
163

164
  buf = taosMemoryMalloc(tlen + 1);
45,948,344✔
165
  TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
45,948,344✔
166

167
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, _over);
45,948,344✔
168

169
  SDecoder decoder;
45,928,394✔
170
  tDecoderInit(&decoder, buf, tlen + 1);
45,948,344✔
171
  code = tDecodeSConfigObj(&decoder, pObj);
45,948,344✔
172
  tDecoderClear(&decoder);
45,948,344✔
173

174
  if (code < 0) {
45,948,344✔
175
    tFreeSConfigObj(pObj);
×
176
  }
177

178
_over:
45,948,344✔
179
  taosMemoryFreeClear(buf);
45,948,344✔
180

181
  if (code != TSDB_CODE_SUCCESS) {
45,948,344✔
182
    mError("cfg:%s, failed to decode from raw:%p since %s at:%d", pObj->name, pRaw, tstrerror(code), lino);
×
183
    taosMemoryFreeClear(pRow);
×
184
    terrno = code;
×
185
    return NULL;
×
186
  } else {
187
    mTrace("config:%s, decode from raw:%p, row:%p", pObj->name, pRaw, pObj);
45,948,344✔
188
    terrno = 0;
45,948,344✔
189
    return pRow;
45,948,344✔
190
  }
191
}
192

193
static int32_t mndCfgActionInsert(SSdb *pSdb, SConfigObj *obj) {
45,856,351✔
194
  mTrace("cfg:%s, perform insert action, row:%p", obj->name, obj);
45,856,351✔
195
  return 0;
45,856,351✔
196
}
197

198
static int32_t mndCfgActionDelete(SSdb *pSdb, SConfigObj *obj) {
45,943,442✔
199
  mTrace("cfg:%s, perform delete action, row:%p", obj->name, obj);
45,943,442✔
200
  tFreeSConfigObj(obj);
45,943,442✔
201
  return 0;
45,943,442✔
202
}
203

204
static int32_t mndCfgActionUpdate(SSdb *pSdb, SConfigObj *pOld, SConfigObj *pNew) {
91,993✔
205
  mTrace("cfg:%s, perform update action, old row:%p new row:%p", pOld->name, pOld, pNew);
91,993✔
206
  switch (pNew->dtype) {
91,993✔
207
    case CFG_DTYPE_NONE:
×
208
      break;
×
209
    case CFG_DTYPE_BOOL:
8,467✔
210
      pOld->bval = pNew->bval;
8,467✔
211
      break;
8,467✔
212
    case CFG_DTYPE_INT32:
77,934✔
213
      pOld->i32 = pNew->i32;
77,934✔
214
      break;
77,934✔
215
    case CFG_DTYPE_INT64:
3,232✔
216
      pOld->i64 = pNew->i64;
3,232✔
217
      break;
3,232✔
218
    case CFG_DTYPE_FLOAT:
896✔
219
    case CFG_DTYPE_DOUBLE:
220
      pOld->fval = pNew->fval;
896✔
221
      break;
896✔
222
    case CFG_DTYPE_STRING:
1,464✔
223
    case CFG_DTYPE_DIR:
224
    case CFG_DTYPE_LOCALE:
225
    case CFG_DTYPE_CHARSET:
226
    case CFG_DTYPE_TIMEZONE:
227
      taosMemoryFree(pOld->str);
1,464✔
228
      pOld->str = taosStrdup(pNew->str);
1,464✔
229
      if (pOld->str == NULL) {
1,464✔
230
        return terrno;
×
231
      }
232
      break;
1,464✔
233
  }
234
  return TSDB_CODE_SUCCESS;
91,993✔
235
}
236

237
static int32_t mndCfgActionDeploy(SMnode *pMnode) { return mndInitWriteCfg(pMnode); }
286,225✔
238

239
static int32_t mndCfgActionAfterRestored(SMnode *pMnode) { return mndSendRebuildReq(pMnode); }
196,234✔
240

241
static int32_t mndProcessConfigReq(SRpcMsg *pReq) {
571,331✔
242
  SMnode    *pMnode = pReq->info.node;
571,331✔
243
  SConfigReq configReq = {0};
571,331✔
244
  int32_t    code = TSDB_CODE_SUCCESS;
571,331✔
245
  SArray    *array = NULL;
571,331✔
246
  bool       needFree = false;
571,331✔
247
  code = tDeserializeSConfigReq(pReq->pCont, pReq->contLen, &configReq);
571,331✔
248
  if (code != 0) {
571,331✔
249
    mError("failed to deserialize config req, since %s", terrstr());
×
250
    goto _OVER;
×
251
  }
252

253
  SConfigObj *vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
571,331✔
254
  if (vObj == NULL) {
571,331✔
255
    mInfo("failed to acquire mnd config version, since %s", terrstr());
×
256
    goto _OVER;
×
257
  }
258

259
  array = taosArrayInit(16, sizeof(SConfigItem));
571,331✔
260
  if (array == NULL) {
571,331✔
261
    code = TSDB_CODE_OUT_OF_MEMORY;
×
262
    goto _OVER;
×
263
  }
264
  SConfigRsp configRsp = {0};
571,331✔
265
  configRsp.cver = vObj->i32;
571,331✔
266

267
  if (configReq.cver == vObj->i32) {
571,331✔
268
    configRsp.isVersionVerified = 1;
129,418✔
269
  } else {
270
    code = initConfigArrayFromSdb(pMnode, array);
441,913✔
271
    if (code != 0) {
441,913✔
272
      mError("failed to init config array from sdb, since %s", tstrerror(code));
×
273
      goto _OVER;
×
274
    }
275
    configRsp.array = array;
441,913✔
276
  }
277

278
  int32_t contLen = tSerializeSConfigRsp(NULL, 0, &configRsp);
571,331✔
279
  if (contLen < 0) {
571,331✔
280
    code = contLen;
×
281
    goto _OVER;
×
282
  }
283
  void *pHead = rpcMallocCont(contLen);
571,331✔
284
  if (pHead == NULL) {
571,331✔
285
    code = TSDB_CODE_OUT_OF_MEMORY;
×
286
    goto _OVER;
×
287
  }
288
  contLen = tSerializeSConfigRsp(pHead, contLen, &configRsp);
571,331✔
289
  if (contLen < 0) {
571,331✔
290
    rpcFreeCont(pHead);
×
291
    code = contLen;
×
292
    goto _OVER;
×
293
  }
294
  pReq->info.rspLen = contLen;
571,331✔
295
  pReq->info.rsp = pHead;
571,331✔
296

297
_OVER:
571,331✔
298
  if (code != 0) {
571,331✔
299
    mError("failed to process config req, since %s", tstrerror(code));
×
300
  }
301
  sdbRelease(pMnode->pSdb, vObj);
571,331✔
302
  cfgArrayCleanUp(array);
571,331✔
303
  tFreeSConfigReq(&configReq);
571,331✔
304
  return code;
571,331✔
305
}
306

307
int32_t mndInitWriteCfg(SMnode *pMnode) {
286,225✔
308
  int    code = 0;
286,225✔
309
  size_t sz = 0;
286,225✔
310

311
  mInfo("init write cfg to sdb");
286,225✔
312
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "init-write-config");
286,225✔
313
  if (pTrans == NULL) {
286,225✔
314
    mError("failed to init write cfg in create trans, since %s", terrstr());
×
315
    goto _OVER;
×
316
  }
317

318
  // encode mnd config version
319
  SConfigObj versionObj = mndInitConfigVersion();
286,225✔
320
  if ((code = mndSetCreateConfigCommitLogs(pTrans, &versionObj)) != 0) {
286,225✔
321
    mError("failed to init mnd config version, since %s", tstrerror(code));
×
322
    tFreeSConfigObj(&versionObj);
×
323
    goto _OVER;
×
324
  }
325
  tFreeSConfigObj(&versionObj);
286,225✔
326
  sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
286,225✔
327

328
  for (int i = 0; i < sz; ++i) {
32,629,650✔
329
    SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
32,343,425✔
330
    SConfigObj   obj;
32,331,560✔
331
    if ((code = mndInitConfigObj(item, &obj)) != 0) {
32,343,425✔
332
      goto _OVER;
×
333
    }
334
    if ((code = mndSetCreateConfigCommitLogs(pTrans, &obj)) != 0) {
32,343,425✔
335
      mError("failed to init mnd config:%s, since %s", item->name, tstrerror(code));
×
336
      tFreeSConfigObj(&obj);
×
337
      goto _OVER;
×
338
    }
339
    tFreeSConfigObj(&obj);
32,343,425✔
340
  }
341
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
286,225✔
342

343
_OVER:
286,225✔
344
  if (code != 0) {
286,225✔
345
    mError("failed to init write cfg, since %s", tstrerror(code));
×
346
  }
347
  mndTransDrop(pTrans);
286,225✔
348
  return code;
286,225✔
349
}
350

351
int32_t mndSendRebuildReq(SMnode *pMnode) {
196,234✔
352
  int32_t code = 0;
196,234✔
353

354
  SRpcMsg rpcMsg = {.pCont = NULL,
196,234✔
355
                    .contLen = 0,
356
                    .msgType = TDMT_MND_CONFIG_SDB,
357
                    .info.ahandle = 0,
358
                    .info.notFreeAhandle = 1,
359
                    .info.refId = 0,
360
                    .info.noResp = 0,
361
                    .info.handle = 0};
362
  SEpSet  epSet = {0};
196,234✔
363

364
  mndGetMnodeEpSet(pMnode, &epSet);
196,234✔
365

366
  code = tmsgSendReq(&epSet, &rpcMsg);
196,234✔
367
  if (code != 0) {
196,234✔
368
    mError("failed to send rebuild config req, since %s", tstrerror(code));
×
369
  }
370
  return code;
196,234✔
371
}
372

373
static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq) {
196,154✔
374
  SMnode *pMnode = pReq->info.node;
196,154✔
375
  if (!mndIsLeader(pMnode)) {
196,154✔
376
    return TSDB_CODE_SUCCESS;
×
377
  }
378

379
  int32_t     code = 0;
196,154✔
380
  SConfigObj *vObj = NULL;
196,154✔
381
  SArray     *addArray = NULL;
196,154✔
382
  SArray     *deleteArray = NULL;
196,154✔
383

384
  vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
196,154✔
385
  if (vObj == NULL) {
196,154✔
386
    code = mndInitWriteCfg(pMnode);
×
387
    if (code < 0) {
×
388
      mError("failed to init write cfg, since %s", tstrerror(code));
×
389
    } else {
390
      mInfo("failed to acquire mnd config version, try to rebuild config in sdb.");
×
391
    }
392
    goto _exit;
×
393
  }
394

395
  addArray = taosArrayInit(4, sizeof(SConfigObj));
196,154✔
396
  deleteArray = taosArrayInit(4, sizeof(SConfigObj));
196,154✔
397
  if (addArray == NULL || deleteArray == NULL) {
196,154✔
398
    code = TSDB_CODE_OUT_OF_MEMORY;
×
399
    goto _exit;
×
400
  }
401

402
  // Find configs to add and delete
403
  if ((code = mndFindConfigsToAdd(pMnode, addArray)) != 0) {
196,154✔
404
    mError("failed to find configs to add, since %s", tstrerror(code));
×
405
    goto _exit;
×
406
  }
407

408
  if ((code = mndFindConfigsToDelete(pMnode, deleteArray)) != 0) {
196,154✔
409
    mError("failed to find configs to delete, since %s", tstrerror(code));
×
410
    goto _exit;
×
411
  }
412

413
  // Execute the sync transaction
414
  if ((code = mndExecuteConfigSyncTrans(pMnode, addArray, deleteArray)) != 0) {
196,154✔
415
    mError("failed to execute config sync transaction, since %s", tstrerror(code));
×
416
    goto _exit;
×
417
  }
418

419
_exit:
196,154✔
420
  if (code != 0) {
196,154✔
421
    mError("failed to try rebuild config in sdb, since %s", tstrerror(code));
×
422
  }
423
  sdbRelease(pMnode->pSdb, vObj);
196,154✔
424
  cfgObjArrayCleanUp(addArray);
196,154✔
425
  cfgObjArrayCleanUp(deleteArray);
196,154✔
426
  TAOS_RETURN(code);
196,154✔
427
}
428

429
int32_t mndSetCreateConfigCommitLogs(STrans *pTrans, SConfigObj *item) {
32,648,138✔
430
  int32_t  code = 0;
32,648,138✔
431
  SSdbRaw *pCommitRaw = mnCfgActionEncode(item);
32,648,138✔
432
  if (pCommitRaw == NULL) {
32,648,138✔
433
    code = terrno;
×
434
    TAOS_RETURN(code);
×
435
  }
436
  if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
32,648,138✔
437
    taosMemoryFree(pCommitRaw);
×
438
    TAOS_RETURN(code);
×
439
  }
440
  if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)) != 0) TAOS_RETURN(code);
32,648,138✔
441
  return TSDB_CODE_SUCCESS;
32,648,138✔
442
}
443

444
int32_t mndSetDeleteConfigCommitLogs(STrans *pTrans, SConfigObj *item) {
×
445
  int32_t  code = 0;
×
446
  SSdbRaw *pCommitRaw = mnCfgActionEncode(item);
×
447
  if (pCommitRaw == NULL) {
×
448
    code = terrno;
×
449
    TAOS_RETURN(code);
×
450
  }
451
  if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
×
452
    taosMemoryFree(pCommitRaw);
×
453
    TAOS_RETURN(code);
×
454
  }
455
  if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED)) != 0) TAOS_RETURN(code);
×
456
  return TSDB_CODE_SUCCESS;
×
457
}
458

459
int32_t mndSetCreateConfigPrepareLogs(STrans *pTrans, SConfigObj *item) {
18,488✔
460
  int32_t  code = 0;
18,488✔
461
  SSdbRaw *pPrepareRaw = mnCfgActionEncode(item);
18,488✔
462
  if (pPrepareRaw == NULL) {
18,488✔
463
    code = terrno;
×
464
    TAOS_RETURN(code);
×
465
  }
466
  if ((code = mndTransAppendPrepareLog(pTrans, pPrepareRaw)) != 0) {
18,488✔
467
    taosMemoryFree(pPrepareRaw);
×
468
    TAOS_RETURN(code);
×
469
  }
470
  if ((code = sdbSetRawStatus(pPrepareRaw, SDB_STATUS_READY)) != 0) TAOS_RETURN(code);
18,488✔
471
  return TSDB_CODE_SUCCESS;
18,488✔
472
}
473

474
static int32_t mndFindConfigsToAdd(SMnode *pMnode, SArray *addArray) {
196,154✔
475
  int32_t code = 0;
196,154✔
476
  int32_t sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
196,154✔
477

478
  for (int i = 0; i < sz; ++i) {
22,361,556✔
479
    SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
22,165,402✔
480
    SConfigObj  *obj = sdbAcquire(pMnode->pSdb, SDB_CFG, item->name);
22,165,402✔
481
    if (obj == NULL) {
22,165,402✔
482
      mInfo("config:%s, not exist in sdb, will add it", item->name);
×
483
      SConfigObj newObj;
×
484
      if ((code = mndInitConfigObj(item, &newObj)) != 0) {
×
485
        TAOS_RETURN(code);
×
486
      }
487
      if (NULL == taosArrayPush(addArray, &newObj)) {
×
488
        tFreeSConfigObj(&newObj);
×
489
        TAOS_RETURN(terrno);
×
490
      }
491
    } else {
492
      sdbRelease(pMnode->pSdb, obj);
22,165,402✔
493
    }
494
  }
495

496
  TAOS_RETURN(TSDB_CODE_SUCCESS);
196,154✔
497
}
498

499
static int32_t mndFindConfigsToDelete(SMnode *pMnode, SArray *deleteArray) {
196,154✔
500
  int32_t     code = 0;
196,154✔
501
  int32_t     sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
196,154✔
502
  SSdb       *pSdb = pMnode->pSdb;
196,154✔
503
  void       *pIter = NULL;
196,154✔
504
  SConfigObj *obj = NULL;
196,154✔
505

506
  while (1) {
22,361,556✔
507
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
22,557,710✔
508
    if (pIter == NULL) break;
22,557,710✔
509
    if (obj == NULL) {
22,361,556✔
510
      code = TSDB_CODE_OUT_OF_MEMORY;
×
511
      sdbCancelFetch(pSdb, pIter);
×
512
      TAOS_RETURN(code);
×
513
    }
514

515
    // Skip the version config
516
    if (strcasecmp(obj->name, "tsmmConfigVersion") == 0) {
22,361,556✔
517
      sdbRelease(pSdb, obj);
196,154✔
518
      continue;
196,154✔
519
    }
520

521
    // Check if this config exists in global config
522
    bool existsInGlobal = false;
22,165,402✔
523
    for (int i = 0; i < sz; ++i) {
1,263,427,914✔
524
      SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
1,263,427,914✔
525
      if (strcasecmp(obj->name, item->name) == 0) {
1,263,427,914✔
526
        existsInGlobal = true;
22,165,402✔
527
        break;
22,165,402✔
528
      }
529
    }
530

531
    if (!existsInGlobal) {
22,165,402✔
532
      mInfo("config:%s, not exist in global config, will delete it from sdb", obj->name);
×
533
      SConfigObj deleteObj = {0};
×
534
      tstrncpy(deleteObj.name, obj->name, CFG_NAME_MAX_LEN);
×
535
      deleteObj.dtype = obj->dtype;
×
536

537
      // Copy the value based on type
538
      switch (obj->dtype) {
×
539
        case CFG_DTYPE_BOOL:
×
540
          deleteObj.bval = obj->bval;
×
541
          break;
×
542
        case CFG_DTYPE_INT32:
×
543
          deleteObj.i32 = obj->i32;
×
544
          break;
×
545
        case CFG_DTYPE_INT64:
×
546
          deleteObj.i64 = obj->i64;
×
547
          break;
×
548
        case CFG_DTYPE_FLOAT:
×
549
        case CFG_DTYPE_DOUBLE:
550
          deleteObj.fval = obj->fval;
×
551
          break;
×
552
        case CFG_DTYPE_STRING:
×
553
        case CFG_DTYPE_DIR:
554
        case CFG_DTYPE_LOCALE:
555
        case CFG_DTYPE_CHARSET:
556
        case CFG_DTYPE_TIMEZONE:
557
          deleteObj.str = taosStrdup(obj->str);
×
558
          if (deleteObj.str == NULL) {
×
559
            sdbCancelFetch(pSdb, pIter);
×
560
            sdbRelease(pSdb, obj);
×
561
            TAOS_RETURN(terrno);
×
562
          }
563
          break;
×
564
        default:
×
565
          break;
×
566
      }
567

568
      if (NULL == taosArrayPush(deleteArray, &deleteObj)) {
×
569
        tFreeSConfigObj(&deleteObj);
×
570
        sdbCancelFetch(pSdb, pIter);
×
571
        sdbRelease(pSdb, obj);
×
572
        TAOS_RETURN(terrno);
×
573
      }
574
    }
575

576
    sdbRelease(pSdb, obj);
22,165,402✔
577
  }
578

579
  TAOS_RETURN(TSDB_CODE_SUCCESS);
196,154✔
580
}
581

582
static int32_t mndExecuteConfigSyncTrans(SMnode *pMnode, SArray *addArray, SArray *deleteArray) {
196,154✔
583
  int32_t addSize = taosArrayGetSize(addArray);
196,154✔
584
  int32_t deleteSize = taosArrayGetSize(deleteArray);
196,154✔
585

586
  if (addSize == 0 && deleteSize == 0) {
196,154✔
587
    return TSDB_CODE_SUCCESS;
196,154✔
588
  }
589

590
  const char *transName = "sync-config";
×
591
  if (addSize > 0 && deleteSize > 0) {
×
592
    transName = "sync-config";
×
593
  } else if (addSize > 0) {
×
594
    transName = "add-config";
×
595
  } else {
596
    transName = "delete-config";
×
597
  }
598

599
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, transName);
×
600
  if (pTrans == NULL) {
×
601
    TAOS_RETURN(terrno);
×
602
  }
603

604
  int32_t code = 0;
×
605

606
  // Add new configs
607
  for (int i = 0; i < addSize; ++i) {
×
608
    SConfigObj *AddObj = taosArrayGet(addArray, i);
×
609
    if ((code = mndSetCreateConfigCommitLogs(pTrans, AddObj)) != 0) {
×
610
      mndTransDrop(pTrans);
×
611
      TAOS_RETURN(code);
×
612
    }
613
  }
614

615
  // Delete obsolete configs
616
  for (int i = 0; i < deleteSize; ++i) {
×
617
    SConfigObj *DelObj = taosArrayGet(deleteArray, i);
×
618
    if ((code = mndSetDeleteConfigCommitLogs(pTrans, DelObj)) != 0) {
×
619
      mndTransDrop(pTrans);
×
620
      TAOS_RETURN(code);
×
621
    }
622
  }
623

624
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
×
625
    mndTransDrop(pTrans);
×
626
    TAOS_RETURN(code);
×
627
  }
628

629
  mInfo("sync config to sdb, add nums:%d, delete nums:%d", addSize, deleteSize);
×
630
  mndTransDrop(pTrans);
×
631
  TAOS_RETURN(TSDB_CODE_SUCCESS);
×
632
}
633

634
static int32_t mndMCfg2DCfg(SMCfgDnodeReq *pMCfgReq, SDCfgDnodeReq *pDCfgReq) {
83,480✔
635
  int32_t code = 0;
83,480✔
636
  char   *p = pMCfgReq->config;
83,480✔
637
  while (*p) {
1,133,923✔
638
    if (*p == ' ') {
1,087,890✔
639
      break;
37,447✔
640
    }
641
    p++;
1,050,443✔
642
  }
643

644
  size_t optLen = p - pMCfgReq->config;
83,480✔
645
  tstrncpy(pDCfgReq->config, pMCfgReq->config, sizeof(pDCfgReq->config));
83,480✔
646
  pDCfgReq->config[optLen] = 0;
83,480✔
647

648
  if (' ' == pMCfgReq->config[optLen]) {
83,480✔
649
    // 'key value'
650
    if (strlen(pMCfgReq->value) != 0) goto _err;
37,447✔
651
    tstrncpy(pDCfgReq->value, p + 1, sizeof(pDCfgReq->value));
37,447✔
652
  } else {
653
    // 'key' 'value'
654
    if (strlen(pMCfgReq->value) == 0) goto _err;
46,033✔
655
    tstrncpy(pDCfgReq->value, pMCfgReq->value, sizeof(pDCfgReq->value));
45,430✔
656
  }
657

658
  TAOS_RETURN(code);
82,877✔
659

660
_err:
603✔
661
  mError("dnode:%d, failed to config since invalid conf:%s", pMCfgReq->dnodeId, pMCfgReq->config);
603✔
662
  code = TSDB_CODE_INVALID_CFG;
603✔
663
  TAOS_RETURN(code);
603✔
664
}
665

666
static int32_t mndBuildCfgDnodeRedoAction(STrans *pTrans, SDnodeObj *pDnode, SDCfgDnodeReq *pDcfgReq) {
10,032✔
667
  int32_t code = 0;
10,032✔
668
  SEpSet  epSet = mndGetDnodeEpset(pDnode);
10,032✔
669
  int32_t bufLen = tSerializeSDCfgDnodeReq(NULL, 0, pDcfgReq);
10,032✔
670
  void   *pBuf = taosMemoryMalloc(bufLen);
10,032✔
671

672
  if (pBuf == NULL) {
10,032✔
673
    code = terrno;
×
674
    return code;
×
675
  }
676

677
  if ((bufLen = tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq)) <= 0) {
10,032✔
678
    code = bufLen;
×
679
    taosMemoryFree(pBuf);
×
680
    return code;
×
681
  }
682

683
  STransAction action = {
10,032✔
684
      .epSet = epSet,
685
      .pCont = pBuf,
686
      .contLen = bufLen,
687
      .msgType = TDMT_DND_CONFIG_DNODE,
688
      .acceptableCode = 0,
689
      .groupId = -1,
690
  };
691

692
  mInfo("dnode:%d, append redo action to trans, config:%s value:%s", pDnode->id, pDcfgReq->config, pDcfgReq->value);
10,032✔
693

694
  if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
10,032✔
695
    taosMemoryFree(pBuf);
×
696
    return code;
×
697
  }
698

699
  return code;
10,032✔
700
}
701

702
static int32_t mndSendCfgDnodeReq(SMnode *pMnode, int32_t dnodeId, SDCfgDnodeReq *pDcfgReq) {
63,151✔
703
  int32_t code = -1;
63,151✔
704
  SSdb   *pSdb = pMnode->pSdb;
63,151✔
705
  void   *pIter = NULL;
63,151✔
706

707
  int64_t curMs = taosGetTimestampMs();
63,151✔
708

709
  while (1) {
169,102✔
710
    SDnodeObj *pDnode = NULL;
232,253✔
711
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
232,253✔
712
    if (pIter == NULL) break;
232,253✔
713

714
    if (pDnode->id == dnodeId || dnodeId == -1 || dnodeId == 0) {
171,058✔
715
      bool online = mndIsDnodeOnline(pDnode, curMs);
63,443✔
716
      if (!online) {
63,443✔
717
        mWarn("dnode:%d, is offline, skip to send config req", pDnode->id);
×
718
        continue;
×
719
      }
720
      SEpSet  epSet = mndGetDnodeEpset(pDnode);
63,443✔
721
      int32_t bufLen = tSerializeSDCfgDnodeReq(NULL, 0, pDcfgReq);
63,443✔
722
      void   *pBuf = rpcMallocCont(bufLen);
63,443✔
723

724
      if (pBuf == NULL) {
63,443✔
725
        sdbCancelFetch(pMnode->pSdb, pIter);
×
726
        sdbRelease(pMnode->pSdb, pDnode);
×
727
        code = TSDB_CODE_OUT_OF_MEMORY;
×
728
        return code;
×
729
      }
730

731
      if ((bufLen = tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq)) <= 0) {
63,443✔
732
        sdbCancelFetch(pMnode->pSdb, pIter);
×
733
        sdbRelease(pMnode->pSdb, pDnode);
×
734
        code = bufLen;
×
735
        rpcFreeCont(pBuf);
×
736
        return code;
×
737
      }
738

739
      mInfo("dnode:%d, send config req to dnode, config:%s value:%s", pDnode->id, pDcfgReq->config, pDcfgReq->value);
63,443✔
740
      SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen};
63,443✔
741
      SRpcMsg rpcRsp = {0};
63,443✔
742

743
      code = rpcSendRecvWithTimeout(pMnode->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, NULL, CFG_ALTER_TIMEOUT);
63,443✔
744
      if (code != 0) {
63,443✔
745
        mError("failed to send config req to dnode:%d, since %s", pDnode->id, tstrerror(code));
×
746
        sdbCancelFetch(pMnode->pSdb, pIter);
×
747
        sdbRelease(pMnode->pSdb, pDnode);
×
748
        return code;
×
749
      }
750

751
      code = rpcRsp.code;
63,443✔
752
      if (code != 0) {
63,443✔
753
        mError("failed to alter config %s,on dnode:%d, since %s", pDcfgReq->config, pDnode->id, tstrerror(code));
1,956✔
754
        sdbCancelFetch(pMnode->pSdb, pIter);
1,956✔
755
        sdbRelease(pMnode->pSdb, pDnode);
1,956✔
756
        return code;
1,956✔
757
      }
758
      rpcFreeCont(rpcRsp.pCont);
61,487✔
759
    }
760
    sdbRelease(pSdb, pDnode);
169,102✔
761
  }
762

763
  if (code == -1) {
61,195✔
764
    code = TSDB_CODE_MND_DNODE_NOT_EXIST;
568✔
765
  }
766
  TAOS_RETURN(code);
61,195✔
767
}
768

769
static int32_t  mndProcessConfigDnodeReq(SRpcMsg *pReq) {
84,768✔
770
  int32_t       code = 0;
84,768✔
771
  int32_t       lino = -1;
84,768✔
772
  SMnode       *pMnode = pReq->info.node;
84,768✔
773
  SMCfgDnodeReq cfgReq = {0};
84,768✔
774
  SUserObj     *pOperUser = NULL;
84,768✔
775
  int64_t       tss = taosGetTimestampMs();
84,768✔
776
  SConfigObj   *vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
84,768✔
777
  if (vObj == NULL) {
84,768✔
778
    code = TSDB_CODE_SDB_OBJ_NOT_THERE;
×
779
    mInfo("failed to acquire mnd config version, since %s", tstrerror(code));
×
780
    goto _err_out;
×
781
  }
782

783
  TAOS_CHECK_RETURN(tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq));
84,768✔
784
  int8_t updateWhiteList = 0;
84,768✔
785
  mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value);
84,768✔
786

787
  code = mndAcquireUser(pMnode, RPC_MSG_USER(pReq), &pOperUser);
84,768✔
788
  if (pOperUser == NULL) {
84,768✔
NEW
789
    code = TSDB_CODE_MND_NO_USER_FROM_CONN;
×
NEW
790
    goto _err_out;
×
791
  }
792

793
  char configName[TSDB_DNODE_CONFIG_LEN] = {0};
84,768✔
794
  strncpy(configName, cfgReq.config, sizeof(configName) - 1);
84,768✔
795
  const char *p = strstr(configName, " ");
84,768✔
796
  if (p) *(char *)p = 0;
84,768✔
797
  EPrivType privType = cfgGetPrivType(tsCfg, configName, 0);
84,768✔
798
  if ((code = mndCheckSysObjPrivilege(pMnode, pOperUser, RPC_MSG_TOKEN(pReq), privType, 0, 0, NULL, NULL))) {
84,768✔
799
    goto _err_out;
1,092✔
800
  }
801

802
  SDCfgDnodeReq dcfgReq = {0};
83,676✔
803
  if (strcasecmp(cfgReq.config, "resetlog") == 0) {
83,676✔
804
    tstrncpy(dcfgReq.config, "resetlog", 9);
196✔
805
    goto _send_req;
196✔
806
#ifdef TD_ENTERPRISE
807
  } else if (strncasecmp(cfgReq.config, "ssblocksize", 12) == 0) {
83,480✔
808
    int32_t optLen = strlen("ssblocksize");
×
809
    int32_t flag = -1;
×
810
    int32_t code = mndMCfgGetValInt32(&cfgReq, optLen, &flag);
×
811
    if (code < 0) {
×
812
      goto _err_out;
×
813
    }
814

815
    if (flag > 1024 * 1024 || (flag > -1 && flag < 1024) || flag < -1) {
×
816
      mError("dnode:%d, failed to config ssblocksize since value:%d. Valid range: -1 or [1024, 1024 * 1024]",
×
817
             cfgReq.dnodeId, flag);
818
      code = TSDB_CODE_INVALID_CFG;
×
819
      goto _err_out;
×
820
    }
821

822
    tstrncpy(dcfgReq.config, "ssblocksize", 12);
×
823
    snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag);
×
824
#endif
825
  } else {
826
    TAOS_CHECK_GOTO(mndMCfg2DCfg(&cfgReq, &dcfgReq), &lino, _err_out);
83,480✔
827
    if (strlen(dcfgReq.config) > TSDB_DNODE_CONFIG_LEN) {
82,877✔
828
      mError("dnode:%d, failed to config since config is too long", cfgReq.dnodeId);
×
829
      code = TSDB_CODE_INVALID_CFG;
×
830
      goto _err_out;
×
831
    }
832
    if (strncasecmp(dcfgReq.config, "enableWhiteList", strlen("enableWhiteList")) == 0) {
82,877✔
833
      updateWhiteList = 1;
216✔
834
    }
835

836
    CfgAlterType alterType = (cfgReq.dnodeId == 0 || cfgReq.dnodeId == -1) ? CFG_ALTER_ALL_DNODES : CFG_ALTER_DNODE;
82,877✔
837
    TAOS_CHECK_GOTO(cfgCheckRangeForDynUpdate(taosGetCfg(), dcfgReq.config, dcfgReq.value, true, alterType), &lino,
82,877✔
838
                    _err_out);
839
  }
840
  SConfigItem *pItem = cfgGetItem(taosGetCfg(), dcfgReq.config);
72,199✔
841
  // Update config in sdb.
842
  if (pItem == NULL) {
72,199✔
843
    mError("failed to find config:%s while process config dnode req", cfgReq.config);
×
844
    code = TSDB_CODE_CFG_NOT_FOUND;
×
845
    goto _err_out;
×
846
  }
847

848
  // Audit log
849
  if (tsAuditLevel >= AUDIT_LEVEL_SYSTEM) {
72,199✔
850
    char obj[50] = {0};
72,199✔
851
    (void)tsnprintf(obj, sizeof(obj), "%d", cfgReq.dnodeId);
72,199✔
852
    int64_t tse = taosGetTimestampMs();
72,199✔
853
    double  duration = (double)(tse - tss);
72,199✔
854
    duration = duration / 1000;
72,199✔
855
    auditRecord(pReq, pMnode->clusterId, "alterDnode", obj, "", cfgReq.sql, cfgReq.sqlLen, duration, 0);
72,199✔
856
  }
857

858
  dcfgReq.version = vObj->i32 + 1;
72,199✔
859

860
  if (pItem->category == CFG_CATEGORY_GLOBAL) {
72,199✔
861
    // Use transaction to update SDB and send to dnode atomically
862
    TAOS_CHECK_GOTO(mndConfigUpdateTransWithDnode(pMnode, dcfgReq.config, dcfgReq.value, pItem->dtype, dcfgReq.version,
9,244✔
863
                                                  cfgReq.dnodeId, &dcfgReq),
864
                    &lino, _err_out);
865
  } else {
866
    // For local config, still use the old method (only send to dnode)
867
    goto _send_req;
62,955✔
868
  }
869

870
  // For global config, transaction has handled everything, go to success
871
  goto _success;
9,244✔
872

873
_send_req:
63,151✔
874
  dcfgReq.version = vObj->i32;
63,151✔
875
  code = mndSendCfgDnodeReq(pMnode, cfgReq.dnodeId, &dcfgReq);
63,151✔
876
  if (code != 0) {
63,151✔
877
    mError("failed to send config req to dnode:%d, since %s", cfgReq.dnodeId, tstrerror(code));
2,524✔
878
    goto _err_out;
2,524✔
879
  }
880

881
_success:
69,871✔
882
  // dont care suss or succ;
883
  if (updateWhiteList) {
69,871✔
884
    int32_t dummy1 = mndRefreshUserIpWhiteList(pMnode);
108✔
885
    int32_t dummy2 = mndRefreshUserDateTimeWhiteList(pMnode);
108✔
886
    (void)dummy1;
887
    (void)dummy2;
888
  }
889
  tFreeSMCfgDnodeReq(&cfgReq);
69,871✔
890
  sdbRelease(pMnode->pSdb, vObj);
69,871✔
891
  mndReleaseUser(pMnode, pOperUser);
69,871✔
892
  TAOS_RETURN(code);
69,871✔
893

894
_err_out:
14,897✔
895
  mError("failed to process config dnode req, since %s", tstrerror(code));
14,897✔
896
  tFreeSMCfgDnodeReq(&cfgReq);
14,897✔
897
  sdbRelease(pMnode->pSdb, vObj);
14,897✔
898
  mndReleaseUser(pMnode, pOperUser);
14,897✔
899
  TAOS_RETURN(code);
14,897✔
900
}
901

902
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp) {
×
903
  mInfo("config rsp from dnode");
×
904
  return 0;
×
905
}
906

907
static int32_t mndTryRebuildConfigSdbRsp(SRpcMsg *pRsp) {
196,127✔
908
  mInfo("rebuild config sdb rsp");
196,127✔
909
  return 0;
196,127✔
910
}
911

912
// Helper function to create and commit a config object
913
static int32_t mndCreateAndCommitConfigObj(STrans *pTrans, const char *srcName, const char *cfgName, char *value,
×
914
                                           int32_t *lino) {
915
  int32_t     code = 0;
×
916
  SConfigObj *pTmp = taosMemoryMalloc(sizeof(SConfigObj));
×
917
  if (pTmp == NULL) {
×
918
    code = terrno;
×
919
    return code;
×
920
  }
921

922
  pTmp->dtype = CFG_DTYPE_INT32;
×
923
  tstrncpy(pTmp->name, cfgName, CFG_NAME_MAX_LEN);
×
924
  code = mndUpdateObj(pTmp, srcName, value);
×
925
  if (code != 0) {
×
926
    tFreeSConfigObj(pTmp);
×
927
    taosMemoryFree(pTmp);
×
928
    return code;
×
929
  }
930

931
  code = mndSetCreateConfigCommitLogs(pTrans, pTmp);
×
932
  tFreeSConfigObj(pTmp);
×
933
  taosMemoryFree(pTmp);
×
934
  return code;
×
935
}
936

937
// Helper function to handle syncTimeout related config updates
938
static int32_t mndHandleSyncTimeoutConfigs(STrans *pTrans, const char *srcName, const char *pValue, int32_t *lino) {
×
939
  int32_t code = 0;
×
940
  int32_t syncTimeout = 0;
×
941
  char    tmp[10] = {0};
×
942

943
  if (sscanf(pValue, "%d", &syncTimeout) != 1) {
×
944
    syncTimeout = 0;
×
945
  }
946

947
  int32_t baseTimeout = syncTimeout - syncTimeout / SYNC_TIMEOUT_DIVISOR;
×
948

949
  // arbSetAssignedTimeoutMs = syncTimeout
950
  sprintf(tmp, "%d", syncTimeout);
×
951
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "arbSetAssignedTimeoutMs", tmp, lino), lino, _OVER);
×
952

953
  // arbHeartBeatIntervalMs = syncTimeout / 4
954
  sprintf(tmp, "%d", syncTimeout / SYNC_TIMEOUT_DIVISOR);
×
955
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "arbHeartBeatIntervalMs", tmp, lino), lino, _OVER);
×
956

957
  // arbCheckSyncIntervalMs = syncTimeout / 4
958
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "arbCheckSyncIntervalMs", tmp, lino), lino, _OVER);
×
959

960
  // syncVnodeElectIntervalMs = (syncTimeout - syncTimeout / 4) / 2
961
  sprintf(tmp, "%d", baseTimeout / SYNC_TIMEOUT_ELECT_DIVISOR);
×
962
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncVnodeElectIntervalMs", tmp, lino), lino, _OVER);
×
963

964
  // syncMnodeElectIntervalMs = (syncTimeout - syncTimeout / 4) / 2
965
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncMnodeElectIntervalMs", tmp, lino), lino, _OVER);
×
966

967
  // statusTimeoutMs = (syncTimeout - syncTimeout / 4) / 2
968
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "statusTimeoutMs", tmp, lino), lino, _OVER);
×
969

970
  // statusSRTimeoutMs = (syncTimeout - syncTimeout / 4) / 4
971
  sprintf(tmp, "%d", baseTimeout / SYNC_TIMEOUT_SR_DIVISOR);
×
972
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "statusSRTimeoutMs", tmp, lino), lino, _OVER);
×
973

974
  // syncVnodeHeartbeatIntervalMs = (syncTimeout - syncTimeout / 4) / 8
975
  sprintf(tmp, "%d", baseTimeout / SYNC_TIMEOUT_HB_DIVISOR);
×
976
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncVnodeHeartbeatIntervalMs", tmp, lino), lino, _OVER);
×
977

978
  // syncMnodeHeartbeatIntervalMs = (syncTimeout - syncTimeout / 4) / 8
979
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncMnodeHeartbeatIntervalMs", tmp, lino), lino, _OVER);
×
980

981
  // statusIntervalMs = (syncTimeout - syncTimeout / 4) / 8
982
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "statusIntervalMs", tmp, lino), lino, _OVER);
×
983

984
_OVER:
×
985
  return code;
×
986
}
987

988
// get int32_t value from 'SMCfgDnodeReq'
989
static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pMCfgReq, int32_t optLen, int32_t *pOutValue) {
×
990
  int32_t code = 0;
×
991
  if (' ' != pMCfgReq->config[optLen] && 0 != pMCfgReq->config[optLen]) {
×
992
    goto _err;
×
993
  }
994

995
  if (' ' == pMCfgReq->config[optLen]) {
×
996
    // 'key value'
997
    if (strlen(pMCfgReq->value) != 0) goto _err;
×
998
    *pOutValue = taosStr2Int32(pMCfgReq->config + optLen + 1, NULL, 10);
×
999
  } else {
1000
    // 'key' 'value'
1001
    if (strlen(pMCfgReq->value) == 0) goto _err;
×
1002
    *pOutValue = taosStr2Int32(pMCfgReq->value, NULL, 10);
×
1003
  }
1004

1005
  TAOS_RETURN(code);
×
1006

1007
_err:
×
1008
  mError(" failed to set config since:%s", tstrerror(code));
×
1009
  TAOS_RETURN(code);
×
1010
}
1011

1012
static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype,
×
1013
                                    int32_t tsmmConfigVersion) {
1014
  int32_t     code = -1;
×
1015
  int32_t     lino = -1;
×
1016
  SConfigObj *pVersion = taosMemoryMalloc(sizeof(SConfigObj)), *pObj = taosMemoryMalloc(sizeof(SConfigObj));
×
1017
  if (pVersion == NULL || pObj == NULL) {
×
1018
    code = terrno;
×
1019
    goto _OVER;
×
1020
  }
1021
  tstrncpy(pVersion->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
×
1022
  pVersion->dtype = CFG_DTYPE_INT32;
×
1023
  pVersion->i32 = tsmmConfigVersion;
×
1024

1025
  pObj->dtype = dtype;
×
1026
  tstrncpy(pObj->name, name, CFG_NAME_MAX_LEN);
×
1027

1028
  TAOS_CHECK_GOTO(mndUpdateObj(pObj, name, pValue), &lino, _OVER);
×
1029
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, NULL, "update-config");
×
1030
  if (pTrans == NULL) {
×
1031
    code = terrno;
×
1032
    goto _OVER;
×
1033
  }
1034
  mInfo("trans:%d, used to update config:%s to value:%s", pTrans->id, name, pValue);
×
1035
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pVersion), &lino, _OVER);
×
1036
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pObj), &lino, _OVER);
×
1037

1038
  if (taosStrncasecmp(name, "syncTimeout", CFG_NAME_MAX_LEN) == 0) {
×
1039
    TAOS_CHECK_GOTO(mndHandleSyncTimeoutConfigs(pTrans, name, pValue, &lino), &lino, _OVER);
×
1040
  }
1041
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
×
1042
  code = 0;
×
1043
_OVER:
×
1044
  if (code != 0) {
×
1045
    mError("failed to update config:%s to value:%s, since %s", name, pValue, tstrerror(code));
×
1046
  }
1047
  mndTransDrop(pTrans);
×
1048
  tFreeSConfigObj(pVersion);
×
1049
  taosMemoryFree(pVersion);
×
1050
  tFreeSConfigObj(pObj);
×
1051
  taosMemoryFree(pObj);
×
1052
  return code;
×
1053
}
1054

1055
static int32_t mndConfigUpdateTransWithDnode(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype,
9,244✔
1056
                                             int32_t tsmmConfigVersion, int32_t dnodeId, SDCfgDnodeReq *pDcfgReq) {
1057
  int32_t     code = -1;
9,244✔
1058
  int32_t     lino = -1;
9,244✔
1059
  SConfigObj *pVersion = taosMemoryMalloc(sizeof(SConfigObj)), *pObj = taosMemoryMalloc(sizeof(SConfigObj));
9,244✔
1060
  if (pVersion == NULL || pObj == NULL) {
9,244✔
1061
    code = terrno;
×
1062
    goto _OVER;
×
1063
  }
1064
  tstrncpy(pVersion->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
9,244✔
1065
  pVersion->dtype = CFG_DTYPE_INT32;
9,244✔
1066
  pVersion->i32 = tsmmConfigVersion;
9,244✔
1067

1068
  pObj->dtype = dtype;
9,244✔
1069
  tstrncpy(pObj->name, name, CFG_NAME_MAX_LEN);
9,244✔
1070

1071
  TAOS_CHECK_GOTO(mndUpdateObj(pObj, name, pValue), &lino, _OVER);
9,244✔
1072
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "update-config-with-dnode");
9,244✔
1073
  if (pTrans == NULL) {
9,244✔
1074
    code = terrno;
×
1075
    goto _OVER;
×
1076
  }
1077
  mInfo("trans:%d, used to update config:%s to value:%s and send to dnode", pTrans->id, name, pValue);
9,244✔
1078

1079
  // Add prepare logs for SDB config updates (execute in PREPARE stage, before redo actions)
1080
  TAOS_CHECK_GOTO(mndSetCreateConfigPrepareLogs(pTrans, pVersion), &lino, _OVER);
9,244✔
1081
  TAOS_CHECK_GOTO(mndSetCreateConfigPrepareLogs(pTrans, pObj), &lino, _OVER);
9,244✔
1082

1083
  // Add commit logs for transaction persistence
1084
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pVersion), &lino, _OVER);
9,244✔
1085
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pObj), &lino, _OVER);
9,244✔
1086

1087
  if (taosStrncasecmp(name, "syncTimeout", CFG_NAME_MAX_LEN) == 0) {
9,244✔
1088
    TAOS_CHECK_GOTO(mndHandleSyncTimeoutConfigs(pTrans, name, pValue, &lino), &lino, _OVER);
×
1089
  }
1090

1091
  // Add redo actions to send config to dnodes
1092
  SSdb   *pSdb = pMnode->pSdb;
9,244✔
1093
  void   *pIter = NULL;
9,244✔
1094
  int64_t curMs = taosGetTimestampMs();
9,244✔
1095

1096
  while (1) {
10,032✔
1097
    SDnodeObj *pDnode = NULL;
19,276✔
1098
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
19,276✔
1099
    if (pIter == NULL) break;
19,276✔
1100

1101
    if (pDnode->id == dnodeId || dnodeId == -1 || dnodeId == 0) {
10,032✔
1102
      bool online = mndIsDnodeOnline(pDnode, curMs);
10,032✔
1103
      if (!online) {
10,032✔
1104
        mWarn("dnode:%d, is offline, still add to trans for retry", pDnode->id);
×
1105
      }
1106

1107
      code = mndBuildCfgDnodeRedoAction(pTrans, pDnode, pDcfgReq);
10,032✔
1108
      if (code != 0) {
10,032✔
1109
        mError("failed to build config redo action for dnode:%d, since %s", pDnode->id, tstrerror(code));
×
1110
        sdbCancelFetch(pMnode->pSdb, pIter);
×
1111
        sdbRelease(pMnode->pSdb, pDnode);
×
1112
        goto _OVER;
×
1113
      }
1114
    }
1115
    sdbRelease(pSdb, pDnode);
10,032✔
1116
  }
1117

1118
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
9,244✔
1119
  code = 0;
9,244✔
1120

1121
_OVER:
9,244✔
1122
  if (code != 0) {
9,244✔
1123
    mError("failed to update config:%s to value:%s and send to dnode, since %s", name, pValue, tstrerror(code));
×
1124
  }
1125
  mndTransDrop(pTrans);
9,244✔
1126
  tFreeSConfigObj(pVersion);
9,244✔
1127
  taosMemoryFree(pVersion);
9,244✔
1128
  tFreeSConfigObj(pObj);
9,244✔
1129
  taosMemoryFree(pObj);
9,244✔
1130
  return code;
9,244✔
1131
}
1132

1133
static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array) {
441,913✔
1134
  int32_t     code = 0;
441,913✔
1135
  SSdb       *pSdb = pMnode->pSdb;
441,913✔
1136
  void       *pIter = NULL;
441,913✔
1137
  SConfigObj *obj = NULL;
441,913✔
1138

1139
  while (1) {
50,378,082✔
1140
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
50,819,995✔
1141
    if (pIter == NULL) break;
50,819,995✔
1142
    if (obj == NULL) {
50,378,082✔
1143
      code = TSDB_CODE_OUT_OF_MEMORY;
×
1144
      goto _exit;
×
1145
    }
1146
    if (strcasecmp(obj->name, "tsmmConfigVersion") == 0) {
50,378,082✔
1147
      sdbRelease(pSdb, obj);
441,913✔
1148
      continue;
441,913✔
1149
    }
1150
    SConfigItem item = {0};
49,936,169✔
1151
    item.dtype = obj->dtype;
49,936,169✔
1152
    item.name = taosStrdup(obj->name);
49,936,169✔
1153
    if (item.name == NULL) {
49,936,169✔
1154
      code = terrno;
×
1155
      sdbCancelFetch(pSdb, pIter);
×
1156
      sdbRelease(pSdb, obj);
×
1157
      goto _exit;
×
1158
    }
1159
    switch (obj->dtype) {
49,936,169✔
1160
      case CFG_DTYPE_NONE:
×
1161
        break;
×
1162
      case CFG_DTYPE_BOOL:
11,931,651✔
1163
        item.bval = obj->bval;
11,931,651✔
1164
        break;
11,931,651✔
1165
      case CFG_DTYPE_INT32:
26,072,867✔
1166
        item.i32 = obj->i32;
26,072,867✔
1167
        break;
26,072,867✔
1168
      case CFG_DTYPE_INT64:
2,651,478✔
1169
        item.i64 = obj->i64;
2,651,478✔
1170
        break;
2,651,478✔
1171
      case CFG_DTYPE_FLOAT:
883,826✔
1172
      case CFG_DTYPE_DOUBLE:
1173
        item.fval = obj->fval;
883,826✔
1174
        break;
883,826✔
1175
      case CFG_DTYPE_STRING:
8,396,347✔
1176
      case CFG_DTYPE_DIR:
1177
      case CFG_DTYPE_LOCALE:
1178
      case CFG_DTYPE_CHARSET:
1179
      case CFG_DTYPE_TIMEZONE:
1180
        item.str = taosStrdup(obj->str);
8,396,347✔
1181
        if (item.str == NULL) {
8,396,347✔
1182
          sdbCancelFetch(pSdb, pIter);
×
1183
          sdbRelease(pSdb, obj);
×
1184
          code = terrno;
×
1185
          goto _exit;
×
1186
        }
1187
        break;
8,396,347✔
1188
    }
1189
    if (taosArrayPush(array, &item) == NULL) {
49,936,169✔
1190
      sdbCancelFetch(pSdb, pIter);
×
1191
      sdbRelease(pSdb, obj);
×
1192
      code = TSDB_CODE_OUT_OF_MEMORY;
×
1193
      goto _exit;
×
1194
      break;
1195
    }
1196
    sdbRelease(pSdb, obj);
49,936,169✔
1197
  }
1198
_exit:
441,913✔
1199
  if (code != 0) {
441,913✔
1200
    mError("failed to init config array from sdb, since %s", tstrerror(code));
×
1201
  }
1202
  return code;
441,913✔
1203
}
1204

1205
static void cfgArrayCleanUp(SArray *array) {
571,331✔
1206
  if (array == NULL) {
571,331✔
1207
    return;
×
1208
  }
1209

1210
  int32_t sz = taosArrayGetSize(array);
571,331✔
1211
  for (int32_t i = 0; i < sz; ++i) {
50,507,500✔
1212
    SConfigItem *item = taosArrayGet(array, i);
49,936,169✔
1213
    if (item->dtype == CFG_DTYPE_STRING || item->dtype == CFG_DTYPE_DIR || item->dtype == CFG_DTYPE_LOCALE ||
49,936,169✔
1214
        item->dtype == CFG_DTYPE_CHARSET || item->dtype == CFG_DTYPE_TIMEZONE) {
42,423,648✔
1215
      taosMemoryFreeClear(item->str);
8,396,347✔
1216
    }
1217
    taosMemoryFreeClear(item->name);
49,936,169✔
1218
  }
1219

1220
  taosArrayDestroy(array);
571,331✔
1221
}
1222

1223
static void cfgObjArrayCleanUp(SArray *array) {
392,308✔
1224
  if (array == NULL) {
392,308✔
1225
    return;
×
1226
  }
1227
  int32_t sz = taosArrayGetSize(array);
392,308✔
1228
  for (int32_t i = 0; i < sz; ++i) {
392,308✔
1229
    SConfigObj *obj = taosArrayGet(array, i);
×
1230
    tFreeSConfigObj(obj);
×
1231
  }
1232
  taosArrayDestroy(array);
392,308✔
1233
}
1234

1235
static SArray *initVariablesFromItems(SArray *pItems, const char* likePattern) {
8,754✔
1236
  if (pItems == NULL) {
8,754✔
1237
    return NULL;
×
1238
  }
1239

1240
  int32_t sz = taosArrayGetSize(pItems);
8,754✔
1241

1242
  SArray *pInfos = taosArrayInit(sz, sizeof(SVariablesInfo));
8,754✔
1243
  if (pInfos == NULL) {
8,754✔
1244
    mError("failed to init array while init variables from items, since %s", tstrerror(terrno));
×
1245
    return NULL;
×
1246
  }
1247
  for (int32_t i = 0; i < sz; ++i) {
997,956✔
1248
    SConfigItem   *pItem = taosArrayGet(pItems, i);
989,202✔
1249
    SVariablesInfo info = {0};
989,202✔
1250
    tstrncpy(info.name, pItem->name, sizeof(info.name));
989,202✔
1251
    if (likePattern != NULL && rawStrPatternMatch(pItem->name, likePattern) != TSDB_PATTERN_MATCH) {
989,202✔
1252
      continue;
252,912✔
1253
    }
1254

1255
    // init info value
1256
    switch (pItem->dtype) {
736,290✔
1257
      case CFG_DTYPE_NONE:
×
1258
        break;
×
1259
      case CFG_DTYPE_BOOL:
174,974✔
1260
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->bval);
174,974✔
1261
        break;
174,974✔
1262
      case CFG_DTYPE_INT32:
386,282✔
1263
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->i32);
386,282✔
1264
        break;
386,282✔
1265
      case CFG_DTYPE_INT64:
38,784✔
1266
        tsnprintf(info.value, sizeof(info.value), "%" PRId64, pItem->i64);
38,784✔
1267
        break;
38,784✔
1268
      case CFG_DTYPE_FLOAT:
12,928✔
1269
      case CFG_DTYPE_DOUBLE:
1270
        tsnprintf(info.value, sizeof(info.value), "%f", pItem->fval);
12,928✔
1271
        break;
12,928✔
1272
      case CFG_DTYPE_STRING:
123,322✔
1273
      case CFG_DTYPE_DIR:
1274
      case CFG_DTYPE_LOCALE:
1275
      case CFG_DTYPE_CHARSET:
1276
      case CFG_DTYPE_TIMEZONE:
1277
        tsnprintf(info.value, sizeof(info.value), "%s", pItem->str);
123,322✔
1278
        break;
123,322✔
1279
    }
1280

1281
    // init info scope
1282
    switch (pItem->scope) {
736,290✔
1283
      case CFG_SCOPE_SERVER:
594,022✔
1284
        tstrncpy(info.scope, "server", sizeof(info.scope));
594,022✔
1285
        break;
594,022✔
1286
      case CFG_SCOPE_CLIENT:
×
1287
        tstrncpy(info.scope, "client", sizeof(info.scope));
×
1288
        break;
×
1289
      case CFG_SCOPE_BOTH:
142,268✔
1290
        tstrncpy(info.scope, "both", sizeof(info.scope));
142,268✔
1291
        break;
142,268✔
1292
      default:
×
1293
        tstrncpy(info.scope, "unknown", sizeof(info.scope));
×
1294
        break;
×
1295
    }
1296
    // init info category
1297
    switch (pItem->category) {
736,290✔
1298
      case CFG_CATEGORY_GLOBAL:
736,290✔
1299
        tstrncpy(info.category, "global", sizeof(info.category));
736,290✔
1300
        break;
736,290✔
1301
      case CFG_CATEGORY_LOCAL:
×
1302
        tstrncpy(info.category, "local", sizeof(info.category));
×
1303
        break;
×
1304
      default:
×
1305
        tstrncpy(info.category, "unknown", sizeof(info.category));
×
1306
        break;
×
1307
    }
1308
    if (NULL == taosArrayPush(pInfos, &info)) {
736,290✔
1309
      mError("failed to push info to array while init variables from items,since %s", tstrerror(terrno));
×
1310
      taosArrayDestroy(pInfos);
×
1311
      return NULL;
×
1312
    }
1313
  }
1314

1315
  return pInfos;
8,754✔
1316
}
1317

1318
static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) {
8,754✔
1319
  SShowVariablesRsp rsp = {0};
8,754✔
1320
  int32_t           code = TSDB_CODE_SUCCESS;
8,754✔
1321
  SShowVariablesReq req = {0};
8,754✔
1322
  SArray           *array = NULL;
8,754✔
1323

1324
  code = tDeserializeSShowVariablesReq(pReq->pCont, pReq->contLen, &req);
8,754✔
1325
  if (code != 0) {
8,754✔
1326
    mError("failed to deserialize config req, since %s", terrstr());
×
1327
    goto _OVER;
×
1328
  }
1329

1330
  if ((code = mndCheckOperPrivilege(pReq->info.node, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_SHOW_VARIABLES)) != 0) {
8,754✔
1331
    goto _OVER;
×
1332
  }
1333

1334
  SVariablesInfo info = {0};
8,754✔
1335
  char          *likePattern = req.opType == OP_TYPE_LIKE ? req.val : NULL;
8,754✔
1336
  rsp.variables = initVariablesFromItems(taosGetGlobalCfg(tsCfg), likePattern);
8,754✔
1337
  if (rsp.variables == NULL) {
8,754✔
1338
    code = terrno;
×
1339
    goto _OVER;
×
1340
  }
1341
  int32_t rspLen = tSerializeSShowVariablesRsp(NULL, 0, &rsp);
8,754✔
1342
  void   *pRsp = rpcMallocCont(rspLen);
8,754✔
1343
  if (pRsp == NULL) {
8,754✔
1344
    code = terrno;
×
1345
    goto _OVER;
×
1346
  }
1347

1348
  if ((rspLen = tSerializeSShowVariablesRsp(pRsp, rspLen, &rsp)) <= 0) {
8,754✔
1349
    rpcFreeCont(pRsp);
×
1350
    code = rspLen;
×
1351
    goto _OVER;
×
1352
  }
1353

1354
  pReq->info.rspLen = rspLen;
8,754✔
1355
  pReq->info.rsp = pRsp;
8,754✔
1356
  code = 0;
8,754✔
1357

1358
_OVER:
8,754✔
1359

1360
  if (code != 0) {
8,754✔
1361
    mError("failed to get show variables info since %s", tstrerror(code));
×
1362
  }
1363
  tFreeSShowVariablesReq(&req);
8,754✔
1364
  tFreeSShowVariablesRsp(&rsp);
8,754✔
1365
  TAOS_RETURN(code);
8,754✔
1366
}
1367

1368
int32_t compareSConfigItem(const SConfigObj *item1, SConfigItem *item2, bool *compare) {
×
1369
  *compare = true;
×
1370
  switch (item1->dtype) {
×
1371
    case CFG_DTYPE_BOOL:
×
1372
      if (item1->bval != item2->bval) {
×
1373
        item2->bval = item1->bval;
×
1374
        *compare = false;
×
1375
      }
1376
      break;
×
1377
    case CFG_DTYPE_FLOAT:
×
1378
      if (item1->fval != item2->fval) {
×
1379
        item2->fval = item1->fval;
×
1380
        *compare = false;
×
1381
      }
1382
      break;
×
1383
    case CFG_DTYPE_INT32:
×
1384
      if (item1->i32 != item2->i32) {
×
1385
        item2->i32 = item1->i32;
×
1386
        *compare = false;
×
1387
      }
1388
      break;
×
1389
    case CFG_DTYPE_INT64:
×
1390
      if (item1->i64 != item2->i64) {
×
1391
        item2->i64 = item1->i64;
×
1392
        *compare = false;
×
1393
      }
1394
      break;
×
1395
    case CFG_DTYPE_STRING:
×
1396
    case CFG_DTYPE_DIR:
1397
    case CFG_DTYPE_LOCALE:
1398
    case CFG_DTYPE_CHARSET:
1399
    case CFG_DTYPE_TIMEZONE:
1400
      if (strcmp(item1->str, item2->str) != 0) {
×
1401
        item2->str = taosStrdup(item1->str);
×
1402
        if (item2->str == NULL) {
×
1403
          return TSDB_CODE_OUT_OF_MEMORY;
×
1404
        }
1405
        *compare = false;
×
1406
      }
1407
      break;
×
1408
    default:
×
1409
      *compare = false;
×
1410
      return TSDB_CODE_INVALID_CFG;
×
1411
  }
1412
  return TSDB_CODE_SUCCESS;
×
1413
}
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