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

taosdata / TDengine / #5034

24 Apr 2026 11:25AM UTC coverage: 73.058%. Remained the same
#5034

push

travis-ci

web-flow
merge: from main to 3.0 branch #35224

merge: from main to 3.0 branch[manual-only]

1336 of 1975 new or added lines in 48 files covered. (67.65%)

14149 existing lines in 164 files now uncovered.

275896 of 377640 relevant lines covered (73.06%)

132944440.29 hits per line

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

79.11
/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
bool schemasHasTypeMod(const SSchema *pSchema, int32_t nCols) {
1,348,062,064✔
23
  for (int32_t i = 0; i < nCols; i++) {
2,147,483,647✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
2,147,483,647✔
25
      return true;
170,595,287✔
26
    }
27
  }
28
  return false;
1,175,026,631✔
29
}
30

31
static const SSchemaWrapper *metaGetEntryRowSchema(const SMetaEntry *pME) {
1,736,185,669✔
32
  if (pME == NULL) {
1,736,185,669✔
33
    return NULL;
×
34
  }
35

36
  if (pME->type == TSDB_SUPER_TABLE) {
1,736,185,669✔
37
    return &pME->stbEntry.schemaRow;
1,208,103,641✔
38
  }
39

40
  if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
528,334,814✔
41
    return &pME->ntbEntry.schemaRow;
338,105,714✔
42
  }
43

44
  return NULL;
190,215,149✔
45
}
46

47
static int32_t metaGetEntryRowSchemaNum(const SMetaEntry *pME) {
210,197,398✔
48
  const SSchemaWrapper *pSchema = metaGetEntryRowSchema(pME);
210,197,398✔
49
  return pSchema == NULL ? 0 : pSchema->nCols;
210,224,279✔
50
}
51

52
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
215,459,484✔
53
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
215,459,484✔
54
  bool                  hasTypeMods = false;
215,485,887✔
55

56
  if (pME->pExtSchemas == NULL || pSchWrapper == NULL) {
215,485,887✔
57
    return 0;
202,388,658✔
58
  }
59

60
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
13,092,931✔
61
  for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,398,703,242✔
62
    TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
63
  }
64
  return 0;
13,250,655✔
65
}
66

67
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
2,082,760✔
68
  const SColRefWrapper *pw = &pME->colRef;
2,082,760✔
69
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
4,166,158✔
70
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
4,166,796✔
71
  uTrace("encode cols:%d", pw->nCols);
2,083,398✔
72

73
  for (int32_t i = 0; i < pw->nCols; i++) {
487,962,842✔
74
    SColRef *p = &pw->pColRef[i];
485,880,082✔
75
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
971,758,250✔
76
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
971,758,250✔
77
    if (p->hasRef) {
485,879,444✔
78
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
644,005,926✔
79
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
644,007,202✔
80
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
644,006,564✔
81
    }
82
  }
83

84
  // Encode tag references
85
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nTagRefs));
4,161,692✔
86
  for (int32_t i = 0; i < pw->nTagRefs; i++) {
2,082,122✔
87
    SColRef *p = &pw->pTagRef[i];
×
88
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
×
89
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
×
90
    if (p->hasRef) {
×
91
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
×
92
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
×
93
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
×
94
    }
95
  }
96

97
  return 0;
2,082,122✔
98
}
99

100
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
1,262,991,058✔
101
  bool                  hasExtSchema = false;
1,262,991,058✔
102
  const SSchemaWrapper* pSchWrapper = metaGetEntryRowSchema((const SMetaEntry*)pME);
1,262,991,058✔
103

104
  if (pSchWrapper == NULL) {
1,262,923,596✔
105
    return 0;
×
106
  }
107

108
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,262,923,596✔
109
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,263,115,547✔
110
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
312,666,295✔
111
    if (pME->pExtSchemas == NULL) {
156,336,770✔
112
      return terrno;
×
113
    }
114

115
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
2,147,483,647✔
116
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
2,147,483,647✔
117
    }
118
  } else {
119
    pME->pExtSchemas = NULL;
1,106,780,016✔
120
  }
121

122
  return 0;
1,263,134,157✔
123
}
124

125
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
47,549,195✔
126
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
47,549,195✔
127
  bool                  hasTypeMods = false;
