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

taosdata / TDengine / #4829

30 Oct 2025 09:25AM UTC coverage: 49.734% (-11.3%) from 61.071%
#4829

push

travis-ci

web-flow
Merge pull request #33435 from taosdata/3.0

merge 3.0

123072 of 323930 branches covered (37.99%)

Branch coverage included in aggregate %.

7 of 25 new or added lines in 3 files covered. (28.0%)

35232 existing lines in 327 files now uncovered.

172062 of 269495 relevant lines covered (63.85%)

70709785.06 hits per line

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

54.4
/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
static bool schemasHasTypeMod(const SSchema *pSchema, int32_t nCols) {
136,343,735✔
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;
8,984,276✔
26
    }
27
  }
28
  return false;
126,474,184✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
41,285,464✔
32
  if (pME->pExtSchemas) {
41,285,464✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
3,127,481✔
34
    bool                  hasTypeMods = false;
3,127,481✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
3,127,481✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
3,106,729✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
20,534!
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
20,534✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
3,127,808✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
210,301,700✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
414,352,522!
46
    }
47
  }
48
  return 0;
41,302,393✔
49
}
50

51
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
512,818✔
52
  const SColRefWrapper *pw = &pME->colRef;
512,818✔
53
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
1,025,636!
54
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
1,025,636!
55
  uTrace("encode cols:%d", pw->nCols);
512,818!
56

57
  for (int32_t i = 0; i < pw->nCols; i++) {
5,478,138✔
58
    SColRef *p = &pw->pColRef[i];
4,965,320✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
9,930,640!
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
9,930,640!
61
    if (p->hasRef) {
4,965,320!
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
5,158,212!
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
5,158,212!
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
5,158,212!
65
    }
66
  }
67
  return 0;
512,818✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
130,860,704✔
71
  bool hasExtSchema = false;
130,860,704✔
72
  SSchemaWrapper* pSchWrapper = NULL;
130,860,704✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
130,860,704✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
130,515,806✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
339,073!
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
339,073✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
130,865,607✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
130,880,955!
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
12,967,840!
84
    if (pME->pExtSchemas == NULL) {
6,483,064!
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
270,882,962✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
528,795,914!
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
124,395,748✔
93
  }
94

95
  return 0;
130,898,504✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
2,364,113✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
2,364,113✔
100
  bool                  hasTypeMods = false;
2,364,113✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
2,364,113✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
655,630✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
1,708,996!
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
1,709,338✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
2,365,127✔
109

110
  if (hasTypeMods) {
2,364,455!
UNCOV
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
×
UNCOV
112
    if (ret != NULL) {
×
UNCOV
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
×
114
    }
UNCOV
115
    return ret;
×
116
  }
117
  return NULL;
2,364,455✔
118
}
119

