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

taosdata / TDengine / #5057

17 May 2026 01:15AM UTC coverage: 73.406% (+0.02%) from 73.384%
#5057

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)

281727 of 383795 relevant lines covered (73.41%)

136101761.85 hits per line

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

79.11
/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,483,599,052✔
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;
181,111,116✔
26
    }
27
  }
28
  return false;
1,299,239,679✔
29
}
30

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

36
  if (pME->type == TSDB_SUPER_TABLE) {
1,904,008,419✔
37
    return &pME->stbEntry.schemaRow;
1,322,909,678✔
38
  }
39

40
  if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
581,305,989✔
41
    return &pME->ntbEntry.schemaRow;
374,408,053✔
42
  }
43

44
  return NULL;
206,849,418✔
45
}
46

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

52
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
232,410,890✔
53
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
232,410,890✔
54
  bool                  hasTypeMods = false;
232,441,304✔
55

56
  if (pME->pExtSchemas == NULL || pSchWrapper == NULL) {
232,441,304✔
57
    return 0;
218,554,645✔
58
  }
59

60
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
13,899,639✔
61
  for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,524,875,051✔
62
    TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
63
  }
64
  return 0;
13,917,490✔
65
}
66

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

73
  for (int32_t i = 0; i < pw->nCols; i++) {
501,810,002✔
74
    SColRef *p = &pw->pColRef[i];
499,581,972✔
75
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
999,163,944✔
76
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
999,163,944✔
77
    if (p->hasRef) {
499,581,972✔
78
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
662,030,176✔
79
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
662,030,176✔
80
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
662,030,176✔
81
    }
82
  }
83

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

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

104
  if (pSchWrapper == NULL) {
1,391,239,397✔
105
    return 0;
×
106
  }
107

108
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,391,239,397✔
109
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,391,568,036✔
110
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
331,891,733✔
111
    if (pME->pExtSchemas == NULL) {
165,947,187✔
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,225,618,596✔
120
  }
121

122
  return 0;
1,391,576,080✔
123
}
124

125
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
51,775,029✔
126
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
51,775,029✔
127
  bool                  hasTypeMods = false;
51,804,791✔
128

129
  if (pSchWrapper == NULL) {
51,804,791✔
130
    return NULL;
×
131
  }
132

133
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
51,804,791✔
134

135
  if (hasTypeMods) {
51,774,020✔
136
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
40,019✔
137
    if (ret != NULL) {
40,019✔
138
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
40,019✔
139
    }
140
    return ret;
40,019✔
141
  }
142
  return NULL;
51,734,001✔
143
}
144

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

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

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

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

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

175
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
30,525✔
176
  int32_t    i = 0, j = 0;
30,525✔
177
  for (i = 0; i < nCols; ++i) {
231,000✔
178
    while (j < pParam->nFuncs) {
364,650✔
179
      if (pParam->funcColIds[j] == pSchema[i].colId) {
349,800✔
180
        pFuncIds[i] = pParam->funcIds[j];
163,350✔
181
        break;
163,350✔
182
      }
183
      if (pParam->funcColIds[j] > pSchema[i].colId) {
186,450✔
184
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
37,125✔
185
        break;
37,125✔
186
      }
187
      ++j;
149,325✔
188
    }
189
    if (j >= pParam->nFuncs) {
215,325✔
190
      for (; i < nCols; ++i) {
29,700✔
191
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
14,850✔
192
      }
193
      break;
14,850✔
194
    }
195
  }
196
  pFuncIds[0] = 0;  // Primary TS column has no function
30,525✔
197

198
  return 0;
30,525✔
199
}
200

201
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
45,623,764✔
202
  SColRefWrapper *pWrapper = &pME->colRef;
45,623,764✔
203
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
91,258,609✔
204
  if (pWrapper->nCols == 0) {
45,627,340✔
205
    return 0;
×
206
  }
207

208
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
91,255,736✔
209
  uDebug("decode cols:%d", pWrapper->nCols);
45,633,282✔
210
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
91,255,374✔
211
  if (pWrapper->pColRef == NULL) {
45,624,602✔
212
    return terrno;
×
213
  }
214

215
  for (int i = 0; i < pWrapper->nCols; i++) {
760,786,495✔
216
    SColRef *p = &pWrapper->pColRef[i];
715,160,637✔
217
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,430,332,885✔
218
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,430,365,179✔
219
    if (p->hasRef) {
715,192,438✔
220
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
407,252,845✔
221
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
407,234,120✔
222
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
407,256,966✔
223
    }
224
  }
