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

taosdata / TDengine / #5087

17 May 2026 01:15AM UTC coverage: 73.331% (+0.007%) from 73.324%
#5087

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)

281439 of 383795 relevant lines covered (73.33%)

136666483.31 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,454,674,712✔
23
  for (int32_t i = 0; i < nCols; i++) {
2,147,483,647✔
24
    if (HAS_TYPE_MOD(pSchema + i)) {
2,147,483,647✔
25
      return true;
183,690,073✔
26
    }
27
  }
28
  return false;
1,268,249,294✔
29
}
30

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

36
  if (pME->type == TSDB_SUPER_TABLE) {
1,871,006,716✔
37
    return &pME->stbEntry.schemaRow;
1,303,881,595✔
38
  }
39

40
  if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
567,249,336✔
41
    return &pME->ntbEntry.schemaRow;
362,419,915✔
42
  }
43

44
  return NULL;
204,822,121✔
45
}
46

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

52
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
230,683,096✔
53
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
230,683,096✔
54
  bool                  hasTypeMods = false;
230,700,640✔
55

56
  if (pME->pExtSchemas == NULL || pSchWrapper == NULL) {
230,700,640✔
57
    return 0;
216,226,829✔
58
  }
59

60
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
14,482,473✔
61
  for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
1,634,463,118✔
62
    TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
2,147,483,647✔
63
  }
64
  return 0;
14,475,793✔
65
}
66

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

73
  for (int32_t i = 0; i < pw->nCols; i++) {
513,402,908✔
74
    SColRef *p = &pw->pColRef[i];
511,195,888✔
75
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
1,022,391,776✔
76
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
1,022,391,776✔
77
    if (p->hasRef) {
511,195,888✔
78
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
677,574,980✔
79
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
677,574,980✔
80
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
677,574,980✔
81
    }
82
  }
83

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

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

104
  if (pSchWrapper == NULL) {
1,364,996,651✔
105
    return 0;
×
106
  }
107

108
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
1,364,996,651✔
109
  if (hasExtSchema && pSchWrapper->nCols > 0) {
1,365,173,888✔
110
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
335,389,068✔
111
    if (pME->pExtSchemas == NULL) {
167,700,513✔
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,197,477,702✔
120
  }
121

122
  return 0;
1,365,214,021✔
123
}
124

125
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
48,340,632✔
126
  const SSchemaWrapper *pSchWrapper = metaGetEntryRowSchema(pME);
48,340,632✔
127
  bool                  hasTypeMods = false;
48,362,255✔
128

129
  if (pSchWrapper == NULL) {
48,362,255✔
130
    return NULL;
×
131
  }
132

133
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
48,362,255✔
134

135
  if (hasTypeMods) {
48,333,166✔
136
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
39,975✔
137
    if (ret != NULL) {
39,975✔
138
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
39,975✔
139
    }
140
    return ret;
39,975✔
141
  }
142
  return NULL;
48,293,191✔
143
}
144

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

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

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

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

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

175
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
30,562✔
176
  int32_t    i = 0, j = 0;
30,562✔
177
  for (i = 0; i < nCols; ++i) {
231,280✔
178
    while (j < pParam->nFuncs) {
365,092✔
179
      if (pParam->funcColIds[j] == pSchema[i].colId) {
350,224✔
180
        pFuncIds[i] = pParam->funcIds[j];
163,548✔
181
        break;
163,548✔
182
      }
183
      if (pParam->funcColIds[j] > pSchema[i].colId) {
186,676✔
184
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
37,170✔
185
        break;
37,170✔
186
      }
187
      ++j;
149,506✔
188
    }
189
    if (j >= pParam->nFuncs) {
215,586✔
190
      for (; i < nCols; ++i) {
29,736✔
191
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
14,868✔
192
      }
193
      break;
14,868✔
194
    }
195
  }
196
  pFuncIds[0] = 0;  // Primary TS column has no function
30,562✔
197

198
  return 0;
30,562✔
199
}
200

201
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
45,951,890✔
202
  SColRefWrapper *pWrapper = &pME->colRef;
45,951,890✔
203
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
91,914,677✔
204
  if (pWrapper->nCols == 0) {
45,956,701✔
205
    return 0;
×
206
  }
207

208
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
91,910,502✔
209
  uDebug("decode cols:%d", pWrapper->nCols);
45,955,935✔
210
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
91,908,724✔
211
  if (pWrapper->pColRef == NULL) {
45,954,595✔
212
    return terrno;
×
213
  }
214

