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

taosdata / TDengine / #4898

26 Dec 2025 09:58AM UTC coverage: 65.061% (-0.7%) from 65.717%
#4898

push

travis-ci

web-flow
feat: support encryption of configuration files, data files and metadata files (#33801)

350 of 1333 new or added lines in 31 files covered. (26.26%)

2796 existing lines in 159 files now uncovered.

184024 of 282850 relevant lines covered (65.06%)

113940470.33 hits per line

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

57.82
/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) {
402,544✔
65
  int32_t   code = 0;
402,544✔
66
  SSdbTable table = {.sdbType = SDB_CFG,
402,544✔
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);
402,544✔
77
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeReq);
402,544✔
78
  mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndTransProcessRsp);
402,544✔
79
  mndSetMsgHandle(pMnode, TDMT_MND_SHOW_VARIABLES, mndProcessShowVariablesReq);
402,544✔
80
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_SDB, mndTryRebuildConfigSdb);
402,544✔
81
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_SDB_RSP, mndTryRebuildConfigSdbRsp);
402,544✔
82

83
  return sdbSetTable(pMnode->pSdb, table);
402,544✔
84
}
85

86
SSdbRaw *mnCfgActionEncode(SConfigObj *obj) {
119,404,658✔
87
  int32_t  code = 0;
119,404,658✔
88
  int32_t  lino = 0;
119,404,658✔
89
  void    *buf = NULL;
119,404,658✔
90
  SSdbRaw *pRaw = NULL;
119,404,658✔
91

92
  SEncoder encoder;
119,361,718✔
93
  tEncoderInit(&encoder, NULL, 0);
119,404,658✔
94
  if ((code = tEncodeSConfigObj(&encoder, obj)) < 0) {
119,404,658✔
95
    tEncoderClear(&encoder);
×
96
    TSDB_CHECK_CODE(code, lino, _over);
×
97
  }
98

99
  int32_t tlen = encoder.pos;
119,404,658✔
100
  tEncoderClear(&encoder);
119,404,658✔
101

102
  int32_t size = sizeof(int32_t) + tlen;
119,404,658✔
103
  pRaw = sdbAllocRaw(SDB_CFG, CFG_VER_NUMBER, size);
119,404,658✔
104
  TSDB_CHECK_NULL(pRaw, code, lino, _over, terrno);
119,404,658✔
105

106
  buf = taosMemoryMalloc(tlen);
119,404,658✔
107
  TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
119,404,658✔
108

109
  tEncoderInit(&encoder, buf, tlen);
119,404,658✔
110
  if ((code = tEncodeSConfigObj(&encoder, obj)) < 0) {
119,404,658✔
111
    tEncoderClear(&encoder);
×
112
    TSDB_CHECK_CODE(code, lino, _over);
×
113
  }
114

115
  tEncoderClear(&encoder);
119,404,658✔
116

117
  int32_t dataPos = 0;
119,404,658✔
118
  SDB_SET_INT32(pRaw, dataPos, tlen, _over);
119,404,658✔
119
  SDB_SET_BINARY(pRaw, dataPos, buf, tlen, _over);
119,404,658✔
120
  SDB_SET_DATALEN(pRaw, dataPos, _over);
119,404,658✔
121

122
_over:
119,404,658✔
123
  taosMemoryFreeClear(buf);
119,404,658✔
124
  if (code != TSDB_CODE_SUCCESS) {
119,404,658✔
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;
119,404,658✔
132
  mTrace("cfg:%s, encode to raw:%p, row:%p", obj->name, pRaw, obj);
119,404,658✔
133
  return pRaw;
119,404,658✔
134
}
135

136
SSdbRow *mndCfgActionDecode(SSdbRaw *pRaw) {
45,606,680✔
137
  int32_t     code = 0;
45,606,680✔
138
  int32_t     lino = 0;
45,606,680✔
139
  SSdbRow    *pRow = NULL;
45,606,680✔
140
  SConfigObj *pObj = NULL;
45,606,680✔
141
  void       *buf = NULL;
45,606,680✔
142
  int8_t      sver = 0;
45,606,680✔
143
  int32_t     tlen;
45,584,532✔
144
  int32_t     dataPos = 0;
45,606,680✔
145

146
  code = sdbGetRawSoftVer(pRaw, &sver);
45,606,680✔
147
  TSDB_CHECK_CODE(code, lino, _over);
45,606,680✔
148

149
  if (sver != CFG_VER_NUMBER) {
45,606,680✔
150
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
151
    goto _over;
×
152
  }
153

154
  pRow = sdbAllocRow(sizeof(SConfigObj));
45,606,680✔
155
  TSDB_CHECK_NULL(pRow, code, lino, _over, terrno);
45,606,680✔
156

157
  pObj = sdbGetRowObj(pRow);
45,606,680✔
158
  TSDB_CHECK_NULL(pObj, code, lino, _over, terrno);
45,606,680✔
159

160
  SDB_GET_INT32(pRaw, dataPos, &tlen, _over);
45,606,680✔
161

162
  buf = taosMemoryMalloc(tlen + 1);
45,606,680✔
163
  TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
45,606,680✔
164

165
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, _over);
45,606,680✔
166

167
  SDecoder decoder;
45,584,532✔
168
  tDecoderInit(&decoder, buf, tlen + 1);
45,606,680✔
169
  code = tDecodeSConfigObj(&decoder, pObj);
45,606,680✔
170
  tDecoderClear(&decoder);
45,606,680✔
171

172
  if (code < 0) {
45,606,680✔
173
    tFreeSConfigObj(pObj);
×
174
  }
175

176
_over:
45,606,680✔
177
  taosMemoryFreeClear(buf);
45,606,680✔
178

179
  if (code != TSDB_CODE_SUCCESS) {
45,606,680✔
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);
45,606,680✔
186
    terrno = 0;
45,606,680✔
187
    return pRow;
45,606,680✔
188
  }
