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

taosdata / TDengine / #5071

17 May 2026 01:15AM UTC coverage: 63.054% (-10.3%) from 73.326%
#5071

push

travis-ci

web-flow
feat (TDgpt): Dynamic Model Synchronization Enhancements (#35344)

* refactor: do some internal refactor.

* fix: fix multiprocess sync issue.

* feat: add dynamic anomaly detection and forecasting services

* fix: log error message for undeploying model in exception handling

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: handle undeploy when model exists only on disk

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/286aafa0-c3ce-4c27-b803-2707571e9dc1

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: guard dynamic registry concurrent access

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: tighten service list locking scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: restore prophet support and update tests per review feedback

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: improve test name and move copy inside lock scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* Potential fix for pull request finding

Co-au... (continued)

238317 of 377957 relevant lines covered (63.05%)

130539817.12 hits per line

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

78.92
/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,377,039,321✔
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;
180,484,899✔
26
    }
27
  }
28
  return false;
1,191,769,835✔
29
}
30

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

36
  if (pME->type == TSDB_SUPER_TABLE) {
1,734,997,583✔
37
    return &pME->stbEntry.schemaRow;
1,149,519,996✔
38
  }
39

40
  if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
586,228,661✔
41
    return &pME->ntbEntry.schemaRow;
407,566,353✔
42
  }
43

44
  return NULL;
178,633,792✔
45
}
46

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

52
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
193,775,330✔
53
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
193,775,330✔
54
  bool                  hasTypeMods = false;
193,864,361✔
55

56
  if (pME->pExtSchemas == NULL || pSchWrapper == NULL) {
193,864,361✔
57
    return 0;
181,519,910✔
58
  }
59

60
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
12,379,436✔
61
  for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
720,664,470✔
62
    TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
1,416,283,663✔
63
  }
64
  return 0;
12,638,262✔
65
}
66

67
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
2,110,816✔
68
  const SColRefWrapper *pw = &pME->colRef;
2,110,816✔
69
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
4,221,632✔
70
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
4,221,632✔
71
  uTrace("encode cols:%d", pw->nCols);
2,110,816✔
72

73
  for (int32_t i = 0; i < pw->nCols; i++) {
540,467,736✔
74
    SColRef *p = &pw->pColRef[i];
538,356,920✔
75
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
1,076,713,840✔
76
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
1,076,713,840✔
77
    if (p->hasRef) {
538,356,920✔
78
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
713,244,644✔
79
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
713,244,644✔
80
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
713,244,644✔
81
    }
82
  }
83

84
  // Encode tag references
85
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nTagRefs));
4,221,632✔
86
  for (int32_t i = 0; i < pw->nTagRefs; i++) {
2,110,816✔
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,110,816✔
98
}
99

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

104
  if (pSchWrapper == NULL) {
1,310,435,174✔
105
    return 0;
×
106
  }
107

108
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,310,435,174✔
109
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,311,171,239✔
110
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
334,438,893✔
111
    if (pME->pExtSchemas == NULL) {
167,211,937✔
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,143,929,458✔
120
  }
121

122
  return 0;
1,311,305,723✔
123
}
124

125
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
32,457,294✔
126
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
32,457,294✔
127
  bool                  hasTypeMods = false;
32,460,980✔
128

129
  if (pSchWrapper == NULL) {
32,460,980✔
130
    return NULL;
×
131
  }
132

133
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
32,460,980✔
134

135
  if (hasTypeMods) {
32,448,587✔
136
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
11,816✔
137
    if (ret != NULL) {
11,816✔
138
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
11,816✔
139
    }
140
    return ret;
11,816✔
141
  }
142
  return NULL;
32,436,771✔
143
}
144

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

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

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

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

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

175
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
31,228✔
176
  int32_t    i = 0, j = 0;
