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

taosdata / TDengine / #4660

08 Aug 2025 02:38AM UTC coverage: 60.053% (+0.1%) from 59.907%
#4660

push

travis-ci

web-flow
fix(stream)[TD-37079]: force close the last window in fill_history (#32436)

137890 of 291849 branches covered (47.25%)

Branch coverage included in aggregate %.

208070 of 284239 relevant lines covered (73.2%)

18089591.27 hits per line

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

64.79
/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) {
20,226,754✔
23
  for (int32_t i = 0; i < nCols; i++) {
475,352,625✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
455,210,772✔
25
      return true;
84,901✔
26
    }
27
  }
28
  return false;
20,141,853✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
659,807✔
32
  if (pME->pExtSchemas) {
659,807✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
26,753✔
34
    bool                  hasTypeMods = false;
26,753✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
26,753✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
26,616✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
137!
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
138✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
26,754✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,799,495✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
11,545,482!
46
    }
47
  }
48
  return 0;
659,808✔
49
}
50

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

57
  for (int32_t i = 0; i < pw->nCols; i++) {
15,358✔
58
    SColRef *p = &pw->pColRef[i];
13,916✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
27,832!
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
27,832!
61
    if (p->hasRef) {
13,916✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
15,416!
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
15,416!
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
15,416!
65
    }
66
  }
67
  return 0;
1,442✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
19,951,500✔
71
  bool hasExtSchema = false;
19,951,500✔
72
  SSchemaWrapper* pSchWrapper = NULL;
19,951,500✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
19,951,500!
74
    pSchWrapper = &pME->stbEntry.schemaRow;
20,011,318✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
×
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
2,707✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
20,014,025✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
20,115,057!
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
62,626!
84
    if (pME->pExtSchemas == NULL) {
62,637!
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
7,669,715✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
15,213,861!
90
    }
91
  }
92

93
  return 0;
20,115,363✔
94
}
95

96
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
131,883✔
97
  const SSchemaWrapper *pSchWrapper = NULL;
131,883✔
98
  bool                  hasTypeMods = false;
131,883✔
99
  if (pME->type == TSDB_SUPER_TABLE) {
131,883✔
100
    pSchWrapper = &pME->stbEntry.schemaRow;
91,897✔
101
  } else if (pME->type == TSDB_NORMAL_TABLE) {
39,986!
102
    pSchWrapper = &pME->ntbEntry.schemaRow;
39,997✔
103
  } else {
104
    return NULL;
×
105
  }
106
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
131,894✔
107

108
  if (hasTypeMods) {
131,888✔
109
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
77!
110
    if (ret != NULL) {
70!
111
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
70✔
112
    }
113
    return ret;
70✔
114
  }
115
  return NULL;
131,811✔
116
}
117

118
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
4,503✔
119
  SColRefWrapper *pWrapper = &pME->colRef;
4,503✔
120
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
9,005!
121
  if (pWrapper->nCols == 0) {
4,502!
122
    return 0;
×
123
  }
124

125
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
9,006!
126
  uDebug("decode cols:%d", pWrapper->nCols);
4,504!
127
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
4,504!
128
  if (pWrapper->pColRef == NULL) {
4,504!
129
    return terrno;
×
130
  }
131

132
  for (int i = 0; i < pWrapper->nCols; i++) {
63,343✔
133
    SColRef *p = &pWrapper->pColRef[i];
58,873✔
134
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
117,694!
135
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
117,635!
136
    if (p->hasRef) {
58,814✔
137
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
31,395!
138
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
31,440!
139
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
31,442✔
140
    }
141
  }
142
  return 0;
4,470✔
143
}
144

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

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

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

174
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
139,196✔
175
  int32_t code = 0;
139,196✔
176
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
278,392!
177
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
278,392!
178
  uTrace("encode cols:%d", pw->nCols);
139,196✔
179

180
  for (int32_t i = 0; i < pw->nCols; i++) {
24,749,200✔
181
    SColCmpr *p = &pw->pColCmpr[i];
24,610,039✔
182
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
49,220,078!
183
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
49,220,078!
184
  }
185
  return code;
139,161✔
186
}
187
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
139,054✔
188
  const SColCmprWrapper *pw = &pME->colCmpr;
