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

taosdata / TDengine / #3653

14 Mar 2025 08:10AM UTC coverage: 22.565% (-41.0%) from 63.596%
#3653

push

travis-ci

web-flow
feat(keep): support keep on super table level. (#30097)

* Feat: support use keep while create super table.

* Test(keep): add test for create super table with keep option.

* Feat(keep): Add tmsg for create keep.

* Feat(keep): support alter table option keep.

* Fix(keep): Add baisc test for alter table option.

* Fix(keep): memory leek.

* Feat(keep): add keep to metaEntry&metaCache and fix earliestTs with stn keep.

* Test(keep): add some cases for select with stb keep.

* Fix: fix ci core while alter stb.

* Feat(keep): delete expired data in super table level.

* Feat: remove get stb keep while query.

* Fix : build error.

* Revert "Fix : build error."

This reverts commit 0ed66e4e8.

* Revert "Feat(keep): delete expired data in super table level."

This reverts commit 36330f6b4.

* Fix : build errors.

* Feat : support restart taosd.

* Fix : alter table comment problems.

* Test : add tests for super table keep.

* Fix: change sdb stb reserve size.

* Test: add more tests.

* Feat: Disable normal tables and sub tables from setting the keep parameter

* Fix: add more checks to avoid unknown address.

* Docs: Add docs for stable keep.

* Fix: some review changes.

* Fix: review errors.

49248 of 302527 branches covered (16.28%)

Branch coverage included in aggregate %.

53 of 99 new or added lines in 12 files covered. (53.54%)

155872 existing lines in 443 files now uncovered.

87359 of 302857 relevant lines covered (28.84%)

570004.22 hits per line

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

0.0
/source/dnode/vnode/src/meta/metaTable.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
extern SDmNotifyHandle dmNotifyHdl;
19

20
int32_t metaAddTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp);
21
int32_t metaDropTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp);
22
int32_t metaAlterTableColumnName(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp);
23
int32_t metaAlterTableColumnBytes(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp);
24
int32_t metaUpdateTableTagValue(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq);
25
int32_t metaUpdateTableMultiTagValue(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq);
26
int32_t metaUpdateTableOptions2(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq);
27
int32_t metaUpdateTableColCompress2(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq);
28

29
int32_t metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema);
30

31
int32_t    metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema);
32
static int metaUpdateChangeTime(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs);
33
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *pSuid, int8_t *pSysTbl);
34
void       metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey);
35
// opt ins_tables query
36
static int metaDeleteBtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
37
static int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
38

UNCOV
39
int32_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add, uint32_t compress) {
×
UNCOV
40
  int32_t nCols = pWp->nCols;
×
UNCOV
41
  int32_t ver = pWp->version;
×
UNCOV
42
  if (add) {
×
UNCOV
43
    SColCmpr *p = taosMemoryRealloc(pWp->pColCmpr, sizeof(SColCmpr) * (nCols + 1));
×
UNCOV
44
    if (p == NULL) {
×
45
      return terrno;
×
46
    }
UNCOV
47
    pWp->pColCmpr = p;
×
48

UNCOV
49
    SColCmpr *pCol = p + nCols;
×
UNCOV
50
    pCol->id = pSchema->colId;
×
UNCOV
51
    pCol->alg = compress;
×
UNCOV
52
    pWp->nCols = nCols + 1;
×
UNCOV
53
    pWp->version = ver;
×
54
  } else {
UNCOV
55
    for (int32_t i = 0; i < nCols; i++) {
×
UNCOV
56
      SColCmpr *pOCmpr = &pWp->pColCmpr[i];
×
UNCOV
57
      if (pOCmpr->id == pSchema->colId) {
×
UNCOV
58
        int32_t left = (nCols - i - 1) * sizeof(SColCmpr);
×
UNCOV
59
        if (left) {
×
UNCOV
60
          memmove(pWp->pColCmpr + i, pWp->pColCmpr + i + 1, left);
×
61
        }
UNCOV
62
        nCols--;
×
UNCOV
63
        break;
×
64
      }
65
    }
UNCOV
66
    pWp->nCols = nCols;
×
UNCOV
67
    pWp->version = ver;
×
68
  }
UNCOV
69
  return 0;
×
70
}
71

UNCOV
72
int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema, STableMetaRsp *pMetaRsp) {
×
UNCOV
73
  pMetaRsp->pSchemas = taosMemoryMalloc(pSchema->nCols * sizeof(SSchema));
×
UNCOV
74
  if (NULL == pMetaRsp->pSchemas) {
×
75
    return terrno;
×
76
  }
77

UNCOV
78
  pMetaRsp->pSchemaExt = taosMemoryMalloc(pSchema->nCols * sizeof(SSchemaExt));
×
UNCOV
79
  if (pMetaRsp->pSchemaExt == NULL) {
×
80
    taosMemoryFree(pMetaRsp->pSchemas);
×
81
    return terrno;
×
82
  }
83

UNCOV
84
  tstrncpy(pMetaRsp->tbName, tbName, TSDB_TABLE_NAME_LEN);
×
UNCOV
85
  pMetaRsp->numOfColumns = pSchema->nCols;
×
UNCOV
86
  pMetaRsp->tableType = TSDB_NORMAL_TABLE;
×
UNCOV
87
  pMetaRsp->sversion = pSchema->version;
×
UNCOV
88
  pMetaRsp->tuid = uid;
×
89

UNCOV
90
  memcpy(pMetaRsp->pSchemas, pSchema->pSchema, pSchema->nCols * sizeof(SSchema));
×
91

UNCOV
92
  return 0;
×
93
}
94

