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

taosdata / TDengine / #4892

20 Dec 2025 01:15PM UTC coverage: 65.571% (+0.02%) from 65.549%
#4892

push

travis-ci

web-flow
feat: support taos_connect_with func (#33952)

* feat: support taos_connect_with

* refactor: enhance connection options and add tests for taos_set_option and taos_connect_with

* fix: handle NULL keys and values in taos_connect_with options

* fix: revert TAOSWS_GIT_TAG to default value "main"

* docs: add TLS configuration options for WebSocket connections in documentation

* docs: modify zh docs and add en docs

* chore: update taos.cfg

* docs: add examples

* docs: add error handling for connection failure in example code

2 of 82 new or added lines in 3 files covered. (2.44%)

527 existing lines in 120 files now uncovered.

182859 of 278870 relevant lines covered (65.57%)

104634355.9 hits per line

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

80.5
/source/dnode/vnode/src/meta/metaEntry.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

16
#include "meta.h"
17
#include "osMemPool.h"
18
#include "osMemory.h"
19
#include "tencode.h"
20
#include "tmsg.h"
21

22
static bool schemasHasTypeMod(const SSchema *pSchema, int32_t nCols) {
668,433,458✔
23
  for (int32_t i = 0; i < nCols; i++) {
2,147,483,647✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
2,147,483,647✔
25
      return true;
38,315,566✔
26
    }
27
  }
28
  return false;
628,857,709✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
177,138,294✔
32
  if (pME->pExtSchemas) {
177,138,294✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
15,235,274✔
34
    bool                  hasTypeMods = false;
15,235,274✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
15,235,274✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
15,100,430✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
134,648✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
134,648✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
15,234,021✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,499,940,202✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
46
    }
47
  }
48
  return 0;
177,179,758✔
49
}
50

51
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
1,271,584✔
52
  const SColRefWrapper *pw = &pME->colRef;
1,271,584✔
53
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
2,543,168✔
54
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
2,543,168✔
55
  uTrace("encode cols:%d", pw->nCols);
1,271,584✔
56

57
  for (int32_t i = 0; i < pw->nCols; i++) {
12,087,698✔
58
    SColRef *p = &pw->pColRef[i];
10,816,114✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
21,632,228✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
21,632,228✔
61
    if (p->hasRef) {
10,816,114✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
12,116,780✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
12,116,780✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
12,116,780✔
65
    }
66
  }
67
  return 0;
1,271,584✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
639,834,152✔
71
  bool hasExtSchema = false;
639,834,152✔
72
  SSchemaWrapper* pSchWrapper = NULL;
639,834,152✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
639,834,152✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
634,944,531✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
4,954,275✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
4,954,275✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
639,961,629✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
639,995,783✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
52,274,537✔
84
    if (pME->pExtSchemas == NULL) {
26,131,569✔
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
1,886,954,335✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
2,147,483,647✔
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
613,853,511✔
93
  }
94

95
  return 0;
640,008,374✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
13,382,778✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
13,382,778✔
100
  bool                  hasTypeMods = false;
13,382,778✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
13,382,778✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
11,978,130✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,408,454✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
1,410,428✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
13,388,978✔
109

110
  if (hasTypeMods) {
13,383,200✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
41,412✔
112
    if (ret != NULL) {
41,412✔
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
41,412✔
114
    }
115
    return ret;
41,412✔
116
  }
117
  return NULL;
13,341,788✔
118
}
119

