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

taosdata / TDengine / #5061

17 May 2026 01:15AM UTC coverage: 73.408% (-0.02%) from 73.425%
#5061

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)

281737 of 383795 relevant lines covered (73.41%)

134677323.24 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,472,227,806✔
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,846,050✔
26
    }
27
  }
28
  return false;
1,287,829,570✔
29
}
30

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

36
  if (pME->type == TSDB_SUPER_TABLE) {
1,890,236,001✔
37
    return &pME->stbEntry.schemaRow;
1,319,811,736✔
38
  }
39

40
  if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
570,543,693✔
41
    return &pME->ntbEntry.schemaRow;
365,387,274✔
42
  }
43

44
  return NULL;
205,107,663✔
45
}
46

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

52
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
231,820,458✔
53
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
231,820,458✔
54
  bool                  hasTypeMods = false;
231,843,371✔
55

56
  if (pME->pExtSchemas == NULL || pSchWrapper == NULL) {
231,843,371✔
57
    return 0;
217,750,882✔
58
  }
59

60
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
14,105,935✔
61
  for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,580,163,151✔
62
    TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
63
  }
64
  return 0;
14,160,248✔
65
}
66

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

73
  for (int32_t i = 0; i < pw->nCols; i++) {
502,511,495✔
74
    SColRef *p = &pw->pColRef[i];
500,292,003✔
75
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
1,000,588,773✔
76
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
1,000,589,454✔
77
    if (p->hasRef) {
500,294,046✔
78
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
663,005,993✔
79
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
663,007,355✔
80
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
663,006,674✔
81
    }
82
  }
83

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

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

104
  if (pSchWrapper == NULL) {
1,383,954,365✔
105
    return 0;
×
106
  }
107

108
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,383,954,365✔
109
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,384,311,065✔
110
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
332,821,814✔
111
    if (pME->pExtSchemas == NULL) {
166,415,510✔
112
      return terrno;
×
113
    }
114

115
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
2,147,483,647✔
116
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
2,147,483,647✔
117
    }
118
  } else {
119
    pME->pExtSchemas = NULL;
1,217,896,244✔
120
  }
121

122
  return 0;
1,384,392,004✔
123
}
124

125
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
47,268,729✔
126
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
47,268,729✔
127
  bool                  hasTypeMods = false;
47,306,507✔
128

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

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

135
  if (hasTypeMods) {
47,261,117✔
136
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
39,512✔
137
    if (ret != NULL) {
39,512✔
138
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
39,512✔
139
    }
140
    return ret;
39,512✔
141
  }
142
  return NULL;
47,221,605✔
143
}
144

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

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

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

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

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

175
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
30,266✔
176
  int32_t    i = 0, j = 0;
30,266✔
177
  for (i = 0; i < nCols; ++i) {
229,040✔
178
    while (j < pParam->nFuncs) {
361,556✔
179
      if (pParam->funcColIds[j] == pSchema[i].colId) {
346,832✔
180
        pFuncIds[i] = pParam->funcIds[j];
161,964✔
181
        break;
161,964✔
182
      }
183
      if (pParam->funcColIds[j] > pSchema[i].colId) {
184,868✔
184
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
36,810✔
185
        break;
36,810✔
186
      }
187
      ++j;
148,058✔
188
    }
189
    if (j >= pParam->nFuncs) {
213,498✔
190
      for (; i < nCols; ++i) {
29,448✔
191
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
14,724✔
192
      }
193
      break;
14,724✔
194
    }
195
  }
196
  pFuncIds[0] = 0;  // Primary TS column has no function
30,266✔
197

198
  return 0;
30,266✔
199
}
200

201
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
45,610,185✔
202
  SColRefWrapper *pWrapper = &pME->colRef;
45,610,185✔
203
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
91,243,595✔
204
  if (pWrapper->nCols == 0) {
45,625,267✔
205
    return 0;
×
206
  }
207

208
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
91,242,960✔
209
  uDebug("decode cols:%d", pWrapper->nCols);
45,625,284✔
210
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
91,243,222✔
211
  if (pWrapper->pColRef == NULL) {
45,619,756✔
212
    return terrno;
×
213
  }
214

215
  for (int i = 0; i < pWrapper->nCols; i++) {
760,223,766✔
216
    SColRef *p = &pWrapper->pColRef[i];
714,594,688✔
217
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,429,223,501✔
218
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,429,256,754✔
219
    if (p->hasRef) {
714,641,651✔
220
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
406,984,963✔
221
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
406,971,406✔
222
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
406,985,896✔
223
    }
224
  }
