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

taosdata / TDengine / #4712

06 Sep 2025 04:27PM UTC coverage: 58.144% (-1.0%) from 59.134%
#4712

push

travis-ci

GitHub
test: update case description (#32878)

133123 of 291691 branches covered (45.64%)

Branch coverage included in aggregate %.

201244 of 283375 relevant lines covered (71.02%)

5637899.03 hits per line

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

77.56
/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
int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) {
1,494✔
22
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
1,494!
23

24
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
2,988!
25
  TAOS_CHECK_RETURN(tSerializeSCMCreateStreamReqImpl(pEncoder, pObj->pCreate));
1,494!
26

27
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->mainSnodeId));
2,988!
28
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->userStopped));
2,988!
29
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->createTime));
2,988!
30
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->updateTime));
2,988!
31

32
  tEndEncode(pEncoder);
1,494✔
33
  return pEncoder->pos;
1,494✔
34
}
35

36
int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj, int32_t sver) {
421✔
37
  int32_t code = 0;
421✔
38
  int32_t lino = 0;
421✔
39
  TAOS_CHECK_RETURN(tStartDecode(pDecoder));
421!
40

41
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->name));
421!
42
  pObj->pCreate = taosMemoryCalloc(1, sizeof(*pObj->pCreate));
421!
43
  if (NULL == pObj) {
421!
44
    TAOS_CHECK_EXIT(terrno);
×
45
  }
46
  
47
  TAOS_CHECK_RETURN(tDeserializeSCMCreateStreamReqImpl(pDecoder, pObj->pCreate));
421!
48

49
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->mainSnodeId));
842!
50
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->userStopped));
842!
51
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->createTime));
842!
52
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->updateTime));
842!
53

54
_exit:
421✔
55

56
  tEndDecode(pDecoder);
421✔
57
  tDecoderClear(pDecoder);  
421✔
58
  
59
  TAOS_RETURN(code);
421✔
60
}
61

62
void tFreeStreamObj(SStreamObj *pStream) {
844✔
63
  tFreeSCMCreateStreamReq(pStream->pCreate);
844✔
64
  taosMemoryFreeClear(pStream->pCreate);
844!
65
}
844✔
66

67
void freeSMqConsumerEp(void* data) {
1,493✔
68
  if (data == NULL) return;
1,493!
69
  SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)data;
1,493✔
70
  taosArrayDestroy(pConsumerEp->vgs);
1,493✔
71
  pConsumerEp->vgs = NULL;
1,493✔
72
  taosArrayDestroy(pConsumerEp->offsetRows);
1,493✔
73
  pConsumerEp->offsetRows = NULL;
1,493✔
74
}
75

76
int32_t tEncodeSMqVgEp(void **buf, const SMqVgEp *pVgEp) {
6,600✔
77
  int32_t tlen = 0;
6,600✔
78
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
6,600✔
79
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
6,600✔
80
  return tlen;
6,600✔
81
}
82

83
void *tDecodeSMqVgEp(const void *buf, SMqVgEp *pVgEp, int8_t sver) {
2,985✔
84
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
2,985!
85
  if (sver == 1) {
2,985!
86
    uint64_t size = 0;
×
87
    buf = taosDecodeVariantU64(buf, &size);
×
88
    buf = POINTER_SHIFT(buf, size);
×
89
  }
90
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
2,985✔
91
  return (void *)buf;
2,985✔
92
}
93

94
static void *topicNameDup(void *p) { return taosStrdup((char *)p); }
425!
95

96
int32_t tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, char *topic, SCMSubscribeReq *subscribe,
1,819✔
97
                           SMqConsumerObj **ppConsumer) {
98
  int32_t         code = 0;
1,819✔
99
  SMqConsumerObj *pConsumer = taosMemoryCalloc(1, sizeof(SMqConsumerObj));
1,819!
100
  if (pConsumer == NULL) {
1,819!
101
    code = terrno;
×
102
    goto END;
×
103
  }
104

105
  pConsumer->consumerId = consumerId;
1,819✔
106
  (void)memcpy(pConsumer->cgroup, cgroup, TSDB_CGROUP_LEN);
1,819✔
107

108
  pConsumer->epoch = 0;
1,819✔
109
  pConsumer->status = MQ_CONSUMER_STATUS_REBALANCE;
1,819✔
110
  pConsumer->hbStatus = 0;
1,819✔
111
  pConsumer->pollStatus = 0;
1,819✔
112

113
  taosInitRWLatch(&pConsumer->lock);
1,819✔
114
  pConsumer->createTime = taosGetTimestampMs();
1,819✔
115
  pConsumer->updateType = updateType;
1,819✔
116

117
  if (updateType == CONSUMER_ADD_REB) {
1,819✔
118
    pConsumer->rebNewTopics = taosArrayInit(0, sizeof(void *));
430✔
119
    if (pConsumer->rebNewTopics == NULL) {
430!
120
      code = terrno;
×
121
      goto END;
×
122
    }
123

124
    char *topicTmp = taosStrdup(topic);
430!
125
    if (taosArrayPush(pConsumer->rebNewTopics, &topicTmp) == NULL) {
860!
126
      code = terrno;
×
127
      goto END;
×
128
    }
129
  } else if (updateType == CONSUMER_REMOVE_REB) {
1,389✔
130
    pConsumer->rebRemovedTopics = taosArrayInit(0, sizeof(void *));
328✔
131
    if (pConsumer->rebRemovedTopics == NULL) {
328!
132
      code = terrno;
×
133
      goto END;
×
134
    }
135
    char *topicTmp = taosStrdup(topic);
328!
136
    if (taosArrayPush(pConsumer->rebRemovedTopics, &topicTmp) == NULL) {
656!
137
      code = terrno;
×
138
      goto END;
×
139
    }
140
  } else if (updateType == CONSUMER_INSERT_SUB) {
1,061✔
141
    tstrncpy(pConsumer->clientId, subscribe->clientId, tListLen(pConsumer->clientId));
420✔
142
    pConsumer->withTbName = subscribe->withTbName;
420✔
143
    pConsumer->autoCommit = subscribe->autoCommit;
420✔
144
    pConsumer->autoCommitInterval = subscribe->autoCommitInterval;
420✔
145
    pConsumer->resetOffsetCfg = subscribe->resetOffsetCfg;
420✔
146
    pConsumer->maxPollIntervalMs = subscribe->maxPollIntervalMs;
420✔
147
    pConsumer->sessionTimeoutMs = subscribe->sessionTimeoutMs;
420✔
148
    tstrncpy(pConsumer->user, subscribe->user, TSDB_USER_LEN);
420✔
149
    tstrncpy(pConsumer->fqdn, subscribe->fqdn, TSDB_FQDN_LEN);
420✔
150

151
    pConsumer->rebNewTopics = taosArrayDup(subscribe->topicNames, topicNameDup);
420✔
152
    if (pConsumer->rebNewTopics == NULL) {
420!
153
      code = terrno;
×
154
      goto END;
×
155
    }
156
    pConsumer->assignedTopics = subscribe->topicNames;
420✔
157
    subscribe->topicNames = NULL;
420✔
158
  } else if (updateType == CONSUMER_UPDATE_SUB) {
641✔
159
    pConsumer->assignedTopics = subscribe->topicNames;
332✔
160
    subscribe->topicNames = NULL;
332✔
161
  }
162

163
  *ppConsumer = pConsumer;
1,819✔
164
  return 0;
1,819✔
165

166
END:
×
167
  tDeleteSMqConsumerObj(pConsumer);
×
168
  return code;
×
169
}
170

