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

taosdata / TDengine / #3613

14 Feb 2025 09:14AM UTC coverage: 63.499% (-0.01%) from 63.513%
#3613

push

travis-ci

web-flow
Merge pull request #29781 from taosdata/doc/internal

docs: minor changes

141396 of 286269 branches covered (49.39%)

Branch coverage included in aggregate %.

220278 of 283307 relevant lines covered (77.75%)

19138445.45 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) {
534,870✔
19
  const SColCmprWrapper *pw = &pME->colCmpr;
534,870✔
20
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->nCols));
1,069,740!
21
  TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pw->version));
1,069,740!
22
  uDebug("encode cols:%d", pw->nCols);
534,870✔
23

24
  for (int32_t i = 0; i < pw->nCols; i++) {
6,231,468✔
25
    SColCmpr *p = &pw->pColCmpr[i];
5,696,080✔
26
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
11,392,160!
27
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
11,392,160!
28
  }
29
  return 0;
535,388✔
30
}
31
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
21,666,331✔
32
  SColCmprWrapper *pWrapper = &pME->colCmpr;
21,666,331✔
33
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
43,211,114!
34
  if (pWrapper->nCols == 0) {
21,544,783!
35
    return 0;
×
36
  }
37

38
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
43,051,561!
39
  uDebug("dencode cols:%d", pWrapper->nCols);
21,506,778✔
40
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
21,506,873✔
41
  if (pWrapper->pColCmpr == NULL) {
21,683,520!
42
    return terrno;
×
43
  }
44

45
  for (int i = 0; i < pWrapper->nCols; i++) {
455,174,368✔
46
    SColCmpr *p = &pWrapper->pColCmpr[i];
434,792,235✔
47
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
865,598,525!
48
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
864,297,138!
49
  }
50
  return 0;
20,382,133✔
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++) {
228!
60
    SColCmpr *pColCmpr = &pCmpr->pColCmpr[i];
208✔
61
    SSchema  *pColSchema = &pSchema->pSchema[i];
208✔
62
    pColCmpr->id = pColSchema->colId;
208✔
63
    pColCmpr->alg = createDefaultColCmprByType(pColSchema->type);
208✔
64
  }
65
  return 0;
20✔
66
}
67

68
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
256,941✔
69
  if (pSrc->nCols > 0) {
256,941✔
70
    pDst->nCols = pSrc->nCols;
246,331✔
71
    pDst->version = pSrc->version;
246,331✔
72
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
246,331!
73
    if (NULL == pDst->pColCmpr) {
246,396!
74
      return terrno;
×
75
    }
76
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
246,396✔
77
  }
78
  return 0;
257,006✔
79
}
80

81
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
257,004✔
82
  if (pCmpr) {
257,004!
83
    taosMemoryFreeClear(pCmpr->pColCmpr);
257,012!
84
  }
85
}
257,029✔
86

87
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
544,658✔
88
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
544,658✔
89
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,090,398!
90
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,090,398!
91
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,090,398!
92

93
  if (pME->type > 0) {
545,199✔
94
    if (pME->name == NULL) {
535,441!
95
      return TSDB_CODE_INVALID_PARA;
×
96
    }
97

98
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,070,882!
99

100
    if (pME->type == TSDB_SUPER_TABLE) {
535,441✔
101
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
141,946!
102
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
141,946!
103
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
141,946!
104
      if (TABLE_IS_ROLLUP(pME->flags)) {
70,973✔
105
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
14!
106
      }
107
    } else if (pME->type == TSDB_CHILD_TABLE) {
464,468✔
108
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
871,168!
109
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
871,168!
110
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
871,168!
111
      if (pME->ctbEntry.commentLen > 0) {
435,584✔
112
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
140!
113
      }
114
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
871,168!
115
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
435,584!
116
    } else if (pME->type == TSDB_NORMAL_TABLE) {
28,884✔
117
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
57,622!
118
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
57,622!
119
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
57,622!
120
      if (pME->ntbEntry.commentLen > 0) {
28,811✔
121
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
140!
122
      }
123
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
57,622!
124
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
57,622!
125
    } else if (pME->type == TSDB_TSMA_TABLE) {
73✔
126
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
56!
127
    } else {
128
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
17!
129
      return TSDB_CODE_INVALID_PARA;
×
130
    }
131
    TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
535,396!
132
  }
133

134
  tEndEncode(pCoder);
545,118✔
135
  return 0;
545,162✔
136
}
137

138
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
31,155,932✔
139
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
31,155,932!
140
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
62,130,829!
141
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
61,551,360!
142
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
61,247,358!
143