225

226
  // Decode tag references (backward compatible)
227
  pWrapper->nTagRefs = 0;
45,615,082✔
228
  pWrapper->pTagRef = NULL;
45,640,079✔
229
  if (!tDecodeIsEnd(pDecoder)) {
45,638,045✔
230
    TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nTagRefs));
91,276,768✔
231
    if (pWrapper->nTagRefs > 0) {
45,638,723✔
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,627,942✔
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,408,426✔
270
  if (pSrc->nCols > 0) {
1,408,426✔
271
    pDst->nCols = pSrc->nCols;
1,408,426✔
272
    pDst->version = pSrc->version;
1,408,426✔
273
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,408,426✔
274
    if (NULL == pDst->pColRef) {
1,407,070✔
275
      return terrno;
×
276
    }
277
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,407,748✔
278
  }
279
  return 0;
1,407,748✔
280
}
281

282
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
54,812,768✔
283
  int32_t code = 0;
54,812,768✔
284
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
109,587,044✔
285
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
109,614,251✔
286
  uTrace("encode cols:%d", pw->nCols);
54,839,975✔
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;
54,904,663✔
294
}
295
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
54,569,151✔
296
  const SColCmprWrapper *pw = &pME->colCmpr;
54,569,151✔
297
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
54,585,856✔
298
}
299
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,391,337,747✔
300
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,391,337,747✔
301
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
302
  if (pWrapper->nCols == 0) {
1,391,518,926✔
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,391,696,473✔
308
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
309
  if (pWrapper->pColCmpr == NULL) {
1,391,444,401✔
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,392,164,513✔
319
}
320
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
321
                                                            SSchemaWrapper *pSchema) {
322
  pCmpr->nCols = pSchema->nCols;
328,400✔
323

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

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

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

343
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
227,042,291✔
344
  if (pSrc->nCols > 0) {
227,042,291✔
345
    pDst->nCols = pSrc->nCols;
197,719,284✔
346
    pDst->version = pSrc->version;
197,717,105✔
347
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
197,702,306✔
348
    if (NULL == pDst->pColCmpr) {
197,698,032✔
349
      return terrno;
×
350
    }
351
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
197,696,167✔
352
  }
353
  return 0;
227,035,776✔
354
}
355

356
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
228,426,753✔
357
  if (pColRef) {
228,426,753✔
358
    taosMemoryFreeClear(pColRef->pColRef);
228,444,332✔
359
  }
360
}
228,444,372✔
361

362
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
228,429,878✔
363
  if (pCmpr) {
228,429,878✔
364
    taosMemoryFreeClear(pCmpr->pColCmpr);
228,441,433✔
365
  }
366
}
228,459,055✔
367

368
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
238,240,823✔
369
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
238,240,823✔
370
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
476,515,093✔
371
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
476,463,761✔
372
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
476,484,654✔
373

374
  if (pME->type > 0) {
238,244,921✔
375
    if (pME->name == NULL) {
232,426,154✔
376
      return TSDB_CODE_INVALID_PARA;
×
377
    }
378

379
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
464,836,541✔
380

381
    if (pME->type == TSDB_SUPER_TABLE) {
232,445,803✔
382
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
59,994,848✔
383
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
60,018,405✔
384
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
60,056,725✔
385
      if (TABLE_IS_ROLLUP(pME->flags)) {
30,011,996✔
386
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
125,292✔
387
      }
388
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
202,374,179✔
389
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
353,238,611✔
390
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
353,252,762✔
391
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
353,276,330✔
392
      if (pME->ctbEntry.commentLen > 0) {
176,643,386✔
393
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
32,632✔
394
      }
395
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
353,272,983✔
396
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
176,632,580✔
397
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
25,782,696✔
398
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
51,565,392✔
399
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
51,565,392✔
400
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
51,565,392✔
401
      if (pME->ntbEntry.commentLen > 0) {
25,782,696✔
402
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
46,696✔
403
      }
404
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
51,565,392✔
405
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
51,565,392✔
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) {
232,435,976✔
413
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,399,380✔
414
    } else {
415
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
230,112,913✔
416
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
30,042,510✔
417
      } else if (pME->type == TSDB_NORMAL_TABLE) {
200,202,906✔
418
        if (pME->colCmpr.nCols != 0) {
24,854,558✔
419
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,526,158✔
420
        } else {
421
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
328,400✔
422
          SColCmprWrapper colCmprs = {0};
328,400✔
423
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
328,400✔
424
          if (code != 0) {
328,400✔
425
            taosMemoryFree(colCmprs.pColCmpr);
×
426
            TAOS_CHECK_RETURN(code);
×
427
          }
428
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
328,400✔
429
          taosMemoryFree(colCmprs.pColCmpr);
328,400✔
430
          TAOS_CHECK_RETURN(code);
328,400✔
431
        }
432
      }
433
    }