31,228✔
177
  for (i = 0; i < nCols; ++i) {
236,320✔
178
    while (j < pParam->nFuncs) {
373,048✔
179
      if (pParam->funcColIds[j] == pSchema[i].colId) {
357,856✔
180
        pFuncIds[i] = pParam->funcIds[j];
167,112✔
181
        break;
167,112✔
182
      }
183
      if (pParam->funcColIds[j] > pSchema[i].colId) {
190,744✔
184
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
37,980✔
185
        break;
37,980✔
186
      }
187
      ++j;
152,764✔
188
    }
189
    if (j >= pParam->nFuncs) {
220,284✔
190
      for (; i < nCols; ++i) {
30,384✔
191
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
15,192✔
192
      }
193
      break;
15,192✔
194
    }
195
  }
196
  pFuncIds[0] = 0;  // Primary TS column has no function
31,228✔
197

198
  return 0;
31,228✔
199
}
200

201
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
72,281,828✔
202
  SColRefWrapper *pWrapper = &pME->colRef;
72,281,828✔
203
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
144,607,935✔
204
  if (pWrapper->nCols == 0) {
72,299,713✔
205
    return 0;
×
206
  }
207

208
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
144,597,424✔
209
  uDebug("decode cols:%d", pWrapper->nCols);
72,307,017✔
210
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
144,588,569✔
211
  if (pWrapper->pColRef == NULL) {
72,283,432✔
212
    return terrno;
×
213
  }
214

215
  for (int i = 0; i < pWrapper->nCols; i++) {
1,255,584,820✔
216
    SColRef *p = &pWrapper->pColRef[i];
1,183,298,298✔
217
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
2,147,483,647✔
218
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
2,147,483,647✔
219
    if (p->hasRef) {
1,183,491,357✔
220
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
643,514,092✔
221
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
643,448,365✔
222
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
643,476,823✔
223
    }
224
  }
225

226
  // Decode tag references (backward compatible)
227
  pWrapper->nTagRefs = 0;
72,141,637✔
228
  pWrapper->pTagRef = NULL;
72,331,874✔
229
  if (!tDecodeIsEnd(pDecoder)) {
72,329,420✔
230
    TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nTagRefs));
144,650,607✔
231
    if (pWrapper->nTagRefs > 0) {
72,319,921✔
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;
72,292,747✔
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,373,010✔
270
  if (pSrc->nCols > 0) {
1,373,010✔
271
    pDst->nCols = pSrc->nCols;
1,373,010✔
272
    pDst->version = pSrc->version;
1,373,010✔
273
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,373,679✔
274
    if (NULL == pDst->pColRef) {
1,373,679✔
275
      return terrno;
×
276
    }
277
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,373,679✔
278
  }
279
  return 0;
1,373,679✔
280
}
281

282
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
44,980,286✔
283
  int32_t code = 0;
44,980,286✔
284
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
90,042,369✔
285
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
90,241,343✔
286
  uTrace("encode cols:%d", pw->nCols);
45,179,260✔
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;
45,210,726✔
294
}
295
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
45,008,394✔
296
  const SColCmprWrapper *pw = &pME->colCmpr;
45,008,394✔
297
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
45,036,313✔
298
}
299
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,311,271,490✔
300
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,311,271,490✔
301
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
302
  if (pWrapper->nCols == 0) {
1,311,628,684✔
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,311,707,868✔
308
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
309
  if (pWrapper->pColCmpr == NULL) {
1,310,749,370✔
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,313,227,090✔
319
}
320
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
321
                                                            SSchemaWrapper *pSchema) {
322
  pCmpr->nCols = pSchema->nCols;
172,372✔
323

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

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

334
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
966,310✔
335
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
793,938✔
336
    SSchema  *pColSchema = &pSchema->pSchema[i];
793,938✔
337
    pColCmpr->id = pColSchema->colId;
793,938✔
338
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
793,938✔
339
  }
340
  return 0;
172,372✔
341
}
342

343
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
196,448,747✔
344
  if (pSrc->nCols > 0) {
196,448,747✔
345
    pDst->nCols = pSrc->nCols;
166,462,544✔
346
    pDst->version = pSrc->version;
166,459,908✔
347
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
166,442,830✔
348
    if (NULL == pDst->pColCmpr) {
166,419,646✔
349
      return terrno;
×
350
    }
351
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
166,435,996✔
352
  }