171
void tClearSMqConsumerObj(SMqConsumerObj *pConsumer) {
6,539✔
172
  if (pConsumer == NULL) return;
6,539✔
173
  taosArrayDestroyP(pConsumer->currentTopics, NULL);
3,677✔
174
  taosArrayDestroyP(pConsumer->rebNewTopics, NULL);
3,677✔
175
  taosArrayDestroyP(pConsumer->rebRemovedTopics, NULL);
3,677✔
176
  taosArrayDestroyP(pConsumer->assignedTopics, NULL);
3,677✔
177
}
178

179
void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer) {
4,681✔
180
  tClearSMqConsumerObj(pConsumer);
4,681✔
181
  taosMemoryFree(pConsumer);
4,681!
182
}
4,681✔
183

184
int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
4,342✔
185
  int32_t tlen = 0;
4,342✔
186
  int32_t sz;
187
  tlen += taosEncodeFixedI64(buf, pConsumer->consumerId);
4,342✔
188
  tlen += taosEncodeString(buf, pConsumer->clientId);
4,342✔
189
  tlen += taosEncodeString(buf, pConsumer->cgroup);
4,342✔
190
  tlen += taosEncodeFixedI8(buf, pConsumer->updateType);
4,342✔
191
  tlen += taosEncodeFixedI32(buf, pConsumer->epoch);
4,342✔
192
  tlen += taosEncodeFixedI32(buf, pConsumer->status);
4,342✔
193

194
  tlen += taosEncodeFixedI32(buf, pConsumer->pid);
4,342✔
195
  tlen += taosEncodeSEpSet(buf, &pConsumer->ep);
4,342✔
196
  tlen += taosEncodeFixedI64(buf, pConsumer->createTime);
4,342✔
197
  tlen += taosEncodeFixedI64(buf, pConsumer->subscribeTime);
4,342✔
198
  tlen += taosEncodeFixedI64(buf, pConsumer->rebalanceTime);
4,342✔
199

200
  // current topics
201
  if (pConsumer->currentTopics) {
4,342✔
202
    sz = taosArrayGetSize(pConsumer->currentTopics);
726✔
203
    tlen += taosEncodeFixedI32(buf, sz);
726✔
204
    for (int32_t i = 0; i < sz; i++) {
1,152✔
205
      char *topic = taosArrayGetP(pConsumer->currentTopics, i);
426✔
206
      tlen += taosEncodeString(buf, topic);
426✔
207
    }
208
  } else {
209
    tlen += taosEncodeFixedI32(buf, 0);
3,616✔
210
  }
211

212
  // reb new topics
213
  if (pConsumer->rebNewTopics) {
4,342✔
214
    sz = taosArrayGetSize(pConsumer->rebNewTopics);
3,068✔
215
    tlen += taosEncodeFixedI32(buf, sz);
3,068✔
216
    for (int32_t i = 0; i < sz; i++) {
4,994✔
217
      char *topic = taosArrayGetP(pConsumer->rebNewTopics, i);
1,926✔
218
      tlen += taosEncodeString(buf, topic);
1,926✔
219
    }
220
  } else {
221
    tlen += taosEncodeFixedI32(buf, 0);
1,274✔
222
  }
223

224
  // reb removed topics
