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

taosdata / TDengine / #3720

26 Mar 2025 06:20AM UTC coverage: 30.242% (-31.7%) from 61.936%
#3720

push

travis-ci

web-flow
feat(taosBenchmark): supports decimal data type (#30456)

* feat: taosBenchmark supports decimal data type

* build: decimal script not use pytest.sh

* fix: fix typo for decimal script

* test: insertBasic.py debug

71234 of 313946 branches covered (22.69%)

Branch coverage included in aggregate %.

38 of 423 new or added lines in 8 files covered. (8.98%)

120240 existing lines in 447 files now uncovered.

118188 of 312400 relevant lines covered (37.83%)

1450220.33 hits per line

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

48.53
/source/dnode/mnode/impl/src/mndDef.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
#define _DEFAULT_SOURCE
16
#include "mndConsumer.h"
17
#include "mndDef.h"
18
#include "taoserror.h"
19
#include "tunit.h"
20

21
#ifdef USE_STREAM
22
static void *freeStreamTasks(SArray *pTaskLevel);
23

UNCOV
24
int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) {
×
UNCOV
25
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
×
UNCOV
26
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
×
27

UNCOV
28
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->createTime));
×
UNCOV
29
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->updateTime));
×
UNCOV
30
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->version));
×
UNCOV
31
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->totalLevel));
×
UNCOV
32
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->smaId));
×
33

UNCOV
34
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->uid));
×
UNCOV
35
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->status));
×
36

UNCOV
37
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->conf.igExpired));
×
UNCOV
38
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->conf.trigger));
×
UNCOV
39
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->conf.fillHistory));
×
UNCOV
40
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->conf.triggerParam));
×
UNCOV
41
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->conf.watermark));
×
42

UNCOV
43
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->sourceDbUid));
×
UNCOV
44
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->targetDbUid));
×
UNCOV
45
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->sourceDb));
×
UNCOV
46
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->targetDb));
×
UNCOV
47
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->targetSTbName));
×
UNCOV
48
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->targetStbUid));
×
UNCOV
49
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->fixedSinkVgId));
×
50

UNCOV
51
  if (pObj->sql != NULL) {
×
UNCOV
52
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->sql));
×
53
  } else {
UNCOV
54
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
×
55
  }
56

UNCOV
57
  if (pObj->ast != NULL) {
×
UNCOV
58
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->ast));
×
59
  } else {
UNCOV
60
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
×
61
  }
62

UNCOV
63
  if (pObj->physicalPlan != NULL) {
×
UNCOV
64
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->physicalPlan));
×
65
  } else {
UNCOV
66
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
×
67
  }
68

UNCOV
69
  int32_t sz = taosArrayGetSize(pObj->pTaskList);
×
UNCOV
70
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, sz));
×
UNCOV
71
  for (int32_t i = 0; i < sz; i++) {
×
UNCOV
72
    SArray *pArray = taosArrayGetP(pObj->pTaskList, i);
×
UNCOV
73
    int32_t innerSz = taosArrayGetSize(pArray);
×
UNCOV
74
    TAOS_CHECK_RETURN(tEncodeI32(pEncoder, innerSz));
×
UNCOV
75
    for (int32_t j = 0; j < innerSz; j++) {
×
UNCOV
76
      SStreamTask *pTask = taosArrayGetP(pArray, j);
×
UNCOV
77
      if (pTask->ver < SSTREAM_TASK_SUBTABLE_CHANGED_VER) {
×
UNCOV
78
        pTask->ver = SSTREAM_TASK_VER;
×
79
      }
UNCOV
80
      TAOS_CHECK_RETURN(tEncodeStreamTask(pEncoder, pTask));
×
81
    }
82
  }
83

UNCOV
84
  TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pEncoder, &pObj->outputSchema));
×
85

86
  // 3.0.20 ver =2
UNCOV
87
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->checkpointFreq));
×
UNCOV
88
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->igCheckUpdate));
×
89

90
  // 3.0.50 ver = 3
UNCOV
91
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->checkpointId));
×
UNCOV
92
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->subTableWithoutMd5));
×
93

UNCOV
94
  TAOS_CHECK_RETURN(tEncodeCStrWithLen(pEncoder, pObj->reserve, sizeof(pObj->reserve) - 1));
×
95

UNCOV
96
  tEndEncode(pEncoder);
×
UNCOV
97
  return pEncoder->pos;
×
98
}
99

UNCOV
100
int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj, int32_t sver) {
×
UNCOV
101
  int32_t code = 0;
×
UNCOV
102
  TAOS_CHECK_RETURN(tStartDecode(pDecoder));
×
UNCOV
103
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->name));
×
104

UNCOV
105
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->createTime));
×
UNCOV
106
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->updateTime));
×
UNCOV
107
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->version));
×
UNCOV
108
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->totalLevel));
×
UNCOV
109
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->smaId));
×
110

UNCOV
111
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->uid));
×
UNCOV
112
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->status));
×
113

UNCOV
114
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->conf.igExpired));
×
UNCOV
115
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->conf.trigger));
×
UNCOV
116
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->conf.fillHistory));
×
UNCOV
117
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->conf.triggerParam));
×
UNCOV
118
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->conf.watermark));
×
119

UNCOV
120
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->sourceDbUid));
×
UNCOV
121
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->targetDbUid));
×
UNCOV
122
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->sourceDb));
×
UNCOV
123
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->targetDb));
×
UNCOV
124
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->targetSTbName));
×
UNCOV
125
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->targetStbUid));
×
UNCOV
126
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->fixedSinkVgId));
×
127

UNCOV
128
  TAOS_CHECK_RETURN(tDecodeCStrAlloc(pDecoder, &pObj->sql));
×
UNCOV
129
  TAOS_CHECK_RETURN(tDecodeCStrAlloc(pDecoder, &pObj->ast));
×
UNCOV
130
  TAOS_CHECK_RETURN(tDecodeCStrAlloc(pDecoder, &pObj->physicalPlan));
×
131

UNCOV
132
  if (pObj->pTaskList != NULL) {
×
133
    pObj->pTaskList = freeStreamTasks(pObj->pTaskList);
×
134
  }
135

136
  int32_t sz;
UNCOV
137
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &sz));
×
138

