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

taosdata / TDengine / #5066

17 May 2026 01:15AM UTC coverage: 73.393% (-0.01%) from 73.407%
#5066

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)

281679 of 383795 relevant lines covered (73.39%)

134058284.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,466,147,905✔
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;
183,381,178✔
26
    }
27
  }
28
  return false;
1,284,140,901✔
29
}
30

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

36
  if (pME->type == TSDB_SUPER_TABLE) {
1,884,871,244✔
37
    return &pME->stbEntry.schemaRow;
1,316,186,092✔
38
  }
39

40
  if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
568,814,448✔
41
    return &pME->ntbEntry.schemaRow;
362,120,626✔
42
  }
43

44
  return NULL;
206,681,576✔
45
}
46

47
static int32_t metaGetEntryRowSchemaNum(const SMetaEntry *pME) {
228,735,402✔
48
  const SSchemaWrapper *pSchema = metaGetEntryRowSchema(pME);
228,735,402✔
49
  return pSchema == NULL ? 0 : pSchema->nCols;
228,752,711✔
50
}
51

52
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
231,491,578✔
53
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
231,491,578✔
54
  bool                  hasTypeMods = false;
231,502,798✔
55

56
  if (pME->pExtSchemas == NULL || pSchWrapper == NULL) {
231,502,798✔
57
    return 0;
216,871,452✔
58
  }
59

60
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
14,648,206✔
61
  for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,178,342,339✔
62
    TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
63
  }
64
  return 0;
14,665,606✔
65
}
66

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

73
  for (int32_t i = 0; i < pw->nCols; i++) {
501,716,260✔
74
    SColRef *p = &pw->pColRef[i];
499,498,408✔
75
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
998,998,850✔
76
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
999,000,884✔
77
    if (p->hasRef) {
499,499,764✔
78
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
661,946,650✔
79
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
661,945,972✔
80
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
661,945,972✔
81
    }
82
  }
83

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

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

104
  if (pSchWrapper == NULL) {
1,376,925,688✔
105
    return 0;
×
106
  }
107

108
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,376,925,688✔
109
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,377,260,031✔
110
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
334,270,308✔
111
    if (pME->pExtSchemas == NULL) {
167,136,967✔
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,210,118,524✔
120
  }
121

122
  return 0;
1,377,313,203✔
123
}
124

125
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
47,456,632✔
126
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
47,456,632✔
127
  bool                  hasTypeMods = false;
47,481,820✔
128

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

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

135
  if (hasTypeMods) {
47,437,854✔
136
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
39,056✔
137
    if (ret != NULL) {
39,056✔
138
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
39,056✔
139
    }
140
    return ret;
39,056✔
141
  }
142
  return NULL;
47,398,798✔
143
}
144

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

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

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

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

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

175
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
28,749✔
176
  int32_t    i = 0, j = 0;
28,749✔
177
  for (i = 0; i < nCols; ++i) {
217,560✔
178
    while (j < pParam->nFuncs) {
343,434✔
179
      if (pParam->funcColIds[j] == pSchema[i].colId) {
329,448✔
180
        pFuncIds[i] = pParam->funcIds[j];
153,846✔
181
        break;
153,846✔
182
      }
183
      if (pParam->funcColIds[j] > pSchema[i].colId) {
175,602✔
184
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
34,965✔
185
        break;
34,965✔
186
      }
187
      ++j;
140,637✔
188
    }
189
    if (j >= pParam->nFuncs) {
202,797✔
190
      for (; i < nCols; ++i) {
27,972✔
191
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
13,986✔
192
      }
193
      break;
13,986✔
194
    }
195
  }
196
  pFuncIds[0] = 0;  // Primary TS column has no function
28,749✔
197

198
  return 0;
28,749✔
199
}
200

201
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
45,708,734✔
202
  SColRefWrapper *pWrapper = &pME->colRef;
45,708,734✔
203
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
91,418,223✔
204
  if (pWrapper->nCols == 0) {
45,709,489✔
205
    return 0;
×
206
  }
207

208
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
91,416,153✔
209
  uDebug("decode cols:%d", pWrapper->nCols);
45,710,131✔
210
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
91,416,406✔
211
  if (pWrapper->pColRef == NULL) {
45,710,125✔
212
    return terrno;
×
213
  }
214

215
  for (int i = 0; i < pWrapper->nCols; i++) {
759,694,128✔
216
    SColRef *p = &pWrapper->pColRef[i];
713,988,918✔
217
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,427,998,149✔
218
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,428,023,023✔
219
    if (p->hasRef) {
714,016,575✔
220
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
406,860,388✔
221
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
406,861,597✔
222
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
406,852,711✔
223
    }
224
  }