225
  if (pConsumer->rebRemovedTopics) {
4,342✔
226
    sz = taosArrayGetSize(pConsumer->rebRemovedTopics);
2,024✔
227
    tlen += taosEncodeFixedI32(buf, sz);
2,024✔
228
    for (int32_t i = 0; i < sz; i++) {
3,326✔
229
      char *topic = taosArrayGetP(pConsumer->rebRemovedTopics, i);
1,302✔
230
      tlen += taosEncodeString(buf, topic);
1,302✔
231
    }
232
  } else {
233
    tlen += taosEncodeFixedI32(buf, 0);
2,318✔
234
  }
235

236
  // lost topics
237
  if (pConsumer->assignedTopics) {
4,342✔
238
    sz = taosArrayGetSize(pConsumer->assignedTopics);
2,208✔
239
    tlen += taosEncodeFixedI32(buf, sz);
2,208✔
240
    for (int32_t i = 0; i < sz; i++) {
3,696✔
241
      char *topic = taosArrayGetP(pConsumer->assignedTopics, i);
1,488✔
242
      tlen += taosEncodeString(buf, topic);
1,488✔
243
    }
244
  } else {
245
    tlen += taosEncodeFixedI32(buf, 0);
2,134✔
246
  }
247

248
  tlen += taosEncodeFixedI8(buf, pConsumer->withTbName);
4,342✔
249
  tlen += taosEncodeFixedI8(buf, pConsumer->autoCommit);
4,342✔
250
  tlen += taosEncodeFixedI32(buf, pConsumer->autoCommitInterval);
4,342✔
251
  tlen += taosEncodeFixedI32(buf, pConsumer->resetOffsetCfg);
4,342✔
252
  tlen += taosEncodeFixedI32(buf, pConsumer->maxPollIntervalMs);
4,342✔
253
  tlen += taosEncodeFixedI32(buf, pConsumer->sessionTimeoutMs);
4,342✔
254
  tlen += taosEncodeString(buf, pConsumer->user);
4,342✔
255
  tlen += taosEncodeString(buf, pConsumer->fqdn);
4,342✔
256
  return tlen;
4,342✔
257
}
258

259
void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer, int8_t sver) {
1,858✔
260
  int32_t sz;
261
  buf = taosDecodeFixedI64(buf, &pConsumer->consumerId);
1,858!
262
  buf = taosDecodeStringTo(buf, pConsumer->clientId);
1,858✔
263
  buf = taosDecodeStringTo(buf, pConsumer->cgroup);
1,858✔
264
  buf = taosDecodeFixedI8(buf, &pConsumer->updateType);
1,858✔
265
  buf = taosDecodeFixedI32(buf, &pConsumer->epoch);
1,858!
266
  buf = taosDecodeFixedI32(buf, &pConsumer->status);
1,858!
267

268
  buf = taosDecodeFixedI32(buf, &pConsumer->pid);
1,858!
269
  buf = taosDecodeSEpSet(buf, &pConsumer->ep);
1,858✔
270
  buf = taosDecodeFixedI64(buf, &pConsumer->createTime);
1,858!
271
  buf = taosDecodeFixedI64(buf, &pConsumer->subscribeTime);
1,858!
272
  buf = taosDecodeFixedI64(buf, &pConsumer->rebalanceTime);
3,716!
273

274
  // current topics
275
  buf = taosDecodeFixedI32(buf, &sz);
1,858✔
276
  pConsumer->currentTopics = taosArrayInit(sz, sizeof(void *));
1,858✔
277
  if (pConsumer->currentTopics == NULL) {
1,858!
278
    return NULL;
×
279
  }
280
  for (int32_t i = 0; i < sz; i++) {
1,878✔
281
    char *topic;
282
    buf = taosDecodeString(buf, &topic);
20✔
283
    if (taosArrayPush(pConsumer->currentTopics, &topic) == NULL) {
40!
284
      return NULL;
×
285
    }
286
  }
287

288
  // reb new topics
289
  buf = taosDecodeFixedI32(buf, &sz);
1,858✔
290
  pConsumer->rebNewTopics = taosArrayInit(sz, sizeof(void *));
1,858✔
291
  for (int32_t i = 0; i < sz; i++) {
2,730✔
292
    char *topic;
293
    buf = taosDecodeString(buf, &topic);
872✔
294
    if (taosArrayPush(pConsumer->rebNewTopics, &topic) == NULL) {
1,744!
295
      return NULL;
×
296
    }
297
  }
298

299
  // reb removed topics
300
  buf = taosDecodeFixedI32(buf, &sz);
1,858✔
301
  pConsumer->rebRemovedTopics = taosArrayInit(sz, sizeof(void *));
1,858✔
302
  for (int32_t i = 0; i < sz; i++) {
2,519✔
303
    char *topic;
304
    buf = taosDecodeString(buf, &topic);
661✔
305
    if (taosArrayPush(pConsumer->rebRemovedTopics, &topic) == NULL) {
1,322!
306
      return NULL;
×
307
    }
308
  }
309

310
  // reb removed topics
311
  buf = taosDecodeFixedI32(buf, &sz);
1,858✔
312
  pConsumer->assignedTopics = taosArrayInit(sz, sizeof(void *));
1,858✔
313
  for (int32_t i = 0; i < sz; i++) {
2,314✔
314
    char *topic;
315
    buf = taosDecodeString(buf, &topic);
456✔
316
    if (taosArrayPush(pConsumer->assignedTopics, &topic) == NULL) {
912!
317
      return NULL;
×
318
    }
319
  }
320

321
  if (sver > 1) {
1,858!
322
    buf = taosDecodeFixedI8(buf, &pConsumer->withTbName);
1,858✔
323
    buf = taosDecodeFixedI8(buf, &pConsumer->autoCommit);
1,858✔
324
    buf = taosDecodeFixedI32(buf, &pConsumer->autoCommitInterval);
1,858!
325
    buf = taosDecodeFixedI32(buf, &pConsumer->resetOffsetCfg);
3,716!
326
  }
327
  if (sver > 2) {
1,858!
328
    buf = taosDecodeFixedI32(buf, &pConsumer->maxPollIntervalMs);
1,858!
329
    buf = taosDecodeFixedI32(buf, &pConsumer->sessionTimeoutMs);
1,858!
330
    buf = taosDecodeStringTo(buf, pConsumer->user);
1,858✔
331
    buf = taosDecodeStringTo(buf, pConsumer->fqdn);
3,716✔
332
  } else {
333
    pConsumer->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
334
    pConsumer->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
335
  }
336

337
  return (void *)buf;
1,858✔
338
}
339