139,054✔
189
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
139,054✔
190
}
191
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
22,453,988✔
192
  SColCmprWrapper *pWrapper = &pME->colCmpr;
22,453,988✔
193
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
44,792,069!
194
  if (pWrapper->nCols == 0) {
22,338,081!
195
    return 0;
×
196
  }
197

198
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
44,659,243!
199
  uDebug("dencode cols:%d", pWrapper->nCols);
22,321,162✔
200
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
22,321,250✔
201
  if (pWrapper->pColCmpr == NULL) {
22,482,336!
202
    return terrno;
×
203
  }
204

205
  for (int i = 0; i < pWrapper->nCols; i++) {
490,702,228✔
206
    SColCmpr *p = &pWrapper->pColCmpr[i];
469,167,683✔
207
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
933,633,980!
208
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
932,686,189!
209
  }
210
  return 0;
21,534,545✔
211
}
212
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
213
                                                            SSchemaWrapper *pSchema) {
214
  pCmpr->nCols = pSchema->nCols;
×
215

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

222
  if (pCmpr->pColCmpr == NULL) {
270!
223
    return terrno;
×
224
  }
225

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

235
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
586,210✔
236
  if (pSrc->nCols > 0) {
586,210✔
237
    pDst->nCols = pSrc->nCols;
537,663✔
238
    pDst->version = pSrc->version;
537,663✔
239
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
537,663!
240
    if (NULL == pDst->pColCmpr) {
537,836!
241
      return terrno;
×
242
    }
243
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
537,836✔
244
  }
245
  return 0;
586,383✔
246
}
247

248
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
587,133✔
249
  if (pColRef) {
587,133!
250
    taosMemoryFreeClear(pColRef->pColRef);
587,134!
251
  }
252
}
587,133✔
253

254
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
587,095✔
255
  if (pCmpr) {
587,095!
256
    taosMemoryFreeClear(pCmpr->pColCmpr);
587,120!
257
  }
258
}
587,153✔
259

260
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
698,657✔
261
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
698,657✔
262
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,399,408!
263
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,399,408!
264
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,399,408!
265

266
  if (pME->type > 0) {
699,704✔
267
    if (pME->name == NULL) {
660,967!
268
      return TSDB_CODE_INVALID_PARA;
×
269
    }
270

271
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,321,934!
272

273
    if (pME->type == TSDB_SUPER_TABLE) {
660,967✔
274
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
197,584!
275
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
197,584!
276
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
197,584!
277
      if (TABLE_IS_ROLLUP(pME->flags)) {
98,792!
278
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
279
      }
280
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
562,175✔
281
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
1,041,546!
282
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
1,041,546!
283
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
1,041,546!
284
      if (pME->ctbEntry.commentLen > 0) {
520,773✔
285
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
286
      }
287
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
1,041,546!
288
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
520,773!
289
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
41,402!
290
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
82,804!
291
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
82,804!
292
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
82,804!
293
      if (pME->ntbEntry.commentLen > 0) {
41,402✔
294
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
76!
295
      }
296
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
82,804!
297
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
82,804!
298
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
299
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
300
    } else {
301
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
302
      return TSDB_CODE_INVALID_PARA;
×
303
    }
304
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
660,861✔
305
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,318!
306
    } else {
307
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
659,543!
308
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
98,905✔
309
      } else if (pME->type == TSDB_NORMAL_TABLE) {
560,638✔
310
        if (pME->colCmpr.nCols != 0) {
40,440✔
311
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
40,170!
312
        } else {
313
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
270!
314
          SColCmprWrapper colCmprs = {0};
270✔
315
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
270!
316
          if (code != 0) {
270!
317
            taosMemoryFree(colCmprs.pColCmpr);
×
318
            TAOS_CHECK_RETURN(code);
×
319
          }
320
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
270✔
321
          taosMemoryFree(colCmprs.pColCmpr);
270!
322
          TAOS_CHECK_RETURN(code);
270!
323
        }
324
      }
325
    }
326
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
660,636!
327
  }
328
  if (pME->type == TSDB_SUPER_TABLE) {
699,616✔
329
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
197,676!
330
  }
331

332
  tEndEncode(pCoder);
699,616✔
333
  return 0;
699,612✔
334
}
335