UNCOV
95
int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema) {
×
UNCOV
96
  int32_t code = 0;
×
97

98
#ifdef USE_INVERTED_INDEX
UNCOV
99
  if (pMeta->pTagIvtIdx == NULL || pCtbEntry == NULL) {
×
100
    return TSDB_CODE_INVALID_PARA;
×
101
  }
UNCOV
102
  void       *data = pCtbEntry->ctbEntry.pTags;
×
UNCOV
103
  const char *tagName = pSchema->name;
×
104

UNCOV
105
  tb_uid_t    suid = pCtbEntry->ctbEntry.suid;
×
UNCOV
106
  tb_uid_t    tuid = pCtbEntry->uid;
×
UNCOV
107
  const void *pTagData = pCtbEntry->ctbEntry.pTags;
×
UNCOV
108
  int32_t     nTagData = 0;
×
109

UNCOV
110
  SArray *pTagVals = NULL;
×
UNCOV
111
  code = tTagToValArray((const STag *)data, &pTagVals);
×
UNCOV
112
  if (code) {
×
113
    return code;
×
114
  }
115

UNCOV
116
  SIndexMultiTerm *terms = indexMultiTermCreate();
×
UNCOV
117
  if (terms == NULL) {
×
118
    return terrno;
×
119
  }
120

UNCOV
121
  int16_t nCols = taosArrayGetSize(pTagVals);
×
UNCOV
122
  for (int i = 0; i < nCols; i++) {
×
UNCOV
123
    STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i);
×
UNCOV
124
    char     type = pTagVal->type;
×
125

UNCOV
126
    char   *key = pTagVal->pKey;
×
UNCOV
127
    int32_t nKey = strlen(key);
×
128

UNCOV
129
    SIndexTerm *term = NULL;
×
UNCOV
130
    if (type == TSDB_DATA_TYPE_NULL) {
×
UNCOV
131
      term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, NULL, 0);
×
UNCOV
132
    } else if (type == TSDB_DATA_TYPE_NCHAR) {
×
UNCOV
133
      if (pTagVal->nData > 0) {
×
UNCOV
134
        char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE);
×
UNCOV
135
        if (val == NULL) {
×
136
          TAOS_CHECK_GOTO(terrno, NULL, _exception);
×
137
        }
UNCOV
138
        int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE, NULL);
×
UNCOV
139
        if (len < 0) {
×
140
          TAOS_CHECK_GOTO(len, NULL, _exception);
×
141
        }
UNCOV
142
        memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE);
×
UNCOV
143
        type = TSDB_DATA_TYPE_VARCHAR;
×
UNCOV
144
        term = indexTermCreate(suid, ADD_VALUE, type, key, nKey, val, len);
×
UNCOV
145
        taosMemoryFree(val);
×
UNCOV
146
      } else if (pTagVal->nData == 0) {
×
UNCOV
147
        term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, pTagVal->pData, 0);
×
148
      }
UNCOV
149
    } else if (type == TSDB_DATA_TYPE_DOUBLE) {
×
UNCOV
150
      double val = *(double *)(&pTagVal->i64);
×
UNCOV
151
      int    len = sizeof(val);
×
UNCOV
152
      term = indexTermCreate(suid, ADD_VALUE, type, key, nKey, (const char *)&val, len);
×
UNCOV
153
    } else if (type == TSDB_DATA_TYPE_BOOL) {
×
UNCOV
154
      int val = *(int *)(&pTagVal->i64);
×
UNCOV
155
      int len = sizeof(val);
×
UNCOV
156
      term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BOOL, key, nKey, (const char *)&val, len);
×
157
    }
158

UNCOV
159
    if (term != NULL) {
×
UNCOV
160
      int32_t ret = indexMultiTermAdd(terms, term);
×
UNCOV
161
      if (ret < 0) {
×
162
        metaError("vgId:%d, failed to add term to multi term, uid: %" PRId64 ", key: %s, type: %d, ret: %d",
×
163
                  TD_VID(pMeta->pVnode), tuid, key, type, ret);
164
      }
165
    } else {
166
      code = terrno;
×
167
      goto _exception;
×
168
    }
169
  }
UNCOV
170
  code = indexJsonPut(pMeta->pTagIvtIdx, terms, tuid);
×
UNCOV
171
  indexMultiTermDestroy(terms);
×
172

UNCOV
173
  taosArrayDestroy(pTagVals);
×
UNCOV
174
  return code;
×
UNCOV
175
_exception:
×
176
  indexMultiTermDestroy(terms);
×
177
  taosArrayDestroy(pTagVals);
×
178
#endif
179
  return code;
