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

taosdata / TDengine / #4948

04 Feb 2026 09:05AM UTC coverage: 66.866% (-0.006%) from 66.872%
#4948

push

travis-ci

web-flow
enh(keeper): password information desensitization processing (#34458)

Close https://project.feishu.cn/taosdata_td/feature/detail/6600039687

Commits:

* feat: add String method to TDengineRestful for safe string representation

* feat: replace hardcoded credentials with test utility functions in tests

* feat: update test workflows to use environment variables for credentials

* test: fix failed test case

* chore: setup tmate

* feat: streamline test execution by setting environment variables for credentials

* feat: enhance test utility functions to return default values if environment variables are not set

205522 of 307364 relevant lines covered (66.87%)

124991068.44 hits per line

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

80.9
/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) {
1,010,997,134✔
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;
27,861,434✔
26
    }
27
  }
28
  return false;
982,055,267✔
29
}
30

31
static int32_t metaEncodeExtSchema(SEncoder* pCoder, const SMetaEntry* pME) {
185,274,196✔
32
  if (pME->pExtSchemas) {
185,274,196✔
33
    const SSchemaWrapper *pSchWrapper = NULL;
12,275,788✔
34
    bool                  hasTypeMods = false;
12,275,788✔
35
    if (pME->type == TSDB_SUPER_TABLE) {
12,275,788✔
36
      pSchWrapper = &pME->stbEntry.schemaRow;
12,177,972✔
37
    } else if (pME->type == TSDB_NORMAL_TABLE) {
90,070✔
38
      pSchWrapper = &pME->ntbEntry.schemaRow;
90,070✔
39
    } else {
40
      return 0;
×
41
    }
42
    hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
12,267,706✔
43

44
    for (int32_t i = 0; i < pSchWrapper->nCols && hasTypeMods; ++i) {
994,705,249✔
45
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->pExtSchemas[i].typeMod));
1,964,858,722✔
46
    }
47
  }
48
  return 0;
185,269,517✔
49
}
50

51
int meteEncodeColRefEntry(SEncoder *pCoder, const SMetaEntry *pME) {
1,244,582✔
52
  const SColRefWrapper *pw = &pME->colRef;
1,244,582✔
53
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
2,489,164✔
54
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
2,489,164✔
55
  uTrace("encode cols:%d", pw->nCols);
1,244,582✔
56

57
  for (int32_t i = 0; i < pw->nCols; i++) {
413,780,818✔
58
    SColRef *p = &pw->pColRef[i];
412,536,236✔
59
    TAOS_CHECK_RETURN(tEncodeI8(pCoder, p->hasRef));
825,072,472✔
60
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
825,072,472✔
61
    if (p->hasRef) {
412,536,236✔
62
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refDbName));
547,227,000✔
63
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refTableName));
547,227,000✔
64
      TAOS_CHECK_RETURN(tEncodeCStr(pCoder, p->refColName));
547,227,000✔
65
    }
66
  }
67
  return 0;
1,244,582✔
68
}
69

70
static int32_t metaDecodeExtSchemas(SDecoder* pDecoder, SMetaEntry* pME) {
956,232,576✔
71
  bool hasExtSchema = false;
956,232,576✔
72
  SSchemaWrapper* pSchWrapper = NULL;
956,232,576✔
73
  if (pME->type == TSDB_SUPER_TABLE) {
956,232,576✔
74
    pSchWrapper = &pME->stbEntry.schemaRow;
723,311,535✔
75
  } else if (pME->type == TSDB_NORMAL_TABLE) {
233,011,472✔
76
    pSchWrapper = &pME->ntbEntry.schemaRow;
233,105,733✔
77
  } else {
78
    return 0;
×
79
  }
80

81
  hasExtSchema = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
956,495,682✔
82
  if (hasExtSchema && pSchWrapper->nCols > 0) {
956,504,451✔
83
    pME->pExtSchemas = (SExtSchema*)tDecoderMalloc(pDecoder, sizeof(SExtSchema) * pSchWrapper->nCols);
37,024,000✔
84
    if (pME->pExtSchemas == NULL) {
18,509,887✔
85
      return terrno;
×
86
    }
87

88
    for (int32_t i = 0; i < pSchWrapper->nCols && hasExtSchema; i++) {
1,213,792,382✔
89
      TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pME->pExtSchemas[i].typeMod));
2,147,483,647✔
90
    }
