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

taosdata / TDengine / #3631

07 Mar 2025 03:18PM UTC coverage: 60.671% (-3.0%) from 63.629%
#3631

push

travis-ci

web-flow
Merge pull request #30074 from taosdata/ciup30

ci: update ci workflow to fix path issue

141481 of 300084 branches covered (47.15%)

Branch coverage included in aggregate %.

223132 of 300884 relevant lines covered (74.16%)

7878557.0 hits per line

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

68.73
/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

18
int meteEncodeColCmprEntry(SEncoder *pCoder, const SMetaEntry *pME) {
359,561✔
19
  const SColCmprWrapper *pw = &pME->colCmpr;
359,561✔
20
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
719,122!
21
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
719,122!
22
  uDebug("encode cols:%d", pw->nCols);
359,561✔
23

24
  for (int32_t i = 0; i < pw->nCols; i++) {
5,502,797✔
25
    SColCmpr *p = &pw->pColCmpr[i];
5,143,274✔
26
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
10,286,548!
27
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
10,286,548!
28
  }
29
  return 0;
359,523✔
30
}
31
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
4,191,164✔
32
  SColCmprWrapper *pWrapper = &pME->colCmpr;
4,191,164✔
33
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
8,383,513!
34
  if (pWrapper->nCols == 0) {
4,192,349!
35
    return 0;
×
36
  }
37

38
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
8,385,156!
39
  uDebug("dencode cols:%d", pWrapper->nCols);
4,192,807✔
40
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
4,192,878✔
41
  if (pWrapper->pColCmpr == NULL) {
4,195,216!
42
    return terrno;
×
43
  }
44

45
  for (int i = 0; i < pWrapper->nCols; i++) {
72,360,835✔
46
    SColCmpr *p = &pWrapper->pColCmpr[i];
68,167,174✔
47
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
136,332,962!
48
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
136,331,407!
49
  }
50
  return 0;
4,193,661✔
51
}
52
static FORCE_INLINE int32_t metatInitDefaultSColCmprWrapper(SDecoder *pDecoder, SColCmprWrapper *pCmpr,
53
                                                            SSchemaWrapper *pSchema) {
54
  pCmpr->nCols = pSchema->nCols;
×
55
  if ((pCmpr->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pCmpr->nCols * sizeof(SColCmpr))) == NULL) {
20!
56
    return terrno;
×
57
  }
58

59
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
179!
60
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
159✔
61
    SSchema  *pColSchema = &pSchema->pSchema[i];
159✔
62
    pColCmpr->id = pColSchema->colId;
159✔
63
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
159✔
64
  }
65
  return 0;
20✔
66
}
67

68
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
165,947✔
69
  if (pSrc->nCols > 0) {
165,947✔
70
    pDst->nCols = pSrc->nCols;
160,064✔
71
    pDst->version = pSrc->version;
160,064✔
72
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
160,064!
73
    if (NULL == pDst->pColCmpr) {
160,119!
74
      return terrno;
×
75
    }
76
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
160,119✔
77
  }
78
  return 0;
166,002✔
79
}
80

81
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
165,985✔
82
  if (pCmpr) {
165,985!
83
    taosMemoryFreeClear(pCmpr->pColCmpr);
165,994!
84
  }
85
}
166,010✔
86

87
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
368,980✔
88
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
368,980✔
89
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
739,146!
90
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
739,146!
91
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
739,146!
92

93
  if (pME->type > 0) {
369,573✔
94
    if (pME->name == NULL) {
359,836!
95
      return TSDB_CODE_INVALID_PARA;
×
96
    }
97

98
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
719,672!
99

100
    if (pME->type == TSDB_SUPER_TABLE) {
359,836✔
101
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
114,642!
102
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
114,642!
103
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
114,642!
104
      if (TABLE_IS_ROLLUP(pME->flags)) {
57,321✔
105
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
13!
106
      }
107
    } else if (pME->type == TSDB_CHILD_TABLE) {
302,515✔
108
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
550,920!
109
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
550,920!
110
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
550,920!
111
      if (pME->ctbEntry.commentLen > 0) {
275,460✔
112
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
140!
113
      }
114
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
550,920!
115
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
275,460!
116
    } else if (pME->type == TSDB_NORMAL_TABLE) {
27,055✔
117
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
53,856!
118
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
53,856!
119
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
53,856!
120
      if (pME->ntbEntry.commentLen > 0) {
26,928✔
121
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
148!
122
      }
123
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
53,856!
124
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
53,856!
125
    } else if (pME->type == TSDB_TSMA_TABLE) {
127✔
126
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
50!
127
    } else {
128
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
77!
129
      return TSDB_CODE_INVALID_PARA;
×
130
    }
131
    TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
359,743!
132
  }