336
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
33,853,136✔
337
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
33,853,136!
338
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
67,538,733!
339
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
67,031,048!
340
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
66,825,521!
341

342
  if (headerOnly) {
33,391,578✔
343
    tEndDecode(pCoder);
90,330✔
344
    return 0;
90,330✔
345
  }
346

347
  if (pME->type > 0) {
33,301,248!
348
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
67,190,440!
349

350
    if (pME->type == TSDB_SUPER_TABLE) {
33,791,870✔
351
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
40,019,162!
352
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
37,154,706!
353
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
36,740,160!
354
      if (TABLE_IS_ROLLUP(pME->flags)) {
19,525,776!
355
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
356
      }
357
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
13,713,030✔
358
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
22,653,306!
359
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
22,622,881!
360
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
22,612,236!
361
      if (pME->ctbEntry.commentLen > 0) {
11,315,775✔
362
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
363
      }
364
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
22,622,965!
365
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
11,307,190!
366
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,386,144!
367
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,769,098!
368
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,763,162!
369
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,760,535!
370
      if (pME->ntbEntry.commentLen > 0) {
2,380,327✔
371
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
218!
372
      }
373
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,761,709!
374
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,694,693!
375
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
376
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
377
      if (!pME->smaEntry.tsma) {
×
378
        return terrno;
×
379
      }
380
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
381
    } else {
382
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
383
      return TSDB_CODE_INVALID_PARA;
×
384
    }
385
    if (pME->type == TSDB_SUPER_TABLE) {
33,825,959✔
386
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
20,078,190!
387
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
20,085,275!
388

389
        if (pME->colCmpr.nCols == 0) {
19,963,893!
390
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
391
        }
392
      } else {
393
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
394
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
395
      }
396
    } else if (pME->type == TSDB_NORMAL_TABLE) {
13,747,769✔
397
      if (!tDecodeIsEnd(pCoder)) {
2,384,308!
398
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,384,351✔
399
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,384,354✔
400
        if (pME->colCmpr.nCols == 0) {
2,381,422!
401
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
402
        }
403
      } else {
404
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
405
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
406
      }
407
      TABLE_SET_COL_COMPRESSED(pME->flags);
2,381,422✔
408
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
11,363,461!
409
      if (!tDecodeIsEnd(pCoder)) {
4,502!
410
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
4,502!
411
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
4,502!
412
      } else {
413
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
414
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
415
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
416
        }
417
      }
418
    }
419
    if (!tDecodeIsEnd(pCoder)) {
33,549,154✔
420
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
19,960,460!
421
    }
422
  }
423
  if (pME->type == TSDB_SUPER_TABLE) {
33,601,509✔
424
    if (!tDecodeIsEnd(pCoder)) {
20,112,015!
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
40,103,200!
426
    }
427
  }
428

429

430
  tEndDecode(pCoder);
33,478,635✔
431
  return 0;
33,613,590✔
432
}
433

434
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
33,766,853✔
435

436
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
1,061,706✔
437
  if (pSrc == NULL || pDst == NULL) {
1,061,706!
438
    return TSDB_CODE_INVALID_PARA;
×
439
  }
440

441
  pDst->nCols = pSrc->nCols;
1,061,750✔
442
  pDst->version = pSrc->version;
1,061,750✔
443
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
1,061,750!
444
  if (pDst->pSchema == NULL) {
1,061,739!
445
    return terrno;
×
446
  }
447
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
1,061,739✔
448
  return TSDB_CODE_SUCCESS;
1,061,739✔
449
}
450

451
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
1,061,855✔
452
  if (pSchema) {
1,061,855!
453
    taosMemoryFreeClear(pSchema->pSchema);
1,061,874!
454
  }
455
}
1,062,064✔
456

457
void metaCloneEntryFree(SMetaEntry **ppEntry) {
587,164✔
458
  if (ppEntry == NULL || *ppEntry == NULL) {
587,164!
459
    return;
85✔
460
  }
461

462
  taosMemoryFreeClear((*ppEntry)->name);
587,079!
463

464
  if ((*ppEntry)->type < 0) {
587,101!
465
    taosMemoryFreeClear(*ppEntry);
×
466
    return;
×
467
  }
468

469
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
587,101✔
470
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
523,637✔
471
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
523,689✔
472
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
63,464✔
473
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
48,641!
474
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
48,641!
475
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
14,823!
476
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
14,823✔
477
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
14,823!
478
  } else {
479
    return;
×
480
  }