91
  } else {
92
    pME->pExtSchemas = NULL;
937,994,223✔
93
  }
94

95
  return 0;
956,507,627✔
96
}
97

98
SExtSchema* metaGetSExtSchema(const SMetaEntry *pME) {
42,504,248✔
99
  const SSchemaWrapper *pSchWrapper = NULL;
42,504,248✔
100
  bool                  hasTypeMods = false;
42,504,248✔
101
  if (pME->type == TSDB_SUPER_TABLE) {
42,504,248✔
102
    pSchWrapper = &pME->stbEntry.schemaRow;
31,123,268✔
103
  } else if (pME->type == TSDB_NORMAL_TABLE) {
11,401,436✔
104
    pSchWrapper = &pME->ntbEntry.schemaRow;
11,403,716✔
105
  } else {
106
    return NULL;
×
107
  }
108
  hasTypeMods = schemasHasTypeMod(pSchWrapper->pSchema, pSchWrapper->nCols);
42,526,987✔
109

110
  if (hasTypeMods) {
42,498,025✔
111
    SExtSchema *ret = taosMemoryMalloc(sizeof(SExtSchema) * pSchWrapper->nCols);
38,624✔
112
    if (ret != NULL) {
38,624✔
113
      memcpy(ret, pME->pExtSchemas, pSchWrapper->nCols * sizeof(SExtSchema));
38,624✔
114
    }
115
    return ret;
38,624✔
116
  }
117
  return NULL;
42,459,401✔
118
}
119

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

127
  const SRSmaParam *pParam = &pME->stbEntry.rsmaParam;
25,884✔
128
  const SSchema    *pSchema = pME->stbEntry.schemaRow.pSchema;
25,884✔
129
  int32_t           nCols = pME->stbEntry.schemaRow.nCols;
25,884✔
130

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

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

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

150
  func_id_t *pFuncIds = (*rsmaSchema)->funcIds;
25,884✔
151
  int32_t    i = 0, j = 0;
25,884✔
152
  for (i = 0; i < nCols; ++i) {
199,163✔
153
    while (j < pParam->nFuncs) {
314,922✔
154
      if (pParam->funcColIds[j] == pSchema[i].colId) {
302,699✔
155
        pFuncIds[i] = pParam->funcIds[j];
141,643✔
156
        break;
141,643✔
157
      }
158
      if (pParam->funcColIds[j] > pSchema[i].colId) {
161,056✔
159
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
31,636✔
160
        break;
31,636✔
161
      }
162
      ++j;
129,420✔
163
    }
164
    if (j >= pParam->nFuncs) {
185,502✔
165
      for (; i < nCols; ++i) {
24,446✔
166
        pFuncIds[i] = 36;  // use last if not specified, fmGetFuncId("last") = 36
12,223✔
167
      }
168
      break;
12,223✔
169
    }
170
  }
171
  pFuncIds[0] = 0;  // Primary TS column has no function
25,884✔
172

173
  return 0;
25,884✔
174
}
175

176
int meteDecodeColRefEntry(SDecoder *pDecoder, SMetaEntry *pME) {
32,031,805✔
177
  SColRefWrapper *pWrapper = &pME->colRef;
32,031,805✔
178
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
64,071,217✔
179
  if (pWrapper->nCols == 0) {
32,035,601✔
180
    return 0;
×
181
  }
182

183
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
64,067,758✔
184
  uDebug("decode cols:%d", pWrapper->nCols);
32,035,815✔
185
  pWrapper->pColRef = (SColRef *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColRef));
64,068,812✔
186
  if (pWrapper->pColRef == NULL) {
32,031,634✔
187
    return terrno;
×
188
  }
189

190
  for (int i = 0; i < pWrapper->nCols; i++) {
743,684,156✔
191
    SColRef *p = &pWrapper->pColRef[i];
711,616,546✔
192
    TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t *)&p->hasRef));
1,423,306,977✔
193
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
1,423,344,747✔
194
    if (p->hasRef) {
711,687,130✔
195
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refDbName));
394,308,684✔
196
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refTableName));
394,316,173✔
197
      TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, p->refColName));
394,315,357✔
198
    }
199
  }
200
  return 0;
