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

taosdata / TDengine / #3643

11 Mar 2025 12:59PM UTC coverage: 48.693% (+2.4%) from 46.316%
#3643

push

travis-ci

web-flow
Merge pull request #30118 from taosdata/wl30

udpate ci workflow

109528 of 296098 branches covered (36.99%)

Branch coverage included in aggregate %.

178197 of 294804 relevant lines covered (60.45%)

3723000.77 hits per line

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

60.91
/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) {
120,523✔
19
  const SColCmprWrapper *pw = &pME->colCmpr;
120,523✔
20
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
241,046!
21
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
241,046!
22
  uDebug("encode cols:%d", pw->nCols);
120,523✔
23

24
  for (int32_t i = 0; i < pw->nCols; i++) {
874,336✔
25
    SColCmpr *p = &pw->pColCmpr[i];
753,631✔
26
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
1,507,262!
27
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
1,507,262!
28
  }
29
  return 0;
120,705✔
30
}
31
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
2,655,438✔
32
  SColCmprWrapper *pWrapper = &pME->colCmpr;
2,655,438✔
33
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
5,310,512!
34
  if (pWrapper->nCols == 0) {
2,655,074!
35
    return 0;
×
36
  }
37

38
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
5,311,825!
39
  uDebug("dencode cols:%d", pWrapper->nCols);
2,656,751✔
40
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
2,656,881✔
41
  if (pWrapper->pColCmpr == NULL) {
2,657,050!
42
    return terrno;
×
43
  }
44

45
  for (int i = 0; i < pWrapper->nCols; i++) {
56,416,930✔
46
    SColCmpr *p = &pWrapper->pColCmpr[i];
53,760,777✔
47
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
107,563,351!
48
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
107,562,454!
49
  }
50
  return 0;
2,656,153✔
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) {
×
56
    return terrno;
×
57
  }
58

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

68
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
51,745✔
69
  if (pSrc->nCols > 0) {
51,745✔
70
    pDst->nCols = pSrc->nCols;
49,272✔
71
    pDst->version = pSrc->version;
49,272✔
72
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
49,272!
73
    if (NULL == pDst->pColCmpr) {
49,296!
74
      return terrno;
×
75
    }
76
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
49,296✔
77
  }
78
  return 0;
51,769✔
79
}
80

81
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
51,779✔
82
  if (pCmpr) {
51,779!
83
    taosMemoryFreeClear(pCmpr->pColCmpr);
51,783!
84
  }
85
}
51,784✔
86

87
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
125,786✔
88
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
125,786✔
89
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
251,984!
90
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
251,984!
91
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
251,984!
92

93
  if (pME->type > 0) {
125,992✔
94
    if (pME->name == NULL) {
120,739!
95
      return TSDB_CODE_INVALID_PARA;
×
96
    }
97

98
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
241,478!
99

100
    if (pME->type == TSDB_SUPER_TABLE) {
120,739✔
101
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
35,888!
102
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
35,888!
103
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
35,888!
104
      if (TABLE_IS_ROLLUP(pME->flags)) {
17,944!
105
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
106
      }
107
    } else if (pME->type == TSDB_CHILD_TABLE) {
102,795✔
108
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
166,166!
109
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
166,166!
110
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
166,166!
111
      if (pME->ctbEntry.commentLen > 0) {
83,083!
112
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
×
113
      }
114
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
166,166!
115
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
83,083!
116
    } else if (pME->type == TSDB_NORMAL_TABLE) {
19,712✔
117
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
39,344!
118
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
39,344!
119
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
39,344!
120
      if (pME->ntbEntry.commentLen > 0) {
19,672✔
121
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
88!
122
      }
123
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
39,344!
124
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
39,344!
125
    } else if (pME->type == TSDB_TSMA_TABLE) {
40✔
126
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
10!
127
    } else {
128
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
30!
129
      return TSDB_CODE_INVALID_PARA;
×
130
    }
131
    TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
120,688!
132
  }
133

134
  tEndEncode(pCoder);
125,921✔
135
  return 0;
125,932✔
136
}
137