353
  return 0;
196,465,165✔
354
}
355

356
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
197,765,547✔
357
  if (pColRef) {
197,765,547✔
358
    taosMemoryFreeClear(pColRef->pColRef);
197,789,300✔
359
  }
360
}
197,791,645✔
361

362
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
197,772,293✔
363
  if (pCmpr) {
197,772,293✔
364
    taosMemoryFreeClear(pCmpr->pColCmpr);
197,787,545✔
365
  }
366
}
197,850,351✔
367

368
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
198,097,934✔
369
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
198,097,934✔
370
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
396,383,186✔
371
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
396,385,651✔
372
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
396,365,294✔
373

374
  if (pME->type > 0) {
198,166,172✔
375
    if (pME->name == NULL) {
193,861,518✔
376
      return TSDB_CODE_INVALID_PARA;
×
377
    }
378

379
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
387,778,486✔
380

381
    if (pME->type == TSDB_SUPER_TABLE) {
193,933,203✔
382
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
49,454,152✔
383
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
49,504,831✔
384
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
49,473,512✔
385
      if (TABLE_IS_ROLLUP(pME->flags)) {
24,683,908✔
386
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
124,912✔
387
      }
388
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
169,128,528✔
389
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
295,576,412✔
390
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
295,571,371✔
391
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
295,566,067✔
392
      if (pME->ctbEntry.commentLen > 0) {
147,785,215✔
393
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
32,672✔
394
      }
395
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
295,567,712✔
396
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
147,784,882✔
397
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
21,346,956✔
398
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
42,693,912✔
399
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
42,693,912✔
400
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
42,693,912✔
401
      if (pME->ntbEntry.commentLen > 0) {
21,346,956✔
402
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
20,704✔
403
      }
404
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
42,693,912✔
405
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
42,693,912✔
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) {
193,826,569✔
413
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,273,708✔
414
    } else {
415
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
191,702,751✔
416
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,756,712✔
417
      } else if (pME->type == TSDB_NORMAL_TABLE) {
166,999,187✔
418
        if (pME->colCmpr.nCols != 0) {
20,446,544✔
419
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
20,274,172✔
420
        } else {
421
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
172,372✔
422
          SColCmprWrapper colCmprs = {0};
172,372✔
423
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
172,372✔
424
          if (code != 0) {
172,372✔
425
            taosMemoryFree(colCmprs.pColCmpr);
×
426
            TAOS_CHECK_RETURN(code);
×
427
          }
428
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
172,372✔
429
          taosMemoryFree(colCmprs.pColCmpr);
172,372✔
430
          TAOS_CHECK_RETURN(code);
172,372✔
431
        }
432
      }
433
    }
434
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
193,890,583✔
435
  }
436
  if (pME->type == TSDB_SUPER_TABLE) {
198,119,466✔
437
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
49,352,561✔
438
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
49,300,841✔
439
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->stbEntry.securityLevel));
49,230,567✔
440
  } else if (pME->type == TSDB_NORMAL_TABLE) {
173,379,059✔
441
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
40,893,088✔
442
  }
443

444
  tEndEncode(pCoder);
197,959,322✔
445
  return 0;
198,011,592✔
446
}
447

448
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
2,147,483,647✔
449
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
2,147,483,647✔
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,147,483,647✔
455
    tEndDecode(pCoder);
75,894✔
456
    return 0;
75,894✔
457
  }
458

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

462
    if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
463
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,870,653,336✔
464
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,871,800,510✔
465
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,871,783,446✔
466
      if (TABLE_IS_ROLLUP(pME->flags)) {
935,741,826✔
467
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
384,864✔
468
      }
469
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,325,093,383✔
470
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,874,675,901✔
471
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,875,545,415✔
472
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,874,581,843✔
473
      if (pME->ctbEntry.commentLen > 0) {
936,827,303✔
474
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
56,578✔
475
      }
