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

taosdata / TDengine / #4335

20 Jun 2025 05:45AM UTC coverage: 60.571% (-2.3%) from 62.916%
#4335

push

travis-ci

web-flow
fix: compatibility ci problems. (#31430)

149119 of 315107 branches covered (47.32%)

Branch coverage included in aggregate %.

231167 of 312731 relevant lines covered (73.92%)

6342953.77 hits per line

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

74.92
/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) {
5,632✔
25
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
5,632!
26
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
11,264!
27

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

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

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

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

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

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

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

69
  int32_t sz = taosArrayGetSize(pObj->pTaskList);
5,632✔
70
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, sz));
5,632!
71
  for (int32_t i = 0; i < sz; i++) {
16,508✔
72
    SArray *pArray = taosArrayGetP(pObj->pTaskList, i);
10,876✔
73
    int32_t innerSz = taosArrayGetSize(pArray);
10,876✔
74
    TAOS_CHECK_RETURN(tEncodeI32(pEncoder, innerSz));
10,876!
75
    for (int32_t j = 0; j < innerSz; j++) {
36,888✔
76
      SStreamTask *pTask = taosArrayGetP(pArray, j);
26,012✔
77
      if (pTask->ver < SSTREAM_TASK_SUBTABLE_CHANGED_VER) {
26,012✔
78
        pTask->ver = SSTREAM_TASK_VER;
1✔
79
      }
80
      TAOS_CHECK_RETURN(tEncodeStreamTask(pEncoder, pTask));
26,012!
81
    }
82
  }
83

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

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

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

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

96
  tEndEncode(pEncoder);
5,632✔
97
  return pEncoder->pos;
5,632✔
98
}
99

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

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

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

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

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

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

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

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

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

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

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

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

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

197
  tEndDecode(pDecoder);
2,386✔
198
  TAOS_RETURN(code);
2,386✔
199
}
200

201
void *freeStreamTasks(SArray *pTaskLevel) {
6,912✔
202
  if (pTaskLevel == NULL) return NULL;
6,912✔
203
  int32_t numOfLevel = taosArrayGetSize(pTaskLevel);
4,506✔
204

205
  for (int32_t i = 0; i < numOfLevel; i++) {
11,906✔
206
    SArray *pLevel = taosArrayGetP(pTaskLevel, i);
7,400✔
207
    int32_t taskSz = taosArrayGetSize(pLevel);
7,400✔
208
    for (int32_t j = 0; j < taskSz; j++) {
25,100✔
209
      SStreamTask *pTask = taosArrayGetP(pLevel, j);
17,700✔
210
      tFreeStreamTask(pTask);
17,700✔
211
    }
212

213
    taosArrayDestroy(pLevel);
7,400✔
214
  }
215

216
  taosArrayDestroy(pTaskLevel);
4,506✔
217

218
  return NULL;
4,506✔
219
}
220

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

226
  if (pStream->outputSchema.nCols || pStream->outputSchema.pSchema) {
3,456!
227
    taosMemoryFree(pStream->outputSchema.pSchema);
3,449!
228
  }
229

230
  pStream->pTaskList = freeStreamTasks(pStream->pTaskList);
3,456✔
231
  pStream->pHTaskList = freeStreamTasks(pStream->pHTaskList);
3,456✔
232

233
  // tagSchema.pSchema
234
  if (pStream->tagSchema.nCols > 0) {
3,456✔
235
    taosMemoryFree(pStream->tagSchema.pSchema);
133!
236
  }
237

238
  qDestroyQueryPlan(pStream->pPlan);
3,456✔
239
  pStream->pPlan = NULL;
3,456✔
240

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

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

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

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

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

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

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

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

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

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

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

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

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

353
  *ppConsumer = pConsumer;
2,652✔
354
  return 0;
2,652✔
355

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

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

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

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

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

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

402
  // reb new topics
