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

taosdata / TDengine / #4917

07 Jan 2026 03:52PM UTC coverage: 65.42% (+0.02%) from 65.402%
#4917

push

travis-ci

web-flow
merge: from main to 3.0 branch #34204

31 of 34 new or added lines in 2 files covered. (91.18%)

819 existing lines in 129 files now uncovered.

202679 of 309814 relevant lines covered (65.42%)

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

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

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

92
  SEncoder encoder;
115,817,437✔
93
  tEncoderInit(&encoder, NULL, 0);
115,856,422✔
94
  if ((code = tEncodeSConfigObj(&encoder, obj)) < 0) {
115,856,422✔
95
    tEncoderClear(&encoder);
×
96
    TSDB_CHECK_CODE(code, lino, _over);
×
97
  }
98

99
  int32_t tlen = encoder.pos;
115,856,422✔
100
  tEncoderClear(&encoder);
115,856,422✔
101

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

106
  buf = taosMemoryMalloc(tlen);
115,856,422✔
107
  TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
115,856,422✔
108

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

115
  tEncoderClear(&encoder);
115,856,422✔
116

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

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

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

146
  code = sdbGetRawSoftVer(pRaw, &sver);
43,889,024✔
147
  TSDB_CHECK_CODE(code, lino, _over);
43,889,024✔
148

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

154
  pRow = sdbAllocRow(sizeof(SConfigObj));
43,889,024✔
155
  TSDB_CHECK_NULL(pRow, code, lino, _over, terrno);
43,889,024✔
156

157
  pObj = sdbGetRowObj(pRow);
43,889,024✔
158
  TSDB_CHECK_NULL(pObj, code, lino, _over, terrno);
43,889,024✔
159

160
  SDB_GET_INT32(pRaw, dataPos, &tlen, _over);
43,889,024✔
161

162
  buf = taosMemoryMalloc(tlen + 1);
43,889,024✔
163
  TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
43,889,024✔
164

165
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, _over);
43,889,024✔
166

167
  SDecoder decoder;
43,869,023✔
168
  tDecoderInit(&decoder, buf, tlen + 1);
43,889,024✔
169
  code = tDecodeSConfigObj(&decoder, pObj);
43,889,024✔
170
  tDecoderClear(&decoder);
43,889,024✔
171

172
  if (code < 0) {
43,889,024✔
173
    tFreeSConfigObj(pObj);
×
174
  }
175

176
_over:
43,889,024✔
177
  taosMemoryFreeClear(buf);
43,889,024✔
178

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

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

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

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

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

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

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

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

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

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

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

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

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

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

326
  for (int i = 0; i < sz; ++i) {
31,502,931✔
327
    SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
31,224,144✔
328
    SConfigObj   obj;
31,212,272✔
329
    if ((code = mndInitConfigObj(item, &obj)) != 0) {
31,224,144✔
330
      goto _OVER;
×
331
    }
332
    if ((code = mndSetCreateConfigCommitLogs(pTrans, &obj)) != 0) {
31,224,144✔
333
      mError("failed to init mnd config:%s, since %s", item->name, tstrerror(code));
×
334
      tFreeSConfigObj(&obj);
×
335
      goto _OVER;
×
336
    }
337
    tFreeSConfigObj(&obj);
31,224,144✔
338
  }
339
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
278,787✔
340

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

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

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

362
  mndGetMnodeEpSet(pMnode, &epSet);
184,588✔
363

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

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

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

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

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

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

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

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

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

494
  TAOS_RETURN(TSDB_CODE_SUCCESS);
184,534✔
495
}
496

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

504
  while (1) {
20,852,342✔
505
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
21,036,876✔
506
    if (pIter == NULL) break;
21,036,876✔
507
    if (obj == NULL) {
20,852,342✔
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) {
20,852,342✔
515
      sdbRelease(pSdb, obj);
184,534✔
516
      continue;
184,534✔
517
    }
518

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

529
    if (!existsInGlobal) {
20,667,808✔
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);
20,667,808✔
575
  }
576

577
  TAOS_RETURN(TSDB_CODE_SUCCESS);
184,534✔
578
}
579

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