434
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
232,473,699✔
435
  }
436
  if (pME->type == TSDB_SUPER_TABLE) {
238,275,871✔
437
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
59,943,050✔
438
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
59,923,196✔
439
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->stbEntry.securityLevel));
59,938,133✔
440
  } else if (pME->type == TSDB_NORMAL_TABLE) {
208,178,140✔
441
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
49,709,116✔
442
  }
443

444
  tEndEncode(pCoder);
238,158,795✔
445
  return 0;
238,215,262✔
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);
366,414✔
456
    return 0;
366,414✔
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,134,881,534✔
464
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
2,134,999,927✔
465
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
2,134,913,999✔
466
      if (TABLE_IS_ROLLUP(pME->flags)) {
1,067,391,661✔
467
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
379,237✔
468
      }
469
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,311,763,933✔
470
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,959,795,505✔
471
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,960,086,394✔
472
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,959,730,063✔
473
      if (pME->ctbEntry.commentLen > 0) {
979,692,362✔
474
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
56,480✔
475
      }
476
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,959,769,165✔
477
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
980,050,047✔
478
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
332,306,886✔
479
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
664,840,984✔
480
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
664,961,048✔
481
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
664,836,708✔
482
      if (pME->ntbEntry.commentLen > 0) {
332,353,141✔
483
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
85,952✔
484
      }
485
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
664,739,687✔
486
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
664,790,881✔
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,067,432,034✔
499
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
1,067,454,081✔
500

501
        if (pME->colCmpr.nCols == 0) {
1,067,569,852✔
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,311,637,704✔
509
      if (!tDecodeIsEnd(pCoder)) {
324,510,952✔
510
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
324,515,778✔
511
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
324,516,296✔
512
        if (pME->colCmpr.nCols == 0) {
324,452,323✔
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);
646✔
517
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
646✔
518
      }
519
      TABLE_SET_COL_COMPRESSED(pME->flags);
324,463,988✔
520
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
987,297,908✔
521
      if (!tDecodeIsEnd(pCoder)) {
45,634,094✔
522
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
45,634,738✔
523
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
45,635,564✔
524
      } else {
525
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
526
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
19✔
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,391,998,495✔
533
    } else {
534
      pME->pExtSchemas = NULL;
987,644,158✔
535
    }
536
  }
537
  if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
538
    if (!tDecodeIsEnd(pCoder)) {
1,066,932,030✔
539
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
2,134,477,953✔
540
    }
541
    if (!tDecodeIsEnd(pCoder)) {
1,067,145,254✔
542
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
2,134,459,256✔
543
    }
544
    if (!tDecodeIsEnd(pCoder)) {
1,067,138,474✔
545
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->stbEntry.securityLevel));
2,134,399,910✔
546
    }
547
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,311,602,023✔
548
    if (!tDecodeIsEnd(pCoder)) {
324,452,787✔
549
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
648,980,546✔
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) {
386,427,272✔
561
  if (pSrc == NULL || pDst == NULL) {
386,427,272✔
562
    return TSDB_CODE_INVALID_PARA;
×
563
  }
564

565
  pDst->nCols = pSrc->nCols;
386,455,006✔
566
  pDst->version = pSrc->version;
386,439,297✔
567
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
386,452,309✔
568
  if (pDst->pSchema == NULL) {
386,312,294✔
569
    return terrno;
×
570
  }
571
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
386,365,289✔
572
  return TSDB_CODE_SUCCESS;
386,456,045✔
573
}
574

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

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

603
  return TSDB_CODE_SUCCESS;
83,571✔
604
}
605

606
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
386,399,948✔
607
  if (pSchema) {
386,399,948✔
608
    taosMemoryFreeClear(pSchema->pSchema);
386,414,903✔
609
  }