133

134
  tEndEncode(pCoder);
369,232✔
135
  return 0;
369,264✔
136
}
137

138
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
6,525,616✔
139
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
6,525,616!
140
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
13,061,476!
141
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
13,056,151!
142
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
13,050,813!
143

144
  if (headerOnly) {
6,524,069✔
145
    tEndDecode(pCoder);
12,074✔
146
    return 0;
12,074✔
147
  }
148

149
  if (pME->type > 0) {
6,511,995✔
150
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
13,020,507!
151

152
    if (pME->type == TSDB_SUPER_TABLE) {
6,511,307✔
153
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
7,200,643!
154
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
7,188,629!
155
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
7,186,361!
156
      if (TABLE_IS_ROLLUP(pME->flags)) {
3,597,600✔
157
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
260!
158
      }
159
    } else if (pME->type == TSDB_CHILD_TABLE) {
2,910,532✔
160
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
4,641,567!
161
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
4,640,726!
162
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
4,639,550!
163
      if (pME->ctbEntry.commentLen > 0) {
2,319,449✔
164
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
290!
165
      }
166
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
4,639,158!
167
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
2,319,709!
168
    } else if (pME->type == TSDB_NORMAL_TABLE) {
589,590!
169
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
1,181,175!
170
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
1,181,097!
171
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
1,180,935!
172
      if (pME->ntbEntry.commentLen > 0) {
590,398✔
173
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
346!
174
      }
175
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
1,180,803!
176
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
1,179,202!
177
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
178
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
2✔
179
      if (!pME->smaEntry.tsma) {
2!
180
        return terrno;
×
181
      }
182
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
2!
183
    } else {
184
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
185
      return TSDB_CODE_INVALID_PARA;
×
186
    }
187
    if (pME->type == TSDB_SUPER_TABLE) {
6,511,002✔
188
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
3,601,024!
189
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
3,601,036!
190

191
        if (pME->colCmpr.nCols == 0) {
3,602,897!
192
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
193
        }
194
      } else {
195
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
8!
196
        TABLE_SET_COL_COMPRESSED(pME->flags);
20✔
197
      }
198
    } else if (pME->type == TSDB_NORMAL_TABLE) {
2,909,978✔
199
      if (!tDecodeIsEnd(pCoder)) {
590,641!
200
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
590,699✔
201
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
590,702✔
202
        if (pME->colCmpr.nCols == 0) {
590,395!
203
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
204
        }
205
      } else {
206
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
207
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
208
      }
209
      TABLE_SET_COL_COMPRESSED(pME->flags);
590,395✔
210
    }
211
  }
212

213
  tEndDecode(pCoder);
6,515,444✔
214
  return 0;
6,510,199✔
215
}
216

217
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
6,514,179✔
218

219
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
317,824✔
220
  if (pSrc == NULL || pDst == NULL) {
317,824!
221
    return TSDB_CODE_INVALID_PARA;
×
222
  }
223

224
  pDst->nCols = pSrc->nCols;
317,861✔
225
  pDst->version = pSrc->version;
317,861✔
226
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
317,861!
227
  if (pDst->pSchema == NULL) {
317,871!
228
    return terrno;
×
229
  }
230
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
317,871✔
231
  return TSDB_CODE_SUCCESS;
317,871✔
232
}
233

234
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
317,864✔
235
  if (pSchema) {
317,864!
236
    taosMemoryFreeClear(pSchema->pSchema);
317,881!
237
  }
238
}
317,872✔
239

