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

taosdata / TDengine / #5062

17 May 2026 01:15AM UTC coverage: 73.408%. Remained the same
#5062

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)

281738 of 383795 relevant lines covered (73.41%)

133896459.32 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,456,342,699✔
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;
184,330,594✔
26
    }
27
  }
28
  return false;
1,268,548,545✔
29
}
30

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

36
  if (pME->type == TSDB_SUPER_TABLE) {
1,883,158,679✔
37
    return &pME->stbEntry.schemaRow;
1,307,691,750✔
38
  }
39

40
  if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
575,670,333✔
41
    return &pME->ntbEntry.schemaRow;
367,214,365✔
42
  }
43

44
  return NULL;
208,453,810✔
45
}
46

47
static int32_t metaGetEntryRowSchemaNum(const SMetaEntry *pME) {
231,283,336✔
48
  const SSchemaWrapper *pSchema = metaGetEntryRowSchema(pME);
231,283,336✔
49
  return pSchema == NULL ? 0 : pSchema->nCols;
231,305,245✔
50
}
51

52
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
237,731,748✔
53
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
237,731,748✔
54
  bool                  hasTypeMods = false;
237,770,193✔
55

56
  if (pME->pExtSchemas == NULL || pSchWrapper == NULL) {
237,770,193✔
57
    return 0;
222,853,804✔
58
  }
59

60
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
14,915,353✔
61
  for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,411,050,683✔
62
    TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
63
  }
64
  return 0;
15,091,643✔
65
}
66

67
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
2,260,612✔
68
  const SColRefWrapper *pw = &pME->colRef;
2,260,612✔
69
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
4,521,915✔
70
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
4,522,606✔
71
  uTrace("encode cols:%d", pw->nCols);
2,261,994✔
72

73
  for (int32_t i = 0; i < pw->nCols; i++) {
509,947,550✔
74
    SColRef *p = &pw->pColRef[i];
507,689,011✔
75
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
1,015,378,713✔
76
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
1,015,378,022✔
77
    if (p->hasRef) {
507,689,011✔
78
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
672,790,736✔
79
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
672,790,736✔
80
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
672,790,736✔
81
    }
82
  }
83

84
  // Encode tag references
85
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nTagRefs));
4,517,769✔
86
  for (int32_t i = 0; i < pw->nTagRefs; i++) {
2,258,539✔
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,259,230✔
98
}
99

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

104
  if (pSchWrapper == NULL) {
1,364,677,681✔
105
    return 0;
×
106
  }
107

108
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,364,677,681✔
109
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,364,919,818✔
110
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
335,544,650✔
111
    if (pME->pExtSchemas == NULL) {
167,771,938✔
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,197,141,248✔
120
  }
121

122
  return 0;
1,365,010,135✔
123
}
124

125
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
49,243,927✔
126
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
49,243,927✔
127
  bool                  hasTypeMods = false;
49,269,222✔
128

129
  if (pSchWrapper == NULL) {
49,269,222✔
130
    return NULL;
×
131
  }
132

133
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
49,269,222✔
134

135
  if (hasTypeMods) {
49,227,790✔
136
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
40,874✔
137
    if (ret != NULL) {
40,874✔
138
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
40,874✔
139
    }
140
    return ret;
40,874✔
141
  }
142
  return NULL;
49,186,916✔
143
}
144

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

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

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

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

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

175
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
30,599✔
176
  int32_t    i = 0, j = 0;
30,599✔
177
  for (i = 0; i < nCols; ++i) {
231,560✔
178
    while (j < pParam->nFuncs) {
365,534✔
179
      if (pParam->funcColIds[j] == pSchema[i].colId) {
350,648✔
180
        pFuncIds[i] = pParam->funcIds[j];
163,746✔
181
        break;
163,746✔
182
      }
183
      if (pParam->funcColIds[j] > pSchema[i].colId) {
186,902✔
184
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
37,215✔
185
        break;
37,215✔
186
      }
187
      ++j;
149,687✔
188
    }
189
    if (j >= pParam->nFuncs) {
215,847✔
190
      for (; i < nCols; ++i) {
29,772✔
191
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
14,886✔
192
      }
193
      break;
14,886✔
194
    }
195
  }
196
  pFuncIds[0] = 0;  // Primary TS column has no function
30,599✔
197

198
  return 0;
30,599✔
199
}
200

201
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
45,924,520✔
202
  SColRefWrapper *pWrapper = &pME->colRef;
45,924,520✔
203
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
91,864,185✔
204
  if (pWrapper->nCols == 0) {
45,933,402✔
205
    return 0;
×
206
  }
207

208
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
91,865,061✔
209
  uDebug("decode cols:%d", pWrapper->nCols);
