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

taosdata / TDengine / #5068

17 May 2026 01:15AM UTC coverage: 73.368% (-0.03%) from 73.401%
#5068

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)

281583 of 383795 relevant lines covered (73.37%)

138448173.88 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,579,832,265✔
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;
187,317,718✔
26
    }
27
  }
28
  return false;
1,387,652,573✔
29
}
30

31
static const SSchemaWrapper *metaGetEntryRowSchema(const SMetaEntry *pME) {
2,001,021,200✔
32
  if (pME == NULL) {
2,001,021,200✔
33
    return NULL;
×
34
  }
35

36
  if (pME->type == TSDB_SUPER_TABLE) {
2,001,021,200✔
37
    return &pME->stbEntry.schemaRow;
1,337,607,563✔
38
  }
39

40
  if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
663,875,744✔
41
    return &pME->ntbEntry.schemaRow;
458,133,235✔
42
  }
43

44
  return NULL;
205,770,645✔
45
}
46

47
static int32_t metaGetEntryRowSchemaNum(const SMetaEntry *pME) {
227,909,644✔
48
  const SSchemaWrapper *pSchema = metaGetEntryRowSchema(pME);
227,909,644✔
49
  return pSchema == NULL ? 0 : pSchema->nCols;
227,946,146✔
50
}
51

52
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
234,127,952✔
53
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
234,127,952✔
54
  bool                  hasTypeMods = false;
234,164,366✔
55

56
  if (pME->pExtSchemas == NULL || pSchWrapper == NULL) {
234,164,366✔
57
    return 0;
219,893,953✔
58
  }
59

60
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
14,309,400✔
61
  for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,642,431,110✔
62
    TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
63
  }
64
  return 0;
14,745,891✔
65
}
66

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

73
  for (int32_t i = 0; i < pw->nCols; i++) {
517,961,516✔
74
    SColRef *p = &pw->pColRef[i];
515,715,041✔
75
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
1,031,432,774✔
76
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
1,031,432,101✔
77
    if (p->hasRef) {
515,716,387✔
78
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
683,415,544✔
79
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
683,415,544✔
80
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
683,417,563✔
81
    }
82
  }
83

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

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

104
  if (pSchWrapper == NULL) {
1,485,171,224✔
105
    return 0;
×
106
  }
107

108
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,485,171,224✔
109
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,486,034,309✔
110
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
343,207,408✔
111
    if (pME->pExtSchemas == NULL) {
171,603,745✔
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,314,423,075✔
120
  }
121

122
  return 0;
1,486,327,953✔
123
}
124

125
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
52,932,435✔
126
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
52,932,435✔
127
  bool                  hasTypeMods = false;
53,001,685✔
128

129
  if (pSchWrapper == NULL) {
53,001,685✔
130
    return NULL;
×
131
  }
132

133
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
53,001,685✔
134

135
  if (hasTypeMods) {
52,896,682✔
136
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
40,066✔
137
    if (ret != NULL) {
40,066✔
138
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
40,066✔
139
    }
140
    return ret;
40,066✔
141
  }
142
  return NULL;
52,856,616✔
143
}
144

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

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

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

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

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

175
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
30,858✔
176
  int32_t    i = 0, j = 0;
30,858✔
177
  for (i = 0; i < nCols; ++i) {
233,520✔
178
    while (j < pParam->nFuncs) {
368,628✔
179
      if (pParam->funcColIds[j] == pSchema[i].colId) {
353,616✔
180
        pFuncIds[i] = pParam->funcIds[j];
165,132✔
181
        break;
165,132✔
182
      }
183
      if (pParam->funcColIds[j] > pSchema[i].colId) {
188,484✔
184
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
37,530✔
185
        break;
37,530✔
186
      }
187
      ++j;
150,954✔
188
    }
189
    if (j >= pParam->nFuncs) {
217,674✔
190
      for (; i < nCols; ++i) {
30,024✔
191
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
15,012✔
192
      }
193
      break;
15,012✔
194
    }
195
  }
196
  pFuncIds[0] = 0;  // Primary TS column has no function
30,858✔
197

198
  return 0;
30,858✔
199
}
200

201
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
71,821,246✔
202
  SColRefWrapper *pWrapper = &pME->colRef;
71,821,246✔
203
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
143,677,555✔
204
  if (pWrapper->nCols == 0) {
71,829,077✔
205
    return 0;
×
206
  }
207

208
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
143,667,002✔
209
  uDebug("decode cols:%d", pWrapper->nCols);
71,839,812✔
210
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
143,665,193✔
211
  if (pWrapper->pColRef == NULL) {
71,824,491✔
212
    return terrno;
×
213
  }
214