UNCOV
120
int32_t metaGetRsmaSchema(const SMetaEntry *pME, SSchemaRsma **rsmaSchema) {
×
UNCOV
121
  if (!rsmaSchema) return 0;
×
UNCOV
122
  if ((pME->type != TSDB_SUPER_TABLE) || !TABLE_IS_ROLLUP(pME->flags)) {  // only support super table
×
123
    *rsmaSchema = NULL;
×
124
    return 0;
×
125
  }
126

UNCOV
127
  const SRSmaParam *pParam = &pME->stbEntry.rsmaParam;
×
UNCOV
128
  const SSchema    *pSchema = pME->stbEntry.schemaRow.pSchema;
×
UNCOV
129
  int32_t           nCols = pME->stbEntry.schemaRow.nCols;
×
130

UNCOV
131
  *rsmaSchema = (SSchemaRsma *)taosMemoryMalloc(sizeof(SSchemaRsma));
×
UNCOV
132
  if (*rsmaSchema == NULL) {
×
133
    return terrno;
×
134
  }
135

UNCOV
136
  (*rsmaSchema)->funcIds = taosMemoryMalloc(sizeof(func_id_t) * nCols);
×
UNCOV
137
  if ((*rsmaSchema)->funcIds == NULL) {
×
138
    taosMemoryFree(*rsmaSchema);
×
139
    *rsmaSchema = NULL;
×
140
    return terrno;
×
141
  }
142

UNCOV
143
  (void)snprintf((*rsmaSchema)->tbName, TSDB_TABLE_NAME_LEN, "%s", pME->name);
×
UNCOV
144
  (*rsmaSchema)->tbUid = pME->uid;
×
UNCOV
145
  (*rsmaSchema)->tbType = pME->type;
×
UNCOV
146
  (*rsmaSchema)->interval[0] = pParam->interval[0];
×
UNCOV
147
  (*rsmaSchema)->interval[1] = pParam->interval[1];
×
UNCOV
148
  (*rsmaSchema)->nFuncs = nCols;
×
149

UNCOV
150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
×
UNCOV
151
  int32_t    i = 0, j = 0;
×
UNCOV
152
  for (i = 0; i < nCols; ++i) {
×
UNCOV
153
    while (j < pParam->nFuncs) {
×
UNCOV
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
×
UNCOV
155
        pFuncIds[i] = pParam->funcIds[j];
×
UNCOV
156
        break;
×
157
      }
UNCOV
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
×
UNCOV
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
×
UNCOV
160
        break;
×
161
      }
UNCOV
162
      ++j;
×
163
    }
UNCOV
164
    if (j >= pParam->nFuncs) {
×
UNCOV
165
      for (; i < nCols; ++i) {
×
UNCOV
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
×
167
      }
UNCOV
168
      break;
×
169
    }
170
  }
UNCOV
171
  pFuncIds[0] = 0;  // Primary TS column has no function
×
172

UNCOV
173
  return 0;
×
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
6,718,044✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
6,718,044✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
13,436,088!
179
  if (pWrapper->nCols == 0) {
6,718,044!
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
13,435,194!
184
  uDebug("decode cols:%d", pWrapper->nCols);
6,717,150✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
13,434,903!
186
  if (pWrapper->pColRef == NULL) {
6,717,753!
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
108,726,354✔
191
    SColRef *p = &pWrapper->pColRef[i];
101,994,223✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
204,018,659!
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
204,023,111!
194
    if (p->hasRef) {
102,012,839!
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
58,708,417!
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
58,706,739!
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
58,707,304!
198
    }
199
  }
200
  return 0;
6,718,044✔
201
}
202

203
static FORCE_INLINE int32_t metatInitDefaultSColRefWrapper(SDecoder *pDecoder, SColRefWrapper *pRef,
204
                                                            SSchemaWrapper *pSchema) {
205
  pRef->nCols = pSchema->nCols;
×
206
  if ((pRef->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pRef->nCols * sizeof(SColRef))) == NULL) {
×
207
    return terrno;
×
208
  }
209

210
  for (int32_t i = 0; i < pRef->nCols; i++) {
×
211
    SColRef  *pColRef = &pRef->pColRef[i];
×
212
    SSchema  *pColSchema = &pSchema->pSchema[i];
×
213
    pColRef->id = pColSchema->colId;
×
214
    pColRef->hasRef = false;
×
215
  }
216
  return 0;
×
217
}
218