×
180
}
UNCOV
181
int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema) {
×
UNCOV
182
int32_t code = 0;
×
183
#ifdef USE_INVERTED_INDEX
184
  if (pMeta->pTagIvtIdx == NULL || pCtbEntry == NULL) {
×
UNCOV
185
    return TSDB_CODE_INVALID_PARA;
×
186
  }
UNCOV
187
  void       *data = pCtbEntry->ctbEntry.pTags;
×
UNCOV
188
  const char *tagName = pSchema->name;
×
189

UNCOV
190
  tb_uid_t    suid = pCtbEntry->ctbEntry.suid;
×
UNCOV
191
  tb_uid_t    tuid = pCtbEntry->uid;
×
UNCOV
192
  const void *pTagData = pCtbEntry->ctbEntry.pTags;
×
UNCOV
193
  int32_t     nTagData = 0;
×
194

UNCOV
195
  SArray *pTagVals = NULL;
×
UNCOV
196
  code = tTagToValArray((const STag *)data, &pTagVals);
×
197
  if (code) {
×
UNCOV
198
    return code;
×
199
  }
200

UNCOV
201
  SIndexMultiTerm *terms = indexMultiTermCreate();
×
202
  if (terms == NULL) {
×
UNCOV
203
    return terrno;
×
204
  }
205

UNCOV
206
  int16_t nCols = taosArrayGetSize(pTagVals);
×
UNCOV
207
  for (int i = 0; i < nCols; i++) {
×
UNCOV
208
    STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i);
×
UNCOV
209
    char     type = pTagVal->type;
×
210

UNCOV
211
    char   *key = pTagVal->pKey;
×
UNCOV
212
    int32_t nKey = strlen(key);
×
213

UNCOV
214
    SIndexTerm *term = NULL;
×
215
    if (type == TSDB_DATA_TYPE_NULL) {
×
UNCOV
216
      term = indexTermCreate(suid, DEL_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, NULL, 0);
×
UNCOV
217
    } else if (type == TSDB_DATA_TYPE_NCHAR) {
×
UNCOV
218
      if (pTagVal->nData > 0) {
×
UNCOV
219
        char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE);
×
220
        if (val == NULL) {
×
UNCOV
221
          TAOS_CHECK_GOTO(terrno, NULL, _exception);
×
222
        }
UNCOV
223
        int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE, NULL);
×
224
        if (len < 0) {
×
UNCOV
225
          TAOS_CHECK_GOTO(len, NULL, _exception);
×
226
        }
UNCOV
227
        memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE);
×
UNCOV
228
        type = TSDB_DATA_TYPE_VARCHAR;
×
UNCOV
229
        term = indexTermCreate(suid, DEL_VALUE, type, key, nKey, val, len);
×
230
        taosMemoryFree(val);
×
231
      } else if (pTagVal->nData == 0) {
×
UNCOV
232
        term = indexTermCreate(suid, DEL_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, pTagVal->pData, 0);
×
233
      }
UNCOV
234
    } else if (type == TSDB_DATA_TYPE_DOUBLE) {
×
UNCOV
235
      double val = *(double *)(&pTagVal->i64);
×
UNCOV
236
      int    len = sizeof(val);
×
UNCOV
237
      term = indexTermCreate(suid, DEL_VALUE, type, key, nKey, (const char *)&val, len);
×
UNCOV
238
    } else if (type == TSDB_DATA_TYPE_BOOL) {
×
UNCOV
239
      int val = *(int *)(&pTagVal->i64);
×
UNCOV
240
      int len = sizeof(val);
×
UNCOV
241
      term = indexTermCreate(suid, DEL_VALUE, TSDB_DATA_TYPE_BOOL, key, nKey, (const char *)&val, len);
×
242
    }
UNCOV
243
    if (term != NULL) {
×
UNCOV
244
      int32_t ret = indexMultiTermAdd(terms, term);
×
245
      if (ret < 0) {
×
UNCOV
246
        metaError("vgId:%d, failed to add term to multi term, uid: %" PRId64 ", key: %s, type: %d, ret: %d",
×
247
                  TD_VID(pMeta->pVnode), tuid, key, type, ret);
248
      }
249
    } else {
250
      code = terrno;
×
UNCOV
251
      goto _exception;
×
252
    }
253
  }
UNCOV
254
  code = indexJsonPut(pMeta->pTagIvtIdx, terms, tuid);
×
UNCOV
255
  indexMultiTermDestroy(terms);
×
UNCOV
256
  taosArrayDestroy(pTagVals);
×
UNCOV
257
  return code;
×
258
_exception:
×
259
  indexMultiTermDestroy(terms);
×
260
  taosArrayDestroy(pTagVals);
×
261
#endif
UNCOV
262
  return code;
×
263
}
264

UNCOV
265
static int32_t metaDropTables(SMeta *pMeta, SArray *tbUids) {
×
UNCOV
266
  int32_t code = 0;
×
UNCOV
267
  if (taosArrayGetSize(tbUids) == 0) return TSDB_CODE_SUCCESS;
×
268

UNCOV
269
  int64_t    nCtbDropped = 0;
×
UNCOV
270
  SSHashObj *suidHash = tSimpleHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
×
271
  if (suidHash == NULL) {
×
UNCOV
272
    return terrno;
×
273
  }
274

UNCOV
275
  metaWLock(pMeta);
×
UNCOV
276
  for (int i = 0; i < taosArrayGetSize(tbUids); ++i) {
×
UNCOV
277
    tb_uid_t uid = *(tb_uid_t *)taosArrayGet(tbUids, i);
×
UNCOV
278
    tb_uid_t suid = 0;
×
UNCOV
279
    int8_t   sysTbl = 0;
×
280
    int      type;
UNCOV
281
    code = metaDropTableByUid(pMeta, uid, &type, &suid, &sysTbl);
×
UNCOV
282
    if (code) return code;
×
UNCOV
283
    if (!sysTbl && type == TSDB_CHILD_TABLE && suid != 0 && suidHash) {
×
UNCOV
284
      int64_t *pVal = tSimpleHashGet(suidHash, &suid, sizeof(tb_uid_t));
×
UNCOV
285
      if (pVal) {
×
UNCOV
286
        nCtbDropped = *pVal + 1;
×
287
      } else {
UNCOV
288
        nCtbDropped = 1;
×
289
      }
UNCOV
290
      code = tSimpleHashPut(suidHash, &suid, sizeof(tb_uid_t), &nCtbDropped, sizeof(int64_t));
×
UNCOV
291
      if (code) return code;
×
292
    }
293
    /*
294
    if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
295
      tsdbCacheDropTable(pMeta->pVnode->pTsdb, uid, suid, NULL);
296
    }
297
    */
UNCOV
298
    metaDebug("batch drop table:%" PRId64, uid);
×
299
  }
UNCOV
300
  metaULock(pMeta);
×
301

302
  // update timeseries
UNCOV
303
  void   *pCtbDropped = NULL;
×
UNCOV
304
  int32_t iter = 0;
×
UNCOV
305
  while ((pCtbDropped = tSimpleHashIterate(suidHash, pCtbDropped, &iter))) {
×
UNCOV
306
    tb_uid_t    *pSuid = tSimpleHashGetKey(pCtbDropped, NULL);
×
UNCOV
307
    int32_t      nCols = 0;
×
UNCOV
308
    SVnodeStats *pStats = &pMeta->pVnode->config.vndStats;
×
UNCOV
309
    if (metaGetStbStats(pMeta->pVnode, *pSuid, NULL, &nCols) == 0) {
×
UNCOV
310
      pStats->numOfTimeSeries -= *(int64_t *)pCtbDropped * (nCols - 1);
×
311
    }
312
  }
UNCOV
313
  tSimpleHashCleanup(suidHash);
×
314

UNCOV
315
  pMeta->changed = true;
×
UNCOV
316
  return 0;
×
317
}
318