32,041,251✔
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) {
646,804✔
220
  if (pSrc->nCols > 0) {
646,804✔
221
    pDst->nCols = pSrc->nCols;
646,804✔
222
    pDst->version = pSrc->version;
646,804✔
223
    pDst->pColRef = (SColRef*)taosMemoryCalloc(pSrc->nCols, sizeof(SColRef));
646,804✔
224
    if (NULL == pDst->pColRef) {
646,804✔
225
      return terrno;
×
226
    }
227
    memcpy(pDst->pColRef, pSrc->pColRef, pSrc->nCols * sizeof(SColRef));
646,804✔
228
  }
229
  return 0;
646,804✔
230
}
231

232
static int32_t metaEncodeComprEntryImpl(SEncoder *pCoder, SColCmprWrapper *pw) {
44,750,016✔
233
  int32_t code = 0;
44,750,016✔
234
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
89,483,867✔
235
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
89,499,426✔
236
  uTrace("encode cols:%d", pw->nCols);
44,765,575✔
237

238
  for (int32_t i = 0; i < pw->nCols; i++) {
2,147,483,647✔
239
    SColCmpr *p = &pw->pColCmpr[i];
2,147,483,647✔
240
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
2,147,483,647✔
241
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
2,147,483,647✔
242
  }
243
  return code;
44,829,888✔
244
}
245
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
44,552,649✔
246
  const SColCmprWrapper *pw = &pME->colCmpr;
44,552,649✔
247
  return metaEncodeComprEntryImpl(pCoder, (SColCmprWrapper *)pw);
44,615,647✔
248
}
249
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
956,318,650✔
250
  SColCmprWrapper *pWrapper = &pME->colCmpr;
956,318,650✔
251
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
1,912,934,796✔
252
  if (pWrapper->nCols == 0) {
956,358,010✔
253
    return 0;
×
254
  }
255

256
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
1,912,533,874✔
257
  uDebug("dencode cols:%d", pWrapper->nCols);
956,269,048✔
258
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
1,912,690,076✔
259
  if (pWrapper->pColCmpr == NULL) {
956,454,057✔
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;
956,832,096✔
269
}
270
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
271
                                                            SSchemaWrapper *pSchema) {
272
  pCmpr->nCols = pSchema->nCols;
216,546✔
273

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

280
  if (pCmpr->pColCmpr == NULL) {
216,546✔
281
    return terrno;
×
282
  }
283

284
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1,092,438✔
285
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
875,892✔
286
    SSchema  *pColSchema = &pSchema->pSchema[i];
875,892✔
287
    pColCmpr->id = pColSchema->colId;
875,892✔
288
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
875,892✔
289
  }
290
  return 0;
216,546✔
291
}
292

293
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
173,783,344✔
294
  if (pSrc->nCols > 0) {
173,783,344✔
295
    pDst->nCols = pSrc->nCols;
157,572,819✔
296
    pDst->version = pSrc->version;
157,573,046✔
297
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
157,549,516✔
298
    if (NULL == pDst->pColCmpr) {
157,535,565✔
299
      return terrno;
×
300
    }
301
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
157,529,136✔
302
  }
303
  return 0;
173,786,783✔
304
}
305

306
static void metaCloneColRefFree(SColRefWrapper *pColRef) {
174,413,661✔
307
  if (pColRef) {
174,413,661✔
308
    taosMemoryFreeClear(pColRef->pColRef);
174,425,221✔
309
  }
310
}
174,427,000✔
311

312
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
174,415,101✔
313
  if (pCmpr) {
174,415,101✔
314
    taosMemoryFreeClear(pCmpr->pColCmpr);
174,433,267✔
315
  }
316
}
174,429,181✔
317

318
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
189,741,726✔
319
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
189,741,726✔
320
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
379,522,339✔
321
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
379,511,378✔
322
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
379,525,762✔
323

