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

taosdata / TDengine / #3627

02 Mar 2025 11:16PM UTC coverage: 63.596% (-0.2%) from 63.764%
#3627

push

travis-ci

GitHub
Merge pull request #29973 from taosdata/doc/internal

148665 of 299855 branches covered (49.58%)

Branch coverage included in aggregate %.

233076 of 300407 relevant lines covered (77.59%)

17543856.65 hits per line

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

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

24
  for (int32_t i = 0; i < pw->nCols; i++) {
5,602,724✔
25
    SColCmpr *p = &pw->pColCmpr[i];
5,213,925✔
26
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
10,427,850!
27
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
10,427,850!
28
  }
29
  return 0;
388,799✔
30
}
31
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
21,452,275✔
32
  SColCmprWrapper *pWrapper = &pME->colCmpr;
21,452,275✔
33
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
42,794,494!
34
  if (pWrapper->nCols == 0) {
21,342,219!
35
    return 0;
×
36
  }
37

38
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
42,672,249!
39
  uDebug("dencode cols:%d", pWrapper->nCols);
21,330,030✔
40
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
21,330,149✔
41
  if (pWrapper->pColCmpr == NULL) {
21,492,130!
42
    return terrno;
×
43
  }
44

45
  for (int i = 0; i < pWrapper->nCols; i++) {
447,904,416✔
46
    SColCmpr *p = &pWrapper->pColCmpr[i];
427,489,545✔
47
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
851,317,113!
48
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
850,239,854!
49
  }
50
  return 0;
20,414,871✔
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) {
29!
56
    return terrno;
×
57
  }
58

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

68
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
183,832✔
69
  if (pSrc->nCols > 0) {
183,832✔
70
    pDst->nCols = pSrc->nCols;
173,453✔
71
    pDst->version = pSrc->version;
173,453✔
72
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
173,453!
73
    if (NULL == pDst->pColCmpr) {
173,506!
74
      return terrno;
×
75
    }
76
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
173,506✔
77
  }
78
  return 0;
183,885✔
79
}
80

81
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
183,883✔
82
  if (pCmpr) {
183,883!
83
    taosMemoryFreeClear(pCmpr->pColCmpr);
183,891!
84
  }
85
}
183,902✔
86

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

93
  if (pME->type > 0) {
398,453✔
94
    if (pME->name == NULL) {
389,163!
95
      return TSDB_CODE_INVALID_PARA;
×
96
    }
97

98
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
778,326!
99

100
    if (pME->type == TSDB_SUPER_TABLE) {
389,163✔
101
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
150,090!
102
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
150,090!
103
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
150,090!
104
      if (TABLE_IS_ROLLUP(pME->flags)) {
75,045✔
105
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
14!
106
      }
107
    } else if (pME->type == TSDB_CHILD_TABLE) {
314,118✔
108
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
570,410!
109
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
570,410!
110
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
570,410!
111
      if (pME->ctbEntry.commentLen > 0) {
285,205✔
112
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
140!
113
      }
114
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
570,410!
115
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
285,205!
116
    } else if (pME->type == TSDB_NORMAL_TABLE) {
28,913✔
117
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
57,688!
118
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
57,688!
119
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
57,688!
120
      if (pME->ntbEntry.commentLen > 0) {
28,844✔
121
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
148!
122
      }
123
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
57,688!
124
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
57,688!
125
    } else if (pME->type == TSDB_TSMA_TABLE) {
69✔
126
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
56!
127
    } else {
128
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
13!
129
      return TSDB_CODE_INVALID_PARA;
×
130
    }
131
    TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
389,138!
132
  }
133

134
  tEndEncode(pCoder);
398,112✔
135
  return 0;
398,597✔
136
}
137