476
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,874,670,147✔
477
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
937,826,632✔
478
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
388,704,131✔
479
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
777,923,439✔
480
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
778,100,143✔
481
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
777,902,695✔
482
      if (pME->ntbEntry.commentLen > 0) {
388,859,356✔
483
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
43,114✔
484
      }
485
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
777,684,618✔
486
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
778,016,482✔
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
      }
492
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
493
    } else {
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,147,483,647✔
498
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
935,831,088✔
499
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
935,760,038✔
500

501
        if (pME->colCmpr.nCols == 0) {
936,075,683✔
502
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
503
        }
504
      } else {
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,324,943,800✔
509
      if (!tDecodeIsEnd(pCoder)) {
376,914,197✔
510
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
376,909,744✔
511
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
376,909,744✔
512
        if (pME->colCmpr.nCols == 0) {
377,033,597✔
513
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
514
        }
515
      } else {
516
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
4,565✔
517
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
4,565✔
518
      }
519
      TABLE_SET_COL_COMPRESSED(pME->flags);
376,903,612✔
520
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
948,084,768✔
521
      if (!tDecodeIsEnd(pCoder)) {
72,305,673✔
522
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
72,311,679✔
523
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
72,311,679✔
524
      } else {
525
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
526
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
527
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
528
        }
529
      }
530
    }
531
    if (!tDecodeIsEnd(pCoder)) {
2,147,483,647✔
532
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
1,312,435,769✔
533
    } else {
534
      pME->pExtSchemas = NULL;
948,772,972✔
535
    }
536
  }
537
  if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
538
    if (!tDecodeIsEnd(pCoder)) {
932,774,915✔
539
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,869,430,835✔
540
    }
541
    if (!tDecodeIsEnd(pCoder)) {
934,971,969✔
542
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,870,155,870✔
543
    }
544
    if (!tDecodeIsEnd(pCoder)) {
934,466,402✔
545
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->stbEntry.securityLevel));
1,870,070,319✔
546
    }
547
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,324,718,739✔
548
    if (!tDecodeIsEnd(pCoder)) {
376,588,399✔
549
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
753,479,258✔
550
    }
551
  }
552

553

554
  tEndDecode(pCoder);
2,147,483,647✔
555
  return 0;
2,147,483,647✔
556
}
557

558
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
2,147,483,647✔
559

560
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
324,423,993✔
561
  if (pSrc == NULL || pDst == NULL) {
324,423,993✔
562
    return TSDB_CODE_INVALID_PARA;
×
563
  }
564

565
  pDst->nCols = pSrc->nCols;
324,465,612✔
566
  pDst->version = pSrc->version;
324,467,591✔
567
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
324,476,050✔
568
  if (pDst->pSchema == NULL) {
324,374,598✔
569
    return terrno;
×
570
  }
571
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
324,384,033✔
572
  return TSDB_CODE_SUCCESS;
324,499,819✔
573
}
574

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

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

603
  return TSDB_CODE_SUCCESS;
82,712✔
604
}
605

606
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
324,457,212✔
607
  if (pSchema) {
324,457,212✔
608
    taosMemoryFreeClear(pSchema->pSchema);
324,481,944✔
609
  }
610
}
324,480,513✔
611

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

625
void metaCloneEntryFree(SMetaEntry **ppEntry) {
197,879,159✔
626
  if (ppEntry == NULL || *ppEntry == NULL) {
197,879,159✔
627
    return;
86,018✔
628
  }
629

630
  taosMemoryFreeClear((*ppEntry)->name);
197,802,934✔
631

632
  if ((*ppEntry)->type < 0) {
197,828,293✔
633
    taosMemoryFreeClear(*ppEntry);
×
634
    return;
×
635
  }
636

637
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
197,791,452✔
638
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
157,506,516✔
639
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
157,491,693✔
640
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
157,498,875✔
641
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
127,444✔
642
    }
