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

taosdata / TDengine / #3610

12 Feb 2025 09:54AM UTC coverage: 54.713% (-8.4%) from 63.066%
#3610

push

travis-ci

web-flow
Merge pull request #29745 from taosdata/fix/TD33664-3.0

fix: --version show information check for 3.0

120957 of 286549 branches covered (42.21%)

Branch coverage included in aggregate %.

190849 of 283342 relevant lines covered (67.36%)

4969786.97 hits per line

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

53.2
/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,081✔
51
  int32_t   code = 0;
1,081✔
52
  SSdbTable table = {.sdbType = SDB_CFG,
1,081✔
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,081✔
63
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeReq);
1,081✔
64
  mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndProcessConfigDnodeRsp);
1,081✔
65
  mndSetMsgHandle(pMnode, TDMT_MND_SHOW_VARIABLES, mndProcessShowVariablesReq);
1,081✔
66
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_SDB, mndTryRebuildConfigSdb);
1,081✔
67
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_SDB_RSP, mndTryRebuildConfigSdbRsp);
1,081✔
68

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

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

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

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

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

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

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

101
  tEncoderClear(&encoder);
236,296✔
102

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

108
_over:
236,296✔
109
  taosMemoryFreeClear(buf);
236,296!
110
  if (code != TSDB_CODE_SUCCESS) {
236,296!
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;
236,296✔
118
  mTrace("cfg:%s, encode to raw:%p, row:%p", obj->name, pRaw, obj);
236,296✔
119
  return pRaw;
236,296✔
120
}
121

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

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

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

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

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

146
  SDB_GET_INT32(pRaw, dataPos, &tlen, _over);
96,741!
147

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

151
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, _over);
96,741!
152

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

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

162
_over:
96,741✔
163
  taosMemoryFreeClear(buf);
96,741!
164

165
  if (code != TSDB_CODE_SUCCESS) {
96,741!
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);
96,741✔
172
    terrno = 0;
96,741✔
173
    return pRow;
96,741✔
174
  }
175
}
176

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

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

188
static int32_t mndCfgActionUpdate(SSdb *pSdb, SConfigObj *pOld, SConfigObj *pNew) {
532✔
189
  mTrace("cfg:%s, perform update action, old row:%p new row:%p", pOld->name, pOld, pNew);
532!
190
  switch (pNew->dtype) {
532!
191
    case CFG_DTYPE_NONE:
×
192
      break;
×
193
    case CFG_DTYPE_BOOL:
60✔
194
      pOld->bval = pNew->bval;
60✔
195
      break;
60✔
196
    case CFG_DTYPE_INT32:
432✔
197
      pOld->i32 = pNew->i32;
432✔
198
      break;
432✔
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:
12✔
207
    case CFG_DTYPE_DIR:
208
    case CFG_DTYPE_LOCALE:
209
    case CFG_DTYPE_CHARSET:
210
    case CFG_DTYPE_TIMEZONE:
211
      taosMemoryFree(pOld->str);
12!
212
      pOld->str = taosStrdup(pNew->str);
12!
213
      if (pOld->str == NULL) {
12!
214
        return terrno;
×
215
      }
216
      break;
12✔
217
  }
218
  return TSDB_CODE_SUCCESS;
532✔
219
}
220

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

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

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

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

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

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

251
  configRsp.cver = vObj->i32;
1,358✔
252
  if (configRsp.forceReadConfig) {
1,358!
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) {
1,358✔
266
      configRsp.isVersionVerified = 1;
272✔
267
    } else {
268
      code = initConfigArrayFromSdb(pMnode, array);
1,086✔
269
      if (code != 0) {
1,086!
270
        mError("failed to init config array from sdb, since %s", terrstr());
×
271
        goto _OVER;
×
272
      }
273
      configRsp.array = array;
1,086✔
274
    }
275
  }
276

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

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

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

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

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

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

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

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

362
  mndGetMnodeEpSet(pMnode, &epSet);
343✔
363

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

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

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

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

441
static int32_t mndMCfg2DCfg(SMCfgDnodeReq *pMCfgReq, SDCfgDnodeReq *pDCfgReq) {
168✔
442
  int32_t code = 0;
168✔
443
  char   *p = pMCfgReq->config;
168✔
444
  while (*p) {
2,611✔
445
    if (*p == ' ') {
2,602✔
446
      break;
159✔
447
    }
448
    p++;
2,443✔
449
  }
450

451
  size_t optLen = p - pMCfgReq->config;
168✔
452
  tstrncpy(pDCfgReq->config, pMCfgReq->config, sizeof(pDCfgReq->config));
168✔
453
  pDCfgReq->config[optLen] = 0;
168✔
454

455
  if (' ' == pMCfgReq->config[optLen]) {
168✔
456
    // 'key value'
457
    if (strlen(pMCfgReq->value) != 0) goto _err;
159!
458
    tstrncpy(pDCfgReq->value, p + 1, sizeof(pDCfgReq->value));
159✔
459
  } else {
460
    // 'key' 'value'
461
    if (strlen(pMCfgReq->value) == 0) goto _err;
9!
462
    tstrncpy(pDCfgReq->value, pMCfgReq->value, sizeof(pDCfgReq->value));
9✔
463
  }
464

465
  TAOS_RETURN(code);
168✔
466

467
_err:
×
468
  mError("dnode:%d, failed to config since invalid conf:%s", pMCfgReq->dnodeId, pMCfgReq->config);
×
469
  code = TSDB_CODE_INVALID_CFG;
×
470
  TAOS_RETURN(code);
×
471
}
472

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

478
  int64_t curMs = taosGetTimestampMs();