189
}
190

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

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

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

235
static int32_t mndCfgActionDeploy(SMnode *pMnode) { return mndInitWriteCfg(pMnode); }
288,363✔
236

237
static int32_t mndCfgActionAfterRestored(SMnode *pMnode) { return mndSendRebuildReq(pMnode); }
192,216✔
238

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

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

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

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

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

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

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

309
  mInfo("init write cfg to sdb");
288,363✔
310
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "init-write-config");
288,363✔
311
  if (pTrans == NULL) {
288,363✔
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();
288,363✔
318
  if ((code = mndSetCreateConfigCommitLogs(pTrans, &versionObj)) != 0) {
288,363✔
319
    mError("failed to init mnd config version, since %s", tstrerror(code));
×
320
    tFreeSConfigObj(&versionObj);
×
321
    goto _OVER;
×
322
  }
323
  tFreeSConfigObj(&versionObj);
288,363✔
324
  sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
288,363✔
325

326
  for (int i = 0; i < sz; ++i) {
32,585,019✔
327
    SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
32,296,656✔
328
    SConfigObj   obj;
32,283,664✔
329
    if ((code = mndInitConfigObj(item, &obj)) != 0) {
32,296,656✔
330
      goto _OVER;
×
331
    }
332
    if ((code = mndSetCreateConfigCommitLogs(pTrans, &obj)) != 0) {
32,296,656✔
333
      mError("failed to init mnd config:%s, since %s", item->name, tstrerror(code));
×
334
      tFreeSConfigObj(&obj);
×
335
      goto _OVER;
×
336
    }
337
    tFreeSConfigObj(&obj);
32,296,656✔
338
  }
339
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
288,363✔
340

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

349
int32_t mndSendRebuildReq(SMnode *pMnode) {
192,216✔
350
  int32_t code = 0;
192,216✔
351

352
  SRpcMsg rpcMsg = {.pCont = NULL,
192,216✔
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};
192,216✔
361

362
  mndGetMnodeEpSet(pMnode, &epSet);
192,216✔
363

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

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

377
  int32_t     code = 0;
192,282✔
378
  SConfigObj *vObj = NULL;
192,282✔
379
  SArray     *addArray = NULL;
192,282✔
380
  SArray     *deleteArray = NULL;
192,282✔
381

382
  vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
192,282✔
383
  if (vObj == NULL) {
192,282✔
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));
192,282✔
394
  deleteArray = taosArrayInit(4, sizeof(SConfigObj));
192,282✔
395
  if (addArray == NULL || deleteArray == NULL) {
192,282✔
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) {
192,282✔
402
    mError("failed to find configs to add, since %s", tstrerror(code));
×
403
    goto _exit;
×
404
  }
405

406
  if ((code = mndFindConfigsToDelete(pMnode, deleteArray)) != 0) {
192,282✔
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) {
192,282✔
413
    mError("failed to execute config sync transaction, since %s", tstrerror(code));
×
414
    goto _exit;
×
415
  }
416

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

427
int32_t mndSetCreateConfigCommitLogs(STrans *pTrans, SConfigObj *item) {
32,605,227✔
428
  int32_t  code = 0;
32,605,227✔
429
  SSdbRaw *pCommitRaw = mnCfgActionEncode(item);
32,605,227✔
430
  if (pCommitRaw == NULL) {
32,605,227✔
431
    code = terrno;
×
432
    TAOS_RETURN(code);
×
433
  }
434
  if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
32,605,227✔
435
    taosMemoryFree(pCommitRaw);
×
436
    TAOS_RETURN(code);
×
437
  }
438
  if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)) != 0) TAOS_RETURN(code);
32,605,227✔
439
  return TSDB_CODE_SUCCESS;
32,605,227✔
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) {
20,208✔
458
  int32_t  code = 0;
20,208✔
459
  SSdbRaw *pPrepareRaw = mnCfgActionEncode(item);
20,208✔
460
  if (pPrepareRaw == NULL) {
20,208✔
461
    code = terrno;
×
462
    TAOS_RETURN(code);
×
463
  }
464
  if ((code = mndTransAppendPrepareLog(pTrans, pPrepareRaw)) != 0) {
20,208✔
465
    taosMemoryFree(pPrepareRaw);
×
466
    TAOS_RETURN(code);
×
467
  }
468
  if ((code = sdbSetRawStatus(pPrepareRaw, SDB_STATUS_READY)) != 0) TAOS_RETURN(code);
20,208✔
469
  return TSDB_CODE_SUCCESS;
20,208✔
470
}
471

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

