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

taosdata / TDengine / #4837

07 Nov 2025 09:40AM UTC coverage: 58.963% (+0.2%) from 58.728%
#4837

push

travis-ci

DuanKuanJun
coverity: cases_other.task add -R -Q2 -Q3 -Q4

150245 of 324452 branches covered (46.31%)

Branch coverage included in aggregate %.

200054 of 269646 relevant lines covered (74.19%)

317833830.25 hits per line

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

47.44
/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
static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pInMCfgReq, int32_t optLen, int32_t *pOutValue);
39
static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq);
40
static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq);
41
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp);
42
static int32_t mndProcessConfigReq(SRpcMsg *pReq);
43
static int32_t mndInitWriteCfg(SMnode *pMnode);
44
static int32_t mndSendRebuildReq(SMnode *pMnode);
45
static int32_t mndTryRebuildConfigSdbRsp(SRpcMsg *pRsp);
46
static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array);
47
static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq);
48
static void    cfgArrayCleanUp(SArray *array);
49
static void    cfgObjArrayCleanUp(SArray *array);
50
int32_t        compareSConfigItemArrays(SMnode *pMnode, const SArray *dArray, SArray *diffArray);
51

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

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

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

76
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG, mndProcessConfigReq);
4,988,091✔
77
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeReq);
4,988,091✔
78
  mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndProcessConfigDnodeRsp);
4,988,091✔
79
  mndSetMsgHandle(pMnode, TDMT_MND_SHOW_VARIABLES, mndProcessShowVariablesReq);
4,988,091✔
80
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_SDB, mndTryRebuildConfigSdb);
4,988,091✔
81
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_SDB_RSP, mndTryRebuildConfigSdbRsp);
4,988,091✔
82

83
  return sdbSetTable(pMnode->pSdb, table);
4,988,091✔
84
}
85

86
SSdbRaw *mnCfgActionEncode(SConfigObj *obj) {
1,255,899,957✔
87
  int32_t  code = 0;
1,255,899,957✔
88
  int32_t  lino = 0;
1,255,899,957✔
89
  void    *buf = NULL;
1,255,899,957✔
90
  SSdbRaw *pRaw = NULL;
1,255,899,957✔
91

92
  SEncoder encoder;
1,255,405,248✔
93
  tEncoderInit(&encoder, NULL, 0);
1,255,899,957✔
94
  if ((code = tEncodeSConfigObj(&encoder, obj)) < 0) {
1,255,899,957!
95
    tEncoderClear(&encoder);
×
96
    TSDB_CHECK_CODE(code, lino, _over);
×
97
  }
98

99
  int32_t tlen = encoder.pos;
1,255,899,957✔
100
  tEncoderClear(&encoder);
1,255,899,957✔
101

102
  int32_t size = sizeof(int32_t) + tlen;
1,255,899,957✔
103
  pRaw = sdbAllocRaw(SDB_CFG, CFG_VER_NUMBER, size);
1,255,899,957✔
104
  TSDB_CHECK_NULL(pRaw, code, lino, _over, terrno);
1,255,899,957!
105

106
  buf = taosMemoryMalloc(tlen);
1,255,899,957!
107
  TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
1,255,899,957!
108

109
  tEncoderInit(&encoder, buf, tlen);
1,255,899,957✔
110
  if ((code = tEncodeSConfigObj(&encoder, obj)) < 0) {
1,255,899,957!
111
    tEncoderClear(&encoder);
×
112
    TSDB_CHECK_CODE(code, lino, _over);
×
113
  }
114

115
  tEncoderClear(&encoder);
1,255,899,957✔
116

117
  int32_t dataPos = 0;
1,255,899,957✔
118
  SDB_SET_INT32(pRaw, dataPos, tlen, _over);
1,255,899,957!
119
  SDB_SET_BINARY(pRaw, dataPos, buf, tlen, _over);
1,255,899,957!
120
  SDB_SET_DATALEN(pRaw, dataPos, _over);
1,255,899,957!
121

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

131
  terrno = 0;
1,255,899,957✔
132
  mTrace("cfg:%s, encode to raw:%p, row:%p", obj->name, pRaw, obj);
1,255,899,957✔
133
  return pRaw;
1,255,899,957✔
134
}
135

136
SSdbRow *mndCfgActionDecode(SSdbRaw *pRaw) {
515,889,821✔
137
  int32_t     code = 0;
515,889,821✔
138
  int32_t     lino = 0;
515,889,821✔
139
  SSdbRow    *pRow = NULL;
515,889,821✔
140
  SConfigObj *pObj = NULL;
515,889,821✔
141
  void       *buf = NULL;
515,889,821✔
142
  int8_t      sver = 0;
515,889,821✔
143
  int32_t     tlen;
515,570,521✔
144
  int32_t     dataPos = 0;
515,889,821✔
145

146
  code = sdbGetRawSoftVer(pRaw, &sver);
515,889,821✔
147
  TSDB_CHECK_CODE(code, lino, _over);
515,889,821!
148

149
  if (sver != CFG_VER_NUMBER) {
515,889,821!
150
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
151
    goto _over;
×
152
  }
153

154
  pRow = sdbAllocRow(sizeof(SConfigObj));
515,889,821✔
155
  TSDB_CHECK_NULL(pRow, code, lino, _over, terrno);
515,889,821!
156

157
  pObj = sdbGetRowObj(pRow);
515,889,821✔
158
  TSDB_CHECK_NULL(pObj, code, lino, _over, terrno);
515,889,821!
159

160
  SDB_GET_INT32(pRaw, dataPos, &tlen, _over);
515,889,821!
161

162
  buf = taosMemoryMalloc(tlen + 1);
515,889,821!
163
  TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
515,889,821!
164

165
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, _over);
515,889,821!
166

167
  SDecoder decoder;
515,570,521✔
168
  tDecoderInit(&decoder, buf, tlen + 1);
515,889,821✔
169
  code = tDecodeSConfigObj(&decoder, pObj);
515,889,821✔
170
  tDecoderClear(&decoder);
515,889,821✔
171

172
  if (code < 0) {
515,889,821!
173
    tFreeSConfigObj(pObj);
×
174
  }
175

176
_over:
515,889,821✔
177
  taosMemoryFreeClear(buf);
515,889,821!
178

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

191
static int32_t mndCfgActionInsert(SSdb *pSdb, SConfigObj *obj) {
513,753,100✔
192
  mTrace("cfg:%s, perform insert action, row:%p", obj->name, obj);
513,753,100✔
193
  return 0;
513,753,100✔
194
}
195

196
static int32_t mndCfgActionDelete(SSdb *pSdb, SConfigObj *obj) {
515,837,600✔
197
  mTrace("cfg:%s, perform delete action, row:%p", obj->name, obj);
515,837,600✔
198
  tFreeSConfigObj(obj);
515,837,600✔
199
  return 0;
515,837,600✔
200
}
201

