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

taosdata / TDengine / #4683

21 Aug 2025 12:03PM UTC coverage: 60.097% (+0.2%) from 59.918%
#4683

push

travis-ci

web-flow
jdbc release 3.7.3 (#32682)

* chore(jdbc): update jdbc version

* docs(jdbc): release 3.7.3

138078 of 292193 branches covered (47.26%)

Branch coverage included in aggregate %.

208479 of 284466 relevant lines covered (73.29%)

17837633.69 hits per line

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

66.31
/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) {
18,498,194✔
23
  for (int32_t i = 0; i < nCols; i++) {
434,073,452✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
415,668,988✔
25
      return true;
93,730✔
26
    }
27
  }
28
  return false;
18,404,464✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
606,340✔
32
  if (pME->pExtSchemas) {
606,340✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
28,532✔
34
    bool                  hasTypeMods = false;
28,532✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
28,532✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
28,365✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
167✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
166✔
39
    } else {
40
      return 0;
1✔
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
28,531✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,695,965✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
11,334,868!
46
    }
47
  }
48
  return 0;
606,339✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
14,496✔
58
    SColRef *p = &pw->pColRef[i];
13,088✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
26,176!
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
26,176!
61
    if (p->hasRef) {
13,088✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
14,744!
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
14,744!
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
14,744!
65
    }
66
  }
67
  return 0;
1,408✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
18,215,664✔
71
  bool hasExtSchema = false;
18,215,664✔
72
  SSchemaWrapper* pSchWrapper = NULL;
18,215,664✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
18,215,664!
74
    pSchWrapper = &pME->stbEntry.schemaRow;
18,246,032✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
×
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
3,340✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
18,249,372✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
18,381,640!
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
69,678!
84
    if (pME->pExtSchemas == NULL) {
69,688!
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
7,647,321✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
15,154,708!
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
18,311,962✔
93
  }
94

95
  return 0;
18,382,208✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
131,578✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
131,578✔
100
  bool                  hasTypeMods = false;
131,578✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
131,578✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
91,567✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
40,011!
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
40,030✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
131,597✔
109

110
  if (hasTypeMods) {
131,616✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
131!
112
    if (ret != NULL) {
118!
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
118✔
114
    }
115
    return ret;
118✔
116
  }
117
  return NULL;
131,485✔
118
}
119

120
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
4,270✔
121
  SColRefWrapper *pWrapper = &pME->colRef;
4,270✔
122
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
8,540!
123
  if (pWrapper->nCols == 0) {
4,270!
124
    return 0;
×
125
  }
126

127
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
8,540!
128
  uDebug("decode cols:%d", pWrapper->nCols);
4,270!
129
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
4,270!
130
  if (pWrapper->pColRef == NULL) {
4,274!
131
    return terrno;
×
132
  }
133

134
  for (int i = 0; i < pWrapper->nCols; i++) {
60,949✔
135
    SColRef *p = &pWrapper->pColRef[i];
56,708✔
136
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
113,347!
137
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
113,274!
138
    if (p->hasRef) {
56,635✔
139
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
30,161!
140
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
30,239!
141
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
30,257✔
142
    }
143
  }
144
  return 0;
4,241✔
145
}
146

147
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
148
                                                            SSchemaWrapper *pSchema) {
149
  pRef->nCols = pSchema->nCols;
×
150
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
151
    return terrno;
×
152
  }
153

154
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
155
    SColRef  *pColRef = &pRef->pColRef[i];
×
156
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
157
    pColRef->id = pColSchema->colId;
×
158
    pColRef->hasRef = false;
×
159
  }
160
  return 0;
×
161
}
162

163
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
710✔
164
  if (pSrc->nCols > 0) {
710!
165
    pDst->nCols = pSrc->nCols;
710✔
166
    pDst->version = pSrc->version;
710✔
167
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
710!
168
    if (NULL == pDst->pColRef) {
710!
169
      return terrno;
×
170
    }
171
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
710✔
172
  }
173
  return 0;
710✔
174
}
175

176
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
133,998✔
177
  int32_t code = 0;
133,998✔
178
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
267,996!
179
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
267,996!
180
  uTrace("encode cols:%d", pw->nCols);
133,998✔
181

182
  for (int32_t i = 0; i < pw->nCols; i++) {
24,677,282✔
183
    SColCmpr *p = &pw->pColCmpr[i];
24,543,260✔
184
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
49,086,520!
185
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
49,086,520!
186
  }