476
  for (int i = 0; i < sz; ++i) {
21,727,866✔
477
    SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
21,535,584✔
478
    SConfigObj  *obj = sdbAcquire(pMnode->pSdb, SDB_CFG, item->name);
21,535,584✔
479
    if (obj == NULL) {
21,535,584✔
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);
21,535,584✔
491
    }
492
  }
493

494
  TAOS_RETURN(TSDB_CODE_SUCCESS);
192,282✔
495
}
496

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

504
  while (1) {
21,727,866✔
505
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
21,920,148✔
506
    if (pIter == NULL) break;
21,920,148✔
507
    if (obj == NULL) {
21,727,866✔
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) {
21,727,866✔
515
      sdbRelease(pSdb, obj);
192,282✔
516
      continue;
192,282✔
517
    }
518

519
    // Check if this config exists in global config
520
    bool existsInGlobal = false;
21,535,584✔
521
    for (int i = 0; i < sz; ++i) {
1,216,760,496✔
522
      SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
1,216,760,496✔
523
      if (strcasecmp(obj->name, item->name) == 0) {
1,216,760,496✔
524
        existsInGlobal = true;
21,535,584✔
525
        break;
21,535,584✔
526
      }
527
    }
528

529
    if (!existsInGlobal) {
21,535,584✔
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);
21,535,584✔
575
  }
576

577
  TAOS_RETURN(TSDB_CODE_SUCCESS);
192,282✔
578
}
579

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

584
  if (addSize == 0 && deleteSize == 0) {
192,282✔
585
    return TSDB_CODE_SUCCESS;
192,282✔
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) {
78,794✔
633
  int32_t code = 0;
78,794✔
634
  char   *p = pMCfgReq->config;
78,794✔
635
  while (*p) {
1,146,859✔
636
    if (*p == ' ') {
1,100,498✔
637
      break;
32,433✔
638
    }
639
    p++;
1,068,065✔
640
  }
641

642
  size_t optLen = p - pMCfgReq->config;
78,794✔
643
  tstrncpy(pDCfgReq->config, pMCfgReq->config, sizeof(pDCfgReq->config));
78,794✔
644
  pDCfgReq->config[optLen] = 0;
78,794✔
645

646
  if (' ' == pMCfgReq->config[optLen]) {
78,794✔
647
    // 'key value'
648
    if (strlen(pMCfgReq->value) != 0) goto _err;
32,433✔
649
    tstrncpy(pDCfgReq->value, p + 1, sizeof(pDCfgReq->value));
32,433✔
650
  } else {
651
    // 'key' 'value'
652
    if (strlen(pMCfgReq->value) == 0) goto _err;
46,361✔
653
    tstrncpy(pDCfgReq->value, pMCfgReq->value, sizeof(pDCfgReq->value));
45,754✔
654
  }
655

656
  TAOS_RETURN(code);
78,187✔
657

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

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

670
  if (pBuf == NULL) {
10,920✔
671
    code = terrno;
×
672
    return code;
×
673
  }
674

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

681
  STransAction action = {
10,920✔
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);
10,920✔
691

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

697
  return code;
10,920✔
698
}
699

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

705
  int64_t curMs = taosGetTimestampMs();
54,055✔
706

707
  while (1) {
159,827✔
708
    SDnodeObj *pDnode = NULL;
213,882✔
709
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
213,882✔
710
    if (pIter == NULL) break;
213,882✔
711

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

722
      if (pBuf == NULL) {
54,493✔
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) {
54,493✔
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);
54,493✔
738
      SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen};
54,493✔
739
      SRpcMsg rpcRsp = {0};
54,493✔
740

741
      code = rpcSendRecvWithTimeout(pMnode->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, NULL, CFG_ALTER_TIMEOUT);
54,493✔
742
      if (code != 0) {
54,493✔
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;
54,493✔
750
      if (code != 0) {
54,493✔
751
        mError("failed to alter config %s,on dnode:%d, since %s", pDcfgReq->config, pDnode->id, tstrerror(code));
1,956✔
752
        sdbCancelFetch(pMnode->pSdb, pIter);
1,956✔
753
        sdbRelease(pMnode->pSdb, pDnode);
1,956✔
754
        return code;
1,956✔
755
      }
756
      rpcFreeCont(rpcRsp.pCont);
52,537✔
757
    }
758
    sdbRelease(pSdb, pDnode);
159,827✔
759
  }
760

761
  if (code == -1) {
52,099✔
762
    code = TSDB_CODE_MND_DNODE_NOT_EXIST;
640✔
763
  }
764
  TAOS_RETURN(code);
52,099✔
765
}
766

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

780
  TAOS_CHECK_RETURN(tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq));
80,168✔
781
  int8_t updateWhiteList = 0;
80,168✔
782
  mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value);
80,168✔
783
  if ((code = mndCheckOperPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_CONFIG_DNODE)) != 0) {
80,168✔
784
    goto _err_out;
1,134✔
785
  }
786

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

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

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

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

833
  // Audit log
834
  if (tsAuditLevel >= AUDIT_LEVEL_SYSTEM) {
63,919✔
835
    char obj[50] = {0};
63,919✔
836
    (void)tsnprintf(obj, sizeof(obj), "%d", cfgReq.dnodeId);
63,919✔
837
    int64_t tse = taosGetTimestampMs();
63,919✔
838
    double  duration = (double)(tse - tss);
63,919✔
839
    duration = duration / 1000;
63,919✔
840
    auditRecord(pReq, pMnode->clusterId, "alterDnode", obj, "", cfgReq.sql, cfgReq.sqlLen, duration, 0);
63,919✔
841
  }
