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

taosdata / TDengine / #3629

04 Mar 2025 01:45PM UTC coverage: 63.692% (-0.1%) from 63.79%
#3629

push

travis-ci

web-flow
Merge pull request #30007 from taosdata/revert-29951-docs/update-exception-handling-strategy

Revert "docs: update exception handling strategy"

149369 of 300378 branches covered (49.73%)

Branch coverage included in aggregate %.

233614 of 300930 relevant lines covered (77.63%)

18792670.99 hits per line

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

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

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

31
static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pInMCfgReq, int32_t optLen, int32_t *pOutValue);
32
static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq);
33
static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq);
34
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp);
35
static int32_t mndProcessConfigReq(SRpcMsg *pReq);
36
static int32_t mndInitWriteCfg(SMnode *pMnode);
37
static int32_t mndSendRebuildReq(SMnode *pMnode);
38
static int32_t mndTryRebuildConfigSdbRsp(SRpcMsg *pRsp);
39
static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array);
40
static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq);
41
static void    cfgArrayCleanUp(SArray *array);
42
static void    cfgObjArrayCleanUp(SArray *array);
43
int32_t        compareSConfigItemArrays(SMnode *pMnode, const SArray *dArray, SArray *diffArray);
44

45
static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype,
46
                                    int32_t tsmmConfigVersion);
47

48
int32_t mndSetCreateConfigCommitLogs(STrans *pTrans, SConfigObj *obj);
49

50
int32_t mndInitConfig(SMnode *pMnode) {
1,858✔
51
  int32_t   code = 0;
1,858✔
52
  SSdbTable table = {.sdbType = SDB_CFG,
1,858✔
53
                     .keyType = SDB_KEY_BINARY,
54
                     .encodeFp = (SdbEncodeFp)mnCfgActionEncode,
55
                     .decodeFp = (SdbDecodeFp)mndCfgActionDecode,
56
                     .insertFp = (SdbInsertFp)mndCfgActionInsert,
57
                     .updateFp = (SdbUpdateFp)mndCfgActionUpdate,
58
                     .deleteFp = (SdbDeleteFp)mndCfgActionDelete,
59
                     .deployFp = (SdbDeployFp)mndCfgActionDeploy,
60
                     .afterRestoredFp = (SdbAfterRestoredFp)mndCfgActionAfterRestored};
61

62
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG, mndProcessConfigReq);
1,858✔
63
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeReq);
1,858✔
64
  mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndProcessConfigDnodeRsp);
1,858✔
65
  mndSetMsgHandle(pMnode, TDMT_MND_SHOW_VARIABLES, mndProcessShowVariablesReq);
1,858✔
66
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_SDB, mndTryRebuildConfigSdb);
1,858✔
67
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_SDB_RSP, mndTryRebuildConfigSdbRsp);
1,858✔
68

69
  return sdbSetTable(pMnode->pSdb, table);
1,858✔
70
}
71

72
SSdbRaw *mnCfgActionEncode(SConfigObj *obj) {
417,941✔
73
  int32_t  code = 0;
417,941✔
74
  int32_t  lino = 0;
417,941✔
75
  void    *buf = NULL;
417,941✔
76
  SSdbRaw *pRaw = NULL;
417,941✔
77

78
  SEncoder encoder;
79
  tEncoderInit(&encoder, NULL, 0);
417,941✔
80
  if ((code = tEncodeSConfigObj(&encoder, obj)) < 0) {
417,941!
81
    tEncoderClear(&encoder);
×
82
    TSDB_CHECK_CODE(code, lino, _over);
×
83
  }
84

85
  int32_t tlen = encoder.pos;
417,941✔
86
  tEncoderClear(&encoder);
417,941✔
87

88
  int32_t size = sizeof(int32_t) + tlen;
417,941✔
89
  pRaw = sdbAllocRaw(SDB_CFG, CFG_VER_NUMBER, size);
417,941✔
90
  TSDB_CHECK_NULL(pRaw, code, lino, _over, terrno);
417,941!
91

92
  buf = taosMemoryMalloc(tlen);
417,941!
93
  TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
417,941!
94

95
  tEncoderInit(&encoder, buf, tlen);
417,941✔
96
  if ((code = tEncodeSConfigObj(&encoder, obj)) < 0) {
417,941!
97
    tEncoderClear(&encoder);
×
98
    TSDB_CHECK_CODE(code, lino, _over);
×
99
  }
100

101
  tEncoderClear(&encoder);
417,941✔
102

103
  int32_t dataPos = 0;
417,941✔
104
  SDB_SET_INT32(pRaw, dataPos, tlen, _over);
417,941!
105
  SDB_SET_BINARY(pRaw, dataPos, buf, tlen, _over);
417,941!
106
  SDB_SET_DATALEN(pRaw, dataPos, _over);
417,941!
107

108
_over:
417,941✔
109
  taosMemoryFreeClear(buf);
417,941!
110
  if (code != TSDB_CODE_SUCCESS) {
417,941!
111
    mError("cfg:%s, failed to encode to raw:%p at line:%d since %s", obj->name, pRaw, lino, tstrerror(code));
×
112
    sdbFreeRaw(pRaw);
×
113
    terrno = code;
×
114
    return NULL;
×
115
  }
116

117
  terrno = 0;
417,941✔
118
  mTrace("cfg:%s, encode to raw:%p, row:%p", obj->name, pRaw, obj);
417,941✔
119
  return pRaw;
417,941✔
120
}
121