202
static int32_t mndCfgActionUpdate(SSdb *pSdb, SConfigObj *pOld, SConfigObj *pNew) {
2,136,721✔
203
  mTrace("cfg:%s, perform update action, old row:%p new row:%p", pOld->name, pOld, pNew);
2,136,721!
204
  switch (pNew->dtype) {
2,136,721!
205
    case CFG_DTYPE_NONE:
×
206
      break;
×
207
    case CFG_DTYPE_BOOL:
223,195✔
208
      pOld->bval = pNew->bval;
223,195!
209
      break;
223,195✔
210
    case CFG_DTYPE_INT32:
1,752,587✔
211
      pOld->i32 = pNew->i32;
1,752,587✔
212
      break;
1,752,587✔
213
    case CFG_DTYPE_INT64:
89,435✔
214
      pOld->i64 = pNew->i64;
89,435✔
215
      break;
89,435✔
216
    case CFG_DTYPE_FLOAT:
27,240✔
217
    case CFG_DTYPE_DOUBLE:
218
      pOld->fval = pNew->fval;
27,240✔
219
      break;
27,240✔
220
    case CFG_DTYPE_STRING:
44,264✔
221
    case CFG_DTYPE_DIR:
222
    case CFG_DTYPE_LOCALE:
223
    case CFG_DTYPE_CHARSET:
224
    case CFG_DTYPE_TIMEZONE:
225
      taosMemoryFree(pOld->str);
44,264!
226
      pOld->str = taosStrdup(pNew->str);
44,264!
227
      if (pOld->str == NULL) {
44,264!
228
        return terrno;
×
229
      }
230
      break;
44,264✔
231
  }
232
  return TSDB_CODE_SUCCESS;
2,136,721✔
233
}
234

235
static int32_t mndCfgActionDeploy(SMnode *pMnode) { return mndInitWriteCfg(pMnode); }
3,246,145✔
236

237
static int32_t mndCfgActionAfterRestored(SMnode *pMnode) { return mndSendRebuildReq(pMnode); }
2,656,751✔
238

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

251
  SConfigObj *vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
6,645,749✔
252
  if (vObj == NULL) {
6,645,749!
253
    mInfo("failed to acquire mnd config version, since %s", terrstr());
×
254
    goto _OVER;
×
255
  }
256

257
  array = taosArrayInit(16, sizeof(SConfigItem));
6,645,749✔
258
  if (array == NULL) {
6,645,749!
259
    code = TSDB_CODE_OUT_OF_MEMORY;
×
260
    goto _OVER;
×
261
  }
262
  SConfigRsp configRsp = {0};
6,645,749✔
263
  configRsp.cver = vObj->i32;
6,645,749✔
264

265
  if (configReq.cver == vObj->i32) {
6,645,749✔
266
    configRsp.isVersionVerified = 1;
1,586,338✔
267
  } else {
268
    code = initConfigArrayFromSdb(pMnode, array);
5,059,411✔
269
    if (code != 0) {
5,059,411!
270
      mError("failed to init config array from sdb, since %s", tstrerror(code));
×
271
      goto _OVER;
×
272
    }
273
    configRsp.array = array;
5,059,411✔
274
  }
275

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

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

305
int32_t mndInitWriteCfg(SMnode *pMnode) {
3,246,145✔
306
  int    code = 0;
3,246,145✔
307
  size_t sz = 0;
3,246,145✔
308

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

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

326
  for (int i = 0; i < sz; ++i) {
334,352,935✔
327
    SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
331,106,790✔
328
    SConfigObj   obj;
330,967,254✔
329
    if ((code = mndInitConfigObj(item, &obj)) != 0) {
331,106,790!
330
      goto _OVER;
×
331
    }
332
    if ((code = mndSetCreateConfigCommitLogs(pTrans, &obj)) != 0) {
331,106,790!
333
      mError("failed to init mnd config:%s, since %s", item->name, tstrerror(code));
×
334
      tFreeSConfigObj(&obj);
×
335
      goto _OVER;
×
336
    }
337
    tFreeSConfigObj(&obj);
331,106,790✔
338
  }
339
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
3,246,145!
340

341
_OVER:
3,246,145✔
342
  if (code != 0) {
3,246,145!
343
    mError("failed to init write cfg, since %s", tstrerror(code));
×
344
  }
345
  mndTransDrop(pTrans);
3,246,145✔
346
  return code;
3,246,145✔
347
}
348

349
int32_t mndSendRebuildReq(SMnode *pMnode) {
2,656,751✔
350
  int32_t code = 0;
2,656,751✔
351

352
  SRpcMsg rpcMsg = {.pCont = NULL,
2,656,751✔
353
                    .contLen = 0,
354
                    .msgType = TDMT_MND_CONFIG_SDB,
355
                    .info.ahandle = 0,
356
                    .info.notFreeAhandle = 1,
357
                    .info.refId = 0,
358
                    .info.noResp = 0,
359
                    .info.handle = 0};
360
  SEpSet  epSet = {0};
2,656,751✔
361

362
  mndGetMnodeEpSet(pMnode, &epSet);
2,656,751✔
363

364
  code = tmsgSendReq(&epSet, &rpcMsg);
2,656,751✔
365
  if (code != 0) {
2,656,751!
366
    mError("failed to send rebuild config req, since %s", tstrerror(code));
×
367
  }
368
  return code;
2,656,751✔
369
}
370