219
static int32_t metaCloneColRef(const SColRefWrapper*pSrc, SColRefWrapper *pDst) {
279,571✔
220
  if (pSrc->nCols > 0) {
279,571!
221
    pDst->nCols = pSrc->nCols;
279,571✔
222
    pDst->version = pSrc->version;
279,571✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
279,571!
224
    if (NULL == pDst->pColRef) {
279,571!
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
279,571!
228
  }
229
  return 0;
279,571✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
7,443,529✔
233
  int32_t code = 0;
7,443,529✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
14,890,815!
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
14,894,576!
236
  uTrace("encode cols:%d", pw->nCols);
7,447,290✔
237

238
  for (int32_t i = 0; i < pw->nCols; i++) {
268,581,068✔
239
    SColCmpr *p = &pw->pColCmpr[i];
261,102,958✔
240
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
522,268,342!
241
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
522,267,806!
242
  }
243
  return code;
7,450,118✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
7,415,797✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
7,415,797✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
7,433,062✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
192,545,892✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
192,545,892✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
385,129,192!
252
  if (pWrapper->nCols == 0) {
192,537,325!
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
385,117,030!
257
  uDebug("dencode cols:%d", pWrapper->nCols);
192,578,697✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
385,090,194✔
259
  if (pWrapper->pColCmpr == NULL) {
192,570,181!
260
    return terrno;
×
261
  }
262

263
  for (int i = 0; i < pWrapper->nCols; i++) {
2,147,483,647✔
264
    SColCmpr *p = &pWrapper->pColCmpr[i];
2,147,483,647✔
265
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
2,147,483,647!
266
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
2,147,483,647!
267
  }
268
  return 0;
192,642,071✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
24,978✔
273

274
  if (pDecoder == NULL) {
24,978!
275
    pCmpr->pColCmpr = taosMemoryCalloc(1, pCmpr->nCols * sizeof(SColCmpr));
24,978!
276
  } else {
277
    pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr));
×
278
  }
279

280
  if (pCmpr->pColCmpr == NULL) {
24,978!
281
    return terrno;
×
282
  }
283

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
140,330!
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
115,352✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
115,352✔
287
    pColCmpr->id = pColSchema->colId;
115,352✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
115,352✔
289
  }
290
  return 0;
24,978✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
39,878,113✔
294
  if (pSrc->nCols > 0) {
39,878,113✔
295
    pDst->nCols = pSrc->nCols;
36,127,177✔
296
    pDst->version = pSrc->version;
36,127,716✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
36,126,710!
298
    if (NULL == pDst->pColCmpr) {
36,124,649!
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
36,125,065!
302
  }
303
  return 0;
39,877,927✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
40,153,594✔
307
  if (pColRef) {
40,153,594!
308
    taosMemoryFreeClear(pColRef->pColRef);
40,154,436!
309
  }
310
}
40,155,379✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
40,153,320✔
313
  if (pCmpr) {
40,153,320!
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
40,155,703!
315
  }
316
}
40,152,266✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
42,300,868✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
42,300,868!
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
84,612,253!
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
84,607,525!
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
84,598,356!
323