47,596,121✔
128

129
  if (pSchWrapper == NULL) {
47,596,121✔
130
    return NULL;
×
131
  }
132

133
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
47,596,121✔
134

135
  if (hasTypeMods) {
47,534,983✔
136
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
36,754✔
137
    if (ret != NULL) {
36,754✔
138
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
36,754✔
139
    }
140
    return ret;
36,754✔
141
  }
142
  return NULL;
47,498,229✔
143
}
144

145
int32_t metaGetRsmaSchema(const SMetaEntry *pME, SSchemaRsma **rsmaSchema) {
29,119✔
146
  if (!rsmaSchema) return 0;
29,119✔
147
  if ((pME->type != TSDB_SUPER_TABLE) || !TABLE_IS_ROLLUP(pME->flags)) {  // only support super table
29,119✔
148
    *rsmaSchema = NULL;
×
149
    return 0;
×
150
  }
151

152
  const SRSmaParam *pParam = &pME->stbEntry.rsmaParam;
29,119✔
153
  const SSchema    *pSchema = pME->stbEntry.schemaRow.pSchema;
29,119✔
154
  int32_t           nCols = pME->stbEntry.schemaRow.nCols;
29,119✔
155

156
  *rsmaSchema = (SSchemaRsma *)taosMemoryMalloc(sizeof(SSchemaRsma));
29,119✔
157
  if (*rsmaSchema == NULL) {
29,119✔
158
    return terrno;
×
159
  }
160

161
  (*rsmaSchema)->funcIds = taosMemoryMalloc(sizeof(func_id_t) * nCols);
29,119✔
162
  if ((*rsmaSchema)->funcIds == NULL) {
29,119✔
163
    taosMemoryFree(*rsmaSchema);
×
164
    *rsmaSchema = NULL;
×
165
    return terrno;
×
166
  }
167

168
  (void)snprintf((*rsmaSchema)->tbName, TSDB_TABLE_NAME_LEN, "%s", pME->name);
29,119✔
169
  (*rsmaSchema)->tbUid = pME->uid;
29,119✔
170
  (*rsmaSchema)->tbType = pME->type;
29,119✔
171
  (*rsmaSchema)->interval[0] = pParam->interval[0];
29,119✔
172
  (*rsmaSchema)->interval[1] = pParam->interval[1];
29,119✔
173
  (*rsmaSchema)->nFuncs = nCols;
29,119✔
174

175
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
29,119✔
176
  int32_t    i = 0, j = 0;
29,119✔
177
  for (i = 0; i < nCols; ++i) {
220,360✔
178
    while (j < pParam->nFuncs) {
347,854✔
179
      if (pParam->funcColIds[j] == pSchema[i].colId) {
333,688✔
180
        pFuncIds[i] = pParam->funcIds[j];
155,826✔
181
        break;
155,826✔
182
      }
183
      if (pParam->funcColIds[j] > pSchema[i].colId) {
177,862✔
184
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
35,415✔
185
        break;
35,415✔
186
      }
187
      ++j;
142,447✔
188
    }
189
    if (j >= pParam->nFuncs) {
205,407✔
190
      for (; i < nCols; ++i) {
28,332✔
191
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
14,166✔
192
      }
193
      break;
14,166✔
194
    }
195
  }
196
  pFuncIds[0] = 0;  // Primary TS column has no function
29,119✔
197

198
  return 0;
29,119✔
199
}
200

201
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
41,367,722✔
202
  SColRefWrapper *pWrapper = &pME->colRef;
41,367,722✔
203
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
82,745,046✔
204
  if (pWrapper->nCols == 0) {
41,367,104✔
205
    return 0;
×
206
  }
207

208
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
82,739,281✔
209
  uDebug("decode cols:%d", pWrapper->nCols);
41,374,743✔
210
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
82,731,751✔
211
  if (pWrapper->pColRef == NULL) {
41,354,882✔
212
    return terrno;
×
213
  }
214

215
  for (int i = 0; i < pWrapper->nCols; i++) {
711,025,166✔
216
    SColRef *p = &pWrapper->pColRef[i];
669,634,719✔
217
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,339,325,557✔
218
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,339,381,309✔
219
    if (p->hasRef) {
669,701,329✔
220
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
380,249,368✔
221
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
380,237,421✔
222
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
380,220,979✔
223
    }
224
  }
