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

taosdata / TDengine / #5078

17 May 2026 01:15AM UTC coverage: 73.443% (+0.04%) from 73.407%
#5078

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)

281871 of 383795 relevant lines covered (73.44%)

135968015.44 hits per line

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

78.53
/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,475,081,745✔
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;
182,293,761✔
26
    }
27
  }
28
  return false;
1,287,596,240✔
29
}
30

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

36
  if (pME->type == TSDB_SUPER_TABLE) {
1,891,065,055✔
37
    return &pME->stbEntry.schemaRow;
1,305,670,810✔
38
  }
39

40
  if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
585,638,082✔
41
    return &pME->ntbEntry.schemaRow;
381,598,215✔
42
  }
43

44
  return NULL;
203,943,860✔
45
}
46

47
static int32_t metaGetEntryRowSchemaNum(const SMetaEntry *pME) {
226,237,345✔
48
  const SSchemaWrapper *pSchema = metaGetEntryRowSchema(pME);
226,237,345✔
49
  return pSchema == NULL ? 0 : pSchema->nCols;
226,251,386✔
50
}
51

52
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
231,190,130✔
53
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
231,190,130✔
54
  bool                  hasTypeMods = false;
231,224,886✔
55

56
  if (pME->pExtSchemas == NULL || pSchWrapper == NULL) {
231,224,886✔
57
    return 0;
216,577,982✔
58
  }
59

60
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
14,664,776✔
61
  for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,208,126,841✔
62
    TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
63
  }
64
  return 0;
14,722,894✔
65
}
66

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

73
  for (int32_t i = 0; i < pw->nCols; i++) {
505,031,868✔
74
    SColRef *p = &pw->pColRef[i];
502,803,152✔
75
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
1,005,606,304✔
76
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
1,005,606,304✔
77
    if (p->hasRef) {
502,803,152✔
78
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
666,306,076✔
79
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
666,306,076✔
80
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
666,305,398✔
81
    }
82
  }
83

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

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

104
  if (pSchWrapper == NULL) {
1,382,732,409✔
105
    return 0;
×
106
  }
107

108
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,382,732,409✔
109
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,383,086,264✔
110
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
332,074,255✔
111
    if (pME->pExtSchemas == NULL) {
166,038,026✔
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,217,042,248✔
120
  }
121

122
  return 0;
1,383,083,798✔
123
}
124

125
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
50,790,402✔
126
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
50,790,402✔
127
  bool                  hasTypeMods = false;
50,829,492✔
128

129
  if (pSchWrapper == NULL) {
50,829,492✔
130
    return NULL;
×
131
  }
132

133
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
50,829,492✔
134

135
  if (hasTypeMods) {
50,769,849✔
136
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
39,843✔
137
    if (ret != NULL) {
39,843✔
138
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
39,843✔
139
    }
140
    return ret;
39,843✔
141
  }
142
  return NULL;
50,730,006✔
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) {
46,711,430✔
202
  SColRefWrapper *pWrapper = &pME->colRef;
46,711,430✔
203
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
93,433,678✔
204
  if (pWrapper->nCols == 0) {
46,714,821✔
205
    return 0;
×
206
  }
207

208
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
93,413,968✔
209
  uDebug("decode cols:%d", pWrapper->nCols);
46,720,166✔
210
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
93,430,457✔
211
  if (pWrapper->pColRef == NULL) {
46,708,035✔
212
    return terrno;
×
213
  }
214

215
  for (int i = 0; i < pWrapper->nCols; i++) {
776,524,092✔
216
    SColRef *p = &pWrapper->pColRef[i];
729,808,859✔
217
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,459,639,114✔
218
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,459,662,342✔
219
    if (p->hasRef) {
729,839,371✔
220
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
416,165,561✔
221
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
416,154,870✔
222
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
416,143,233✔
223
    }
224
  }
225

226
  // Decode tag references (backward compatible)
227
  pWrapper->nTagRefs = 0;
46,689,470✔
228
  pWrapper->pTagRef = NULL;
46,722,871✔
229
  if (!tDecodeIsEnd(pDecoder)) {
46,720,837✔
230
    TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nTagRefs));
93,442,352✔
231
    if (pWrapper->nTagRefs > 0) {
46,720,159✔
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;
46,713,379✔
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,405,451✔
270
  if (pSrc->nCols > 0) {
1,405,451✔
271
    pDst->nCols = pSrc->nCols;
1,405,451✔
272
    pDst->version = pSrc->version;
1,405,451✔
273
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,405,451✔
274
    if (NULL == pDst->pColRef) {
1,404,773✔
275
      return terrno;
×
276
    }
277
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,404,773✔
278
  }
279
  return 0;
1,405,451✔
280
}
281