120
int32_t metaGetRsmaSchema(const SMetaEntry *pME, SSchemaRsma **rsmaSchema) {
28,656✔
121
  if (!rsmaSchema) return 0;
28,656✔
122
  if ((pME->type != TSDB_SUPER_TABLE) || !TABLE_IS_ROLLUP(pME->flags)) {  // only support super table
28,656✔
123
    *rsmaSchema = NULL;
×
124
    return 0;
×
125
  }
126

127
  const SRSmaParam *pParam = &pME->stbEntry.rsmaParam;
28,656✔
128
  const SSchema    *pSchema = pME->stbEntry.schemaRow.pSchema;
28,656✔
129
  int32_t           nCols = pME->stbEntry.schemaRow.nCols;
28,656✔
130

131
  *rsmaSchema = (SSchemaRsma *)taosMemoryMalloc(sizeof(SSchemaRsma));
28,656✔
132
  if (*rsmaSchema == NULL) {
28,656✔
133
    return terrno;
×
134
  }
135

136
  (*rsmaSchema)->funcIds = taosMemoryMalloc(sizeof(func_id_t) * nCols);
28,656✔
137
  if ((*rsmaSchema)->funcIds == NULL) {
28,656✔
138
    taosMemoryFree(*rsmaSchema);
×
139
    *rsmaSchema = NULL;
×
140
    return terrno;
×
141
  }
142

143
  (void)snprintf((*rsmaSchema)->tbName, TSDB_TABLE_NAME_LEN, "%s", pME->name);
28,656✔
144
  (*rsmaSchema)->tbUid = pME->uid;
28,656✔
145
  (*rsmaSchema)->tbType = pME->type;
28,656✔
146
  (*rsmaSchema)->interval[0] = pParam->interval[0];
28,656✔
147
  (*rsmaSchema)->interval[1] = pParam->interval[1];
28,656✔
148
  (*rsmaSchema)->nFuncs = nCols;
28,656✔
149

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
28,656✔
151
  int32_t    i = 0, j = 0;
28,656✔
152
  for (i = 0; i < nCols; ++i) {
220,492✔
153
    while (j < pParam->nFuncs) {
348,648✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
335,116✔
155
        pFuncIds[i] = pParam->funcIds[j];
156,812✔
156
        break;
156,812✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
178,304✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
35,024✔
160
        break;
35,024✔
161
      }
162
      ++j;
143,280✔
163
    }
164
    if (j >= pParam->nFuncs) {
205,368✔
165
      for (; i < nCols; ++i) {
27,064✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
13,532✔
167
      }
168
      break;
13,532✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
28,656✔
172

173
  return 0;
28,656✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
12,123,832✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
12,123,832✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
24,248,673✔
179
  if (pWrapper->nCols == 0) {
12,124,445✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
24,246,850✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
12,123,425✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
24,246,850✔
186
  if (pWrapper->pColRef == NULL) {
12,124,049✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
140,058,734✔
191
    SColRef *p = &pWrapper->pColRef[i];
127,930,547✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
255,870,627✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
255,884,356✔
194
    if (p->hasRef) {
127,952,336✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
75,706,945✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
75,704,953✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
75,704,332✔
198
    }
199
  }
200
  return 0;
12,124,852✔
201
}
202

203
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
204
                                                            SSchemaWrapper *pSchema) {
205
  pRef->nCols = pSchema->nCols;
×
206
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
207
    return terrno;
×
208
  }
209

210
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
211
    SColRef  *pColRef = &pRef->pColRef[i];
×
212
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
213
    pColRef->id = pColSchema->colId;
×
214
    pColRef->hasRef = false;
×
215
  }
216
  return 0;
×
217
}
218