340
int32_t tEncodeOffRows(void **buf, SArray *offsetRows) {
3,910✔
341
  int32_t tlen = 0;
3,910✔
342
  int32_t szVgs = taosArrayGetSize(offsetRows);
3,910✔
343
  tlen += taosEncodeFixedI32(buf, szVgs);
3,910✔
344
  for (int32_t j = 0; j < szVgs; ++j) {
8,302✔
345
    OffsetRows *offRows = taosArrayGet(offsetRows, j);
4,392✔
346
    tlen += taosEncodeFixedI32(buf, offRows->vgId);
4,392✔
347
    tlen += taosEncodeFixedI64(buf, offRows->rows);
4,392✔
348
    tlen += taosEncodeFixedI8(buf, offRows->offset.type);
4,392✔
349
    if (offRows->offset.type == TMQ_OFFSET__SNAPSHOT_DATA || offRows->offset.type == TMQ_OFFSET__SNAPSHOT_META) {
4,392!
350
      tlen += taosEncodeFixedI64(buf, offRows->offset.uid);
278✔
351
      tlen += taosEncodeFixedI64(buf, offRows->offset.ts);
556✔
352
    } else if (offRows->offset.type == TMQ_OFFSET__LOG) {
4,114✔
353
      tlen += taosEncodeFixedI64(buf, offRows->offset.version);
7,264✔
354
    } else {
355
      // do nothing
356
    }
357
    tlen += taosEncodeFixedI64(buf, offRows->ever);
8,784✔
358
  }
359

360
  return tlen;
3,910✔
361
}
362

363
int32_t tEncodeSMqConsumerEp(void **buf, const SMqConsumerEp *pConsumerEp) {
1,358✔
364
  int32_t tlen = 0;
1,358✔
365
  tlen += taosEncodeFixedI64(buf, pConsumerEp->consumerId);
1,358✔
366
  int32_t sz = taosArrayGetSize(pConsumerEp->vgs);
1,358✔
367
  tlen += taosEncodeFixedI32(buf, sz);
1,358✔
368
  for (int32_t i = 0; i < sz; i++) {
4,154✔
369
    void* data = taosArrayGet(pConsumerEp->vgs, i);
2,796✔
370
    tlen += tEncodeSMqVgEp(buf, data);
2,796✔
371
  }
372

373
  return tlen + tEncodeOffRows(buf, pConsumerEp->offsetRows);
1,358✔
374
}
375

376
void *tDecodeOffRows(const void *buf, SArray **offsetRows, int8_t sver) {
1,512✔
377
  int32_t szVgs = 0;
1,512!
378
  buf = taosDecodeFixedI32(buf, &szVgs);
1,512✔
379
  if (szVgs > 0) {
1,512✔
380
    *offsetRows = taosArrayInit(szVgs, sizeof(OffsetRows));
624✔
381
    if (NULL == *offsetRows) return NULL;
624!
382
    for (int32_t j = 0; j < szVgs; ++j) {
2,586✔
383
      OffsetRows *offRows = taosArrayReserve(*offsetRows, 1);
1,962✔
384
      buf = taosDecodeFixedI32(buf, &offRows->vgId);
1,962!
385
      buf = taosDecodeFixedI64(buf, &offRows->rows);
1,962!
386
      buf = taosDecodeFixedI8(buf, &offRows->offset.type);
1,962✔
387
      if (offRows->offset.type == TMQ_OFFSET__SNAPSHOT_DATA || offRows->offset.type == TMQ_OFFSET__SNAPSHOT_META) {
1,962!
388
        buf = taosDecodeFixedI64(buf, &offRows->offset.uid);
138!
389
        buf = taosDecodeFixedI64(buf, &offRows->offset.ts);
276!
390
      } else if (offRows->offset.type == TMQ_OFFSET__LOG) {
1,824✔
391
        buf = taosDecodeFixedI64(buf, &offRows->offset.version);
3,204!
392
      } else {
393
        // do nothing
394
      }
395
      if (sver > 2) {
1,962!
396
        buf = taosDecodeFixedI64(buf, &offRows->ever);
3,924!
397
      }
398
    }
399
  }
400
  return (void *)buf;
1,512✔
401
}
402

403
void *tDecodeSMqConsumerEp(const void *buf, SMqConsumerEp *pConsumerEp, int8_t sver) {
492✔
404
  buf = taosDecodeFixedI64(buf, &pConsumerEp->consumerId);
492!
405
  int32_t sz = 0;
492!
406
  buf = taosDecodeFixedI32(buf, &sz);
492✔
407
  pConsumerEp->vgs = taosArrayInit(sz, sizeof(SMqVgEp));
492✔
408
  if (pConsumerEp->vgs == NULL) {
492!
409
    return NULL;
×
410
  }
411
  for (int32_t i = 0; i < sz; i++) {
1,706✔
412
    SMqVgEp* vgEp = taosArrayReserve(pConsumerEp->vgs, 1);
1,214✔
413
    if (vgEp != NULL)
1,214!
414
      buf = tDecodeSMqVgEp(buf, vgEp, sver);
1,214✔
415
  }
416
  if (sver > 1) {
492!
417
    buf = tDecodeOffRows(buf, &pConsumerEp->offsetRows, sver);
492✔
418
  }
419

420
  return (void *)buf;
492✔
421
}
422