282
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
55,328,951✔
283
  int32_t code = 0;
55,328,951✔
284
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
110,617,364✔
285
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
110,634,945✔
286
  uTrace("encode cols:%d", pw->nCols);
55,346,532✔
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;
55,413,114✔
294
}
295
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
55,077,309✔
296
  const SColCmprWrapper *pw = &pME->colCmpr;
55,077,309✔
297
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
55,100,356✔
298
}
299
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,382,987,294✔
300
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,382,987,294✔
301
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
302
  if (pWrapper->nCols == 0) {
1,383,105,692✔
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,383,229,344✔
308
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
309
  if (pWrapper->pColCmpr == NULL) {
1,383,036,020✔
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,383,801,003✔
319
}
320
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
321
                                                            SSchemaWrapper *pSchema) {
322
  pCmpr->nCols = pSchema->nCols;
325,014✔
323

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

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

334
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,624,522✔
335
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,299,508✔
336
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,299,954✔
337
    pColCmpr->id = pColSchema->colId;
1,299,954✔
338
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,299,954✔
339
  }
340
  return 0;
325,014✔
341
}
342

343
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
224,822,958✔
344
  if (pSrc->nCols > 0) {
224,822,958✔
345
    pDst->nCols = pSrc->nCols;
196,702,728✔
346
    pDst->version = pSrc->version;
196,703,797✔
347
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
196,691,311✔
348
    if (NULL == pDst->pColCmpr) {
196,675,857✔
349
      return terrno;
×
350
    }
351
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
196,671,223✔
352
  }
353
  return 0;
224,848,641✔
354
}
355

356
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
226,231,793✔
357
  if (pColRef) {
226,231,793✔
358
    taosMemoryFreeClear(pColRef->pColRef);
226,237,505✔
359
  }
360
}
226,251,682✔
361

362
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
226,241,459✔
363
  if (pCmpr) {
226,241,459✔
364
    taosMemoryFreeClear(pCmpr->pColCmpr);
226,251,260✔
365
  }
366
}
226,266,620✔
367

368
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
237,164,368✔
369
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
237,164,368✔
370
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
474,376,427✔
371
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
474,358,097✔
372
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
474,368,454✔
373

374
  if (pME->type > 0) {
237,173,251✔
375
    if (pME->name == NULL) {
231,208,017✔
376
      return TSDB_CODE_INVALID_PARA;
×
377
    }
378

379
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
462,421,469✔
380

381
    if (pME->type == TSDB_SUPER_TABLE) {
231,245,820✔
382
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
60,692,091✔
383
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
60,722,021✔
384
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
60,756,749✔
385
      if (TABLE_IS_ROLLUP(pME->flags)) {
30,354,374✔
386
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
124,821✔
387
      }
388
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
200,820,862✔
389
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
349,809,770✔
390
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
349,821,983✔
391
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
349,826,490✔
392
      if (pME->ctbEntry.commentLen > 0) {
174,915,728✔
393
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
32,612✔
394
      }
395
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
349,826,969✔
396
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
174,909,495✔
397
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
25,951,486✔
398
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
51,902,972✔
399
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
51,902,972✔
400
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
51,902,972✔
401
      if (pME->ntbEntry.commentLen > 0) {
25,951,486✔
402
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
46,564✔
403
      }
404
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
51,902,972✔
405
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
51,902,972✔
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) {
231,226,123✔
413
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,357,769✔
414
    } else {
415
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
228,919,227✔
416
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
30,383,329✔
417
      } else if (pME->type == TSDB_NORMAL_TABLE) {
198,645,367✔
418
        if (pME->colCmpr.nCols != 0) {
25,023,210✔
419
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,698,196✔
420
        } else {
421
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
325,014✔
422
          SColCmprWrapper colCmprs = {0};
325,014✔
423
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
325,014✔
424
          if (code != 0) {
325,014✔
425
            taosMemoryFree(colCmprs.pColCmpr);
×
426
            TAOS_CHECK_RETURN(code);
×
427
          }
428
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
325,014✔
429
          taosMemoryFree(colCmprs.pColCmpr);
325,014✔
430
          TAOS_CHECK_RETURN(code);
325,014✔
431
        }
432
      }
433
    }