324
  if (pME->type > 0) {
189,762,859✔
325
    if (pME->name == NULL) {
185,289,674✔
326
      return TSDB_CODE_INVALID_PARA;
×
327
    }
328

329
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
370,578,618✔
330

331
    if (pME->type == TSDB_SUPER_TABLE) {
185,302,646✔
332
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
49,864,097✔
333
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
49,916,058✔
334
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
49,912,206✔
335
      if (TABLE_IS_ROLLUP(pME->flags)) {
24,922,871✔
336
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
74,057✔
337
      }
338
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
160,335,399✔
339
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
279,628,503✔
340
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
279,646,554✔
341
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
279,655,730✔
342
      if (pME->ctbEntry.commentLen > 0) {
139,825,262✔
343
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
27,852✔
344
      }
345
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
279,637,494✔
346
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
139,818,174✔
347
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
20,532,558✔
348
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
41,065,116✔
349
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
41,065,116✔
350
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
41,065,116✔
351
      if (pME->ntbEntry.commentLen > 0) {
20,532,558✔
352
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
38,300✔
353
      }
354
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
41,065,116✔
355
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
41,065,116✔
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) {
185,286,527✔
363
      TAOS_CHECK_RETURN(meteEncodeColRefEntry(pCoder, pME));
1,359,552✔
364
    } else {
365
      if (pME->type == TSDB_SUPER_TABLE && TABLE_IS_COL_COMPRESSED(pME->flags)) {
183,950,985✔
366
        TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
24,961,474✔
367
      } else if (pME->type == TSDB_NORMAL_TABLE) {
159,115,733✔
368
        if (pME->colCmpr.nCols != 0) {
19,864,594✔
369
          TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
19,648,048✔
370
        } else {
371
          metaWarn("meta/entry: failed to get compress cols, type:%d", pME->type);
216,546✔
372
          SColCmprWrapper colCmprs = {0};
216,546✔
373
          int32_t code = metatInitDefaultSColCmprWrapper(NULL, &colCmprs, (SSchemaWrapper *)&pME->ntbEntry.schemaRow);
216,546✔
374
          if (code != 0) {
216,546✔
375
            taosMemoryFree(colCmprs.pColCmpr);
×
376
            TAOS_CHECK_RETURN(code);
×
377
          }
378
          code = metaEncodeComprEntryImpl(pCoder, &colCmprs);
216,546✔
379
          taosMemoryFree(colCmprs.pColCmpr);
216,546✔
380
          TAOS_CHECK_RETURN(code);
216,546✔
381
        }
382
      }
383
    }
384
    TAOS_CHECK_RETURN(metaEncodeExtSchema(pCoder, pME));
185,319,212✔
385
  }
386
  if (pME->type == TSDB_SUPER_TABLE) {
189,737,066✔
387
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->stbEntry.keep));
49,853,590✔
388
    TAOS_CHECK_RETURN(tEncodeI64v(pCoder, pME->stbEntry.ownerId));
49,798,826✔
389
  } else if (pME->type == TSDB_NORMAL_TABLE) {
164,788,407✔
390
    TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.ownerId));
39,729,188✔
391
  }
392

393
  tEndEncode(pCoder);
189,709,692✔
394
  return 0;
189,723,799✔
395
}
396

397
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
1,679,331,942✔
398
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
1,679,331,942✔
399
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
2,147,483,647✔
400
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
2,147,483,647✔
401
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
2,147,483,647✔
402

403
  if (headerOnly) {
1,680,047,927✔
404
    tEndDecode(pCoder);
311,514✔
405
    return 0;
311,514✔
406
  }
407