215
  for (int i = 0; i < pWrapper->nCols; i++) {
767,912,519✔
216
    SColRef *p = &pWrapper->pColRef[i];
721,968,002✔
217
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,443,964,869✔
218
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,443,983,764✔
219
    if (p->hasRef) {
721,995,840✔
220
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
411,829,490✔
221
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
411,825,016✔
222
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
411,830,354✔
223
    }
224
  }
225

226
  // Decode tag references (backward compatible)
227
  pWrapper->nTagRefs = 0;
45,928,488✔
228
  pWrapper->pTagRef = NULL;
45,960,675✔
229
  if (!tDecodeIsEnd(pDecoder)) {
45,960,000✔
230
    TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nTagRefs));
91,919,287✔
231
    if (pWrapper->nTagRefs > 0) {
45,959,287✔
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,949,844✔
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,750✔
270
  if (pSrc->nCols > 0) {
1,396,750✔
271
    pDst->nCols = pSrc->nCols;
1,396,750✔
272
    pDst->version = pSrc->version;
1,396,750✔
273
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
1,396,750✔
274
    if (NULL == pDst->pColRef) {
1,396,750✔
275
      return terrno;
×
276
    }
277
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
1,396,750✔
278
  }
279
  return 0;
1,396,750✔
280
}
281

282
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
55,368,359✔
283
  int32_t code = 0;
55,368,359✔
284
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
110,725,308✔
285
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
110,746,057✔
286
  uTrace("encode cols:%d", pw->nCols);
55,389,108✔
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,417,165✔
294
}
295
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
55,089,839✔
296
  const SColCmprWrapper *pw = &pME->colCmpr;
55,089,839✔
297
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
55,099,714✔
298
}
299
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
1,365,160,802✔
300
  SColCmprWrapper *pWrapper = &pME->colCmpr;
1,365,160,802✔
301
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
2,147,483,647✔
302
  if (pWrapper->nCols == 0) {
1,365,065,645✔
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,365,214,948✔
308
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,147,483,647✔
309
  if (pWrapper->pColCmpr == NULL) {
1,365,149,253✔
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,365,587,652✔
319
}
320
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
321
                                                            SSchemaWrapper *pSchema) {
322
  pCmpr->nCols = pSchema->nCols;
326,678✔
323

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

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

334
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,630,578✔
335
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
1,303,900✔
336
    SSchema  *pColSchema = &pSchema->pSchema[i];
1,303,900✔
337
    pColCmpr->id = pColSchema->colId;
1,303,900✔
338
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
1,303,900✔
339
  }
340
  return 0;
326,678✔
341
}
342

343
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
225,488,018✔
344
  if (pSrc->nCols > 0) {
225,488,018✔
345
    pDst->nCols = pSrc->nCols;
195,921,789✔
346
    pDst->version = pSrc->version;
195,913,282✔
347
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
195,904,793✔
348
    if (NULL == pDst->pColCmpr) {
195,900,374✔
349
      return terrno;
×
350
    }
351
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
195,896,702✔
352
  }
353
  return 0;
225,476,147✔
354
}
355

356
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
226,864,809✔
357
  if (pColRef) {
226,864,809✔
358
    taosMemoryFreeClear(pColRef->pColRef);
226,872,945✔
359
  }
360
}
226,874,694✔
361

362
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
226,864,069✔
363
  if (pCmpr) {
226,864,069✔
364
    taosMemoryFreeClear(pCmpr->pColCmpr);
226,871,452✔
365
  }
366
}
226,878,792✔
367

368
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
236,408,564✔
369
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
236,408,564✔
370
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
472,840,000✔
371
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
472,816,702✔
372
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
472,838,822✔
373