122
SSdbRow *mndCfgActionDecode(SSdbRaw *pRaw) {
165,124✔
123
  int32_t     code = 0;
165,124✔
124
  int32_t     lino = 0;
165,124✔
125
  SSdbRow    *pRow = NULL;
165,124✔
126
  SConfigObj *pObj = NULL;
165,124✔
127
  void       *buf = NULL;
165,124✔
128
  int8_t      sver = 0;
165,124✔
129
  int32_t     tlen;
130
  int32_t     dataPos = 0;
165,124✔
131

132
  code = sdbGetRawSoftVer(pRaw, &sver);
165,124✔
133
  TSDB_CHECK_CODE(code, lino, _over);
165,124!
134

135
  if (sver != CFG_VER_NUMBER) {
165,124!
136
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
137
    goto _over;
×
138
  }
139

140
  pRow = sdbAllocRow(sizeof(SConfigObj));
165,124✔
141
  TSDB_CHECK_NULL(pRow, code, lino, _over, terrno);
165,124!
142

143
  pObj = sdbGetRowObj(pRow);
165,124✔
144
  TSDB_CHECK_NULL(pObj, code, lino, _over, terrno);
165,124!
145

146
  SDB_GET_INT32(pRaw, dataPos, &tlen, _over);
165,124!
147

148
  buf = taosMemoryMalloc(tlen + 1);
165,124!
149
  TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
165,124!
150

151
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, _over);
165,124!
152

153
  SDecoder decoder;
154
  tDecoderInit(&decoder, buf, tlen + 1);
165,124✔
155
  code = tDecodeSConfigObj(&decoder, pObj);
165,124✔
156
  tDecoderClear(&decoder);
165,124✔
157

158
  if (code < 0) {
165,124!
159
    tFreeSConfigObj(pObj);
×
160
  }
161

162
_over:
165,124✔
163
  taosMemoryFreeClear(buf);
165,124!
164

165
  if (code != TSDB_CODE_SUCCESS) {
165,124!
166
    mError("cfg:%s, failed to decode from raw:%p since %s at:%d", pObj->name, pRaw, tstrerror(code), lino);
×
167
    taosMemoryFreeClear(pRow);
×
168
    terrno = code;
×
169
    return NULL;
×
170
  } else {
171
    mTrace("config:%s, decode from raw:%p, row:%p", pObj->name, pRaw, pObj);
165,124✔
172
    terrno = 0;
165,124✔
173
    return pRow;
165,124✔
174
  }
175
}
176

177
static int32_t mndCfgActionInsert(SSdb *pSdb, SConfigObj *obj) {
162,809✔
178
  mTrace("cfg:%s, perform insert action, row:%p", obj->name, obj);
162,809✔
179
  return 0;
162,809✔
180
}
181

182
static int32_t mndCfgActionDelete(SSdb *pSdb, SConfigObj *obj) {
165,036✔
183
  mTrace("cfg:%s, perform delete action, row:%p", obj->name, obj);
165,036✔
184
  tFreeSConfigObj(obj);
165,036✔
185
  return 0;
165,036✔
186
}
187

188
static int32_t mndCfgActionUpdate(SSdb *pSdb, SConfigObj *pOld, SConfigObj *pNew) {
2,315✔
189
  mTrace("cfg:%s, perform update action, old row:%p new row:%p", pOld->name, pOld, pNew);
2,315!
190
  switch (pNew->dtype) {
2,315!
191
    case CFG_DTYPE_NONE:
×
192
      break;
×
193
    case CFG_DTYPE_BOOL:
64✔
194
      pOld->bval = pNew->bval;
64✔
195
      break;
64✔
196
    case CFG_DTYPE_INT32:
1,471✔
197
      pOld->i32 = pNew->i32;
1,471✔
198
      break;
1,471✔
199
    case CFG_DTYPE_INT64:
20✔
200
      pOld->i64 = pNew->i64;
20✔
201
      break;
20✔
202
    case CFG_DTYPE_FLOAT:
8✔
203
    case CFG_DTYPE_DOUBLE:
204
      pOld->fval = pNew->fval;
8✔
205
      break;
8✔
206
    case CFG_DTYPE_STRING:
752✔
207
    case CFG_DTYPE_DIR:
208
    case CFG_DTYPE_LOCALE:
209
    case CFG_DTYPE_CHARSET:
210
    case CFG_DTYPE_TIMEZONE:
211
      taosMemoryFree(pOld->str);
752!
212
      pOld->str = taosStrdup(pNew->str);
752!
213
      if (pOld->str == NULL) {
752!
214
        return terrno;
×
215
      }
216
      break;
752✔
217
  }
218
  return TSDB_CODE_SUCCESS;
2,315✔
219
}
220

221
static int32_t mndCfgActionDeploy(SMnode *pMnode) { return mndInitWriteCfg(pMnode); }
1,364✔
222

223
static int32_t mndCfgActionAfterRestored(SMnode *pMnode) { return mndSendRebuildReq(pMnode); }
535✔
224