UNCOV
139
  if (sz != 0) {
×
UNCOV
140
    pObj->pTaskList = taosArrayInit(sz, sizeof(void *));
×
UNCOV
141
    if (pObj->pTaskList == NULL) {
×
142
      code = terrno;
×
143
      TAOS_RETURN(code);
×
144
    }
145

UNCOV
146
    for (int32_t i = 0; i < sz; i++) {
×
147
      int32_t innerSz;
UNCOV
148
      TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &innerSz));
×
UNCOV
149
      SArray *pArray = taosArrayInit(innerSz, sizeof(void *));
×
UNCOV
150
      if (pArray != NULL) {
×
UNCOV
151
        for (int32_t j = 0; j < innerSz; j++) {
×
UNCOV
152
          SStreamTask *pTask = taosMemoryCalloc(1, sizeof(SStreamTask));
×
UNCOV
153
          if (pTask == NULL) {
×
154
            taosArrayDestroy(pArray);
×
155
            code = terrno;
×
156
            TAOS_RETURN(code);
×
157
          }
UNCOV
158
          if ((code = tDecodeStreamTask(pDecoder, pTask)) < 0) {
×
159
            taosMemoryFree(pTask);
×
160
            taosArrayDestroy(pArray);
×
161
            TAOS_RETURN(code);
×
162
          }
UNCOV
163
          if (taosArrayPush(pArray, &pTask) == NULL) {
×
164
            taosMemoryFree(pTask);
×
165
            taosArrayDestroy(pArray);
×
166
            code = terrno;
×
167
            TAOS_RETURN(code);
×
168
          }
169
        }
170
      }
UNCOV
171
      if (taosArrayPush(pObj->pTaskList, &pArray) == NULL) {
×
172
        taosArrayDestroy(pArray);
×
173
        code = terrno;
×
174
        TAOS_RETURN(code);
×
175
      }
176
    }
177
  }
178

UNCOV
179
  TAOS_CHECK_RETURN(tDecodeSSchemaWrapper(pDecoder, &pObj->outputSchema));
×
180

181
  // 3.0.20
UNCOV
182
  if (sver >= 2) {
×
UNCOV
183
    TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->checkpointFreq));
×
UNCOV
184
    if (!tDecodeIsEnd(pDecoder)) {
×
UNCOV
185
      TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->igCheckUpdate));
×
186
    }
187
  }
UNCOV
188
  if (sver >= 3) {
×
UNCOV
189
    TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->checkpointId));
×
190
  }
191

UNCOV
192
  if (sver >= 5) {
×
UNCOV
193
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->subTableWithoutMd5));
×
194
  }
UNCOV
195
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->reserve));
×
196

UNCOV
197
  tEndDecode(pDecoder);
×
UNCOV
198
  TAOS_RETURN(code);
×
199
}
200

UNCOV
201
void *freeStreamTasks(SArray *pTaskLevel) {
×
UNCOV
202
  if (pTaskLevel == NULL) return NULL;
×
UNCOV
203
  int32_t numOfLevel = taosArrayGetSize(pTaskLevel);
×
204

UNCOV
205
  for (int32_t i = 0; i < numOfLevel; i++) {
×
UNCOV
206
    SArray *pLevel = taosArrayGetP(pTaskLevel, i);
×
UNCOV
207
    int32_t taskSz = taosArrayGetSize(pLevel);
×
UNCOV
208
    for (int32_t j = 0; j < taskSz; j++) {
×
UNCOV
209
      SStreamTask *pTask = taosArrayGetP(pLevel, j);
×
UNCOV
210
      tFreeStreamTask(pTask);
×
211
    }
212

UNCOV
213
    taosArrayDestroy(pLevel);
×
214
  }
215

UNCOV
216
  taosArrayDestroy(pTaskLevel);
×
217

UNCOV
218
  return NULL;
×
219
}
220

UNCOV
221
void tFreeStreamObj(SStreamObj *pStream) {
×
UNCOV
222
  taosMemoryFree(pStream->sql);
×
UNCOV
223
  taosMemoryFree(pStream->ast);
×
UNCOV
224
  taosMemoryFree(pStream->physicalPlan);
×
225

UNCOV
226
  if (pStream->outputSchema.nCols || pStream->outputSchema.pSchema) {
×
UNCOV
227
    taosMemoryFree(pStream->outputSchema.pSchema);
×
228
  }
229

UNCOV
230
  pStream->pTaskList = freeStreamTasks(pStream->pTaskList);
×
UNCOV
231
  pStream->pHTaskList = freeStreamTasks(pStream->pHTaskList);
×
232

233
  // tagSchema.pSchema
UNCOV
234
  if (pStream->tagSchema.nCols > 0) {
×
UNCOV
235
    taosMemoryFree(pStream->tagSchema.pSchema);
×
236
  }
237

UNCOV
238
  qDestroyQueryPlan(pStream->pPlan);
×
UNCOV
239
  pStream->pPlan = NULL;
×
240

UNCOV
241
  tSimpleHashCleanup(pStream->pVTableMap);
×
UNCOV
242
  pStream->pVTableMap = NULL;
×
UNCOV
243
}
×
244
#endif
245

246
SMqVgEp *tCloneSMqVgEp(const SMqVgEp *pVgEp) {
12✔
247
  SMqVgEp *pVgEpNew = taosMemoryMalloc(sizeof(SMqVgEp));
12!
248
  if (pVgEpNew == NULL) {
12!
249
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
250
    return NULL;
×
251
  }
252
  pVgEpNew->vgId = pVgEp->vgId;
12✔
253
  //  pVgEpNew->qmsg = taosStrdup(pVgEp->qmsg);
254
  pVgEpNew->epSet = pVgEp->epSet;
12✔
255
  return pVgEpNew;
12✔
256
}
257

258
void tDeleteSMqVgEp(SMqVgEp *pVgEp) {
63✔
259
  if (pVgEp) {
63!
260
    //    taosMemoryFreeClear(pVgEp->qmsg);
261
    taosMemoryFree(pVgEp);
63!
262
  }
263
}
63✔
264

265
int32_t tEncodeSMqVgEp(void **buf, const SMqVgEp *pVgEp) {
60✔
266
  int32_t tlen = 0;
60✔
267
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
60✔
268
  //  tlen += taosEncodeString(buf, pVgEp->qmsg);
269
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
60✔
270
  return tlen;
60✔
271
}
272