374
  if (pME->type > 0) {
236,421,591✔
375
    if (pME->name == NULL) {
230,705,026✔
376
      return TSDB_CODE_INVALID_PARA;
×
377
    }
378

379
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
461,390,922✔
380

381
    if (pME->type == TSDB_SUPER_TABLE) {
230,713,098✔
382
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
60,974,360✔
383
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
61,000,924✔
384
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
61,023,141✔
385
      if (TABLE_IS_ROLLUP(pME->flags)) {
30,501,712✔
386
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
125,686✔
387
      }
388
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
200,188,807✔
389
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
348,749,293✔
390
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
348,758,469✔
391
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
348,775,072✔
392
      if (pME->ctbEntry.commentLen > 0) {
174,389,119✔
393
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
32,520✔
394
      }
395
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
348,762,424✔
396
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
174,377,852✔
397
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
25,823,214✔
398
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
51,646,428✔
399
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
51,646,428✔
400
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
51,646,428✔
401
      if (pME->ntbEntry.commentLen > 0) {
25,823,214✔
402
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
46,968✔
403
      }
404
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
51,646,428✔
405
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
51,646,428✔
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) {
230,701,866✔
413
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
2,277,148✔
414
    } else {
415
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
228,459,256✔
416
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
30,510,549✔
417
      } else if (pME->type == TSDB_NORMAL_TABLE) {
198,000,657✔
418
        if (pME->colCmpr.nCols != 0) {
24,904,764✔
419
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,578,086✔
420
        } else {
421
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
326,678✔
422
          SColCmprWrapper colCmprs = {0};
326,678✔
423
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
326,678✔
424
          if (code != 0) {
326,678✔
425
            taosMemoryFree(colCmprs.pColCmpr);
×
426
            TAOS_CHECK_RETURN(code);
×
427
          }
428
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
326,678✔
429
          taosMemoryFree(colCmprs.pColCmpr);
326,678✔
430
          TAOS_CHECK_RETURN(code);
326,678✔
431
        }
432
      }
433
    }
434
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
230,717,910✔
435
  }
436
  if (pME->type == TSDB_SUPER_TABLE) {
236,430,521✔
437
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
60,943,606✔
438
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
60,931,982✔
439
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->stbEntry.securityLevel));
60,929,003✔
440
  } else if (pME->type == TSDB_NORMAL_TABLE) {
205,899,252✔
441
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
49,809,528✔
442
  }
443

444
  tEndEncode(pCoder);
236,358,017✔
445
  return 0;
236,407,691✔
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);
369,370✔
456
    return 0;
369,370✔
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,098,842,393✔
464
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
2,098,939,572✔
465
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
2,098,883,544✔
466
      if (TABLE_IS_ROLLUP(pME->flags)) {
1,049,391,742✔
467
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
380,236✔
468
      }
469
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,305,503,067✔
470
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,963,877,326✔
471
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,964,037,505✔
472
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,963,839,792✔
473
      if (pME->ctbEntry.commentLen > 0) {
981,822,267✔
474
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
56,248✔
475
      }
476
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,963,854,338✔
477
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
982,012,730✔
478
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
323,818,233✔
479
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
647,754,451✔
480
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
647,825,564✔
481
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
647,749,549✔
482
      if (pME->ntbEntry.commentLen > 0) {
323,837,506✔
483
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
86,320✔
484
      }
485
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
647,668,239✔
486
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
647,705,430✔
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,049,448,235✔
499
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
1,049,451,363✔
500

501
        if (pME->colCmpr.nCols == 0) {
1,049,515,747✔
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,305,465,285✔
509
      if (!tDecodeIsEnd(pCoder)) {
316,018,794✔
510
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
316,027,501✔
511
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
316,028,327✔
512
        if (pME->colCmpr.nCols == 0) {
315,961,995✔
513
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
514
        }
515
      } else {
516
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
517
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
518
      }
519
      TABLE_SET_COL_COMPRESSED(pME->flags);
315,986,836✔
520
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
989,523,399✔
521
      if (!tDecodeIsEnd(pCoder)) {
45,959,325✔
522
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
45,957,365✔
523
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
45,957,365✔
524
      } else {
525
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
1,960✔
526
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
1,960✔
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,365,516,598✔
533
    } else {
534
      pME->pExtSchemas = NULL;
989,690,579✔
535
    }
536
  }
537
  if (pME->type == TSDB_SUPER_TABLE) {
2,147,483,647✔
538
    if (!tDecodeIsEnd(pCoder)) {
1,049,146,364✔
539
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
2,098,620,806✔
540
    }
541
    if (!tDecodeIsEnd(pCoder)) {
1,049,278,967✔
542
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
2,098,578,426✔
543
    }
544
    if (!tDecodeIsEnd(pCoder)) {
1,049,262,538✔
545
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->stbEntry.securityLevel));
2,098,576,960✔
546
    }
547
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,305,366,427✔
548
    if (!tDecodeIsEnd(pCoder)) {
315,960,012✔
549
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
631,982,557✔
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) {
382,899,392✔
561
  if (pSrc == NULL || pDst == NULL) {
382,899,392✔
562
    return TSDB_CODE_INVALID_PARA;
×
563
  }
564

565
  pDst->nCols = pSrc->nCols;
382,914,361✔
566
  pDst->version = pSrc->version;
382,906,153✔
567
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
382,924,007✔
568
  if (pDst->pSchema == NULL) {
382,824,912✔
569
    return terrno;
×
570
  }
571
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
382,847,170✔
572
  return TSDB_CODE_SUCCESS;
382,916,626✔
573
}
574

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

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