215
  for (int i = 0; i < pWrapper->nCols; i++) {
1,215,641,518✔
216
    SColRef *p = &pWrapper->pColRef[i];
1,143,859,918✔
217
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
2,147,483,647✔
218
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
2,147,483,647✔
219
    if (p->hasRef) {
1,143,910,398✔
220
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
623,866,209✔
221
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
623,851,970✔
222
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
623,887,377✔
223
    }
224
  }
225

226
  // Decode tag references (backward compatible)
227
  pWrapper->nTagRefs = 0;
71,692,216✔
228
  pWrapper->pTagRef = NULL;
71,865,634✔
229
  if (!tDecodeIsEnd(pDecoder)) {
71,855,927✔
230
    TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nTagRefs));
143,700,990✔
231
    if (pWrapper->nTagRefs > 0) {
71,843,030✔
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;
71,820,061✔
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,396,017✔
270
  if (pSrc->nCols > 0) {
1,396,017✔
271
    pDst->nCols = pSrc->nCols;
1,396,690✔
272
    pDst->version = pSrc->version;
1,398,036✔
273
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,396,017✔
274
    if (NULL == pDst->pColRef) {
1,393,325✔
275
      return terrno;
×
276
    }
277
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,394,671✔
278
  }
279
  return 0;
1,397,363✔
280
}
281

282
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
56,107,110✔
283
  int32_t code = 0;
56,107,110✔
284
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
112,227,361✔
285
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
112,421,554✔
286
  uTrace("encode cols:%d", pw->nCols);
56,301,303✔
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,407,188✔
294
}
295
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
56,025,272✔
296
  const SColCmprWrapper *pw = &pME->colCmpr;
56,025,272✔
297
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
56,061,222✔
298
}
299
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,486,296,816✔
300
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,486,296,816✔
301
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
302
  if (pWrapper->nCols == 0) {
1,486,325,584✔
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,486,586,540✔
308
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
309
  if (pWrapper->pColCmpr == NULL) {
1,485,711,373✔
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,488,267,001✔
319
}
320
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
321
                                                            SSchemaWrapper *pSchema) {
322
  pCmpr->nCols = pSchema->nCols;
330,174✔
323

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

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

334
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,646,666✔
335
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,316,492✔
336
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,316,760✔
337
    pColCmpr->id = pColSchema->colId;
1,316,760✔
338
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,316,760✔
339
  }
340
  return 0;
330,174✔
341
}
342

343
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
226,536,245✔
344
  if (pSrc->nCols > 0) {
226,536,245✔
345
    pDst->nCols = pSrc->nCols;
198,576,094✔
346
    pDst->version = pSrc->version;
198,574,791✔
347
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
198,547,376✔
348
    if (NULL == pDst->pColCmpr) {
198,511,417✔
349
      return terrno;
×
350
    }
351
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
198,518,805✔
352
  }
353
  return 0;
226,556,864✔
354
}
355

356
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
227,826,785✔
357
  if (pColRef) {
227,826,785✔
358
    taosMemoryFreeClear(pColRef->pColRef);
227,846,385✔
359
  }
360
}
227,871,729✔
361

362
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
227,850,233✔
363
  if (pCmpr) {
227,850,233✔
364
    taosMemoryFreeClear(pCmpr->pColCmpr);
227,888,415✔
365
  }
366
}
227,956,187✔
367

368
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
240,209,742✔
369
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
240,209,742✔
370
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
480,555,063✔
371
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
480,523,233✔
372
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
480,521,347✔
373

374
  if (pME->type > 0) {
240,254,081✔
375
    if (pME->name == NULL) {
234,153,903✔
376
      return TSDB_CODE_INVALID_PARA;
×
377
    }
378

379
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
468,425,427✔
380

381
    if (pME->type == TSDB_SUPER_TABLE) {
234,282,507✔
382
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
62,052,463✔
383
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
62,128,037✔
384
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
62,092,871✔
385
      if (TABLE_IS_ROLLUP(pME->flags)) {
30,990,413✔
386
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
125,266✔
387
      }
388
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
203,106,239✔
389
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
353,806,972✔
390
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
353,812,183✔
391
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
353,840,960✔
392
      if (pME->ctbEntry.commentLen > 0) {
176,931,325✔
393
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
32,596✔
394
      }
395
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
353,818,726✔
396
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
176,913,914✔
397
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
26,230,954✔
398
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
52,461,640✔
399
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
52,461,640✔
400
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
52,461,908✔
401
      if (pME->ntbEntry.commentLen > 0) {
26,230,954✔
402
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
46,468✔
403
      }
404
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
52,461,908✔
405
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
52,461,908✔
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) {
234,129,017✔
413
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,479,046✔
414
    } else {
415
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
231,818,190✔
416
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
31,082,605✔
417
      } else if (pME->type == TSDB_NORMAL_TABLE) {
200,847,255✔
418
        if (pME->colCmpr.nCols != 0) {
25,298,624✔
419
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,968,450✔
420
        } else {
421
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
330,174✔
422
          SColCmprWrapper colCmprs = {0};
330,174✔
423
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
330,174✔
424
          if (code != 0) {
330,174✔
425
            taosMemoryFree(colCmprs.pColCmpr);
×
426
            TAOS_CHECK_RETURN(code);
×
427
          }
428
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
330,174✔
429
          taosMemoryFree(colCmprs.pColCmpr);
330,174✔
430
          TAOS_CHECK_RETURN(code);
329,906✔
431
        }
432
      }
433
    }
