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

taosdata / TDengine / #3579

12 Jan 2025 03:09AM UTC coverage: 62.976% (-0.2%) from 63.183%
#3579

push

travis-ci

web-flow
Merge pull request #29551 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

139324 of 284527 branches covered (48.97%)

Branch coverage included in aggregate %.

34 of 50 new or added lines in 4 files covered. (68.0%)

1114 existing lines in 141 files now uncovered.

217258 of 281694 relevant lines covered (77.13%)

9262344.36 hits per line

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

66.61
/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) {
511,431✔
19
  const SColCmprWrapper *pw = &pME->colCmpr;
511,431✔
20
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
1,022,862!
21
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
1,022,862!
22
  uDebug("encode cols:%d", pw->nCols);
511,431✔
23

24
  for (int32_t i = 0; i < pw->nCols; i++) {
5,796,196✔
25
    SColCmpr *p = &pw->pColCmpr[i];
5,284,971✔
26
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
10,569,942!
27
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
10,569,942!
28
  }
29
  return 0;
511,225✔
30
}
31
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
4,077,552✔
32
  SColCmprWrapper *pWrapper = &pME->colCmpr;
4,077,552✔
33
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
8,155,008!
34
  if (pWrapper->nCols == 0) {
4,077,456!
35
    return 0;
×
36
  }
37

38
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
8,157,443!
39
  uDebug("dencode cols:%d", pWrapper->nCols);
4,079,987✔
40
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
4,080,102✔
41
  if (pWrapper->pColCmpr == NULL) {
4,083,487!
42
    return terrno;
×
43
  }
44

45
  for (int i = 0; i < pWrapper->nCols; i++) {
74,382,817✔
46
    SColCmpr *p = &pWrapper->pColCmpr[i];
70,317,456✔
47
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
140,643,869!
48
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
140,625,743!
49
  }
50
  return 0;
4,065,361✔
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) {
27!
56
    return terrno;
×
57
  }
58

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

68
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
239,171✔
69
  if (pSrc->nCols > 0) {
239,171✔
70
    pDst->nCols = pSrc->nCols;
233,154✔
71
    pDst->version = pSrc->version;
233,154✔
72
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
233,154!
73
    if (NULL == pDst->pColCmpr) {
233,208!
74
      return terrno;
×
75
    }
76
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
233,208✔
77
  }
78
  return 0;
239,225✔
79
}
80

81
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
239,204✔
82
  if (pCmpr) {
239,204!
83
    taosMemoryFreeClear(pCmpr->pColCmpr);
239,219!
84
  }
85
}
239,223✔
86

87
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
520,884✔
88
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
520,884✔
89
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,043,136!
90
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,043,136!
91
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,043,136!
92

93
  if (pME->type > 0) {
521,568✔
94
    if (pME->name == NULL) {
511,228!
95
      return TSDB_CODE_INVALID_PARA;
×
96
    }
97

98
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,022,456!
99

100
    if (pME->type == TSDB_SUPER_TABLE) {
511,228✔
101
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
125,354!
102
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
125,354!
103
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
125,354!
104
      if (TABLE_IS_ROLLUP(pME->flags)) {
62,677✔
105
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
13!
106
      }
107
    } else if (pME->type == TSDB_CHILD_TABLE) {
448,551✔
108
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
842,822!
109
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
842,822!
110
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
842,822!
111
      if (pME->ctbEntry.commentLen > 0) {
421,411✔
112
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
140!
113
      }
114
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
842,822!
115
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
421,411!
116
    } else if (pME->type == TSDB_NORMAL_TABLE) {
27,140!
117
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
55,108!
118
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
55,108!
119
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
55,108!
120
      if (pME->ntbEntry.commentLen > 0) {
27,554✔
121
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
140!
122
      }
123
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
55,108!
124
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
55,108!
UNCOV
125
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
126
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
54!
127
    } else {
UNCOV
128
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
×
129
      return TSDB_CODE_INVALID_PARA;
×
130
    }
131
    TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
511,690!
132
  }
133

134
  tEndEncode(pCoder);
521,644✔
135
  return 0;
521,219✔
136
}
137

138
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
6,785,631✔
139
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
6,785,631!
140
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
13,594,001!
141
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
13,588,359!
142
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
13,578,332!
143