UNCOV
319
static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) {
×
UNCOV
320
  int32_t code = 0;
×
321
  // 1, tranverse table's
322
  // 2, validate table name using vnodeValidateTableHash
323
  // 3, push invalidated table's uid into uidList
324

325
  TBC *pCur;
UNCOV
326
  code = tdbTbcOpen(pMeta->pTbDb, &pCur, NULL);
×
327
  if (code < 0) {
×
UNCOV
328
    return code;
×
329
  }
330

UNCOV
331
  code = tdbTbcMoveToFirst(pCur);
×
332
  if (code) {
×
333
    tdbTbcClose(pCur);
×
UNCOV
334
    return code;
×
335
  }
336

UNCOV
337
  void *pData = NULL, *pKey = NULL;
×
UNCOV
338
  int   nData = 0, nKey = 0;
×
339

UNCOV
340
  while (1) {
×
UNCOV
341
    int32_t ret = tdbTbcNext(pCur, &pKey, &nKey, &pData, &nData);
×
UNCOV
342
    if (ret < 0) {
×
UNCOV
343
      break;
×
344
    }
345

UNCOV
346
    SMetaEntry me = {0};
×
UNCOV
347
    SDecoder   dc = {0};
×
UNCOV
348
    tDecoderInit(&dc, pData, nData);
×
UNCOV
349
    code = metaDecodeEntry(&dc, &me);
×
350
    if (code < 0) {
×
351
      tDecoderClear(&dc);
×
UNCOV
352
      return code;
×
353
    }
354

UNCOV
355
    if (me.type != TSDB_SUPER_TABLE) {
×
356
      char tbFName[TSDB_TABLE_FNAME_LEN + 1];
UNCOV
357
      snprintf(tbFName, sizeof(tbFName), "%s.%s", pMeta->pVnode->config.dbname, me.name);
×
UNCOV
358
      tbFName[TSDB_TABLE_FNAME_LEN] = '\0';
×
UNCOV
359
      int32_t ret = vnodeValidateTableHash(pMeta->pVnode, tbFName);
×
UNCOV
360
      if (ret < 0 && terrno == TSDB_CODE_VND_HASH_MISMATCH) {
×
361
        if (taosArrayPush(uidList, &me.uid) == NULL) {
×
362
          code = terrno;
×
UNCOV
363
          break;
×
364
        }
365
      }
366
    }
UNCOV
367
    tDecoderClear(&dc);
×
368
  }
UNCOV
369
  tdbFree(pData);
×
UNCOV
370
  tdbFree(pKey);
×
UNCOV
371
  tdbTbcClose(pCur);
×
372

UNCOV
373
  return 0;
×
374
}
375

UNCOV
376
int32_t metaTrimTables(SMeta *pMeta, int64_t version) {
×
UNCOV
377
  int32_t code = 0;
×
378

UNCOV
379
  SArray *tbUids = taosArrayInit(8, sizeof(int64_t));
×
380
  if (tbUids == NULL) {
×
UNCOV
381
    return terrno;
×
382
  }
383

UNCOV
384
  code = metaFilterTableByHash(pMeta, tbUids);
×
385
  if (code != 0) {
×
UNCOV
386
    goto end;
×
387
  }
UNCOV
388
  if (TARRAY_SIZE(tbUids) == 0) {
×
UNCOV
389
    goto end;
×
390
  }
391

UNCOV
392
  metaInfo("vgId:%d, trim %ld tables", TD_VID(pMeta->pVnode), taosArrayGetSize(tbUids));
×
UNCOV
393
  code = metaDropTables(pMeta, tbUids);
×
UNCOV
394
  if (code) goto end;
×
395

UNCOV
396
end:
×
UNCOV
397
  taosArrayDestroy(tbUids);
×
398

UNCOV
399
  return code;
×
400
}
401

UNCOV
402
int metaTtlFindExpired(SMeta *pMeta, int64_t timePointMs, SArray *tbUids, int32_t ttlDropMaxCount) {
×
UNCOV
403
  metaRLock(pMeta);
×
404

UNCOV
405
  int ret = ttlMgrFindExpired(pMeta->pTtlMgr, timePointMs, tbUids, ttlDropMaxCount);
×
406

UNCOV
407
  metaULock(pMeta);
×
408

409
  if (ret != 0) {
×
UNCOV
410
    metaError("ttl failed to find expired table, ret:%d", ret);
×
411
  }
412

UNCOV
413
  return ret;
×
414
}
415