225
static int32_t mndProcessConfigReq(SRpcMsg *pReq) {
2,240✔
226
  SMnode    *pMnode = pReq->info.node;
2,240✔
227
  SConfigReq configReq = {0};
2,240✔
228
  int32_t    code = TSDB_CODE_SUCCESS;
2,240✔
229
  SArray    *array = NULL;
2,240✔
230

231
  code = tDeserializeSConfigReq(pReq->pCont, pReq->contLen, &configReq);
2,240✔
232
  if (code != 0) {
2,240!
233
    mError("failed to deserialize config req, since %s", terrstr());
×
234
    goto _OVER;
×
235
  }
236

237
  SConfigObj *vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
2,240✔
238
  if (vObj == NULL) {
2,240!
239
    mInfo("failed to acquire mnd config version, since %s", terrstr());
×
240
    goto _OVER;
×
241
  }
242

243
  array = taosArrayInit(16, sizeof(SConfigItem));
2,240✔
244
  if (array == NULL) {
2,240!
245
    code = TSDB_CODE_OUT_OF_MEMORY;
×
246
    goto _OVER;
×
247
  }
248
  SConfigRsp configRsp = {0};
2,240✔
249
  configRsp.forceReadConfig = configReq.forceReadConfig;
2,240✔
250

251
  configRsp.cver = vObj->i32;
2,240✔
252
  if (configRsp.forceReadConfig) {
2,240!
253
    // compare config array from configReq with current config array
254
    code = compareSConfigItemArrays(pMnode, configReq.array, array);
×
255
    if (code != TSDB_CODE_SUCCESS) {
×
256
      mError("failed to compare config array, since %s", tstrerror(code));
×
257
      goto _OVER;
×
258
    }
259
    if (taosArrayGetSize(array) > 0) {
×
260
      configRsp.array = array;
×
261
    } else {
262
      configRsp.isConifgVerified = 1;
×
263
    }
264
  } else {
265
    if (configReq.cver == vObj->i32) {
2,240✔
266
      configRsp.isVersionVerified = 1;
417✔
267
    } else {
268
      code = initConfigArrayFromSdb(pMnode, array);
1,823✔
269
      if (code != 0) {
1,823!
270
        mError("failed to init config array from sdb, since %s", terrstr());
×
271
        goto _OVER;
×
272
      }
273
      configRsp.array = array;
1,823✔
274
    }
275
  }
276

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

296
_OVER:
2,240✔
297
  if (code != 0) {
2,240!
298
    mError("failed to process config req, since %s", tstrerror(code));
×
299
  }
300
  sdbRelease(pMnode->pSdb, vObj);
2,240✔
301
  cfgArrayCleanUp(array);
2,240✔
302

303
  tFreeSConfigReq(&configReq);
2,240✔
304
  return code;
2,240✔
305
}
306

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

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

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

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

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

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

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

364
  mndGetMnodeEpSet(pMnode, &epSet);
535✔
365

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

373
static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq) {
535✔
374
  SMnode *pMnode = pReq->info.node;
535✔
375
  if (!mndIsLeader(pMnode)) {
535!
376
    return TSDB_CODE_SUCCESS;
×
377
  }
378
  int32_t     code = 0;
535✔
379
  int32_t     sz = -1;
535✔
380
  STrans     *pTrans = NULL;
535✔
381
  SConfigObj *vObj = NULL;
535✔
382
  SArray     *addArray = NULL;
535✔
383

384
  vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
535✔
385
  if (vObj == NULL) {
535!
386
    if ((code = mndInitWriteCfg(pMnode)) < 0) goto _exit;
×
387
    mInfo("failed to acquire mnd config version, try to rebuild config in sdb.");
×
388
  } else {
389
    sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
535✔
390
    addArray = taosArrayInit(4, sizeof(SConfigObj));
535✔
391
    for (int i = 0; i < sz; ++i) {
47,080✔
392
      SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
46,545✔
393
      SConfigObj  *obj = sdbAcquire(pMnode->pSdb, SDB_CFG, item->name);
46,545✔
394
      if (obj == NULL) {
46,545!
395
        mInfo("config:%s, not exist in sdb, try to add it", item->name);
×
396
        SConfigObj newObj;
397
        if ((code = mndInitConfigObj(item, &newObj)) != 0) goto _exit;
×
398
        if (NULL == taosArrayPush(addArray, &newObj)) {
×
399
          code = terrno;
×
400
          goto _exit;
×
401
        }
402
      } else {
403
        sdbRelease(pMnode->pSdb, obj);
46,545✔
404
      }
405
    }
406
    int32_t addSize = taosArrayGetSize(addArray);
535✔
407
    if (addSize > 0) {
535!
408
      pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "add-config");
×
409
      if (pTrans == NULL) {
×
410
        code = terrno;
×
411
        goto _exit;
×
412
      }
413
      for (int i = 0; i < addSize; ++i) {
×
414
        SConfigObj *AddObj = taosArrayGet(addArray, i);
×
415
        if ((code = mndSetCreateConfigCommitLogs(pTrans, AddObj)) != 0) goto _exit;
×
416
      }
417
      if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _exit;
×
418
      mInfo("add new config to sdb, nums:%d", addSize);
×
419
    }
420
  }
421
_exit:
535✔
422
  if (code != 0) {
535!
423
    mError("failed to try rebuild config in sdb, since %s", tstrerror(code));
×
424
  }
425
  sdbRelease(pMnode->pSdb, vObj);
535✔
426
  cfgObjArrayCleanUp(addArray);
535✔
427
  mndTransDrop(pTrans);
535✔
428
  TAOS_RETURN(code);
535✔
429
}
430

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

