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

taosdata / TDengine / #4658

09 Aug 2025 02:19PM UTC coverage: 59.866% (-1.3%) from 61.2%
#4658

push

travis-ci

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

137251 of 291849 branches covered (47.03%)

Branch coverage included in aggregate %.

207628 of 284239 relevant lines covered (73.05%)

4861547.17 hits per line

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

65.28
/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) {
3,467,269✔
23
  for (int32_t i = 0; i < nCols; i++) {
60,028,901✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
56,646,533✔
25
      return true;
84,901✔
26
    }
27
  }
28
  return false;
3,382,368✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
510,697✔
32
  if (pME->pExtSchemas) {
510,697✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
26,677✔
34
    bool                  hasTypeMods = false;
26,677✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
26,677✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
26,540✔
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,678✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
5,799,419✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
11,545,482!
46
    }
47
  }
48
  return 0;
510,698✔
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) {
3,308,675✔
71
  bool hasExtSchema = false;
3,308,675✔
72
  SSchemaWrapper* pSchWrapper = NULL;
3,308,675✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
3,308,675✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
3,306,389✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
2,286!
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
2,707✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
3,309,096✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
3,310,193!
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;
3,310,499✔
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) {
126,200✔
175
  int32_t code = 0;
126,200✔
176
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
252,400!
177
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
252,400!
178
  uTrace("encode cols:%d", pw->nCols);
126,200✔
179

180
  for (int32_t i = 0; i < pw->nCols; i++) {
24,455,165✔
181
    SColCmpr *p = &pw->pColCmpr[i];
24,328,994✔
182
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
48,657,988!
183
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
48,657,988!
184
  }
185
  return code;
126,171✔
186
}
187
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
126,038✔
188
  const SColCmprWrapper *pw = &pME->colCmpr;
126,038✔
189
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
126,038✔
190
}
191
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
3,888,184✔
192
  SColCmprWrapper *pWrapper = &pME->colCmpr;
3,888,184✔
193
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
7,777,088!
194
  if (pWrapper->nCols == 0) {
3,888,904!
195
    return 0;
×
196
  }
197

198
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
7,778,275!
199
  uDebug("dencode cols:%d", pWrapper->nCols);
3,889,371✔
200
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
3,889,459✔
201
  if (pWrapper->pColCmpr == NULL) {
3,891,907!
202
    return terrno;
×
203
  }
204

205
  for (int i = 0; i < pWrapper->nCols; i++) {
90,283,856✔
206
    SColCmpr *p = &pWrapper->pColCmpr[i];
86,388,085✔
207
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
172,768,576!
208
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
172,772,440!
209
  }
210
  return 0;
3,895,771✔
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) {
480,712✔
236
  if (pSrc->nCols > 0) {
480,712✔
237
    pDst->nCols = pSrc->nCols;
437,887✔
238
    pDst->version = pSrc->version;
437,887✔
239
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
437,887!
240
    if (NULL == pDst->pColCmpr) {
438,021!
241
      return terrno;
×
242
    }
243
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
438,021✔
244
  }
245
  return 0;
480,846✔
246
}
247

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

254
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
481,574✔
255
  if (pCmpr) {
481,574!
256
    taosMemoryFreeClear(pCmpr->pColCmpr);
481,592!
257
  }
258
}
481,620✔
259

260
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
547,505✔
261
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
547,505✔
262
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,097,046!
263
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,097,046!
264
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,097,046!
265

266
  if (pME->type > 0) {
548,523✔
267
    if (pME->name == NULL) {
511,845!
268
      return TSDB_CODE_INVALID_PARA;
×
269
    }
270

271
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,023,690!
272

273
    if (pME->type == TSDB_SUPER_TABLE) {
511,845✔
274
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
174,056!
275
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
174,056!
276
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
174,056!
277
      if (TABLE_IS_ROLLUP(pME->flags)) {
87,028!
278
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
279
      }
280
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
424,817✔
281
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
769,302!
282
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
769,302!
283
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
769,302!
284
      if (pME->ctbEntry.commentLen > 0) {
384,651✔
285
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
156!
286
      }
287
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
769,302!
288
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
384,651!
289
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
40,166!
290
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
80,332!
291
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
80,332!
292
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
80,332!
293
      if (pME->ntbEntry.commentLen > 0) {
40,166✔
294
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
76!
295
      }
296
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
80,332!
297
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
80,332!
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) {
511,746✔
305
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,340!
306
    } else {
307
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
510,406!
308
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
87,125✔
309
      } else if (pME->type == TSDB_NORMAL_TABLE) {
423,281✔
310
        if (pME->colCmpr.nCols != 0) {
39,204✔
311
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
38,934!
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));
511,510!
327
  }
