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

taosdata / TDengine / #3609

12 Feb 2025 05:57AM UTC coverage: 63.066%. Remained the same
#3609

push

travis-ci

web-flow
Merge pull request #29746 from taosdata/merge/mainto3.02

merge: from main to 3.0 branch

140199 of 286257 branches covered (48.98%)

Branch coverage included in aggregate %.

89 of 161 new or added lines in 18 files covered. (55.28%)

3022 existing lines in 14 files now uncovered.

218998 of 283298 relevant lines covered (77.3%)

5949310.66 hits per line

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

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

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

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

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

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

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

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

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

101
  tEncoderClear(&encoder);
384,953✔
102

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

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

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

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

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

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

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

146
  SDB_GET_INT32(pRaw, dataPos, &tlen, _over);
158,612!
147

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

151
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, _over);
158,612!
152

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

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

162
_over:
158,612✔
163
  taosMemoryFreeClear(buf);
158,612!
164

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

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

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

188
static int32_t mndCfgActionUpdate(SSdb *pSdb, SConfigObj *pOld, SConfigObj *pNew) {
540✔
189
  mTrace("cfg:%s, perform update action, old row:%p new row:%p", pOld->name, pOld, pNew);
540!
190
  switch (pNew->dtype) {
540!
UNCOV
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:
436✔
197
      pOld->i32 = pNew->i32;
436✔
198
      break;
436✔
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!
UNCOV
214
        return terrno;
×
215
      }
216
      break;
12✔
217
  }
218
  return TSDB_CODE_SUCCESS;
540✔
219
}
220

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

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

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

231
  code = tDeserializeSConfigReq(pReq->pCont, pReq->contLen, &configReq);
2,142✔
232
  if (code != 0) {
2,142!
UNCOV
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,142✔
238
  if (vObj == NULL) {
2,142!
UNCOV
239
    mInfo("failed to acquire mnd config version, since %s", terrstr());
×
240
    goto _OVER;
×
241
  }
242

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

251
  configRsp.cver = vObj->i32;
2,142✔
252
  if (configRsp.forceReadConfig) {
2,142!
253
    // compare config array from configReq with current config array
NEW
254
    code = compareSConfigItemArrays(pMnode, configReq.array, array);
×
NEW
255
    if (code != TSDB_CODE_SUCCESS) {
×
NEW
256
      mError("failed to compare config array, since %s", tstrerror(code));
×
NEW
257
      goto _OVER;
×
258
    }
NEW
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,142✔
266
      configRsp.isVersionVerified = 1;
385✔
267
    } else {
268
      code = initConfigArrayFromSdb(pMnode, array);
1,757✔
269
      if (code != 0) {
1,757!
UNCOV
270
        mError("failed to init config array from sdb, since %s", terrstr());
×
UNCOV
271
        goto _OVER;
×
272
      }
273
      configRsp.array = array;
1,757✔
274
    }
275
  }
276

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

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

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

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

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

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

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

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

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

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

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

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

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

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

441
static int32_t mndMCfg2DCfg(SMCfgDnodeReq *pMCfgReq, SDCfgDnodeReq *pDCfgReq) {
228✔
442
  int32_t code = 0;
228✔
443
  char   *p = pMCfgReq->config;
228✔
444
  while (*p) {
3,331✔
445
    if (*p == ' ') {
3,292✔
446
      break;
189✔
447
    }
448
    p++;
3,103✔
449
  }
450

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

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

465
  TAOS_RETURN(code);
227✔
466

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

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

478
  int64_t curMs = taosGetTimestampMs();
216✔
479

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

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

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

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

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

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

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

534
  if (code == -1) {
216✔
535
    code = TSDB_CODE_MND_DNODE_NOT_EXIST;
5✔
536
  }
537
  TAOS_RETURN(code);
216✔
538
}
539

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

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

559
  SDCfgDnodeReq dcfgReq = {0};
