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

taosdata / TDengine / #3827

01 Apr 2025 11:58AM UTC coverage: 34.049% (-0.03%) from 34.075%
#3827

push

travis-ci

happyguoxy
test:alter gcda dir

148461 of 599532 branches covered (24.76%)

Branch coverage included in aggregate %.

222339 of 489477 relevant lines covered (45.42%)

762087.13 hits per line

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

53.27
/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

18
static bool schemasHasTypeMod(const SSchema *pSchema, int32_t nCols) {
12,775✔
19
  for (int32_t i = 0; i < nCols; i++) {
269,033✔
20
    if (HAS_TYPE_MOD(pSchema + i)) {
256,438✔
21
      return true;
180✔
22
    }
23
  }
24
  return false;
12,595✔
25
}
26

27
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
7,779✔
28
  if (pME->pExtSchemas) {
7,779✔
29
    const SSchemaWrapper *pSchWrapper = NULL;
72✔
30
    bool                  hasTypeMods = false;
72✔
31
    if (pME->type == TSDB_SUPER_TABLE) {
72!
32
      pSchWrapper = &pME->stbEntry.schemaRow;
72✔
33
    } else if (pME->type == TSDB_NORMAL_TABLE) {
×
34
      pSchWrapper = &pME->ntbEntry.schemaRow;
×
35
    } else {
36
      return 0;
×
37
    }
38
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
72✔
39

40
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
380!
41
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
616!
42
    }
43
  }
44
  return 0;
7,779✔
45
}
46

47
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
×
48
  const SColRefWrapper *pw = &pME->colRef;
×
49
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
×
50
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
×
51
  uTrace("encode cols:%d", pw->nCols);
×
52

53
  for (int32_t i = 0; i < pw->nCols; i++) {
×
54
    SColRef *p = &pw->pColRef[i];
×
55
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
×
56
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
×
57
    if (p->hasRef) {
×
58
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
×
59
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
×
60
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
×
61
    }
62
  }
63
  return 0;
×
64
}
65

66
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
31,657✔
67
  bool hasExtSchema = false;
31,657✔
68
  SSchemaWrapper* pSchWrapper = NULL;
31,657✔
69
  if (pME->type == TSDB_SUPER_TABLE) {
31,657✔
70
    pSchWrapper = &pME->stbEntry.schemaRow;
12,658✔
71
  } else if (pME->type == TSDB_NORMAL_TABLE) {
18,999!
72
    pSchWrapper = &pME->ntbEntry.schemaRow;
×
73
  } else {
74
    return 0;
18,999✔
75
  }
76

77
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
12,658✔
78
  if (hasExtSchema && pSchWrapper->nCols > 0) {
12,663!
79
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
108!
80
    if (pME->pExtSchemas == NULL) {
108!
81
      return terrno;
×
82
    }
83

84
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
564!
85
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
912!
86
    }
87
  }
88

89
  return 0;
12,663✔
90
}
91

92
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
47✔
93
  const SSchemaWrapper *pSchWrapper = NULL;
47✔
94
  bool                  hasTypeMods = false;
47✔
95
  if (pME->type == TSDB_SUPER_TABLE) {
47✔
96
    pSchWrapper = &pME->stbEntry.schemaRow;
45✔
97
  } else if (pME->type == TSDB_NORMAL_TABLE) {
2!
98
    pSchWrapper = &pME->ntbEntry.schemaRow;
2✔
99
  } else {
100
    return NULL;
×
101
  }
102
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
47✔
103

104
  if (hasTypeMods) {
47!
105
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
×
106
    if (ret != NULL) {
×
107
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
×
108
    }
109
    return ret;
×
110
  }
111
  return NULL;
47✔
112
}
113

114
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
×
115
  SColRefWrapper *pWrapper = &pME->colRef;
×
116
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
×
117
  if (pWrapper->nCols == 0) {
×
118
    return 0;
×
119
  }
120

121
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
×
122
  uDebug("decode cols:%d", pWrapper->nCols);
×
123
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
×
124
  if (pWrapper->pColRef == NULL) {
×
125
    return terrno;
×
126
  }
127

128
  for (int i = 0; i < pWrapper->nCols; i++) {
×
129
    SColRef *p = &pWrapper->pColRef[i];
×
130
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
×
131
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
×
132
    if (p->hasRef) {
×
133
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
×
134
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
×
135
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
×
136
    }
137
  }