187
  return code;
134,022✔
188
}
189
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
133,948✔
190
  const SColCmprWrapper *pw = &pME->colCmpr;
133,948✔
191
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
133,948✔
192
}
193
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
20,623,846✔
194
  SColCmprWrapper *pWrapper = &pME->colCmpr;
20,623,846✔
195
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
41,124,460!
196
  if (pWrapper->nCols == 0) {
20,500,614!
197
    return 0;
×
198
  }
199

200
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
41,002,577!
201
  uDebug("dencode cols:%d", pWrapper->nCols);
20,501,963✔
202
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
20,502,002✔
203
  if (pWrapper->pColCmpr == NULL) {
20,642,129!
204
    return terrno;
×
205
  }
206

207
  for (int i = 0; i < pWrapper->nCols; i++) {
448,129,494✔
208
    SColCmpr *p = &pWrapper->pColCmpr[i];
428,951,059✔
209
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
857,369,705!
210
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
855,906,011!
211
  }
212
  return 0;
19,178,435✔
213
}
214
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
215
                                                            SSchemaWrapper *pSchema) {
216
  pCmpr->nCols = pSchema->nCols;
×
217

218
  if (pDecoder == NULL) {
×
219
    pCmpr->pColCmpr = taosMemoryCalloc(1, pCmpr->nCols * sizeof(SColCmpr));
342!
220
  } else {
221
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
222
  }
223

224
  if (pCmpr->pColCmpr == NULL) {
342!
225
    return terrno;
×
226
  }
227

228
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,504!
229
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,162✔
230
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,162✔
231
    pColCmpr->id = pColSchema->colId;
1,162✔
232
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,162✔
233
  }
234
  return 0;
342✔
235
}
236

237
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
537,144✔
238
  if (pSrc->nCols > 0) {
537,144✔
239
    pDst->nCols = pSrc->nCols;
489,575✔
240
    pDst->version = pSrc->version;
489,575✔
241
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
489,575!
242
    if (NULL == pDst->pColCmpr) {
489,742!
243
      return terrno;
×
244
    }
245
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
489,742✔
246
  }
247
  return 0;
537,311✔
248
}
249

250
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
538,016✔
251
  if (pColRef) {
538,016!
252
    taosMemoryFreeClear(pColRef->pColRef);
538,029!
253
  }
254
}
538,016✔
255

256
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
537,928✔
257
  if (pCmpr) {
537,928!
258
    taosMemoryFreeClear(pCmpr->pColCmpr);
537,957!
259
  }
260
}
537,990✔
261

262
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
644,846✔
263
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
644,846✔
264
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,291,344!
265
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,291,344!
266
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,291,344!
267

268
  if (pME->type > 0) {
645,672✔
269
    if (pME->name == NULL) {
607,289!
270
      return TSDB_CODE_INVALID_PARA;
×
271
    }
272

273
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,214,578!
274

275
    if (pME->type == TSDB_SUPER_TABLE) {
607,289✔
276
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
196,822!
277
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
196,822!
278
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
196,822!
279
      if (TABLE_IS_ROLLUP(pME->flags)) {
98,411!
280
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
281
      }
282
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
508,878✔
283
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
943,944!
284
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
943,944!
285
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
943,944!
286
      if (pME->ctbEntry.commentLen > 0) {
471,972✔
287
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
288
      }
289
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
943,944!
290
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
471,972!
291
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
36,906!
292
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
73,812!
293
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
73,812!
294
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
73,812!
295
      if (pME->ntbEntry.commentLen > 0) {
36,906✔
296
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
156!
297
      }
298
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
73,812!
299
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
73,812!
300
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
301
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
302
    } else {
303
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
304
      return TSDB_CODE_INVALID_PARA;
×
305
    }
306
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
607,198✔
307
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,448!
308
    } else {
309
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
605,750✔
310
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
98,334✔
311
      } else if (pME->type == TSDB_NORMAL_TABLE) {
507,416✔
312
        if (pME->colCmpr.nCols != 0) {
35,980✔
313
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
35,638!
314
        } else {
315
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
342!
316
          SColCmprWrapper colCmprs = {0};
342✔
317
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
342!
318
          if (code != 0) {
342!
319
            taosMemoryFree(colCmprs.pColCmpr);
×
320
            TAOS_CHECK_RETURN(code);
×
321
          }
322
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
342✔
323
          taosMemoryFree(colCmprs.pColCmpr);
342!
324
          TAOS_CHECK_RETURN(code);
342!
325
        }
326
      }