434
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
234,255,011✔
435
  }
436
  if (pME->type == TSDB_SUPER_TABLE) {
240,244,665✔
437
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
61,953,120✔
438
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
61,839,470✔
439
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->stbEntry.securityLevel));
61,768,711✔
440
  } else if (pME->type == TSDB_NORMAL_TABLE) {
209,117,309✔
441
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
50,596,980✔
442
  }
443

444
  tEndEncode(pCoder);
239,984,129✔
445
  return 0;
240,038,637✔
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);
416,172✔
456
    return 0;
416,172✔
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,147,483,647✔
464
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
2,147,483,647✔
465
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
2,147,483,647✔
466
      if (TABLE_IS_ROLLUP(pME->flags)) {
1,079,676,207✔
467
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
383,944✔
468
      }
469
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,478,903,707✔
470
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
2,120,760,659✔
471
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
2,121,356,516✔
472
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
2,120,557,351✔
473
      if (pME->ctbEntry.commentLen > 0) {
1,059,892,684✔
474
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
56,360✔
475
      }
476
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
2,120,557,639✔
477
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
1,060,691,306✔
478
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
419,331,636✔
479
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
839,180,410✔
480
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
839,495,092✔
481
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
839,201,326✔
482
      if (pME->ntbEntry.commentLen > 0) {
419,448,092✔
483
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
85,490✔
484
      }
485
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
838,942,922✔
486
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
839,303,773✔
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,079,907,892✔
499
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
1,079,721,719✔
500

501
        if (pME->colCmpr.nCols == 0) {
1,080,184,380✔
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,478,861,867✔
509
      if (!tDecodeIsEnd(pCoder)) {
407,776,456✔
510
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
407,777,937✔
511
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
407,777,937✔
512
        if (pME->colCmpr.nCols == 0) {
407,953,328✔
513
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
514
        }
515
      } else {
516
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
4,077✔
517
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
4,077✔
518
      }
519
      TABLE_SET_COL_COMPRESSED(pME->flags);
407,787,748✔
520
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,071,164,328✔
521
      if (!tDecodeIsEnd(pCoder)) {
71,848,722✔
522
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
71,851,155✔
523
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
71,851,155✔
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,487,389,183✔
533
    } else {
534
      pME->pExtSchemas = NULL;
1,071,567,091✔
535
    }
536
  }
537
  if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
538
    if (!tDecodeIsEnd(pCoder)) {
1,077,081,296✔
539
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
2,147,483,647✔
540
    }
541
    if (!tDecodeIsEnd(pCoder)) {
1,078,845,292✔
542
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
2,147,483,647✔
543
    }
544
    if (!tDecodeIsEnd(pCoder)) {
1,078,453,222✔
545
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->stbEntry.securityLevel));
2,147,483,647✔
546
    }
547
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,478,389,418✔
548
    if (!tDecodeIsEnd(pCoder)) {
407,518,551✔
549
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
815,318,362✔
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) {
388,021,357✔
561
  if (pSrc == NULL || pDst == NULL) {
388,021,357✔
562
    return TSDB_CODE_INVALID_PARA;
×
563
  }
564

565
  pDst->nCols = pSrc->nCols;
388,079,295✔
566
  pDst->version = pSrc->version;
388,088,587✔
567
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
388,122,672✔
568
  if (pDst->pSchema == NULL) {
387,919,616✔
569
    return terrno;
×
570
  }
571
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
387,957,868✔
572
  return TSDB_CODE_SUCCESS;
388,154,596✔
573
}
574

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

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

603
  return TSDB_CODE_SUCCESS;
84,654✔
604
}
605

606
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
387,995,787✔
607
  if (pSchema) {
387,995,787✔
608
    taosMemoryFreeClear(pSchema->pSchema);
388,044,188✔
609
  }
610
}
388,037,886✔
611

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