138
  return 0;
×
139
}
140

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

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

157
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
×
158
  if (pSrc->nCols > 0) {
×
159
    pDst->nCols = pSrc->nCols;
×
160
    pDst->version = pSrc->version;
×
161
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
×
162
    if (NULL == pDst->pColRef) {
×
163
      return terrno;
×
164
    }
165
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
×
166
  }
167
  return 0;
×
168
}
169

170
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
7,778✔
171
  const SColCmprWrapper *pw = &pME->colCmpr;
7,778✔
172
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
15,556!
173
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
15,556!
174
  uTrace("encode cols:%d", pw->nCols);
7,778✔
175

176
  for (int32_t i = 0; i < pw->nCols; i++) {
13,601✔
177
    SColCmpr *p = &pw->pColCmpr[i];
5,824✔
178
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
11,648!
179
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
11,648!
180
  }
181
  return 0;
7,777✔
182
}
183
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
13,154✔
184
  SColCmprWrapper *pWrapper = &pME->colCmpr;
13,154✔
185
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
26,306!
186
  if (pWrapper->nCols == 0) {
13,152✔
187
    return 0;
25✔
188
  }
189

190
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
26,255!
191
  uDebug("dencode cols:%d", pWrapper->nCols);
13,128✔
192
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
13,130✔
193
  if (pWrapper->pColCmpr == NULL) {
13,133!
194
    return terrno;
×
195
  }
196

197
  for (int i = 0; i < pWrapper->nCols; i++) {
116,873✔
198
    SColCmpr *p = &pWrapper->pColCmpr[i];
103,737✔
199
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
207,481!
200
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
207,484!
201
  }
202
  return 0;
13,136✔
203
}
204
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
205
                                                            SSchemaWrapper *pSchema) {
206
  pCmpr->nCols = pSchema->nCols;
347✔
207
  if ((pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr))) == NULL) {
348!
208
    return terrno;
×
209
  }
210

211
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
155,861!
212
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
155,746✔
213
    SSchema  *pColSchema = &pSchema->pSchema[i];
155,746✔
214
    pColCmpr->id = pColSchema->colId;
155,746✔
215
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
155,746✔
216
  }
217
  return 0;
115✔
218
}
219

220
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
21,206✔
221
  if (pSrc->nCols > 0) {
21,206✔
222
    pDst->nCols = pSrc->nCols;
4,495✔
223
    pDst->version = pSrc->version;
4,495✔
224
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
4,495!
225
    if (NULL == pDst->pColCmpr) {
4,495!
226
      return terrno;
×
227
    }
228
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
4,495✔
229
  }
230
  return 0;
21,206✔
231
}
232

233
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
21,207✔
234
  if (pColRef) {
21,207!
235
    taosMemoryFreeClear(pColRef->pColRef);
21,207!
236
  }
237
}
21,207✔
238

239
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
21,206✔
240
  if (pCmpr) {
21,206!
241
    taosMemoryFreeClear(pCmpr->pColCmpr);
21,206!
242
  }
243
}
21,206✔
244

245
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
9,450✔
246
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
9,450✔
247
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
18,908!
248
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
18,908!
249
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
18,908!
250

251
  if (pME->type > 0) {
9,454✔
252
    if (pME->name == NULL) {
7,781!
253
      return TSDB_CODE_INVALID_PARA;
×
254
    }
255

256
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
15,562!
257

258
    if (pME->type == TSDB_SUPER_TABLE) {
7,781✔
259
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
1,718!
260
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
1,718!
261
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
1,718!
262
      if (TABLE_IS_ROLLUP(pME->flags)) {
859!
263
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
264
      }
265
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
6,922!
266
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
13,580!
267
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
13,580!
268
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
13,580!
269
      if (pME->ctbEntry.commentLen > 0) {
6,790!
270
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
×
271
      }
272
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
13,580!
273
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
6,790!
274
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
132!
275
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
264!
276
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
264!
277
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
264!
278
      if (pME->ntbEntry.commentLen > 0) {
132!
279
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
×
280
      }
281
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
264!
282
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
264!
283
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
284
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
285
    } else {
286
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
287
      return TSDB_CODE_INVALID_PARA;
×
288
    }
289
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
7,777!
290
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
×
291
    } else {
292
      TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
7,777!
293
    }