443
static int32_t mndMCfg2DCfg(SMCfgDnodeReq *pMCfgReq, SDCfgDnodeReq *pDCfgReq) {
1,116✔
444
  int32_t code = 0;
1,116✔
445
  char   *p = pMCfgReq->config;
1,116✔
446
  while (*p) {
15,467✔
447
    if (*p == ' ') {
14,540✔
448
      break;
189✔
449
    }
450
    p++;
14,351✔
451
  }
452

453
  size_t optLen = p - pMCfgReq->config;
1,116✔
454
  tstrncpy(pDCfgReq->config, pMCfgReq->config, sizeof(pDCfgReq->config));
1,116✔
455
  pDCfgReq->config[optLen] = 0;
1,116✔
456

457
  if (' ' == pMCfgReq->config[optLen]) {
1,116✔
458
    // 'key value'
459
    if (strlen(pMCfgReq->value) != 0) goto _err;
189!
460
    tstrncpy(pDCfgReq->value, p + 1, sizeof(pDCfgReq->value));
189✔
461
  } else {
462
    // 'key' 'value'
463
    if (strlen(pMCfgReq->value) == 0) goto _err;
927✔
464
    tstrncpy(pDCfgReq->value, pMCfgReq->value, sizeof(pDCfgReq->value));
926✔
465
  }
466

467
  TAOS_RETURN(code);
1,115✔
468

469
_err:
1✔
470
  mError("dnode:%d, failed to config since invalid conf:%s", pMCfgReq->dnodeId, pMCfgReq->config);
1!
471
  code = TSDB_CODE_INVALID_CFG;
1✔
472
  TAOS_RETURN(code);
1✔
473
}
474

475
static int32_t mndSendCfgDnodeReq(SMnode *pMnode, int32_t dnodeId, SDCfgDnodeReq *pDcfgReq) {
1,104✔
476
  int32_t code = -1;
1,104✔
477
  SSdb   *pSdb = pMnode->pSdb;
1,104✔
478
  void   *pIter = NULL;
1,104✔
479

480
  int64_t curMs = taosGetTimestampMs();
1,104✔
481

482
  while (1) {
1,425✔
483
    SDnodeObj *pDnode = NULL;
2,529✔
484
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
2,529✔
485
    if (pIter == NULL) break;
2,529✔
486

487
    if (pDnode->id == dnodeId || dnodeId == -1 || dnodeId == 0) {
1,425!
488
      bool online = mndIsDnodeOnline(pDnode, curMs);
1,404✔
489
      if (!online) {
1,404✔
490
        mWarn("dnode:%d, is offline, skip to send config req", pDnode->id);
1!
491
        continue;
1✔
492
      }
493
      SEpSet  epSet = mndGetDnodeEpset(pDnode);
1,403✔
494
      int32_t bufLen = tSerializeSDCfgDnodeReq(NULL, 0, pDcfgReq);
1,403✔
495
      void   *pBuf = rpcMallocCont(bufLen);
1,403✔
496

497
      if (pBuf == NULL) {
1,403!
498
        sdbCancelFetch(pMnode->pSdb, pIter);
×
499
        sdbRelease(pMnode->pSdb, pDnode);
×
500
        code = TSDB_CODE_OUT_OF_MEMORY;
×
501
        return code;
×
502
      }
503

504
      if ((bufLen = tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq)) <= 0) {
1,403!
505
        sdbCancelFetch(pMnode->pSdb, pIter);
×
506
        sdbRelease(pMnode->pSdb, pDnode);
×
507
        code = bufLen;
×
508
        rpcFreeCont(pBuf);
×
509
        return code;
×
510
      }
511

512
      mInfo("dnode:%d, send config req to dnode, config:%s value:%s", pDnode->id, pDcfgReq->config, pDcfgReq->value);
1,403!
513
      SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen};
1,403✔
514
      SRpcMsg rpcRsp = {0};
1,403✔
515

516
      code = rpcSendRecvWithTimeout(pMnode->msgCb.statusRpc, &epSet, &rpcMsg, &rpcRsp, NULL, CFG_ALTER_TIMEOUT);
1,403✔
517
      if (code != 0) {
1,403!
518
        mError("failed to send config req to dnode:%d, since %s", pDnode->id, tstrerror(code));
×
519
        sdbCancelFetch(pMnode->pSdb, pIter);
×
520
        sdbRelease(pMnode->pSdb, pDnode);
×
521
        return code;
×
522
      }
523

524
      code = rpcRsp.code;
1,403✔
525
      if (code != 0) {
1,403!
526
        mError("failed to alter config %s,on dnode:%d, since %s", pDcfgReq->config, pDnode->id, tstrerror(code));
×
527
        sdbCancelFetch(pMnode->pSdb, pIter);
×
528
        sdbRelease(pMnode->pSdb, pDnode);
×
529
        return code;
×
530
      }
531
      rpcFreeCont(rpcRsp.pCont);
1,403✔
532
    }
533
    sdbRelease(pSdb, pDnode);
1,424✔
534
  }
535

536
  if (code == -1) {
1,104✔
537
    code = TSDB_CODE_MND_DNODE_NOT_EXIST;
5✔
538
  }
539
  TAOS_RETURN(code);
1,104✔
540
}
541

542
static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
1,125✔
543
  int32_t       code = 0;
1,125✔
544
  int32_t       lino = -1;
1,125✔
545
  SMnode       *pMnode = pReq->info.node;
1,125✔
546
  SMCfgDnodeReq cfgReq = {0};
1,125✔
547
  SConfigObj   *vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