273
void *tDecodeSMqVgEp(const void *buf, SMqVgEp *pVgEp, int8_t sver) {
21✔
274
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
21!
275
  if (sver == 1) {
21!
276
    uint64_t size = 0;
×
277
    buf = taosDecodeVariantU64(buf, &size);
×
278
    buf = POINTER_SHIFT(buf, size);
×
279
  }
280
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
21✔
281
  return (void *)buf;
21✔
282
}
283

284
static void *topicNameDup(void *p) { return taosStrdup((char *)p); }
12!
285

286
int32_t tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, char *topic, SCMSubscribeReq *subscribe,
44✔
287
                           SMqConsumerObj **ppConsumer) {
288
  int32_t         code = 0;
44✔
289
  SMqConsumerObj *pConsumer = taosMemoryCalloc(1, sizeof(SMqConsumerObj));
44!
290
  if (pConsumer == NULL) {
44!
291
    code = terrno;
×
292
    goto END;
×
293
  }
294

295
  pConsumer->consumerId = consumerId;
44✔
296
  (void)memcpy(pConsumer->cgroup, cgroup, TSDB_CGROUP_LEN);
44✔
297

298
  pConsumer->epoch = 0;
44✔
299
  pConsumer->status = MQ_CONSUMER_STATUS_REBALANCE;
44✔
300
  pConsumer->hbStatus = 0;
44✔
301
  pConsumer->pollStatus = 0;
44✔
302

303
  taosInitRWLatch(&pConsumer->lock);
44✔
304
  pConsumer->createTime = taosGetTimestampMs();
44✔
305
  pConsumer->updateType = updateType;
44✔
306

307
  if (updateType == CONSUMER_ADD_REB) {
44✔
308
    pConsumer->rebNewTopics = taosArrayInit(0, sizeof(void *));
12✔
309
    if (pConsumer->rebNewTopics == NULL) {
12!
310
      code = terrno;
×
311
      goto END;
×
312
    }
313

314
    char *topicTmp = taosStrdup(topic);
12!
315
    if (taosArrayPush(pConsumer->rebNewTopics, &topicTmp) == NULL) {
24!
316
      code = terrno;
×
317
      goto END;
×
318
    }
319
  } else if (updateType == CONSUMER_REMOVE_REB) {
32✔
320
    pConsumer->rebRemovedTopics = taosArrayInit(0, sizeof(void *));
12✔
321
    if (pConsumer->rebRemovedTopics == NULL) {
12!
322
      code = terrno;
×
323
      goto END;
×
324
    }
325
    char *topicTmp = taosStrdup(topic);
12!
326
    if (taosArrayPush(pConsumer->rebRemovedTopics, &topicTmp) == NULL) {
24!
327
      code = terrno;
×
328
      goto END;
×
329
    }
330
  } else if (updateType == CONSUMER_INSERT_SUB) {
20✔
331
    tstrncpy(pConsumer->clientId, subscribe->clientId, tListLen(pConsumer->clientId));
6✔
332
    pConsumer->withTbName = subscribe->withTbName;
6✔
333
    pConsumer->autoCommit = subscribe->autoCommit;
6✔
334
    pConsumer->autoCommitInterval = subscribe->autoCommitInterval;
6✔
335
    pConsumer->resetOffsetCfg = subscribe->resetOffsetCfg;
6✔
336
    pConsumer->maxPollIntervalMs = subscribe->maxPollIntervalMs;
6✔
337
    pConsumer->sessionTimeoutMs = subscribe->sessionTimeoutMs;
6✔
338
    tstrncpy(pConsumer->user, subscribe->user, TSDB_USER_LEN);
6✔
339
    tstrncpy(pConsumer->fqdn, subscribe->fqdn, TSDB_FQDN_LEN);
6✔
340

341
    pConsumer->rebNewTopics = taosArrayDup(subscribe->topicNames, topicNameDup);
6✔
342
    if (pConsumer->rebNewTopics == NULL) {
6!
343
      code = terrno;
×
344
      goto END;
×
345
    }
346
    pConsumer->assignedTopics = subscribe->topicNames;
6✔
347
    subscribe->topicNames = NULL;
6✔
348
  } else if (updateType == CONSUMER_UPDATE_SUB) {
14✔
349
    pConsumer->assignedTopics = subscribe->topicNames;
6✔
350
    subscribe->topicNames = NULL;
6✔
351
  }
352

353
  *ppConsumer = pConsumer;
44✔
354
  return 0;
44✔
355

356
END:
×
357
  tDeleteSMqConsumerObj(pConsumer);
×
358
  return code;
×
359
}
360

361
void tClearSMqConsumerObj(SMqConsumerObj *pConsumer) {
157✔
362
  if (pConsumer == NULL) return;
157✔
363
  taosArrayDestroyP(pConsumer->currentTopics, NULL);
88✔
364
  taosArrayDestroyP(pConsumer->rebNewTopics, NULL);
88✔
365
  taosArrayDestroyP(pConsumer->rebRemovedTopics, NULL);
88✔
366
  taosArrayDestroyP(pConsumer->assignedTopics, NULL);
88✔
367
}
368

369
void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer) {
113✔
370
  tClearSMqConsumerObj(pConsumer);
113✔
371
  taosMemoryFree(pConsumer);
113!
372
}
113✔
373

374
int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
90✔
375
  int32_t tlen = 0;
90✔
376
  int32_t sz;
377
  tlen += taosEncodeFixedI64(buf, pConsumer->consumerId);
90✔
378
  tlen += taosEncodeString(buf, pConsumer->clientId);
90✔
379
  tlen += taosEncodeString(buf, pConsumer->cgroup);
90✔
380
  tlen += taosEncodeFixedI8(buf, pConsumer->updateType);
90✔
381
  tlen += taosEncodeFixedI32(buf, pConsumer->epoch);
90✔
382
  tlen += taosEncodeFixedI32(buf, pConsumer->status);
90✔
383

384
  tlen += taosEncodeFixedI32(buf, pConsumer->pid);
90✔
385
  tlen += taosEncodeSEpSet(buf, &pConsumer->ep);
90✔
386
  tlen += taosEncodeFixedI64(buf, pConsumer->createTime);
90✔
387
  tlen += taosEncodeFixedI64(buf, pConsumer->subscribeTime);
90✔
388
  tlen += taosEncodeFixedI64(buf, pConsumer->rebalanceTime);
90✔
389

390
  // current topics