371
static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq) {
2,648,208✔
372
  SMnode *pMnode = pReq->info.node;
2,648,208✔
373
  if (!mndIsLeader(pMnode)) {
2,648,208!
374
    return TSDB_CODE_SUCCESS;
×
375
  }
376

377
  int32_t     code = 0;
2,648,208✔
378
  SConfigObj *vObj = NULL;
2,648,208✔
379
  SArray     *addArray = NULL;
2,648,208✔
380
  SArray     *deleteArray = NULL;
2,648,208✔
381

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

393
  addArray = taosArrayInit(4, sizeof(SConfigObj));
2,648,208✔
394
  deleteArray = taosArrayInit(4, sizeof(SConfigObj));
2,648,208✔
395
  if (addArray == NULL || deleteArray == NULL) {
2,648,208!
396
    code = TSDB_CODE_OUT_OF_MEMORY;
×
397
    goto _exit;
×
398
  }
399

400
  // Find configs to add and delete
401
  if ((code = mndFindConfigsToAdd(pMnode, addArray)) != 0) {
2,648,208!
402
    mError("failed to find configs to add, since %s", tstrerror(code));
×
403
    goto _exit;
×
404
  }
405

406
  if ((code = mndFindConfigsToDelete(pMnode, deleteArray)) != 0) {
2,648,208!
407
    mError("failed to find configs to delete, since %s", tstrerror(code));
×
408
    goto _exit;
×
409
  }
410

411
  // Execute the sync transaction
412
  if ((code = mndExecuteConfigSyncTrans(pMnode, addArray, deleteArray)) != 0) {
2,648,208!
413
    mError("failed to execute config sync transaction, since %s", tstrerror(code));
×
414
    goto _exit;
×
415
  }
416

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

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

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

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

472
static int32_t mndFindConfigsToAdd(SMnode *pMnode, SArray *addArray) {
2,648,208✔
473
  int32_t code = 0;
2,648,208✔
474
  int32_t sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
2,648,208✔
475

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

494
  TAOS_RETURN(TSDB_CODE_SUCCESS);
2,648,208✔
495
}
496

497
static int32_t mndFindConfigsToDelete(SMnode *pMnode, SArray *deleteArray) {
2,648,208✔
498
  int32_t     code = 0;
2,648,208✔
499
  int32_t     sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
2,648,208✔
500
  SSdb       *pSdb = pMnode->pSdb;
2,648,208✔
501
  void       *pIter = NULL;
2,648,208✔
502
  SConfigObj *obj = NULL;
2,648,208✔
503

504
  while (1) {
272,765,424✔
505
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
275,413,632✔
506
    if (pIter == NULL) break;
275,413,632✔
507
    if (obj == NULL) {
272,765,424!
508
      code = TSDB_CODE_OUT_OF_MEMORY;
×
509
      sdbCancelFetch(pSdb, pIter);
×
510
      TAOS_RETURN(code);
×
511
    }
512

513
    // Skip the version config
514
    if (strcasecmp(obj->name, "tsmmConfigVersion") == 0) {
272,765,424✔
515
      sdbRelease(pSdb, obj);
2,648,208✔
516
      continue;
2,648,208✔
517
    }
518

519
    // Check if this config exists in global config
520
    bool existsInGlobal = false;
270,117,216✔
521
    for (int i = 0; i < sz; ++i) {
2,147,483,647!
522
      SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
2,147,483,647✔
523
      if (strcasecmp(obj->name, item->name) == 0) {
2,147,483,647!
524
        existsInGlobal = true;
270,117,216✔
525
        break;
270,117,216✔
526
      }
527
    }
528

529
    if (!existsInGlobal) {
270,117,216!
530
      mInfo("config:%s, not exist in global config, will delete it from sdb", obj->name);
×
531
      SConfigObj deleteObj = {0};
×
532
      tstrncpy(deleteObj.name, obj->name, CFG_NAME_MAX_LEN);
×
533
      deleteObj.dtype = obj->dtype;
×
534

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

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

574
    sdbRelease(pSdb, obj);
270,117,216✔
575
  }
576

577
  TAOS_RETURN(TSDB_CODE_SUCCESS);
2,648,208✔
578
}
579

580
static int32_t mndExecuteConfigSyncTrans(SMnode *pMnode, SArray *addArray, SArray *deleteArray) {
2,648,208✔
581
  int32_t addSize = taosArrayGetSize(addArray);
2,648,208✔
582
  int32_t deleteSize = taosArrayGetSize(deleteArray);
2,648,208✔
583

584
  if (addSize == 0 && deleteSize == 0) {
2,648,208!
585
    return TSDB_CODE_SUCCESS;
2,648,208✔
586
  }
587

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

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

602
  int32_t code = 0;
×
603

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

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

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

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

632
static int32_t mndMCfg2DCfg(SMCfgDnodeReq *pMCfgReq, SDCfgDnodeReq *pDCfgReq) {
1,198,684✔
633
  int32_t code = 0;
1,198,684✔
634
  char   *p = pMCfgReq->config;
1,198,684✔
635
  while (*p) {
18,206,960✔
636
    if (*p == ' ') {
17,737,356✔
637
      break;
729,080✔
638
    }
639
    p++;
17,008,276✔
640
  }
641

642
  size_t optLen = p - pMCfgReq->config;
1,198,684✔
643
  tstrncpy(pDCfgReq->config, pMCfgReq->config, sizeof(pDCfgReq->config));
1,198,684!
644
  pDCfgReq->config[optLen] = 0;
1,198,684✔
645

646
  if (' ' == pMCfgReq->config[optLen]) {
1,198,684✔
647
    // 'key value'
648
    if (strlen(pMCfgReq->value) != 0) goto _err;
729,080!
649
    tstrncpy(pDCfgReq->value, p + 1, sizeof(pDCfgReq->value));
729,080!
650
  } else {
651
    // 'key' 'value'
652
    if (strlen(pMCfgReq->value) == 0) goto _err;
469,604✔
653
    tstrncpy(pDCfgReq->value, pMCfgReq->value, sizeof(pDCfgReq->value));
454,729!
654
  }
655

656
  TAOS_RETURN(code);
1,183,809✔
657

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

664
static int32_t mndBuildCfgDnodeRedoAction(STrans *pTrans, SDnodeObj *pDnode, SDCfgDnodeReq *pDcfgReq) {
246,982✔
665
  int32_t code = 0;
246,982✔
666
  SEpSet  epSet = mndGetDnodeEpset(pDnode);
246,982✔
667
  int32_t bufLen = tSerializeSDCfgDnodeReq(NULL, 0, pDcfgReq);
246,982✔
668
  void   *pBuf = taosMemoryMalloc(bufLen);
246,982!
669

670
  if (pBuf == NULL) {
246,982!
671
    code = terrno;
×
672
    return code;
×
673
  }
674

675
  if ((bufLen = tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq)) <= 0) {
246,982!
676
    code = bufLen;
×
677
    taosMemoryFree(pBuf);
×
678
    return code;
×
679
  }
680

681
  STransAction action = {
246,982✔
682
      .epSet = epSet,
683
      .pCont = pBuf,
684
      .contLen = bufLen,
685
      .msgType = TDMT_DND_CONFIG_DNODE,
686
      .acceptableCode = 0,
687
      .groupId = -1,
688
  };
689

690
  mInfo("dnode:%d, append redo action to trans, config:%s value:%s", pDnode->id, pDcfgReq->config, pDcfgReq->value);
246,982!
691

692
  if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
246,982!
693
    taosMemoryFree(pBuf);
×
694
    return code;
×
695
  }
696

697
  return code;
246,982✔
698
}
699

700
static int32_t mndSendCfgDnodeReq(SMnode *pMnode, int32_t dnodeId, SDCfgDnodeReq *pDcfgReq) {
580,617✔
701
  int32_t code = -1;
580,617✔
702
  SSdb   *pSdb = pMnode->pSdb;
580,617✔
703
  void   *pIter = NULL;
580,617✔
704

705
  int64_t curMs = taosGetTimestampMs();
580,617✔
706

707
  while (1) {
1,330,425✔
708
    SDnodeObj *pDnode = NULL;
1,911,042✔
709
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
1,911,042✔
710
    if (pIter == NULL) break;
1,911,042✔
711

712
    if (pDnode->id == dnodeId || dnodeId == -1 || dnodeId == 0) {
1,339,608!
713
      bool online = mndIsDnodeOnline(pDnode, curMs);
607,737✔
714
      if (!online) {
607,737✔
715
        mWarn("dnode:%d, is offline, skip to send config req", pDnode->id);
34,040!
716
        continue;
34,040✔
717
      }
718
      SEpSet  epSet = mndGetDnodeEpset(pDnode);
573,697✔
719
      int32_t bufLen = tSerializeSDCfgDnodeReq(NULL, 0, pDcfgReq);
573,697✔
720
      void   *pBuf = rpcMallocCont(bufLen);
573,697✔
721

722
      if (pBuf == NULL) {
573,697!
723
        sdbCancelFetch(pMnode->pSdb, pIter);
×
724
        sdbRelease(pMnode->pSdb, pDnode);
×
725
        code = TSDB_CODE_OUT_OF_MEMORY;
×
726
        return code;
×
727
      }
728

729
      if ((bufLen = tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq)) <= 0) {
573,697!
730
        sdbCancelFetch(pMnode->pSdb, pIter);
×
731
        sdbRelease(pMnode->pSdb, pDnode);
×
732
        code = bufLen;
×
733
        rpcFreeCont(pBuf);
×
734
        return code;
×
735
      }
736

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

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

749
      code = rpcRsp.code;
573,697✔
750
      if (code != 0) {
573,697✔
751
        mError("failed to alter config %s,on dnode:%d, since %s", pDcfgReq->config, pDnode->id, tstrerror(code));
9,183!
752
        sdbCancelFetch(pMnode->pSdb, pIter);
9,183✔
753
        sdbRelease(pMnode->pSdb, pDnode);
9,183✔
754
        return code;
9,183✔
755
      }
756
      rpcFreeCont(rpcRsp.pCont);
564,514✔
757
    }
758
    sdbRelease(pSdb, pDnode);
1,296,385✔
759
  }
760

761
  if (code == -1) {
571,434✔
762
    code = TSDB_CODE_MND_DNODE_NOT_EXIST;
14,144✔
763
  }
764
  TAOS_RETURN(code);
571,434✔
765
}
766

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

779
  TAOS_CHECK_RETURN(tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq));