225

226
  // Decode tag references (backward compatible)
227
  pWrapper->nTagRefs = 0;
45,597,345✔
228
  pWrapper->pTagRef = NULL;
45,637,427✔
229
  if (!tDecodeIsEnd(pDecoder)) {
45,634,022✔
230
    TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nTagRefs));
91,265,326✔
231
    if (pWrapper->nTagRefs > 0) {
45,630,623✔
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,619,089✔
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,990✔
270
  if (pSrc->nCols > 0) {
1,403,990✔
271
    pDst->nCols = pSrc->nCols;
1,403,990✔
272
    pDst->version = pSrc->version;
1,404,671✔
273
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,405,352✔
274
    if (NULL == pDst->pColRef) {
1,402,628✔
275
      return terrno;
×
276
    }
277
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,402,628✔
278
  }
279
  return 0;
1,403,309✔
280
}
281

282
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
55,133,573✔
283
  int32_t code = 0;
55,133,573✔
284
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
110,230,626✔
285
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
110,247,834✔
286
  uTrace("encode cols:%d", pw->nCols);
55,150,781✔
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,224,995✔
294
}
295
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
54,909,852✔
296
  const SColCmprWrapper *pw = &pME->colCmpr;
54,909,852✔
297
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
54,924,954✔
298
}
299
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,384,238,411✔
300
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,384,238,411✔
301
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
302
  if (pWrapper->nCols == 0) {
1,384,327,774✔
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,384,400,206✔
308
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
309
  if (pWrapper->pColCmpr == NULL) {
1,384,212,731✔
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,384,927,522✔
319
}
320
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
321
                                                            SSchemaWrapper *pSchema) {
322
  pCmpr->nCols = pSchema->nCols;
323,676✔
323

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

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

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

343
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
225,578,139✔
344
  if (pSrc->nCols > 0) {
225,578,139✔
345
    pDst->nCols = pSrc->nCols;
197,064,147✔
346
    pDst->version = pSrc->version;
197,061,548✔
347
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
197,045,875✔
348
    if (NULL == pDst->pColCmpr) {
197,022,174✔
349
      return terrno;
×
350
    }
351
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
197,015,620✔
352
  }
353
  return 0;
225,571,590✔
354
}
355

356
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
226,957,627✔
357
  if (pColRef) {
226,957,627✔
358
    taosMemoryFreeClear(pColRef->pColRef);
226,973,190✔
359
  }
360
}
226,984,636✔
361

362
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
226,966,213✔
363
  if (pCmpr) {
226,966,213✔
364
    taosMemoryFreeClear(pCmpr->pColCmpr);
226,968,052✔
365
  }
366
}
226,997,391✔
367

368
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
237,762,522✔
369
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
237,762,522✔
370
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
475,541,769✔
371
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
475,530,236✔
372
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
475,553,126✔
373

374
  if (pME->type > 0) {
237,772,470✔
375
    if (pME->name == NULL) {
231,827,316✔
376
      return TSDB_CODE_INVALID_PARA;
×
377
    }
378

379
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
463,644,417✔
380

381
    if (pME->type == TSDB_SUPER_TABLE) {
231,837,362✔
382
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
60,690,561✔
383
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
60,727,883✔
384
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
60,799,795✔
385
      if (TABLE_IS_ROLLUP(pME->flags)) {
30,381,307✔
386
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
123,588✔
387
      }
388
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
201,420,858✔
389
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
351,388,682✔
390
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
351,397,194✔
391
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
351,417,942✔
392
      if (pME->ctbEntry.commentLen > 0) {
175,711,274✔
393
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
32,624✔
394
      }
395
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
351,409,813✔
396
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
175,704,534✔
397
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
25,748,050✔
398
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
51,496,546✔
399
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
51,496,546✔
400
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
51,496,546✔
401
      if (pME->ntbEntry.commentLen > 0) {
25,748,050✔
402
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
46,480✔
403
      }
404
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
51,496,546✔
405
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
51,496,992✔
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,823,278✔
413
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,381,813✔
414
    } else {
415
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
229,511,793✔
416
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
30,385,116✔
417
      } else if (pME->type == TSDB_NORMAL_TABLE) {
199,260,442✔
418
        if (pME->colCmpr.nCols != 0) {
24,825,140✔
419
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,501,464✔
420
        } else {
421
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
323,676✔
422
          SColCmprWrapper colCmprs = {0};
323,676✔
423
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
323,676✔
424
          if (code != 0) {
323,676✔
425
            taosMemoryFree(colCmprs.pColCmpr);
×
426
            TAOS_CHECK_RETURN(code);
×
427
          }
428
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
323,676✔
429
          taosMemoryFree(colCmprs.pColCmpr);
323,676✔
430
          TAOS_CHECK_RETURN(code);
323,676✔
431
        }
432
      }
433
    }