327
    }
328
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
606,843!
329
  }
330
  if (pME->type == TSDB_SUPER_TABLE) {
645,499✔
331
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
196,700!
332
  }
333

334
  tEndEncode(pCoder);
645,499✔
335
  return 0;
645,514✔
336
}
337

338
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
31,241,536✔
339
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
31,241,536!
340
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
62,217,523!
341
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
61,643,265!
342
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
61,338,917!
343

344
  if (headerOnly) {
30,649,144✔
345
    tEndDecode(pCoder);
90,298✔
346
    return 0;
90,298✔
347
  }
348

349
  if (pME->type > 0) {
30,558,846!
350
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
61,802,595!
351

352
    if (pME->type == TSDB_SUPER_TABLE) {
31,132,750✔
353
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
36,564,977!
354
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
34,453,982!
355
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
34,519,452!
356
      if (TABLE_IS_ROLLUP(pME->flags)) {
18,286,079!
357
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
358
      }
359
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
12,788,382✔
360
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
21,003,428!
361
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
20,988,477!
362
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
20,994,374!
363
      if (pME->ctbEntry.commentLen > 0) {
10,510,453✔
364
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
365
      }
366
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
21,018,230!
367
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
10,507,777✔
368
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,289,510!
369
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,576,440!
370
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,572,297!
371
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,571,865!
372
      if (pME->ntbEntry.commentLen > 0) {
2,286,498✔
373
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
350!
374
      }
375
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,572,630!
376
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,556,111!
377
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
378
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
379
      if (!pME->smaEntry.tsma) {
×
380
        return terrno;
×
381
      }
382
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
383
    } else {
384
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
385
      return TSDB_CODE_INVALID_PARA;
×
386
    }
387
    if (pME->type == TSDB_SUPER_TABLE) {
31,169,756✔
388
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
18,338,590!
389
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
18,346,418!
390

391
        if (pME->colCmpr.nCols == 0) {
18,223,744!
392
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
393
        }
394
      } else {
395
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
396
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
397
      }
398
    } else if (pME->type == TSDB_NORMAL_TABLE) {
12,831,166✔
399
      if (!tDecodeIsEnd(pCoder)) {
2,288,677✔
400
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,288,595✔
401
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,288,595✔
402
        if (pME->colCmpr.nCols == 0) {
2,285,782!
403
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
404
        }
405
      } else {
406
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
82!
407
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
408
      }
409
      TABLE_SET_COL_COMPRESSED(pME->flags);
2,285,782✔
410
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
10,542,489!
411
      if (!tDecodeIsEnd(pCoder)) {
4,272!
412
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
4,272!
413
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
4,272!
414
      } else {
415
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
416
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
417
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
418
        }
419
      }
420
    }
421
    if (!tDecodeIsEnd(pCoder)) {
30,901,751✔
422
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
18,223,447!
423
    } else {
424
      pME->pExtSchemas = NULL;
12,678,304✔
425
    }
426
  }
427
  if (pME->type == TSDB_SUPER_TABLE) {
30,944,334✔
428
    if (!tDecodeIsEnd(pCoder)) {
18,373,853!
429
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
36,639,440!
430
    }
431
  }
432

433

434
  tEndDecode(pCoder);
30,828,442✔
435
  return 0;
30,973,890✔
436
}
437

438
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
31,120,533✔
439

440
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
965,614✔
441
  if (pSrc == NULL || pDst == NULL) {
965,614!
442
    return TSDB_CODE_INVALID_PARA;
×
443
  }
444

445
  pDst->nCols = pSrc->nCols;
965,660✔
446
  pDst->version = pSrc->version;
965,660✔
447
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
965,660!
448
  if (pDst->pSchema == NULL) {
965,655!
449
    return terrno;
×
450
  }
451
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
965,655✔
452
  return TSDB_CODE_SUCCESS;
965,655✔
453
}
454

455
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
965,722✔
456
  if (pSchema) {
965,722!
457
    taosMemoryFreeClear(pSchema->pSchema);
965,748!
458
  }
459
}
965,808✔
460