UNCOV
416
static int metaBuildBtimeIdxKey(SBtimeIdxKey *btimeKey, const SMetaEntry *pME) {
×
417
  int64_t btime;
UNCOV
418
  if (pME->type == TSDB_CHILD_TABLE) {
×
UNCOV
419
    btime = pME->ctbEntry.btime;
×
UNCOV
420
  } else if (pME->type == TSDB_NORMAL_TABLE) {
×
UNCOV
421
    btime = pME->ntbEntry.btime;
×
422
  } else {
UNCOV
423
    return TSDB_CODE_FAILED;
×
424
  }
425

UNCOV
426
  btimeKey->btime = btime;
×
UNCOV
427
  btimeKey->uid = pME->uid;
×
UNCOV
428
  return 0;
×
429
}
430

UNCOV
431
static int metaBuildNColIdxKey(SNcolIdxKey *ncolKey, const SMetaEntry *pME) {
×
UNCOV
432
  if (pME->type == TSDB_NORMAL_TABLE) {
×
UNCOV
433
    ncolKey->ncol = pME->ntbEntry.schemaRow.nCols;
×
UNCOV
434
    ncolKey->uid = pME->uid;
×
435
  } else {
UNCOV
436
    return TSDB_CODE_FAILED;
×
437
  }
UNCOV
438
  return 0;
×
439
}
440

UNCOV
441
static void metaDeleteTtl(SMeta *pMeta, const SMetaEntry *pME) {
×
UNCOV
442
  if (pME->type != TSDB_CHILD_TABLE && pME->type != TSDB_NORMAL_TABLE) return;
×
443

UNCOV
444
  STtlDelTtlCtx ctx = {.uid = pME->uid, .pTxn = pMeta->txn};
×
UNCOV
445
  if (pME->type == TSDB_CHILD_TABLE) {
×
UNCOV
446
    ctx.ttlDays = pME->ctbEntry.ttlDays;
×
447
  } else {
UNCOV
448
    ctx.ttlDays = pME->ntbEntry.ttlDays;
×
449
  }
450

UNCOV
451
  int32_t ret = ttlMgrDeleteTtl(pMeta->pTtlMgr, &ctx);
×
452
  if (ret < 0) {
×
UNCOV
453
    metaError("vgId:%d, failed to delete ttl for table:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pME->name,
×
454
              pME->uid, tstrerror(ret));
455
  }
UNCOV
456
  return;
×
457
}
458

UNCOV
459
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *pSuid, int8_t *pSysTbl) {
×
UNCOV
460
  void      *pData = NULL;
×
UNCOV
461
  int        nData = 0;
×
UNCOV
462
  int        rc = 0;
×
UNCOV
463
  SMetaEntry e = {0};
×
UNCOV
464
  SDecoder   dc = {0};
×
UNCOV
465
  int32_t    ret = 0;
×
466

UNCOV
467
  rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData);
×
468
  if (rc < 0) {
×
UNCOV
469
    return rc;
×
470
  }
UNCOV
471
  int64_t version = ((SUidIdxVal *)pData)[0].version;
×
472

UNCOV
473
  rc = tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData);
×
474
  if (rc < 0) {
×
475
    tdbFree(pData);
×
UNCOV
476
    return rc;
×
477
  }
478

UNCOV
479
  tDecoderInit(&dc, pData, nData);
×
UNCOV
480
  rc = metaDecodeEntry(&dc, &e);
×
481
  if (rc < 0) {
×
482
    tDecoderClear(&dc);
×
UNCOV
483
    return rc;
×
484
  }
485

UNCOV
486
  if (type) *type = e.type;
×
487

UNCOV
488
  if (e.type == TSDB_CHILD_TABLE) {
×
UNCOV
489
    if (pSuid) *pSuid = e.ctbEntry.suid;
×
UNCOV
490
    void *tData = NULL;
×
UNCOV
491
    int   tLen = 0;
×
492

UNCOV
493
    if (tdbTbGet(pMeta->pUidIdx, &e.ctbEntry.suid, sizeof(tb_uid_t), &tData, &tLen) == 0) {
×
UNCOV
494
      STbDbKey tbDbKey = {.uid = e.ctbEntry.suid, .version = ((SUidIdxVal *)tData)[0].version};
×
UNCOV
495
      if (tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &tData, &tLen) == 0) {
×
UNCOV
496
        SDecoder   tdc = {0};
×
UNCOV
497
        SMetaEntry stbEntry = {0};
×
498

UNCOV
499
        tDecoderInit(&tdc, tData, tLen);
×
UNCOV
500
        int32_t ret = metaDecodeEntry(&tdc, &stbEntry);
×
501
        if (ret < 0) {
×
502
          tDecoderClear(&tdc);
×
UNCOV
503
          metaError("vgId:%d, failed to decode child table:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name,
×
504
                    e.ctbEntry.suid, tstrerror(ret));
UNCOV
505
          return ret;
×
506
        }
507

UNCOV
508
        if (pSysTbl) *pSysTbl = metaTbInFilterCache(pMeta, stbEntry.name, 1) ? 1 : 0;
×
509

UNCOV
510
        SSchema        *pTagColumn = NULL;
×
UNCOV
511
        SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag;
×
512
        if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
×
513
          pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0];
×
514
          ret = metaDelJsonVarFromIdx(pMeta, &e, pTagColumn);
×
515
          if (ret < 0) {
×
UNCOV
516
            metaError("vgId:%d, failed to delete json var from idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode),
×
517
                      e.name, e.uid, tstrerror(ret));
518
          }
519
        } else {
UNCOV
520
          for (int i = 0; i < pTagSchema->nCols; i++) {
×
UNCOV
521
            pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[i];
×
UNCOV
522
            if (!IS_IDX_ON(pTagColumn)) continue;
×
UNCOV
523
            STagIdxKey *pTagIdxKey = NULL;
×
524
            int32_t     nTagIdxKey;
525

UNCOV
526
            const void *pTagData = NULL;
×
UNCOV
527
            int32_t     nTagData = 0;
×
528

UNCOV
529
            STagVal tagVal = {.cid = pTagColumn->colId};
×
UNCOV
530
            if (tTagGet((const STag *)e.ctbEntry.pTags, &tagVal)) {
×
531
              if (IS_VAR_DATA_TYPE(pTagColumn->type)) {
×
532
                pTagData = tagVal.pData;
×
UNCOV
533
                nTagData = (int32_t)tagVal.nData;
×
534
              } else {
UNCOV
535
                pTagData = &(tagVal.i64);
×
UNCOV
536
                nTagData = tDataTypes[pTagColumn->type].bytes;
×
537
              }
538
            } else {
539
              if (!IS_VAR_DATA_TYPE(pTagColumn->type)) {
×
UNCOV
540
                nTagData = tDataTypes[pTagColumn->type].bytes;
×
541
              }
542
            }
543

UNCOV
544
            if (metaCreateTagIdxKey(e.ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type, uid,
×
545
                                    &pTagIdxKey, &nTagIdxKey) == 0) {
UNCOV
546
              ret = tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn);
×
547
              if (ret < 0) {
×
UNCOV
548
                metaError("vgId:%d, failed to delete tag idx key:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode),
×
549
                          e.name, e.uid, tstrerror(ret));
550
              }
551
            }
UNCOV
552
            metaDestroyTagIdxKey(pTagIdxKey);
×
UNCOV
553
            pTagIdxKey = NULL;
×
554
          }