481
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
587,134✔
482
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
587,142!
483
  metaCloneColRefFree(&(*ppEntry)->colRef);
587,145✔
484

485
  taosMemoryFreeClear(*ppEntry);
587,131!
486
  return;
587,177✔
487
}
488

489
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
586,878✔
490
  int32_t code = TSDB_CODE_SUCCESS;
586,878✔
491

492
  if (NULL == pEntry || NULL == ppEntry) {
586,878!
493
    return TSDB_CODE_INVALID_PARA;
×
494
  }
495

496
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
586,911!
497
  if (NULL == *ppEntry) {
587,150!
498
    return terrno;
×
499
  }
500

501
  (*ppEntry)->version = pEntry->version;
587,150✔
502
  (*ppEntry)->type = pEntry->type;
587,150✔
503
  (*ppEntry)->uid = pEntry->uid;
587,150✔
504

505
  if (pEntry->type < 0) {
587,150!
506
    return TSDB_CODE_SUCCESS;
×
507
  }
508

509
  if (pEntry->name) {
587,150!
510
    (*ppEntry)->name = tstrdup(pEntry->name);
587,150✔
511
    if (NULL == (*ppEntry)->name) {
587,082!
512
      code = terrno;
×
513
      metaCloneEntryFree(ppEntry);
×
514
      return code;
×
515
    }
516
  }
517

518
  if (pEntry->type == TSDB_SUPER_TABLE) {
587,097✔
519
    (*ppEntry)->flags = pEntry->flags;
523,633✔
520

521
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
523,633✔
522
    if (code) {
523,576!
523
      metaCloneEntryFree(ppEntry);
×
524
      return code;
×
525
    }
526

527
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
523,576✔
528
    if (code) {
523,548!
529
      metaCloneEntryFree(ppEntry);
×
530
      return code;
×
531
    }
532
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
523,569✔
533
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
63,464✔
534
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
48,641✔
535
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
48,641✔
536
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
48,641✔
537

538
    // comment
539
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
48,641✔
540
    if (pEntry->ctbEntry.commentLen > 0) {
48,641✔
541
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
45!
542
      if (NULL == (*ppEntry)->ctbEntry.comment) {
45!
543
        code = terrno;
×
544
        metaCloneEntryFree(ppEntry);
×
545
        return code;
×
546
      }
547
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
45✔
548
    }
549

550
    // tags
551
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
48,641✔
552
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
48,641!
553
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
48,641!
554
      code = terrno;
×
555
      metaCloneEntryFree(ppEntry);
×
556
      return code;
×
557
    }
558
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
48,641✔
559
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,823!
560
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
14,823✔
561
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
14,823✔
562
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
14,823✔
563

564
    // schema
565
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
14,823✔
566
    if (code) {
14,823!
567
      metaCloneEntryFree(ppEntry);
×
568
      return code;
×
569
    }
570

571
    // comment
572
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
14,823✔
573
    if (pEntry->ntbEntry.commentLen > 0) {
14,823✔
574
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
25!
575
      if (NULL == (*ppEntry)->ntbEntry.comment) {
25!
576
        code = terrno;
×
577
        metaCloneEntryFree(ppEntry);
×
578
        return code;
×
579
      }
580
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
25✔
581
    }
582
  } else {
583
    return TSDB_CODE_INVALID_PARA;
×
584
  }
585

586
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
587,033✔
587
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
802✔
588
    if (code) {
764!
589
      metaCloneEntryFree(ppEntry);
×
590
      return code;
×
591
    }
592
  } else {
593
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
586,231✔
594
    if (code) {
586,362✔
595
      metaCloneEntryFree(ppEntry);
49✔
596
      return code;
×
597
    }
598
  }
599
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
587,077!
600
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
23,408!
601
    if (!(*ppEntry)->pExtSchemas) {
23,409!
602
      code = terrno;
×
603
      metaCloneEntryFree(ppEntry);
×
604
      return code;
×
605
    }
606
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
23,409✔
607
  }
608

609
  return code;
587,078✔
610
}
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