625
void metaCloneEntryFree(SMetaEntry **ppEntry) {
227,961,792✔
626
  if (ppEntry == NULL || *ppEntry == NULL) {
227,961,792✔
627
    return;
90,329✔
628
  }
629

630
  taosMemoryFreeClear((*ppEntry)->name);
227,895,884✔
631

632
  if ((*ppEntry)->type < 0) {
227,957,516✔
633
    taosMemoryFreeClear(*ppEntry);
×
634
    return;
×
635
  }
636

637
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
227,845,409✔
638
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
188,996,281✔
639
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
188,981,431✔
640
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
188,988,270✔
641
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
129,425✔
642
    }
643
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
38,919,863✔
644
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
28,843,244✔
645
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
28,835,749✔
646
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
10,089,551✔
647
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
10,089,551✔
648
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
10,089,551✔
649
  } else {
650
    return;
×
651
  }
652
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
227,920,039✔
653
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
227,894,998✔
654
  metaCloneColRefFree(&(*ppEntry)->colRef);
227,924,688✔
655

656
  taosMemoryFreeClear(*ppEntry);
227,861,934✔
657
  return;
227,867,233✔
658
}
659

660
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
227,880,085✔
661
  int32_t code = TSDB_CODE_SUCCESS;
227,880,085✔
662

663
  if (NULL == pEntry || NULL == ppEntry) {
227,880,085✔
664
    return TSDB_CODE_INVALID_PARA;
×
665
  }
666

667
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
227,953,932✔
668
  if (NULL == *ppEntry) {
227,820,898✔
669
    return terrno;
×
670
  }
671

672
  (*ppEntry)->version = pEntry->version;
227,856,642✔
673
  (*ppEntry)->type = pEntry->type;
227,870,445✔
674
  (*ppEntry)->uid = pEntry->uid;
227,935,780✔
675

676
  if (pEntry->type < 0) {
227,912,863✔
677
    return TSDB_CODE_SUCCESS;
×
678
  }
679

680
  if (pEntry->name) {
227,917,640✔
681
    (*ppEntry)->name = tstrdup(pEntry->name);
227,932,554✔
682
    if (NULL == (*ppEntry)->name) {
227,941,833✔
683
      code = terrno;
×
684
      metaCloneEntryFree(ppEntry);
×
685
      return code;
×
686
    }
687
  }
688

689
  if (pEntry->type == TSDB_SUPER_TABLE) {
227,889,462✔
690
    (*ppEntry)->flags = pEntry->flags;
188,969,982✔
691

692
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
188,992,920✔
693
    if (code) {
189,022,741✔
694
      metaCloneEntryFree(ppEntry);
×
695
      return code;
×
696
    }
697

698
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
189,022,741✔
699
    if (code) {
189,056,338✔
700
      metaCloneEntryFree(ppEntry);
×
701
      return code;
×
702
    }
703
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
189,056,338✔
704
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
84,654✔
705
      if (code) {
84,654✔
706
        metaCloneEntryFree(ppEntry);
×
707
        return code;
×
708
      }
709
    }
710
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
189,057,818✔
711
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
189,036,855✔
712
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
38,925,874✔
713
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
28,838,758✔
714
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
28,838,959✔
715
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
28,839,310✔
716

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

729
    // tags
730
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
28,842,065✔
731
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
28,837,048✔
732
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
28,842,787✔
733
      code = terrno;
×
734
      metaCloneEntryFree(ppEntry);
×
735
      return code;
×
736
    }
737
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
28,839,414✔
738
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
10,089,551✔
739
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
10,089,551✔
740
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
10,089,551✔
741
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
10,089,551✔
742
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
10,089,551✔
743

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

751
    // comment
752
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
10,089,551✔
753
    if (pEntry->ntbEntry.commentLen > 0) {
10,089,551✔
754
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
14,385✔
755
      if (NULL == (*ppEntry)->ntbEntry.comment) {
14,385✔
756
        code = terrno;
×
757
        metaCloneEntryFree(ppEntry);
×
758
        return code;
×
759
      }
760
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
14,385✔
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) {
227,936,673✔
767
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,389,226✔
768
    if (code) {
1,396,690✔
769
      metaCloneEntryFree(ppEntry);
×
770
      return code;
×
771
    }
772
  } else {
773
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
226,535,517✔
774
    if (code) {
226,531,898✔
775
      metaCloneEntryFree(ppEntry);
×
776
      return code;
×
777
    }
778
  }
779
  int32_t numOfExtSchema = metaGetEntryRowSchemaNum(pEntry);
227,928,588✔
780
  if (pEntry->pExtSchemas && numOfExtSchema > 0) {
227,940,466✔
781
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(numOfExtSchema, sizeof(SExtSchema));
11,394,235✔
782
    if (!(*ppEntry)->pExtSchemas) {
11,378,085✔
783
      code = terrno;
×
784
      metaCloneEntryFree(ppEntry);
×
785
      return code;
×
786
    }
787
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * numOfExtSchema);
11,373,746✔
788
  }
789

790
  return code;
227,897,267✔
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