45,937,725✔
210
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
91,875,721✔
211
  if (pWrapper->pColRef == NULL) {
45,939,143✔
212
    return terrno;
×
213
  }
214

215
  for (int i = 0; i < pWrapper->nCols; i++) {
769,326,404✔
216
    SColRef *p = &pWrapper->pColRef[i];
723,396,435✔
217
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,446,804,463✔
218
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,446,827,128✔
219
    if (p->hasRef) {
723,419,559✔
220
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
411,518,323✔
221
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
411,506,451✔
222
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
411,518,038✔
223
    }
224
  }
225

226
  // Decode tag references (backward compatible)
227
  pWrapper->nTagRefs = 0;
45,915,406✔
228
  pWrapper->pTagRef = NULL;
45,943,289✔
229
  if (!tDecodeIsEnd(pDecoder)) {
45,943,980✔
230
    TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nTagRefs));
91,881,768✔
231
    if (pWrapper->nTagRefs > 0) {
45,937,788✔
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;
45,935,957✔
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,428,558✔
270
  if (pSrc->nCols > 0) {
1,428,558✔
271
    pDst->nCols = pSrc->nCols;
1,429,249✔
272
    pDst->version = pSrc->version;
1,429,249✔
273
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,429,249✔
274
    if (NULL == pDst->pColRef) {
1,427,176✔
275
      return terrno;
×
276
    }
277
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,427,176✔
278
  }
279
  return 0;
1,429,249✔
280
}
281

282
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
56,803,476✔
283
  int32_t code = 0;
56,803,476✔
284
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
113,612,786✔
285
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
113,731,389✔
286
  uTrace("encode cols:%d", pw->nCols);
56,922,079✔
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;
56,998,705✔
294
}
295
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
56,606,614✔
296
  const SColCmprWrapper *pw = &pME->colCmpr;
56,606,614✔
297
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
56,622,870✔
298
}
299
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,364,929,370✔
300
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,364,929,370✔
301
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
302
  if (pWrapper->nCols == 0) {
1,364,973,739✔
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,364,980,286✔
308
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
309
  if (pWrapper->pColCmpr == NULL) {
1,364,830,942✔
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,365,530,124✔
319
}
320
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
321
                                                            SSchemaWrapper *pSchema) {
322
  pCmpr->nCols = pSchema->nCols;
337,190✔
323

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

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

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

343
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
229,855,558✔
344
  if (pSrc->nCols > 0) {
229,855,558✔
345
    pDst->nCols = pSrc->nCols;
202,139,117✔
346
    pDst->version = pSrc->version;
202,175,023✔
347
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
202,170,351✔
348
    if (NULL == pDst->pColCmpr) {
202,162,602✔
349
      return terrno;
×
350
    }
351
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
202,157,060✔
352
  }
353
  return 0;
229,888,685✔
354
}
355

356
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
231,209,062✔
357
  if (pColRef) {
231,209,062✔
358
    taosMemoryFreeClear(pColRef->pColRef);
231,225,668✔
359
  }
360
}
231,246,357✔
361

362
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
231,235,353✔
363
  if (pCmpr) {
231,235,353✔
364
    taosMemoryFreeClear(pCmpr->pColCmpr);
231,247,108✔
365
  }
366
}
231,304,571✔
367

368
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
244,046,095✔
369
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
244,046,095✔
370
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
488,169,387✔
371
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
488,119,266✔
372
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
488,136,370✔
373

374
  if (pME->type > 0) {
244,079,110✔
375
    if (pME->name == NULL) {
237,723,394✔
376
      return TSDB_CODE_INVALID_PARA;
×
377
    }
378

379
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
475,497,699✔
380

381
    if (pME->type == TSDB_SUPER_TABLE) {
237,793,564✔
382
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
63,291,419✔
383
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
63,326,492✔
384
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
63,335,477✔
385
      if (TABLE_IS_ROLLUP(pME->flags)) {
31,634,534✔
386
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
126,060✔
387
      }
388
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
206,041,015✔
389
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
359,710,304✔
390
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
359,724,382✔
391
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
359,734,662✔
392
      if (pME->ctbEntry.commentLen > 0) {
179,868,786✔
393
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
33,380✔
394
      }
395
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
359,727,340✔
396
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
179,863,851✔
397
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
26,211,536✔
398
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
52,423,072✔
399
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
52,423,072✔
400
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
52,423,072✔
401
      if (pME->ntbEntry.commentLen > 0) {
26,211,536✔
402
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
47,668✔
403
      }
404
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
52,423,072✔
405
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
52,423,072✔
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) {
237,725,249✔
413
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,419,571✔
414
    } else {
415
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
235,421,693✔
416
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
31,692,727✔
417
      } else if (pME->type == TSDB_NORMAL_TABLE) {
203,767,480✔
418
        if (pME->colCmpr.nCols != 0) {
25,271,090✔
419
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,933,900✔
420
        } else {
421
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
337,190✔
422
          SColCmprWrapper colCmprs = {0};
337,190✔
423
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
337,190✔
424
          if (code != 0) {
337,190✔
425
            taosMemoryFree(colCmprs.pColCmpr);
×
426
            TAOS_CHECK_RETURN(code);
×
427
          }
428
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
337,190✔
429
          taosMemoryFree(colCmprs.pColCmpr);
337,190✔
430
          TAOS_CHECK_RETURN(code);
337,190✔
431
        }
432
      }
433
    }