1,125✔
548
  if (vObj == NULL) {
1,125!
549
    code = TSDB_CODE_SDB_OBJ_NOT_THERE;
×
550
    mInfo("failed to acquire mnd config version, since %s", tstrerror(code));
×
551
    goto _err_out;
×
552
  }
553

554
  TAOS_CHECK_RETURN(tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq));
1,125!
555
  int8_t updateIpWhiteList = 0;
1,125✔
556
  mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value);
1,125!
557
  if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_DNODE)) != 0) {
1,125✔
558
    goto _err_out;
7✔
559
  }
560

561
  SDCfgDnodeReq dcfgReq = {0};
1,118✔
562
  if (strcasecmp(cfgReq.config, "resetlog") == 0) {
1,118✔
563
    tstrncpy(dcfgReq.config, "resetlog", 9);
2✔
564
    goto _send_req;
2✔
565
#ifdef TD_ENTERPRISE
566
  } else if (strncasecmp(cfgReq.config, "s3blocksize", 12) == 0) {
1,116!
567
    int32_t optLen = strlen("s3blocksize");
×
568
    int32_t flag = -1;
×
569
    int32_t code = mndMCfgGetValInt32(&cfgReq, optLen, &flag);
×
570
    if (code < 0) {
×
571
      goto _err_out;
×
572
    }
573

574
    if (flag > 1024 * 1024 || (flag > -1 && flag < 1024) || flag < -1) {
×
575
      mError("dnode:%d, failed to config s3blocksize since value:%d. Valid range: -1 or [1024, 1024 * 1024]",
×
576
             cfgReq.dnodeId, flag);
577
      code = TSDB_CODE_INVALID_CFG;
×
578
      goto _err_out;
×
579
    }
580

581
    tstrncpy(dcfgReq.config, "s3blocksize", 12);
×
582
    snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag);
×
583
#endif
584
  } else {
585
    TAOS_CHECK_GOTO(mndMCfg2DCfg(&cfgReq, &dcfgReq), &lino, _err_out);
1,116✔
586
    if (strlen(dcfgReq.config) > TSDB_DNODE_CONFIG_LEN) {
1,115!
587
      mError("dnode:%d, failed to config since config is too long", cfgReq.dnodeId);
×
588
      code = TSDB_CODE_INVALID_CFG;
×
589
      goto _err_out;
×
590
    }
591
    if (strncasecmp(dcfgReq.config, "enableWhiteList", strlen("enableWhiteList")) == 0) {
1,115✔
592
      updateIpWhiteList = 1;
2✔
593
    }
594

595
    CfgAlterType alterType = (cfgReq.dnodeId == 0 || cfgReq.dnodeId == -1) ? CFG_ALTER_ALL_DNODES : CFG_ALTER_DNODE;
1,115!
596
    TAOS_CHECK_GOTO(cfgCheckRangeForDynUpdate(taosGetCfg(), dcfgReq.config, dcfgReq.value, true, alterType), &lino,
1,115✔
597
                    _err_out);
598
  }
599
  SConfigItem *pItem = cfgGetItem(taosGetCfg(), dcfgReq.config);
1,102✔
600
  // Update config in sdb.
601
  if (pItem == NULL) {
1,102!
602
    mError("failed to find config:%s while process config dnode req", cfgReq.config);
×
603
    code = TSDB_CODE_CFG_NOT_FOUND;
×
604
    goto _err_out;
×
605
  }
606
  if (pItem->category == CFG_CATEGORY_GLOBAL) {
1,102✔
607
    TAOS_CHECK_GOTO(mndConfigUpdateTrans(pMnode, dcfgReq.config, dcfgReq.value, pItem->dtype, ++vObj->i32), &lino,
1,026!
608
                    _err_out);
609
  }
610
_send_req :
1,102✔
611

612
{  // audit
613
  char obj[50] = {0};
1,104✔
614
  (void)tsnprintf(obj, sizeof(obj), "%d", cfgReq.dnodeId);
1,104✔
615

616
  auditRecord(pReq, pMnode->clusterId, "alterDnode", obj, "", cfgReq.sql, cfgReq.sqlLen);
1,104✔
617
}
618
  dcfgReq.version = vObj->i32;
1,104✔
619
  code = mndSendCfgDnodeReq(pMnode, cfgReq.dnodeId, &dcfgReq);
1,104✔
620
  if (code != 0) {
1,104✔
621
    mError("failed to send config req to dnode:%d, since %s", cfgReq.dnodeId, tstrerror(code));
5!
622
    goto _err_out;
5✔
623
  }
624
  // dont care suss or succ;
625
  if (updateIpWhiteList) mndRefreshUserIpWhiteList(pMnode);
1,099✔
626
  tFreeSMCfgDnodeReq(&cfgReq);
1,099✔
627
  sdbRelease(pMnode->pSdb, vObj);
1,099✔
628
  TAOS_RETURN(code);
1,099✔
629

630
_err_out:
26✔
631
  mError("failed to process config dnode req, since %s", tstrerror(code));
26!
632
  tFreeSMCfgDnodeReq(&cfgReq);
26✔
633
  sdbRelease(pMnode->pSdb, vObj);
26✔
634
  TAOS_RETURN(code);
26✔
635
}
636

637
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp) {
×
638
  mInfo("config rsp from dnode");
×
639
  return 0;
×
640
}
641

642
static int32_t mndTryRebuildConfigSdbRsp(SRpcMsg *pRsp) {
534✔
643
  mInfo("rebuild config sdb rsp");
534!
644
  return 0;
534✔
645
}
646