584
  if (addSize == 0 && deleteSize == 0) {
184,534✔
585
    return TSDB_CODE_SUCCESS;
184,534✔
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) {
75,276✔
633
  int32_t code = 0;
75,276✔
634
  char   *p = pMCfgReq->config;
75,276✔
635
  while (*p) {
1,086,091✔
636
    if (*p == ' ') {
1,041,046✔
637
      break;
30,231✔
638
    }
639
    p++;
1,010,815✔
640
  }
641

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

646
  if (' ' == pMCfgReq->config[optLen]) {
75,276✔
647
    // 'key value'
648
    if (strlen(pMCfgReq->value) != 0) goto _err;
30,231✔
649
    tstrncpy(pDCfgReq->value, p + 1, sizeof(pDCfgReq->value));
30,231✔
650
  } else {
651
    // 'key' 'value'
652
    if (strlen(pMCfgReq->value) == 0) goto _err;
45,045✔
653
    tstrncpy(pDCfgReq->value, pMCfgReq->value, sizeof(pDCfgReq->value));
44,471✔
654
  }
655

656
  TAOS_RETURN(code);
74,702✔
657

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

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

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

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

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

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

697
  return code;
9,843✔
698
}
699

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

705
  int64_t curMs = taosGetTimestampMs();
53,067✔
706

707
  while (1) {
157,137✔
708
    SDnodeObj *pDnode = NULL;
210,204✔
709
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
210,204✔
710
    if (pIter == NULL) break;
210,204✔
711

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

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

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

761
  if (code == -1) {
51,141✔
762
    code = TSDB_CODE_MND_DNODE_NOT_EXIST;
560✔
763
  }
764
  TAOS_RETURN(code);
51,141✔
765
}
766

767
static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
76,502✔
768
  int32_t       code = 0;
76,502✔
769
  int32_t       lino = -1;
76,502✔
770
  SMnode       *pMnode = pReq->info.node;
76,502✔
771
  SMCfgDnodeReq cfgReq = {0};
76,502✔
772
  int64_t       tss = taosGetTimestampMs();
76,502✔
773
  SConfigObj   *vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
76,502✔
774
  if (vObj == NULL) {
76,502✔
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));
76,502✔
781
  int8_t updateWhiteList = 0;
76,502✔
782
  mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value);
76,502✔
783
  if ((code = mndCheckOperPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_CONFIG_DNODE)) != 0) {
76,502✔
784
    goto _err_out;
1,029✔
785
  }
786

787
  SDCfgDnodeReq dcfgReq = {0};
75,473✔
788
  if (strcasecmp(cfgReq.config, "resetlog") == 0) {
75,473✔
789
    tstrncpy(dcfgReq.config, "resetlog", 9);
197✔
790
    goto _send_req;
197✔
791
#ifdef TD_ENTERPRISE
792
  } else if (strncasecmp(cfgReq.config, "ssblocksize", 12) == 0) {
75,276✔
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);
75,276✔
812
    if (strlen(dcfgReq.config) > TSDB_DNODE_CONFIG_LEN) {
74,702✔
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) {
74,702✔
818
      updateWhiteList = 1;
228✔
819
    }
820

821
    CfgAlterType alterType = (cfgReq.dnodeId == 0 || cfgReq.dnodeId == -1) ? CFG_ALTER_ALL_DNODES : CFG_ALTER_DNODE;
74,702✔
822
    TAOS_CHECK_GOTO(cfgCheckRangeForDynUpdate(taosGetCfg(), dcfgReq.config, dcfgReq.value, true, alterType), &lino,
74,702✔
823
                    _err_out);
824
  }
825
  SConfigItem *pItem = cfgGetItem(taosGetCfg(), dcfgReq.config);
61,949✔
826
  // Update config in sdb.
827
  if (pItem == NULL) {
61,949✔
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) {
61,949✔
835
    char obj[50] = {0};
61,949✔
836
    (void)tsnprintf(obj, sizeof(obj), "%d", cfgReq.dnodeId);
61,949✔
837
    int64_t tse = taosGetTimestampMs();
61,949✔
838
    double  duration = (double)(tse - tss);
61,949✔
839
    duration = duration / 1000;
61,949✔
840
    auditRecord(pReq, pMnode->clusterId, "alterDnode", obj, "", cfgReq.sql, cfgReq.sqlLen, duration, 0);
61,949✔
841
  }
842

843
  dcfgReq.version = vObj->i32 + 1;
61,949✔
844

845
  if (pItem->category == CFG_CATEGORY_GLOBAL) {
61,949✔
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,
9,079✔
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;
52,870✔
853
  }
854

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

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

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

878
_err_out:
16,842✔
879
  mError("failed to process config dnode req, since %s", tstrerror(code));
16,842✔
880
  tFreeSMCfgDnodeReq(&cfgReq);
16,842✔
881
  sdbRelease(pMnode->pSdb, vObj);
16,842✔
882
  TAOS_RETURN(code);