225

226
  // Decode tag references (backward compatible)
227
  pWrapper->nTagRefs = 0;
41,340,165✔
228
  pWrapper->pTagRef = NULL;
41,390,635✔
229
  if (!tDecodeIsEnd(pDecoder)) {
41,390,629✔
230
    TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nTagRefs));
82,772,138✔
231
    if (pWrapper->nTagRefs > 0) {
41,380,865✔
232
      pWrapper->pTagRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nTagRefs * sizeof(SColRef));
×
233
      if (pWrapper->pTagRef == NULL) {
×
234
        return terrno;
×
235
      }
236

237
      for (int i = 0; i < pWrapper->nTagRefs; i++) {
×
238
        SColRef *p = &pWrapper->pTagRef[i];
×
239
        TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
×
240
        TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
×
241
        if (p->hasRef) {
×
242
          TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
×
243
          TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
×
244
          TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
×
245
        }
246
      }
247
    }
248
  }
249

250
  return 0;
41,364,269✔
251
}
252

253
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
254
                                                            SSchemaWrapper *pSchema) {
255
  pRef->nCols = pSchema->nCols;
×
256
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
257
    return terrno;
×
258
  }
259

260
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
261
    SColRef  *pColRef = &pRef->pColRef[i];
×
262
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
263
    pColRef->id = pColSchema->colId;
×
264
    pColRef->hasRef = false;
×
265
  }
266
  return 0;
×
267
}
268

269
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
1,324,242✔
270
  if (pSrc->nCols > 0) {
1,324,242✔
271
    pDst->nCols = pSrc->nCols;
1,324,242✔
272
    pDst->version = pSrc->version;
1,324,242✔
273
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,324,242✔
274
    if (NULL == pDst->pColRef) {
1,324,242✔
275
      return terrno;
×
276
    }
277
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,324,242✔
278
  }
279
  return 0;
1,324,242✔
280
}
281

282
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
50,523,656✔
283
  int32_t code = 0;
50,523,656✔
284
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
101,039,835✔
285
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
101,058,454✔
286
  uTrace("encode cols:%d", pw->nCols);
50,542,275✔
287

288
  for (int32_t i = 0; i < pw->nCols; i++) {
2,147,483,647✔
289
    SColCmpr *p = &pw->pColCmpr[i];
2,147,483,647✔
290
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
2,147,483,647✔
291
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
2,147,483,647✔
292
  }
293
  return code;
50,586,548✔
294
}
295
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
50,285,874✔
296
  const SColCmprWrapper *pw = &pME->colCmpr;
50,285,874✔
297
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
50,329,396✔
298
}
299
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,262,944,619✔
300
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,262,944,619✔
301
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
302
  if (pWrapper->nCols == 0) {
1,262,986,817✔
303
    return 0;
×
304
  }
305

306
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
2,147,483,647✔
307
  uDebug("dencode cols:%d", pWrapper->nCols);
1,262,950,190✔
308
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
309
  if (pWrapper->pColCmpr == NULL) {
1,263,217,448✔
310
    return terrno;
×
311
  }
312

313
  for (int i = 0; i < pWrapper->nCols; i++) {
2,147,483,647✔
314
    SColCmpr *p = &pWrapper->pColCmpr[i];
2,147,483,647✔
315
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
2,147,483,647✔
316
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
2,147,483,647✔
317
  }
318
  return 0;
1,263,519,662✔
319
}
320
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
321
                                                            SSchemaWrapper *pSchema) {
322
  pCmpr->nCols = pSchema->nCols;
264,712✔
323

324
  if (pDecoder == NULL) {
264,712✔
325
    pCmpr->pColCmpr = taosMemoryCalloc(1, pCmpr->nCols * sizeof(SColCmpr));
264,712✔
326
  } else {
327
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
328
  }
329

330
  if (pCmpr->pColCmpr == NULL) {
264,712✔
331
    return terrno;
×
332
  }
333

334
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,306,680✔
335
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,041,968✔
336
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,041,968✔
337
    pColCmpr->id = pColSchema->colId;
1,041,968✔
338
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,041,968✔
339
  }
340
  return 0;
264,712✔
341
}
342

