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

taosdata / TDengine / #4390

28 Jun 2025 01:36AM UTC coverage: 60.352% (-2.0%) from 62.344%
#4390

push

travis-ci

web-flow
enh/TS-5619-add-case-crypted-pass (#31508)

148724 of 315812 branches covered (47.09%)

Branch coverage included in aggregate %.

231175 of 313662 relevant lines covered (73.7%)

6194679.52 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,592✔
25
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
5,592!
26
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
11,184!
27

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

216
  taosArrayDestroy(pTaskLevel);
4,480✔
217

218
  return NULL;
4,480✔
219
}
220

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

402
  // reb new topics
403
  if (pConsumer->rebNewTopics) {
5,988✔
404
    sz = taosArrayGetSize(pConsumer->rebNewTopics);
3,984✔
405
    tlen += taosEncodeFixedI32(buf, sz);
3,984✔
406
    for (int32_t i = 0; i < sz; i++) {
6,686✔
407
      char *topic = taosArrayGetP(pConsumer->rebNewTopics, i);
2,702✔
408
      tlen += taosEncodeString(buf, topic);
2,702✔
409
    }
410
  } else {
411
    tlen += taosEncodeFixedI32(buf, 0);
2,004✔
412
  }
413

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

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

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

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

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

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

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

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

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

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

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

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

550
  return tlen;
5,286✔
551
}
552

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

742
int32_t mndInitConfigObj(SConfigItem *pItem, SConfigObj *pObj) {
155,682✔
743
  tstrncpy(pObj->name, pItem->name, CFG_NAME_MAX_LEN);
155,682✔
744
  pObj->dtype = pItem->dtype;
155,682✔
745
  switch (pItem->dtype) {
155,682!
746
    case CFG_DTYPE_NONE:
×
747
      break;
×
748
    case CFG_DTYPE_BOOL:
33,480✔
749
      pObj->bval = pItem->bval;
33,480✔
750
      break;
33,480✔
751
    case CFG_DTYPE_INT32:
80,352✔
752
      pObj->i32 = pItem->i32;
80,352✔
753
      break;
80,352✔
754
    case CFG_DTYPE_INT64:
13,392✔
755
      pObj->i64 = pItem->i64;
13,392✔
756
      break;
13,392✔
757
    case CFG_DTYPE_FLOAT:
5,022✔
758
    case CFG_DTYPE_DOUBLE:
759
      pObj->fval = pItem->fval;
5,022✔
760
      break;
5,022✔
761
    case CFG_DTYPE_STRING:
23,436✔
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);
23,436!
767
      if (pObj->str == NULL) {
23,436!
768
        taosMemoryFree(pObj);
×
769
        return TSDB_CODE_OUT_OF_MEMORY;
×
770
      }
771
      break;
23,436✔
772
  }
773
  return TSDB_CODE_SUCCESS;
155,682✔
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,682✔
831
  SConfigObj obj;
832
  memset(&obj, 0, sizeof(SConfigObj));
1,682✔
833

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

840
int32_t tEncodeSConfigObj(SEncoder *pEncoder, const SConfigObj *pObj) {
1,076,152✔
841
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
1,076,152!
842
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
2,152,304!
843

844
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->dtype));
2,152,304!
845
  switch (pObj->dtype) {
1,076,152!
846
    case CFG_DTYPE_BOOL:
228,944✔
847
      TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->bval));
457,888!
848
      break;
228,944✔
849
    case CFG_DTYPE_INT32:
561,048✔
850
      TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->i32));
1,122,096!
851
      break;
561,048✔
852
    case CFG_DTYPE_INT64:
91,578✔
853
      TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->i64));
183,156!
854
      break;
91,578✔
855
    case CFG_DTYPE_FLOAT:
34,338✔
856
    case CFG_DTYPE_DOUBLE:
857
      TAOS_CHECK_RETURN(tEncodeFloat(pEncoder, pObj->fval));
68,676!
858
      break;
34,338✔
859
    case CFG_DTYPE_STRING:
160,244✔
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) {
160,244!
865
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->str));
320,488!
866
      } else {
867
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
×
868
      }
869
      break;
160,244✔
870
    default:
×
871
      break;
×
872
  }
873
  tEndEncode(pEncoder);
1,076,152✔
874
  return pEncoder->pos;
1,076,152✔
875
}
876

877
int32_t tDecodeSConfigObj(SDecoder *pDecoder, SConfigObj *pObj) {
209,906✔
878
  TAOS_CHECK_RETURN(tStartDecode(pDecoder));
209,906!
879
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->name));
209,906!
880
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, (int32_t *)&pObj->dtype));
419,812!
881
  switch (pObj->dtype) {
209,906!
882
    case CFG_DTYPE_NONE:
×
883
      break;
×
884
    case CFG_DTYPE_BOOL:
44,652✔
885
      TAOS_CHECK_RETURN(tDecodeBool(pDecoder, &pObj->bval));
44,652!
886
      break;
44,652✔
887
    case CFG_DTYPE_INT32:
109,449✔
888
      TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->i32));
218,898!
889
      break;
109,449✔
890
    case CFG_DTYPE_INT64:
17,861✔
891
      TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->i64));
35,722!
892
      break;
17,861✔
893
    case CFG_DTYPE_FLOAT:
6,696✔
894
    case CFG_DTYPE_DOUBLE:
895
      TAOS_CHECK_RETURN(tDecodeFloat(pDecoder, &pObj->fval));
13,392!
896
      break;
6,696✔
897
    case CFG_DTYPE_STRING:
31,248✔
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));
62,496!
903
      break;
31,248✔
904
  }
905
  tEndDecode(pDecoder);
209,906✔
906
  TAOS_RETURN(TSDB_CODE_SUCCESS);
209,906✔
907
}
908

909
void tFreeSConfigObj(SConfigObj *obj) {
367,172✔
910
  if (obj == NULL) {
367,172!
911
    return;
×
912
  }
913
  if (obj->dtype == CFG_DTYPE_STRING || obj->dtype == CFG_DTYPE_DIR || obj->dtype == CFG_DTYPE_LOCALE ||
367,172!
914
      obj->dtype == CFG_DTYPE_CHARSET || obj->dtype == CFG_DTYPE_TIMEZONE) {
320,324✔
915
    taosMemoryFree(obj->str);
54,656!
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