219
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
713,436✔
220
  if (pSrc->nCols > 0) {
713,436✔
221
    pDst->nCols = pSrc->nCols;
713,436✔
222
    pDst->version = pSrc->version;
713,436✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
713,436✔
224
    if (NULL == pDst->pColRef) {
713,436✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
713,436✔
228
  }
229
  return 0;
713,436✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
44,619,102✔
233
  int32_t code = 0;
44,619,102✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
89,282,585✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
89,313,594✔
236
  uTrace("encode cols:%d", pw->nCols);
44,650,111✔
237

238
  for (int32_t i = 0; i < pw->nCols; i++) {
2,147,483,647✔
239
    SColCmpr *p = &pw->pColCmpr[i];
2,147,483,647✔
240
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
2,147,483,647✔
241
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
2,147,483,647✔
242
  }
243
  return code;
44,680,879✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
44,410,999✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
44,410,999✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
44,427,427✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
724,734,812✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
724,734,812✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
1,449,675,813✔
252
  if (pWrapper->nCols == 0) {
724,746,666✔
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
1,449,461,028✔
257
  uDebug("dencode cols:%d", pWrapper->nCols);
724,836,387✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
1,449,663,554✔
259
  if (pWrapper->pColCmpr == NULL) {
724,831,895✔
260
    return terrno;
×
261
  }
262

263
  for (int i = 0; i < pWrapper->nCols; i++) {
2,147,483,647✔
264
    SColCmpr *p = &pWrapper->pColCmpr[i];
2,147,483,647✔
265
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
2,147,483,647✔
266
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
2,147,483,647✔
267
  }
268
  return 0;
725,018,734✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
262,236✔
273

274
  if (pDecoder == NULL) {
262,236✔
275
    pCmpr->pColCmpr = taosMemoryCalloc(1, pCmpr->nCols * sizeof(SColCmpr));
262,236✔
276
  } else {
277
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
278
  }
279

280
  if (pCmpr->pColCmpr == NULL) {
262,236✔
281
    return terrno;
×
282
  }
283

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,321,786✔
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,059,550✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,059,550✔
287
    pColCmpr->id = pColSchema->colId;
1,059,550✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,059,550✔
289
  }
290
  return 0;
262,236✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
169,832,351✔
294
  if (pSrc->nCols > 0) {
169,832,351✔
295
    pDst->nCols = pSrc->nCols;
152,563,431✔
296
    pDst->version = pSrc->version;
152,569,661✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
152,563,381✔
298
    if (NULL == pDst->pColCmpr) {
152,556,175✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
152,555,784✔
302
  }
303
  return 0;
169,836,525✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
170,529,884✔
307
  if (pColRef) {
170,529,884✔
308
    taosMemoryFreeClear(pColRef->pColRef);
170,537,873✔
309
  }
310
}
170,543,840✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
170,535,064✔
313
  if (pCmpr) {
170,535,064✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
170,541,415✔
315
  }
316
}
170,550,950✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
181,210,583✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
181,210,583✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
362,464,355✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
362,466,322✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
362,460,416✔
323