555
        }
UNCOV
556
        tDecoderClear(&tdc);
×
557
      }
UNCOV
558
      tdbFree(tData);
×
559
    }
560
  }
561

UNCOV
562
  ret = tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), pMeta->txn);
×
563
  if (ret < 0) {
×
UNCOV
564
    metaError("vgId:%d, failed to delete table:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid,
×
565
              tstrerror(ret));
566
  }
UNCOV
567
  ret = tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, pMeta->txn);
×
568
  if (ret < 0) {
×
UNCOV
569
    metaError("vgId:%d, failed to delete name idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid,
×
570
              tstrerror(ret));
571
  }
UNCOV
572
  ret = tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), pMeta->txn);
×
573
  if (ret < 0) {
×
UNCOV
574
    metaError("vgId:%d, failed to delete uid idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid,
×
575
              tstrerror(ret));
576
  }
577

UNCOV
578
  if (e.type == TSDB_CHILD_TABLE || e.type == TSDB_NORMAL_TABLE) metaDeleteBtimeIdx(pMeta, &e);
×
UNCOV
579
  if (e.type == TSDB_NORMAL_TABLE) metaDeleteNcolIdx(pMeta, &e);
×
580

UNCOV
581
  if (e.type != TSDB_SUPER_TABLE) metaDeleteTtl(pMeta, &e);
×
582

UNCOV
583
  if (e.type == TSDB_CHILD_TABLE) {
×
584
    ret =
UNCOV
585
        tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), pMeta->txn);
×
586
    if (ret < 0) {
×
UNCOV
587
      metaError("vgId:%d, failed to delete ctb idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid,
×
588
                tstrerror(ret));
589
    }
590

UNCOV
591
    --pMeta->pVnode->config.vndStats.numOfCTables;
×
NEW
592
    metaUpdateStbStats(pMeta, e.ctbEntry.suid, -1, 0, -1);
×
UNCOV
593
    ret = metaUidCacheClear(pMeta, e.ctbEntry.suid);
×
594
    if (ret < 0) {
×
UNCOV
595
      metaError("vgId:%d, failed to clear uid cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name,
×
596
                e.ctbEntry.suid, tstrerror(ret));
597
    }
UNCOV
598
    ret = metaTbGroupCacheClear(pMeta, e.ctbEntry.suid);
×
599
    if (ret < 0) {
×
UNCOV
600
      metaError("vgId:%d, failed to clear group cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name,
×
601
                e.ctbEntry.suid, tstrerror(ret));
602
    }
603
    /*
604
    if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
605
      tsdbCacheDropTable(pMeta->pVnode->pTsdb, e.uid, e.ctbEntry.suid, NULL);
606
    }
607
    */
UNCOV
608
  } else if (e.type == TSDB_NORMAL_TABLE) {
×
609
    // drop schema.db (todo)
610

UNCOV
611
    --pMeta->pVnode->config.vndStats.numOfNTables;
×
UNCOV
612
    pMeta->pVnode->config.vndStats.numOfNTimeSeries -= e.ntbEntry.schemaRow.nCols - 1;
×
613

614
    /*
615
    if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
616
      tsdbCacheDropTable(pMeta->pVnode->pTsdb, e.uid, -1, &e.ntbEntry.schemaRow);
617
    }
618
    */
619
  } else if (e.type == TSDB_SUPER_TABLE) {
×
620
    ret = tdbTbDelete(pMeta->pSuidIdx, &e.uid, sizeof(tb_uid_t), pMeta->txn);
×
621
    if (ret < 0) {
×
UNCOV
622
      metaError("vgId:%d, failed to delete suid idx:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid,
×
623
                tstrerror(ret));
624
    }
625
    // drop schema.db (todo)
626

627
    ret = metaStatsCacheDrop(pMeta, uid);
×
628
    if (ret < 0) {
×
UNCOV
629
      metaError("vgId:%d, failed to drop stats cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid,
×
630
                tstrerror(ret));
631
    }
632
    ret = metaUidCacheClear(pMeta, uid);
×
633
    if (ret < 0) {
×
UNCOV
634
      metaError("vgId:%d, failed to clear uid cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid,
×
635
                tstrerror(ret));
636
    }
637
    ret = metaTbGroupCacheClear(pMeta, uid);
×
638
    if (ret < 0) {
×
UNCOV
639
      metaError("vgId:%d, failed to clear group cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name,
×
640
                e.uid, tstrerror(ret));
641
    }
UNCOV
642
    --pMeta->pVnode->config.vndStats.numOfSTables;
×
643
  }