328
  if (pME->type == TSDB_SUPER_TABLE) {
548,451✔
329
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
174,158!
330
  }
331

332
  tEndEncode(pCoder);
548,451✔
333
  return 0;
548,451✔
334
}
335

336
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
6,495,394✔
337
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
6,495,394!
338
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
13,004,557!
339
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
13,000,971!
340
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
12,994,503!
341

342
  if (headerOnly) {
6,494,757✔
343
    tEndDecode(pCoder);
1,290✔
344
    return 0;
1,290✔
345
  }
346

347
  if (pME->type > 0) {
6,493,467!
348
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
12,987,923!
349

350
    if (pME->type == TSDB_SUPER_TABLE) {
6,493,599✔
351
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
6,606,439!
352
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
6,594,242!
353
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
6,588,303!
354
      if (TABLE_IS_ROLLUP(pME->flags)) {
3,296,582!
355
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
356
      }
357
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
3,189,681✔
358
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
5,209,653!
359
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
5,207,421!
360
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
5,205,052!
361
      if (pME->ctbEntry.commentLen > 0) {
2,601,983✔
362
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
308!
363
      }
364
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
5,203,423!
365
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
2,601,440!
366
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
584,380!
367
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
1,168,607!
368
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
1,168,302!
369
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
1,167,725!
370
      if (pME->ntbEntry.commentLen > 0) {
583,650✔
371
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
218!
372
      }
373
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
1,167,220!
374
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
1,165,867!
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) {
6,491,241✔
386
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
3,306,198!
387
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
3,306,526!
388

389
        if (pME->colCmpr.nCols == 0) {
3,306,998!
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) {
3,185,043✔
397
      if (!tDecodeIsEnd(pCoder)) {
582,359!
398
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
582,372✔
399
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
582,375✔
400
        if (pME->colCmpr.nCols == 0) {
582,181!
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);
582,181✔
408
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
2,602,684✔
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)) {
6,489,797✔
420
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
3,309,147!
421
    }
422
  }
423
  if (pME->type == TSDB_SUPER_TABLE) {
6,489,819✔
424
    if (!tDecodeIsEnd(pCoder)) {
3,307,781!
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
6,615,700!
426
    }
427
  }
428

429

430
  tEndDecode(pCoder);
6,489,715✔
431
  return 0;
6,490,592✔
432
}
433

434
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
6,495,242✔
435

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

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

451
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
862,266✔
452
  if (pSchema) {
862,266!
453
    taosMemoryFreeClear(pSchema->pSchema);
862,281!
454
  }
455
}
862,460✔
456

457
void metaCloneEntryFree(SMetaEntry **ppEntry) {
481,647✔
458
  if (ppEntry == NULL || *ppEntry == NULL) {
481,647!
459
    return;
88✔
460
  }
461

462
  taosMemoryFreeClear((*ppEntry)->name);
481,559!
463

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

469
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
481,558✔
470
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
423,819✔
471
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
423,880✔
472
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
57,739✔
473
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
42,916!
474
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
42,916!
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);
481,602✔
482
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
481,610!
483
  metaCloneColRefFree(&(*ppEntry)->colRef);
481,613✔
484

485
  taosMemoryFreeClear(*ppEntry);
481,603!
486
  return;
481,634✔
487
}
488

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

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

496
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
481,412!
497
  if (NULL == *ppEntry) {
481,621!
498
    return terrno;
×
499
  }
500

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

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

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

518
  if (pEntry->type == TSDB_SUPER_TABLE) {
481,576✔
519
    (*ppEntry)->flags = pEntry->flags;
423,837✔
520

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

527
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
423,793✔
528
    if (code) {
423,758!
529
      metaCloneEntryFree(ppEntry);
×
530
      return code;
×
531
    }
532
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
423,778✔
533
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
57,739✔
534
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
42,916✔
535
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
42,916✔
536
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
42,916✔
537

538
    // comment
539
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
42,916✔
540
    if (pEntry->ctbEntry.commentLen > 0) {
42,916✔
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;
42,916✔
552
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
42,916!
553
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
42,916!
554
      code = terrno;
×
555
      metaCloneEntryFree(ppEntry);
×
556
      return code;
×
557
    }
558
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
42,916✔
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) {
481,517✔
587
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
792✔
588
    if (code) {
764!
589
      metaCloneEntryFree(ppEntry);
×
590
      return code;
×
591
    }
592
  } else {
593
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
480,725✔
594
    if (code) {
480,830✔
595
      metaCloneEntryFree(ppEntry);
31✔
596
      return code;
×
597
    }
598
  }
599
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
481,563!
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;
481,564✔
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