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

taosdata / TDengine / #3568

27 Dec 2024 02:27PM UTC coverage: 63.286% (+0.6%) from 62.733%
#3568

push

travis-ci

web-flow
Merge pull request #29378 from taosdata/revert-29377-revert-29165-enh/TD-29974-improve-trans

Revert "Revert "Enh:[td 29974]improve trans""

139941 of 284289 branches covered (49.22%)

Branch coverage included in aggregate %.

105 of 355 new or added lines in 12 files covered. (29.58%)

4077 existing lines in 132 files now uncovered.

218122 of 281494 relevant lines covered (77.49%)

19355607.91 hits per line

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

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

24
  for (int32_t i = 0; i < pw->nCols; i++) {
5,993,500✔
25
    SColCmpr *p = &pw->pColCmpr[i];
5,467,155✔
26
    TAOS_CHECK_RETURN(tEncodeI16v(pCoder, p->id));
10,934,310!
27
    TAOS_CHECK_RETURN(tEncodeU32(pCoder, p->alg));
10,934,310!
28
  }
29
  return 0;
526,345✔
30
}
31
int meteDecodeColCmprEntry(SDecoder *pDecoder, SMetaEntry *pME) {
18,594,807✔
32
  SColCmprWrapper *pWrapper = &pME->colCmpr;
18,594,807✔
33
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->nCols));
37,067,321!
34
  if (pWrapper->nCols == 0) {
18,472,514!
35
    return 0;
×
36
  }
37

38
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pWrapper->version));
36,913,268!
39
  uDebug("dencode cols:%d", pWrapper->nCols);
18,440,754✔
40
  pWrapper->pColCmpr = (SColCmpr *)tDecoderMalloc(pDecoder, pWrapper->nCols * sizeof(SColCmpr));
18,440,880✔
41
  if (pWrapper->pColCmpr == NULL) {
18,627,424!
42
    return terrno;
×
43
  }
44

45
  for (int i = 0; i < pWrapper->nCols; i++) {
371,943,715✔
46
    SColCmpr *p = &pWrapper->pColCmpr[i];
354,736,186✔
47
    TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &p->id));
705,760,035!
48
    TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &p->alg));
704,340,140!
49
  }
50
  return 0;
17,207,529✔
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) {
24!
56
    return terrno;
×
57
  }
58

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

68
static int32_t metaCloneColCmpr(const SColCmprWrapper *pSrc, SColCmprWrapper *pDst) {
252,496✔
69
  if (pSrc->nCols > 0) {
252,496✔
70
    pDst->nCols = pSrc->nCols;
241,950✔
71
    pDst->version = pSrc->version;
241,950✔
72
    pDst->pColCmpr = (SColCmpr *)taosMemoryCalloc(pSrc->nCols, sizeof(SColCmpr));
241,950!
73
    if (NULL == pDst->pColCmpr) {
242,013!
74
      return terrno;
×
75
    }
76
    memcpy(pDst->pColCmpr, pSrc->pColCmpr, pSrc->nCols * sizeof(SColCmpr));
242,013✔
77
  }
78
  return 0;
252,559✔
79
}
80

81
static void metaCloneColCmprFree(SColCmprWrapper *pCmpr) {
252,538✔
82
  if (pCmpr) {
252,538!
83
    taosMemoryFreeClear(pCmpr->pColCmpr);
252,552!
84
  }
85
}
252,565✔
86

87
int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
535,791✔
88
  TAOS_CHECK_RETURN(tStartEncode(pCoder));
535,791✔
89
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->version));
1,072,938!
90
  TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->type));
1,072,938!
91
  TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->uid));
1,072,938!
92

93
  if (pME->type > 0) {
536,469✔
94
    if (pME->name == NULL) {
526,636!
95
      return TSDB_CODE_INVALID_PARA;
×
96
    }
97

98
    TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->name));
1,053,272!
99

100
    if (pME->type == TSDB_SUPER_TABLE) {
526,636✔
101
      TAOS_CHECK_RETURN(tEncodeI8(pCoder, pME->flags));
140,406!
102
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaRow));
140,406!
103
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag));
140,406!
104
      if (TABLE_IS_ROLLUP(pME->flags)) {
70,203✔
105
        TAOS_CHECK_RETURN(tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
14!
106
      }
107
    } else if (pME->type == TSDB_CHILD_TABLE) {
456,433✔
108
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.btime));
854,960!
109
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ctbEntry.ttlDays));
854,960!
110
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ctbEntry.commentLen));
854,960!
111
      if (pME->ctbEntry.commentLen > 0) {
427,480✔
112
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ctbEntry.comment));
84!
113
      }
114
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ctbEntry.suid));
854,960!
115
      TAOS_CHECK_RETURN(tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags));
427,480!
116
    } else if (pME->type == TSDB_NORMAL_TABLE) {
28,953✔
117
      TAOS_CHECK_RETURN(tEncodeI64(pCoder, pME->ntbEntry.btime));
57,578!
118
      TAOS_CHECK_RETURN(tEncodeI32(pCoder, pME->ntbEntry.ttlDays));
57,578!
119
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.commentLen));
57,578!
120
      if (pME->ntbEntry.commentLen > 0) {
28,789✔
121
        TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pME->ntbEntry.comment));
116!
122
      }
123
      TAOS_CHECK_RETURN(tEncodeI32v(pCoder, pME->ntbEntry.ncid));
57,578!
124
      TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow));
57,578!
125
    } else if (pME->type == TSDB_TSMA_TABLE) {
164✔
126
      TAOS_CHECK_RETURN(tEncodeTSma(pCoder, pME->smaEntry.tsma));
55!
127
    } else {
128
      metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
109!
129
      return TSDB_CODE_INVALID_PARA;
×
130
    }