434
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
231,852,110✔
435
  }
436
  if (pME->type == TSDB_SUPER_TABLE) {
237,802,386✔
437
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
60,657,011✔
438
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
60,659,309✔
439
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->stbEntry.securityLevel));
60,669,254✔
440
  } else if (pME->type == TSDB_NORMAL_TABLE) {
207,341,408✔
441
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
49,650,280✔
442
  }
443

444
  tEndEncode(pCoder);
237,679,871✔
445
  return 0;
237,742,700✔
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);
373,524✔
456
    return 0;
373,524✔
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,131,363,029✔
464
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
2,131,487,175✔
465
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
2,131,413,150✔
466
      if (TABLE_IS_ROLLUP(pME->flags)) {
1,065,658,529✔
467
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
376,506✔
468
      }
469
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,262,655,141✔
470
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,872,688,229✔
471
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,872,986,036✔
472
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,872,608,364✔
473
      if (pME->ctbEntry.commentLen > 0) {
936,113,816✔
474
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
56,418✔
475
      }
476
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,872,611,618✔
477
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
936,490,892✔
478
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
326,811,901✔
479
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
653,866,097✔
480
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
653,970,649✔
481
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
653,855,295✔
482
      if (pME->ntbEntry.commentLen > 0) {
326,868,317✔
483
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
85,530✔
484
      }
485
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
653,750,576✔
486
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
653,817,819✔
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,065,694,681✔
499
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
1,065,702,433✔
500

501
        if (pME->colCmpr.nCols == 0) {
1,065,813,239✔
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,262,540,103✔
509
      if (!tDecodeIsEnd(pCoder)) {
319,034,525✔
510
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
319,039,661✔
511
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
319,039,661✔
512
        if (pME->colCmpr.nCols == 0) {
319,010,464✔
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);
319,010,295✔
520
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
943,718,363✔
521
      if (!tDecodeIsEnd(pCoder)) {
45,631,834✔
522
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
45,630,684✔
523
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
45,630,684✔
524
      } else {
525
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
1,315✔
526
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
1,315✔
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,384,749,648✔
533
    } else {
534
      pME->pExtSchemas = NULL;
944,118,957✔
535
    }
536
  }
537
  if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
538
    if (!tDecodeIsEnd(pCoder)) {
1,065,174,705✔
539
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
2,130,995,671✔
540
    }
541
    if (!tDecodeIsEnd(pCoder)) {
1,065,444,147✔
542
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
2,131,005,861✔
543
    }
544
    if (!tDecodeIsEnd(pCoder)) {
1,065,413,575✔
545
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->stbEntry.securityLevel));
2,130,987,633✔
546
    }
547
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,262,518,921✔
548
    if (!tDecodeIsEnd(pCoder)) {
318,931,133✔
549
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
637,981,008✔
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) {
385,112,880✔
561
  if (pSrc == NULL || pDst == NULL) {
385,112,880✔
562
    return TSDB_CODE_INVALID_PARA;
×
563
  }
564

565
  pDst->nCols = pSrc->nCols;
385,133,799✔
566
  pDst->version = pSrc->version;
385,125,792✔
567
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
385,129,492✔
568
  if (pDst->pSchema == NULL) {
384,972,926✔
569
    return terrno;
×
570
  }
571
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
385,021,009✔
572
  return TSDB_CODE_SUCCESS;
385,136,460✔
573
}
574

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

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

603
  return TSDB_CODE_SUCCESS;
82,968✔
604
}
605

606
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
385,095,478✔
607
  if (pSchema) {
385,095,478✔
608
    taosMemoryFreeClear(pSchema->pSchema);
385,119,827✔
609
  }
610
}
385,071,925✔
611

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

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