324
  if (pME->type > 0) {
181,229,793✔
325
    if (pME->name == NULL) {
177,181,767✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
354,358,890✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
177,178,492✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
65,189,196✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
65,224,052✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
65,234,138✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
32,605,501✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
82,784✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
144,566,783✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
263,662,542✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
263,662,248✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
263,664,090✔
342
      if (pME->ctbEntry.commentLen > 0) {
131,834,171✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
15,460✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
263,662,884✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
131,832,536✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
12,736,762✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
25,473,524✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
25,473,524✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
25,473,524✔
351
      if (pME->ntbEntry.commentLen > 0) {
12,736,762✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
15,412✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
25,473,524✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
25,473,524✔
356
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
357
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
358
    } else {
359
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
360
      return TSDB_CODE_INVALID_PARA;
×
361
    }
362
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
177,167,030✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,300,673✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
175,891,559✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
32,599,291✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
143,293,720✔
368
        if (pME->colCmpr.nCols != 0) {
12,067,426✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
11,805,190✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
262,236✔
372
          SColCmprWrapper colCmprs = {0};
262,236✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
262,236✔
374
          if (code != 0) {
262,236✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
262,236✔
379
          taosMemoryFree(colCmprs.pColCmpr);
262,236✔
380
          TAOS_CHECK_RETURN(code);
262,236✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
177,160,967✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
181,209,090✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
65,165,589✔
388
  }
389

390
  tEndEncode(pCoder);
181,177,337✔
391
  return 0;
181,163,003✔
392
}
393

394
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
1,297,283,940✔
395
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
1,297,283,940✔
396
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
2,147,483,647✔
397
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
2,147,483,647✔
398
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
2,147,483,647✔
399

400
  if (headerOnly) {
1,297,935,358✔
401
    tEndDecode(pCoder);
106,718✔
402
    return 0;
106,718✔
403
  }
404

405
  if (pME->type > 0) {
1,297,828,640✔
406
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
2,147,483,647✔
407

408
    if (pME->type == TSDB_SUPER_TABLE) {
1,297,684,430✔
409
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,270,099,558✔
410
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,270,216,036✔
411
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,270,069,824✔
412
      if (TABLE_IS_ROLLUP(pME->flags)) {
634,992,619✔
413
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
304,868✔
414
      }
415
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
662,263,134✔
416
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,140,214,419✔
417
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,140,527,437✔
418
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,140,292,516✔
419
      if (pME->ctbEntry.commentLen > 0) {
570,020,803✔
420
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
21,712✔
421
      }
422
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,140,252,784✔
423
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
570,268,847✔
424
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
92,400,505✔
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
184,821,713✔
426
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
184,837,173✔
427
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
184,822,440✔
428
      if (pME->ntbEntry.commentLen > 0) {
92,405,567✔
429
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
23,002✔
430
      }
431
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
184,791,324✔
432
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
184,819,303✔
433
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
434
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
435
      if (!pME->smaEntry.tsma) {
×
436
        return terrno;
×
437
      }
438
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
439
    } else {
440
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
441
      return TSDB_CODE_INVALID_PARA;
×
442
    }
443
    if (pME->type == TSDB_SUPER_TABLE) {
1,297,416,561✔
444
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
635,080,467✔
445
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
634,906,203✔
446

447
        if (pME->colCmpr.nCols == 0) {
635,105,643✔
448
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
449
        }
450
      } else {
451
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
452
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
453
      }
454
    } else if (pME->type == TSDB_NORMAL_TABLE) {
662,231,404✔
455
      if (!tDecodeIsEnd(pCoder)) {
89,851,857✔
456
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
89,855,799✔
457
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
89,855,799✔
458
        if (pME->colCmpr.nCols == 0) {
89,856,955✔
459
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
460
        }
461
      } else {
462
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
463
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
464
      }
465
      TABLE_SET_COL_COMPRESSED(pME->flags);
89,850,828✔
466
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
572,330,406✔
467
      if (!tDecodeIsEnd(pCoder)) {
12,122,420✔
468
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
12,122,420✔
469
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
12,123,974✔
470
      } else {
UNCOV
471
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
472
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
473
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
474
        }
475
      }
476
    }
477
    if (!tDecodeIsEnd(pCoder)) {
1,297,551,489✔
478
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
639,994,671✔
479
    } else {
480
      pME->pExtSchemas = NULL;
657,556,818✔
481
    }
482
  }
483
  if (pME->type == TSDB_SUPER_TABLE) {
1,297,243,672✔
484
    if (!tDecodeIsEnd(pCoder)) {
634,956,812✔
485
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,270,087,487✔
486
    }
487
  }
488

489

490
  tEndDecode(pCoder);
1,297,545,201✔
491
  return 0;
1,297,357,831✔
492
}
493

494
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
1,297,279,721✔
495

496
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
297,169,119✔
497
  if (pSrc == NULL || pDst == NULL) {
297,169,119✔
498
    return TSDB_CODE_INVALID_PARA;
×
499
  }
500

501
  pDst->nCols = pSrc->nCols;
297,184,826✔
502
  pDst->version = pSrc->version;
297,175,439✔
503
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
297,168,302✔
504
  if (pDst->pSchema == NULL) {
297,147,237✔
505
    return terrno;
×
506
  }
507
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
297,158,209✔
508
  return TSDB_CODE_SUCCESS;