1,231,823!
780
  int8_t updateIpWhiteList = 0;
1,231,823✔
781
  mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value);
1,231,823!
782
  if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE)) != 0) {
1,231,823✔
783
    goto _err_out;
24,864✔
784
  }
785

786
  SDCfgDnodeReq dcfgReq = {0};
1,206,959✔
787
  if (strcasecmp(cfgReq.config, "resetlog") == 0) {
1,206,959✔
788
    tstrncpy(dcfgReq.config, "resetlog", 9);
8,275✔
789
    goto _send_req;
8,275✔
790
#ifdef TD_ENTERPRISE
791
  } else if (strncasecmp(cfgReq.config, "ssblocksize", 12) == 0) {
1,198,684!
792
    int32_t optLen = strlen("ssblocksize");
×
793
    int32_t flag = -1;
×
794
    int32_t code = mndMCfgGetValInt32(&cfgReq, optLen, &flag);
×
795
    if (code < 0) {
×
796
      goto _err_out;
×
797
    }
798

799
    if (flag > 1024 * 1024 || (flag > -1 && flag < 1024) || flag < -1) {
×
800
      mError("dnode:%d, failed to config ssblocksize since value:%d. Valid range: -1 or [1024, 1024 * 1024]",
×
801
             cfgReq.dnodeId, flag);
802
      code = TSDB_CODE_INVALID_CFG;
×
803
      goto _err_out;
×
804
    }
805

806
    tstrncpy(dcfgReq.config, "ssblocksize", 12);
×
807
    snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag);
×
808
#endif
809
  } else {
810
    TAOS_CHECK_GOTO(mndMCfg2DCfg(&cfgReq, &dcfgReq), &lino, _err_out);
1,198,684✔
811
    if (strlen(dcfgReq.config) > TSDB_DNODE_CONFIG_LEN) {
1,183,809!
812
      mError("dnode:%d, failed to config since config is too long", cfgReq.dnodeId);
×
813
      code = TSDB_CODE_INVALID_CFG;
×
814
      goto _err_out;
×
815
    }
816
    if (strncasecmp(dcfgReq.config, "enableWhiteList", strlen("enableWhiteList")) == 0) {
1,183,809✔
817
      updateIpWhiteList = 1;
18,956✔
818
    }
819

820
    CfgAlterType alterType = (cfgReq.dnodeId == 0 || cfgReq.dnodeId == -1) ? CFG_ALTER_ALL_DNODES : CFG_ALTER_DNODE;
1,183,809!
821
    TAOS_CHECK_GOTO(cfgCheckRangeForDynUpdate(taosGetCfg(), dcfgReq.config, dcfgReq.value, true, alterType), &lino,
1,183,809✔
822
                    _err_out);
823
  }
824
  SConfigItem *pItem = cfgGetItem(taosGetCfg(), dcfgReq.config);
798,280✔
825
  // Update config in sdb.
826
  if (pItem == NULL) {
798,280!
827
    mError("failed to find config:%s while process config dnode req", cfgReq.config);
×
828
    code = TSDB_CODE_CFG_NOT_FOUND;
×
829
    goto _err_out;
×
830
  }
831

832
  // Audit log
833
  {
834
    char obj[50] = {0};
798,280✔
835
    (void)tsnprintf(obj, sizeof(obj), "%d", cfgReq.dnodeId);
798,280✔
836
    auditRecord(pReq, pMnode->clusterId, "alterDnode", obj, "", cfgReq.sql, cfgReq.sqlLen);
798,280✔
837
  }
838

839
  dcfgReq.version = vObj->i32 + 1;
798,280✔
840

841
  if (pItem->category == CFG_CATEGORY_GLOBAL) {
798,280✔
842
    // Use transaction to update SDB and send to dnode atomically
843
    TAOS_CHECK_GOTO(mndConfigUpdateTransWithDnode(pMnode, dcfgReq.config, dcfgReq.value, pItem->dtype, dcfgReq.version,
225,938!
844
                                                  cfgReq.dnodeId, &dcfgReq),
845
                    &lino, _err_out);
846
  } else {
847
    // For local config, still use the old method (only send to dnode)
848
    goto _send_req;
572,342✔
849
  }
850

851
  // For global config, transaction has handled everything, go to success
852
  goto _success;
225,938✔
853

854
_send_req:
580,617✔
855
  dcfgReq.version = vObj->i32;
580,617✔
856
  code = mndSendCfgDnodeReq(pMnode, cfgReq.dnodeId, &dcfgReq);