144
  if (pME->type > 0) {
30,587,934!
145
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
61,918,282!
146

147
    if (pME->type == TSDB_SUPER_TABLE) {
31,181,241✔
148
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
38,940,826!
149
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
39,936,574!
150
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
39,698,745!
151
      if (TABLE_IS_ROLLUP(pME->flags)) {
19,170,190✔
152
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
261!
153
      }
154
    } else if (pME->type == TSDB_CHILD_TABLE) {
11,648,434✔
155
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
19,060,353!
156
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
18,991,592!
157
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
18,984,233!
158
      if (pME->ctbEntry.commentLen > 0) {
9,498,819✔
159
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
290!
160
      }
161
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
18,986,193!
162
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
9,487,374!
163
    } else if (pME->type == TSDB_NORMAL_TABLE) {
2,094,259!
164
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,270,713!
165
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,265,187!
166
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,263,743!
167
      if (pME->ntbEntry.commentLen > 0) {
2,132,067✔
168
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
332!
169
      }
170
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,265,134!
171
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,199,099!
172
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
173
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
1✔
174
      if (!pME->smaEntry.tsma) {
1!
175
        return terrno;
×
176
      }
177
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
1!
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) {
31,218,386✔
183
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
19,529,742!
184
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
19,540,104!
185

186
        if (pME->colCmpr.nCols == 0) {
19,412,232!
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);
20✔
192
      }
193
    } else if (pME->type == TSDB_NORMAL_TABLE) {
11,688,644✔
194
      if (!tDecodeIsEnd(pCoder)) {
2,137,456!
195
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,137,823✔
196
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,137,828✔
197
        if (pME->colCmpr.nCols == 0) {
2,132,939!
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);
2,132,939✔
205
    }
206
  }
207

208
  tEndDecode(pCoder);
30,947,272✔
209
  return 0;
30,930,955✔
210
}
211

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

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

227
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
490,377✔
228
  if (pSchema) {
490,377!
229
    taosMemoryFreeClear(pSchema->pSchema);
490,382!
230
  }
231
}
490,445✔
232

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

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

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

245
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
257,020✔
246
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
244,105✔
247
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
244,128✔
248
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type) {
12,915✔
249
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
10,644!
250
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
10,644!
251
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type) {
2,271✔
252
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
2,254✔
253
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
2,254!
254
  } else {
255
    return;
17✔
256
  }
257
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
257,032✔
258

259
  taosMemoryFreeClear(*ppEntry);
257,031!
260
  return;
257,043✔
261
}
262

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

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

270
  *ppEntry = (SMetaEntry *)taosMemoryCalloc(1, sizeof(SMetaEntry));
256,956!
271
  if (NULL == *ppEntry) {
257,028!
272
    return terrno;
×
273
  }
274

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

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

283
  if (pEntry->name) {
257,028!
284
    (*ppEntry)->name = tstrdup(pEntry->name);
257,036✔
285
    if (NULL == (*ppEntry)->name) {
256,983!
286
      code = terrno;
×
287
      metaCloneEntryFree(ppEntry);
×
288
      return code;
×
289
    }
290
  }
291

292
  if (pEntry->type == TSDB_SUPER_TABLE) {
256,986✔
293
    (*ppEntry)->flags = pEntry->flags;
244,089✔
294

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

301
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
244,068✔
302
    if (code) {
244,072!
303
      metaCloneEntryFree(ppEntry);
×
304
      return code;
×
305
    }
306
  } else if (pEntry->type == TSDB_CHILD_TABLE) {
12,897✔
307
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
10,643✔
308
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
10,643✔
309
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
10,643✔
310

311
    // comment
312
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
10,643✔
313
    if (pEntry->ctbEntry.commentLen > 0) {
10,643✔
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;
10,643✔
325
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
10,643!
326
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
10,642!
327
      code = terrno;
×
328
      metaCloneEntryFree(ppEntry);
×
329
      return code;
×
330
    }
331
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
10,642✔
332
  } else if (pEntry->type == TSDB_NORMAL_TABLE) {
2,254!
333
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
2,254✔
334
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
2,254✔
335
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
2,254✔
336

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

344
    // comment
345
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
2,254✔
346
    if (pEntry->ntbEntry.commentLen > 0) {
2,254✔
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);
256,968✔
360
  if (code) {
257,007✔
361
    metaCloneEntryFree(ppEntry);
12✔
362
    return code;
×
363
  }
364

365
  return code;
256,995✔
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