225

226
  // Decode tag references (backward compatible)
227
  pWrapper->nTagRefs = 0;
45,667,105✔
228
  pWrapper->pTagRef = NULL;
45,714,158✔
229
  if (!tDecodeIsEnd(pDecoder)) {
45,712,124✔
230
    TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nTagRefs));
91,423,593✔
231
    if (pWrapper->nTagRefs > 0) {
45,711,473✔
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,712,802✔
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,403,898✔
270
  if (pSrc->nCols > 0) {
1,403,898✔
271
    pDst->nCols = pSrc->nCols;
1,403,898✔
272
    pDst->version = pSrc->version;
1,403,898✔
273
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,403,898✔
274
    if (NULL == pDst->pColRef) {
1,403,220✔
275
      return terrno;
×
276
    }
277
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,403,220✔
278
  }
279
  return 0;
1,403,898✔
280
}
281

282
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
55,556,872✔
283
  int32_t code = 0;
55,556,872✔
284
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
111,105,054✔
285
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
111,114,899✔
286
  uTrace("encode cols:%d", pw->nCols);
55,566,717✔
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,639,627✔
294
}
295
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
55,328,069✔
296
  const SColCmprWrapper *pw = &pME->colCmpr;
55,328,069✔
297
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
55,337,283✔
298
}
299
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,377,222,368✔
300
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,377,222,368✔
301
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
302
  if (pWrapper->nCols == 0) {
1,377,259,772✔
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,377,404,786✔
308
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
309
  if (pWrapper->pColCmpr == NULL) {
1,377,190,535✔
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,377,925,672✔
319
}
320
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
321
                                                            SSchemaWrapper *pSchema) {
322
  pCmpr->nCols = pSchema->nCols;
325,326✔
323

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

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

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

343
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
227,347,693✔
344
  if (pSrc->nCols > 0) {
227,347,693✔
345
    pDst->nCols = pSrc->nCols;
196,536,448✔
346
    pDst->version = pSrc->version;
196,528,383✔
347
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
196,522,958✔
348
    if (NULL == pDst->pColCmpr) {
196,503,462✔
349
      return terrno;
×
350
    }
351
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
196,504,898✔
352
  }
353
  return 0;
227,343,838✔
354
}
355

356
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
228,743,245✔
357
  if (pColRef) {
228,743,245✔
358
    taosMemoryFreeClear(pColRef->pColRef);
228,754,080✔
359
  }
360
}
228,761,523✔
361

362
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
228,730,274✔
363
  if (pCmpr) {
228,730,274✔
364
    taosMemoryFreeClear(pCmpr->pColCmpr);
228,739,468✔
365
  }
366
}
228,759,352✔
367

368
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
237,099,853✔
369
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
237,099,853✔
370
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
474,217,810✔
371
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
474,185,977✔
372
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
474,216,029✔
373

374
  if (pME->type > 0) {
237,110,324✔
375
    if (pME->name == NULL) {
231,505,795✔
376
      return TSDB_CODE_INVALID_PARA;
×
377
    }
378

379
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
463,027,245✔
380

381
    if (pME->type == TSDB_SUPER_TABLE) {
231,548,403✔
382
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
61,667,796✔
383
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
61,698,057✔
384
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
61,758,669✔
385
      if (TABLE_IS_ROLLUP(pME->flags)) {
30,866,204✔
386
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
118,208✔
387
      }
388
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
200,635,438✔
389
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
349,943,235✔
390
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
349,959,744✔
391
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
349,979,070✔
392
      if (pME->ctbEntry.commentLen > 0) {
174,993,028✔
393
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
32,692✔
394
      }
395
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
349,954,925✔
396
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
174,980,410✔
397
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
25,690,284✔
398
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
51,380,568✔
399
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
51,380,568✔
400
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
51,380,568✔
401
      if (pME->ntbEntry.commentLen > 0) {
25,690,284✔
402
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
46,500✔
403
      }
404
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
51,380,568✔
405
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
51,380,568✔
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,520,841✔
413
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,335,988✔
414
    } else {
415
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
229,249,329✔
416
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
30,881,614✔
417
      } else if (pME->type == TSDB_NORMAL_TABLE) {
198,458,992✔
418
        if (pME->colCmpr.nCols != 0) {
24,766,210✔
419
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,440,852✔
420
        } else {
421
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
325,358✔
422
          SColCmprWrapper colCmprs = {0};
325,358✔
423
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
325,358✔
424
          if (code != 0) {
325,358✔
425
            taosMemoryFree(colCmprs.pColCmpr);
×
426
            TAOS_CHECK_RETURN(code);
×
427
          }
428
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
325,358✔
429
          taosMemoryFree(colCmprs.pColCmpr);
325,358✔
430
          TAOS_CHECK_RETURN(code);
325,358✔
431
        }
432
      }
433
    }