603
  return TSDB_CODE_SUCCESS;
83,826✔
604
}
605

606
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
382,877,665✔
607
  if (pSchema) {
382,877,665✔
608
    taosMemoryFreeClear(pSchema->pSchema);
382,888,737✔
609
  }
610
}
382,877,262✔
611

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

625
void metaCloneEntryFree(SMetaEntry **ppEntry) {
226,960,306✔
626
  if (ppEntry == NULL || *ppEntry == NULL) {
226,960,306✔
627
    return;
89,976✔
628
  }
629

630
  taosMemoryFreeClear((*ppEntry)->name);
226,877,332✔
631

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

637
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
226,835,485✔
638
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
186,443,338✔
639
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
186,432,026✔
640
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
186,436,350✔
641
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
128,155✔
642
    }
643
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
40,427,846✔
644
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
30,428,425✔
645
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
30,429,100✔
646
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
9,998,346✔
647
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
9,998,346✔
648
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
9,998,346✔
649
  } else {
650
    return;
×
651
  }
652
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
226,864,363✔
653
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
226,846,446✔
654
  metaCloneColRefFree(&(*ppEntry)->colRef);
226,854,733✔
655

656
  taosMemoryFreeClear(*ppEntry);
226,840,329✔
657
  return;
226,862,999✔
658
}
659

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

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

667
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
226,888,505✔
668
  if (NULL == *ppEntry) {
226,849,387✔
669
    return terrno;
×
670
  }
671

672
  (*ppEntry)->version = pEntry->version;
226,859,575✔
673
  (*ppEntry)->type = pEntry->type;
226,864,528✔
674
  (*ppEntry)->uid = pEntry->uid;
226,875,763✔
675

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

680
  if (pEntry->name) {
226,879,951✔
681
    (*ppEntry)->name = tstrdup(pEntry->name);
226,882,132✔
682
    if (NULL == (*ppEntry)->name) {
226,878,002✔
683
      code = terrno;
×
684
      metaCloneEntryFree(ppEntry);
×
685
      return code;
×
686
    }
687
  }
688

689
  if (pEntry->type == TSDB_SUPER_TABLE) {
226,867,384✔
690
    (*ppEntry)->flags = pEntry->flags;
186,443,493✔
691

692
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
186,449,835✔
693
    if (code) {
186,451,050✔
694
      metaCloneEntryFree(ppEntry);
×
695
      return code;
×
696
    }
697

698
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
186,451,050✔
699
    if (code) {
186,465,462✔
700
      metaCloneEntryFree(ppEntry);
×
701
      return code;
×
702
    }
703
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
186,465,462✔
704
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
83,826✔
705
      if (code) {
83,826✔
706
        metaCloneEntryFree(ppEntry);
×
707
        return code;
×
708
      }
709
    }
710
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
186,465,784✔
711
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
186,460,520✔
712
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
40,428,546✔
713
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
30,430,200✔
714
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
30,430,200✔
715
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
30,430,200✔
716

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

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

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

751
    // comment
752
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
9,998,346✔
753
    if (pEntry->ntbEntry.commentLen > 0) {
9,998,346✔
754
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
14,534✔
755
      if (NULL == (*ppEntry)->ntbEntry.comment) {
14,534✔
756
        code = terrno;
×
757
        metaCloneEntryFree(ppEntry);
×
758
        return code;
×
759
      }
760
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
14,534✔
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,895,394✔
767
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
1,405,550✔
768
    if (code) {
1,396,750✔
769
      metaCloneEntryFree(ppEntry);
×
770
      return code;
×
771
    }
772
  } else {
773
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
225,464,340✔
774
    if (code) {
225,465,669✔
775
      metaCloneEntryFree(ppEntry);
×
776
      return code;
×
777
    }
778
  }
779
  int32_t numOfExtSchema = metaGetEntryRowSchemaNum(pEntry);
226,862,419✔
780
  if (pEntry->pExtSchemas && numOfExtSchema > 0) {
226,873,017✔
781
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(numOfExtSchema, sizeof(SExtSchema));
11,541,474✔
782
    if (!(*ppEntry)->pExtSchemas) {
11,540,349✔
783
      code = terrno;
×
784
      metaCloneEntryFree(ppEntry);
×
785
      return code;
×
786
    }
787
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * numOfExtSchema);
11,533,786✔
788
  }
789

790
  return code;
226,870,831✔
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