131
    TAOS_CHECK_RETURN(meteEncodeColCmprEntry(pCoder, pME));
526,530!
132
  }
133

134
  tEndEncode(pCoder);
536,139✔
135
  return 0;
536,209✔
136
}
137

138
int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
27,512,164✔
139
  TAOS_CHECK_RETURN(tStartDecode(pCoder));
27,512,164!
140
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->version));
54,863,960!
141
  TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->type));
54,308,231!
142
  TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->uid));
53,997,034!
143

144
  if (pME->type > 0) {
26,945,521!
145
    TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->name));
54,241,504!
146

147
    if (pME->type == TSDB_SUPER_TABLE) {
27,173,444✔
148
      TAOS_CHECK_RETURN(tDecodeI8(pCoder, &pME->flags));
32,673,234!
149
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaRow));
27,441,949!
150
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag));
27,149,295!
151
      if (TABLE_IS_ROLLUP(pME->flags)) {
16,034,174✔
152
        TAOS_CHECK_RETURN(tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam));
268!
153
      }
154
    } else if (pME->type == TSDB_CHILD_TABLE) {
10,827,038✔
155
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.btime));
17,865,508!
156
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ctbEntry.ttlDays));
17,834,875!
157
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ctbEntry.commentLen));
17,843,618!
158
      if (pME->ctbEntry.commentLen > 0) {
8,934,306✔
159
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ctbEntry.comment));
174!
160
      }
161
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ctbEntry.suid));
17,858,661!
162
      TAOS_CHECK_RETURN(tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags));
8,924,355!
163
    } else if (pME->type == TSDB_NORMAL_TABLE) {
1,887,093!
164
      TAOS_CHECK_RETURN(tDecodeI64(pCoder, &pME->ntbEntry.btime));
4,237,536!
165
      TAOS_CHECK_RETURN(tDecodeI32(pCoder, &pME->ntbEntry.ttlDays));
4,236,066!
166
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.commentLen));
4,237,168!
167
      if (pME->ntbEntry.commentLen > 0) {
2,119,407✔
168
        TAOS_CHECK_RETURN(tDecodeCStr(pCoder, &pME->ntbEntry.comment));
252!
169
      }
170
      TAOS_CHECK_RETURN(tDecodeI32v(pCoder, &pME->ntbEntry.ncid));
4,238,773!
171
      TAOS_CHECK_RETURN(tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow));
4,003,346!
172
    } else if (pME->type == TSDB_TSMA_TABLE) {
×
173
      pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
2✔
174
      if (!pME->smaEntry.tsma) {
2!
175
        return terrno;
×
176
      }
177
      TAOS_CHECK_RETURN(tDecodeTSma(pCoder, pME->smaEntry.tsma, true));
2!
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) {
27,583,157✔
183
      if (TABLE_IS_COL_COMPRESSED(pME->flags)) {
16,480,672!
184
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
16,493,065!
185

186
        if (pME->colCmpr.nCols == 0) {
16,342,390!
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);
24✔
192
      }
193
    } else if (pME->type == TSDB_NORMAL_TABLE) {
11,102,485✔
194
      if (!tDecodeIsEnd(pCoder)) {
2,123,277!
195
        uDebug("set type: %d, tableName:%s", pME->type, pME->name);
2,123,445✔
196
        TAOS_CHECK_RETURN(meteDecodeColCmprEntry(pCoder, pME));
2,123,449✔
197
        if (pME->colCmpr.nCols == 0) {
2,119,359!
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,119,359✔
205
    }
206
  }
207

208
  tEndDecode(pCoder);
27,318,442✔
209
  return 0;
27,271,784✔
210
}
211

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

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

227
static void metaCloneSchemaFree(SSchemaWrapper *pSchema) {
481,613✔
228
  if (pSchema) {
481,613!
229
    taosMemoryFreeClear(pSchema->pSchema);
481,635!
230
  }
231
}
481,678✔
232

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

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

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

245
  if (TSDB_SUPER_TABLE == (*ppEntry)->type) {
252,554✔
246
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaRow);
239,749✔
247
    metaCloneSchemaFree(&(*ppEntry)->stbEntry.schemaTag);
239,758✔
248
  } else if (TSDB_CHILD_TABLE == (*ppEntry)->type) {
12,805✔
249
    taosMemoryFreeClear((*ppEntry)->ctbEntry.comment);
10,569!
250
    taosMemoryFreeClear((*ppEntry)->ctbEntry.pTags);
10,569!
251
  } else if (TSDB_NORMAL_TABLE == (*ppEntry)->type) {
2,236!
252
    metaCloneSchemaFree(&(*ppEntry)->ntbEntry.schemaRow);
2,243✔
253
    taosMemoryFreeClear((*ppEntry)->ntbEntry.comment);
2,243!
254
  } else {
UNCOV
255
    return;
×
256
  }
257
  metaCloneColCmprFree(&(*ppEntry)->colCmpr);
252,564✔
258

259
  taosMemoryFreeClear(*ppEntry);
252,559!
260
  return;
252,582✔
261
}
262

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

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

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

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

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

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

292
  if (pEntry->type == TSDB_SUPER_TABLE) {
252,553✔
293
    (*ppEntry)->flags = pEntry->flags;
239,740✔
294

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

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

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

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

344
    // comment
345
    (*ppEntry)->ntbEntry.commentLen = pEntry->ntbEntry.commentLen;
2,243✔
346
    if (pEntry->ntbEntry.commentLen > 0) {
2,243✔
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);
252,519✔
360
  if (code) {
252,532!
UNCOV
361
    metaCloneEntryFree(ppEntry);
×
362
    return code;
×
363
  }
364

365
  return code;
252,556✔
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