423
int32_t tNewSubscribeObj(const char *key, SMqSubscribeObj **ppSub) {
373✔
424
  int32_t          code = 0;
373✔
425
  SMqSubscribeObj *pSubObj = taosMemoryCalloc(1, sizeof(SMqSubscribeObj));
373!
426
  MND_TMQ_NULL_CHECK(pSubObj);
373!
427
  *ppSub = pSubObj;
373✔
428
  
429
  (void)memcpy(pSubObj->key, key, TSDB_SUBSCRIBE_KEY_LEN);
373✔
430
  taosInitRWLatch(&pSubObj->lock);
373✔
431
  pSubObj->vgNum = 0;
373✔
432
  pSubObj->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
373✔
433
  MND_TMQ_NULL_CHECK(pSubObj->consumerHash);
373!
434
  taosHashSetFreeFp(pSubObj->consumerHash, freeSMqConsumerEp);
373✔
435

436
  pSubObj->unassignedVgs = taosArrayInit(0, sizeof(SMqVgEp));
373✔
437
  MND_TMQ_NULL_CHECK(pSubObj->unassignedVgs);
373!
438

439
END:
373✔
440
  return code;
373✔
441
}
442

443
int32_t tCloneSubscribeObj(const SMqSubscribeObj *pSub, SMqSubscribeObj **ppSub) {
590✔
444
  int32_t          code = 0;
590✔
445
  SMqSubscribeObj *pSubNew = taosMemoryMalloc(sizeof(SMqSubscribeObj));
590!
446
  if (pSubNew == NULL) {
590!
447
    code = terrno;
×
448
    goto END;
×
449
  }
450
  *ppSub = pSubNew;
590✔
451

452
  (void)memcpy(pSubNew->key, pSub->key, TSDB_SUBSCRIBE_KEY_LEN);
590✔
453
  taosInitRWLatch(&pSubNew->lock);
590✔
454

455
  pSubNew->dbUid = pSub->dbUid;
590✔
456
  pSubNew->stbUid = pSub->stbUid;
590✔
457
  pSubNew->subType = pSub->subType;
590✔
458
  pSubNew->withMeta = pSub->withMeta;
590✔
459

460
  pSubNew->vgNum = pSub->vgNum;
590✔
461
  pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
590✔
462
  if (pSubNew->consumerHash == NULL) {
590!
463
    code = terrno;
×
464
    goto END;
×
465
  }
466
  taosHashSetFreeFp(pSubNew->consumerHash, freeSMqConsumerEp);
590✔
467

468
  void          *pIter = NULL;
590✔
469
  SMqConsumerEp *pConsumerEp = NULL;
590✔
470
  while (1) {
571✔
471
    pIter = taosHashIterate(pSub->consumerHash, pIter);
1,161✔
472
    if (pIter == NULL) break;
1,161✔
473
    pConsumerEp = (SMqConsumerEp *)pIter;
571✔
474
    SMqConsumerEp newEp = {
1,142✔
475
        .consumerId = pConsumerEp->consumerId,
571✔
476
        .vgs = taosArrayDup(pConsumerEp->vgs, NULL),
571✔
477
    };
478
    if ((code = taosHashPut(pSubNew->consumerHash, &newEp.consumerId, sizeof(int64_t), &newEp,
571!
479
                            sizeof(SMqConsumerEp))) != 0)
480
      goto END;
×
481
  }
482
  pSubNew->unassignedVgs = taosArrayDup(pSub->unassignedVgs, NULL);
590✔
483
  if (pSubNew->unassignedVgs == NULL) {
590!
484
    code = terrno;
×
485
    goto END;
×
486
  }
487
  pSubNew->offsetRows = taosArrayDup(pSub->offsetRows, NULL);
590✔
488
  if (pSub->offsetRows != NULL && pSubNew->offsetRows == NULL) {
590!
489
    code = terrno;
×
490
    goto END;
×
491
  }
492
  (void)memcpy(pSubNew->dbName, pSub->dbName, TSDB_DB_FNAME_LEN);
590✔
493
  pSubNew->qmsg = taosStrdup(pSub->qmsg);
590!
494
  if (pSubNew->qmsg == NULL) {
590!
495
    code = terrno;
×
496
    goto END;
×
497
  }
498

499
END:
590✔
500
  return code;
590✔
501
}
502

503
void tDeleteSubscribeObj(SMqSubscribeObj *pSub) {
1,983✔
504
  if (pSub == NULL) return;
1,983!
505
  taosHashCleanup(pSub->consumerHash);
1,983✔
506
  pSub->consumerHash = NULL;
1,983✔
507
  taosArrayDestroy(pSub->unassignedVgs);
1,983✔
508
  pSub->unassignedVgs = NULL;
1,983✔
509
  taosMemoryFreeClear(pSub->qmsg);
1,983!
510
  taosArrayDestroy(pSub->offsetRows);
1,983✔
511
  pSub->offsetRows = NULL;
1,983✔
512
}
513

514
int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
2,552✔
515
  int32_t tlen = 0;