294
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
7,780!
295
  }
296
  if (pME->type == TSDB_SUPER_TABLE) {
9,451✔
297
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
1,718!
298
  }
299

300
  tEndEncode(pCoder);
9,451✔
301
  return 0;
9,451✔
302
}
303

304
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
32,489✔
305
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
32,489!
306
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
65,003!
307
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
65,000!
308
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
64,992!
309

310
  if (headerOnly) {
32,493!
311
    tEndDecode(pCoder);
×
312
    return 0;
×
313
  }
314

315
  if (pME->type > 0) {
32,493✔
316
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
64,985!
317

318
    if (pME->type == TSDB_SUPER_TABLE) {
32,494✔
319
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
25,415!
320
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
25,363!
321
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
25,370!
322
      if (TABLE_IS_ROLLUP(pME->flags)) {
12,716!
323
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
324
      }
325
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
19,788!
326
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
38,042!
327
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
38,040!
328
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
38,040!
329
      if (pME->ctbEntry.commentLen > 0) {
19,020!
330
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
×
331
      }
332
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
38,039!
333
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
19,019!
334
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
766!
335
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
1,532!
336
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
1,532!
337
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
1,532!
338
      if (pME->ntbEntry.commentLen > 0) {
766!
339
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
×
340
      }
341
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
1,532!
342
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
1,532!
343
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
344
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
345
      if (!pME->smaEntry.tsma) {
×
346
        return terrno;
×
347
      }
348
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
349
    } else {
350
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
351
      return TSDB_CODE_INVALID_PARA;
×
352
    }
353
    if (pME->type == TSDB_SUPER_TABLE) {
32,496✔
354
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
12,711✔
355
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
12,389!
356

357
        if (pME->colCmpr.nCols == 0) {
12,391✔
358
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
50!
359
        }
360
      } else {
361
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
412!
362
        TABLE_SET_COL_COMPRESSED(pME->flags);
90✔
363
      }
364
    } else if (pME->type == TSDB_NORMAL_TABLE) {
19,785✔
365
      if (!tDecodeIsEnd(pCoder)) {
766!
366
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
766✔
367
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
766!
368
        if (pME->colCmpr.nCols == 0) {
766!
369
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
370
        }
371
      } else {
372
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
373
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
374
      }
375
      TABLE_SET_COL_COMPRESSED(pME->flags);
766✔
376
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
19,019!
377
      if (!tDecodeIsEnd(pCoder)) {
×
378
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
×
379
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
×
380
      } else {
381
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
382
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
226!
383
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
384
        }
385
      }
386
    }
387
    if (!tDecodeIsEnd(pCoder)) {
32,492✔
388
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
31,658!
389
    }
390
  }
391
  if (pME->type == TSDB_SUPER_TABLE) {
32,494✔
392
    if (!tDecodeIsEnd(pCoder)) {
12,712✔
393
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
25,324!
394
    }
395
  }
396

397

398
  tEndDecode(pCoder);
32,494✔
399
  return 0;
32,497✔
400
}
401

402
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
32,491✔
403

404
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
8,932✔
405
  if (pSrc == NULL || pDst == NULL) {
8,932!
406
    return TSDB_CODE_INVALID_PARA;
407
  }
408

409
  pDst->nCols = pSrc->nCols;
8,933✔
410
  pDst->version = pSrc->version;
8,933✔
411
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
8,933!
412
  if (pDst->pSchema == NULL) {
8,934!
413
    return terrno;
×
414
  }
415
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
8,934✔
416
  return TSDB_CODE_SUCCESS;
8,934✔
417
}
418

419
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
8,931✔
420
  if (pSchema) {
8,931!
421
    taosMemoryFreeClear(pSchema->pSchema);
8,932!
422
  }
423
}
8,932✔
424

425
void metaCloneEntryFree(SMetaEntry **ppEntry) {
21,205✔
426
  if (ppEntry == NULL || *ppEntry == NULL) {
21,205!
427
    return;
×
428
  }
429

430
  taosMemoryFreeClear((*ppEntry)->name);
21,205!
431

432
  if ((*ppEntry)->type < 0) {
21,206!
433
    taosMemoryFreeClear(*ppEntry);
×
434
    return;
×
435
  }
436

437
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
21,206✔
438
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
4,439✔
439
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
4,439✔
440
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
16,767!
441
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
16,711!
442
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
16,711!
443
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
56!
444
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
56✔
445
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
56!
446
  } else {
447
    return;
×
448
  }