297,181,180✔
509
}
510

511
static int32_t metaCloneRsmaParam(const SRSmaParam *pSrc, SRSmaParam *pDst) {
46,964✔
512
  if (pSrc == NULL || pDst == NULL) {
46,964✔
513
    return TSDB_CODE_INVALID_PARA;
×
514
  }
515
  memcpy(pDst, pSrc, sizeof(SRSmaParam));
46,964✔
516
  pDst->name = tstrdup(pSrc->name);
46,964✔
517
  if (pDst->name == NULL) {
46,964✔
518
    return terrno;
×
519
  }
520
  if (pSrc->nFuncs > 0) {
46,964✔
521
    pDst->nFuncs = pSrc->nFuncs;
46,964✔
522
    pDst->funcColIds = (col_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(col_id_t));
46,964✔
523
    if (pDst->funcColIds == NULL) {
46,964✔
524
      return terrno;
×
525
    }
526
    memcpy(pDst->funcColIds, pSrc->funcColIds, pSrc->nFuncs * sizeof(col_id_t));
46,964✔
527

528
    pDst->funcIds = (func_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(func_id_t));
46,964✔
529
    if (pDst->funcIds == NULL) {
46,964✔
530
      return terrno;
×
531
    }
532
    memcpy(pDst->funcIds, pSrc->funcIds, pSrc->nFuncs * sizeof(func_id_t));
46,964✔
533
  } else {
534
    pDst->nFuncs = 0;
×
535
    pDst->funcColIds = NULL;
×
536
    pDst->funcIds = NULL;
×
537
  }
538

539
  return TSDB_CODE_SUCCESS;
46,964✔
540
}
541

542
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
297,157,697✔
543
  if (pSchema) {
297,157,697✔
544
    taosMemoryFreeClear(pSchema->pSchema);
297,170,994✔
545
  }
546
}
297,170,562✔
547

548
/**
549
 * @param type 0x01 free name
550
 */
551
void metaFreeRsmaParam(SRSmaParam *pParam, int8_t type) {
70,048✔
552
  if (pParam) {
70,048✔
553
    if ((type & 0x01)) {
70,048✔
554
      taosMemoryFreeClear(pParam->name);
70,048✔
555
    }
556
    taosMemoryFreeClear(pParam->funcColIds);
70,844✔
557
    taosMemoryFreeClear(pParam->funcIds);
70,844✔
558
  }
559
}
70,844✔
560

561
void metaCloneEntryFree(SMetaEntry **ppEntry) {
170,622,586✔
562
  if (ppEntry == NULL || *ppEntry == NULL) {
170,622,586✔
563
    return;
81,054✔
564
  }
565

566
  taosMemoryFreeClear((*ppEntry)->name);
170,546,275✔
567

568
  if ((*ppEntry)->type < 0) {
170,552,153✔
569
    taosMemoryFreeClear(*ppEntry);
×
570
    return;
×
571
  }
572

573
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
170,536,465✔
574
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
144,140,232✔
575
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
144,135,427✔
576
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
144,140,382✔
577
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
70,048✔
578
    }
579
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
26,410,330✔
580
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
17,507,445✔
581
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
17,508,126✔
582
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,902,885✔
583
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,902,885✔
584
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,902,885✔
585
  } else {
586
    return;
×
587
  }
588
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
170,550,959✔
589
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
170,545,504✔
590
  metaCloneColRefFree(&(*ppEntry)->colRef);
170,545,851✔
591

592
  taosMemoryFreeClear(*ppEntry);
170,533,440✔
593
  return;
170,545,565✔
594
}
595

596
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
170,538,133✔
597
  int32_t code = TSDB_CODE_SUCCESS;
170,538,133✔
598

599
  if (NULL == pEntry || NULL == ppEntry) {
170,538,133✔
600
    return TSDB_CODE_INVALID_PARA;
×
601
  }
602