343
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
208,879,149✔
344
  if (pSrc->nCols > 0) {
208,879,149✔
345
    pDst->nCols = pSrc->nCols;
183,550,780✔
346
    pDst->version = pSrc->version;
183,547,908✔
347
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
183,539,423✔
348
    if (NULL == pDst->pColCmpr) {
183,522,396✔
349
      return terrno;
×
350
    }
351
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
183,523,844✔
352
  }
353
  return 0;
208,878,280✔
354
}
355

356
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
210,194,243✔
357
  if (pColRef) {
210,194,243✔
358
    taosMemoryFreeClear(pColRef->pColRef);
210,215,038✔
359
  }
360
}
210,208,595✔
361

362
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
210,196,726✔
363
  if (pCmpr) {
210,196,726✔
364
    taosMemoryFreeClear(pCmpr->pColCmpr);
210,214,333✔
365
  }
366
}
210,206,338✔
367

368
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
221,126,894✔
369
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
221,126,894✔
370
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
442,314,664✔
371
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
442,227,186✔
372
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
442,224,726✔
373

374
  if (pME->type > 0) {
221,142,170✔
375
    if (pME->name == NULL) {
215,474,670✔
376
      return TSDB_CODE_INVALID_PARA;
×
377
    }
378

379
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
430,958,687✔
380

381
    if (pME->type == TSDB_SUPER_TABLE) {
215,491,628✔
382
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
55,122,483✔
383
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
55,173,716✔
384
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
55,211,818✔
385
      if (TABLE_IS_ROLLUP(pME->flags)) {
27,583,568✔
386
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
118,796✔
387
      }
388
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
187,883,997✔
389
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
328,076,733✔
390
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
328,093,103✔
391
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
328,102,483✔
392
      if (pME->ctbEntry.commentLen > 0) {
164,051,009✔
393
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
30,864✔
394
      }
395
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
328,083,413✔
396
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
164,038,439✔
397
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
23,861,560✔
398
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
47,723,120✔
399
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
47,723,120✔
400
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
47,723,120✔
401
      if (pME->ntbEntry.commentLen > 0) {
23,861,560✔
402
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
43,600✔
403
      }
404
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
47,723,120✔
405
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
47,723,120✔
406
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
407
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
408
    } else {
409
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
410
      return TSDB_CODE_INVALID_PARA;
×
411
    }
412
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
215,466,441✔
413
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,110,975✔
414
    } else {
415
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
213,369,273✔
416
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
27,583,009✔
417
      } else if (pME->type == TSDB_NORMAL_TABLE) {
185,854,326✔
418
        if (pME->colCmpr.nCols != 0) {
22,991,222✔
419
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
22,726,510✔
420
        } else {
421
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
264,712✔
422
          SColCmprWrapper colCmprs = {0};
264,712✔
423
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
264,712✔
424
          if (code != 0) {
264,712✔
425
            taosMemoryFree(colCmprs.pColCmpr);
×
426
            TAOS_CHECK_RETURN(code);
×
427
          }
428
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
264,712✔
429
          taosMemoryFree(colCmprs.pColCmpr);
264,712✔
430
          TAOS_CHECK_RETURN(code);
264,712✔
431
        }
432
      }
433
    }
434
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
215,501,047✔
435
  }
436
  if (pME->type == TSDB_SUPER_TABLE) {
221,159,183✔
437
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
55,137,525✔
438
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
55,075,917✔
439
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->stbEntry.securityLevel));
55,037,624✔
440
  } else if (pME->type == TSDB_NORMAL_TABLE) {
193,534,386✔
441
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
45,982,444✔
442
  }
443

444
  tEndEncode(pCoder);
221,060,929✔
445
  return 0;
221,116,236✔
446
}
447

448
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
2,132,608,913✔
449
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
2,132,608,913✔
450
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
2,147,483,647✔
451
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
2,147,483,647✔
452
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
2,147,483,647✔
453

454
  if (headerOnly) {
2,133,293,440✔
455
    tEndDecode(pCoder);
337,276✔
456
    return 0;
337,276✔
457
  }
458