630
  taosMemoryFreeClear((*ppEntry)->name);
226,965,224✔
631

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

637
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
226,914,562✔
638
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
187,514,492✔
639
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
187,496,956✔
640
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
187,491,300✔
641
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
126,844✔
642
    }
643
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
39,452,697✔
644
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
29,392,497✔
645
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
29,393,660✔
646
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
10,065,278✔
647
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
10,065,278✔
648
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
10,065,278✔
649
  } else {
650
    return;
×
651
  }
652
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
226,948,925✔
653
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
226,930,377✔
654
  metaCloneColRefFree(&(*ppEntry)->colRef);
226,944,537✔
655

656
  taosMemoryFreeClear(*ppEntry);
226,922,538✔
657
  return;
226,956,841✔
658
}
659

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

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

667
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
226,998,831✔
668
  if (NULL == *ppEntry) {
226,915,869✔
669
    return terrno;
×
670
  }
671

672
  (*ppEntry)->version = pEntry->version;
226,928,565✔
673
  (*ppEntry)->type = pEntry->type;
226,933,850✔
674
  (*ppEntry)->uid = pEntry->uid;
226,974,256✔
675

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

680
  if (pEntry->name) {
226,969,747✔
681
    (*ppEntry)->name = tstrdup(pEntry->name);
226,979,462✔
682
    if (NULL == (*ppEntry)->name) {
226,977,587✔
683
      code = terrno;
×
684
      metaCloneEntryFree(ppEntry);
×
685
      return code;
×
686
    }
687
  }
688

689
  if (pEntry->type == TSDB_SUPER_TABLE) {
226,949,859✔
690
    (*ppEntry)->flags = pEntry->flags;
187,502,764✔
691

692
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
187,502,743✔
693
    if (code) {
187,532,288✔
694
      metaCloneEntryFree(ppEntry);
×
695
      return code;
×
696
    }
697

698
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
187,532,288✔
699
    if (code) {
187,549,886✔
700
      metaCloneEntryFree(ppEntry);
×
701
      return code;
×
702
    }
703
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
187,549,886✔
704
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
82,968✔
705
      if (code) {
82,968✔
706
        metaCloneEntryFree(ppEntry);
×
707
        return code;
×
708
      }
709
    }
710
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
187,550,030✔
711
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
187,549,616✔
712
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
39,456,334✔
713
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
29,391,306✔
714
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
29,391,904✔
715
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
29,391,295✔
716

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

729
    // tags
730
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
29,392,657✔
731
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
29,393,099✔
732
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
29,393,338✔
733
      code = terrno;
×
734
      metaCloneEntryFree(ppEntry);
×
735
      return code;
×
736
    }
737
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
29,393,338✔
738
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
10,065,278✔
739
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
10,065,278✔
740
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
10,065,278✔
741
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
10,065,278✔
742
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
10,065,278✔
743

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

751
    // comment
752
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
10,065,278✔
753
    if (pEntry->ntbEntry.commentLen > 0) {
10,065,278✔
754
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
14,389✔
755
      if (NULL == (*ppEntry)->ntbEntry.comment) {
14,389✔
756
        code = terrno;
×
757
        metaCloneEntryFree(ppEntry);
×
758
        return code;
×
759
      }
760
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
14,389✔
761
    }
762
  } else {
763
    return TSDB_CODE_INVALID_PARA;
×
764
  }
765

766
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
226,996,953✔
767
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,419,433✔
768
    if (code) {
1,403,309✔
769
      metaCloneEntryFree(ppEntry);
×
770
      return code;
×
771
    }
772
  } else {
773
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
225,550,563✔
774
    if (code) {
225,557,516✔
775
      metaCloneEntryFree(ppEntry);
×
776
      return code;
×
777
    }
778
  }
779
  int32_t numOfExtSchema = metaGetEntryRowSchemaNum(pEntry);
226,960,825✔
780
  if (pEntry->pExtSchemas && numOfExtSchema > 0) {
226,962,618✔
781
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(numOfExtSchema, sizeof(SExtSchema));
11,163,697✔
782
    if (!(*ppEntry)->pExtSchemas) {
11,164,159✔
783
      code = terrno;
×
784
      metaCloneEntryFree(ppEntry);
×
785
      return code;
×
786
    }
787
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * numOfExtSchema);
11,159,066✔
788
  }
789

790
  return code;
226,965,753✔
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