647
// get int32_t value from 'SMCfgDnodeReq'
648
static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pMCfgReq, int32_t optLen, int32_t *pOutValue) {
×
649
  int32_t code = 0;
×
650
  if (' ' != pMCfgReq->config[optLen] && 0 != pMCfgReq->config[optLen]) {
×
651
    goto _err;
×
652
  }
653

654
  if (' ' == pMCfgReq->config[optLen]) {
×
655
    // 'key value'
656
    if (strlen(pMCfgReq->value) != 0) goto _err;
×
657
    *pOutValue = taosStr2Int32(pMCfgReq->config + optLen + 1, NULL, 10);
×
658
  } else {
659
    // 'key' 'value'
660
    if (strlen(pMCfgReq->value) == 0) goto _err;
×
661
    *pOutValue = taosStr2Int32(pMCfgReq->value, NULL, 10);
×
662
  }
663

664
  TAOS_RETURN(code);
×
665

666
_err:
×
667
  mError(" failed to set config since:%s", tstrerror(code));
×
668
  TAOS_RETURN(code);
×
669
}
670

671
static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype,
1,026✔
672
                                    int32_t tsmmConfigVersion) {
673
  int32_t     code = -1;
1,026✔
674
  int32_t     lino = -1;
1,026✔
675
  SConfigObj *pVersion = taosMemoryMalloc(sizeof(SConfigObj)), *pObj = taosMemoryMalloc(sizeof(SConfigObj));
1,026!
676
  if (pVersion == NULL || pObj == NULL) {
1,026!
677
    code = terrno;
×
678
    goto _OVER;
×
679
  }
680
  tstrncpy(pVersion->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
1,026✔
681
  pVersion->dtype = CFG_DTYPE_INT32;
1,026✔
682
  pVersion->i32 = tsmmConfigVersion;
1,026✔
683

684
  pObj->dtype = dtype;
1,026✔
685
  tstrncpy(pObj->name, name, CFG_NAME_MAX_LEN);
1,026✔
686

687
  TAOS_CHECK_GOTO(mndUpdateObj(pObj, name, pValue), &lino, _OVER);
1,026!
688
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, NULL, "update-config");
1,026✔
689
  if (pTrans == NULL) {
1,026!
690
    code = terrno;
×
691
    goto _OVER;
×
692
  }
693
  mInfo("trans:%d, used to update config:%s to value:%s", pTrans->id, name, pValue);
1,026!
694
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pVersion), &lino, _OVER);
1,026!
695
  TAOS_CHECK_GOTO(mndSetCreateConfigCommitLogs(pTrans, pObj), &lino, _OVER);
1,026!
696
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
1,026!
697
  code = 0;
1,026✔
698
_OVER:
1,026✔
699
  if (code != 0) {
1,026!
700
    mError("failed to update config:%s to value:%s, since %s", name, pValue, tstrerror(code));
×
701
  }
702
  mndTransDrop(pTrans);
1,026✔
703
  tFreeSConfigObj(pVersion);
1,026✔
704
  taosMemoryFree(pVersion);
1,026!
705
  tFreeSConfigObj(pObj);
1,026✔
706
  taosMemoryFree(pObj);
1,026!
707
  return code;
1,026✔
708
}
709

710
static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array) {
1,823✔
711
  int32_t     code = 0;
1,823✔
712
  SSdb       *pSdb = pMnode->pSdb;
1,823✔
713
  void       *pIter = NULL;
1,823✔
714
  SConfigObj *obj = NULL;
1,823✔
715

716
  while (1) {
158,771✔
717
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
160,594✔
718
    if (pIter == NULL) break;
160,594✔
719
    if (obj == NULL) {
158,771!
720
      code = TSDB_CODE_OUT_OF_MEMORY;
×
721
      goto _exit;
×
722
    }
723
    if (strcasecmp(obj->name, "tsmmConfigVersion") == 0) {
158,771✔
724
      sdbRelease(pSdb, obj);
1,823✔
725
      continue;
1,823✔
726
    }
727
    SConfigItem item = {0};
156,948✔
728
    item.dtype = obj->dtype;
156,948✔
729
    item.name = taosStrdup(obj->name);
156,948!
730
    if (item.name == NULL) {
156,948!
731
      code = terrno;
×
732
      sdbCancelFetch(pSdb, pIter);
×
733
      sdbRelease(pSdb, obj);
×
734
      goto _exit;
×
735
    }
736
    switch (obj->dtype) {
156,948!
737
      case CFG_DTYPE_NONE:
×
738
        break;
×
739
      case CFG_DTYPE_BOOL:
32,472✔
740
        item.bval = obj->bval;
32,472✔
741
        break;
32,472✔
742
      case CFG_DTYPE_INT32:
82,984✔
743
        item.i32 = obj->i32;
82,984✔
744
        break;
82,984✔
745
      case CFG_DTYPE_INT64:
12,628✔
746
        item.i64 = obj->i64;
12,628✔
747
        break;
12,628✔
748
      case CFG_DTYPE_FLOAT:
5,412✔
749
      case CFG_DTYPE_DOUBLE:
750
        item.fval = obj->fval;
5,412✔
751
        break;
5,412✔
752
      case CFG_DTYPE_STRING:
23,452✔
753
      case CFG_DTYPE_DIR:
754
      case CFG_DTYPE_LOCALE:
755
      case CFG_DTYPE_CHARSET:
756
      case CFG_DTYPE_TIMEZONE:
757
        item.str = taosStrdup(obj->str);
23,452!
758
        if (item.str == NULL) {
23,452!
759
          sdbCancelFetch(pSdb, pIter);
×
760
          sdbRelease(pSdb, obj);
×
761
          code = terrno;
×
762
          goto _exit;
×
763
        }
764
        break;
23,452✔
765
    }
766
    if (taosArrayPush(array, &item) == NULL) {
156,948!
767
      sdbCancelFetch(pSdb, pIter);
×
768
      sdbRelease(pSdb, obj);
×
769
      code = TSDB_CODE_OUT_OF_MEMORY;
×
770
      goto _exit;
×
771
      break;
772
    }
773
    sdbRelease(pSdb, obj);
156,948✔
774
  }
775
_exit:
1,823✔
776
  if (code != 0) {
1,823!
777
    mError("failed to init config array from sdb, since %s", tstrerror(code));
×
778
  }
779
  return code;
1,823✔
780
}
781