842

843
  dcfgReq.version = vObj->i32 + 1;
63,919✔
844

845
  if (pItem->category == CFG_CATEGORY_GLOBAL) {
63,919✔
846
    // Use transaction to update SDB and send to dnode atomically
847
    TAOS_CHECK_GOTO(mndConfigUpdateTransWithDnode(pMnode, dcfgReq.config, dcfgReq.value, pItem->dtype, dcfgReq.version,
10,104✔
848
                                                  cfgReq.dnodeId, &dcfgReq),
849
                    &lino, _err_out);
850
  } else {
851
    // For local config, still use the old method (only send to dnode)
852
    goto _send_req;
53,815✔
853
  }
854

855
  // For global config, transaction has handled everything, go to success
856
  goto _success;
10,104✔
857

858
_send_req:
54,055✔
859
  dcfgReq.version = vObj->i32;
54,055✔
860
  code = mndSendCfgDnodeReq(pMnode, cfgReq.dnodeId, &dcfgReq);
54,055✔
861
  if (code != 0) {
54,055✔
862
    mError("failed to send config req to dnode:%d, since %s", cfgReq.dnodeId, tstrerror(code));
2,596✔
863
    goto _err_out;
2,596✔
864
  }
865

866
_success:
61,563✔
867
  // dont care suss or succ;
868
  if (updateWhiteList) {
61,563✔
869
    int32_t dummy1 = mndRefreshUserIpWhiteList(pMnode);
160✔
870
    int32_t dummy2 = mndRefreshUserDateTimeWhiteList(pMnode);
160✔
871
    (void)dummy1;
872
    (void)dummy2;
873
  }
874
  tFreeSMCfgDnodeReq(&cfgReq);
61,563✔
875
  sdbRelease(pMnode->pSdb, vObj);
61,563✔
876
  TAOS_RETURN(code);
61,563✔
877

878
_err_out:
18,605✔
879
  mError("failed to process config dnode req, since %s", tstrerror(code));
18,605✔
880
  tFreeSMCfgDnodeReq(&cfgReq);
18,605✔
881
  sdbRelease(pMnode->pSdb, vObj);
18,605✔
882
  TAOS_RETURN(code);
18,605✔
883
}
884

885
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp) {
×
886
  mInfo("config rsp from dnode");
×
887
  return 0;
×
888
}
889

890
static int32_t mndTryRebuildConfigSdbRsp(SRpcMsg *pRsp) {
191,991✔
891
  mInfo("rebuild config sdb rsp");
191,991✔
892
  return 0;
191,991✔
893
}
894

895
// Helper function to create and commit a config object
896
static int32_t mndCreateAndCommitConfigObj(STrans *pTrans, const char *srcName, const char *cfgName, char *value,
×
897
                                           int32_t *lino) {
898
  int32_t     code = 0;
×
899
  SConfigObj *pTmp = taosMemoryMalloc(sizeof(SConfigObj));
×
900
  if (pTmp == NULL) {
×
901
    code = terrno;
×
902
    return code;
×
903
  }
904

905
  pTmp->dtype = CFG_DTYPE_INT32;
×
906
  tstrncpy(pTmp->name, cfgName, CFG_NAME_MAX_LEN);
×
907
  code = mndUpdateObj(pTmp, srcName, value);
×
908
  if (code != 0) {
×
909
    tFreeSConfigObj(pTmp);
×
910
    taosMemoryFree(pTmp);
×
911
    return code;
×
912
  }
913

914
  code = mndSetCreateConfigCommitLogs(pTrans, pTmp);
×
915
  tFreeSConfigObj(pTmp);
×
916
  taosMemoryFree(pTmp);
×
917
  return code;
×
918
}
919

920
// Helper function to handle syncTimeout related config updates
921
static int32_t mndHandleSyncTimeoutConfigs(STrans *pTrans, const char *srcName, const char *pValue, int32_t *lino) {
×
922
  int32_t code = 0;
×
923
  int32_t syncTimeout = 0;
×
924
  char    tmp[10] = {0};
×
925

926
  if (sscanf(pValue, "%d", &syncTimeout) != 1) {
×
927
    syncTimeout = 0;
×
928
  }
929

930
  int32_t baseTimeout = syncTimeout - syncTimeout / SYNC_TIMEOUT_DIVISOR;
×
931

932
  // arbSetAssignedTimeoutMs = syncTimeout
933
  sprintf(tmp, "%d", syncTimeout);
×
934
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "arbSetAssignedTimeoutMs", tmp, lino), lino, _OVER);
×
935

936
  // arbHeartBeatIntervalMs = syncTimeout / 4
937
  sprintf(tmp, "%d", syncTimeout / SYNC_TIMEOUT_DIVISOR);
×
938
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "arbHeartBeatIntervalMs", tmp, lino), lino, _OVER);
×
939

940
  // arbCheckSyncIntervalMs = syncTimeout / 4
941
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "arbCheckSyncIntervalMs", tmp, lino), lino, _OVER);
×
942

