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

taosdata / TDengine / #3887

22 Apr 2025 05:36AM UTC coverage: 54.338% (-0.7%) from 55.04%
#3887

push

travis-ci

happyguoxy
Sync branches at 2025-04-22 13:35

171762 of 316101 relevant lines covered (54.34%)

1622197.57 hits per line

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

82.98
/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) {
28✔
25
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
28✔
26
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
56✔
27

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

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

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

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

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

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

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

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

84
  TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pEncoder, &pObj->outputSchema));
56✔
85

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

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

94
  TAOS_CHECK_RETURN(tEncodeCStrWithLen(pEncoder, pObj->reserve, sizeof(pObj->reserve) - 1));
56✔
95

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

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

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

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

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

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

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

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

136
  int32_t sz;
137
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &sz));
10✔
138

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

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

179
  TAOS_CHECK_RETURN(tDecodeSSchemaWrapper(pDecoder, &pObj->outputSchema));
20✔
180

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

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

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

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

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

213
    taosArrayDestroy(pLevel);
39✔
214
  }
215

216
  taosArrayDestroy(pTaskLevel);
19✔
217

218
  return NULL;
19✔
219
}
220

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

226
  if (pStream->outputSchema.nCols || pStream->outputSchema.pSchema) {
14✔
227
    taosMemoryFree(pStream->outputSchema.pSchema);
12✔
228
  }
229

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

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

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

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

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

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

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

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

284
static void *topicNameDup(void *p) { return taosStrdup((char *)p); }
46✔
285

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

464
  // current topics
465
  buf = taosDecodeFixedI32(buf, &sz);
213✔
466
  pConsumer->currentTopics = taosArrayInit(sz, sizeof(void *));
213✔
467
  if (pConsumer->currentTopics == NULL) {
213✔
468
    return NULL;
×
469
  }
470
  for (int32_t i = 0; i < sz; i++) {
213✔
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);
213✔
480
  pConsumer->rebNewTopics = taosArrayInit(sz, sizeof(void *));
213✔
481
  for (int32_t i = 0; i < sz; i++) {
305✔
482
    char *topic;
483
    buf = taosDecodeString(buf, &topic);
92✔
484
    if (taosArrayPush(pConsumer->rebNewTopics, &topic) == NULL) {
184✔
485
      return NULL;
×
486
    }
487
  }
488

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

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

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

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

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

550
  return tlen;
326✔
551
}
552

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

840
int32_t tEncodeSConfigObj(SEncoder *pEncoder, const SConfigObj *pObj) {
21,870✔
841
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
21,870✔
842
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
43,740✔
843

844
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->dtype));
43,740✔
845
  switch (pObj->dtype) {
21,870✔
846
    case CFG_DTYPE_BOOL:
4,598✔
847
      TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->bval));
9,196✔
848
      break;
4,598✔
849
    case CFG_DTYPE_INT32:
11,464✔
850
      TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->i32));
22,928✔
851
      break;
11,464✔
852
    case CFG_DTYPE_INT64:
1,936✔
853
      TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->i64));
3,872✔
854
      break;
1,936✔
855
    case CFG_DTYPE_FLOAT:
726✔
856
    case CFG_DTYPE_DOUBLE:
857
      TAOS_CHECK_RETURN(tEncodeFloat(pEncoder, pObj->fval));
1,452✔
858
      break;
726✔
859
    case CFG_DTYPE_STRING:
3,146✔
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) {
3,146✔
865
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->str));
6,292✔
866
      } else {
867
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
×
868
      }
869
      break;
3,146✔
870
    default:
×
871
      break;
×
872
  }
873
  tEndEncode(pEncoder);
21,870✔
874
  return pEncoder->pos;
21,870✔
875
}
876

877
int32_t tDecodeSConfigObj(SDecoder *pDecoder, SConfigObj *pObj) {
4,786✔
878
  TAOS_CHECK_RETURN(tStartDecode(pDecoder));
4,786✔
879
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->name));
4,786✔
880
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, (int32_t *)&pObj->dtype));
9,572✔
881
  switch (pObj->dtype) {
4,786✔
882
    case CFG_DTYPE_NONE:
×
883
      break;
×
884
    case CFG_DTYPE_BOOL:
1,007✔
885
      TAOS_CHECK_RETURN(tDecodeBool(pDecoder, &pObj->bval));
1,007✔
886
      break;
1,007✔
887
    case CFG_DTYPE_INT32:
2,507✔
888
      TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->i32));
5,014✔
889
      break;
2,507✔
890
    case CFG_DTYPE_INT64:
424✔
891
      TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->i64));
848✔
892
      break;
424✔
893
    case CFG_DTYPE_FLOAT:
159✔
894
    case CFG_DTYPE_DOUBLE:
895
      TAOS_CHECK_RETURN(tDecodeFloat(pDecoder, &pObj->fval));
318✔
896
      break;
159✔
897
    case CFG_DTYPE_STRING:
689✔
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));
1,378✔
903
      break;
689✔
904
  }
905
  tEndDecode(pDecoder);
4,786✔
906
  TAOS_RETURN(TSDB_CODE_SUCCESS);
4,786✔
907
}
908

909
void tFreeSConfigObj(SConfigObj *obj) {
7,772✔
910
  if (obj == NULL) {
7,772✔
911
    return;
×
912
  }
913
  if (obj->dtype == CFG_DTYPE_STRING || obj->dtype == CFG_DTYPE_DIR || obj->dtype == CFG_DTYPE_LOCALE ||
7,772✔
914
      obj->dtype == CFG_DTYPE_CHARSET || obj->dtype == CFG_DTYPE_TIMEZONE) {
6,826✔
915
    taosMemoryFree(obj->str);
1,118✔
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