2,552✔
516
  tlen += taosEncodeString(buf, pSub->key);
2,552✔
517
  tlen += taosEncodeFixedI64(buf, pSub->dbUid);
2,552✔
518
  tlen += taosEncodeFixedI32(buf, pSub->vgNum);
2,552✔
519
  tlen += taosEncodeFixedI8(buf, pSub->subType);
2,552✔
520
  tlen += taosEncodeFixedI8(buf, pSub->withMeta);
2,552✔
521
  tlen += taosEncodeFixedI64(buf, pSub->stbUid);
2,552✔
522

523
  void   *pIter = NULL;
2,552✔
524
  int32_t sz = taosHashGetSize(pSub->consumerHash);
2,552✔
525
  tlen += taosEncodeFixedI32(buf, sz);
2,552✔
526

527
  int32_t cnt = 0;
2,552✔
528
  while (1) {
1,358✔
529
    pIter = taosHashIterate(pSub->consumerHash, pIter);
3,910✔
530
    if (pIter == NULL) break;
3,910✔
531
    SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
1,358✔
532
    tlen += tEncodeSMqConsumerEp(buf, pConsumerEp);
1,358✔
533
    cnt++;
1,358✔
534
  }
535
  if (cnt != sz) return -1;
2,552!
536
  int32_t len = taosArrayGetSize(pSub->unassignedVgs);
2,552✔
537
  tlen += taosEncodeFixedI32(buf, len);
2,552✔
538
  for (int32_t i = 0; i < len; i++) {
6,356✔
539
    void* data = taosArrayGet(pSub->unassignedVgs, i);
3,804✔
540
    tlen += tEncodeSMqVgEp(buf, data);
3,804✔
541
  }
542
  tlen += taosEncodeString(buf, pSub->dbName);
2,552✔
543

544
  tlen += tEncodeOffRows(buf, pSub->offsetRows);
2,552✔
545
  tlen += taosEncodeString(buf, pSub->qmsg);
2,552✔
546
  return tlen;
2,552✔
547
}
548

549
void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) {
1,020✔
550
  //
551
  buf = taosDecodeStringTo(buf, pSub->key);
1,020✔
552
  buf = taosDecodeFixedI64(buf, &pSub->dbUid);
1,020!
553
  buf = taosDecodeFixedI32(buf, &pSub->vgNum);
1,020!
554
  buf = taosDecodeFixedI8(buf, &pSub->subType);
1,020✔
555
  buf = taosDecodeFixedI8(buf, &pSub->withMeta);
1,020✔
556
  buf = taosDecodeFixedI64(buf, &pSub->stbUid);
2,040!
557

558
  int32_t sz;
559
  buf = taosDecodeFixedI32(buf, &sz);
1,020✔
560

561
  pSub->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
1,020✔
562
  if (pSub->consumerHash == NULL) {
1,020!
563
    return NULL;
×
564
  }
565
  taosHashSetFreeFp(pSub->consumerHash, freeSMqConsumerEp);
1,020✔
566

567
  for (int32_t i = 0; i < sz; i++) {
1,512✔
568
    SMqConsumerEp consumerEp = {0};
492✔
569
    buf = tDecodeSMqConsumerEp(buf, &consumerEp, sver);
492✔
570
    if (taosHashPut(pSub->consumerHash, &consumerEp.consumerId, sizeof(int64_t), &consumerEp, sizeof(SMqConsumerEp)) !=
492!
571
        0)
572
      return NULL;
×
573
  }
574

575
  int32_t len = 0;
1,020!
576
  buf = taosDecodeFixedI32(buf, &len);
1,020✔
577
  pSub->unassignedVgs = taosArrayInit(len, sizeof(SMqVgEp));
1,020✔
578
  if (pSub->unassignedVgs == NULL) {
1,020!
579
    return NULL;
×
580
  }
581
  for (int32_t i = 0; i < len; i++) {
2,791✔
582
    SMqVgEp* vgEp = taosArrayReserve(pSub->unassignedVgs, 1);
1,771✔
583
    if (vgEp != NULL)
1,771!
584
      buf = tDecodeSMqVgEp(buf, vgEp, sver);
1,771✔
585
  }
586

587
  buf = taosDecodeStringTo(buf, pSub->dbName);
1,020✔
588

589
  if (sver > 1) {
1,020!
590
    buf = tDecodeOffRows(buf, &pSub->offsetRows, sver);
1,020✔
591
    buf = taosDecodeString(buf, &pSub->qmsg);
2,040✔
592
  } else {
593
    pSub->qmsg = taosStrdup("");
×
594
  }
595
  return (void *)buf;
1,020✔
596
}
597

598
int32_t mndInitConfigObj(SConfigItem *pItem, SConfigObj *pObj) {
117,180✔
599
  tstrncpy(pObj->name, pItem->name, CFG_NAME_MAX_LEN);
117,180✔
600
  pObj->dtype = pItem->dtype;
117,180✔
601
  switch (pItem->dtype) {
117,180!
602
    case CFG_DTYPE_NONE:
×
603
      break;
×
604
    case CFG_DTYPE_BOOL:
25,110✔
605
      pObj->bval = pItem->bval;
25,110✔
606
      break;
25,110✔
607
    case CFG_DTYPE_INT32:
62,775✔
608
      pObj->i32 = pItem->i32;
62,775✔
609
      break;
62,775✔
610
    case CFG_DTYPE_INT64:
8,370✔
611
      pObj->i64 = pItem->i64;
8,370✔
612
      break;
8,370✔
613
    case CFG_DTYPE_FLOAT:
2,790✔
614
    case CFG_DTYPE_DOUBLE:
615
      pObj->fval = pItem->fval;
2,790✔
616
      break;
2,790✔
617
    case CFG_DTYPE_STRING:
18,135✔
618
    case CFG_DTYPE_DIR:
619
    case CFG_DTYPE_LOCALE:
620
    case CFG_DTYPE_CHARSET:
621
    case CFG_DTYPE_TIMEZONE:
622
      pObj->str = taosStrdup(pItem->str);
18,135!
623
      if (pObj->str == NULL) {
18,135!
624
        taosMemoryFree(pObj);
×
625
        return TSDB_CODE_OUT_OF_MEMORY;
×
626
      }
627
      break;
18,135✔
628
  }
629
  return TSDB_CODE_SUCCESS;
117,180✔
630
}
631