580,617✔
857
  if (code != 0) {
580,617✔
858
    mError("failed to send config req to dnode:%d, since %s", cfgReq.dnodeId, tstrerror(code));
23,327!
859
    goto _err_out;
23,327✔
860
  }
861

862
_success:
783,228✔
863
  // dont care suss or succ;
864
  if (updateIpWhiteList) mndRefreshUserIpWhiteList(pMnode);
783,228✔
865
  tFreeSMCfgDnodeReq(&cfgReq);
783,228✔
866
  sdbRelease(pMnode->pSdb, vObj);
783,228✔
867
  TAOS_RETURN(code);
783,228✔
868

869
_err_out:
448,595✔
870
  mError("failed to process config dnode req, since %s", tstrerror(code));
448,595!
871
  tFreeSMCfgDnodeReq(&cfgReq);
448,595✔
872
  sdbRelease(pMnode->pSdb, vObj);
448,595✔
873
  TAOS_RETURN(code);
448,595✔
874
}
875

876
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp) {
1,535,356✔
877
  mInfo("config rsp from dnode");
1,535,356!
878
  return 0;
1,535,356✔
879
}
880

881
static int32_t mndTryRebuildConfigSdbRsp(SRpcMsg *pRsp) {
2,651,189✔
882
  mInfo("rebuild config sdb rsp");
2,651,189!
883
  return 0;
2,651,189✔
884
}
885

886
// Helper function to create and commit a config object
887
static int32_t mndCreateAndCommitConfigObj(STrans *pTrans, const char *srcName, const char *cfgName, char *value,
×
888
                                           int32_t *lino) {
889
  int32_t     code = 0;
×
890
  SConfigObj *pTmp = taosMemoryMalloc(sizeof(SConfigObj));
×
891
  if (pTmp == NULL) {
×
892
    code = terrno;
×
893
    return code;
×
894
  }
895

896
  pTmp->dtype = CFG_DTYPE_INT32;
×
897
  tstrncpy(pTmp->name, cfgName, CFG_NAME_MAX_LEN);
×
898
  code = mndUpdateObj(pTmp, srcName, value);
×
899
  if (code != 0) {
×
900
    tFreeSConfigObj(pTmp);
×
901
    taosMemoryFree(pTmp);
×
902
    return code;
×
903
  }
904

905
  code = mndSetCreateConfigCommitLogs(pTrans, pTmp);
×
906
  tFreeSConfigObj(pTmp);
×
907
  taosMemoryFree(pTmp);
×
908
  return code;
×
909
}
910

911
// Helper function to handle syncTimeout related config updates
912
static int32_t mndHandleSyncTimeoutConfigs(STrans *pTrans, const char *srcName, const char *pValue, int32_t *lino) {
×
913
  int32_t code = 0;
×
914
  int32_t syncTimeout = 0;
×
915
  char    tmp[10] = {0};
×
916

917
  if (sscanf(pValue, "%d", &syncTimeout) != 1) {
×
918
    syncTimeout = 0;
×
919
  }
920

921
  int32_t baseTimeout = syncTimeout - syncTimeout / SYNC_TIMEOUT_DIVISOR;
×
922

923
  // arbSetAssignedTimeoutMs = syncTimeout
924
  sprintf(tmp, "%d", syncTimeout);
×
925
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "arbSetAssignedTimeoutMs", tmp, lino), lino, _OVER);
×
926

927
  // arbHeartBeatIntervalMs = syncTimeout / 4
928
  sprintf(tmp, "%d", syncTimeout / SYNC_TIMEOUT_DIVISOR);
×
929
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "arbHeartBeatIntervalMs", tmp, lino), lino, _OVER);
×
930

931
  // arbCheckSyncIntervalMs = syncTimeout / 4
932
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "arbCheckSyncIntervalMs", tmp, lino), lino, _OVER);
×
933

934
  // syncVnodeElectIntervalMs = (syncTimeout - syncTimeout / 4) / 2
935
  sprintf(tmp, "%d", baseTimeout / SYNC_TIMEOUT_ELECT_DIVISOR);
×
936
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncVnodeElectIntervalMs", tmp, lino), lino, _OVER);
×
937

938
  // syncMnodeElectIntervalMs = (syncTimeout - syncTimeout / 4) / 2
939
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncMnodeElectIntervalMs", tmp, lino), lino, _OVER);
×
940

941
  // statusTimeoutMs = (syncTimeout - syncTimeout / 4) / 2
942
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "statusTimeoutMs", tmp, lino), lino, _OVER);
×
943

944
  // statusSRTimeoutMs = (syncTimeout - syncTimeout / 4) / 4
945
  sprintf(tmp, "%d", baseTimeout / SYNC_TIMEOUT_SR_DIVISOR);
×
946
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "statusSRTimeoutMs", tmp, lino), lino, _OVER);
×
947

948
  // syncVnodeHeartbeatIntervalMs = (syncTimeout - syncTimeout / 4) / 8
949
  sprintf(tmp, "%d", baseTimeout / SYNC_TIMEOUT_HB_DIVISOR);
×
950
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncVnodeHeartbeatIntervalMs", tmp, lino), lino, _OVER);
×
951

952
  // syncMnodeHeartbeatIntervalMs = (syncTimeout - syncTimeout / 4) / 8
953
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncMnodeHeartbeatIntervalMs", tmp, lino), lino, _OVER);
×
954

955
  // statusIntervalMs = (syncTimeout - syncTimeout / 4) / 8
956
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "statusIntervalMs", tmp, lino), lino, _OVER);
×
957

958
_OVER:
×
959
  return code;
×
960
}
961

962
// get int32_t value from 'SMCfgDnodeReq'
963
static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pMCfgReq, int32_t optLen, int32_t *pOutValue) {
×
964
  int32_t code = 0;
×
965
  if (' ' != pMCfgReq->config[optLen] && 0 != pMCfgReq->config[optLen]) {
×
966
    goto _err;
×
967
  }
968

969
  if (' ' == pMCfgReq->config[optLen]) {
×
970
    // 'key value'
971
    if (strlen(pMCfgReq->value) != 0) goto _err;
×
972
    *pOutValue = taosStr2Int32(pMCfgReq->config + optLen + 1, NULL, 10);
×
973
  } else {
974
    // 'key' 'value'
975
    if (strlen(pMCfgReq->value) == 0) goto _err;
×
976
    *pOutValue = taosStr2Int32(pMCfgReq->value, NULL, 10);
×
977
  }
978

979
  TAOS_RETURN(code);
×
980

981
_err:
×
982
  mError(" failed to set config since:%s", tstrerror(code));
×
983
  TAOS_RETURN(code);
×
984
}
985