144
  if (pME->type > 0) {
6,785,426!
145
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
13,570,339!
146

147
    if (pME->type == TSDB_SUPER_TABLE) {
6,784,451✔
148
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
7,045,873!
149
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
7,001,372!
150
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
6,993,837!
151
      if (TABLE_IS_ROLLUP(pME->flags)) {
3,514,669✔
152
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
267!
153
      }
154
    } else if (pME->type == TSDB_CHILD_TABLE) {
3,260,782✔
155
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
5,418,877!
156
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
5,417,436!
157
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
5,416,497!
158
      if (pME->ctbEntry.commentLen > 0) {
2,707,941✔
159
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
290!
160
      }
161
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
5,416,520!
162
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
2,708,579!
163
    } else if (pME->type == TSDB_NORMAL_TABLE) {
550,785!
164
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
1,108,026!
165
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
1,107,856!
166
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
1,107,679!
167
      if (pME->ntbEntry.commentLen > 0) {
553,768✔
168
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
332!
169
      }
170
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
1,107,301!
171
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
1,108,215!
172
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
173
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
3✔
174
      if (!pME->smaEntry.tsma) {
3!
175
        return terrno;
×
176
      }
177
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
3!
178
    } else {
179
      metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
×
180
      return TSDB_CODE_INVALID_PARA;
×
181
    }
182
    if (pME->type == TSDB_SUPER_TABLE) {
6,786,314✔
183
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
3,523,792!
184
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
3,524,495!
185

186
        if (pME->colCmpr.nCols == 0) {
3,527,644!
187
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
188
        }
189
      } else {
190
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->stbEntry.schemaRow));
×
191
        TABLE_SET_COL_COMPRESSED(pME->flags);
27✔
192
      }
193
    } else if (pME->type == TSDB_NORMAL_TABLE) {
3,262,522✔
194
      if (!tDecodeIsEnd(pCoder)) {
554,201!
195
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
554,213✔
196
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
554,217✔
197
        if (pME->colCmpr.nCols == 0) {
553,932!
198
          TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
199
        }
200
      } else {
201
        uDebug("set default type: %d, tableName:%s", pME->type, pME->name);
×
202
        TAOS_CHECK_RETURN(metatInitDefaultSColCmprWrapper(pCoder, &pME->colCmpr, &pME->ntbEntry.schemaRow));
×
203
      }
204
      TABLE_SET_COL_COMPRESSED(pME->flags);
553,932✔
205
    }
206
  }
207

208
  tEndDecode(pCoder);
6,789,462✔
209
  return 0;
6,785,936✔
210
}
211

212
static int32_t metaCloneSchema(const SSchemaWrapper *pSrc, SSchemaWrapper *pDst) {
463,974✔
213
  if (pSrc == NULL || pDst == NULL) {
463,974!
214
    return TSDB_CODE_INVALID_PARA;
×
215
  }
216

217
  pDst->nCols = pSrc->nCols;
464,024✔
218
  pDst->version = pSrc->version;
464,024✔
219
  pDst->pSchema = (SSchema *)taosMemoryMalloc(pSrc->nCols * sizeof(SSchema));
464,024!
220
  if (pDst->pSchema == NULL) {
464,037!
221
    return terrno;
×
222
  }
223
  memcpy(pDst->pSchema, pSrc->pSchema, pSrc->nCols * sizeof(SSchema));
464,037✔
224
  return TSDB_CODE_SUCCESS;
464,037✔
225
}
226

227
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
463,974✔
228
  if (pSchema) {
463,974!
229
    taosMemoryFreeClear(pSchema->pSchema);
463,994!
230
  }
231
}
464,042✔
232

233
void metaCloneEntryFree(SMetaEntry **ppEntry) {
239,192✔
234
  if (ppEntry == NULL || *ppEntry == NULL) {
239,192!
235
    return;
×
236
  }
237

238
  taosMemoryFreeClear((*ppEntry)->name);
239,215!
239

240
  if ((*ppEntry)->type < 0) {
239,219!
241
    taosMemoryFreeClear(*ppEntry);
×
242
    return;
×
243
  }
244

245
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
239,219✔
246
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
230,907✔
247
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
230,931✔
248
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type) {
8,312✔
249
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
6,050!
250
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
6,050!
251
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type) {
2,262!
252
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
2,263✔
253
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
2,263!
254
  } else {
UNCOV
255
    return;
×
256
  }
257
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
239,227✔
258

259
  taosMemoryFreeClear(*ppEntry);