610
}
386,395,728✔
611

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

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

630
  taosMemoryFreeClear((*ppEntry)->name);
228,447,047✔
631

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

637
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
228,373,877✔
638
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
188,159,061✔
639
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
188,137,430✔
640
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
188,151,247✔
641
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
126,926✔
642
    }
643
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
40,265,843✔
644
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
30,202,737✔
645
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
30,199,918✔
646
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
10,071,522✔
647
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
10,071,522✔
648
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
10,071,522✔
649
  } else {
650
    return;
×
651
  }
652
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
228,422,161✔
653
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
228,396,685✔
654
  metaCloneColRefFree(&(*ppEntry)->colRef);
228,412,028✔
655

656
  taosMemoryFreeClear(*ppEntry);
228,385,336✔
657
  return;
228,417,819✔
658
}
659

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

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

667
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
228,467,714✔
668
  if (NULL == *ppEntry) {
228,395,234✔
669
    return terrno;
×
670
  }
671

672
  (*ppEntry)->version = pEntry->version;
228,409,512✔
673
  (*ppEntry)->type = pEntry->type;
228,413,261✔
674
  (*ppEntry)->uid = pEntry->uid;
228,452,040✔
675

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

680
  if (pEntry->name) {
228,445,609✔
681
    (*ppEntry)->name = tstrdup(pEntry->name);
228,446,234✔
682
    if (NULL == (*ppEntry)->name) {
228,444,930✔
683
      code = terrno;
×
684
      metaCloneEntryFree(ppEntry);
×
685
      return code;
×
686
    }
687
  }
688

689
  if (pEntry->type == TSDB_SUPER_TABLE) {
228,414,597✔
690
    (*ppEntry)->flags = pEntry->flags;
188,155,604✔
691

692
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
188,165,425✔
693
    if (code) {
188,182,288✔
694
      metaCloneEntryFree(ppEntry);
×
695
      return code;
×
696
    }
697

698
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
188,182,288✔
699
    if (code) {
188,206,448✔
700
      metaCloneEntryFree(ppEntry);
×
701
      return code;
×
702
    }
703
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
188,206,448✔
704
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
83,571✔
705
      if (code) {
83,571✔
706
        metaCloneEntryFree(ppEntry);
×
707
        return code;
×
708
      }
709
    }
710
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
188,206,448✔
711
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
188,200,494✔
712
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
40,270,711✔
713
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
30,198,773✔
714
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
30,200,545✔
715
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
30,200,965✔
716

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

729
    // tags
730
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
30,201,044✔
731
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
30,196,161✔
732
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
30,199,609✔
733
      code = terrno;
×
734
      metaCloneEntryFree(ppEntry);
×
735
      return code;
×
736
    }
737
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
30,199,419✔
738
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
10,071,522✔
739
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
10,071,522✔
740
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
10,071,522✔
741
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
10,071,522✔
742
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
10,071,522✔
743

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

751
    // comment
752
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
10,071,522✔
753
    if (pEntry->ntbEntry.commentLen > 0) {
10,071,522✔
754
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
14,454✔
755
      if (NULL == (*ppEntry)->ntbEntry.comment) {
14,454✔
756
        code = terrno;
×
757
        metaCloneEntryFree(ppEntry);
×
758
        return code;
×
759
      }
760
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
14,454✔
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,459,477✔
767
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,407,191✔
768
    if (code) {
1,407,748✔
769
      metaCloneEntryFree(ppEntry);
×
770
      return code;
×
771
    }
772
  } else {
773
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
227,030,395✔
774
    if (code) {
227,021,367✔
775
      metaCloneEntryFree(ppEntry);
×
776
      return code;
×
777
    }
778
  }
779
  int32_t numOfExtSchema = metaGetEntryRowSchemaNum(pEntry);
228,429,115✔
780
  if (pEntry->pExtSchemas && numOfExtSchema > 0) {
228,451,098✔
781
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(numOfExtSchema, sizeof(SExtSchema));
10,965,282✔
782
    if (!(*ppEntry)->pExtSchemas) {
10,962,382✔
783
      code = terrno;
×
784
      metaCloneEntryFree(ppEntry);
×
785
      return code;
×
786
    }
787
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * numOfExtSchema);
10,957,723✔
788
  }
789

790
  return code;
228,434,706✔
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