986
static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype,
×
987
                                    int32_t tsmmConfigVersion) {
988
  int32_t     code = -1;
×
989
  int32_t     lino = -1;
×
990
  SConfigObj *pVersion = taosMemoryMalloc(sizeof(SConfigObj)), *pObj = taosMemoryMalloc(sizeof(SConfigObj));
×
991
  if (pVersion == NULL || pObj == NULL) {
×
992
    code = terrno;
×
993
    goto _OVER;
×
994
  }
995
  tstrncpy(pVersion->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
×
996
  pVersion->dtype = CFG_DTYPE_INT32;
×
997
  pVersion->i32 = tsmmConfigVersion;
×
998

999
  pObj->dtype = dtype;
×
1000
  tstrncpy(pObj->name, name, CFG_NAME_MAX_LEN);
×
1001

1002
  TAOS_CHECK_GOTO(mndUpdateObj(pObj, name, pValue), &lino, _OVER);
×
1003
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, NULL, "update-config");
×
1004
  if (pTrans == NULL) {
×
1005
    code = terrno;
×
1006
    goto _OVER;
×
1007
  }
1008
  mInfo("trans:%d, used to update config:%s to value:%s", pTrans->id, name, pValue);
×
1009
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pVersion), &lino, _OVER);
×
1010
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pObj), &lino, _OVER);
×
1011

1012
  if (taosStrncasecmp(name, "syncTimeout", CFG_NAME_MAX_LEN) == 0) {
×
1013
    TAOS_CHECK_GOTO(mndHandleSyncTimeoutConfigs(pTrans, name, pValue, &lino), &lino, _OVER);
×
1014
  }
1015
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
×
1016
  code = 0;
×
1017
_OVER:
×
1018
  if (code != 0) {
×
1019
    mError("failed to update config:%s to value:%s, since %s", name, pValue, tstrerror(code));
×
1020
  }
1021
  mndTransDrop(pTrans);
×
1022
  tFreeSConfigObj(pVersion);
×
1023
  taosMemoryFree(pVersion);
×
1024
  tFreeSConfigObj(pObj);
×
1025
  taosMemoryFree(pObj);
×
1026
  return code;
×
1027
}
1028

1029
static int32_t mndConfigUpdateTransWithDnode(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype,
225,938✔
1030
                                             int32_t tsmmConfigVersion, int32_t dnodeId, SDCfgDnodeReq *pDcfgReq) {
1031
  int32_t     code = -1;
225,938✔
1032
  int32_t     lino = -1;
225,938✔
1033
  SConfigObj *pVersion = taosMemoryMalloc(sizeof(SConfigObj)), *pObj = taosMemoryMalloc(sizeof(SConfigObj));
225,938!
1034
  if (pVersion == NULL || pObj == NULL) {
225,938!
1035
    code = terrno;
×
1036
    goto _OVER;
×
1037
  }
1038
  tstrncpy(pVersion->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
225,938!
1039
  pVersion->dtype = CFG_DTYPE_INT32;
225,938✔
1040
  pVersion->i32 = tsmmConfigVersion;
225,938✔
1041

1042
  pObj->dtype = dtype;
225,938✔
1043
  tstrncpy(pObj->name, name, CFG_NAME_MAX_LEN);
225,938!
1044

1045
  TAOS_CHECK_GOTO(mndUpdateObj(pObj, name, pValue), &lino, _OVER);
225,938!
1046
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "update-config-with-dnode");
225,938✔
1047
  if (pTrans == NULL) {
225,938!
1048
    code = terrno;
×
1049
    goto _OVER;
×
1050
  }
1051
  mInfo("trans:%d, used to update config:%s to value:%s and send to dnode", pTrans->id, name, pValue);
225,938!
1052

1053
  // Add prepare logs for SDB config updates (execute in PREPARE stage, before redo actions)
1054
  TAOS_CHECK_GOTO(mndSetCreateConfigPrepareLogs(pTrans, pVersion), &lino, _OVER);
225,938!
1055
  TAOS_CHECK_GOTO(mndSetCreateConfigPrepareLogs(pTrans, pObj), &lino, _OVER);
225,938!
1056

1057
  // Add commit logs for transaction persistence
1058
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pVersion), &lino, _OVER);
225,938!
1059
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pObj), &lino, _OVER);
225,938!
1060

1061
  if (taosStrncasecmp(name, "syncTimeout", CFG_NAME_MAX_LEN) == 0) {
225,938!
1062
    TAOS_CHECK_GOTO(mndHandleSyncTimeoutConfigs(pTrans, name, pValue, &lino), &lino, _OVER);
×
1063
  }
1064

1065
  // Add redo actions to send config to dnodes
1066
  SSdb   *pSdb = pMnode->pSdb;
225,938✔
1067
  void   *pIter = NULL;
225,938✔
1068
  int64_t curMs = taosGetTimestampMs();
225,938✔
1069

1070
  while (1) {
246,982✔
1071
    SDnodeObj *pDnode = NULL;
472,920✔
1072
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
472,920✔
1073
    if (pIter == NULL) break;
472,920✔
1074

1075
    if (pDnode->id == dnodeId || dnodeId == -1 || dnodeId == 0) {
246,982!
1076
      bool online = mndIsDnodeOnline(pDnode, curMs);
246,982✔
1077
      if (!online) {
246,982✔
1078
        mWarn("dnode:%d, is offline, still add to trans for retry", pDnode->id);
6,808!
1079
      }
1080

1081
      code = mndBuildCfgDnodeRedoAction(pTrans, pDnode, pDcfgReq);
246,982✔
1082
      if (code != 0) {
246,982!
1083
        mError("failed to build config redo action for dnode:%d, since %s", pDnode->id, tstrerror(code));
×
1084
        sdbCancelFetch(pMnode->pSdb, pIter);
×
1085
        sdbRelease(pMnode->pSdb, pDnode);
×
1086
        goto _OVER;
×
1087
      }
1088
    }
1089
    sdbRelease(pSdb, pDnode);
246,982✔
1090
  }
1091

1092
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
225,938!
1093
  code = 0;
225,938✔
1094

1095
_OVER:
225,938✔
1096
  if (code != 0) {
225,938!
1097
    mError("failed to update config:%s to value:%s and send to dnode, since %s", name, pValue, tstrerror(code));
×
1098
  }
1099
  mndTransDrop(pTrans);
225,938✔
1100
  tFreeSConfigObj(pVersion);
225,938✔
1101
  taosMemoryFree(pVersion);
225,938!
1102
  tFreeSConfigObj(pObj);
225,938✔
1103
  taosMemoryFree(pObj);
225,938!
1104
  return code;
225,938✔
1105
}
1106