434
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
231,255,480✔
435
  }
436
  if (pME->type == TSDB_SUPER_TABLE) {
237,194,437✔
437
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
60,619,013✔
438
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
60,607,637✔
439
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->stbEntry.securityLevel));
60,636,563✔
440
  } else if (pME->type == TSDB_NORMAL_TABLE) {
206,778,613✔
441
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
50,046,420✔
442
  }
443

444
  tEndEncode(pCoder);
237,105,157✔
445
  return 0;
237,145,114✔
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);
407,958✔
456
    return 0;
407,958✔
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,103,901,584✔
464
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
2,104,031,148✔
465
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
2,103,894,910✔
466
      if (TABLE_IS_ROLLUP(pME->flags)) {
1,051,864,438✔
467
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
376,412✔
468
      }
469
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,323,608,431✔
470
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,968,863,532✔
471
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,969,230,133✔
472
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,968,850,341✔
473
      if (pME->ctbEntry.commentLen > 0) {
984,232,195✔
474
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
56,378✔
475
      }
476
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,968,836,976✔
477
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
984,603,913✔
478
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
339,658,101✔
479
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
679,507,191✔
480
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
679,636,528✔
481
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
679,515,511✔
482
      if (pME->ntbEntry.commentLen > 0) {
339,697,957✔
483
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
85,640✔
484
      }
485
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
679,349,435✔
486
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
679,447,862✔
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,051,923,303✔
499
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
1,051,960,721✔
500

501
        if (pME->colCmpr.nCols == 0) {
1,052,062,229✔
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,323,486,102✔
509
      if (!tDecodeIsEnd(pCoder)) {
331,649,033✔
510
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
331,668,342✔
511
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
331,668,342✔
512
        if (pME->colCmpr.nCols == 0) {
331,523,850✔
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);
×
517
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
518
      }
519
      TABLE_SET_COL_COMPRESSED(pME->flags);
331,544,225✔
520
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
992,001,268✔
521
      if (!tDecodeIsEnd(pCoder)) {
46,722,193✔
522
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
46,722,247✔
523
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
46,722,247✔
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,383,637,170✔
533
    } else {
534
      pME->pExtSchemas = NULL;
992,411,041✔
535
    }
536
  }
537
  if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
538
    if (!tDecodeIsEnd(pCoder)) {
1,051,343,790✔
539
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
2,103,432,278✔
540
    }
541
    if (!tDecodeIsEnd(pCoder)) {
1,051,654,194✔
542
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
2,103,453,816✔
543
    }
544
    if (!tDecodeIsEnd(pCoder)) {
1,051,655,227✔
545
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->stbEntry.securityLevel));
2,103,457,836✔
546
    }
547
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,323,445,866✔
548
    if (!tDecodeIsEnd(pCoder)) {
331,555,541✔
549
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
663,215,677✔
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) {
384,378,749✔
561
  if (pSrc == NULL || pDst == NULL) {
384,378,749✔
562
    return TSDB_CODE_INVALID_PARA;
×
563
  }
564

565
  pDst->nCols = pSrc->nCols;
384,404,493✔
566
  pDst->version = pSrc->version;
384,387,299✔
567
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
384,413,158✔
568
  if (pDst->pSchema == NULL) {
384,271,725✔
569
    return terrno;
×
570
  }
571
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
384,322,404✔
572
  return TSDB_CODE_SUCCESS;
384,422,438✔
573
}
574

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

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

603
  return TSDB_CODE_SUCCESS;
82,978✔
604
}
605

606
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
384,378,423✔
607
  if (pSchema) {
384,378,423✔
608
    taosMemoryFreeClear(pSchema->pSchema);
384,389,656✔
609
  }
610
}
384,366,253✔
611

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

625
void metaCloneEntryFree(SMetaEntry **ppEntry) {
226,334,735✔
626
  if (ppEntry == NULL || *ppEntry == NULL) {
226,334,735✔
627
    return;
90,552✔
628
  }
629

630
  taosMemoryFreeClear((*ppEntry)->name);
226,254,239✔
631

632
  if ((*ppEntry)->type < 0) {
226,290,616✔
633
    taosMemoryFreeClear(*ppEntry);
×
634
    return;
×
635
  }
636

637
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
226,195,403✔
638
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
187,172,413✔
639
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
187,142,422✔
640
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
187,147,668✔
641
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
127,286✔
642
    }