943
  // syncVnodeElectIntervalMs = (syncTimeout - syncTimeout / 4) / 2
944
  sprintf(tmp, "%d", baseTimeout / SYNC_TIMEOUT_ELECT_DIVISOR);
×
945
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncVnodeElectIntervalMs", tmp, lino), lino, _OVER);
×
946

947
  // syncMnodeElectIntervalMs = (syncTimeout - syncTimeout / 4) / 2
948
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncMnodeElectIntervalMs", tmp, lino), lino, _OVER);
×
949

950
  // statusTimeoutMs = (syncTimeout - syncTimeout / 4) / 2
951
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "statusTimeoutMs", tmp, lino), lino, _OVER);
×
952

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

957
  // syncVnodeHeartbeatIntervalMs = (syncTimeout - syncTimeout / 4) / 8
958
  sprintf(tmp, "%d", baseTimeout / SYNC_TIMEOUT_HB_DIVISOR);
×
959
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncVnodeHeartbeatIntervalMs", tmp, lino), lino, _OVER);
×
960

961
  // syncMnodeHeartbeatIntervalMs = (syncTimeout - syncTimeout / 4) / 8
962
  TAOS_CHECK_GOTO(mndCreateAndCommitConfigObj(pTrans, srcName, "syncMnodeHeartbeatIntervalMs", tmp, lino), lino, _OVER);
×
963

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

967
_OVER:
×
968
  return code;
×
969
}
970

971
// get int32_t value from 'SMCfgDnodeReq'
972
static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pMCfgReq, int32_t optLen, int32_t *pOutValue) {
×
973
  int32_t code = 0;
×
974
  if (' ' != pMCfgReq->config[optLen] && 0 != pMCfgReq->config[optLen]) {
×
975
    goto _err;
×
976
  }
977

978
  if (' ' == pMCfgReq->config[optLen]) {
×
979
    // 'key value'
980
    if (strlen(pMCfgReq->value) != 0) goto _err;
×
981
    *pOutValue = taosStr2Int32(pMCfgReq->config + optLen + 1, NULL, 10);
×
982
  } else {
983
    // 'key' 'value'
984
    if (strlen(pMCfgReq->value) == 0) goto _err;
×
985
    *pOutValue = taosStr2Int32(pMCfgReq->value, NULL, 10);
×
986
  }
987

988
  TAOS_RETURN(code);
×
989

990
_err:
×
991
  mError(" failed to set config since:%s", tstrerror(code));
×
992
  TAOS_RETURN(code);
×
993
}
994

995
static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype,
×
996
                                    int32_t tsmmConfigVersion) {
997
  int32_t     code = -1;
×
998
  int32_t     lino = -1;
×
999
  SConfigObj *pVersion = taosMemoryMalloc(sizeof(SConfigObj)), *pObj = taosMemoryMalloc(sizeof(SConfigObj));
×
1000
  if (pVersion == NULL || pObj == NULL) {
×
1001
    code = terrno;
×
1002
    goto _OVER;
×
1003
  }
1004
  tstrncpy(pVersion->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
×
1005
  pVersion->dtype = CFG_DTYPE_INT32;
×
1006
  pVersion->i32 = tsmmConfigVersion;
×
1007

1008
  pObj->dtype = dtype;
×
1009
  tstrncpy(pObj->name, name, CFG_NAME_MAX_LEN);
×
1010

1011
  TAOS_CHECK_GOTO(mndUpdateObj(pObj, name, pValue), &lino, _OVER);
×
1012
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, NULL, "update-config");
×
1013
  if (pTrans == NULL) {
×
1014
    code = terrno;
×
1015
    goto _OVER;
×
1016
  }
1017
  mInfo("trans:%d, used to update config:%s to value:%s", pTrans->id, name, pValue);
×
1018
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pVersion), &lino, _OVER);
×
1019
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pObj), &lino, _OVER);
×
1020

1021
  if (taosStrncasecmp(name, "syncTimeout", CFG_NAME_MAX_LEN) == 0) {
×
1022
    TAOS_CHECK_GOTO(mndHandleSyncTimeoutConfigs(pTrans, name, pValue, &lino), &lino, _OVER);
×
1023
  }
1024
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
×
1025
  code = 0;
×
1026
_OVER:
×
1027
  if (code != 0) {
×
1028
    mError("failed to update config:%s to value:%s, since %s", name, pValue, tstrerror(code));
×
1029
  }
1030
  mndTransDrop(pTrans);
×
1031
  tFreeSConfigObj(pVersion);
×
1032
  taosMemoryFree(pVersion);
×
1033
  tFreeSConfigObj(pObj);
×
1034
  taosMemoryFree(pObj);
×
1035
  return code;
×
1036
}
1037