138
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
4,280,164✔
139
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
4,280,164!
140
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
8,561,044!
141
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
8,558,739!
142
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
8,555,379!
143

144
  if (headerOnly) {
4,276,263✔
145
    tEndDecode(pCoder);
1,176✔
146
    return 0;
1,176✔
147
  }
148

149
  if (pME->type > 0) {
4,275,087!
150
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
8,551,290!
151

152
    if (pME->type == TSDB_SUPER_TABLE) {
4,275,570✔
153
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
4,486,747!
154
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
4,484,093!
155
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
4,484,210!
156
      if (TABLE_IS_ROLLUP(pME->flags)) {
2,243,236!
157
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
×
158
      }
159
    } else if (pME->type == TSDB_CHILD_TABLE) {
2,031,942✔
160
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
3,242,931!
161
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
3,242,274!
162
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
3,242,116!
163
      if (pME->ctbEntry.commentLen > 0) {
1,621,048!
164
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
×
165
      }
166
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
3,241,951!
167
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
1,620,903!
168
    } else if (pME->type == TSDB_NORMAL_TABLE) {
410,217!
169
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
820,730!
170
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
820,523!
171
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
820,295!
172
      if (pME->ntbEntry.commentLen > 0) {
410,071✔
173
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
146!
174
      }
175
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
819,921!
176
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
818,817!
177
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
178
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
×
179
      if (!pME->smaEntry.tsma) {
×
180
        return terrno;
×
181
      }
182
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
×
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) {
4,276,354✔
188
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
2,245,493!
189
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,245,843!
190

191
        if (pME->colCmpr.nCols == 0) {
2,246,387!
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));
×
196
        TABLE_SET_COL_COMPRESSED(pME->flags);
×
197
      }
198
    } else if (pME->type == TSDB_NORMAL_TABLE) {
2,030,861✔
199
      if (!tDecodeIsEnd(pCoder)) {
410,177!
200
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
410,180✔
201
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
410,186✔
202
        if (pME->colCmpr.nCols == 0) {
410,070!
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);
410,070✔
210
    }
211
  }
212

213
  tEndDecode(pCoder);
4,276,508✔
214
  return 0;
4,275,282✔
215
}
216

217
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
4,279,658✔
218

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

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

234
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
96,741✔
235
  if (pSchema) {
96,741!
236
    taosMemoryFreeClear(pSchema->pSchema);
96,745!
237
  }
238
}
96,757✔
239

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

245
  taosMemoryFreeClear((*ppEntry)->name);
51,785!
246

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

252
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
51,791✔
253
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
47,484✔
254
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
47,485✔
255
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type) {
4,307✔
256
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
2,490!
257
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
2,490!
258
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type) {
1,817✔
259
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
1,816✔
260
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
1,816!
261
  } else {
262
    return;
1✔
263
  }
264
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
51,795✔
265

266
  taosMemoryFreeClear(*ppEntry);
51,785!
267
  return;
51,795✔
268
}
269

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

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

277
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
51,746!
278
  if (NULL == *ppEntry) {
51,792!
279
    return terrno;
×
280
  }
281

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

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

290
  if (pEntry->name) {
51,792!
291
    (*ppEntry)->name = tstrdup(pEntry->name);
51,794✔
292
    if (NULL == (*ppEntry)->name) {
51,762!
293
      code = terrno;
×
294
      metaCloneEntryFree(ppEntry);
×
295
      return code;
×
296
    }
297
  }
298

299
  if (pEntry->type == TSDB_SUPER_TABLE) {
51,777✔
300
    (*ppEntry)->flags = pEntry->flags;
47,471✔
301

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

308
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
47,436✔
309
    if (code) {
47,454!
310
      metaCloneEntryFree(ppEntry);
×
311
      return code;
×
312
    }
313
  } else if (pEntry->type == TSDB_CHILD_TABLE) {
4,306✔
314
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
2,491✔
315
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
2,491✔
316
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
2,491✔
317

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

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

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

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

366
  code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
51,761✔
367
  if (code) {
51,752!
368
    metaCloneEntryFree(ppEntry);
×
369
    return code;
×
370
  }
371

372
  return code;
51,768✔
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