643
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
39,085,051✔
644
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
29,019,559✔
645
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
29,020,217✔
646
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
10,067,236✔
647
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
10,067,236✔
648
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
10,067,236✔
649
  } else {
650
    return;
×
651
  }
652
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
226,234,148✔
653
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
226,218,015✔
654
  metaCloneColRefFree(&(*ppEntry)->colRef);
226,230,488✔
655

656
  taosMemoryFreeClear(*ppEntry);
226,201,179✔
657
  return;
226,224,121✔
658
}
659

660
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
226,218,378✔
661
  int32_t code = TSDB_CODE_SUCCESS;
226,218,378✔
662

663
  if (NULL == pEntry || NULL == ppEntry) {
226,218,378✔
664
    return TSDB_CODE_INVALID_PARA;
×
665
  }
666

667
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
226,263,230✔
668
  if (NULL == *ppEntry) {
226,176,746✔
669
    return terrno;
×
670
  }
671

672
  (*ppEntry)->version = pEntry->version;
226,196,827✔
673
  (*ppEntry)->type = pEntry->type;
226,187,500✔
674
  (*ppEntry)->uid = pEntry->uid;
226,244,884✔
675

676
  if (pEntry->type < 0) {
226,253,365✔
677
    return TSDB_CODE_SUCCESS;
×
678
  }
679

680
  if (pEntry->name) {
226,247,649✔
681
    (*ppEntry)->name = tstrdup(pEntry->name);
226,251,727✔
682
    if (NULL == (*ppEntry)->name) {
226,252,726✔
683
      code = terrno;
×
684
      metaCloneEntryFree(ppEntry);
×
685
      return code;
×
686
    }
687
  }
688

689
  if (pEntry->type == TSDB_SUPER_TABLE) {
226,208,391✔
690
    (*ppEntry)->flags = pEntry->flags;
187,147,448✔
691

692
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
187,151,210✔
693
    if (code) {
187,171,529✔
694
      metaCloneEntryFree(ppEntry);
×
695
      return code;
×
696
    }
697

698
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
187,171,529✔
699
    if (code) {
187,194,564✔
700
      metaCloneEntryFree(ppEntry);
×
701
      return code;
×
702
    }
703
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
187,194,564✔
704
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
83,805✔
705
      if (code) {
82,978✔
706
        metaCloneEntryFree(ppEntry);
×
707
        return code;
×
708
      }
709
    }
710
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
187,193,156✔
711
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
187,191,444✔
712
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
39,086,660✔
713
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
29,020,688✔
714
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
29,020,928✔
715
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
29,019,184✔
716

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

729
    // tags
730
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
29,021,440✔
731
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
29,019,184✔
732
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
29,017,680✔
733
      code = terrno;
×
734
      metaCloneEntryFree(ppEntry);
×
735
      return code;
×
736
    }
737
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
29,019,184✔
738
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
10,067,236✔
739
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
10,067,236✔
740
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
10,067,236✔
741
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
10,067,236✔
742
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
10,067,236✔
743

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

751
    // comment
752
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
10,067,236✔
753
    if (pEntry->ntbEntry.commentLen > 0) {
10,067,236✔
754
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
14,414✔
755
      if (NULL == (*ppEntry)->ntbEntry.comment) {
14,414✔
756
        code = terrno;
×
757
        metaCloneEntryFree(ppEntry);
×
758
        return code;
×
759
      }
760
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
14,414✔
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) {
226,270,751✔
767
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,409,264✔
768
    if (code) {
1,405,451✔
769
      metaCloneEntryFree(ppEntry);
×
770
      return code;
×
771
    }
772
  } else {
773
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
224,830,975✔
774
    if (code) {
224,829,285✔
775
      metaCloneEntryFree(ppEntry);
×
776
      return code;
×
777
    }
778
  }
779
  int32_t numOfExtSchema = metaGetEntryRowSchemaNum(pEntry);
226,234,736✔
780
  if (pEntry->pExtSchemas && numOfExtSchema > 0) {
226,253,898✔
781
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(numOfExtSchema, sizeof(SExtSchema));
11,709,508✔
782
    if (!(*ppEntry)->pExtSchemas) {
11,707,341✔
783
      code = terrno;
×
784
      metaCloneEntryFree(ppEntry);
×
785
      return code;
×
786
    }
787
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * numOfExtSchema);
11,703,000✔
788
  }
789

790
  return code;
226,243,250✔
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