324
  if (pME->type > 0) {
42,298,961✔
325
    if (pME->name == NULL) {
41,293,746!
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
82,587,259!
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
41,298,463✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
11,415,001!
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
11,421,926!
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
11,426,198!
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
5,709,785!
UNCOV
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
35,582,998✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
66,974,334!
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
66,975,811!
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
66,975,729!
342
      if (pME->ctbEntry.commentLen > 0) {
33,487,767✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
2,576!
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
66,970,907!
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
33,484,293!
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,101,082!
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
4,202,164!
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
4,202,164!
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
4,202,164!
351
      if (pME->ntbEntry.commentLen > 0) {
2,101,082✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
1,104!
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
4,202,164!
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
4,202,164!
356
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
357
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
×
358
    } else {
359
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
360
      return TSDB_CODE_INVALID_PARA;
×
361
    }
362
    if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
41,296,565✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
525,465!
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
40,778,888✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
5,709,119✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
35,076,684✔
368
        if (pME->colCmpr.nCols != 0) {
1,741,368✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
1,716,390!
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
24,978!
372
          SColCmprWrapper colCmprs = {0};
24,978✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
24,978!
374
          if (code != 0) {
24,978!
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
24,978✔
379
          taosMemoryFree(colCmprs.pColCmpr);
24,978!
380
          TAOS_CHECK_RETURN(code);
24,978!
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
41,296,621!
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
42,300,566✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
11,417,861!
388
  }
389

390
  tEndEncode(pCoder);
42,297,459✔
391
  return 0;
42,290,669✔
392
}
393

394
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
258,265,531✔
395
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
258,265,531!
396
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
516,578,635!
397
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
516,601,208!
398
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
516,681,145!
399

400
  if (headerOnly) {
258,343,414✔
401
    tEndDecode(pCoder);
3,264✔
402
    return 0;
3,264✔
403
  }
404

405
  if (pME->type > 0) {
258,340,150✔
406
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
516,587,077!
407

408
    if (pME->type == TSDB_SUPER_TABLE) {
258,299,448✔
409
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
261,098,648!
410
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
261,134,036!
411
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
261,111,857!
412
      if (TABLE_IS_ROLLUP(pME->flags)) {
130,549,666!
UNCOV
413
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
414
      }
415
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
127,711,258✔
416
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
127,104,926!
417
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
127,097,509!
418
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
127,084,512!
419
      if (pME->ctbEntry.commentLen > 0) {
63,534,954✔
420
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
5,336!
421
      }
422
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
127,088,649!
423
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
63,549,120!
424
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
64,195,780!
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
128,419,813!
426
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
128,429,740!
427
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
128,411,202!
428
      if (pME->ntbEntry.commentLen > 0) {
64,197,371✔
429
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
3,680!
430
      }
431
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
128,391,815!
432
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
128,424,118!
433
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
434
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
435
      if (!pME->smaEntry.tsma) {
×
436
        return terrno;
×
437
      }
438
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
439
    } else {
440
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
441
      return TSDB_CODE_INVALID_PARA;
×
442
    }
443
    if (pME->type == TSDB_SUPER_TABLE) {
258,315,796✔
444
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
130,563,806!
445
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
130,548,426!
446

447
        if (pME->colCmpr.nCols == 0) {
130,543,436!
448
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
449
        }
450
      } else {
451
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
452
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
453
      }
454
    } else if (pME->type == TSDB_NORMAL_TABLE) {
127,724,762✔
455
      if (!tDecodeIsEnd(pCoder)) {
62,036,527!
456
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
62,044,248✔
457
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
62,044,248!
458
        if (pME->colCmpr.nCols == 0) {
62,039,876!
459
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
460
        }
461
      } else {
462
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
463
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
464
      }
465
      TABLE_SET_COL_COMPRESSED(pME->flags);
62,046,368✔
466
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
65,690,769✔
467
      if (!tDecodeIsEnd(pCoder)) {
6,718,044!
468
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
6,718,044✔
469
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
6,718,044!
470
      } else {
471
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
472
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
473
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
474
        }
475
      }
476
    }
477
    if (!tDecodeIsEnd(pCoder)) {
258,265,875✔
478
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
130,878,019!
479
    } else {
480
      pME->pExtSchemas = NULL;
127,387,856✔
481
    }
482
  }
483
  if (pME->type == TSDB_SUPER_TABLE) {
258,297,551✔
484
    if (!tDecodeIsEnd(pCoder)) {
130,511,216✔
485
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
261,040,267!
486
    }
487
  }
488

489

490
  tEndDecode(pCoder);
258,290,903✔
491
  return 0;
258,244,719✔
492
}
493

494
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
258,271,195✔
495

496
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
72,354,217✔
497
  if (pSrc == NULL || pDst == NULL) {
72,354,217!
498
    return TSDB_CODE_INVALID_PARA;
×
499
  }
500

501
  pDst->nCols = pSrc->nCols;
72,357,117✔
502
  pDst->version = pSrc->version;
72,355,200✔
503
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
72,354,530!
504
  if (pDst->pSchema == NULL) {
72,340,572!
505
    return terrno;
×
506
  }
507
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
72,343,219!
508
  return TSDB_CODE_SUCCESS;