230✔
560
  if (strcasecmp(cfgReq.config, "resetlog") == 0) {
230✔
561
    tstrncpy(dcfgReq.config, "resetlog", 9);
2✔
562
    goto _send_req;
2✔
563
#ifdef TD_ENTERPRISE
564
  } else if (strncasecmp(cfgReq.config, "s3blocksize", 12) == 0) {
228!
UNCOV
565
    int32_t optLen = strlen("s3blocksize");
×
UNCOV
566
    int32_t flag = -1;
×
UNCOV
567
    int32_t code = mndMCfgGetValInt32(&cfgReq, optLen, &flag);
×
UNCOV
568
    if (code < 0) {
×
UNCOV
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;
×
UNCOV
576
      goto _err_out;
×
577
    }
578

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

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

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

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

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

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

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

645
// get int32_t value from 'SMCfgDnodeReq'
UNCOV
646
static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pMCfgReq, int32_t optLen, int32_t *pOutValue) {
×
UNCOV
647
  int32_t code = 0;
×
UNCOV
648
  if (' ' != pMCfgReq->config[optLen] && 0 != pMCfgReq->config[optLen]) {
×
UNCOV
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;
×
UNCOV
659
    *pOutValue = taosStr2Int32(pMCfgReq->value, NULL, 10);
×
660
  }
661

UNCOV
662
  TAOS_RETURN(code);
×
663

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

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

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

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

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

714
  while (1) {
154,965✔
715
    pIter = sdbFetch(pSdb, SDB_CFG, pIter, (void **)&obj);
156,722✔
716
    if (pIter == NULL) break;
156,722✔
717
    if (obj == NULL) {
154,965!
UNCOV
718
      code = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
719
      goto _exit;
×
720
    }
721
    if (strcasecmp(obj->name, "tsmmConfigVersion") == 0) {
154,965✔
722
      sdbRelease(pSdb, obj);
1,757✔
723
      continue;
1,757✔
724
    }
725
    SConfigItem item = {0};
153,208✔
726
    item.dtype = obj->dtype;
153,208✔
727
    item.name = taosStrdup(obj->name);
153,208!
728
    if (item.name == NULL) {
153,208!
UNCOV
729
      code = terrno;
×
UNCOV
730
      sdbCancelFetch(pSdb, pIter);
×
UNCOV
731
      sdbRelease(pSdb, obj);
×
UNCOV
732
      goto _exit;
×
733
    }
734
    switch (obj->dtype) {
153,208!
735
      case CFG_DTYPE_NONE:
×
736
        break;
×
737
      case CFG_DTYPE_BOOL:
31,338✔
738
        item.bval = obj->bval;
31,338✔
739
        break;
31,338✔
740
      case CFG_DTYPE_INT32:
80,086✔
741
        item.i32 = obj->i32;
80,086✔
742
        break;
80,086✔
743
      case CFG_DTYPE_INT64:
12,187✔
744
        item.i64 = obj->i64;
12,187✔
745
        break;
12,187✔
746
      case CFG_DTYPE_FLOAT:
5,223✔
747
      case CFG_DTYPE_DOUBLE:
748
        item.fval = obj->fval;
5,223✔
749
        break;
5,223✔
750
      case CFG_DTYPE_STRING:
24,374✔
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);
24,374!
756
        if (item.str == NULL) {
24,374!
UNCOV
757
          sdbCancelFetch(pSdb, pIter);
×
UNCOV
758
          sdbRelease(pSdb, obj);
×
UNCOV
759
          code = terrno;
×
UNCOV
760
          goto _exit;
×
761
        }
762
        break;
24,374✔
763
    }
764
    if (taosArrayPush(array, &item) == NULL) {
153,208!
765
      sdbCancelFetch(pSdb, pIter);
×
766
      sdbRelease(pSdb, obj);
×
UNCOV
767
      code = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
768
      goto _exit;
×
769
      break;
770
    }
771
    sdbRelease(pSdb, obj);
153,208✔
772
  }
773
_exit:
1,757✔
774
  if (code != 0) {
1,757!
UNCOV
775
    mError("failed to init config array from sdb, since %s", tstrerror(code));
×
776
  }
777
  return code;
1,757✔
778
}
779

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

785
  int32_t sz = taosArrayGetSize(array);
2,142✔
786
  for (int32_t i = 0; i < sz; ++i) {
155,350✔
787
    SConfigItem *item = taosArrayGet(array, i);
153,208✔
788
    if (item->dtype == CFG_DTYPE_STRING || item->dtype == CFG_DTYPE_DIR || item->dtype == CFG_DTYPE_LOCALE ||
153,208!
789
        item->dtype == CFG_DTYPE_CHARSET || item->dtype == CFG_DTYPE_TIMEZONE) {
132,316✔
790
      taosMemoryFreeClear(item->str);
24,374!
791
    }
792
    taosMemoryFreeClear(item->name);
153,208!
793
  }
794

795
  taosArrayDestroy(array);
2,142✔
796
}
797

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

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

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

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

827
    // init info value
828
    switch (pItem->dtype) {
880!
UNCOV
829
      case CFG_DTYPE_NONE:
×
UNCOV
830
        break;
×
831
      case CFG_DTYPE_BOOL:
180✔
832
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->bval);
180✔
833
        break;
180✔
834
      case CFG_DTYPE_INT32:
460✔
835
        tsnprintf(info.value, sizeof(info.value), "%d", pItem->i32);
460✔
836
        break;
460✔
837
      case CFG_DTYPE_INT64:
70✔
838
        tsnprintf(info.value, sizeof(info.value), "%" PRId64, pItem->i64);
70✔
839
        break;
70✔
840
      case CFG_DTYPE_FLOAT:
30✔
841
      case CFG_DTYPE_DOUBLE:
842
        tsnprintf(info.value, sizeof(info.value), "%f", pItem->fval);
30✔
843
        break;
30✔
844
      case CFG_DTYPE_STRING:
140✔
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);
140✔
850
        break;
140✔
851
    }
852

853
    // init info scope
854
    switch (pItem->scope) {
880!
855
      case CFG_SCOPE_SERVER:
730✔
856
        tstrncpy(info.scope, "server", sizeof(info.scope));
730✔
857
        break;
730✔
UNCOV
858
      case CFG_SCOPE_CLIENT:
×
UNCOV
859
        tstrncpy(info.scope, "client", sizeof(info.scope));
×
UNCOV
860
        break;
×
861
      case CFG_SCOPE_BOTH:
150✔
862
        tstrncpy(info.scope, "both", sizeof(info.scope));
150✔
863
        break;
150✔
864
      default:
×
865
        tstrncpy(info.scope, "unknown", sizeof(info.scope));
×
866
        break;
×
867
    }
868
    // init info category
869
    switch (pItem->category) {
880!
870
      case CFG_CATEGORY_GLOBAL:
880✔
871
        tstrncpy(info.category, "global", sizeof(info.category));
880✔
872
        break;
880✔
UNCOV
873
      case CFG_CATEGORY_LOCAL:
×
UNCOV
874
        tstrncpy(info.category, "local", sizeof(info.category));
×
UNCOV
875
        break;
×
UNCOV
876
      default:
×
UNCOV
877
        tstrncpy(info.category, "unknown", sizeof(info.category));
×
UNCOV
878
        break;
×
879
    }
880
    if (NULL == taosArrayPush(pInfos, &info)) {
880!
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;
10✔
888
}
889

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

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

898
  SVariablesInfo info = {0};
10✔
899

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

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

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

922
_OVER:
10✔
923

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

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

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

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

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

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

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

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

NEW
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