434
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
237,803,870✔
435
  }
436
  if (pME->type == TSDB_SUPER_TABLE) {
244,062,288✔
437
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
63,255,677✔
438
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
63,173,971✔
439
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->stbEntry.securityLevel));
63,131,543✔
440
  } else if (pME->type == TSDB_NORMAL_TABLE) {
212,340,471✔
441
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
50,542,180✔
442
  }
443

444
  tEndEncode(pCoder);
243,901,127✔
445
  return 0;
243,927,258✔
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);
434,858✔
456
    return 0;
434,858✔
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));
2,090,798,114✔
464
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
2,091,076,581✔
465
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
2,090,966,731✔
466
      if (TABLE_IS_ROLLUP(pME->flags)) {
1,045,395,133✔
467
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
380,875✔
468
      }
469
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,290,038,033✔
470
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,925,196,871✔
471
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,925,409,738✔
472
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,925,046,910✔
473
      if (pME->ctbEntry.commentLen > 0) {
962,346,985✔
474
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
57,878✔
475
      }
476
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,925,098,617✔
477
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
962,718,106✔
478
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
327,799,918✔
479
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
655,760,903✔
480
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
655,843,197✔
481
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
655,761,111✔
482
      if (pME->ntbEntry.commentLen > 0) {
327,841,473✔
483
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
87,896✔
484
      }
485
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
655,667,241✔
486
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
655,759,254✔
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)) {
1,045,519,039✔
499
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
1,045,469,862✔
500

501
        if (pME->colCmpr.nCols == 0) {
1,045,593,270✔
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,289,926,634✔
509
      if (!tDecodeIsEnd(pCoder)) {
319,831,978✔
510
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
319,841,302✔
511
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
319,841,572✔
512
        if (pME->colCmpr.nCols == 0) {
319,890,523✔
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);
338✔
517
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
338✔
518
      }
519
      TABLE_SET_COL_COMPRESSED(pME->flags);
319,826,753✔
520
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
970,215,191✔
521
      if (!tDecodeIsEnd(pCoder)) {
45,937,737✔
522
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
45,939,854✔
523
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
45,939,854✔
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,365,338,634✔
533
    } else {
534
      pME->pExtSchemas = NULL;
970,366,349✔
535
    }
536
  }
537
  if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
538
    if (!tDecodeIsEnd(pCoder)) {
1,044,739,090✔
539
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
2,090,513,854✔
540
    }
541
    if (!tDecodeIsEnd(pCoder)) {
1,045,212,117✔
542
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
2,090,534,286✔
543
    }
544
    if (!tDecodeIsEnd(pCoder)) {
1,045,039,252✔
545
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->stbEntry.securityLevel));
2,090,405,024✔
546
    }
547
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,289,861,177✔
548
    if (!tDecodeIsEnd(pCoder)) {
319,756,065✔
549
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
639,610,604✔
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) {
395,227,416✔
561
  if (pSrc == NULL || pDst == NULL) {
395,227,416✔
562
    return TSDB_CODE_INVALID_PARA;
×
563
  }
564

565
  pDst->nCols = pSrc->nCols;
395,272,124✔
566
  pDst->version = pSrc->version;
395,245,160✔
567
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
395,281,604✔
568
  if (pDst->pSchema == NULL) {
395,153,367✔
569
    return terrno;
×
570
  }
571
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
395,171,352✔
572
  return TSDB_CODE_SUCCESS;
395,322,346✔
573
}
574

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

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

603
  return TSDB_CODE_SUCCESS;
84,057✔
604
}
605

606
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
395,206,073✔
607
  if (pSchema) {
395,206,073✔
608
    taosMemoryFreeClear(pSchema->pSchema);
395,224,693✔
609
  }
610
}
395,218,245✔
611

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