167✔
479

480
  while (1) {
487✔
481
    SDnodeObj *pDnode = NULL;
654✔
482
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
654✔
483
    if (pIter == NULL) break;
654✔
484

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

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

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

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

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

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

534
  if (code == -1) {
167!
535
    code = TSDB_CODE_MND_DNODE_NOT_EXIST;
×
536
  }
537
  TAOS_RETURN(code);
167✔
538
}
539

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

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

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

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

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

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

610
{  // audit
611
  char obj[50] = {0};
167✔
612
  (void)tsnprintf(obj, sizeof(obj), "%d", cfgReq.dnodeId);
167✔
613

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

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

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

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

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

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

662
  TAOS_RETURN(code);
×
663

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

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

682
  pObj->dtype = dtype;
134✔
683
  tstrncpy(pObj->name, name, CFG_NAME_MAX_LEN);
134✔
684

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

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

714
  while (1) {
96,654✔
715
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
97,740✔
716
    if (pIter == NULL) break;
97,740✔
717
    if (obj == NULL) {
96,654!
718
      code = TSDB_CODE_OUT_OF_MEMORY;
×
719
      goto _exit;
×
720
    }
721
    if (strcasecmp(obj->name, "tsmmConfigVersion") == 0) {
96,654✔
722
      sdbRelease(pSdb, obj);
1,086✔
723
      continue;
1,086✔
724
    }
725
    SConfigItem item = {0};
95,568✔
726
    item.dtype = obj->dtype;
95,568✔
727
    item.name = taosStrdup(obj->name);
95,568!
728
    if (item.name == NULL) {
95,568!
729
      code = terrno;
×
730
      sdbCancelFetch(pSdb, pIter);
×
731
      sdbRelease(pSdb, obj);
×
732
      goto _exit;
×
733
    }
734
    switch (obj->dtype) {
95,568!
735
      case CFG_DTYPE_NONE:
×
736
        break;
×
737
      case CFG_DTYPE_BOOL:
19,548✔
738
        item.bval = obj->bval;
19,548✔
739
        break;
19,548✔
740
      case CFG_DTYPE_INT32:
49,956✔
741
        item.i32 = obj->i32;
49,956✔
742
        break;
49,956✔
743
      case CFG_DTYPE_INT64:
7,602✔
744
        item.i64 = obj->i64;
7,602✔
745
        break;
7,602✔
746
      case CFG_DTYPE_FLOAT:
3,258✔
747
      case CFG_DTYPE_DOUBLE:
748
        item.fval = obj->fval;
3,258✔
749
        break;
3,258✔
750
      case CFG_DTYPE_STRING:
15,204✔
751
      case CFG_DTYPE_DIR:
752
      case CFG_DTYPE_LOCALE:
753
      case CFG_DTYPE_CHARSET:
754
      case CFG_DTYPE_TIMEZONE:
755
        item.str = taosStrdup(obj->str);
15,204!
756
        if (item.str == NULL) {
15,204!
757
          sdbCancelFetch(pSdb, pIter);
×
758
          sdbRelease(pSdb, obj);
×
759
          code = terrno;
×
760
          goto _exit;
×
761
        }
762
        break;
15,204✔
763
    }
764
    if (taosArrayPush(array, &item) == NULL) {
95,568!
765
      sdbCancelFetch(pSdb, pIter);
×
766
      sdbRelease(pSdb, obj);
×
767
      code = TSDB_CODE_OUT_OF_MEMORY;
×
768
      goto _exit;
×
769
      break;
770
    }
771
    sdbRelease(pSdb, obj);
95,568✔
772
  }
773
_exit:
1,086✔
774
  if (code != 0) {
1,086!
775
    mError("failed to init config array from sdb, since %s", tstrerror(code));
×
776
  }
777
  return code;
1,086✔
778
}
779

780
static void cfgArrayCleanUp(SArray *array) {
1,358✔
781
  if (array == NULL) {
1,358!
782
    return;
×
783
  }
784

785
  int32_t sz = taosArrayGetSize(array);
1,358✔
786
  for (int32_t i = 0; i < sz; ++i) {
96,926✔
787
    SConfigItem *item = taosArrayGet(array, i);
95,568✔
788
    if (item->dtype == CFG_DTYPE_STRING || item->dtype == CFG_DTYPE_DIR || item->dtype == CFG_DTYPE_LOCALE ||
95,568!
789
        item->dtype == CFG_DTYPE_CHARSET || item->dtype == CFG_DTYPE_TIMEZONE) {
82,536✔
790
      taosMemoryFreeClear(item->str);
15,204!
791
    }
792
    taosMemoryFreeClear(item->name);
95,568!
793
  }
794

795
  taosArrayDestroy(array);
1,358✔
796
}
797

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

810
SArray *initVariablesFromItems(SArray *pItems) {
1✔
811
  if (pItems == NULL) {
1!
812
    return NULL;
×
813
  }
814

815
  int32_t sz = taosArrayGetSize(pItems);
1✔
816

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

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

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

887
  return pInfos;
1✔
888
}
889

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

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

898
  SVariablesInfo info = {0};
1✔
899

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

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

918
  pReq->info.rspLen = rspLen;
1✔
919
  pReq->info.rsp = pRsp;
1✔
920
  code = 0;
1✔
921

922
_OVER:
1✔
923

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

928
  tFreeSShowVariablesRsp(&rsp);
1✔
929
  TAOS_RETURN(code);
1✔
930
}
931

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

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

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

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

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

1007
    sdbRelease(pMnode->pSdb, mObj);
×
1008
  }
1009

1010
  return code;
×
1011
}
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