434
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
231,544,533✔
435
  }
436
  if (pME->type == TSDB_SUPER_TABLE) {
237,124,473✔
437
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
61,622,375✔
438
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
61,620,550✔
439
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->stbEntry.securityLevel));
61,621,131✔
440
  } else if (pME->type == TSDB_NORMAL_TABLE) {
206,198,757✔
441
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
49,532,420✔
442
  }
443

444
  tEndEncode(pCoder);
237,023,186✔
445
  return 0;
237,089,071✔
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);
408,612✔
456
    return 0;
408,612✔
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,123,686,009✔
464
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
2,123,811,630✔
465
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
2,123,707,314✔
466
      if (TABLE_IS_ROLLUP(pME->flags)) {
1,061,778,201✔
467
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
356,888✔
468
      }
469
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,255,768,665✔
470
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,865,243,211✔
471
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,865,581,882✔
472
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,865,202,561✔
473
      if (pME->ctbEntry.commentLen > 0) {
932,413,835✔
474
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
56,574✔
475
      }
476
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,865,210,534✔
477
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
932,790,645✔
478
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
323,669,473✔
479
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
647,497,443✔
480
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
647,592,101✔
481
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
647,494,397✔
482
      if (pME->ntbEntry.commentLen > 0) {
323,702,032✔
483
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
85,632✔
484
      }
485
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
647,383,007✔
486
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
647,461,033✔
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,061,845,312✔
499
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
1,061,860,788✔
500

501
        if (pME->colCmpr.nCols == 0) {
1,061,962,303✔
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,255,698,901✔
509
      if (!tDecodeIsEnd(pCoder)) {
315,898,891✔
510
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
315,905,448✔
511
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
315,905,448✔
512
        if (pME->colCmpr.nCols == 0) {
315,836,809✔
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);
315,857,372✔
520
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
939,935,335✔
521
      if (!tDecodeIsEnd(pCoder)) {
45,710,184✔
522
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
45,709,506✔
523
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
45,709,506✔
524
      } else {
525
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
678✔
526
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
678✔
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,377,765,230✔
533
    } else {
534
      pME->pExtSchemas = NULL;
940,392,700✔
535
    }
536
  }
537
  if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
538
    if (!tDecodeIsEnd(pCoder)) {
1,061,248,690✔
539
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
2,123,238,360✔
540
    }
541
    if (!tDecodeIsEnd(pCoder)) {
1,061,593,840✔
542
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
2,123,341,201✔
543
    }
544
    if (!tDecodeIsEnd(pCoder)) {
1,061,561,702✔
545
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->stbEntry.securityLevel));
2,123,272,831✔
546
    }
547
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,255,698,605✔
548
    if (!tDecodeIsEnd(pCoder)) {
315,804,554✔
549
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
631,723,179✔
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,124,673✔
561
  if (pSrc == NULL || pDst == NULL) {
384,124,673✔
562
    return TSDB_CODE_INVALID_PARA;
×
563
  }
564

565
  pDst->nCols = pSrc->nCols;
384,154,315✔
566
  pDst->version = pSrc->version;
384,139,253✔
567
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
384,164,741✔
568
  if (pDst->pSchema == NULL) {
384,003,367✔
569
    return terrno;
×
570
  }
571
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
384,049,768✔
572
  return TSDB_CODE_SUCCESS;
384,169,405✔
573
}
574

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

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

603
  return TSDB_CODE_SUCCESS;
78,831✔
604
}
605

606
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
384,042,266✔
607
  if (pSchema) {
384,042,266✔
608
    taosMemoryFreeClear(pSchema->pSchema);
384,123,127✔
609
  }
610
}
384,004,079✔
611

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

625
void metaCloneEntryFree(SMetaEntry **ppEntry) {
228,830,841✔
626
  if (ppEntry == NULL || *ppEntry == NULL) {
228,830,841✔
627
    return;
90,370✔
628
  }
629

630
  taosMemoryFreeClear((*ppEntry)->name);
228,752,990✔
631

632
  if ((*ppEntry)->type < 0) {
228,775,944✔
633
    taosMemoryFreeClear(*ppEntry);
×
634
    return;
×
635
  }
636

637
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
228,696,260✔
638
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
187,075,023✔
639
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
187,043,669✔
640
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
187,042,673✔
641
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
119,746✔
642
    }