408
  if (pME->type > 0) {
1,679,736,413✔
409
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
2,147,483,647✔
410

411
    if (pME->type == TSDB_SUPER_TABLE) {
1,679,586,797✔
412
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
1,446,997,920✔
413
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
1,447,166,548✔
414
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
1,446,932,104✔
415
      if (TABLE_IS_ROLLUP(pME->flags)) {
723,392,086✔
416
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
273,220✔
417
      }
418
    } else if (pME->type == TSDB_CHILD_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
955,732,660✔
419
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
1,431,965,773✔
420
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
1,432,011,724✔
421
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
1,431,813,250✔
422
      if (pME->ctbEntry.commentLen > 0) {
715,805,687✔
423
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
48,214✔
424
      }
425
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
1,431,844,297✔
426
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
716,005,544✔
427
    } else if (pME->type == TSDB_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
239,981,223✔
428
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
480,103,111✔
429
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
480,181,212✔
430
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
480,100,458✔
431
      if (pME->ntbEntry.commentLen > 0) {
240,003,111✔
432
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
70,804✔
433
      }
434
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
479,984,071✔
435
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
480,110,842✔
436
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
437
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
438
      if (!pME->smaEntry.tsma) {
×
439
        return terrno;
×
440
      }
441
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
442
    } else {
443
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
444
      return TSDB_CODE_INVALID_PARA;
×
445
    }
446
    if (pME->type == TSDB_SUPER_TABLE) {
1,679,376,538✔
447
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
723,546,420✔
448
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
723,502,669✔
449

450
        if (pME->colCmpr.nCols == 0) {
723,408,555✔
451
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
452
        }
453
      } else {
454
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
455
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
456
      }
457
    } else if (pME->type == TSDB_NORMAL_TABLE) {
955,658,985✔
458
      if (!tDecodeIsEnd(pCoder)) {
233,082,076✔
459
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
233,115,454✔
460
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
233,115,454✔
461
        if (pME->colCmpr.nCols == 0) {
233,108,104✔
462
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
463
        }
464
      } else {
465
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
466
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
467
      }
468
      TABLE_SET_COL_COMPRESSED(pME->flags);
233,115,081✔
469
    } else if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE || pME->type == TSDB_VIRTUAL_CHILD_TABLE) {
722,623,161✔
470
      if (!tDecodeIsEnd(pCoder)) {
32,039,092✔
471
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
32,040,704✔
472
        TAOS_CHECK_RETURN(meteDecodeColRefEntry(pCoder, pME));
32,041,422✔
473
      } else {
474
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
475
        if (pME->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
476
           TAOS_CHECK_RETURN(metatInitDefaultSColRefWrapper(pCoder, &pME->colRef, &pME->ntbEntry.schemaRow));
×
477
        }
478
      }
479
    }
480
    if (!tDecodeIsEnd(pCoder)) {
1,679,337,076✔
481
      TAOS_CHECK_RETURN(metaDecodeExtSchemas(pCoder, pME));
956,555,029✔
482
    } else {
483
      pME->pExtSchemas = NULL;
722,782,047✔
484
    }
485
  }
486
  if (pME->type == TSDB_SUPER_TABLE) {
1,679,198,171✔
487
    if (!tDecodeIsEnd(pCoder)) {
723,209,442✔
488
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->stbEntry.keep));
1,446,541,035✔
489
    }
490
    if (!tDecodeIsEnd(pCoder)) {
723,318,277✔
491
      TAOS_CHECK_RETURN(tDecodeI64v(pCoder, &pME->stbEntry.ownerId));
1,446,629,445✔
492
    }
493
  } else if (pME->type == TSDB_NORMAL_TABLE) {
955,622,922✔
494
    if (!tDecodeIsEnd(pCoder)) {
233,115,986✔
495
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.ownerId));
466,243,720✔
496
    }
497
  }
498

499

500
  tEndDecode(pCoder);
1,678,870,745✔
501
  return 0;
1,678,935,300✔
502
}
503

504
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
1,679,164,589✔
505

506
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
307,558,591✔
507
  if (pSrc == NULL || pDst == NULL) {
307,558,591✔
508
    return TSDB_CODE_INVALID_PARA;
×
509
  }
510

511
  pDst->nCols = pSrc->nCols;
307,580,142✔
512
  pDst->version = pSrc->version;
307,572,227✔
513
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
307,571,021✔
514
  if (pDst->pSchema == NULL) {
307,485,408✔
515
    return terrno;
×
516
  }
517
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
307,500,781✔
518
  return TSDB_CODE_SUCCESS;
307,593,012✔
519
}
520