603
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
170,553,244✔
604
  if (NULL == *ppEntry) {
170,527,645✔
605
    return terrno;
×
606
  }
607

608
  (*ppEntry)->version = pEntry->version;
170,535,163✔
609
  (*ppEntry)->type = pEntry->type;
170,542,516✔
610
  (*ppEntry)->uid = pEntry->uid;
170,539,944✔
611

612
  if (pEntry->type < 0) {
170,546,944✔
613
    return TSDB_CODE_SUCCESS;
×
614
  }
615

616
  if (pEntry->name) {
170,546,417✔
617
    (*ppEntry)->name = tstrdup(pEntry->name);
170,546,303✔
618
    if (NULL == (*ppEntry)->name) {
170,551,845✔
619
      code = terrno;
×
620
      metaCloneEntryFree(ppEntry);
×
621
      return code;
×
622
    }
623
  }
624

625
  if (pEntry->type == TSDB_SUPER_TABLE) {
170,546,296✔
626
    (*ppEntry)->flags = pEntry->flags;
144,136,735✔
627

628
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
144,124,665✔
629
    if (code) {
144,140,944✔
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633

634
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
144,140,944✔
635
    if (code) {
144,145,603✔
636
      metaCloneEntryFree(ppEntry);
×
637
      return code;
×
638
    }
639
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
144,145,603✔
640
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
46,964✔
641
      if (code) {
46,964✔
642
        metaCloneEntryFree(ppEntry);
×
643
        return code;
×
644
      }
645
    }
646
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
144,145,554✔
647
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
26,411,011✔
648
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
17,508,126✔
649
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
17,508,126✔
650
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
17,508,126✔
651

652
    // comment
653
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
17,508,126✔
654
    if (pEntry->ctbEntry.commentLen > 0) {
17,508,126✔
655
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
4,709✔
656
      if (NULL == (*ppEntry)->ctbEntry.comment) {
4,709✔
657
        code = terrno;
×
658
        metaCloneEntryFree(ppEntry);
×
659
        return code;
×
660
      }
661
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
4,709✔
662
    }
663

664
    // tags
665
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
17,508,126✔
666
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
17,508,126✔
667
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
17,508,126✔
668
      code = terrno;
×
669
      metaCloneEntryFree(ppEntry);
×
670
      return code;
×
671
    }
672
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
17,508,126✔
673
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
8,902,885✔
674
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
8,902,885✔
675
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
8,902,885✔
676
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
8,902,885✔
677

678
    // schema
679
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
8,902,885✔
680
    if (code) {
8,902,885✔
681
      metaCloneEntryFree(ppEntry);
×
682
      return code;
×
683
    }
684

685
    // comment
686
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,902,885✔
687
    if (pEntry->ntbEntry.commentLen > 0) {
8,902,885✔
688
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
4,825✔
689
      if (NULL == (*ppEntry)->ntbEntry.comment) {
4,825✔
690
        code = terrno;
×
691
        metaCloneEntryFree(ppEntry);
×
692
        return code;
×
693
      }
694
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
4,825✔
695
    }
696
  } else {
697
    return TSDB_CODE_INVALID_PARA;
×
698
  }
699

700
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
170,548,714✔
701
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
725,783✔
702
    if (code) {
713,436✔
703
      metaCloneEntryFree(ppEntry);
×
704
      return code;
×
705
    }
706
  } else {
707
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
169,826,558✔
708
    if (code) {
169,835,687✔
709
      metaCloneEntryFree(ppEntry);
×
710
      return code;
×
711
    }
712
  }
713
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
170,549,123✔
714
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
12,991,839✔
715
    if (!(*ppEntry)->pExtSchemas) {
12,988,436✔
716
      code = terrno;
×
717
      metaCloneEntryFree(ppEntry);
×
718
      return code;
×
719
    }
720
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
12,987,706✔
721
  }
722

723
  return code;
170,539,115✔
724
}
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