16,842✔
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) {
184,487✔
891
  mInfo("rebuild config sdb rsp");
184,487✔
892
  return 0;
184,487✔
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,
9,079✔
1039
                                             int32_t tsmmConfigVersion, int32_t dnodeId, SDCfgDnodeReq *pDcfgReq) {
1040
  int32_t     code = -1;
9,079✔
1041
  int32_t     lino = -1;
9,079✔
1042
  SConfigObj *pVersion = taosMemoryMalloc(sizeof(SConfigObj)), *pObj = taosMemoryMalloc(sizeof(SConfigObj));
9,079✔
1043
  if (pVersion == NULL || pObj == NULL) {
9,079✔
1044
    code = terrno;
×
1045
    goto _OVER;
×
1046
  }
1047
  tstrncpy(pVersion->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
9,079✔
1048
  pVersion->dtype = CFG_DTYPE_INT32;
9,079✔
1049
  pVersion->i32 = tsmmConfigVersion;
9,079✔
1050

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

1054
  TAOS_CHECK_GOTO(mndUpdateObj(pObj, name, pValue), &lino, _OVER);
9,079✔
1055
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "update-config-with-dnode");
9,079✔
1056
  if (pTrans == NULL) {
9,079✔
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);
9,079✔
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);
9,079✔
1064
  TAOS_CHECK_GOTO(mndSetCreateConfigPrepareLogs(pTrans, pObj), &lino, _OVER);
9,079✔
1065

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

1070
  if (taosStrncasecmp(name, "syncTimeout", CFG_NAME_MAX_LEN) == 0) {
9,079✔
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;
9,079✔
1076
  void   *pIter = NULL;
9,079✔
1077
  int64_t curMs = taosGetTimestampMs();
9,079✔
1078

1079
  while (1) {
9,843✔
1080
    SDnodeObj *pDnode = NULL;
18,922✔
1081
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
18,922✔
1082
    if (pIter == NULL) break;
18,922✔
1083

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

1090
      code = mndBuildCfgDnodeRedoAction(pTrans, pDnode, pDcfgReq);
9,843✔
1091
      if (code != 0) {
9,843✔
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);
9,843✔
1099
  }
1100

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

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

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

1122
  while (1) {
47,716,510✔
1123
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
48,138,780✔
1124
    if (pIter == NULL) break;
48,138,780✔
1125
    if (obj == NULL) {
47,716,510✔
1126
      code = TSDB_CODE_OUT_OF_MEMORY;
×
1127
      goto _exit;
×
1128
    }
1129
    if (strcasecmp(obj->name, "tsmmConfigVersion") == 0) {
47,716,510✔
1130
      sdbRelease(pSdb, obj);
422,270✔
1131
      continue;
422,270✔
1132
    }
1133
    SConfigItem item = {0};
47,294,240✔
1134
    item.dtype = obj->dtype;
47,294,240✔
1135
    item.name = taosStrdup(obj->name);
47,294,240✔
1136
    if (item.name == NULL) {
47,294,240✔
1137
      code = terrno;
×
1138
      sdbCancelFetch(pSdb, pIter);
×
1139
      sdbRelease(pSdb, obj);
×
1140
      goto _exit;
×
1141
    }
1142
    switch (obj->dtype) {
47,294,240✔
1143
      case CFG_DTYPE_NONE:
×
1144
        break;
×
1145
      case CFG_DTYPE_BOOL:
10,979,020✔
1146
        item.bval = obj->bval;
10,979,020✔
1147
        break;
10,979,020✔
1148
      case CFG_DTYPE_INT32:
24,913,930✔
1149
        item.i32 = obj->i32;
24,913,930✔
1150
        break;
24,913,930✔
1151
      case CFG_DTYPE_INT64:
2,533,620✔
1152
        item.i64 = obj->i64;
2,533,620✔
1153
        break;
2,533,620✔
1154
      case CFG_DTYPE_FLOAT:
844,540✔
1155
      case CFG_DTYPE_DOUBLE:
1156
        item.fval = obj->fval;
844,540✔
1157
        break;
844,540✔
1158
      case CFG_DTYPE_STRING:
8,023,130✔
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,023,130✔
1164
        if (item.str == NULL) {
8,023,130✔
1165
          sdbCancelFetch(pSdb, pIter);
×
1166
          sdbRelease(pSdb, obj);
×
1167
          code = terrno;
×
1168
          goto _exit;
×
1169
        }
1170
        break;
8,023,130✔
1171
    }
1172
    if (taosArrayPush(array, &item) == NULL) {
47,294,240✔
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);
47,294,240✔
1180
  }
1181
_exit:
422,270✔
1182
  if (code != 0) {
422,270✔
1183
    mError("failed to init config array from sdb, since %s", tstrerror(code));
×
1184
  }
1185
  return code;
422,270✔
1186
}
1187

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