1107
static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array) {
5,059,411✔
1108
  int32_t     code = 0;
5,059,411✔
1109
  SSdb       *pSdb = pMnode->pSdb;
5,059,411✔
1110
  void       *pIter = NULL;
5,059,411✔
1111
  SConfigObj *obj = NULL;
5,059,411✔
1112

1113
  while (1) {
521,119,333✔
1114
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
526,178,744✔
1115
    if (pIter == NULL) break;
526,178,744✔
1116
    if (obj == NULL) {
521,119,333!
1117
      code = TSDB_CODE_OUT_OF_MEMORY;
×
1118
      goto _exit;
×
1119
    }
1120
    if (strcasecmp(obj->name, "tsmmConfigVersion") == 0) {
521,119,333✔
1121
      sdbRelease(pSdb, obj);
5,059,411✔
1122
      continue;
5,059,411✔
1123
    }
1124
    SConfigItem item = {0};
516,059,922✔
1125
    item.dtype = obj->dtype;
516,059,922✔
1126
    item.name = taosStrdup(obj->name);
516,059,922!
1127
    if (item.name == NULL) {
516,059,922!
1128
      code = terrno;
×
1129
      sdbCancelFetch(pSdb, pIter);
×
1130
      sdbRelease(pSdb, obj);
×
1131
      goto _exit;
×
1132
    }
1133
    switch (obj->dtype) {
516,059,922!
1134
      case CFG_DTYPE_NONE:
×
1135
        break;
×
1136
      case CFG_DTYPE_BOOL:
96,128,809✔
1137
        item.bval = obj->bval;
96,128,809!
1138
        break;
96,128,809✔
1139
      case CFG_DTYPE_INT32:
288,386,427✔
1140
        item.i32 = obj->i32;
288,386,427✔
1141
        break;
288,386,427✔
1142
      case CFG_DTYPE_INT64:
30,356,466✔
1143
        item.i64 = obj->i64;
30,356,466✔
1144
        break;
30,356,466✔
1145
      case CFG_DTYPE_FLOAT:
10,118,822✔
1146
      case CFG_DTYPE_DOUBLE:
1147
        item.fval = obj->fval;
10,118,822✔
1148
        break;
10,118,822✔
1149
      case CFG_DTYPE_STRING:
91,069,398✔
1150
      case CFG_DTYPE_DIR:
1151
      case CFG_DTYPE_LOCALE:
1152
      case CFG_DTYPE_CHARSET:
1153
      case CFG_DTYPE_TIMEZONE:
1154
        item.str = taosStrdup(obj->str);
91,069,398!
1155
        if (item.str == NULL) {
91,069,398!
1156
          sdbCancelFetch(pSdb, pIter);
×
1157
          sdbRelease(pSdb, obj);
×
1158
          code = terrno;
×
1159
          goto _exit;
×
1160
        }
1161
        break;
91,069,398✔
1162
    }
1163
    if (taosArrayPush(array, &item) == NULL) {
516,059,922!
1164
      sdbCancelFetch(pSdb, pIter);
×
1165
      sdbRelease(pSdb, obj);
×
1166
      code = TSDB_CODE_OUT_OF_MEMORY;
×
1167
      goto _exit;
×
1168
      break;
1169
    }
1170
    sdbRelease(pSdb, obj);
516,059,922✔
1171
  }
1172
_exit:
5,059,411✔
1173
  if (code != 0) {
5,059,411!
1174
    mError("failed to init config array from sdb, since %s", tstrerror(code));
×
1175
  }
1176
  return code;
5,059,411✔
1177
}
1178

1179
static void cfgArrayCleanUp(SArray *array) {
6,645,749✔
1180
  if (array == NULL) {
6,645,749!
1181
    return;
×
1182
  }
1183

1184
  int32_t sz = taosArrayGetSize(array);
6,645,749✔
1185
  for (int32_t i = 0; i < sz; ++i) {
522,705,671✔
1186
    SConfigItem *item = taosArrayGet(array, i);
516,059,922✔
1187
    if (item->dtype == CFG_DTYPE_STRING || item->dtype == CFG_DTYPE_DIR || item->dtype == CFG_DTYPE_LOCALE ||
516,059,922!
1188
        item->dtype == CFG_DTYPE_CHARSET || item->dtype == CFG_DTYPE_TIMEZONE) {
435,109,346✔
1189
      taosMemoryFreeClear(item->str);
91,069,398!
1190
    }
1191
    taosMemoryFreeClear(item->name);
516,059,922!
1192
  }
1193

1194
  taosArrayDestroy(array);
6,645,749✔
1195
}
1196

1197
static void cfgObjArrayCleanUp(SArray *array) {
5,296,416✔
1198
  if (array == NULL) {
5,296,416!
1199
    return;
×
1200
  }
1201
  int32_t sz = taosArrayGetSize(array);
5,296,416✔
1202
  for (int32_t i = 0; i < sz; ++i) {
5,296,416!
1203
    SConfigObj *obj = taosArrayGet(array, i);
×
1204
    tFreeSConfigObj(obj);
×
1205
  }
1206
  taosArrayDestroy(array);
5,296,416✔
1207
}
1208

1209
static SArray *initVariablesFromItems(SArray *pItems, const char* likePattern) {
792,569✔
1210
  if (pItems == NULL) {
792,569!
1211
    return NULL;
×
1212
  }
1213

1214
  int32_t sz = taosArrayGetSize(pItems);
792,569✔
1215

1216
  SArray *pInfos = taosArrayInit(sz, sizeof(SVariablesInfo));
792,569✔
1217
  if (pInfos == NULL) {
792,569!
1218
    mError("failed to init array while init variables from items, since %s", tstrerror(terrno));
×
1219
    return NULL;
×
1220
  }
1221
  for (int32_t i = 0; i < sz; ++i) {
81,634,607✔
1222
    SConfigItem   *pItem = taosArrayGet(pItems, i);
80,842,038✔
1223
    SVariablesInfo info = {0};
80,842,038✔
1224
    tstrncpy(info.name, pItem->name, sizeof(info.name));
80,842,038!
1225
    if (likePattern != NULL && rawStrPatternMatch(pItem->name, likePattern) != TSDB_PATTERN_MATCH) {
80,842,038✔
1226
      continue;
10,618,782✔
1227
    }
1228

1229
    // init info value
1230
    switch (pItem->dtype) {
70,223,256!
1231
      case CFG_DTYPE_NONE:
×
1232
        break;
×
1233
      case CFG_DTYPE_BOOL:
13,050,779✔
1234
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->bval);
13,050,779!
1235
        break;
13,050,779✔
1236
      case CFG_DTYPE_INT32:
39,317,729✔
1237
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->i32);
39,317,729✔
1238
        break;
39,317,729✔
1239
      case CFG_DTYPE_INT64:
4,114,770✔
1240
        tsnprintf(info.value, sizeof(info.value), "%" PRId64, pItem->i64);
4,114,770✔
1241
        break;
4,114,770✔
1242
      case CFG_DTYPE_FLOAT:
1,371,590✔
1243
      case CFG_DTYPE_DOUBLE:
1244
        tsnprintf(info.value, sizeof(info.value), "%f", pItem->fval);
1,371,590✔
1245
        break;
1,371,590✔
1246
      case CFG_DTYPE_STRING:
12,368,388✔
1247
      case CFG_DTYPE_DIR:
1248
      case CFG_DTYPE_LOCALE:
1249
      case CFG_DTYPE_CHARSET:
1250
      case CFG_DTYPE_TIMEZONE:
1251
        tsnprintf(info.value, sizeof(info.value), "%s", pItem->str);
12,368,388✔
1252
        break;
12,368,388✔
1253
    }
