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

taosdata / TDengine / #3814

01 Apr 2025 05:36AM UTC coverage: 30.169% (-3.6%) from 33.798%
#3814

push

travis-ci

happyguoxy
test:add build cmake

129680 of 592945 branches covered (21.87%)

Branch coverage included in aggregate %.

196213 of 487270 relevant lines covered (40.27%)

555639.42 hits per line

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

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

24
int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) {
22✔
25
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
22!
26
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
44!
27

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

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

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

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

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

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

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

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

84
  TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pEncoder, &pObj->outputSchema));
44!
85

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

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

94
  TAOS_CHECK_RETURN(tEncodeCStrWithLen(pEncoder, pObj->reserve, sizeof(pObj->reserve) - 1));
44!
95

96
  tEndEncode(pEncoder);
22✔
97
  return pEncoder->pos;
22✔
98
}
99

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

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

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

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

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

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

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

136
  int32_t sz;
137
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &sz));
8!
138

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

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

179
  TAOS_CHECK_RETURN(tDecodeSSchemaWrapper(pDecoder, &pObj->outputSchema));
16!
180

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

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

197
  tEndDecode(pDecoder);
8✔
198
  TAOS_RETURN(code);
8✔
199
}
200

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

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

213
    taosArrayDestroy(pLevel);
34✔
214
  }
215

216
  taosArrayDestroy(pTaskLevel);
14✔
217

218
  return NULL;
14✔
219
}
220

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

226
  if (pStream->outputSchema.nCols || pStream->outputSchema.pSchema) {
11!
227
    taosMemoryFree(pStream->outputSchema.pSchema);
10!
228
  }
229

230
  pStream->pTaskList = freeStreamTasks(pStream->pTaskList);
11✔
231
  pStream->pHTaskList = freeStreamTasks(pStream->pHTaskList);
11✔
232

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

238
  qDestroyQueryPlan(pStream->pPlan);
11✔
239
  pStream->pPlan = NULL;
11✔
240

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

550
  return tlen;
128✔
551
}
552

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

742
int32_t mndInitConfigObj(SConfigItem *pItem, SConfigObj *pObj) {
1,246✔
743
  tstrncpy(pObj->name, pItem->name, CFG_NAME_MAX_LEN);
1,246✔
744
  pObj->dtype = pItem->dtype;
1,246✔
745
  switch (pItem->dtype) {
1,246!
746
    case CFG_DTYPE_NONE:
×
747
      break;
×
748
    case CFG_DTYPE_BOOL:
266✔
749
      pObj->bval = pItem->bval;
266✔
750
      break;
266✔
751
    case CFG_DTYPE_INT32:
644✔
752
      pObj->i32 = pItem->i32;
644✔
753
      break;
644✔
754
    case CFG_DTYPE_INT64:
112✔
755
      pObj->i64 = pItem->i64;
112✔
756
      break;
112✔
757
    case CFG_DTYPE_FLOAT:
42✔
758
    case CFG_DTYPE_DOUBLE:
759
      pObj->fval = pItem->fval;
42✔
760
      break;
42✔
761
    case CFG_DTYPE_STRING:
182✔
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);
182!
767
      if (pObj->str == NULL) {
182!
768
        taosMemoryFree(pObj);
×
769
        return TSDB_CODE_OUT_OF_MEMORY;
×
770
      }
771
      break;
182✔
772
  }
773
  return TSDB_CODE_SUCCESS;
1,246✔
774
}
775

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

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

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

840
int32_t tEncodeSConfigObj(SEncoder *pEncoder, const SConfigObj *pObj) {
8,684✔
841
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
8,684!
842
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
17,368!
843

844
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->dtype));
17,368!
845
  switch (pObj->dtype) {
8,684!
846
    case CFG_DTYPE_BOOL:
1,824✔
847
      TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->bval));
3,648!
848
      break;
1,824✔
849
    case CFG_DTYPE_INT32:
4,556✔
850
      TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->i32));
9,112!
851
      break;
4,556✔
852
    case CFG_DTYPE_INT64:
768✔
853
      TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->i64));
1,536!
854
      break;
768✔
855
    case CFG_DTYPE_FLOAT:
288✔
856
    case CFG_DTYPE_DOUBLE:
857
      TAOS_CHECK_RETURN(tEncodeFloat(pEncoder, pObj->fval));
576!
858
      break;
288✔
859
    case CFG_DTYPE_STRING:
1,248✔
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,248!
865
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->str));
2,496!
866
      } else {
867
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
×
868
      }
869
      break;
1,248✔
870
    default:
×
871
      break;
×
872
  }
873
  tEndEncode(pEncoder);
8,684✔
874
  return pEncoder->pos;
8,684✔
875
}
876

877
int32_t tDecodeSConfigObj(SDecoder *pDecoder, SConfigObj *pObj) {
1,898✔
878
  TAOS_CHECK_RETURN(tStartDecode(pDecoder));
1,898!
879
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->name));
1,898!
880
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, (int32_t *)&pObj->dtype));
3,796!
881
  switch (pObj->dtype) {
1,898!
882
    case CFG_DTYPE_NONE:
×
883
      break;
×
884
    case CFG_DTYPE_BOOL:
399✔
885
      TAOS_CHECK_RETURN(tDecodeBool(pDecoder, &pObj->bval));
399!
886
      break;
399✔
887
    case CFG_DTYPE_INT32:
995✔
888
      TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->i32));
1,990!
889
      break;
995✔
890
    case CFG_DTYPE_INT64:
168✔
891
      TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->i64));
336!
892
      break;
168✔
893
    case CFG_DTYPE_FLOAT:
63✔
894
    case CFG_DTYPE_DOUBLE:
895
      TAOS_CHECK_RETURN(tDecodeFloat(pDecoder, &pObj->fval));
126!
896
      break;
63✔
897
    case CFG_DTYPE_STRING:
273✔
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));
546!
903
      break;
273✔
904
  }
905
  tEndDecode(pDecoder);
1,898✔
906
  TAOS_RETURN(TSDB_CODE_SUCCESS);
1,898✔
907
}
908

909
void tFreeSConfigObj(SConfigObj *obj) {
3,076✔
910
  if (obj == NULL) {
3,076!
911
    return;
×
912
  }
913
  if (obj->dtype == CFG_DTYPE_STRING || obj->dtype == CFG_DTYPE_DIR || obj->dtype == CFG_DTYPE_LOCALE ||
3,076!
914
      obj->dtype == CFG_DTYPE_CHARSET || obj->dtype == CFG_DTYPE_TIMEZONE) {
2,702✔
915
    taosMemoryFree(obj->str);
442!
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