459
  if (pME->type > 0) {
2,132,956,164✔
460
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
2,147,483,647✔
461

462
    if (pME->type == TSDB_SUPER_TABLE) {
2,132,819,687✔
463
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,942,347,835✔
464
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,942,438,556✔
465
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,942,311,519✔
466
      if (TABLE_IS_ROLLUP(pME->flags)) {
971,052,712✔
467
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
361,399✔
468
      }
469
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,161,270,645✔
470
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,724,310,270✔
471
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,724,443,577✔
472
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,724,302,352✔
473
      if (pME->ctbEntry.commentLen > 0) {
862,082,399✔
474
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
53,378✔
475
      }
476
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,724,198,257✔
477
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
862,202,895✔
478
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
299,354,073✔
479
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
598,886,811✔
480
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
598,993,561✔
481
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
598,880,478✔
482
      if (pME->ntbEntry.commentLen > 0) {
299,389,545✔
483
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
80,306✔
484
      }
485
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
598,757,955✔
486
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
598,807,672✔
UNCOV
487
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
488
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
489
      if (!pME->smaEntry.tsma) {
×
490
        return terrno;
×
491
      }
UNCOV
492
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
493
    } else {
UNCOV
494
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
495
      return TSDB_CODE_INVALID_PARA;
×
496
    }
497
    if (pME->type == TSDB_SUPER_TABLE) {
2,132,305,942✔
498
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
971,141,308✔
499
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
971,064,047✔
500

501
        if (pME->colCmpr.nCols == 0) {
971,256,721✔
UNCOV
502
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
503
        }
504
      } else {
UNCOV
505
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
506
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
507
      }
508
    } else if (pME->type == TSDB_NORMAL_TABLE) {
1,161,017,696✔
509
      if (!tDecodeIsEnd(pCoder)) {
292,207,908✔
510
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
292,216,923✔
511
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
292,216,923✔
512
        if (pME->colCmpr.nCols == 0) {
292,100,596✔
UNCOV
513
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
514
        }
515
      } else {
UNCOV
516
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
UNCOV
517
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
518
      }
519
      TABLE_SET_COL_COMPRESSED(pME->flags);
292,135,563✔
520
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
869,036,988✔
521
      if (!tDecodeIsEnd(pCoder)) {
41,389,883✔
522
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
41,389,257✔
523
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
41,389,257✔
524
      } else {
525
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
626✔
526
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
626✔
527
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
528
        }
529
      }
530
    }
531
    if (!tDecodeIsEnd(pCoder)) {
2,132,668,706✔
532
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
1,263,357,977✔
533
    } else {
534
      pME->pExtSchemas = NULL;
869,310,729✔
535
    }
536
  }
537
  if (pME->type == TSDB_SUPER_TABLE) {
2,132,324,322✔
538
    if (!tDecodeIsEnd(pCoder)) {
970,932,076✔
539
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,942,174,055✔
540
    }
541
    if (!tDecodeIsEnd(pCoder)) {
971,034,039✔
542
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,942,062,374✔
543
    }
544
    if (!tDecodeIsEnd(pCoder)) {
970,854,253✔
545
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->stbEntry.securityLevel));
1,942,036,313✔
546
    }
547
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,161,223,459✔
548
    if (!tDecodeIsEnd(pCoder)) {
292,162,801✔
549
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
584,388,012✔
550
    }
551
  }
552

553

554
  tEndDecode(pCoder);
2,132,379,564✔
555
  return 0;
2,132,431,789✔
556
}
557

558
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
2,132,369,228✔
559

560
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
358,974,537✔
561
  if (pSrc == NULL || pDst == NULL) {
358,974,537✔
562
    return TSDB_CODE_INVALID_PARA;
19✔
563
  }
564

565
  pDst->nCols = pSrc->nCols;
359,002,374✔
566
  pDst->version = pSrc->version;
358,991,765✔
567
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
358,998,345✔
568
  if (pDst->pSchema == NULL) {
358,880,677✔
UNCOV
569
    return terrno;
×
570
  }
571
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
358,906,748✔
572
  return TSDB_CODE_SUCCESS;
359,001,938✔
573
}
574