643
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
41,677,350✔
644
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
31,690,033✔
645
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
31,689,355✔
646
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
9,993,840✔
647
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
9,993,840✔
648
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
9,993,840✔
649
  } else {
650
    return;
×
651
  }
652
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
228,728,837✔
653
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
228,724,464✔
654
  metaCloneColRefFree(&(*ppEntry)->colRef);
228,735,993✔
655

656
  taosMemoryFreeClear(*ppEntry);
228,714,756✔
657
  return;
228,746,695✔
658
}
659

660
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
228,716,481✔
661
  int32_t code = TSDB_CODE_SUCCESS;
228,716,481✔
662

663
  if (NULL == pEntry || NULL == ppEntry) {
228,716,481✔
664
    return TSDB_CODE_INVALID_PARA;
×
665
  }
666

667
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
228,766,962✔
668
  if (NULL == *ppEntry) {
228,694,978✔
669
    return terrno;
×
670
  }
671

672
  (*ppEntry)->version = pEntry->version;
228,716,603✔
673
  (*ppEntry)->type = pEntry->type;
228,719,248✔
674
  (*ppEntry)->uid = pEntry->uid;
228,743,315✔
675

676
  if (pEntry->type < 0) {
228,759,643✔
677
    return TSDB_CODE_SUCCESS;
×
678
  }
679

680
  if (pEntry->name) {
228,751,606✔
681
    (*ppEntry)->name = tstrdup(pEntry->name);
228,753,922✔
682
    if (NULL == (*ppEntry)->name) {
228,752,708✔
683
      code = terrno;
×
684
      metaCloneEntryFree(ppEntry);
×
685
      return code;
×
686
    }
687
  }
688

689
  if (pEntry->type == TSDB_SUPER_TABLE) {
228,700,890✔
690
    (*ppEntry)->flags = pEntry->flags;
187,058,898✔
691

692
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
187,072,721✔
693
    if (code) {
187,083,412✔
694
      metaCloneEntryFree(ppEntry);
×
695
      return code;
×
696
    }
697

698
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
187,083,412✔
699
    if (code) {
187,104,161✔
700
      metaCloneEntryFree(ppEntry);
×
701
      return code;
×
702
    }
703
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
187,104,161✔
704
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
78,831✔
705
      if (code) {
78,831✔
706
        metaCloneEntryFree(ppEntry);
×
707
        return code;
×
708
      }
709
    }
710
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
187,103,929✔
711
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
187,100,176✔
712
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
41,683,208✔
713
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
31,687,115✔
714
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
31,690,119✔
715
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
31,686,364✔
716

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

729
    // tags
730
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
31,688,617✔
731
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
31,687,115✔
732
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
31,686,364✔
733
      code = terrno;
×
734
      metaCloneEntryFree(ppEntry);
×
735
      return code;
×
736
    }
737
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
31,688,617✔
738
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
9,993,840✔
739
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
9,993,840✔
740
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
9,993,840✔
741
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
9,993,840✔
742
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
9,993,840✔
743

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

751
    // comment
752
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
9,993,840✔
753
    if (pEntry->ntbEntry.commentLen > 0) {
9,993,840✔
754
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
14,396✔
755
      if (NULL == (*ppEntry)->ntbEntry.comment) {
14,396✔
756
        code = terrno;
×
757
        metaCloneEntryFree(ppEntry);
×
758
        return code;
×
759
      }
760
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
14,396✔
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) {
228,775,321✔
767
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,406,488✔
768
    if (code) {
1,403,898✔
769
      metaCloneEntryFree(ppEntry);
×
770
      return code;
×
771
    }
772
  } else {
773
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
227,331,974✔
774
    if (code) {
227,332,822✔
775
      metaCloneEntryFree(ppEntry);
×
776
      return code;
×
777
    }
778
  }
779
  int32_t numOfExtSchema = metaGetEntryRowSchemaNum(pEntry);
228,736,720✔
780
  if (pEntry->pExtSchemas && numOfExtSchema > 0) {
228,757,446✔
781
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(numOfExtSchema, sizeof(SExtSchema));
11,695,099✔
782
    if (!(*ppEntry)->pExtSchemas) {
11,692,842✔
783
      code = terrno;
×
784
      metaCloneEntryFree(ppEntry);
×
785
      return code;
×
786
    }
787
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * numOfExtSchema);
11,687,313✔
788
  }
789

790
  return code;
228,736,337✔
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