625
void metaCloneEntryFree(SMetaEntry **ppEntry) {
231,355,332✔
626
  if (ppEntry == NULL || *ppEntry == NULL) {
231,355,332✔
627
    return;
91,936✔
628
  }
629

630
  taosMemoryFreeClear((*ppEntry)->name);
231,278,394✔
631

632
  if ((*ppEntry)->type < 0) {
231,295,125✔
633
    taosMemoryFreeClear(*ppEntry);
×
634
    return;
×
635
  }
636

637
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
231,224,488✔
638
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
192,541,934✔
639
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
192,529,308✔
640
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
192,537,815✔
641
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
128,529✔
642
    }
643
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
38,738,756✔
644
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
28,578,274✔
645
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
28,575,386✔
646
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
10,164,390✔
647
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
10,164,390✔
648
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
10,164,390✔
649
  } else {
650
    return;
×
651
  }
652
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
231,274,906✔
653
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
231,259,481✔
654
  metaCloneColRefFree(&(*ppEntry)->colRef);
231,285,460✔
655

656
  taosMemoryFreeClear(*ppEntry);
231,238,571✔
657
  return;
231,244,750✔
658
}
659

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

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

667
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
231,320,744✔
668
  if (NULL == *ppEntry) {
231,225,182✔
669
    return terrno;
×
670
  }
671

672
  (*ppEntry)->version = pEntry->version;
231,242,388✔
673
  (*ppEntry)->type = pEntry->type;
231,240,695✔
674
  (*ppEntry)->uid = pEntry->uid;
231,282,876✔
675

676
  if (pEntry->type < 0) {
231,285,223✔
677
    return TSDB_CODE_SUCCESS;
×
678
  }
679

680
  if (pEntry->name) {
231,279,772✔
681
    (*ppEntry)->name = tstrdup(pEntry->name);
231,293,912✔
682
    if (NULL == (*ppEntry)->name) {
231,297,154✔
683
      code = terrno;
×
684
      metaCloneEntryFree(ppEntry);
×
685
      return code;
×
686
    }
687
  }
688

689
  if (pEntry->type == TSDB_SUPER_TABLE) {
231,226,827✔
690
    (*ppEntry)->flags = pEntry->flags;
192,526,920✔
691

692
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
192,530,950✔
693
    if (code) {
192,571,502✔
694
      metaCloneEntryFree(ppEntry);
×
695
      return code;
×
696
    }
697

698
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
192,571,502✔
699
    if (code) {
192,601,505✔
700
      metaCloneEntryFree(ppEntry);
×
701
      return code;
×
702
    }
703
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
192,601,505✔
704
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
84,057✔
705
      if (code) {
83,230✔
706
        metaCloneEntryFree(ppEntry);
×
707
        return code;
×
708
      }
709
    }
710
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
192,600,968✔
711
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
192,581,427✔
712
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
38,741,182✔
713
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
28,575,276✔
714
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
28,579,027✔
715
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
28,581,181✔
716

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

729
    // tags
730
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
28,580,809✔
731
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
28,572,560✔
732
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
28,578,364✔
733
      code = terrno;
×
734
      metaCloneEntryFree(ppEntry);
×
735
      return code;
×
736
    }
737
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
28,578,893✔
738
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
10,164,390✔
739
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
10,164,390✔
740
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
10,164,390✔
741
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
10,164,390✔
742
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
10,164,390✔
743

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

751
    // comment
752
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
10,164,390✔
753
    if (pEntry->ntbEntry.commentLen > 0) {
10,164,390✔
754
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
14,756✔
755
      if (NULL == (*ppEntry)->ntbEntry.comment) {
14,756✔
756
        code = terrno;
×
757
        metaCloneEntryFree(ppEntry);
×
758
        return code;
×
759
      }
760
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
14,756✔
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) {
231,295,395✔
767
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,423,502✔
768
    if (code) {
1,429,249✔
769
      metaCloneEntryFree(ppEntry);
×
770
      return code;
×
771
    }
772
  } else {
773
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
229,846,221✔
774
    if (code) {
229,875,891✔
775
      metaCloneEntryFree(ppEntry);
×
776
      return code;
×
777
    }
778
  }
779
  int32_t numOfExtSchema = metaGetEntryRowSchemaNum(pEntry);
231,305,140✔
780
  if (pEntry->pExtSchemas && numOfExtSchema > 0) {
231,303,849✔
781
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(numOfExtSchema, sizeof(SExtSchema));
11,960,556✔
782
    if (!(*ppEntry)->pExtSchemas) {
11,950,261✔
783
      code = terrno;
×
784
      metaCloneEntryFree(ppEntry);
×
785
      return code;
×
786
    }
787
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * numOfExtSchema);
11,947,861✔
788
  }
789

790
  return code;
231,278,677✔
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