1038
static int32_t mndConfigUpdateTransWithDnode(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype,
10,104✔
1039
                                             int32_t tsmmConfigVersion, int32_t dnodeId, SDCfgDnodeReq *pDcfgReq) {
1040
  int32_t     code = -1;
10,104✔
1041
  int32_t     lino = -1;
10,104✔
1042
  SConfigObj *pVersion = taosMemoryMalloc(sizeof(SConfigObj)), *pObj = taosMemoryMalloc(sizeof(SConfigObj));
10,104✔
1043
  if (pVersion == NULL || pObj == NULL) {
10,104✔
1044
    code = terrno;
×
1045
    goto _OVER;
×
1046
  }
1047
  tstrncpy(pVersion->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
10,104✔
1048
  pVersion->dtype = CFG_DTYPE_INT32;
10,104✔
1049
  pVersion->i32 = tsmmConfigVersion;
10,104✔
1050

1051
  pObj->dtype = dtype;
10,104✔
1052
  tstrncpy(pObj->name, name, CFG_NAME_MAX_LEN);
10,104✔
1053

1054
  TAOS_CHECK_GOTO(mndUpdateObj(pObj, name, pValue), &lino, _OVER);
10,104✔
1055
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "update-config-with-dnode");
10,104✔
1056
  if (pTrans == NULL) {
10,104✔
1057
    code = terrno;
×
1058
    goto _OVER;
×
1059
  }
1060
  mInfo("trans:%d, used to update config:%s to value:%s and send to dnode", pTrans->id, name, pValue);
10,104✔
1061

1062
  // Add prepare logs for SDB config updates (execute in PREPARE stage, before redo actions)
1063
  TAOS_CHECK_GOTO(mndSetCreateConfigPrepareLogs(pTrans, pVersion), &lino, _OVER);
10,104✔
1064
  TAOS_CHECK_GOTO(mndSetCreateConfigPrepareLogs(pTrans, pObj), &lino, _OVER);
10,104✔
1065

1066
  // Add commit logs for transaction persistence
1067
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pVersion), &lino, _OVER);
10,104✔
1068
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pObj), &lino, _OVER);
10,104✔
1069

1070
  if (taosStrncasecmp(name, "syncTimeout", CFG_NAME_MAX_LEN) == 0) {
10,104✔
1071
    TAOS_CHECK_GOTO(mndHandleSyncTimeoutConfigs(pTrans, name, pValue, &lino), &lino, _OVER);
×
1072
  }
1073

1074
  // Add redo actions to send config to dnodes
1075
  SSdb   *pSdb = pMnode->pSdb;
10,104✔
1076
  void   *pIter = NULL;
10,104✔
1077
  int64_t curMs = taosGetTimestampMs();
10,104✔
1078

1079
  while (1) {
10,920✔
1080
    SDnodeObj *pDnode = NULL;
21,024✔
1081
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
21,024✔
1082
    if (pIter == NULL) break;
21,024✔
1083

1084
    if (pDnode->id == dnodeId || dnodeId == -1 || dnodeId == 0) {
10,920✔
1085
      bool online = mndIsDnodeOnline(pDnode, curMs);
10,920✔
1086
      if (!online) {
10,920✔
UNCOV
1087
        mWarn("dnode:%d, is offline, still add to trans for retry", pDnode->id);
×
1088
      }
1089

1090
      code = mndBuildCfgDnodeRedoAction(pTrans, pDnode, pDcfgReq);
10,920✔
1091
      if (code != 0) {
10,920✔
1092
        mError("failed to build config redo action for dnode:%d, since %s", pDnode->id, tstrerror(code));
×
1093
        sdbCancelFetch(pMnode->pSdb, pIter);
×
1094
        sdbRelease(pMnode->pSdb, pDnode);
×
1095
        goto _OVER;
×
1096
      }
1097
    }
1098
    sdbRelease(pSdb, pDnode);
10,920✔
1099
  }
1100

1101
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
10,104✔
1102
  code = 0;
10,104✔
1103

1104
_OVER:
10,104✔
1105
  if (code != 0) {
10,104✔
1106
    mError("failed to update config:%s to value:%s and send to dnode, since %s", name, pValue, tstrerror(code));
×
1107
  }
1108
  mndTransDrop(pTrans);
10,104✔
1109
  tFreeSConfigObj(pVersion);
10,104✔
1110
  taosMemoryFree(pVersion);
10,104✔
1111
  tFreeSConfigObj(pObj);
10,104✔
1112
  taosMemoryFree(pObj);
10,104✔
1113
  return code;
10,104✔
1114
}
1115