632
int32_t mndUpdateObj(SConfigObj *pObjNew, const char *name, char *value) {
42✔
633
  int32_t code = 0;
42✔
634
  switch (pObjNew->dtype) {
42!
635
    case CFG_DTYPE_BOOL: {
11✔
636
      bool tmp = false;
11✔
637
      if (strcasecmp(value, "true") == 0) {
11!
638
        tmp = true;
×
639
      }
640
      if (taosStr2Int32(value, NULL, 10) > 0) {
11✔
641
        tmp = true;
5✔
642
      }
643
      pObjNew->bval = tmp;
11✔
644
      break;
11✔
645
    }
646
    case CFG_DTYPE_INT32: {
25✔
647
      int32_t ival;
648
      TAOS_CHECK_RETURN(taosStrHumanToInt32(value, &ival));
25!
649
      pObjNew->i32 = ival;
25✔
650
      break;
25✔
651
    }
652
    case CFG_DTYPE_INT64: {
5✔
653
      int64_t ival;
654
      TAOS_CHECK_RETURN(taosStrHumanToInt64(value, &ival));
5!
655
      pObjNew->i64 = ival;
5✔
656
      break;
5✔
657
    }
658
    case CFG_DTYPE_FLOAT:
×
659
    case CFG_DTYPE_DOUBLE: {
660
      float dval = 0;
×
661
      TAOS_CHECK_RETURN(parseCfgReal(value, &dval));
×
662
      pObjNew->fval = dval;
×
663
      break;
×
664
    }
665
    case CFG_DTYPE_DIR:
1✔
666
    case CFG_DTYPE_TIMEZONE:
667
    case CFG_DTYPE_CHARSET:
668
    case CFG_DTYPE_LOCALE:
669
    case CFG_DTYPE_STRING: {
670
      pObjNew->str = taosStrdup(value);
1!
671
      if (pObjNew->str == NULL) {
1!
672
        code = terrno;
×
673
        return code;
×
674
      }
675
      break;
1✔
676
    }
677
    case CFG_DTYPE_NONE:
×
678
      break;
×
679
    default:
×
680
      code = TSDB_CODE_INVALID_CFG;
×
681
      break;
×
682
  }
683
  return code;
42✔
684
}
685

686
SConfigObj mndInitConfigVersion() {
1,419✔
687
  SConfigObj obj;
688
  memset(&obj, 0, sizeof(SConfigObj));
1,419✔
689

690
  tstrncpy(obj.name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
1,419✔
691
  obj.dtype = CFG_DTYPE_INT32;
1,419✔
692
  obj.i32 = 0;
1,419✔
693
  return obj;
1,419✔
694
}
695

696
int32_t tEncodeSConfigObj(SEncoder *pEncoder, const SConfigObj *pObj) {
830,422✔
697
  TAOS_CHECK_RETURN(tStartEncode(pEncoder));
830,422!
698
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
1,660,844!
699

700
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->dtype));
1,660,844!
701
  switch (pObj->dtype) {
830,422!
702
    case CFG_DTYPE_BOOL:
175,810✔
703
      TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->bval));
351,620!
704
      break;
175,810✔
705
    case CFG_DTYPE_INT32:
449,514✔
706
      TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->i32));
899,028!
707
      break;
449,514✔
708
    case CFG_DTYPE_INT64:
58,606✔
709
      TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->i64));
117,212!
710
      break;
58,606✔
711
    case CFG_DTYPE_FLOAT:
19,532✔
712
    case CFG_DTYPE_DOUBLE:
713
      TAOS_CHECK_RETURN(tEncodeFloat(pEncoder, pObj->fval));
39,064!
714
      break;
19,532✔
715
    case CFG_DTYPE_STRING:
126,960✔
716
    case CFG_DTYPE_DIR:
717
    case CFG_DTYPE_LOCALE:
718
    case CFG_DTYPE_CHARSET:
719
    case CFG_DTYPE_TIMEZONE:
720
      if (pObj->str != NULL) {
126,960!
721
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->str));
253,920!
722
      } else {
723
        TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
×
724
      }
725
      break;
126,960✔
726
    default:
×
727
      break;
×
728
  }
729
  tEndEncode(pEncoder);
830,422✔
730
  return pEncoder->pos;
830,422✔
731
}
732

733
int32_t tDecodeSConfigObj(SDecoder *pDecoder, SConfigObj *pObj) {
161,764✔
734
  TAOS_CHECK_RETURN(tStartDecode(pDecoder));
161,764!
735
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->name));
161,764!
736
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, (int32_t *)&pObj->dtype));
323,528!
737
  switch (pObj->dtype) {
161,764!
738
    case CFG_DTYPE_NONE:
×
739
      break;
×
740
    case CFG_DTYPE_BOOL:
34,191✔
741
      TAOS_CHECK_RETURN(tDecodeBool(pDecoder, &pObj->bval));
34,191!
742
      break;
34,191✔
743
    case CFG_DTYPE_INT32:
87,711✔
744
      TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->i32));