403
  if (pConsumer->rebNewTopics) {
6,032✔
404
    sz = taosArrayGetSize(pConsumer->rebNewTopics);
4,030✔
405
    tlen += taosEncodeFixedI32(buf, sz);
4,030✔
406
    for (int32_t i = 0; i < sz; i++) {
6,754✔
407
      char *topic = taosArrayGetP(pConsumer->rebNewTopics, i);
2,724✔
408
      tlen += taosEncodeString(buf, topic);
2,724✔
409
    }
410
  } else {
411
    tlen += taosEncodeFixedI32(buf, 0);
2,002✔
412
  }
413

414
  // reb removed topics
415
  if (pConsumer->rebRemovedTopics) {
6,032✔
416
    sz = taosArrayGetSize(pConsumer->rebRemovedTopics);
2,714✔
417
    tlen += taosEncodeFixedI32(buf, sz);
2,714✔
418
    for (int32_t i = 0; i < sz; i++) {
4,788✔
419
      char *topic = taosArrayGetP(pConsumer->rebRemovedTopics, i);
2,074✔
420
      tlen += taosEncodeString(buf, topic);
2,074✔
421
    }
422
  } else {
423
    tlen += taosEncodeFixedI32(buf, 0);
3,318✔
424
  }
425

426
  // lost topics
427
  if (pConsumer->assignedTopics) {
6,032✔
428
    sz = taosArrayGetSize(pConsumer->assignedTopics);
2,778✔
429
    tlen += taosEncodeFixedI32(buf, sz);
2,778✔
430
    for (int32_t i = 0; i < sz; i++) {
4,680✔
431
      char *topic = taosArrayGetP(pConsumer->assignedTopics, i);
1,902✔
432
      tlen += taosEncodeString(buf, topic);
1,902✔
433
    }
434
  } else {
435
    tlen += taosEncodeFixedI32(buf, 0);
3,254✔
436
  }
437

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

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

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

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

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

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

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

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

527
  return (void *)buf;
2,691✔
528
}
529

530
int32_t tEncodeOffRows(void **buf, SArray *offsetRows) {
5,322✔
531
  int32_t tlen = 0;
5,322✔
532
  int32_t szVgs = taosArrayGetSize(offsetRows);
5,322✔
533
  tlen += taosEncodeFixedI32(buf, szVgs);
5,322✔
534
  for (int32_t j = 0; j < szVgs; ++j) {
11,602✔
535
    OffsetRows *offRows = taosArrayGet(offsetRows, j);
6,280✔
536
    tlen += taosEncodeFixedI32(buf, offRows->vgId);
6,280✔
537
    tlen += taosEncodeFixedI64(buf, offRows->rows);
6,280✔
538
    tlen += taosEncodeFixedI8(buf, offRows->offset.type);
6,280✔
539
    if (offRows->offset.type == TMQ_OFFSET__SNAPSHOT_DATA || offRows->offset.type == TMQ_OFFSET__SNAPSHOT_META) {
6,280!
540
      tlen += taosEncodeFixedI64(buf, offRows->offset.uid);
366✔
541
      tlen += taosEncodeFixedI64(buf, offRows->offset.ts);
732✔
542
    } else if (offRows->offset.type == TMQ_OFFSET__LOG) {
5,914✔
543
      tlen += taosEncodeFixedI64(buf, offRows->offset.version);
10,568✔
544
    } else {
545
      // do nothing
546
    }
547
    tlen += taosEncodeFixedI64(buf, offRows->ever);
12,560✔
548
  }
549

550
  return tlen;
5,322✔
551
}
552

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

