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

taosdata / TDengine / #3563

21 Dec 2024 05:37AM UTC coverage: 61.045% (+34.4%) from 26.655%
#3563

push

travis-ci

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

merge: from main t 3.0

135730 of 287838 branches covered (47.15%)

Branch coverage included in aggregate %.

9 of 28 new or added lines in 5 files covered. (32.14%)

784 existing lines in 21 files now uncovered.

213302 of 283921 relevant lines covered (75.13%)

9176355.9 hits per line

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

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

24
  for (int32_t i = 0; i < pw->nCols; i++) {
3,889,981✔
25
    SColCmpr *p = &pw->pColCmpr[i];
3,426,147✔
26
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
6,852,294!
27
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
6,852,294!
28
  }
29
  return 0;
463,834✔
30
}
31
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
3,973,821✔
32
  SColCmprWrapper *pWrapper = &pME->colCmpr;
3,973,821✔
33
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
7,946,502!
34
  if (pWrapper->nCols == 0) {
3,972,681!
35
    return 0;
×
36
  }
37

38
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
7,947,069!
39
  uDebug("dencode cols:%d", pWrapper->nCols);
3,974,388✔
40
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
3,974,464✔
41
  if (pWrapper->pColCmpr == NULL) {
3,976,974!
42
    return terrno;
×
43
  }
44

45
  for (int i = 0; i < pWrapper->nCols; i++) {
71,226,847✔
46
    SColCmpr *p = &pWrapper->pColCmpr[i];
67,223,190✔
47
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
134,507,612!
48
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
134,534,295!
49
  }
50
  return 0;
4,003,657✔
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) {
26!
56
    return terrno;
×
57
  }
58

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

68
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
219,261✔
69
  if (pSrc->nCols > 0) {
219,261✔
70
    pDst->nCols = pSrc->nCols;
214,271✔
71
    pDst->version = pSrc->version;
214,271✔
72
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
214,271!
73
    if (NULL == pDst->pColCmpr) {
214,332!
74
      return terrno;
×
75
    }
76
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
214,332✔
77
  }
78
  return 0;
219,322✔
79
}
80

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

87
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
471,285✔
88
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
471,285✔
89
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
943,814!
90
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
943,814!
91
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
943,814!
92

93
  if (pME->type > 0) {
471,907✔
94
    if (pME->name == NULL) {
463,887!
95
      return TSDB_CODE_INVALID_PARA;
×
96
    }
97

98
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
927,774!
99

100
    if (pME->type == TSDB_SUPER_TABLE) {
463,887✔
101
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
98,412!
102
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
98,412!
103
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
98,412!
104
      if (TABLE_IS_ROLLUP(pME->flags)) {
49,206✔
105
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
14!
106
      }
107
    } else if (pME->type == TSDB_CHILD_TABLE) {
414,681✔
108
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
763,540!
109
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
763,540!
110
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
763,540!
111
      if (pME->ctbEntry.commentLen > 0) {
381,770✔
112
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
84!
113
      }
114
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
763,540!
115
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
381,770!
116
    } else if (pME->type == TSDB_NORMAL_TABLE) {
32,911✔
117
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
65,660!
118
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
65,660!
119
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
65,660!
120
      if (pME->ntbEntry.commentLen > 0) {
32,830✔
121
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
116!
122
      }
123
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
65,660!
124
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
65,660!
125
    } else if (pME->type == TSDB_TSMA_TABLE) {
81✔
126
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
54!
127
    } else {
128
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
27!
129
      return TSDB_CODE_INVALID_PARA;
×
130
    }
131
    TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
463,863!
132
  }
133

134
  tEndEncode(pCoder);
471,757✔
135
  return 0;
471,748✔
136
}
137

138
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
6,588,372✔
139
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
6,588,372!
140
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
13,176,376!
141
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
13,170,697!
142
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
13,162,892!
143

144
  if (pME->type > 0) {
6,578,838✔
145
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
13,152,497!
146

147
    if (pME->type == TSDB_SUPER_TABLE) {
6,575,032✔
148
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
6,724,069!
149
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
6,720,017!
150
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
6,718,765!
151
      if (TABLE_IS_ROLLUP(pME->flags)) {
3,360,302✔
152
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
267!
153
      }
154
    } else if (pME->type == TSDB_CHILD_TABLE) {
3,212,517✔
155
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
5,223,169!
156
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
5,222,510!
157
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
5,223,202!
158
      if (pME->ctbEntry.commentLen > 0) {
2,611,968✔
159
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
174!
160
      }
161
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
5,223,471!
162
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
2,611,503!
163
    } else if (pME->type == TSDB_NORMAL_TABLE) {
600,624!
164
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
1,216,821!
165
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
1,216,535!
166
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
1,216,426!
167
      if (pME->ntbEntry.commentLen > 0) {
608,072✔
168
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
252!
169
      }
170
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
1,215,835!
171
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
1,214,753!
UNCOV
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 {
UNCOV
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,585,416✔
183
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
3,365,556!
184
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
3,366,409!
185

186
        if (pME->colCmpr.nCols == 0) {
3,366,754!
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);
26✔
192
      }
193
    } else if (pME->type == TSDB_NORMAL_TABLE) {
3,219,860✔
194
      if (!tDecodeIsEnd(pCoder)) {
608,648!
195
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
608,704✔
196
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
608,706✔
197
        if (pME->colCmpr.nCols == 0) {
608,168!
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);
608,168✔
205
    }
206
  }
207

208
  tEndDecode(pCoder);
6,587,533✔
209
  return 0;
6,582,147✔
210
}
211

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

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

227
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
426,389✔
228
  if (pSchema) {
426,389!
229
    taosMemoryFreeClear(pSchema->pSchema);
426,408!
230
  }
231
}
426,434✔
232

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

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

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

245
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
219,336✔
246
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
212,171✔
247
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
212,181✔
248
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type) {
7,165✔
249
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
5,021!
250
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
5,021!
251
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type) {
2,144✔
252
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
2,135✔
253
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
2,135!
254
  } else {
255
    return;
9✔
256
  }
257
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
219,343✔
258

259
  taosMemoryFreeClear(*ppEntry);
219,344!
260
  return;
219,372✔
261
}
262

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

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

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

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

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

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

292
  if (pEntry->type == TSDB_SUPER_TABLE) {
219,329✔
293
    (*ppEntry)->flags = pEntry->flags;
212,178✔
294

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

301
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
212,138✔
302
    if (code) {
212,133!
303
      metaCloneEntryFree(ppEntry);
×
304
      return code;
×
305
    }
306
  } else if (pEntry->type == TSDB_CHILD_TABLE) {
7,151✔
307
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
5,016✔
308
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
5,016✔
309
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
5,016✔
310

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

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

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

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

359
  code = metaCloneColCmpr(&pEntry->colCmpr, &(*ppEntry)->colCmpr);
219,288✔
360
  if (code) {
219,333✔
361
    metaCloneEntryFree(ppEntry);
11✔
362
    return code;
×
363
  }
364

365
  return code;
219,322✔
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