72,354,323✔
509
}
510

UNCOV
511
static int32_t metaCloneRsmaParam(const SRSmaParam *pSrc, SRSmaParam *pDst) {
×
UNCOV
512
  if (pSrc == NULL || pDst == NULL) {
×
513
    return TSDB_CODE_INVALID_PARA;
×
514
  }
UNCOV
515
  memcpy(pDst, pSrc, sizeof(SRSmaParam));
×
UNCOV
516
  pDst->name = tstrdup(pSrc->name);
×
UNCOV
517
  if (pDst->name == NULL) {
×
518
    return terrno;
×
519
  }
UNCOV
520
  if (pSrc->nFuncs > 0) {
×
UNCOV
521
    pDst->nFuncs = pSrc->nFuncs;
×
UNCOV
522
    pDst->funcColIds = (col_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(col_id_t));
×
UNCOV
523
    if (pDst->funcColIds == NULL) {
×
524
      return terrno;
×
525
    }
UNCOV
526
    memcpy(pDst->funcColIds, pSrc->funcColIds, pSrc->nFuncs * sizeof(col_id_t));
×
527

UNCOV
528
    pDst->funcIds = (func_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(func_id_t));
×
UNCOV
529
    if (pDst->funcIds == NULL) {
×
530
      return terrno;
×
531
    }
UNCOV
532
    memcpy(pDst->funcIds, pSrc->funcIds, pSrc->nFuncs * sizeof(func_id_t));
×
533
  } else {
534
    pDst->nFuncs = 0;
×
535
    pDst->funcColIds = NULL;
×
536
    pDst->funcIds = NULL;
×
537
  }
538

UNCOV
539
  return TSDB_CODE_SUCCESS;
×
540
}
541

542
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
72,346,427✔
543
  if (pSchema) {
72,346,427!
544
    taosMemoryFreeClear(pSchema->pSchema);
72,349,150!
545
  }
546
}
72,347,098✔
547

548
/**
549
 * @param type 0x01 free name
550
 */
UNCOV
551
void metaFreeRsmaParam(SRSmaParam *pParam, int8_t type) {
×
UNCOV
552
  if (pParam) {
×
UNCOV
553
    if ((type & 0x01)) {
×
UNCOV
554
      taosMemoryFreeClear(pParam->name);
×
555
    }
UNCOV
556
    taosMemoryFreeClear(pParam->funcColIds);
×
UNCOV
557
    taosMemoryFreeClear(pParam->funcIds);
×
558
  }
UNCOV
559
}
×
560

561
void metaCloneEntryFree(SMetaEntry **ppEntry) {
40,197,352✔
562
  if (ppEntry == NULL || *ppEntry == NULL) {
40,197,352!
563
    return;
42,106✔
564
  }
565

566
  taosMemoryFreeClear((*ppEntry)->name);
40,155,839!
567

568
  if ((*ppEntry)->type < 0) {
40,154,901!
569
    taosMemoryFreeClear(*ppEntry);
×
570
    return;
×
571
  }
572

573
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
40,154,273✔
574
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
35,977,651✔
575
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
35,972,946✔
576
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
35,973,181!
UNCOV
577
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
×
578
    }
579
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
4,178,988✔
580
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
3,779,424!
581
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
3,779,424!
582
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
399,564!
583
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
399,564✔
584
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
399,564!
585
  } else {
586
    return;
×
587
  }
588
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
40,153,650✔
589
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
40,152,684!
590
  metaCloneColRefFree(&(*ppEntry)->colRef);
40,153,964✔
591

592
  taosMemoryFreeClear(*ppEntry);
40,151,930!
593
  return;
40,150,856✔
594
}
595

596
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
40,153,251✔
597
  int32_t code = TSDB_CODE_SUCCESS;
40,153,251✔
598

599
  if (NULL == pEntry || NULL == ppEntry) {
40,153,251!
600
    return TSDB_CODE_INVALID_PARA;
×
601
  }