449
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
21,206✔
450
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
21,206!
451
  metaCloneColRefFree(&(*ppEntry)->colRef);
21,206✔
452

453
  taosMemoryFreeClear(*ppEntry);
21,207!
454
  return;
21,204✔
455
}
456

457
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
21,205✔
458
  int32_t code = TSDB_CODE_SUCCESS;
21,205✔
459

460
  if (NULL == pEntry || NULL == ppEntry) {
21,205!
461
    return TSDB_CODE_INVALID_PARA;
462
  }
463

464
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
21,206!
465
  if (NULL == *ppEntry) {
21,205!
466
    return terrno;
×
467
  }
468

469
  (*ppEntry)->version = pEntry->version;
21,205✔
470
  (*ppEntry)->type = pEntry->type;
21,205✔
471
  (*ppEntry)->uid = pEntry->uid;
21,205✔
472

473
  if (pEntry->type < 0) {
21,205!
474
    return TSDB_CODE_SUCCESS;
×
475
  }
476

477
  if (pEntry->name) {
21,205!
478
    (*ppEntry)->name = tstrdup(pEntry->name);
21,205✔
479
    if (NULL == (*ppEntry)->name) {
21,206!
480
      code = terrno;
×
481
      metaCloneEntryFree(ppEntry);
×
482
      return code;
×
483
    }
484
  }
485

486
  if (pEntry->type == TSDB_SUPER_TABLE) {
21,206✔
487
    (*ppEntry)->flags = pEntry->flags;
4,438✔
488

489
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
4,438✔
490
    if (code) {
4,437!
491
      metaCloneEntryFree(ppEntry);
×
492
      return code;
×
493
    }
494

495
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
4,437✔
496
    if (code) {
4,439!
497
      metaCloneEntryFree(ppEntry);
×
498
      return code;
×
499
    }
500
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
4,439✔
501
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
16,768!
502
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
16,712✔
503
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
16,712✔
504
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
16,712✔
505

506
    // comment
507
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
16,712✔
508
    if (pEntry->ctbEntry.commentLen > 0) {
16,712!
509
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
×
510
      if (NULL == (*ppEntry)->ctbEntry.comment) {
×
511
        code = terrno;
×
512
        metaCloneEntryFree(ppEntry);
×
513
        return code;
×
514
      }
515
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
×
516
    }
517

518
    // tags
519
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
16,712✔
520
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
16,712!
521
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
16,712!
522
      code = terrno;
×
523
      metaCloneEntryFree(ppEntry);
×
524
      return code;
×
525
    }
526
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
16,712✔
527
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
56!
528
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
56✔
529
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
56✔
530
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
56✔
531

532
    // schema
533
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
56✔
534
    if (code) {
56!
535
      metaCloneEntryFree(ppEntry);
×
536
      return code;
×
537
    }
538

539
    // comment
540
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
56✔
541
    if (pEntry->ntbEntry.commentLen > 0) {
56!
542
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
×
543
      if (NULL == (*ppEntry)->ntbEntry.comment) {
×
544
        code = terrno;
×
545
        metaCloneEntryFree(ppEntry);
×
546
        return code;
×
547
      }
548
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
×
549
    }
550
  } else {
551
    return TSDB_CODE_INVALID_PARA;
×
552
  }
553

554
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
21,207!
555
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1✔
556
    if (code) {
×
557
      metaCloneEntryFree(ppEntry);
×
558
      return code;
×
559
    }
560
  } else {
561
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
21,206✔
562
    if (code) {
21,207✔
563
      metaCloneEntryFree(ppEntry);
1✔
564
      return code;
×
565
    }
566
  }
567
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
21,206!
568
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
72!
569
    if (!(*ppEntry)->pExtSchemas) {
72!
570
      code = terrno;
×
571
      metaCloneEntryFree(ppEntry);
×
572
      return code;
×
573
    }
574
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
72✔
575
  }
576

577
  return code;
21,206✔
578
}
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