391
  if (pConsumer->currentTopics) {
90✔
392
    sz = taosArrayGetSize(pConsumer->currentTopics);
2✔
393
    tlen += taosEncodeFixedI32(buf, sz);
2✔
394
    for (int32_t i = 0; i < sz; i++) {
2!
UNCOV
395
      char *topic = taosArrayGetP(pConsumer->currentTopics, i);
×
UNCOV
396
      tlen += taosEncodeString(buf, topic);
×
397
    }
398
  } else {
399
    tlen += taosEncodeFixedI32(buf, 0);
88✔
400
  }
401

402
  // reb new topics
403
  if (pConsumer->rebNewTopics) {
90✔
404
    sz = taosArrayGetSize(pConsumer->rebNewTopics);
50✔
405
    tlen += taosEncodeFixedI32(buf, sz);
50✔
406
    for (int32_t i = 0; i < sz; i++) {
98✔
407
      char *topic = taosArrayGetP(pConsumer->rebNewTopics, i);
48✔
408
      tlen += taosEncodeString(buf, topic);
48✔
409
    }
410
  } else {
411
    tlen += taosEncodeFixedI32(buf, 0);
40✔
412
  }
413

414
  // reb removed topics
415
  if (pConsumer->rebRemovedTopics) {
90✔
416
    sz = taosArrayGetSize(pConsumer->rebRemovedTopics);
38✔
417
    tlen += taosEncodeFixedI32(buf, sz);
38✔
418
    for (int32_t i = 0; i < sz; i++) {
86✔
419
      char *topic = taosArrayGetP(pConsumer->rebRemovedTopics, i);
48✔
420
      tlen += taosEncodeString(buf, topic);
48✔
421
    }
422
  } else {
423
    tlen += taosEncodeFixedI32(buf, 0);
52✔
424
  }
425

426
  // lost topics
427
  if (pConsumer->assignedTopics) {
90✔
428
    sz = taosArrayGetSize(pConsumer->assignedTopics);
26✔
429
    tlen += taosEncodeFixedI32(buf, sz);
26✔
430
    for (int32_t i = 0; i < sz; i++) {
50✔
431
      char *topic = taosArrayGetP(pConsumer->assignedTopics, i);
24✔
432
      tlen += taosEncodeString(buf, topic);
24✔
433
    }
434
  } else {
435
    tlen += taosEncodeFixedI32(buf, 0);
64✔
436
  }
437

438
  tlen += taosEncodeFixedI8(buf, pConsumer->withTbName);
90✔
439
  tlen += taosEncodeFixedI8(buf, pConsumer->autoCommit);
90✔
440
  tlen += taosEncodeFixedI32(buf, pConsumer->autoCommitInterval);
90✔
441
  tlen += taosEncodeFixedI32(buf, pConsumer->resetOffsetCfg);
90✔
442
  tlen += taosEncodeFixedI32(buf, pConsumer->maxPollIntervalMs);
90✔
443
  tlen += taosEncodeFixedI32(buf, pConsumer->sessionTimeoutMs);
90✔
444
  tlen += taosEncodeString(buf, pConsumer->user);
90✔
445
  tlen += taosEncodeString(buf, pConsumer->fqdn);
90✔
446
  return tlen;
90✔
447
}
448

449
void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer, int8_t sver) {
44✔
450
  int32_t sz;
451
  buf = taosDecodeFixedI64(buf, &pConsumer->consumerId);
44!
452
  buf = taosDecodeStringTo(buf, pConsumer->clientId);
44✔
453
  buf = taosDecodeStringTo(buf, pConsumer->cgroup);
44✔
454
  buf = taosDecodeFixedI8(buf, &pConsumer->updateType);
44✔
455
  buf = taosDecodeFixedI32(buf, &pConsumer->epoch);
44!
456
  buf = taosDecodeFixedI32(buf, &pConsumer->status);
44!
457

458
  buf = taosDecodeFixedI32(buf, &pConsumer->pid);
44!
459
  buf = taosDecodeSEpSet(buf, &pConsumer->ep);
44✔
460
  buf = taosDecodeFixedI64(buf, &pConsumer->createTime);
44!
461
  buf = taosDecodeFixedI64(buf, &pConsumer->subscribeTime);
44!
462
  buf = taosDecodeFixedI64(buf, &pConsumer->rebalanceTime);
88!
463

464
  // current topics
465
  buf = taosDecodeFixedI32(buf, &sz);
44✔
466
  pConsumer->currentTopics = taosArrayInit(sz, sizeof(void *));
44✔
467
  if (pConsumer->currentTopics == NULL) {
44!
468
    return NULL;
×
469
  }
470
  for (int32_t i = 0; i < sz; i++) {
44!
471
    char *topic;
UNCOV
472
    buf = taosDecodeString(buf, &topic);
×
UNCOV
473
    if (taosArrayPush(pConsumer->currentTopics, &topic) == NULL) {
×
474
      return NULL;
×
475
    }
476
  }
477

478
  // reb new topics
479
  buf = taosDecodeFixedI32(buf, &sz);
44✔
480
  pConsumer->rebNewTopics = taosArrayInit(sz, sizeof(void *));
44✔
481
  for (int32_t i = 0; i < sz; i++) {
68✔
482
    char *topic;
483
    buf = taosDecodeString(buf, &topic);
24✔
484
    if (taosArrayPush(pConsumer->rebNewTopics, &topic) == NULL) {
48!
485
      return NULL;
×
486
    }
487
  }
488

489
  // reb removed topics
490
  buf = taosDecodeFixedI32(buf, &sz);
44✔
491
  pConsumer->rebRemovedTopics = taosArrayInit(sz, sizeof(void *));
44✔
492
  for (int32_t i = 0; i < sz; i++) {
68✔
493
    char *topic;
494
    buf = taosDecodeString(buf, &topic);
24✔
495
    if (taosArrayPush(pConsumer->rebRemovedTopics, &topic) == NULL) {
48!
496
      return NULL;
×
497
    }
498
  }
499

500
  // reb removed topics
501
  buf = taosDecodeFixedI32(buf, &sz);
44✔
502
  pConsumer->assignedTopics = taosArrayInit(sz, sizeof(void *));
44✔
503
  for (int32_t i = 0; i < sz; i++) {
56✔
504
    char *topic;
505
    buf = taosDecodeString(buf, &topic);
12✔
506
    if (taosArrayPush(pConsumer->assignedTopics, &topic) == NULL) {
24!
507
      return NULL;
×
508
    }
509
  }
510

511
  if (sver > 1) {
44!
512
    buf = taosDecodeFixedI8(buf, &pConsumer->withTbName);
44✔
513
    buf = taosDecodeFixedI8(buf, &pConsumer->autoCommit);
44✔
514
    buf = taosDecodeFixedI32(buf, &pConsumer->autoCommitInterval);
44!
515
    buf = taosDecodeFixedI32(buf, &pConsumer->resetOffsetCfg);
88!
516
  }
517
  if (sver > 2) {
44!
518
    buf = taosDecodeFixedI32(buf, &pConsumer->maxPollIntervalMs);
44!
519
    buf = taosDecodeFixedI32(buf, &pConsumer->sessionTimeoutMs);
44!
520
    buf = taosDecodeStringTo(buf, pConsumer->user);
44✔
521
    buf = taosDecodeStringTo(buf, pConsumer->fqdn);
88✔
522
  } else {
523
    pConsumer->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
524
    pConsumer->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
525
  }
526

527
  return (void *)buf;
44✔
528
}
529