239,223!
260
  return;
239,248✔
261
}
262

263
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry) {
239,145✔
264
  int32_t code = TSDB_CODE_SUCCESS;
239,145✔
265

266
  if (NULL == pEntry || NULL == ppEntry) {
239,145!
267
    return TSDB_CODE_INVALID_PARA;
×
268
  }
269

270
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
239,175!
271
  if (NULL == *ppEntry) {
239,253!
272
    return terrno;
×
273
  }
274

275
  (*ppEntry)->version = pEntry->version;
239,253✔
276
  (*ppEntry)->type = pEntry->type;
239,253✔
277
  (*ppEntry)->uid = pEntry->uid;
239,253✔
278

279
  if (pEntry->type < 0) {
239,253!
280
    return TSDB_CODE_SUCCESS;
×
281
  }
282

283
  if (pEntry->name) {
239,253✔
284
    (*ppEntry)->name = tstrdup(pEntry->name);
239,244✔
285
    if (NULL == (*ppEntry)->name) {
239,193!
286
      code = terrno;
×
287
      metaCloneEntryFree(ppEntry);
×
288
      return code;
×
289
    }
290
  }
291

292
  if (pEntry->type == TSDB_SUPER_TABLE) {
239,233✔
293
    (*ppEntry)->flags = pEntry->flags;
230,917✔
294

295
    code = metaCloneSchema(&pEntry->stbEntry.schemaRow, &(*ppEntry)->stbEntry.schemaRow);
230,917✔
296
    if (code) {
230,880!
297
      metaCloneEntryFree(ppEntry);
×
298
      return code;
×
299
    }
300

301
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
230,880✔
302
    if (code) {
230,901!
303
      metaCloneEntryFree(ppEntry);
×
304
      return code;
×
305
    }
306
  } else if (pEntry->type == TSDB_CHILD_TABLE) {
8,316✔
307
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
6,053✔
308
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
6,053✔
309
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
6,053✔
310

311
    // comment
312
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
6,053✔
313
    if (pEntry->ctbEntry.commentLen > 0) {
6,053✔
314
      (*ppEntry)->ctbEntry.comment = taosMemoryMalloc(pEntry->ctbEntry.commentLen + 1);
40!
315
      if (NULL == (*ppEntry)->ctbEntry.comment) {
40!
316
        code = terrno;
×
317
        metaCloneEntryFree(ppEntry);
×
318
        return code;
×
319
      }
320
      memcpy((*ppEntry)->ctbEntry.comment, pEntry->ctbEntry.comment, pEntry->ctbEntry.commentLen + 1);
40✔
321
    }
322

323
    // tags
324
    STag *pTags = (STag *)pEntry->ctbEntry.pTags;
6,053✔
325
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
6,053!
326
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
6,051!
327
      code = terrno;
×
328
      metaCloneEntryFree(ppEntry);
×
329
      return code;
×
330
    }
331
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
6,051✔
332
  } else if (pEntry->type == TSDB_NORMAL_TABLE) {
2,263!
333
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
2,263✔
334
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
2,263✔
335
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
2,263✔
336

337
    // schema
338
    code = metaCloneSchema(&pEntry->ntbEntry.schemaRow, &(*ppEntry)->ntbEntry.schemaRow);
2,263✔
339
    if (code) {
2,263!
340
      metaCloneEntryFree(ppEntry);
×
341
      return code;
×
342
    }
343

344
    // comment
345
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
2,263✔
346
    if (pEntry->ntbEntry.commentLen > 0) {
2,263✔
347
      (*ppEntry)->ntbEntry.comment = taosMemoryMalloc(pEntry->ntbEntry.commentLen + 1);
44!
348
      if (NULL == (*ppEntry)->ntbEntry.comment) {
44!
349
        code = terrno;
×
350
        metaCloneEntryFree(ppEntry);
×
351
        return code;
×
352
      }
353
      memcpy((*ppEntry)->ntbEntry.comment, pEntry->ntbEntry.comment, pEntry->ntbEntry.commentLen + 1);
44✔
354
    }
355
  } else {
356
    return TSDB_CODE_INVALID_PARA;
×
357
  }
358

359
  code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
239,215✔
360
  if (code) {
239,205!
361
    metaCloneEntryFree(ppEntry);
×
362
    return code;
×
363
  }
364

365
  return code;
239,225✔
366
}
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