1116
static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array) {
453,792✔
1117
  int32_t     code = 0;
453,792✔
1118
  SSdb       *pSdb = pMnode->pSdb;
453,792✔
1119
  void       *pIter = NULL;
453,792✔
1120
  SConfigObj *obj = NULL;
453,792✔
1121

1122
  while (1) {
51,278,496✔
1123
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
51,732,288✔
1124
    if (pIter == NULL) break;
51,732,288✔
1125
    if (obj == NULL) {
51,278,496✔
1126
      code = TSDB_CODE_OUT_OF_MEMORY;
×
1127
      goto _exit;
×
1128
    }
1129
    if (strcasecmp(obj->name, "tsmmConfigVersion") == 0) {
51,278,496✔
1130
      sdbRelease(pSdb, obj);
453,792✔
1131
      continue;
453,792✔
1132
    }
1133
    SConfigItem item = {0};
50,824,704✔
1134
    item.dtype = obj->dtype;
50,824,704✔
1135
    item.name = taosStrdup(obj->name);
50,824,704✔
1136
    if (item.name == NULL) {
50,824,704✔
1137
      code = terrno;
×
1138
      sdbCancelFetch(pSdb, pIter);
×
1139
      sdbRelease(pSdb, obj);
×
1140
      goto _exit;
×
1141
    }
1142
    switch (obj->dtype) {
50,824,704✔
1143
      case CFG_DTYPE_NONE:
×
1144
        break;
×
1145
      case CFG_DTYPE_BOOL:
11,798,592✔
1146
        item.bval = obj->bval;
11,798,592✔
1147
        break;
11,798,592✔
1148
      case CFG_DTYPE_INT32:
26,773,728✔
1149
        item.i32 = obj->i32;
26,773,728✔
1150
        break;
26,773,728✔
1151
      case CFG_DTYPE_INT64:
2,722,752✔
1152
        item.i64 = obj->i64;
2,722,752✔
1153
        break;
2,722,752✔
1154
      case CFG_DTYPE_FLOAT:
907,584✔
1155
      case CFG_DTYPE_DOUBLE:
1156
        item.fval = obj->fval;
907,584✔
1157
        break;
907,584✔
1158
      case CFG_DTYPE_STRING:
8,622,048✔
1159
      case CFG_DTYPE_DIR:
1160
      case CFG_DTYPE_LOCALE:
1161
      case CFG_DTYPE_CHARSET:
1162
      case CFG_DTYPE_TIMEZONE:
1163
        item.str = taosStrdup(obj->str);
8,622,048✔
1164
        if (item.str == NULL) {
8,622,048✔
1165
          sdbCancelFetch(pSdb, pIter);
×
1166
          sdbRelease(pSdb, obj);
×
1167
          code = terrno;
×
1168
          goto _exit;
×
1169
        }
1170
        break;
8,622,048✔
1171
    }
1172
    if (taosArrayPush(array, &item) == NULL) {
50,824,704✔
1173
      sdbCancelFetch(pSdb, pIter);
×
1174
      sdbRelease(pSdb, obj);
×
1175
      code = TSDB_CODE_OUT_OF_MEMORY;
×
1176
      goto _exit;
×
1177
      break;
1178
    }
1179
    sdbRelease(pSdb, obj);
50,824,704✔
1180
  }
1181
_exit:
453,792✔
1182
  if (code != 0) {
453,792✔
1183
    mError("failed to init config array from sdb, since %s", tstrerror(code));
×
1184
  }
1185
  return code;
453,792✔
1186
}
1187

1188
static void cfgArrayCleanUp(SArray *array) {
582,057✔
1189
  if (array == NULL) {
582,057✔
1190
    return;
×
1191
  }
1192

1193
  int32_t sz = taosArrayGetSize(array);
582,057✔
1194
  for (int32_t i = 0; i < sz; ++i) {
51,406,761✔
1195
    SConfigItem *item = taosArrayGet(array, i);
50,824,704✔
1196
    if (item->dtype == CFG_DTYPE_STRING || item->dtype == CFG_DTYPE_DIR || item->dtype == CFG_DTYPE_LOCALE ||
50,824,704✔
1197
        item->dtype == CFG_DTYPE_CHARSET || item->dtype == CFG_DTYPE_TIMEZONE) {
43,110,240✔
1198
      taosMemoryFreeClear(item->str);
8,622,048✔
1199
    }
1200
    taosMemoryFreeClear(item->name);
50,824,704✔
1201
  }
1202

1203
  taosArrayDestroy(array);
582,057✔
1204
}
1205

1206
static void cfgObjArrayCleanUp(SArray *array) {
384,564✔
1207
  if (array == NULL) {
384,564✔
1208
    return;
×
1209
  }
1210
  int32_t sz = taosArrayGetSize(array);
384,564✔
1211
  for (int32_t i = 0; i < sz; ++i) {
384,564✔
1212
    SConfigObj *obj = taosArrayGet(array, i);
×
1213
    tFreeSConfigObj(obj);
×
1214
  }
1215
  taosArrayDestroy(array);
384,564✔
1216
}
1217

1218
static SArray *initVariablesFromItems(SArray *pItems, const char* likePattern) {
12,376✔
1219
  if (pItems == NULL) {
12,376✔
1220
    return NULL;
×
1221
  }
1222

1223
  int32_t sz = taosArrayGetSize(pItems);
12,376✔
1224

1225
  SArray *pInfos = taosArrayInit(sz, sizeof(SVariablesInfo));
12,376✔
1226
  if (pInfos == NULL) {
12,376✔
1227
    mError("failed to init array while init variables from items, since %s", tstrerror(terrno));
×
1228
    return NULL;
×
1229
  }
1230
  for (int32_t i = 0; i < sz; ++i) {
1,398,488✔
1231
    SConfigItem   *pItem = taosArrayGet(pItems, i);
1,386,112✔
1232
    SVariablesInfo info = {0};
1,386,112✔
1233
    tstrncpy(info.name, pItem->name, sizeof(info.name));
1,386,112✔
1234
    if (likePattern != NULL && rawStrPatternMatch(pItem->name, likePattern) != TSDB_PATTERN_MATCH) {
1,386,112✔
1235
      continue;
289,166✔
1236
    }
1237

1238
    // init info value
1239
    switch (pItem->dtype) {
1,096,946✔
1240
      case CFG_DTYPE_NONE:
×
1241
        break;
×
1242
      case CFG_DTYPE_BOOL:
253,596✔
1243
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->bval);
253,596✔
1244
        break;
253,596✔
1245
      case CFG_DTYPE_INT32:
579,938✔
1246
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->i32);
579,938✔
1247
        break;
579,938✔
1248
      case CFG_DTYPE_INT64:
58,404✔
1249
        tsnprintf(info.value, sizeof(info.value), "%" PRId64, pItem->i64);
58,404✔
1250
        break;
58,404✔
1251
      case CFG_DTYPE_FLOAT:
19,468✔
1252
      case CFG_DTYPE_DOUBLE:
1253
        tsnprintf(info.value, sizeof(info.value), "%f", pItem->fval);
19,468✔
1254
        break;
19,468✔
1255
      case CFG_DTYPE_STRING:
185,540✔
1256
      case CFG_DTYPE_DIR:
1257
      case CFG_DTYPE_LOCALE:
1258
      case CFG_DTYPE_CHARSET:
1259
      case CFG_DTYPE_TIMEZONE:
1260
        tsnprintf(info.value, sizeof(info.value), "%s", pItem->str);
185,540✔
1261
        break;
185,540✔
1262
    }