530
int32_t tEncodeOffRows(void **buf, SArray *offsetRows) {
90✔
531
  int32_t tlen = 0;
90✔
532
  int32_t szVgs = taosArrayGetSize(offsetRows);
90✔
533
  tlen += taosEncodeFixedI32(buf, szVgs);
90✔
534
  for (int32_t j = 0; j < szVgs; ++j) {
132✔
535
    OffsetRows *offRows = taosArrayGet(offsetRows, j);
42✔
536
    tlen += taosEncodeFixedI32(buf, offRows->vgId);
42✔
537
    tlen += taosEncodeFixedI64(buf, offRows->rows);
42✔
538
    tlen += taosEncodeFixedI8(buf, offRows->offset.type);
42✔
539
    if (offRows->offset.type == TMQ_OFFSET__SNAPSHOT_DATA || offRows->offset.type == TMQ_OFFSET__SNAPSHOT_META) {
42!
UNCOV
540
      tlen += taosEncodeFixedI64(buf, offRows->offset.uid);
×
UNCOV
541
      tlen += taosEncodeFixedI64(buf, offRows->offset.ts);
×
542
    } else if (offRows->offset.type == TMQ_OFFSET__LOG) {
42✔
543
      tlen += taosEncodeFixedI64(buf, offRows->offset.version);
76✔
544
    } else {
545
      // do nothing
546
    }
547
    tlen += taosEncodeFixedI64(buf, offRows->ever);
84✔
548
  }
549

550
  return tlen;
90✔
551
}
552

553
int32_t tEncodeSMqConsumerEp(void **buf, const SMqConsumerEp *pConsumerEp) {
30✔
554
  int32_t tlen = 0;
30✔
555
  tlen += taosEncodeFixedI64(buf, pConsumerEp->consumerId);
30✔
556
  tlen += taosEncodeArray(buf, pConsumerEp->vgs, (FEncode)tEncodeSMqVgEp);
30✔
557

558
  return tlen + tEncodeOffRows(buf, pConsumerEp->offsetRows);
30✔
559
}
560

561
void *tDecodeOffRows(const void *buf, SArray **offsetRows, int8_t sver) {
36✔
562
  int32_t szVgs = 0;
36!
563
  buf = taosDecodeFixedI32(buf, &szVgs);
36✔
564
  if (szVgs > 0) {
36✔
565
    *offsetRows = taosArrayInit(szVgs, sizeof(OffsetRows));
12✔
566
    if (NULL == *offsetRows) return NULL;
12!
567
    for (int32_t j = 0; j < szVgs; ++j) {
24✔
568
      OffsetRows *offRows = taosArrayReserve(*offsetRows, 1);
12✔
569
      buf = taosDecodeFixedI32(buf, &offRows->vgId);
12!
570
      buf = taosDecodeFixedI64(buf, &offRows->rows);
12!
571
      buf = taosDecodeFixedI8(buf, &offRows->offset.type);
12✔
572
      if (offRows->offset.type == TMQ_OFFSET__SNAPSHOT_DATA || offRows->offset.type == TMQ_OFFSET__SNAPSHOT_META) {
12!
UNCOV
573
        buf = taosDecodeFixedI64(buf, &offRows->offset.uid);
×
UNCOV
574
        buf = taosDecodeFixedI64(buf, &offRows->offset.ts);
×
575
      } else if (offRows->offset.type == TMQ_OFFSET__LOG) {
12✔
576
        buf = taosDecodeFixedI64(buf, &offRows->offset.version);
22!
577
      } else {
578
        // do nothing
579
      }
580
      if (sver > 2) {
12!
581
        buf = taosDecodeFixedI64(buf, &offRows->ever);
24!
582
      }
583
    }
584
  }
585
  return (void *)buf;
36✔
586
}
587

588
void *tDecodeSMqConsumerEp(const void *buf, SMqConsumerEp *pConsumerEp, int8_t sver) {
15✔
589
  buf = taosDecodeFixedI64(buf, &pConsumerEp->consumerId);
15!
590
  buf = taosDecodeArray(buf, &pConsumerEp->vgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqVgEp), sver);
15✔
591
  if (sver > 1) {
15!
592
    buf = tDecodeOffRows(buf, &pConsumerEp->offsetRows, sver);
15✔
593
  }
594

595
  return (void *)buf;
15✔
596
}
597

598
int32_t tNewSubscribeObj(const char *key, SMqSubscribeObj **ppSub) {
9✔
599
  int32_t          code = 0;
9✔
600
  SMqSubscribeObj *pSubObj = taosMemoryCalloc(1, sizeof(SMqSubscribeObj));
9!
601
  MND_TMQ_NULL_CHECK(pSubObj);
9!
602

603
  (void)memcpy(pSubObj->key, key, TSDB_SUBSCRIBE_KEY_LEN);
9✔
604
  taosInitRWLatch(&pSubObj->lock);
9✔
605
  pSubObj->vgNum = 0;
9✔
606
  pSubObj->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
9✔
607
  MND_TMQ_NULL_CHECK(pSubObj->consumerHash);
9!
608
  pSubObj->unassignedVgs = taosArrayInit(0, POINTER_BYTES);
9✔
609
  MND_TMQ_NULL_CHECK(pSubObj->unassignedVgs);
9!
610
  if (ppSub) {
9!
611
    *ppSub = pSubObj;
9✔
612
  }
613
  return code;
9✔
614

615
END:
×
616
  taosMemoryFree(pSubObj);
×
617
  return code;
×
618
}
619