782
static void cfgArrayCleanUp(SArray *array) {
2,240✔
783
  if (array == NULL) {
2,240!
784
    return;
×
785
  }
786

787
  int32_t sz = taosArrayGetSize(array);
2,240✔
788
  for (int32_t i = 0; i < sz; ++i) {
159,188✔
789
    SConfigItem *item = taosArrayGet(array, i);
156,948✔
790
    if (item->dtype == CFG_DTYPE_STRING || item->dtype == CFG_DTYPE_DIR || item->dtype == CFG_DTYPE_LOCALE ||
156,948!
791
        item->dtype == CFG_DTYPE_CHARSET || item->dtype == CFG_DTYPE_TIMEZONE) {
137,104✔
792
      taosMemoryFreeClear(item->str);
23,452!
793
    }
794
    taosMemoryFreeClear(item->name);
156,948!
795
  }
796

797
  taosArrayDestroy(array);
2,240✔
798
}
799

800
static void cfgObjArrayCleanUp(SArray *array) {
535✔
801
  if (array == NULL) {
535!
802
    return;
×
803
  }
804
  int32_t sz = taosArrayGetSize(array);
535✔
805
  for (int32_t i = 0; i < sz; ++i) {
535!
806
    SConfigObj *obj = taosArrayGet(array, i);
×
807
    tFreeSConfigObj(obj);
×
808
  }
809
  taosArrayDestroy(array);
535✔
810
}
811

812
SArray *initVariablesFromItems(SArray *pItems) {
10✔
813
  if (pItems == NULL) {
10!
814
    return NULL;
×
815
  }
816

817
  int32_t sz = taosArrayGetSize(pItems);
10✔
818

819
  SArray *pInfos = taosArrayInit(sz, sizeof(SVariablesInfo));
10✔
820
  if (pInfos == NULL) {
10!
821
    mError("failed to init array while init variables from items, since %s", tstrerror(terrno));
×
822
    return NULL;
×
823
  }
824
  for (int32_t i = 0; i < sz; ++i) {
880✔
825
    SConfigItem   *pItem = taosArrayGet(pItems, i);
870✔
826
    SVariablesInfo info = {0};
870✔
827
    tstrncpy(info.name, pItem->name, sizeof(info.name));
870✔
828

829
    // init info value
830
    switch (pItem->dtype) {
870!
831
      case CFG_DTYPE_NONE:
×
832
        break;
×
833
      case CFG_DTYPE_BOOL:
180✔
834
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->bval);
180✔
835
        break;
180✔
836
      case CFG_DTYPE_INT32:
460✔
837
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->i32);
460✔
838
        break;
460✔
839
      case CFG_DTYPE_INT64:
70✔
840
        tsnprintf(info.value, sizeof(info.value), "%" PRId64, pItem->i64);
70✔
841
        break;
70✔
842
      case CFG_DTYPE_FLOAT:
30✔
843
      case CFG_DTYPE_DOUBLE:
844
        tsnprintf(info.value, sizeof(info.value), "%f", pItem->fval);
30✔
845
        break;
30✔
846
      case CFG_DTYPE_STRING:
130✔
847
      case CFG_DTYPE_DIR:
848
      case CFG_DTYPE_LOCALE:
849
      case CFG_DTYPE_CHARSET:
850
      case CFG_DTYPE_TIMEZONE:
851
        tsnprintf(info.value, sizeof(info.value), "%s", pItem->str);
130✔
852
        break;
130✔
853
    }
854

855
    // init info scope
856
    switch (pItem->scope) {
870!
857
      case CFG_SCOPE_SERVER:
720✔
858
        tstrncpy(info.scope, "server", sizeof(info.scope));
720✔
859
        break;
720✔
860
      case CFG_SCOPE_CLIENT:
×
861
        tstrncpy(info.scope, "client", sizeof(info.scope));
×
862
        break;
×
863
      case CFG_SCOPE_BOTH:
150✔
864
        tstrncpy(info.scope, "both", sizeof(info.scope));
150✔
865
        break;
150✔
866
      default:
×
867
        tstrncpy(info.scope, "unknown", sizeof(info.scope));
×
868
        break;
×
869
    }
870
    // init info category
871
    switch (pItem->category) {
870!
872
      case CFG_CATEGORY_GLOBAL:
870✔
873
        tstrncpy(info.category, "global", sizeof(info.category));
870✔
874
        break;
870✔
875
      case CFG_CATEGORY_LOCAL:
×
876
        tstrncpy(info.category, "local", sizeof(info.category));
×
877
        break;
×
878
      default:
×
879
        tstrncpy(info.category, "unknown", sizeof(info.category));
×
880
        break;
×
881
    }