240
void metaCloneEntryFree(SMetaEntry **ppEntry) {
165,986✔
241
  if (ppEntry == NULL || *ppEntry == NULL) {
165,986!
242
    return;
×
243
  }
244

245
  taosMemoryFreeClear((*ppEntry)->name);
166,002!
246

247
  if ((*ppEntry)->type < 0) {
166,012!
248
    taosMemoryFreeClear(*ppEntry);
×
249
    return;
×
250
  }
251

252
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
166,012✔
253
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
157,827✔
254
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
157,827✔
255
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type) {
8,185✔
256
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
5,891!
257
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
5,891!
258
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type) {
2,294✔
259
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
2,281✔
260
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
2,281!
261
  } else {
262
    return;
13✔
263
  }
264
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
166,011✔
265

266
  taosMemoryFreeClear(*ppEntry);
166,008!
267
  return;
166,029✔
268
}
269

270
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
165,920✔
271
  int32_t code = TSDB_CODE_SUCCESS;
165,920✔
272

273
  if (NULL == pEntry || NULL == ppEntry) {
165,920!
274
    return TSDB_CODE_INVALID_PARA;
×
275
  }
276

277
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
165,935!
278
  if (NULL == *ppEntry) {
166,015!
279
    return terrno;
×
280
  }
281

282
  (*ppEntry)->version = pEntry->version;
166,015✔
283
  (*ppEntry)->type = pEntry->type;
166,015✔
284
  (*ppEntry)->uid = pEntry->uid;
166,015✔
285

286
  if (pEntry->type < 0) {
166,015!
287
    return TSDB_CODE_SUCCESS;
×
288
  }
289

290
  if (pEntry->name) {
166,015!
291
    (*ppEntry)->name = tstrdup(pEntry->name);
166,018✔
292
    if (NULL == (*ppEntry)->name) {
165,985!
293
      code = terrno;
×
294
      metaCloneEntryFree(ppEntry);
×
295
      return code;
×
296
    }
297
  }
298

299
  if (pEntry->type == TSDB_SUPER_TABLE) {
165,991✔
300
    (*ppEntry)->flags = pEntry->flags;
157,817✔
301

302
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
157,817✔
303
    if (code) {
157,799!
304
      metaCloneEntryFree(ppEntry);
×
305
      return code;
×
306
    }
307

308
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
157,799✔
309
    if (code) {
157,790!
310
      metaCloneEntryFree(ppEntry);
×
311
      return code;
×
312
    }
313
  } else if (pEntry->type == TSDB_CHILD_TABLE) {
8,174✔
314
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
5,893✔
315
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
5,893✔
316
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
5,893✔
317

318
    // comment
319
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
5,893✔
320
    if (pEntry->ctbEntry.commentLen > 0) {
5,893✔
321
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
40!
322
      if (NULL == (*ppEntry)->ctbEntry.comment) {
40!
323
        code = terrno;
×
324
        metaCloneEntryFree(ppEntry);
×
325
        return code;
×
326
      }
327
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
40✔
328
    }
329

330
    // tags
331
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
5,893✔
332
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
5,893!
333
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
5,896!
334
      code = terrno;
×
335
      metaCloneEntryFree(ppEntry);
×
336
      return code;
×
337
    }
338
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
5,896✔
339
  } else if (pEntry->type == TSDB_NORMAL_TABLE) {
2,281!
340
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
2,281✔
341
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
2,281✔
342
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
2,281✔
343

344
    // schema
345
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
2,281✔
346
    if (code) {
2,281!
347
      metaCloneEntryFree(ppEntry);
×
348
      return code;
×
349
    }
350

351
    // comment
352
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
2,281✔
353
    if (pEntry->ntbEntry.commentLen > 0) {
2,281✔
354
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
46!
355
      if (NULL == (*ppEntry)->ntbEntry.comment) {
46!
356
        code = terrno;
×
357
        metaCloneEntryFree(ppEntry);
×
358
        return code;
×
359
      }
360
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
46✔
361
    }
362
  } else {
363
    return TSDB_CODE_INVALID_PARA;
×
364
  }
365

366
  code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
165,967✔
367
  if (code) {
166,010✔
368
    metaCloneEntryFree(ppEntry);
8✔
369
    return code;
×
370
  }
371

372
  return code;
166,002✔
373
}
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