1193
  int32_t sz = taosArrayGetSize(array);
546,313✔
1194
  for (int32_t i = 0; i < sz; ++i) {
47,840,553✔
1195
    SConfigItem *item = taosArrayGet(array, i);
47,294,240✔
1196
    if (item->dtype == CFG_DTYPE_STRING || item->dtype == CFG_DTYPE_DIR || item->dtype == CFG_DTYPE_LOCALE ||
47,294,240✔
1197
        item->dtype == CFG_DTYPE_CHARSET || item->dtype == CFG_DTYPE_TIMEZONE) {
40,115,650✔
1198
      taosMemoryFreeClear(item->str);
8,023,130✔
1199
    }
1200
    taosMemoryFreeClear(item->name);
47,294,240✔
1201
  }
1202

1203
  taosArrayDestroy(array);
546,313✔
1204
}
1205

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

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

1223
  int32_t sz = taosArrayGetSize(pItems);
7,743✔
1224

1225
  SArray *pInfos = taosArrayInit(sz, sizeof(SVariablesInfo));
7,743✔
1226
  if (pInfos == NULL) {
7,743✔
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) {
874,959✔
1231
    SConfigItem   *pItem = taosArrayGet(pItems, i);
867,216✔
1232
    SVariablesInfo info = {0};
867,216✔
1233
    tstrncpy(info.name, pItem->name, sizeof(info.name));
867,216✔
1234
    if (likePattern != NULL && rawStrPatternMatch(pItem->name, likePattern) != TSDB_PATTERN_MATCH) {
867,216✔
1235
      continue;
247,562✔
1236
    }
1237

1238
    // init info value
1239
    switch (pItem->dtype) {
619,654✔
1240
      case CFG_DTYPE_NONE:
×
1241
        break;
×
1242
      case CFG_DTYPE_BOOL:
142,946✔
1243
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->bval);
142,946✔
1244
        break;
142,946✔
1245
      case CFG_DTYPE_INT32:
328,219✔
1246
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->i32);
328,219✔
1247
        break;
328,219✔
1248
      case CFG_DTYPE_INT64:
32,886✔
1249
        tsnprintf(info.value, sizeof(info.value), "%" PRId64, pItem->i64);
32,886✔
1250
        break;
32,886✔
1251
      case CFG_DTYPE_FLOAT:
10,962✔
1252
      case CFG_DTYPE_DOUBLE:
1253
        tsnprintf(info.value, sizeof(info.value), "%f", pItem->fval);
10,962✔
1254
        break;
10,962✔
1255
      case CFG_DTYPE_STRING:
104,641✔
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);
104,641✔
1261
        break;
104,641✔
1262
    }
1263

1264
    // init info scope
1265
    switch (pItem->scope) {
619,654✔
1266
      case CFG_SCOPE_SERVER:
499,010✔
1267
        tstrncpy(info.scope, "server", sizeof(info.scope));
499,010✔
1268
        break;
499,010✔
1269
      case CFG_SCOPE_CLIENT:
×
1270
        tstrncpy(info.scope, "client", sizeof(info.scope));
×
1271
        break;
×
1272
      case CFG_SCOPE_BOTH:
120,644✔
1273
        tstrncpy(info.scope, "both", sizeof(info.scope));
120,644✔
1274
        break;
120,644✔
1275
      default:
×
1276
        tstrncpy(info.scope, "unknown", sizeof(info.scope));
×
1277
        break;
×
1278
    }
1279
    // init info category
1280
    switch (pItem->category) {
619,654✔
1281
      case CFG_CATEGORY_GLOBAL:
619,654✔
1282
        tstrncpy(info.category, "global", sizeof(info.category));
619,654✔
1283
        break;
619,654✔
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)) {
619,654✔
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;
7,743✔
1299
}
1300

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

1307
  code = tDeserializeSShowVariablesReq(pReq->pCont, pReq->contLen, &req);
7,743✔
1308
  if (code != 0) {
7,743✔
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) {
7,743✔
1314
    goto _OVER;
×
1315
  }
1316

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

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

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

1341
_OVER:
7,743✔
1342

1343
  if (code != 0) {
7,743✔
1344
    mError("failed to get show variables info since %s", tstrerror(code));
×
1345
  }
1346
  tFreeSShowVariablesReq(&req);
7,743✔
1347
  tFreeSShowVariablesRsp(&rsp);
7,743✔
1348
  TAOS_RETURN(code);
7,743✔
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