521
static int32_t metaCloneRsmaParam(const SRSmaParam *pSrc, SRSmaParam *pDst) {
42,421✔
522
  if (pSrc == NULL || pDst == NULL) {
42,421✔
523
    return TSDB_CODE_INVALID_PARA;
×
524
  }
525
  memcpy(pDst, pSrc, sizeof(SRSmaParam));
42,421✔
526
  pDst->name = tstrdup(pSrc->name);
42,421✔
527
  if (pDst->name == NULL) {
42,421✔
528
    return terrno;
×
529
  }
530
  if (pSrc->nFuncs > 0) {
42,421✔
531
    pDst->nFuncs = pSrc->nFuncs;
42,421✔
532
    pDst->funcColIds = (col_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(col_id_t));
42,421✔
533
    if (pDst->funcColIds == NULL) {
42,421✔
534
      return terrno;
×
535
    }
536
    memcpy(pDst->funcColIds, pSrc->funcColIds, pSrc->nFuncs * sizeof(col_id_t));
42,421✔
537

538
    pDst->funcIds = (func_id_t *)taosMemoryMalloc(pSrc->nFuncs * sizeof(func_id_t));
42,421✔
539
    if (pDst->funcIds == NULL) {
42,421✔
540
      return terrno;
×
541
    }
542
    memcpy(pDst->funcIds, pSrc->funcIds, pSrc->nFuncs * sizeof(func_id_t));
42,421✔
543
  } else {
544
    pDst->nFuncs = 0;
×
545
    pDst->funcColIds = NULL;
×
546
    pDst->funcIds = NULL;
×
547
  }
548

549
  return TSDB_CODE_SUCCESS;
42,421✔
550
}
551

552
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
307,519,131✔
553
  if (pSchema) {
307,519,131✔
554
    taosMemoryFreeClear(pSchema->pSchema);
307,537,273✔
555
  }
556
}
307,550,892✔
557

558
/**
559
 * @param type 0x01 free name
560
 */
561
void metaFreeRsmaParam(SRSmaParam *pParam, int8_t type) {
63,991✔
562
  if (pParam) {
63,991✔
563
    if ((type & 0x01)) {
63,991✔
564
      taosMemoryFreeClear(pParam->name);
63,991✔
565
    }
566
    taosMemoryFreeClear(pParam->funcColIds);
63,991✔
567
    taosMemoryFreeClear(pParam->funcIds);
63,272✔
568
  }
569
}
64,710✔
570

571
void metaCloneEntryFree(SMetaEntry **ppEntry) {
174,491,527✔
572
  if (ppEntry == NULL || *ppEntry == NULL) {
174,491,527✔
573
    return;
72,575✔
574
  }
575

576
  taosMemoryFreeClear((*ppEntry)->name);
174,427,519✔
577

578
  if ((*ppEntry)->type < 0) {
174,413,093✔
579
    taosMemoryFreeClear(*ppEntry);
×
580
    return;
×
581
  }
582

583
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
174,416,928✔
584
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
149,572,984✔
585
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
149,564,877✔
586
    if (TABLE_IS_ROLLUP((*ppEntry)->flags)) {
149,559,921✔
587
      metaFreeRsmaParam(&(*ppEntry)->stbEntry.rsmaParam, 1);
63,991✔
588
    }
589
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_CHILD_TABLE == (*ppEntry)->type) {
24,848,686✔
590
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
16,431,178✔
591
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
16,431,178✔
592
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type || TSDB_VIRTUAL_NORMAL_TABLE == (*ppEntry)->type) {
8,419,275✔
593
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
8,419,275✔
594
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
8,419,275✔
595
  } else {
596
    return;
×
597
  }
598
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
174,427,400✔
599
  taosMemoryFreeClear((*ppEntry)->pExtSchemas);
174,392,090✔
600
  metaCloneColRefFree(&(*ppEntry)->colRef);
174,377,840✔
601

602
  taosMemoryFreeClear(*ppEntry);
174,378,875✔
603
  return;
174,387,790✔
604
}
605

606
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
174,411,320✔
607
  int32_t code = TSDB_CODE_SUCCESS;
174,411,320✔
608

609
  if (NULL == pEntry || NULL == ppEntry) {
174,411,320✔
610
    return TSDB_CODE_INVALID_PARA;
×
611
  }
612

613
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
174,425,552✔
614
  if (NULL == *ppEntry) {
174,365,172✔
615
    return terrno;
×
616
  }
617

618
  (*ppEntry)->version = pEntry->version;
174,397,446✔
619
  (*ppEntry)->type = pEntry->type;
174,420,734✔
620
  (*ppEntry)->uid = pEntry->uid;
174,421,709✔
621

622
  if (pEntry->type < 0) {
174,412,177✔
623
    return TSDB_CODE_SUCCESS;
×
624
  }
625

626
  if (pEntry->name) {
174,409,412✔
627
    (*ppEntry)->name = tstrdup(pEntry->name);
174,433,630✔
628
    if (NULL == (*ppEntry)->name) {
174,435,305✔
629
      code = terrno;
×
630
      metaCloneEntryFree(ppEntry);
×
631
      return code;
×
632
    }
633
  }