776
int32_t mndUpdateObj(SConfigObj *pObjNew, const char *name, char *value) {
45✔
777
  int32_t code = 0;
45✔
778
  switch (pObjNew->dtype) {
45!
779
    case CFG_DTYPE_BOOL: {
12✔
780
      bool tmp = false;
12✔
781
      if (strcasecmp(value, "true") == 0) {
12!
782
        tmp = true;
×
783
      }
784
      if (taosStr2Int32(value, NULL, 10) > 0) {
12✔
785
        tmp = true;
6✔
786
      }
787
      pObjNew->bval = tmp;
12✔
788
      break;
12✔
789
    }
790
    case CFG_DTYPE_INT32: {
28✔
791
      int32_t ival;
792
      TAOS_CHECK_RETURN(taosStrHumanToInt32(value, &ival));
28!
793
      pObjNew->i32 = ival;
28✔
794
      break;
28✔
795
    }
796
    case CFG_DTYPE_INT64: {
5✔
797
      int64_t ival;
798
      TAOS_CHECK_RETURN(taosStrHumanToInt64(value, &ival));
5!
799
      pObjNew->i64 = ival;
5✔
800
      break;
5✔
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;
45✔
828
}
829

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

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

840
int32_t tEncodeSConfigObj(SEncoder *pEncoder, const SConfigObj *pObj) {
1,058,568✔
841
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
1,058,568!
842
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
2,117,136!
843

844
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->dtype));
2,117,136!
845
  switch (pObj->dtype) {
1,058,568!
846
    case CFG_DTYPE_BOOL:
227,624✔
847
      TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->bval));
455,248!
848
      break;
227,624✔
849
    case CFG_DTYPE_INT32:
557,814✔
850
      TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->i32));
1,115,628!
851
      break;
557,814✔
852
    case CFG_DTYPE_INT64:
91,050✔
853
      TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->i64));
182,100!
854
      break;
91,050✔
855
    case CFG_DTYPE_FLOAT:
34,140✔
856
    case CFG_DTYPE_DOUBLE:
857
      TAOS_CHECK_RETURN(tEncodeFloat(pEncoder, pObj->fval));
68,280!
858
      break;
34,140✔
859
    case CFG_DTYPE_STRING:
147,940✔
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) {
147,940!
865
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->str));
295,880!
866
      } else {
867
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
×
868
      }
869
      break;
147,940✔
870
    default:
×
871
      break;
×
872
  }
873
  tEndEncode(pEncoder);
1,058,568✔
874
  return pEncoder->pos;
1,058,568✔
875
}
876

877
int32_t tDecodeSConfigObj(SDecoder *pDecoder, SConfigObj *pObj) {
206,093✔
878
  TAOS_CHECK_RETURN(tStartDecode(pDecoder));
206,093!
879
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->name));
206,093!
880
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, (int32_t *)&pObj->dtype));
412,186!
881
  switch (pObj->dtype) {
206,093!
882
    case CFG_DTYPE_NONE:
×
883
      break;
×
884
    case CFG_DTYPE_BOOL:
44,312✔
885
      TAOS_CHECK_RETURN(tDecodeBool(pDecoder, &pObj->bval));
44,312!
886
      break;
44,312✔
887
    case CFG_DTYPE_INT32:
108,616✔
888
      TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->i32));
217,232!
889
      break;
108,616✔
890
    case CFG_DTYPE_INT64:
17,725✔
891
      TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->i64));
35,450!
892
      break;
17,725✔
893
    case CFG_DTYPE_FLOAT:
6,645✔
894
    case CFG_DTYPE_DOUBLE:
895
      TAOS_CHECK_RETURN(tDecodeFloat(pDecoder, &pObj->fval));
13,290!
896
      break;
6,645✔
897
    case CFG_DTYPE_STRING:
28,795✔
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));
57,590!
903
      break;
28,795✔
904
  }
905
  tEndDecode(pDecoder);
206,093✔
906
  TAOS_RETURN(TSDB_CODE_SUCCESS);
206,093✔
907
}
908

909
void tFreeSConfigObj(SConfigObj *obj) {
360,199✔
910
  if (obj == NULL) {
360,199!
911
    return;
×
912
  }
913
  if (obj->dtype == CFG_DTYPE_STRING || obj->dtype == CFG_DTYPE_DIR || obj->dtype == CFG_DTYPE_LOCALE ||
360,199!
914
      obj->dtype == CFG_DTYPE_CHARSET || obj->dtype == CFG_DTYPE_TIMEZONE) {
317,618✔
915
    taosMemoryFree(obj->str);
50,323!
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