1254

1255
    // init info scope
1256
    switch (pItem->scope) {
70,223,256!
1257
      case CFG_SCOPE_SERVER:
55,818,157✔
1258
        tstrncpy(info.scope, "server", sizeof(info.scope));
55,818,157✔
1259
        break;
55,818,157✔
1260
      case CFG_SCOPE_CLIENT:
×
1261
        tstrncpy(info.scope, "client", sizeof(info.scope));
×
1262
        break;
×
1263
      case CFG_SCOPE_BOTH:
14,405,099✔
1264
        tstrncpy(info.scope, "both", sizeof(info.scope));
14,405,099✔
1265
        break;
14,405,099✔
1266
      default:
×
1267
        tstrncpy(info.scope, "unknown", sizeof(info.scope));
×
1268
        break;
×
1269
    }
1270
    // init info category
1271
    switch (pItem->category) {
70,223,256!
1272
      case CFG_CATEGORY_GLOBAL:
70,223,256✔
1273
        tstrncpy(info.category, "global", sizeof(info.category));
70,223,256✔
1274
        break;
70,223,256✔
1275
      case CFG_CATEGORY_LOCAL:
×
1276
        tstrncpy(info.category, "local", sizeof(info.category));
×
1277
        break;
×
1278
      default:
×
1279
        tstrncpy(info.category, "unknown", sizeof(info.category));
×
1280
        break;
×
1281
    }
1282
    if (NULL == taosArrayPush(pInfos, &info)) {
70,223,256!
1283
      mError("failed to push info to array while init variables from items,since %s", tstrerror(terrno));
×
1284
      taosArrayDestroy(pInfos);
×
1285
      return NULL;
×
1286
    }
1287
  }
1288

1289
  return pInfos;
792,569✔
1290
}
1291

1292
static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) {
792,569✔
1293
  SShowVariablesRsp rsp = {0};
792,569✔
1294
  int32_t           code = TSDB_CODE_SUCCESS;
792,569✔
1295
  SShowVariablesReq req = {0};
792,569✔
1296
  SArray           *array = NULL;
792,569✔
1297

1298
  code = tDeserializeSShowVariablesReq(pReq->pCont, pReq->contLen, &req);
792,569✔
1299
  if (code != 0) {
792,569!
1300
    mError("failed to deserialize config req, since %s", terrstr());
×
1301
    goto _OVER;
×
1302
  }
1303

1304
  if ((code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_SHOW_VARIABLES)) != 0) {
792,569!
1305
    goto _OVER;
×
1306
  }
1307

1308
  SVariablesInfo info = {0};
792,569✔
1309
  char          *likePattern = req.opType == OP_TYPE_LIKE ? req.val : NULL;
792,569✔
1310
  rsp.variables = initVariablesFromItems(taosGetGlobalCfg(tsCfg), likePattern);
792,569✔
1311
  if (rsp.variables == NULL) {
792,569!
1312
    code = terrno;
×
1313
    goto _OVER;
×
1314
  }
1315
  int32_t rspLen = tSerializeSShowVariablesRsp(NULL, 0, &rsp);
792,569✔
1316
  void   *pRsp = rpcMallocCont(rspLen);
792,569✔
1317
  if (pRsp == NULL) {
792,569!
1318
    code = terrno;
×
1319
    goto _OVER;
×
1320
  }
1321

1322
  if ((rspLen = tSerializeSShowVariablesRsp(pRsp, rspLen, &rsp)) <= 0) {
792,569!
1323
    rpcFreeCont(pRsp);
×
1324
    code = rspLen;
×
1325
    goto _OVER;
×
1326
  }
1327

1328
  pReq->info.rspLen = rspLen;
792,569✔
1329
  pReq->info.rsp = pRsp;
792,569✔
1330
  code = 0;
792,569✔
1331

1332
_OVER:
792,569✔
1333

1334
  if (code != 0) {
792,569!
1335
    mError("failed to get show variables info since %s", tstrerror(code));
×
1336
  }
1337
  tFreeSShowVariablesReq(&req);
792,569✔
1338
  tFreeSShowVariablesRsp(&rsp);
792,569✔
1339
  TAOS_RETURN(code);
792,569✔
1340
}
1341

1342
int32_t compareSConfigItem(const SConfigObj *item1, SConfigItem *item2, bool *compare) {
×
1343
  *compare = true;
×
1344
  switch (item1->dtype) {
×
1345
    case CFG_DTYPE_BOOL:
×
1346
      if (item1->bval != item2->bval) {
×
1347
        item2->bval = item1->bval;
×
1348
        *compare = false;
×
1349
      }
1350
      break;
×
1351
    case CFG_DTYPE_FLOAT:
×
1352
      if (item1->fval != item2->fval) {
×
1353
        item2->fval = item1->fval;
×
1354
        *compare = false;
×
1355
      }
1356
      break;
×
1357
    case CFG_DTYPE_INT32:
×
1358
      if (item1->i32 != item2->i32) {
×
1359
        item2->i32 = item1->i32;
×
1360
        *compare = false;
×
1361
      }
1362
      break;
×
1363
    case CFG_DTYPE_INT64:
×
1364
      if (item1->i64 != item2->i64) {
×
1365
        item2->i64 = item1->i64;
×
1366
        *compare = false;
×
1367
      }
1368
      break;
×
1369
    case CFG_DTYPE_STRING:
×
1370
    case CFG_DTYPE_DIR:
1371
    case CFG_DTYPE_LOCALE:
1372
    case CFG_DTYPE_CHARSET:
1373
    case CFG_DTYPE_TIMEZONE:
1374
      if (strcmp(item1->str, item2->str) != 0) {
×
1375
        item2->str = taosStrdup(item1->str);
×
1376
        if (item2->str == NULL) {
×
1377
          return TSDB_CODE_OUT_OF_MEMORY;
×
1378
        }
1379
        *compare = false;
×
1380
      }
1381
      break;
×
1382
    default:
×
1383
      *compare = false;
×
1384
      return TSDB_CODE_INVALID_CFG;
×
1385
  }
1386
  return TSDB_CODE_SUCCESS;
×
1387
}
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