644

UNCOV
645
  ret = metaCacheDrop(pMeta, uid);
×
UNCOV
646
  if (ret < 0) {
×
UNCOV
647
    metaError("vgId:%d, failed to drop cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.uid,
×
648
              tstrerror(ret));
649
  }
650

UNCOV
651
  tDecoderClear(&dc);
×
UNCOV
652
  tdbFree(pData);
×
653

UNCOV
654
  return 0;
×
655
}
656

UNCOV
657
static int metaDeleteBtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
×
UNCOV
658
  SBtimeIdxKey btimeKey = {0};
×
659
  if (metaBuildBtimeIdxKey(&btimeKey, pME) < 0) {
×
UNCOV
660
    return 0;
×
661
  }
UNCOV
662
  return tdbTbDelete(pMeta->pBtimeIdx, &btimeKey, sizeof(btimeKey), pMeta->txn);
×
663
}
664

UNCOV
665
int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
×
UNCOV
666
  SNcolIdxKey ncolKey = {0};
×
667
  if (metaBuildNColIdxKey(&ncolKey, pME) < 0) {
×
UNCOV
668
    return 0;
×
669
  }
UNCOV
670
  return tdbTbDelete(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), pMeta->txn);
×
671
}
672

UNCOV
673
int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pMetaRsp) {
×
UNCOV
674
  pMeta->changed = true;
×
UNCOV
675
  switch (pReq->action) {
×
UNCOV
676
    case TSDB_ALTER_TABLE_ADD_COLUMN:
×
677
    case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION:
UNCOV
678
      return metaAddTableColumn(pMeta, version, pReq, pMetaRsp);
×
UNCOV
679
    case TSDB_ALTER_TABLE_DROP_COLUMN:
×
UNCOV
680
      return metaDropTableColumn(pMeta, version, pReq, pMetaRsp);
×
UNCOV
681
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
×
UNCOV
682
      return metaAlterTableColumnBytes(pMeta, version, pReq, pMetaRsp);
×
UNCOV
683
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME:
×
UNCOV
684
      return metaAlterTableColumnName(pMeta, version, pReq, pMetaRsp);
×
UNCOV
685
    case TSDB_ALTER_TABLE_UPDATE_TAG_VAL:
×
UNCOV
686
      return metaUpdateTableTagValue(pMeta, version, pReq);
×
UNCOV
687
    case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL:
×
UNCOV
688
      return metaUpdateTableMultiTagValue(pMeta, version, pReq);
×
UNCOV
689
    case TSDB_ALTER_TABLE_UPDATE_OPTIONS:
×
UNCOV
690
      return metaUpdateTableOptions2(pMeta, version, pReq);
×
UNCOV
691
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS:
×
692
      return metaUpdateTableColCompress2(pMeta, version, pReq);
×
693
    default:
×
UNCOV
694
      return terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
×
695
      break;
696
  }
697
}
698

699
static int metaUpdateChangeTime(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs) {
×
UNCOV
700
  if (!tsTtlChangeOnWrite) return 0;
×
701

702
  if (changeTimeMs <= 0) {
×
703
    metaWarn("Skip to change ttl deletetion time on write, uid: %" PRId64, uid);
×
UNCOV
704
    return TSDB_CODE_VERSION_NOT_COMPATIBLE;
×
705
  }
706

UNCOV
707
  STtlUpdCtimeCtx ctx = {.uid = uid, .changeTimeMs = changeTimeMs, .pTxn = pMeta->txn};
×
708

UNCOV
709
  return ttlMgrUpdateChangeTime(pMeta->pTtlMgr, &ctx);
×
710
}
711

UNCOV
712
int metaUpdateChangeTimeWithLock(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs) {
×
UNCOV
713
  if (!tsTtlChangeOnWrite) return 0;
×
714

715
  metaWLock(pMeta);
×
716
  int ret = metaUpdateChangeTime(pMeta, uid, changeTimeMs);
×
717
  metaULock(pMeta);
×
UNCOV
718
  return ret;
×
719
}
720

UNCOV
721
int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void *pTagData, int32_t nTagData, int8_t type, tb_uid_t uid,
×
722
                        STagIdxKey **ppTagIdxKey, int32_t *nTagIdxKey) {
UNCOV
723
  if (IS_VAR_DATA_TYPE(type)) {
×
UNCOV
724
    *nTagIdxKey = sizeof(STagIdxKey) + nTagData + VARSTR_HEADER_SIZE + sizeof(tb_uid_t);
×
725
  } else {
UNCOV
726
    *nTagIdxKey = sizeof(STagIdxKey) + nTagData + sizeof(tb_uid_t);
×
727
  }
728

UNCOV
729
  *ppTagIdxKey = (STagIdxKey *)taosMemoryMalloc(*nTagIdxKey);
×
730
  if (*ppTagIdxKey == NULL) {
×
UNCOV
731
    return terrno;
×
732
  }
733

UNCOV
734
  taosSetInt64Aligned(&((*ppTagIdxKey)->suid), suid);
×
UNCOV
735
  (*ppTagIdxKey)->cid = cid;
×
UNCOV
736
  (*ppTagIdxKey)->isNull = (pTagData == NULL) ? 1 : 0;
×
UNCOV
737
  (*ppTagIdxKey)->type = type;
×
738

739
  // refactor
UNCOV
740
  if (IS_VAR_DATA_TYPE(type)) {
×
UNCOV
741
    memcpy((*ppTagIdxKey)->data, (uint16_t *)&nTagData, VARSTR_HEADER_SIZE);
×
UNCOV
742
    if (pTagData != NULL) memcpy((*ppTagIdxKey)->data + VARSTR_HEADER_SIZE, pTagData, nTagData);
×
UNCOV
743
    taosSetInt64Aligned((tb_uid_t *)((*ppTagIdxKey)->data + VARSTR_HEADER_SIZE + nTagData), uid);
×
744
  } else {
UNCOV
745
    if (pTagData != NULL) memcpy((*ppTagIdxKey)->data, pTagData, nTagData);
×
UNCOV
746
    taosSetInt64Aligned((tb_uid_t *)((*ppTagIdxKey)->data + nTagData), uid);
×
747
  }
748

UNCOV
749
  return 0;
×
750
}
751