1263

1264
    // init info scope
1265
    switch (pItem->scope) {
1,096,946✔
1266
      case CFG_SCOPE_SERVER:
882,716✔
1267
        tstrncpy(info.scope, "server", sizeof(info.scope));
882,716✔
1268
        break;
882,716✔
1269
      case CFG_SCOPE_CLIENT:
×
1270
        tstrncpy(info.scope, "client", sizeof(info.scope));
×
1271
        break;
×
1272
      case CFG_SCOPE_BOTH:
214,230✔
1273
        tstrncpy(info.scope, "both", sizeof(info.scope));
214,230✔
1274
        break;
214,230✔
1275
      default:
×
1276
        tstrncpy(info.scope, "unknown", sizeof(info.scope));
×
1277
        break;
×
1278
    }
1279
    // init info category
1280
    switch (pItem->category) {
1,096,946✔
1281
      case CFG_CATEGORY_GLOBAL:
1,096,946✔
1282
        tstrncpy(info.category, "global", sizeof(info.category));
1,096,946✔
1283
        break;
1,096,946✔
1284
      case CFG_CATEGORY_LOCAL:
×
1285
        tstrncpy(info.category, "local", sizeof(info.category));
×
1286
        break;
×
1287
      default:
×
1288
        tstrncpy(info.category, "unknown", sizeof(info.category));
×
1289
        break;
×
1290
    }
1291
    if (NULL == taosArrayPush(pInfos, &info)) {
1,096,946✔
1292
      mError("failed to push info to array while init variables from items,since %s", tstrerror(terrno));
×
1293
      taosArrayDestroy(pInfos);
×
1294
      return NULL;
×
1295
    }
1296
  }
1297

1298
  return pInfos;
12,376✔
1299
}
1300

1301
static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) {
12,376✔
1302
  SShowVariablesRsp rsp = {0};
12,376✔
1303
  int32_t           code = TSDB_CODE_SUCCESS;
12,376✔
1304
  SShowVariablesReq req = {0};
12,376✔
1305
  SArray           *array = NULL;
12,376✔
1306

1307
  code = tDeserializeSShowVariablesReq(pReq->pCont, pReq->contLen, &req);
12,376✔
1308
  if (code != 0) {
12,376✔
1309
    mError("failed to deserialize config req, since %s", terrstr());
×
1310
    goto _OVER;
×
1311
  }
1312

1313
  if ((code = mndCheckOperPrivilege(pReq->info.node, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_SHOW_VARIABLES)) != 0) {
12,376✔
1314
    goto _OVER;
×
1315
  }
1316

1317
  SVariablesInfo info = {0};
12,376✔
1318
  char          *likePattern = req.opType == OP_TYPE_LIKE ? req.val : NULL;
12,376✔
1319
  rsp.variables = initVariablesFromItems(taosGetGlobalCfg(tsCfg), likePattern);
12,376✔
1320
  if (rsp.variables == NULL) {
12,376✔
1321
    code = terrno;
×
1322
    goto _OVER;
×
1323
  }
1324
  int32_t rspLen = tSerializeSShowVariablesRsp(NULL, 0, &rsp);
12,376✔
1325
  void   *pRsp = rpcMallocCont(rspLen);
12,376✔
1326
  if (pRsp == NULL) {
12,376✔
1327
    code = terrno;
×
1328
    goto _OVER;
×
1329
  }
1330

1331
  if ((rspLen = tSerializeSShowVariablesRsp(pRsp, rspLen, &rsp)) <= 0) {
12,376✔
1332
    rpcFreeCont(pRsp);
×
1333
    code = rspLen;
×
1334
    goto _OVER;
×
1335
  }
1336

1337
  pReq->info.rspLen = rspLen;
12,376✔
1338
  pReq->info.rsp = pRsp;
12,376✔
1339
  code = 0;
12,376✔
1340

1341
_OVER:
12,376✔
1342

1343
  if (code != 0) {
12,376✔
1344
    mError("failed to get show variables info since %s", tstrerror(code));
×
1345
  }
1346
  tFreeSShowVariablesReq(&req);
12,376✔
1347
  tFreeSShowVariablesRsp(&rsp);
12,376✔
1348
  TAOS_RETURN(code);
12,376✔
1349
}
1350

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