175,422!
745
      break;
87,711✔
746
    case CFG_DTYPE_INT64:
11,401✔
747
      TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->i64));
22,802!
748
      break;
11,401✔
749
    case CFG_DTYPE_FLOAT:
3,800✔
750
    case CFG_DTYPE_DOUBLE:
751
      TAOS_CHECK_RETURN(tDecodeFloat(pDecoder, &pObj->fval));
7,600!
752
      break;
3,800✔
753
    case CFG_DTYPE_STRING:
24,661✔
754
    case CFG_DTYPE_DIR:
755
    case CFG_DTYPE_LOCALE:
756
    case CFG_DTYPE_CHARSET:
757
    case CFG_DTYPE_TIMEZONE:
758
      TAOS_CHECK_RETURN(tDecodeCStrAlloc(pDecoder, &pObj->str));
49,322!
759
      break;
24,661✔
760
  }
761
  tEndDecode(pDecoder);
161,764✔
762
  TAOS_RETURN(TSDB_CODE_SUCCESS);
161,764✔
763
}
764

765
void tFreeSConfigObj(SConfigObj *obj) {
280,447✔
766
  if (obj == NULL) {
280,447!
767
    return;
×
768
  }
769
  if (obj->dtype == CFG_DTYPE_STRING || obj->dtype == CFG_DTYPE_DIR || obj->dtype == CFG_DTYPE_LOCALE ||
280,447!
770
      obj->dtype == CFG_DTYPE_CHARSET || obj->dtype == CFG_DTYPE_TIMEZONE) {
244,234✔
771
    taosMemoryFree(obj->str);
42,797!
772
  }
773
}
774

775
// SMqSubActionLogEntry *tCloneSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) {
776
//   SMqSubActionLogEntry *pEntryNew = taosMemoryMalloc(sizeof(SMqSubActionLogEntry));
777
//   if (pEntryNew == NULL) return NULL;
778
//   pEntryNew->epoch = pEntry->epoch;
779
//   pEntryNew->consumers = taosArrayDup(pEntry->consumers, (__array_item_dup_fn_t)tCloneSMqConsumerEp);
780
//   return pEntryNew;
781
// }
782
//
783
// void tDeleteSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) {
784
//   taosArrayDestroyEx(pEntry->consumers, (FDelete)tDeleteSMqConsumerEp);
785
// }
786

787
// int32_t tEncodeSMqSubActionLogEntry(void **buf, const SMqSubActionLogEntry *pEntry) {
788
//   int32_t tlen = 0;
789
//   tlen += taosEncodeFixedI32(buf, pEntry->epoch);
790
//   tlen += taosEncodeArray(buf, pEntry->consumers, (FEncode)tEncodeSMqSubActionLogEntry);
791
//   return tlen;
792
// }
793
//
794
// void *tDecodeSMqSubActionLogEntry(const void *buf, SMqSubActionLogEntry *pEntry) {
795
//   buf = taosDecodeFixedI32(buf, &pEntry->epoch);
796
//   buf = taosDecodeArray(buf, &pEntry->consumers, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry));
797
//   return (void *)buf;
798
// }
799

800
// SMqSubActionLogObj *tCloneSMqSubActionLogObj(SMqSubActionLogObj *pLog) {
801
//   SMqSubActionLogObj *pLogNew = taosMemoryMalloc(sizeof(SMqSubActionLogObj));
802
//   if (pLogNew == NULL) return pLogNew;
803
//   memcpy(pLogNew->key, pLog->key, TSDB_SUBSCRIBE_KEY_LEN);
804
//   pLogNew->logs = taosArrayDup(pLog->logs, (__array_item_dup_fn_t)tCloneSMqConsumerEp);
805
//   return pLogNew;
806
// }
807
//
808
// void tDeleteSMqSubActionLogObj(SMqSubActionLogObj *pLog) {
809
//   taosArrayDestroyEx(pLog->logs, (FDelete)tDeleteSMqConsumerEp);
810
// }
811

812
// int32_t tEncodeSMqSubActionLogObj(void **buf, const SMqSubActionLogObj *pLog) {
813
//   int32_t tlen = 0;
814
//   tlen += taosEncodeString(buf, pLog->key);
815
//   tlen += taosEncodeArray(buf, pLog->logs, (FEncode)tEncodeSMqSubActionLogEntry);
816
//   return tlen;
817
// }
818
//
819
// void *tDecodeSMqSubActionLogObj(const void *buf, SMqSubActionLogObj *pLog) {
820
//   buf = taosDecodeStringTo(buf, pLog->key);
821
//   buf = taosDecodeArray(buf, &pLog->logs, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry));
822
//   return (void *)buf;
823
// }
824
//
825
// int32_t tEncodeSMqOffsetObj(void **buf, const SMqOffsetObj *pOffset) {
826
//   int32_t tlen = 0;
827
//   tlen += taosEncodeString(buf, pOffset->key);
828
//   tlen += taosEncodeFixedI64(buf, pOffset->offset);
829
//   return tlen;
830
// }
831
//
832
// void *tDecodeSMqOffsetObj(void *buf, SMqOffsetObj *pOffset) {
833
//   buf = taosDecodeStringTo(buf, pOffset->key);
834
//   buf = taosDecodeFixedI64(buf, &pOffset->offset);
835
//   return buf;
836
// }
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