620
int32_t tCloneSubscribeObj(const SMqSubscribeObj *pSub, SMqSubscribeObj **ppSub) {
12✔
621
  int32_t          code = 0;
12✔
622
  SMqSubscribeObj *pSubNew = taosMemoryMalloc(sizeof(SMqSubscribeObj));
12!
623
  if (pSubNew == NULL) {
12!
624
    code = terrno;
×
625
    goto END;
×
626
  }
627
  (void)memcpy(pSubNew->key, pSub->key, TSDB_SUBSCRIBE_KEY_LEN);
12✔
628
  taosInitRWLatch(&pSubNew->lock);
12✔
629

630
  pSubNew->dbUid = pSub->dbUid;
12✔
631
  pSubNew->stbUid = pSub->stbUid;
12✔
632
  pSubNew->subType = pSub->subType;
12✔
633
  pSubNew->withMeta = pSub->withMeta;
12✔
634

635
  pSubNew->vgNum = pSub->vgNum;
12✔
636
  pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
12✔
637

638
  void          *pIter = NULL;
12✔
639
  SMqConsumerEp *pConsumerEp = NULL;
12✔
640
  while (1) {
15✔
641
    pIter = taosHashIterate(pSub->consumerHash, pIter);
27✔
642
    if (pIter == NULL) break;
27✔
643
    pConsumerEp = (SMqConsumerEp *)pIter;
15✔
644
    SMqConsumerEp newEp = {
30✔
645
        .consumerId = pConsumerEp->consumerId,
15✔
646
        .vgs = taosArrayDup(pConsumerEp->vgs, (__array_item_dup_fn_t)tCloneSMqVgEp),
15✔
647
    };
648
    if ((code = taosHashPut(pSubNew->consumerHash, &newEp.consumerId, sizeof(int64_t), &newEp,
15!
649
                            sizeof(SMqConsumerEp))) != 0)
650
      goto END;
×
651
  }
652
  pSubNew->unassignedVgs = taosArrayDup(pSub->unassignedVgs, (__array_item_dup_fn_t)tCloneSMqVgEp);
12✔
653
  pSubNew->offsetRows = taosArrayDup(pSub->offsetRows, NULL);
12✔
654
  (void)memcpy(pSubNew->dbName, pSub->dbName, TSDB_DB_FNAME_LEN);
12✔
655
  pSubNew->qmsg = taosStrdup(pSub->qmsg);
12!
656
  if (ppSub) {
12!
657
    *ppSub = pSubNew;
12✔
658
  }
659
END:
×
660
  return code;
12✔
661
}
662

663
void tDeleteSubscribeObj(SMqSubscribeObj *pSub) {
42✔
664
  if (pSub == NULL) return;
42!
665
  void *pIter = NULL;
42✔
666
  while (1) {
30✔
667
    pIter = taosHashIterate(pSub->consumerHash, pIter);
72✔
668
    if (pIter == NULL) break;
72✔
669
    SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
30✔
670
    taosArrayDestroyP(pConsumerEp->vgs, (FDelete)tDeleteSMqVgEp);
30✔
671
    taosArrayDestroy(pConsumerEp->offsetRows);
30✔
672
  }
673
  taosHashCleanup(pSub->consumerHash);
42✔
674
  taosArrayDestroyP(pSub->unassignedVgs, (FDelete)tDeleteSMqVgEp);
42✔
675
  taosMemoryFreeClear(pSub->qmsg);
42!
676
  taosArrayDestroy(pSub->offsetRows);
42✔
677
}
678

679
int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
60✔
680
  int32_t tlen = 0;
60✔
681
  tlen += taosEncodeString(buf, pSub->key);
60✔
682
  tlen += taosEncodeFixedI64(buf, pSub->dbUid);
60✔
683
  tlen += taosEncodeFixedI32(buf, pSub->vgNum);
60✔
684
  tlen += taosEncodeFixedI8(buf, pSub->subType);
60✔
685
  tlen += taosEncodeFixedI8(buf, pSub->withMeta);
60✔
686
  tlen += taosEncodeFixedI64(buf, pSub->stbUid);
60✔
687

688
  void   *pIter = NULL;
60✔
689
  int32_t sz = taosHashGetSize(pSub->consumerHash);
60✔
690
  tlen += taosEncodeFixedI32(buf, sz);
60✔
691

692
  int32_t cnt = 0;
60✔
693
  while (1) {
30✔
694
    pIter = taosHashIterate(pSub->consumerHash, pIter);
90✔
695
    if (pIter == NULL) break;
90✔
696
    SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
30✔
697
    tlen += tEncodeSMqConsumerEp(buf, pConsumerEp);
30✔
698
    cnt++;
30✔
699
  }
700
  if (cnt != sz) return -1;
60!
701
  tlen += taosEncodeArray(buf, pSub->unassignedVgs, (FEncode)tEncodeSMqVgEp);
60✔
702
  tlen += taosEncodeString(buf, pSub->dbName);
60✔
703

704
  tlen += tEncodeOffRows(buf, pSub->offsetRows);
60✔
705
  tlen += taosEncodeString(buf, pSub->qmsg);
60✔
706
  return tlen;
60✔
707
}
708

709
void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) {
21✔
710
  //
711
  buf = taosDecodeStringTo(buf, pSub->key);
21✔
712
  buf = taosDecodeFixedI64(buf, &pSub->dbUid);
21!
713
  buf = taosDecodeFixedI32(buf, &pSub->vgNum);
21!
714
  buf = taosDecodeFixedI8(buf, &pSub->subType);
21✔
715
  buf = taosDecodeFixedI8(buf, &pSub->withMeta);
21✔
716
  buf = taosDecodeFixedI64(buf, &pSub->stbUid);
42!
717

718
  int32_t sz;
719
  buf = taosDecodeFixedI32(buf, &sz);
21✔
720

721
  pSub->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
21✔
722
  for (int32_t i = 0; i < sz; i++) {
36✔
723
    SMqConsumerEp consumerEp = {0};
15✔
724
    buf = tDecodeSMqConsumerEp(buf, &consumerEp, sver);
15✔
725
    if (taosHashPut(pSub->consumerHash, &consumerEp.consumerId, sizeof(int64_t), &consumerEp, sizeof(SMqConsumerEp)) !=
15!
726
        0)
727
      return NULL;
×
728
  }
729

730
  buf = taosDecodeArray(buf, &pSub->unassignedVgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqVgEp), sver);