643
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
40,322,391✔
644
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
30,847,044✔
645
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
30,842,578✔
646
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
9,481,313✔
647
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
9,481,313✔
648
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
9,481,313✔
649
  } else {
650
    return;
×
651
  }
652
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
197,824,728✔
653
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
197,819,206✔
654
  metaCloneColRefFree(&(*ppEntry)->colRef);
197,841,821✔
655

656
  taosMemoryFreeClear(*ppEntry);
197,782,682✔
657
  return;
197,806,175✔
658
}
659

660
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
197,787,363✔
661
  int32_t code = TSDB_CODE_SUCCESS;
197,787,363✔
662

663
  if (NULL == pEntry || NULL == ppEntry) {
197,787,363✔
664
    return TSDB_CODE_INVALID_PARA;
×
665
  }
666

667
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
197,850,082✔
668
  if (NULL == *ppEntry) {
197,759,360✔
669
    return terrno;
×
670
  }
671

672
  (*ppEntry)->version = pEntry->version;
197,781,389✔
673
  (*ppEntry)->type = pEntry->type;
197,794,413✔
674
  (*ppEntry)->uid = pEntry->uid;
197,824,841✔
675

676
  if (pEntry->type < 0) {
197,798,898✔
677
    return TSDB_CODE_SUCCESS;
×
678
  }
679

680
  if (pEntry->name) {
197,806,666✔
681
    (*ppEntry)->name = tstrdup(pEntry->name);
197,807,829✔
682
    if (NULL == (*ppEntry)->name) {
197,836,309✔
683
      code = terrno;
×
684
      metaCloneEntryFree(ppEntry);
×
685
      return code;
×
686
    }
687
  }
688

689
  if (pEntry->type == TSDB_SUPER_TABLE) {
197,784,719✔
690
    (*ppEntry)->flags = pEntry->flags;
157,467,567✔
691

692
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
157,480,318✔
693
    if (code) {
157,516,818✔
694
      metaCloneEntryFree(ppEntry);
×
695
      return code;
×
696
    }
697

698
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
157,516,818✔
699
    if (code) {
157,526,208✔
700
      metaCloneEntryFree(ppEntry);
×
701
      return code;
×
702
    }
703
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
157,526,208✔
704
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
83,556✔
705
      if (code) {
82,712✔
706
        metaCloneEntryFree(ppEntry);
×
707
        return code;
×
708
      }
709
    }
710
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
157,528,327✔
711
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
157,512,907✔
712
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
40,328,913✔
713
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
30,846,850✔
714
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
30,849,850✔
715
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
30,850,600✔
716

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

729
    // tags
730
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
30,852,100✔
731
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
30,849,100✔
732
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
30,850,681✔
733
      code = terrno;
×
734
      metaCloneEntryFree(ppEntry);
×
735
      return code;
×
736
    }
737
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
30,850,681✔
738
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
9,481,313✔
739
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
9,481,313✔
740
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
9,481,313✔
741
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
9,481,313✔
742
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
9,481,313✔
743

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

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

766
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
197,820,100✔
767
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,373,291✔
768
    if (code) {
1,373,679✔
769
      metaCloneEntryFree(ppEntry);
×
770
      return code;
×
771
    }
772
  } else {
773
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
196,431,443✔
774
    if (code) {
196,449,274✔
775
      metaCloneEntryFree(ppEntry);
×
776
      return code;
×
777
    }
778
  }
779
  int32_t numOfExtSchema = metaGetEntryRowSchemaNum(pEntry);
197,822,953✔
780
  if (pEntry->pExtSchemas && numOfExtSchema > 0) {
197,829,291✔
781
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(numOfExtSchema, sizeof(SExtSchema));
8,840,286✔
782
    if (!(*ppEntry)->pExtSchemas) {
8,830,575✔
783
      code = terrno;
×
784
      metaCloneEntryFree(ppEntry);
×
785
      return code;
×
786
    }
787
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * numOfExtSchema);
8,821,879✔
788
  }
789

790
  return code;
197,828,692✔
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