882
    if (NULL == taosArrayPush(pInfos, &info)) {
870!
883
      mError("failed to push info to array while init variables from items,since %s", tstrerror(terrno));
×
884
      taosArrayDestroy(pInfos);
×
885
      return NULL;
×
886
    }
887
  }
888

889
  return pInfos;
10✔
890
}
891

892
static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) {
10✔
893
  SShowVariablesRsp rsp = {0};
10✔
894
  int32_t           code = -1;
10✔
895

896
  if ((code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_SHOW_VARIABLES)) != 0) {
10!
897
    goto _OVER;
×
898
  }
899

900
  SVariablesInfo info = {0};
10✔
901

902
  rsp.variables = initVariablesFromItems(taosGetGlobalCfg(tsCfg));
10✔
903
  if (rsp.variables == NULL) {
10!
904
    code = terrno;
×
905
    goto _OVER;
×
906
  }
907
  int32_t rspLen = tSerializeSShowVariablesRsp(NULL, 0, &rsp);
10✔
908
  void   *pRsp = rpcMallocCont(rspLen);
10✔
909
  if (pRsp == NULL) {
10!
910
    code = terrno;
×
911
    goto _OVER;
×
912
  }
913

914
  if ((rspLen = tSerializeSShowVariablesRsp(pRsp, rspLen, &rsp)) <= 0) {
10!
915
    rpcFreeCont(pRsp);
×
916
    code = rspLen;
×
917
    goto _OVER;
×
918
  }
919

920
  pReq->info.rspLen = rspLen;
10✔
921
  pReq->info.rsp = pRsp;
10✔
922
  code = 0;
10✔
923

924
_OVER:
10✔
925

926
  if (code != 0) {
10!
927
    mError("failed to get show variables info since %s", tstrerror(code));
×
928
  }
929

930
  tFreeSShowVariablesRsp(&rsp);
10✔
931
  TAOS_RETURN(code);
10✔
932
}
933

934
int32_t compareSConfigItem(const SConfigObj *item1, SConfigItem *item2, bool *compare) {
×
935
  switch (item1->dtype) {
×
936
    case CFG_DTYPE_BOOL:
×
937
      if (item1->bval != item2->bval) {
×
938
        item2->bval = item1->bval;
×
939
        *compare = false;
×
940
      }
941
      break;
×
942
    case CFG_DTYPE_FLOAT:
×
943
      if (item1->fval != item2->fval) {
×
944
        item2->fval = item1->fval;
×
945
        *compare = false;
×
946
      }
947
      break;
×
948
    case CFG_DTYPE_INT32:
×
949
      if (item1->i32 != item2->i32) {
×
950
        item2->i32 = item1->i32;
×
951
        *compare = false;
×
952
      }
953
      break;
×
954
    case CFG_DTYPE_INT64:
×
955
      if (item1->i64 != item2->i64) {
×
956
        item2->i64 = item1->i64;
×
957
        *compare = false;
×
958
      }
959
      break;
×
960
    case CFG_DTYPE_STRING:
×
961
    case CFG_DTYPE_DIR:
962
    case CFG_DTYPE_LOCALE:
963
    case CFG_DTYPE_CHARSET:
964
    case CFG_DTYPE_TIMEZONE:
965
      if (strcmp(item1->str, item2->str) != 0) {
×
966
        taosMemoryFree(item2->str);
×
967
        item2->str = taosStrdup(item1->str);
×
968
        if (item2->str == NULL) {
×
969
          return TSDB_CODE_OUT_OF_MEMORY;
×
970
        }
971
        *compare = false;
×
972
      }
973
      break;
×
974
    default:
×
975
      *compare = false;
×
976
      return TSDB_CODE_INVALID_CFG;
×
977
  }
978
  *compare = true;
×
979
  return TSDB_CODE_SUCCESS;
×
980
}
981

982
int32_t compareSConfigItemArrays(SMnode *pMnode, const SArray *dArray, SArray *diffArray) {
×
983
  int32_t code = 0;
×
984
  int32_t dsz = taosArrayGetSize(dArray);
×
985
  bool    compare = false;
×
986

987
  for (int i = 0; i < dsz; i++) {
×
988
    SConfigItem *dItem = (SConfigItem *)taosArrayGet(dArray, i);
×
989
    SConfigObj  *mObj = sdbAcquire(pMnode->pSdb, SDB_CFG, dItem->name);
×
990
    if (mObj == NULL) {
×
991
      code = terrno;
×
992
      mError("failed to acquire config:%s from sdb, since %s", dItem->name, tstrerror(code));
×
993
      return code;
×
994
    }
995

996
    code = compareSConfigItem(mObj, dItem, &compare);
×
997
    if (code != TSDB_CODE_SUCCESS) {
×
998
      sdbRelease(pMnode->pSdb, mObj);
×
999
      return code;
×
1000
    }
1001

1002
    if (!compare) {
×
1003
      if (taosArrayPush(diffArray, dItem) == NULL) {
×
1004
        sdbRelease(pMnode->pSdb, mObj);
×
1005
        return terrno;
×
1006
      }
1007
    }
1008

1009
    sdbRelease(pMnode->pSdb, mObj);
×
1010
  }
1011

1012
  return code;
×
1013
}
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