634

635
  if (pEntry->type == TSDB_SUPER_TABLE) {
174,438,836✔
636
    (*ppEntry)->flags = pEntry->flags;
149,590,464✔
637

638
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
149,577,117✔
639
    if (code) {
149,580,487✔
640
      metaCloneEntryFree(ppEntry);
×
641
      return code;
×
642
    }
643

644
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
149,580,487✔
645
    if (code) {
149,595,237✔
646
      metaCloneEntryFree(ppEntry);
×
647
      return code;
×
648
    }
649
    if (TABLE_IS_ROLLUP(pEntry->flags)) {
149,595,237✔
650
      code = metaCloneRsmaParam(&pEntry->stbEntry.rsmaParam, &(*ppEntry)->stbEntry.rsmaParam);
42,421✔
651
      if (code) {
42,421✔
652
        metaCloneEntryFree(ppEntry);
×
653
        return code;
×
654
      }
655
    }
656
    (*ppEntry)->stbEntry.keep = pEntry->stbEntry.keep;
149,585,021✔
657
    (*ppEntry)->stbEntry.ownerId = pEntry->stbEntry.ownerId;
149,586,982✔
658
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
24,849,863✔
659
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
16,430,293✔
660
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
16,430,588✔
661
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
16,430,883✔
662

663
    // comment
664
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
16,430,588✔
665
    if (pEntry->ctbEntry.commentLen > 0) {
16,430,883✔
666
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
8,226✔
667
      if (NULL == (*ppEntry)->ctbEntry.comment) {
8,226✔
668
        code = terrno;
×
669
        metaCloneEntryFree(ppEntry);
×
670
        return code;
×
671
      }
672
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
8,226✔
673
    }
674

675
    // tags
676
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
16,430,588✔
677
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
16,430,293✔
678
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
16,430,293✔
679
      code = terrno;
×
680
      metaCloneEntryFree(ppEntry);
×
681
      return code;
×
682
    }
683
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
16,430,883✔
684
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
8,419,275✔
685
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
8,419,275✔
686
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
8,419,275✔
687
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
8,419,275✔
688
    (*ppEntry)->ntbEntry.ownerId = pEntry->ntbEntry.ownerId;
8,419,275✔
689

690
    // schema
691
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
8,419,275✔
692
    if (code) {
8,419,275✔
693
      metaCloneEntryFree(ppEntry);
×
694
      return code;
×
695
    }
696

697
    // comment
698
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
8,419,275✔
699
    if (pEntry->ntbEntry.commentLen > 0) {
8,419,275✔
700
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
11,870✔
701
      if (NULL == (*ppEntry)->ntbEntry.comment) {
11,870✔
702
        code = terrno;
×
703
        metaCloneEntryFree(ppEntry);
×
704
        return code;
×
705
      }
706
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
11,870✔
707
    }
708
  } else {
709
    return TSDB_CODE_INVALID_PARA;
×
710
  }
711

712
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
174,425,479✔
713
    code = metaCloneColRef(&pEntry->colRef, &(*ppEntry)->colRef);
652,999✔
714
    if (code) {
646,804✔
715
      metaCloneEntryFree(ppEntry);
×
716
      return code;
×
717
    }
718
  } else {
719
    code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
173,786,420✔
720
    if (code) {
173,776,253✔
721
      metaCloneEntryFree(ppEntry);
×
722
      return code;
×
723
    }
724
  }
725
  if (pEntry->pExtSchemas && pEntry->colCmpr.nCols > 0) {
174,423,057✔
726
    (*ppEntry)->pExtSchemas = taosMemoryCalloc(pEntry->colCmpr.nCols, sizeof(SExtSchema));
9,737,405✔
727
    if (!(*ppEntry)->pExtSchemas) {
9,734,909✔
728
      code = terrno;
×
729
      metaCloneEntryFree(ppEntry);
×
730
      return code;
×
731
    }
732
    memcpy((*ppEntry)->pExtSchemas, pEntry->pExtSchemas, sizeof(SExtSchema) * pEntry->colCmpr.nCols);
9,730,981✔
733
  }
734

735
  return code;
174,421,454✔
736
}
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