21✔
731
  buf = taosDecodeStringTo(buf, pSub->dbName);
21✔
732

733
  if (sver > 1) {
21!
734
    buf = tDecodeOffRows(buf, &pSub->offsetRows, sver);
21✔
735
    buf = taosDecodeString(buf, &pSub->qmsg);
42✔
736
  } else {
737
    pSub->qmsg = taosStrdup("");
×
738
  }
739
  return (void *)buf;
21✔
740
}
741

742
int32_t mndInitConfigObj(SConfigItem *pItem, SConfigObj *pObj) {
1,068✔
743
  tstrncpy(pObj->name, pItem->name, CFG_NAME_MAX_LEN);
1,068✔
744
  pObj->dtype = pItem->dtype;
1,068✔
745
  switch (pItem->dtype) {
1,068!
746
    case CFG_DTYPE_NONE:
×
747
      break;
×
748
    case CFG_DTYPE_BOOL:
228✔
749
      pObj->bval = pItem->bval;
228✔
750
      break;
228✔
751
    case CFG_DTYPE_INT32:
552✔
752
      pObj->i32 = pItem->i32;
552✔
753
      break;
552✔
754
    case CFG_DTYPE_INT64:
96✔
755
      pObj->i64 = pItem->i64;
96✔
756
      break;
96✔
757
    case CFG_DTYPE_FLOAT:
36✔
758
    case CFG_DTYPE_DOUBLE:
759
      pObj->fval = pItem->fval;
36✔
760
      break;
36✔
761
    case CFG_DTYPE_STRING:
156✔
762
    case CFG_DTYPE_DIR:
763
    case CFG_DTYPE_LOCALE:
764
    case CFG_DTYPE_CHARSET:
765
    case CFG_DTYPE_TIMEZONE:
766
      pObj->str = taosStrdup(pItem->str);
156!
767
      if (pObj->str == NULL) {
156!
768
        taosMemoryFree(pObj);
×
769
        return TSDB_CODE_OUT_OF_MEMORY;
×
770
      }
771
      break;
156✔
772
  }
773
  return TSDB_CODE_SUCCESS;
1,068✔
774
}
775

UNCOV
776
int32_t mndUpdateObj(SConfigObj *pObjNew, const char *name, char *value) {
×
UNCOV
777
  int32_t code = 0;
×
UNCOV
778
  switch (pObjNew->dtype) {
×
UNCOV
779
    case CFG_DTYPE_BOOL: {
×
UNCOV
780
      bool tmp = false;
×
UNCOV
781
      if (strcasecmp(value, "true") == 0) {
×
782
        tmp = true;
×
783
      }
UNCOV
784
      if (taosStr2Int32(value, NULL, 10) > 0) {
×
UNCOV
785
        tmp = true;
×
786
      }
UNCOV
787
      pObjNew->bval = tmp;
×
UNCOV
788
      break;
×
789
    }
UNCOV
790
    case CFG_DTYPE_INT32: {
×
791
      int32_t ival;
UNCOV
792
      TAOS_CHECK_RETURN(taosStrHumanToInt32(value, &ival));
×
UNCOV
793
      pObjNew->i32 = ival;
×
UNCOV
794
      break;
×
795
    }
UNCOV
796
    case CFG_DTYPE_INT64: {
×
797
      int64_t ival;
UNCOV
798
      TAOS_CHECK_RETURN(taosStrHumanToInt64(value, &ival));
×
UNCOV
799
      pObjNew->i64 = ival;
×
UNCOV
800
      break;
×
801
    }
UNCOV
802
    case CFG_DTYPE_FLOAT:
×
803
    case CFG_DTYPE_DOUBLE: {
UNCOV
804
      float dval = 0;
×
UNCOV
805
      TAOS_CHECK_RETURN(parseCfgReal(value, &dval));
×
UNCOV
806
      pObjNew->fval = dval;
×
UNCOV
807
      break;
×
808
    }
UNCOV
809
    case CFG_DTYPE_DIR:
×
810
    case CFG_DTYPE_TIMEZONE:
811
    case CFG_DTYPE_CHARSET:
812
    case CFG_DTYPE_LOCALE:
813
    case CFG_DTYPE_STRING: {
UNCOV
814
      pObjNew->str = taosStrdup(value);
×
UNCOV
815
      if (pObjNew->str == NULL) {
×
816
        code = terrno;
×
817
        return code;
×
818
      }
UNCOV
819
      break;
×
820
    }
821
    case CFG_DTYPE_NONE:
×
822
      break;
×
823
    default:
×
824
      code = TSDB_CODE_INVALID_CFG;
×
825
      break;
×
826
  }
UNCOV
827
  return code;
×
828
}
829

830
SConfigObj mndInitConfigVersion() {
16✔
831
  SConfigObj obj;
832
  memset(&obj, 0, sizeof(SConfigObj));
16✔
833

834
  tstrncpy(obj.name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
16✔
835
  obj.dtype = CFG_DTYPE_INT32;
16✔
836
  obj.i32 = 0;
16✔
837
  return obj;
16✔
838
}
839

840
int32_t tEncodeSConfigObj(SEncoder *pEncoder, const SConfigObj *pObj) {
7,404✔
841
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
7,404!
842
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
14,808!
843

844
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->dtype));
14,808!
845
  switch (pObj->dtype) {
7,404!
846
    case CFG_DTYPE_BOOL:
1,558✔
847
      TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->bval));
3,116!
848
      break;
1,558✔
849
    case CFG_DTYPE_INT32:
3,878✔
850
      TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->i32));
7,756!
851
      break;
3,878✔
852
    case CFG_DTYPE_INT64:
656✔
853
      TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->i64));
1,312!
854
      break;
656✔
855
    case CFG_DTYPE_FLOAT:
246✔
856
    case CFG_DTYPE_DOUBLE:
857
      TAOS_CHECK_RETURN(tEncodeFloat(pEncoder, pObj->fval));
492!
858
      break;
246✔
859
    case CFG_DTYPE_STRING:
1,066✔
860
    case CFG_DTYPE_DIR:
861
    case CFG_DTYPE_LOCALE:
862
    case CFG_DTYPE_CHARSET:
863
    case CFG_DTYPE_TIMEZONE:
864
      if (pObj->str != NULL) {
1,066!
865
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->str));
2,132!
866
      } else {
867
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
×
868
      }
869
      break;
1,066✔
870
    default:
×
871
      break;
×
872
  }
873
  tEndEncode(pEncoder);
7,404✔
874
  return pEncoder->pos;
7,404✔
875
}
876

877
int32_t tDecodeSConfigObj(SDecoder *pDecoder, SConfigObj *pObj) {
1,444✔
878
  TAOS_CHECK_RETURN(tStartDecode(pDecoder));
1,444!
879
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->name));
1,444!
880
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, (int32_t *)&pObj->dtype));
2,888!
881
  switch (pObj->dtype) {
1,444!
882
    case CFG_DTYPE_NONE:
×
883
      break;
×
884
    case CFG_DTYPE_BOOL:
304✔
885
      TAOS_CHECK_RETURN(tDecodeBool(pDecoder, &pObj->bval));
304!
886
      break;
304✔
887
    case CFG_DTYPE_INT32:
756✔
888
      TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->i32));
1,512!
889
      break;
756✔
890
    case CFG_DTYPE_INT64:
128✔
891
      TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->i64));
256!
892
      break;
128✔
893
    case CFG_DTYPE_FLOAT:
48✔
894
    case CFG_DTYPE_DOUBLE:
895
      TAOS_CHECK_RETURN(tDecodeFloat(pDecoder, &pObj->fval));
96!
896
      break;
48✔
897
    case CFG_DTYPE_STRING:
208✔
898
    case CFG_DTYPE_DIR:
899
    case CFG_DTYPE_LOCALE:
900
    case CFG_DTYPE_CHARSET:
901
    case CFG_DTYPE_TIMEZONE:
902
      TAOS_CHECK_RETURN(tDecodeCStrAlloc(pDecoder, &pObj->str));
416!
903
      break;
208✔
904
  }
905
  tEndDecode(pDecoder);
1,444✔
906
  TAOS_RETURN(TSDB_CODE_SUCCESS);
1,444✔
907
}
908

909
void tFreeSConfigObj(SConfigObj *obj) {
2,528✔
910
  if (obj == NULL) {
2,528!
911
    return;
×
912
  }
913
  if (obj->dtype == CFG_DTYPE_STRING || obj->dtype == CFG_DTYPE_DIR || obj->dtype == CFG_DTYPE_LOCALE ||
2,528!
914
      obj->dtype == CFG_DTYPE_CHARSET || obj->dtype == CFG_DTYPE_TIMEZONE) {
2,220✔
915
    taosMemoryFree(obj->str);
364!
916
  }
917
}
918

919
// SMqSubActionLogEntry *tCloneSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) {
920
//   SMqSubActionLogEntry *pEntryNew = taosMemoryMalloc(sizeof(SMqSubActionLogEntry));
921
//   if (pEntryNew == NULL) return NULL;
922
//   pEntryNew->epoch = pEntry->epoch;
923
//   pEntryNew->consumers = taosArrayDup(pEntry->consumers, (__array_item_dup_fn_t)tCloneSMqConsumerEp);
924
//   return pEntryNew;
925
// }
926
//
927
// void tDeleteSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) {
928
//   taosArrayDestroyEx(pEntry->consumers, (FDelete)tDeleteSMqConsumerEp);
929
// }
930

931
// int32_t tEncodeSMqSubActionLogEntry(void **buf, const SMqSubActionLogEntry *pEntry) {
932
//   int32_t tlen = 0;
933
//   tlen += taosEncodeFixedI32(buf, pEntry->epoch);
934
//   tlen += taosEncodeArray(buf, pEntry->consumers, (FEncode)tEncodeSMqSubActionLogEntry);
935
//   return tlen;
936
// }
937
//
938
// void *tDecodeSMqSubActionLogEntry(const void *buf, SMqSubActionLogEntry *pEntry) {
939
//   buf = taosDecodeFixedI32(buf, &pEntry->epoch);
940
//   buf = taosDecodeArray(buf, &pEntry->consumers, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry));
941
//   return (void *)buf;
942
// }
943

944
// SMqSubActionLogObj *tCloneSMqSubActionLogObj(SMqSubActionLogObj *pLog) {
945
//   SMqSubActionLogObj *pLogNew = taosMemoryMalloc(sizeof(SMqSubActionLogObj));
946
//   if (pLogNew == NULL) return pLogNew;
947
//   memcpy(pLogNew->key, pLog->key, TSDB_SUBSCRIBE_KEY_LEN);
948
//   pLogNew->logs = taosArrayDup(pLog->logs, (__array_item_dup_fn_t)tCloneSMqConsumerEp);
949
//   return pLogNew;
950
// }
951
//
952
// void tDeleteSMqSubActionLogObj(SMqSubActionLogObj *pLog) {
953
//   taosArrayDestroyEx(pLog->logs, (FDelete)tDeleteSMqConsumerEp);
954
// }
955

956
// int32_t tEncodeSMqSubActionLogObj(void **buf, const SMqSubActionLogObj *pLog) {
957
//   int32_t tlen = 0;
958
//   tlen += taosEncodeString(buf, pLog->key);
959
//   tlen += taosEncodeArray(buf, pLog->logs, (FEncode)tEncodeSMqSubActionLogEntry);
960
//   return tlen;
961
// }
962
//
963
// void *tDecodeSMqSubActionLogObj(const void *buf, SMqSubActionLogObj *pLog) {
964
//   buf = taosDecodeStringTo(buf, pLog->key);
965
//   buf = taosDecodeArray(buf, &pLog->logs, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry));
966
//   return (void *)buf;
967
// }
968
//
969
// int32_t tEncodeSMqOffsetObj(void **buf, const SMqOffsetObj *pOffset) {
970
//   int32_t tlen = 0;
971
//   tlen += taosEncodeString(buf, pOffset->key);
972
//   tlen += taosEncodeFixedI64(buf, pOffset->offset);
973
//   return tlen;
974
// }
975
//
976
// void *tDecodeSMqOffsetObj(void *buf, SMqOffsetObj *pOffset) {
977
//   buf = taosDecodeStringTo(buf, pOffset->key);
978
//   buf = taosDecodeFixedI64(buf, &pOffset->offset);
979
//   return buf;
980
// }
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