575
static int32_t metaCloneRsmaParam(const SRSmaParam *pSrc, SRSmaParam *pDst) {
79,653✔
576
  if (pSrc == NULL || pDst == NULL) {
79,653✔
UNCOV
577
    return TSDB_CODE_INVALID_PARA;
×
578
  }
579
  memcpy(pDst, pSrc, sizeof(SRSmaParam));
79,653✔
580
  pDst->name = tstrdup(pSrc->name);
79,653✔
581
  if (pDst->name == NULL) {
79,653✔
UNCOV
582
    return terrno;
×
583
  }
584
  if (pSrc->nFuncs > 0) {
79,653✔
585
    pDst->nFuncs = pSrc->nFuncs;
79,653✔
586
    pDst->funcColIds = (col_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(col_id_t));
79,653✔
587
    if (pDst->funcColIds == NULL) {
79,653✔
UNCOV
588
      return terrno;
×
589
    }
590
    memcpy(pDst->funcColIds, pSrc->funcColIds, pSrc->nFuncs * sizeof(col_id_t));
79,653✔
591

592
    pDst->funcIds = (func_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(func_id_t));
79,653✔
593
    if (pDst->funcIds == NULL) {
79,653✔
UNCOV
594
      return terrno;
×
595
    }
596
    memcpy(pDst->funcIds, pSrc->funcIds, pSrc->nFuncs * sizeof(func_id_t));
79,653✔
597
  } else {
598
    pDst->nFuncs = 0;
×
UNCOV
599
    pDst->funcColIds = NULL;
×
UNCOV
600
    pDst->funcIds = NULL;
×
601
  }
602

603
  return TSDB_CODE_SUCCESS;
79,653✔
604
}
605

606
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
358,969,049✔
607
  if (pSchema) {
358,969,049✔
608
    taosMemoryFreeClear(pSchema->pSchema);
358,982,516✔
609
  }
610
}
358,974,353✔
611

612
/**
613
 * @param type 0x01 free name
614
 */
615
void metaFreeRsmaParam(SRSmaParam *pParam, int8_t type) {
121,447✔
616
  if (pParam) {
121,447✔
617
    if ((type & 0x01)) {
121,447✔
618
      taosMemoryFreeClear(pParam->name);
121,447✔
619
    }
620
    taosMemoryFreeClear(pParam->funcColIds);
121,447✔
621
    taosMemoryFreeClear(pParam->funcIds);
121,447✔
622
  }
623
}
121,447✔
624

625
void metaCloneEntryFree(SMetaEntry **ppEntry) {
210,289,778✔
626
  if (ppEntry == NULL || *ppEntry == NULL) {
210,289,778✔
627
    return;
85,347✔
628
  }
629

630
  taosMemoryFreeClear((*ppEntry)->name);
210,213,504✔
631

632
  if ((*ppEntry)->type < 0) {
210,232,683✔
UNCOV
633
    taosMemoryFreeClear(*ppEntry);
×
UNCOV
634
    return;
×
635
  }
636

637
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
210,181,599✔
638
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
174,936,004✔
639
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
174,917,876✔
640
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
174,917,774✔
641
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
120,660✔
642
    }
643
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
35,276,429✔
644
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
26,159,856✔
645
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
26,161,204✔
646
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
9,118,065✔
647
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
9,118,065✔
648
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
9,118,065✔
649
  } else {
UNCOV
650
    return;
×
651
  }
652
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
210,201,163✔
653
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
210,181,971✔
654
  metaCloneColRefFree(&(*ppEntry)->colRef);
210,191,553✔
655

656
  taosMemoryFreeClear(*ppEntry);
210,179,903✔
657
  return;
210,200,491✔
658
}
659

660
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
210,176,745✔
661
  int32_t code = TSDB_CODE_SUCCESS;
210,176,745✔
662

663
  if (NULL == pEntry || NULL == ppEntry) {
210,176,745✔
UNCOV
664
    return TSDB_CODE_INVALID_PARA;
×
665
  }
666

667
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
210,217,791✔
668
  if (NULL == *ppEntry) {
210,154,176✔
UNCOV
669
    return terrno;
×
670
  }
671

672
  (*ppEntry)->version = pEntry->version;
210,166,890✔
673
  (*ppEntry)->type = pEntry->type;
210,192,511✔
674
  (*ppEntry)->uid = pEntry->uid;
210,207,355✔
675

676
  if (pEntry->type < 0) {
210,222,013✔
UNCOV
677
    return TSDB_CODE_SUCCESS;
×
678
  }