138
int metaDecodeEntryImpl(SDecoder *pCoder, SMetaEntry *pME, bool headerOnly) {
30,840,755✔
139
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
30,840,755!
140
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
61,483,098!
141
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
60,857,042!
142
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
60,532,905!
143

144
  if (headerOnly) {
30,245,095✔
145
    tEndDecode(pCoder);
11,852✔
146
    return 0;
11,852✔
147
  }
148

149
  if (pME->type > 0) {
30,233,243!
150
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
61,175,656!
151

152
    if (pME->type == TSDB_SUPER_TABLE) {
30,831,462✔
153
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
38,451,801!
154
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
36,475,339!
155
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
36,965,762!
156
      if (TABLE_IS_ROLLUP(pME->flags)) {
19,658,762✔
157
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
261!
158
      }
159
    } else if (pME->type == TSDB_CHILD_TABLE) {
11,548,000✔
160
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
18,772,381!
161
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
18,702,380!
162
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
18,696,278!
163
      if (pME->ctbEntry.commentLen > 0) {
9,357,856✔
164
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
290!
165
      }
166
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
18,713,372!
167
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
9,355,516!
168
    } else if (pME->type == TSDB_NORMAL_TABLE) {
2,139,577!
169
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,377,554!
170
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,373,023!
171
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,372,652!
172
      if (pME->ntbEntry.commentLen > 0) {
2,186,751✔
173
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
346!
174
      }
175
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,373,090!
176
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,341,005!
177
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
178
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
3✔
179
      if (!pME->smaEntry.tsma) {
3!
180
        return terrno;
×
181
      }
182
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
3!
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) {
30,866,807✔
188
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
19,272,034!
189
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
19,274,207!
190

191
        if (pME->colCmpr.nCols == 0) {
19,161,133!
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);
29✔
197
      }
198
    } else if (pME->type == TSDB_NORMAL_TABLE) {
11,594,773✔
199
      if (!tDecodeIsEnd(pCoder)) {
2,190,837!
200
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,191,237✔
201
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,191,249✔
202
        if (pME->colCmpr.nCols == 0) {
2,186,551!
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);
2,186,551✔
210
    }
211
  }
212

213
  tEndDecode(pCoder);
30,640,698✔
214
  return 0;
30,587,805✔
215
}
216

217
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { return metaDecodeEntryImpl(pCoder, pME, false); }
30,806,529✔
218

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

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

234
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
344,625✔
235
  if (pSchema) {
344,625!
236
    taosMemoryFreeClear(pSchema->pSchema);
344,628!
237
  }
238
}
344,677✔
239

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

245
  taosMemoryFreeClear((*ppEntry)->name);
183,902!
246

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

252
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
183,906✔
253
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
171,213✔
254
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
171,217✔
255
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type) {
12,693✔
256
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
10,404!
257
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
10,404!
258
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type) {
2,289✔
259
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
2,272✔
260
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
2,272!
261
  } else {
262
    return;
17✔
263
  }
264
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
183,908✔
265

266
  taosMemoryFreeClear(*ppEntry);
183,903!
267
  return;
183,914✔
268
}
269

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

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

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

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

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

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

299
  if (pEntry->type == TSDB_SUPER_TABLE) {
183,850✔
300
    (*ppEntry)->flags = pEntry->flags;
171,177✔
301

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

308
    code = metaCloneSchema(&pEntry->stbEntry.schemaTag, &(*ppEntry)->stbEntry.schemaTag);
171,174✔
309
    if (code) {
171,183!
310
      metaCloneEntryFree(ppEntry);
×
311
      return code;
×
312
    }
313
  } else if (pEntry->type == TSDB_CHILD_TABLE) {
12,673✔
314
    (*ppEntry)->ctbEntry.btime = pEntry->ctbEntry.btime;
10,401✔
315
    (*ppEntry)->ctbEntry.ttlDays = pEntry->ctbEntry.ttlDays;
10,401✔
316
    (*ppEntry)->ctbEntry.suid = pEntry->ctbEntry.suid;
10,401✔
317

318
    // comment
319
    (*ppEntry)->ctbEntry.commentLen = pEntry->ctbEntry.commentLen;
10,401✔
320
    if (pEntry->ctbEntry.commentLen > 0) {
10,401✔
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;
10,401✔
332
    (*ppEntry)->ctbEntry.pTags = taosMemoryCalloc(1, pTags->len);
10,401!
333
    if (NULL == (*ppEntry)->ctbEntry.pTags) {
10,406!
334
      code = terrno;
×
335
      metaCloneEntryFree(ppEntry);
×
336
      return code;
×
337
    }
338
    memcpy((*ppEntry)->ctbEntry.pTags, pEntry->ctbEntry.pTags, pTags->len);
10,406✔
339
  } else if (pEntry->type == TSDB_NORMAL_TABLE) {
2,272!
340
    (*ppEntry)->ntbEntry.btime = pEntry->ntbEntry.btime;
2,272✔
341
    (*ppEntry)->ntbEntry.ttlDays = pEntry->ntbEntry.ttlDays;
2,272✔
342
    (*ppEntry)->ntbEntry.ncid = pEntry->ntbEntry.ncid;
2,272✔
343

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

351
    // comment
352
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
2,272✔
353
    if (pEntry->ntbEntry.commentLen > 0) {
2,272✔
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);
183,861✔
367
  if (code) {
183,885!
368
    metaCloneEntryFree(ppEntry);
×
369
    return code;
×
370
  }
371

372
  return code;
183,886✔
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