602

603
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
40,156,526!
604
  if (NULL == *ppEntry) {
40,148,238!
605
    return terrno;
×
606
  }
607

608
  (*ppEntry)->version = pEntry->version;
40,150,944✔
609
  (*ppEntry)->type = pEntry->type;
40,155,125✔
610
  (*ppEntry)->uid = pEntry->uid;
40,155,637✔
611

612
  if (pEntry->type < 0) {
40,154,771!
613
    return TSDB_CODE_SUCCESS;
×
614
  }
615

616
  if (pEntry->name) {
40,152,723✔
617
    (*ppEntry)->name = tstrdup(pEntry->name);
40,155,568✔
618
    if (NULL == (*ppEntry)->name) {
40,157,281!
619
      code = terrno;
×
620
      metaCloneEntryFree(ppEntry);
×
621
      return code;
×
622
    }
623
  }
624

625
  if (pEntry->type == TSDB_SUPER_TABLE) {
40,159,447✔
626
    (*ppEntry)->flags = pEntry->flags;
35,977,322✔
627

628
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
35,974,951✔
629
    if (code) {
35,975,699!
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633

634
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
35,975,699✔
635
    if (code) {
35,979,321!
636
      metaCloneEntryFree(ppEntry);
×
637
      return code;
×
638
    }
639
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
35,979,321!
UNCOV
640
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
×
UNCOV
641
      if (code) {
×
642
        metaCloneEntryFree(ppEntry);
×
643
        return code;
×
644
      }
645
    }
646
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
35,978,822✔
647
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
4,178,988✔
648
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
3,779,424✔
649
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
3,779,424✔
650
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
3,779,424✔
651

652
    // comment
653
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
3,779,424✔
654
    if (pEntry->ctbEntry.commentLen > 0) {
3,779,424✔
655
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
736!
656
      if (NULL == (*ppEntry)->ctbEntry.comment) {
736!
657
        code = terrno;
×
658
        metaCloneEntryFree(ppEntry);
×
659
        return code;
×
660
      }
661
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
736!
662
    }
663

664
    // tags
665
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
3,779,424✔
666
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
3,779,424!
667
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
3,779,424!
668
      code = terrno;
×
669
      metaCloneEntryFree(ppEntry);
×
670
      return code;
×
671
    }
672
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
3,779,424!
673
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
399,564!
674
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
399,564✔
675
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
399,564✔
676
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
399,564✔
677

678
    // schema
679
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
399,564✔
680
    if (code) {
399,564!
681
      metaCloneEntryFree(ppEntry);
×
682
      return code;
×
683
    }
684

685
    // comment
686
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
399,564✔
687
    if (pEntry->ntbEntry.commentLen > 0) {
399,564✔
688
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
368!
689
      if (NULL == (*ppEntry)->ntbEntry.comment) {
368!
690
        code = terrno;
×
691
        metaCloneEntryFree(ppEntry);
×
692
        return code;
×
693
      }
694
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
368!
695
    }
696
  } else {
697
    return TSDB_CODE_INVALID_PARA;
×
698
  }
699

700
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
40,157,967✔
701
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
284,518✔
702
    if (code) {
279,571!
703
      metaCloneEntryFree(ppEntry);
×
704
      return code;
×
705
    }
706
  } else {
707
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
39,873,721✔
708
    if (code) {
39,878,072!
709
      metaCloneEntryFree(ppEntry);
×
710
      return code;
×
711
    }
712
  }
713
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
40,157,643!
714
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
2,611,066!
715
    if (!(*ppEntry)->pExtSchemas) {
2,611,233!
716
      code = terrno;
×
717
      metaCloneEntryFree(ppEntry);
×
718
      return code;
×
719
    }
720
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
2,611,427!
721
  }
722

723
  return code;
40,156,400✔
724
}
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