UNCOV
752
void metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey) {
×
UNCOV
753
  if (pTagIdxKey) taosMemoryFree(pTagIdxKey);
×
UNCOV
754
}
×
755

UNCOV
756
static void colCompressDebug(SHashObj *pColCmprObj) {
×
UNCOV
757
  void *p = taosHashIterate(pColCmprObj, NULL);
×
UNCOV
758
  while (p) {
×
UNCOV
759
    uint32_t cmprAlg = *(uint32_t *)p;
×
UNCOV
760
    col_id_t colId = *(col_id_t *)taosHashGetKey(p, NULL);
×
UNCOV
761
    p = taosHashIterate(pColCmprObj, p);
×
762

763
    uint8_t l1, l2, lvl;
UNCOV
764
    tcompressDebug(cmprAlg, &l1, &l2, &lvl);
×
765

UNCOV
766
    const char *l1str = columnEncodeStr(l1);
×
UNCOV
767
    const char *l2str = columnCompressStr(l2);
×
UNCOV
768
    const char *lvlstr = columnLevelStr(lvl);
×
UNCOV
769
    metaDebug("colId: %d, encode:%s, compress:%s,level:%s", colId, l1str, l2str, lvlstr);
×
770
  }
UNCOV
771
  return;
×
772
}
773

UNCOV
774
int32_t metaGetColCmpr(SMeta *pMeta, tb_uid_t uid, SHashObj **ppColCmprObj) {
×
UNCOV
775
  int rc = 0;
×
776

UNCOV
777
  SHashObj *pColCmprObj = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_SMALLINT), false, HASH_NO_LOCK);
×
778
  if (pColCmprObj == NULL) {
×
779
    pColCmprObj = NULL;
×
UNCOV
780
    return TSDB_CODE_OUT_OF_MEMORY;
×
781
  }
782

UNCOV
783
  void      *pData = NULL;
×
UNCOV
784
  int        nData = 0;
×
UNCOV
785
  SMetaEntry e = {0};
×
UNCOV
786
  SDecoder   dc = {0};
×
787

UNCOV
788
  *ppColCmprObj = NULL;
×
789

UNCOV
790
  metaRLock(pMeta);
×
UNCOV
791
  rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData);
×
792
  if (rc < 0) {
×
793
    taosHashClear(pColCmprObj);
×
794
    metaULock(pMeta);
×
UNCOV
795
    return TSDB_CODE_FAILED;
×
796
  }
UNCOV
797
  int64_t version = ((SUidIdxVal *)pData)[0].version;
×
UNCOV
798
  rc = tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData);
×
799
  if (rc < 0) {
×
800
    metaULock(pMeta);
×
801
    taosHashClear(pColCmprObj);
×
802
    metaError("failed to get table entry");
×
UNCOV
803
    return rc;
×
804
  }
805

UNCOV
806
  tDecoderInit(&dc, pData, nData);
×
UNCOV
807
  rc = metaDecodeEntry(&dc, &e);
×
808
  if (rc < 0) {
×
809
    tDecoderClear(&dc);
×
810
    tdbFree(pData);
×
811
    metaULock(pMeta);
×
812
    taosHashClear(pColCmprObj);
×
UNCOV
813
    return rc;
×
814
  }
UNCOV
815
  if (useCompress(e.type)) {
×
UNCOV
816
    SColCmprWrapper *p = &e.colCmpr;
×
UNCOV
817
    for (int32_t i = 0; i < p->nCols; i++) {
×
UNCOV
818
      SColCmpr *pCmpr = &p->pColCmpr[i];
×
UNCOV
819
      rc = taosHashPut(pColCmprObj, &pCmpr->id, sizeof(pCmpr->id), &pCmpr->alg, sizeof(pCmpr->alg));
×
820
      if (rc < 0) {
×
821
        tDecoderClear(&dc);
×
822
        tdbFree(pData);
×
823
        metaULock(pMeta);
×
824
        taosHashClear(pColCmprObj);
×
UNCOV
825
        return rc;
×
826
      }
827
    }
828
  } else {
829
    tDecoderClear(&dc);
×
830
    tdbFree(pData);
×
831
    metaULock(pMeta);
×
832
    taosHashClear(pColCmprObj);
×
UNCOV
833
    return 0;
×
834
  }
UNCOV
835
  tDecoderClear(&dc);
×
UNCOV
836
  tdbFree(pData);
×
UNCOV
837
  metaULock(pMeta);
×
838

UNCOV
839
  *ppColCmprObj = pColCmprObj;
×
UNCOV
840
  colCompressDebug(pColCmprObj);
×
841

UNCOV
842
  return 0;
×
843
}
844
// refactor later
UNCOV
845
void *metaGetIdx(SMeta *pMeta) { return pMeta->pTagIdx; }
×
UNCOV
846
void *metaGetIvtIdx(SMeta *pMeta) { return pMeta->pTagIvtIdx; }
×
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