679

680
  if (pEntry->name) {
210,229,684✔
681
    (*ppEntry)->name = tstrdup(pEntry->name);
210,214,783✔
682
    if (NULL == (*ppEntry)->name) {
210,212,995✔
UNCOV
683
      code = terrno;
×
UNCOV
684
      metaCloneEntryFree(ppEntry);
×
UNCOV
685
      return code;
×
686
    }
687
  }
688

689
  if (pEntry->type == TSDB_SUPER_TABLE) {
210,203,931✔
690
    (*ppEntry)->flags = pEntry->flags;
174,908,316✔
691

692
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
174,917,651✔
693
    if (code) {
174,941,356✔
UNCOV
694
      metaCloneEntryFree(ppEntry);
×
UNCOV
695
      return code;
×
696
    }
697

698
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
174,941,356✔
699
    if (code) {
174,956,803✔
UNCOV
700
      metaCloneEntryFree(ppEntry);
×
UNCOV
701
      return code;
×
702
    }
703
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
174,956,803✔
704
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
79,653✔
705
      if (code) {
79,653✔
UNCOV
706
        metaCloneEntryFree(ppEntry);
×
UNCOV
707
        return code;
×
708
      }
709
    }
710
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
174,957,775✔
711
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
174,921,983✔
712
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
35,276,995✔
713
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
26,158,220✔
714
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
26,162,480✔
715
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
26,158,930✔
716

717
    // comment
718
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
26,161,770✔
719
    if (pEntry->ctbEntry.commentLen > 0) {
26,161,060✔
720
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
9,117✔
721
      if (NULL == (*ppEntry)->ctbEntry.comment) {
9,117✔
UNCOV
722
        code = terrno;
×
UNCOV
723
        metaCloneEntryFree(ppEntry);
×
UNCOV
724
        return code;
×
725
      }
726
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
9,117✔
727
    }
728

729
    // tags
730
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
26,162,480✔
731
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
26,154,814✔
732
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
26,129,892✔
UNCOV
733
      code = terrno;
×
UNCOV
734
      metaCloneEntryFree(ppEntry);
×
UNCOV
735
      return code;
×
736
    }
737
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
26,161,060✔
738
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
9,118,065✔
739
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
9,118,065✔
740
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
9,118,065✔
741
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
9,118,065✔
742
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
9,118,065✔
743

744
    // schema
745
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
9,118,065✔
746
    if (code) {
9,118,065✔
UNCOV
747
      metaCloneEntryFree(ppEntry);
×
UNCOV
748
      return code;
×
749
    }
750

751
    // comment
752
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
9,118,065✔
753
    if (pEntry->ntbEntry.commentLen > 0) {
9,118,065✔
754
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
13,501✔
755
      if (NULL == (*ppEntry)->ntbEntry.comment) {
13,501✔
UNCOV
756
        code = terrno;
×
UNCOV
757
        metaCloneEntryFree(ppEntry);
×
UNCOV
758
        return code;
×
759
      }
760
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
13,501✔
761
    }
762
  } else {
UNCOV
763
    return TSDB_CODE_INVALID_PARA;
×
764
  }
765

766
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
210,221,033✔
767
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,325,075✔
768
    if (code) {
1,324,242✔
UNCOV
769
      metaCloneEntryFree(ppEntry);
×
UNCOV
770
      return code;
×
771
    }
772
  } else {
773
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
208,871,885✔
774
    if (code) {
208,869,509✔
UNCOV
775
      metaCloneEntryFree(ppEntry);
×
UNCOV
776
      return code;
×
777
    }
778
  }
779
  int32_t numOfExtSchema = metaGetEntryRowSchemaNum(pEntry);
210,193,751✔
780
  if (pEntry->pExtSchemas && numOfExtSchema > 0) {
210,219,791✔
781
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(numOfExtSchema, sizeof(SExtSchema));
10,257,377✔
782
    if (!(*ppEntry)->pExtSchemas) {
10,256,987✔
UNCOV
783
      code = terrno;
×
UNCOV
784
      metaCloneEntryFree(ppEntry);
×
UNCOV
785
      return code;
×
786
    }
787
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * numOfExtSchema);
10,255,337✔
788
  }
789

790
  return code;
210,197,984✔
791
}
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