461
void metaCloneEntryFree(SMetaEntry **ppEntry) {
538,014✔
462
  if (ppEntry == NULL || *ppEntry == NULL) {
538,014!
463
    return;
93✔
464
  }
465

466
  taosMemoryFreeClear((*ppEntry)->name);
537,921!
467

468
  if ((*ppEntry)->type < 0) {
537,934!
469
    taosMemoryFreeClear(*ppEntry);
×
470
    return;
×
471
  }
472

473
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
537,934✔
474
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
475,559✔
475
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
475,613✔
476
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
62,375✔
477
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
47,638!
478
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
47,638!
479
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,737!
480
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,737✔
481
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,737!
482
  } else {
483
    return;
×
484
  }
485
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
538,002✔
486
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
538,005!
487
  metaCloneColRefFree(&(*ppEntry)->colRef);
538,007✔
488

489
  taosMemoryFreeClear(*ppEntry);
538,019!
490
  return;
538,040✔
491
}
492

493
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
537,790✔
494
  int32_t code = TSDB_CODE_SUCCESS;
537,790✔
495

496
  if (NULL == pEntry || NULL == ppEntry) {
537,790!
497
    return TSDB_CODE_INVALID_PARA;
×
498
  }
499

500
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
537,826!
501
  if (NULL == *ppEntry) {
538,006!
502
    return terrno;
×
503
  }
504

505
  (*ppEntry)->version = pEntry->version;
538,006✔
506
  (*ppEntry)->type = pEntry->type;
538,006✔
507
  (*ppEntry)->uid = pEntry->uid;
538,006✔
508

509
  if (pEntry->type < 0) {
538,006!
510
    return TSDB_CODE_SUCCESS;
×
511
  }
512

513
  if (pEntry->name) {
538,006!
514
    (*ppEntry)->name = tstrdup(pEntry->name);
538,022✔
515
    if (NULL == (*ppEntry)->name) {
537,967✔
516
      code = terrno;
4✔
517
      metaCloneEntryFree(ppEntry);
×
518
      return code;
×
519
    }
520
  }
521

522
  if (pEntry->type == TSDB_SUPER_TABLE) {
537,947✔
523
    (*ppEntry)->flags = pEntry->flags;
475,572✔
524

525
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
475,572✔
526
    if (code) {
475,545!
527
      metaCloneEntryFree(ppEntry);
×
528
      return code;
×
529
    }
530

531
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
475,545✔
532
    if (code) {
475,508✔
533
      metaCloneEntryFree(ppEntry);
33✔
534
      return code;
×
535
    }
536
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
475,475✔
537
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
62,375✔
538
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
47,638✔
539
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
47,638✔
540
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
47,638✔
541

542
    // comment
543
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
47,638✔
544
    if (pEntry->ctbEntry.commentLen > 0) {
47,638✔
545
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
45!
546
      if (NULL == (*ppEntry)->ctbEntry.comment) {
45!
547
        code = terrno;
×
548
        metaCloneEntryFree(ppEntry);
×
549
        return code;
×
550
      }
551
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
45✔
552
    }
553

554
    // tags
555
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
47,638✔
556
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
47,638!
557
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
47,638!
558
      code = terrno;
×
559
      metaCloneEntryFree(ppEntry);
×
560
      return code;
×
561
    }
562
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
47,638✔
563
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,737!
564
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
14,737✔
565
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
14,737✔
566
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
14,737✔
567

568
    // schema
569
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
14,737✔
570
    if (code) {
14,737!
571
      metaCloneEntryFree(ppEntry);
×
572
      return code;
×
573
    }
574

575
    // comment
576
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
14,737✔
577
    if (pEntry->ntbEntry.commentLen > 0) {
14,737✔
578
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
49!
579
      if (NULL == (*ppEntry)->ntbEntry.comment) {
49!
580
        code = terrno;
×
581
        metaCloneEntryFree(ppEntry);
×
582
        return code;
×
583
      }
584
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
49✔
585
    }
586
  } else {
587
    return TSDB_CODE_INVALID_PARA;
×
588
  }
589

590
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
537,850✔
591
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
692✔
592
    if (code) {
710!
593
      metaCloneEntryFree(ppEntry);
×
594
      return code;
×
595
    }
596
  } else {
597
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
537,158✔
598
    if (code) {
537,318✔
599
      metaCloneEntryFree(ppEntry);
56✔
600
      return code;
×
601
    }
602
  }
603
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
537,972!
604
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
25,381!
605
    if (!(*ppEntry)->pExtSchemas) {
25,380!
606
      code = terrno;
×
607
      metaCloneEntryFree(ppEntry);
×
608
      return code;
×
609
    }
610
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
25,380✔
611
  }
612

613
  return code;
537,971✔
614
}
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