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

taosdata / TDengine / #3561

19 Dec 2024 03:15AM UTC coverage: 58.812% (-1.3%) from 60.124%
#3561

push

travis-ci

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

merge: from main to 3.0 branch

130770 of 287658 branches covered (45.46%)

Branch coverage included in aggregate %.

32 of 78 new or added lines in 4 files covered. (41.03%)

7347 existing lines in 166 files now uncovered.

205356 of 283866 relevant lines covered (72.34%)

7187865.64 hits per line

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

61.44
/source/dnode/vnode/src/meta/metaEntry2.c
1
/*
2
 * Copyright (c) 2023 Hongze Cheng <hzcheng@umich.edu>.
3
 * All rights reserved.
4
 *
5
 * This code is the intellectual property of Hongze Cheng.
6
 * Any reproduction or distribution, in whole or in part,
7
 * without the express written permission of Hongze Cheng is
8
 * strictly prohibited.
9
 */
10

11
#include "meta.h"
12

13
int32_t metaCloneEntry(const SMetaEntry *pEntry, SMetaEntry **ppEntry);
14
void    metaCloneEntryFree(SMetaEntry **ppEntry);
15
void    metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey);
16
int     metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema);
17
int     metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema);
18
void    metaTimeSeriesNotifyCheck(SMeta *pMeta);
19
int     tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
20

21
static int32_t metaGetChildUidsOfSuperTable(SMeta *pMeta, tb_uid_t suid, SArray **childList);
22
static int32_t metaFetchTagIdxKey(SMeta *pMeta, const SMetaEntry *pEntry, const SSchema *pTagColumn,
23
                                  STagIdxKey **ppTagIdxKey, int32_t *pTagIdxKeySize);
24
static void    metaFetchTagIdxKeyFree(STagIdxKey **ppTagIdxKey);
25

26
#define metaErr(VGID, ERRNO)                                                                                     \
27
  do {                                                                                                           \
28
    metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " type:%d uid:%" PRId64 " name:%s", VGID, \
29
              __func__, __FILE__, __LINE__, tstrerror(ERRNO), pEntry->version, pEntry->type, pEntry->uid,        \
30
              pEntry->type > 0 ? pEntry->name : NULL);                                                           \
31
  } while (0)
32

33
typedef enum {
34
  META_ENTRY_TABLE = 0,
35
  META_SCHEMA_TABLE,
36
  META_UID_IDX,
37
  META_NAME_IDX,
38
  META_SUID_IDX,
39
  META_CHILD_IDX,
40
  META_TAG_IDX,
41
  META_BTIME_IDX,
42
  META_TTL_IDX,
43
  META_TABLE_MAX,
44
} EMetaTable;
45

46
typedef enum {
47
  META_TABLE_OP_INSERT = 0,
48
  META_TABLE_OP_UPDATA,
49
  META_TABLE_OP_DELETE,
50
  META_TABLE_OP_MAX,
51
} EMetaTableOp;
52

53
typedef struct {
54
  const SMetaEntry *pEntry;
55
  const SMetaEntry *pSuperEntry;
56
  const SMetaEntry *pOldEntry;
57
} SMetaHandleParam;
58

59
typedef struct {
60
  EMetaTable   table;
61
  EMetaTableOp op;
62
} SMetaTableOp;
63

64
int32_t metaFetchEntryByUid(SMeta *pMeta, int64_t uid, SMetaEntry **ppEntry) {
215,037✔
65
  int32_t code = TSDB_CODE_SUCCESS;
215,037✔
66
  void   *value = NULL;
215,037✔
67
  int32_t valueSize = 0;
215,037✔
68

69
  // search uid index
70
  code = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &value, &valueSize);
215,037✔
71
  if (TSDB_CODE_SUCCESS != code) {
215,100!
72
    metaError("vgId:%d, failed to get entry by uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), uid, tstrerror(code));
×
73
    return code;
×
74
  }
75

76
  // search entry table
77
  STbDbKey key = {
215,100✔
78
      .version = ((SUidIdxVal *)value)->version,
215,100✔
79
      .uid = uid,
80
  };
81
  tdbFreeClear(value);
215,100✔
82

83
  code = tdbTbGet(pMeta->pTbDb, &key, sizeof(key), &value, &valueSize);
215,092✔
84
  if (TSDB_CODE_SUCCESS != code) {
215,085!
85
    metaError("vgId:%d, failed to get entry by uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), uid, tstrerror(code));
×
86
    code = TSDB_CODE_INTERNAL_ERROR;
×
87
    return code;
×
88
  }
89

90
  // decode entry
91
  SDecoder   decoder = {0};
215,085✔
92
  SMetaEntry entry = {0};
215,085✔
93

94
  tDecoderInit(&decoder, value, valueSize);
215,085✔
95
  code = metaDecodeEntry(&decoder, &entry);
215,065✔
96
  if (code) {
215,015!
97
    metaError("vgId:%d, failed to decode entry by uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), uid,
×
98
              tstrerror(code));
99
    tDecoderClear(&decoder);
×
100
    tdbFreeClear(value);
×
101
    return code;
×
102
  }
103

104
  code = metaCloneEntry(&entry, ppEntry);
215,015✔
105
  if (code) {
215,049!
106
    metaError("vgId:%d, failed to clone entry by uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), uid,
×
107
              tstrerror(code));
108
    tDecoderClear(&decoder);
×
109
    tdbFreeClear(value);
×
110
    return code;
×
111
  }
112

113
  tdbFreeClear(value);
215,049✔
114
  tDecoderClear(&decoder);
215,059✔
115
  return code;
215,080✔
116
}
117

118
int32_t metaFetchEntryByName(SMeta *pMeta, const char *name, SMetaEntry **ppEntry) {
7,016✔
119
  int32_t code = TSDB_CODE_SUCCESS;
7,016✔
120
  void   *value = NULL;
7,016✔
121
  int32_t valueSize = 0;
7,016✔
122

123
  code = tdbTbGet(pMeta->pNameIdx, name, strlen(name) + 1, &value, &valueSize);
7,016✔
124
  if (TSDB_CODE_SUCCESS != code) {
7,016!
125
    metaError("vgId:%d, failed to get entry by name:%s since %s", TD_VID(pMeta->pVnode), name, tstrerror(code));
×
126
    return code;
×
127
  }
128
  int64_t uid = *(int64_t *)value;
7,016✔
129
  tdbFreeClear(value);
7,016✔
130

131
  code = metaFetchEntryByUid(pMeta, uid, ppEntry);
7,016✔
132
  if (TSDB_CODE_SUCCESS != code) {
7,016!
133
    metaError("vgId:%d, failed to get entry by uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), uid, tstrerror(code));
×
134
    code = TSDB_CODE_INTERNAL_ERROR;
×
135
  }
136
  return code;
7,016✔
137
}
138

139
void metaFetchEntryFree(SMetaEntry **ppEntry) { metaCloneEntryFree(ppEntry); }
215,037✔
140

141
// Entry Table
142
static int32_t metaEntryTableUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
229,516✔
143
  const SMetaEntry *pEntry = pParam->pEntry;
229,516✔
144

145
  int32_t  code = TSDB_CODE_SUCCESS;
229,516✔
146
  int32_t  vgId = TD_VID(pMeta->pVnode);
229,516✔
147
  void    *value = NULL;
229,516✔
148
  int32_t  valueSize = 0;
229,516✔
149
  SEncoder encoder = {0};
229,516✔
150
  STbDbKey key = {
229,516✔
151
      .version = pEntry->version,
229,516✔
152
      .uid = pEntry->uid,
229,516✔
153
  };
154

155
  // encode entry
156
  tEncodeSize(metaEncodeEntry, pEntry, valueSize, code);
229,516!
157
  if (code != 0) {
229,460!
158
    metaErr(vgId, code);
×
159
    return code;
×
160
  }
161

162
  value = taosMemoryMalloc(valueSize);
229,460!
163
  if (NULL == value) {
229,453!
164
    metaErr(vgId, terrno);
×
165
    return terrno;
×
166
  }
167

168
  tEncoderInit(&encoder, value, valueSize);
229,453✔
169
  code = metaEncodeEntry(&encoder, pEntry);
229,466✔
170
  if (code) {
229,413!
171
    metaErr(vgId, code);
×
172
    tEncoderClear(&encoder);
×
173
    taosMemoryFree(value);
×
174
    return code;
×
175
  }
176
  tEncoderClear(&encoder);
229,413✔
177

178
  // put to tdb
179
  if (META_TABLE_OP_INSERT == op) {
229,475✔
180
    code = tdbTbInsert(pMeta->pTbDb, &key, sizeof(key), value, valueSize, pMeta->txn);
218,501✔
181
  } else if (META_TABLE_OP_UPDATA == op) {
10,974✔
182
    code = tdbTbUpsert(pMeta->pTbDb, &key, sizeof(key), value, valueSize, pMeta->txn);
6,989✔
183
  } else if (META_TABLE_OP_DELETE == op) {
3,985✔
184
    code = tdbTbInsert(pMeta->pTbDb, &key, sizeof(key), value, valueSize, pMeta->txn);
3,984✔
185
  } else {
186
    code = TSDB_CODE_INVALID_PARA;
1✔
187
  }
188
  if (TSDB_CODE_SUCCESS != code) {
229,593!
189
    metaErr(vgId, code);
×
190
  }
191
  taosMemoryFree(value);
229,584!
192
  return code;
229,562✔
193
}
194

195
static int32_t metaEntryTableInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
218,251✔
196
  return metaEntryTableUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
218,251✔
197
}
198

199
static int32_t metaEntryTableUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
6,989✔
200
  return metaEntryTableUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
6,989✔
201
}
202

203
static int32_t metaEntryTableDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
3,985✔
204
  return metaEntryTableUpsert(pMeta, pParam, META_TABLE_OP_DELETE);
3,985✔
205
}
206

207
// Schema Table
208
static int32_t metaSchemaTableUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
32,897✔
209
  int32_t  code = TSDB_CODE_SUCCESS;
32,897✔
210
  int32_t  vgId = TD_VID(pMeta->pVnode);
32,897✔
211
  SEncoder encoder = {0};
32,897✔
212
  void    *value = NULL;
32,897✔
213
  int32_t  valueSize = 0;
32,897✔
214

215
  const SMetaEntry     *pEntry = pParam->pEntry;
32,897✔
216
  const SSchemaWrapper *pSchema = NULL;
32,897✔
217
  if (pEntry->type == TSDB_SUPER_TABLE) {
32,897✔
218
    pSchema = &pEntry->stbEntry.schemaRow;
19,609✔
219
  } else if (pEntry->type == TSDB_NORMAL_TABLE) {
13,288!
220
    pSchema = &pEntry->ntbEntry.schemaRow;
13,319✔
221
  } else {
222
    return TSDB_CODE_INVALID_PARA;
×
223
  }
224
  SSkmDbKey key = {
32,928✔
225
      .uid = pEntry->uid,
32,928✔
226
      .sver = pSchema->version,
32,928✔
227
  };
228

229
  // encode schema
230
  tEncodeSize(tEncodeSSchemaWrapper, pSchema, valueSize, code);
65,844✔
231
  if (TSDB_CODE_SUCCESS != code) {
32,834!
232
    metaErr(vgId, code);
×
233
    return code;
×
234
  }
235

236
  value = taosMemoryMalloc(valueSize);
32,834!
237
  if (NULL == value) {
32,801!
238
    metaErr(vgId, terrno);
×
239
    return terrno;
×
240
  }
241

242
  tEncoderInit(&encoder, value, valueSize);
32,801✔
243
  code = tEncodeSSchemaWrapper(&encoder, pSchema);
32,809✔
244
  if (TSDB_CODE_SUCCESS != code) {
32,809!
245
    metaErr(vgId, code);
×
246
    tEncoderClear(&encoder);
×
247
    taosMemoryFree(value);
×
248
    return code;
×
249
  }
250
  tEncoderClear(&encoder);
32,809✔
251

252
  // put to tdb
253
  if (META_TABLE_OP_INSERT == op) {
32,855!
254
    code = tdbTbInsert(pMeta->pSkmDb, &key, sizeof(key), value, valueSize, pMeta->txn);
×
255
  } else if (META_TABLE_OP_UPDATA == op) {
32,865!
256
    code = tdbTbUpsert(pMeta->pSkmDb, &key, sizeof(key), value, valueSize, pMeta->txn);
32,865✔
257
  } else {
258
    code = TSDB_CODE_INVALID_PARA;
×
259
  }
260
  if (TSDB_CODE_SUCCESS != code) {
32,982!
261
    metaErr(vgId, code);
×
262
  }
263
  taosMemoryFree(value);
32,982!
264
  return code;
32,969✔
265
}
266

267
static int32_t metaSchemaTableInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
268
  return metaSchemaTableUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
×
269
}
270

271
static int32_t metaAddOrDropTagIndexOfSuperTable(SMeta *pMeta, const SMetaHandleParam *pParam,
83,506✔
272
                                                 const SSchema *pOldColumn, const SSchema *pNewColumn) {
273
  int32_t code = TSDB_CODE_SUCCESS;
83,506✔
274

275
  const SMetaEntry *pEntry = pParam->pEntry;
83,506✔
276
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
83,506✔
277
  enum { ADD_INDEX, DROP_INDEX } action;
278

279
  if (pOldColumn && pNewColumn) {
83,506✔
280
    if (IS_IDX_ON(pOldColumn) && IS_IDX_ON(pNewColumn)) {
81,831✔
281
      return TSDB_CODE_SUCCESS;
2,957✔
282
    } else if (IS_IDX_ON(pOldColumn) && !IS_IDX_ON(pNewColumn)) {
78,874!
283
      action = DROP_INDEX;
60✔
284
    } else if (!IS_IDX_ON(pOldColumn) && IS_IDX_ON(pNewColumn)) {
78,814!
285
      action = ADD_INDEX;
21✔
286
    } else {
287
      return TSDB_CODE_SUCCESS;
78,793✔
288
    }
289
  } else if (pOldColumn) {
1,675✔
290
    if (IS_IDX_ON(pOldColumn)) {
720✔
291
      action = DROP_INDEX;
15✔
292
    } else {
293
      return TSDB_CODE_SUCCESS;
705✔
294
    }
295
  } else {
296
    if (IS_IDX_ON(pNewColumn)) {
955!
297
      action = ADD_INDEX;
×
298
    } else {
299
      return TSDB_CODE_SUCCESS;
955✔
300
    }
301
  }
302

303
  // fetch all child tables
304
  SArray *childTables = 0;
96✔
305
  code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &childTables);
96✔
306
  if (code) {
95!
307
    metaErr(TD_VID(pMeta->pVnode), code);
×
308
    return code;
×
309
  }
310

311
  // do drop or add index
312
  for (int32_t i = 0; i < taosArrayGetSize(childTables); i++) {
340✔
313
    int64_t uid = *(int64_t *)taosArrayGet(childTables, i);
245✔
314

315
    // fetch child entry
316
    SMetaEntry *pChildEntry = NULL;
245✔
317
    code = metaFetchEntryByUid(pMeta, uid, &pChildEntry);
245✔
318
    if (code) {
245!
319
      metaErr(TD_VID(pMeta->pVnode), code);
×
320
      taosArrayDestroy(childTables);
×
321
      return code;
×
322
    }
323

324
    STagIdxKey *pTagIdxKey = NULL;
245✔
325
    int32_t     tagIdxKeySize = 0;
245✔
326

327
    if (action == ADD_INDEX) {
245✔
328
      code = metaFetchTagIdxKey(pMeta, pChildEntry, pNewColumn, &pTagIdxKey, &tagIdxKeySize);
111✔
329
      if (code) {
111!
330
        metaErr(TD_VID(pMeta->pVnode), code);
×
331
        taosArrayDestroy(childTables);
×
332
        metaFetchEntryFree(&pChildEntry);
×
333
        return code;
×
334
      }
335

336
      code = tdbTbInsert(pMeta->pTagIdx, pTagIdxKey, tagIdxKeySize, NULL, 0, pMeta->txn);
111✔
337
      if (code) {
111!
338
        metaErr(TD_VID(pMeta->pVnode), code);
×
339
        taosArrayDestroy(childTables);
×
340
        metaFetchEntryFree(&pChildEntry);
×
341
        metaFetchTagIdxKeyFree(&pTagIdxKey);
×
342
        return code;
×
343
      }
344
    } else {
345
      code = metaFetchTagIdxKey(pMeta, pChildEntry, pOldColumn, &pTagIdxKey, &tagIdxKeySize);
134✔
346
      if (code) {
134!
347
        metaErr(TD_VID(pMeta->pVnode), code);
×
348
        taosArrayDestroy(childTables);
×
349
        metaFetchEntryFree(&pChildEntry);
×
350
        return code;
×
351
      }
352

353
      code = tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, tagIdxKeySize, pMeta->txn);
134✔
354
      if (code) {
134!
355
        metaErr(TD_VID(pMeta->pVnode), code);
×
356
        taosArrayDestroy(childTables);
×
357
        metaFetchEntryFree(&pChildEntry);
×
358
        metaFetchTagIdxKeyFree(&pTagIdxKey);
×
359
        return code;
×
360
      }
361
    }
362

363
    metaFetchTagIdxKeyFree(&pTagIdxKey);
245✔
364
    metaFetchEntryFree(&pChildEntry);
245✔
365
  }
366

367
  taosArrayDestroy(childTables);
95✔
368
  return code;
96✔
369
}
370

371
static int32_t metaUpdateSuperTableTagSchema(SMeta *pMeta, const SMetaHandleParam *pParam) {
3,071✔
372
  int32_t               code = TSDB_CODE_SUCCESS;
3,071✔
373
  const SMetaEntry     *pEntry = pParam->pEntry;
3,071✔
374
  const SMetaEntry     *pOldEntry = pParam->pOldEntry;
3,071✔
375
  const SSchemaWrapper *pNewTagSchema = &pEntry->stbEntry.schemaTag;
3,071✔
376
  const SSchemaWrapper *pOldTagSchema = &pOldEntry->stbEntry.schemaTag;
3,071✔
377

378
  int32_t iOld = 0, iNew = 0;
3,071✔
379
  for (; iOld < pOldTagSchema->nCols && iNew < pNewTagSchema->nCols;) {
85,488✔
380
    SSchema *pOldColumn = pOldTagSchema->pSchema + iOld;
82,418✔
381
    SSchema *pNewColumn = pNewTagSchema->pSchema + iNew;
82,418✔
382

383
    if (pOldColumn->colId == pNewColumn->colId) {
82,418✔
384
      code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, pOldColumn, pNewColumn);
81,831✔
385
      if (code) {
81,832✔
386
        metaErr(TD_VID(pMeta->pVnode), code);
1!
387
        return code;
×
388
      }
389

390
      iOld++;
81,831✔
391
      iNew++;
81,831✔
392
    } else if (pOldColumn->colId < pNewColumn->colId) {
587!
393
      code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, pOldColumn, NULL);
587✔
394
      if (code) {
587✔
395
        metaErr(TD_VID(pMeta->pVnode), code);
1!
396
        return code;
×
397
      }
398

399
      iOld++;
586✔
400
    } else {
401
      code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, NULL, pNewColumn);
×
402
      if (code) {
×
403
        metaErr(TD_VID(pMeta->pVnode), code);
×
404
        return code;
×
405
      }
406

407
      iNew++;
×
408
    }
409
  }
410

411
  for (; iOld < pOldTagSchema->nCols; iOld++) {
3,203✔
412
    SSchema *pOldColumn = pOldTagSchema->pSchema + iOld;
133✔
413
    code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, pOldColumn, NULL);
133✔
414
    if (code) {
133!
415
      metaErr(TD_VID(pMeta->pVnode), code);
×
416
      return code;
×
417
    }
418
  }
419

420
  for (; iNew < pNewTagSchema->nCols; iNew++) {
4,027✔
421
    SSchema *pNewColumn = pNewTagSchema->pSchema + iNew;
957✔
422
    code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, NULL, pNewColumn);
957✔
423
    if (code) {
957!
424
      metaErr(TD_VID(pMeta->pVnode), code);
×
425
      return code;
×
426
    }
427
  }
428

429
  return code;
3,070✔
430
}
431

432
static int32_t metaSchemaTableUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
35,990✔
433
  int32_t code = TSDB_CODE_SUCCESS;
35,990✔
434

435
  const SMetaEntry *pEntry = pParam->pEntry;
35,990✔
436
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
35,990✔
437

438
  if (NULL == pOldEntry) {
35,990✔
439
    return metaSchemaTableUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
29,693✔
440
  }
441

442
  if (pEntry->type == TSDB_NORMAL_TABLE) {
6,297✔
443
    // check row schema
444
    if (pOldEntry->ntbEntry.schemaRow.version != pEntry->ntbEntry.schemaRow.version) {
192✔
445
      return metaSchemaTableUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
160✔
446
    }
447
  } else if (pEntry->type == TSDB_SUPER_TABLE) {
6,105!
448
    // check row schema
449
    if (pOldEntry->stbEntry.schemaRow.version != pEntry->stbEntry.schemaRow.version) {
6,129✔
450
      return metaSchemaTableUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
3,058✔
451
    }
452

453
    // check tag schema
454
    code = metaUpdateSuperTableTagSchema(pMeta, pParam);
3,071✔
455
    if (code) {
3,071!
UNCOV
456
      metaErr(TD_VID(pMeta->pVnode), code);
×
457
      return code;
×
458
    }
459

460
  } else {
461
    return TSDB_CODE_INVALID_PARA;
×
462
  }
463

464
  return TSDB_CODE_SUCCESS;
3,103✔
465
}
466

467
static int32_t metaSchemaTableDelete(SMeta *pMeta, const SMetaHandleParam *pEntry) {
×
468
  // TODO
469
  return TSDB_CODE_SUCCESS;
×
470
}
471

472
// Uid Index
473
static void metaBuildEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
225,472✔
474
  pInfo->uid = pEntry->uid;
225,472✔
475
  pInfo->version = pEntry->version;
225,472✔
476
  if (pEntry->type == TSDB_SUPER_TABLE) {
225,472✔
477
    pInfo->suid = pEntry->uid;
22,689✔
478
    pInfo->skmVer = pEntry->stbEntry.schemaRow.version;
22,689✔
479
  } else if (pEntry->type == TSDB_CHILD_TABLE) {
202,783✔
480
    pInfo->suid = pEntry->ctbEntry.suid;
189,527✔
481
    pInfo->skmVer = 0;
189,527✔
482
  } else if (pEntry->type == TSDB_NORMAL_TABLE) {
13,256!
483
    pInfo->suid = 0;
13,351✔
484
    pInfo->skmVer = pEntry->ntbEntry.schemaRow.version;
13,351✔
485
  }
486
}
225,472✔
487

488
static int32_t metaUidIdxUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
225,487✔
489
  int32_t code = TSDB_CODE_SUCCESS;
225,487✔
490
  int32_t vgId = TD_VID(pMeta->pVnode);
225,487✔
491

492
  const SMetaEntry *pEntry = pParam->pEntry;
225,487✔
493

494
  // update cache
495
  SMetaInfo info = {0};
225,487✔
496
  metaBuildEntryInfo(pEntry, &info);
225,487✔
497
  code = metaCacheUpsert(pMeta, &info);
225,578✔
498
  if (code) {
225,504!
499
    metaErr(vgId, code);
×
500
  }
501

502
  // put to tdb
503
  SUidIdxVal value = {
225,451✔
504
      .suid = info.suid,
225,451✔
505
      .skmVer = info.skmVer,
225,451✔
506
      .version = pEntry->version,
225,451✔
507
  };
508
  if (META_TABLE_OP_INSERT == op) {
225,451✔
509
    code = tdbTbInsert(pMeta->pUidIdx, &pEntry->uid, sizeof(pEntry->uid), &value, sizeof(value), pMeta->txn);
218,463✔
510
  } else if (META_TABLE_OP_UPDATA == op) {
6,988!
511
    code = tdbTbUpsert(pMeta->pUidIdx, &pEntry->uid, sizeof(pEntry->uid), &value, sizeof(value), pMeta->txn);
6,988✔
512
  }
513
  return code;
225,653✔
514
}
515

516
static int32_t metaUidIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
218,507✔
517
  return metaUidIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
218,507✔
518
}
519

520
static int32_t metaUidIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
6,988✔
521
  return metaUidIdxUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
6,988✔
522
}
523

524
static int32_t metaUidIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
7,198✔
525
  int32_t code = 0;
7,198✔
526

527
  const SMetaEntry *pEntry = pParam->pOldEntry;
7,198✔
528

529
  // delete tdb
530
  code = tdbTbDelete(pMeta->pUidIdx, &pEntry->uid, sizeof(pEntry->uid), pMeta->txn);
7,198✔
531
  if (code) {
7,199!
532
    metaErr(TD_VID(pMeta->pVnode), code);
×
533
  }
534

535
  // delete cache
536
  (void)metaCacheDrop(pMeta, pEntry->uid);
7,199✔
537
  return code;
7,199✔
538
}
539

540
// Name Index
541
static int32_t metaNameIdxUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
218,549✔
542
  int32_t code = TSDB_CODE_SUCCESS;
218,549✔
543

544
  const SMetaEntry *pEntry = pParam->pEntry;
218,549✔
545

546
  if (META_TABLE_OP_INSERT == op) {
218,549!
547
    code = tdbTbInsert(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, &pEntry->uid, sizeof(pEntry->uid),
218,570✔
548
                       pMeta->txn);
549
  } else if (META_TABLE_OP_UPDATA == op) {
×
550
    code = tdbTbUpsert(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, &pEntry->uid, sizeof(pEntry->uid),
×
551
                       pMeta->txn);
552
  } else {
553
    code = TSDB_CODE_INVALID_PARA;
×
554
  }
555
  return code;
218,644✔
556
}
557

558
static int32_t metaNameIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
218,569✔
559
  int32_t code = TSDB_CODE_SUCCESS;
218,569✔
560
  return metaNameIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
218,569✔
561
}
562

563
static int32_t metaNameIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
564
  return metaNameIdxUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
×
565
}
566

567
static int32_t metaNameIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
7,198✔
568
  int32_t code = TSDB_CODE_SUCCESS;
7,198✔
569

570
  const SMetaEntry *pEntry = pParam->pOldEntry;
7,198✔
571
  code = tdbTbDelete(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, pMeta->txn);
7,198✔
572
  if (code) {
7,199!
573
    metaErr(TD_VID(pMeta->pVnode), code);
×
574
  }
575
  return code;
7,199✔
576
}
577

578
// Suid Index
579
static int32_t metaSUidIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
16,543✔
580
  const SMetaEntry *pEntry = pParam->pEntry;
16,543✔
581

582
  int32_t code = tdbTbInsert(pMeta->pSuidIdx, &pEntry->uid, sizeof(pEntry->uid), NULL, 0, pMeta->txn);
16,543✔
583
  if (code) {
16,616!
584
    metaErr(TD_VID(pMeta->pVnode), code);
×
585
  }
586
  return code;
16,565✔
587
}
588

589
static int32_t metaSUidIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
2,089✔
590
  const SMetaEntry *pEntry = pParam->pOldEntry;
2,089✔
591

592
  int32_t code = tdbTbDelete(pMeta->pSuidIdx, &pEntry->uid, sizeof(pEntry->uid), pMeta->txn);
2,089✔
593
  if (code) {
2,088!
594
    metaErr(TD_VID(pMeta->pVnode), code);
×
595
  }
596
  return code;
2,088✔
597
}
598

599
// Child Index
600
static int32_t metaChildIdxUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
189,322✔
601
  int32_t code = TSDB_CODE_SUCCESS;
189,322✔
602

603
  const SMetaEntry *pEntry = pParam->pEntry;
189,322✔
604

605
  SCtbIdxKey key = {
189,322✔
606
      .suid = pEntry->ctbEntry.suid,
189,322✔
607
      .uid = pEntry->uid,
189,322✔
608
  };
609

610
  if (META_TABLE_OP_INSERT == op) {
189,322✔
611
    code = tdbTbInsert(pMeta->pCtbIdx, &key, sizeof(key), pEntry->ctbEntry.pTags,
188,867✔
612
                       ((STag *)(pEntry->ctbEntry.pTags))->len, pMeta->txn);
188,867✔
613
  } else if (META_TABLE_OP_UPDATA == op) {
455!
614
    code = tdbTbUpsert(pMeta->pCtbIdx, &key, sizeof(key), pEntry->ctbEntry.pTags,
461✔
615
                       ((STag *)(pEntry->ctbEntry.pTags))->len, pMeta->txn);
461✔
616
  } else {
617
    code = TSDB_CODE_INVALID_PARA;
×
618
  }
619
  return code;
189,343✔
620
}
621

622
static int32_t metaChildIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
188,861✔
623
  return metaChildIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
188,861✔
624
}
625

626
static int32_t metaChildIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
668✔
627
  const SMetaEntry *pEntry = pParam->pEntry;
668✔
628
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
668✔
629
  const SMetaEntry *pSuperEntry = pParam->pSuperEntry;
668✔
630

631
  const STag *pNewTags = (const STag *)pEntry->ctbEntry.pTags;
668✔
632
  const STag *pOldTags = (const STag *)pOldEntry->ctbEntry.pTags;
668✔
633
  if (pNewTags->len != pOldTags->len || memcmp(pNewTags, pOldTags, pNewTags->len)) {
668✔
634
    return metaChildIdxUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
461✔
635
  }
636
  return 0;
207✔
637
}
638

639
static int32_t metaChildIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
3,432✔
640
  const SMetaEntry *pEntry = pParam->pOldEntry;
3,432✔
641

642
  SCtbIdxKey key = {
3,432✔
643
      .suid = pEntry->ctbEntry.suid,
3,432✔
644
      .uid = pEntry->uid,
3,432✔
645
  };
646
  return tdbTbDelete(pMeta->pCtbIdx, &key, sizeof(key), pMeta->txn);
3,432✔
647
}
648

649
// Tag Index
650
static int32_t metaFetchTagIdxKey(SMeta *pMeta, const SMetaEntry *pEntry, const SSchema *pTagColumn,
193,280✔
651
                                  STagIdxKey **ppTagIdxKey, int32_t *pTagIdxKeySize) {
652
  int32_t code = TSDB_CODE_SUCCESS;
193,280✔
653

654
  STagIdxKey *pTagIdxKey = NULL;
193,280✔
655
  int32_t     nTagIdxKey;
656
  const void *pTagData = NULL;
193,280✔
657
  int32_t     nTagData = 0;
193,280✔
658

659
  STagVal tagVal = {
193,280✔
660
      .cid = pTagColumn->colId,
193,280✔
661
  };
662

663
  if (tTagGet((const STag *)pEntry->ctbEntry.pTags, &tagVal)) {
193,280✔
664
    if (IS_VAR_DATA_TYPE(pTagColumn->type)) {
192,868!
665
      pTagData = tagVal.pData;
8,496✔
666
      nTagData = (int32_t)tagVal.nData;
8,496✔
667
    } else {
668
      pTagData = &(tagVal.i64);
184,372✔
669
      nTagData = tDataTypes[pTagColumn->type].bytes;
184,372✔
670
    }
671
  } else {
672
    if (!IS_VAR_DATA_TYPE(pTagColumn->type)) {
421!
673
      nTagData = tDataTypes[pTagColumn->type].bytes;
242✔
674
    }
675
  }
676

677
  code = metaCreateTagIdxKey(pEntry->ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type,
193,289✔
678
                             pEntry->uid, &pTagIdxKey, &nTagIdxKey);
193,289✔
679
  if (code) {
193,292✔
680
    metaErr(TD_VID(pMeta->pVnode), code);
13!
681
    return code;
×
682
  }
683

684
  *ppTagIdxKey = pTagIdxKey;
193,279✔
685
  *pTagIdxKeySize = nTagIdxKey;
193,279✔
686
  return code;
193,279✔
687
}
688

689
static void metaFetchTagIdxKeyFree(STagIdxKey **ppTagIdxKey) {
193,315✔
690
  metaDestroyTagIdxKey(*ppTagIdxKey);
193,315✔
691
  *ppTagIdxKey = NULL;
193,315✔
692
}
193,315✔
693

694
static int32_t metaTagIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
188,866✔
695
  int32_t code = TSDB_CODE_SUCCESS;
188,866✔
696

697
  const SMetaEntry *pEntry = pParam->pEntry;
188,866✔
698
  const SMetaEntry *pSuperEntry = pParam->pSuperEntry;
188,866✔
699

700
  const SSchemaWrapper *pTagSchema = &pSuperEntry->stbEntry.schemaTag;
188,866✔
701
  if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
189,018✔
702
    const SSchema *pTagColumn = &pTagSchema->pSchema[0];
152✔
703

704
    STagVal tagVal = {
152✔
705
        .cid = pTagColumn->colId,
152✔
706
    };
707

708
    const void *pTagData = pEntry->ctbEntry.pTags;
152✔
709
    int32_t     nTagData = ((const STag *)pEntry->ctbEntry.pTags)->len;
152✔
710
    code = metaSaveJsonVarToIdx(pMeta, pEntry, pTagColumn);
152✔
711
    if (code) {
152!
712
      metaErr(TD_VID(pMeta->pVnode), code);
×
713
    }
714
  } else {
715
    for (int32_t i = 0; i < pTagSchema->nCols; i++) {
644,505✔
716
      STagIdxKey    *pTagIdxKey = NULL;
455,767✔
717
      int32_t        nTagIdxKey;
718
      const SSchema *pTagColumn = &pTagSchema->pSchema[i];
455,767✔
719

720
      if (!IS_IDX_ON(pTagColumn)) {
455,767✔
721
        continue;
267,065✔
722
      }
723

724
      code = metaFetchTagIdxKey(pMeta, pEntry, pTagColumn, &pTagIdxKey, &nTagIdxKey);
188,702✔
725
      if (code) {
188,691!
726
        metaErr(TD_VID(pMeta->pVnode), code);
×
727
        return code;
×
728
      }
729

730
      code = tdbTbInsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn);
188,691✔
731
      if (code) {
188,730!
732
        metaErr(TD_VID(pMeta->pVnode), code);
×
733
        metaFetchTagIdxKeyFree(&pTagIdxKey);
×
734
        return code;
×
735
      }
736
      metaFetchTagIdxKeyFree(&pTagIdxKey);
188,730✔
737
    }
738
  }
739
  return code;
188,890✔
740
}
741

742
static int32_t metaTagIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
668✔
743
  int32_t code = TSDB_CODE_SUCCESS;
668✔
744

745
  const SMetaEntry     *pEntry = pParam->pEntry;
668✔
746
  const SMetaEntry     *pOldEntry = pParam->pOldEntry;
668✔
747
  const SMetaEntry     *pSuperEntry = pParam->pSuperEntry;
668✔
748
  const SSchemaWrapper *pTagSchema = &pSuperEntry->stbEntry.schemaTag;
668✔
749
  const STag           *pNewTags = (const STag *)pEntry->ctbEntry.pTags;
668✔
750
  const STag           *pOldTags = (const STag *)pOldEntry->ctbEntry.pTags;
668✔
751

752
  if (pNewTags->len == pOldTags->len && !memcmp(pNewTags, pOldTags, pNewTags->len)) {
668✔
753
    return code;
207✔
754
  }
755

756
  if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
461✔
757
    code = metaDelJsonVarFromIdx(pMeta, pOldEntry, &pTagSchema->pSchema[0]);
6✔
758
    if (code) {
6!
759
      metaErr(TD_VID(pMeta->pVnode), code);
×
760
      return code;
×
761
    }
762

763
    code = metaSaveJsonVarToIdx(pMeta, pEntry, &pTagSchema->pSchema[0]);
6✔
764
    if (code) {
6!
765
      metaErr(TD_VID(pMeta->pVnode), code);
×
766
      return code;
×
767
    }
768
  } else {
769
    for (int32_t i = 0; i < pTagSchema->nCols; i++) {
2,312✔
770
      const SSchema *pTagColumn = &pTagSchema->pSchema[i];
1,857✔
771

772
      if (!IS_IDX_ON(pTagColumn)) {
1,857✔
773
        continue;
1,405✔
774
      }
775

776
      STagIdxKey *pOldTagIdxKey = NULL;
452✔
777
      int32_t     oldTagIdxKeySize = 0;
452✔
778
      STagIdxKey *pNewTagIdxKey = NULL;
452✔
779
      int32_t     newTagIdxKeySize = 0;
452✔
780

781
      code = metaFetchTagIdxKey(pMeta, pOldEntry, pTagColumn, &pOldTagIdxKey, &oldTagIdxKeySize);
452✔
782
      if (code) {
452!
783
        metaErr(TD_VID(pMeta->pVnode), code);
×
784
        return code;
×
785
      }
786

787
      code = metaFetchTagIdxKey(pMeta, pEntry, pTagColumn, &pNewTagIdxKey, &newTagIdxKeySize);
452✔
788
      if (code) {
452!
789
        metaErr(TD_VID(pMeta->pVnode), code);
×
790
        metaFetchTagIdxKeyFree(&pOldTagIdxKey);
×
791
        return code;
×
792
      }
793

794
      if (tagIdxKeyCmpr(pOldTagIdxKey, oldTagIdxKeySize, pNewTagIdxKey, newTagIdxKeySize)) {
452✔
795
        code = tdbTbDelete(pMeta->pTagIdx, pOldTagIdxKey, oldTagIdxKeySize, pMeta->txn);
88✔
796
        if (code) {
88!
797
          metaErr(TD_VID(pMeta->pVnode), code);
×
798
          metaFetchTagIdxKeyFree(&pOldTagIdxKey);
×
799
          metaFetchTagIdxKeyFree(&pNewTagIdxKey);
×
800
          return code;
×
801
        }
802

803
        code = tdbTbInsert(pMeta->pTagIdx, pNewTagIdxKey, newTagIdxKeySize, NULL, 0, pMeta->txn);
88✔
804
        if (code) {
88!
805
          metaErr(TD_VID(pMeta->pVnode), code);
×
806
          metaFetchTagIdxKeyFree(&pOldTagIdxKey);
×
807
          metaFetchTagIdxKeyFree(&pNewTagIdxKey);
×
808
          return code;
×
809
        }
810
      }
811

812
      metaFetchTagIdxKeyFree(&pOldTagIdxKey);
452✔
813
      metaFetchTagIdxKeyFree(&pNewTagIdxKey);
452✔
814
    }
815
  }
816
  return code;
461✔
817
}
818

819
static int32_t metaTagIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
3,432✔
820
  int32_t code = TSDB_CODE_SUCCESS;
3,432✔
821

822
  const SMetaEntry     *pEntry = pParam->pEntry;
3,432✔
823
  const SMetaEntry     *pChild = pParam->pOldEntry;
3,432✔
824
  const SMetaEntry     *pSuper = pParam->pSuperEntry;
3,432✔
825
  const SSchemaWrapper *pTagSchema = &pSuper->stbEntry.schemaTag;
3,432✔
826
  const SSchema        *pTagColumn = NULL;
3,432✔
827
  const STag           *pTags = (const STag *)pChild->ctbEntry.pTags;
3,432✔
828

829
  if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
3,432✔
830
    pTagColumn = &pTagSchema->pSchema[0];
6✔
831
    code = metaDelJsonVarFromIdx(pMeta, pChild, pTagColumn);
6✔
832
    if (code) {
6!
833
      metaErr(TD_VID(pMeta->pVnode), code);
×
834
    }
835
  } else {
836
    for (int32_t i = 0; i < pTagSchema->nCols; i++) {
26,666✔
837
      pTagColumn = &pTagSchema->pSchema[i];
23,239✔
838
      if (!IS_IDX_ON(pTagColumn)) {
23,239✔
839
        continue;
19,802✔
840
      }
841

842
      STagIdxKey *pTagIdxKey = NULL;
3,437✔
843
      int32_t     nTagIdxKey;
844

845
      code = metaFetchTagIdxKey(pMeta, pChild, pTagColumn, &pTagIdxKey, &nTagIdxKey);
3,437✔
846
      if (code) {
3,437!
847
        metaErr(TD_VID(pMeta->pVnode), code);
×
848
        return code;
×
849
      }
850

851
      code = tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn);
3,437✔
852
      if (code) {
3,438!
853
        metaErr(TD_VID(pMeta->pVnode), code);
×
854
        metaFetchTagIdxKeyFree(&pTagIdxKey);
×
855
        return code;
×
856
      }
857
      metaFetchTagIdxKeyFree(&pTagIdxKey);
3,438✔
858
    }
859
  }
860
  return code;
3,433✔
861
}
862

863
// Btime Index
864
static int32_t metaBtimeIdxUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
207,107✔
865
  int32_t code = TSDB_CODE_SUCCESS;
207,107✔
866

867
  const SMetaEntry *pEntry;
868
  if (META_TABLE_OP_DELETE == op) {
207,107✔
869
    pEntry = pParam->pOldEntry;
5,110✔
870
  } else {
871
    pEntry = pParam->pEntry;
201,997✔
872
  }
873

874
  SBtimeIdxKey key = {
207,107✔
875
      .uid = pEntry->uid,
207,107✔
876
  };
877

878
  if (TSDB_CHILD_TABLE == pEntry->type) {
207,107✔
879
    key.btime = pEntry->ctbEntry.btime;
192,287✔
880
  } else if (TSDB_NORMAL_TABLE == pEntry->type) {
14,820!
881
    key.btime = pEntry->ntbEntry.btime;
14,837✔
882
  } else {
883
    return TSDB_CODE_INVALID_PARA;
×
884
  }
885

886
  if (META_TABLE_OP_INSERT == op) {
207,124✔
887
    code = tdbTbInsert(pMeta->pBtimeIdx, &key, sizeof(key), NULL, 0, pMeta->txn);
202,019✔
888
  } else if (META_TABLE_OP_UPDATA == op) {
5,105!
889
    code = tdbTbUpsert(pMeta->pBtimeIdx, &key, sizeof(key), NULL, 0, pMeta->txn);
×
890
  } else if (META_TABLE_OP_DELETE == op) {
5,105!
891
    code = tdbTbDelete(pMeta->pBtimeIdx, &key, sizeof(key), pMeta->txn);
5,110✔
892
  } else {
893
    code = TSDB_CODE_INVALID_PARA;
×
894
  }
895
  if (code) {
207,152!
896
    metaErr(TD_VID(pMeta->pVnode), code);
×
897
  }
898
  return code;
207,149✔
899
}
900

901
static int32_t metaBtimeIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
202,005✔
902
  return metaBtimeIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
202,005✔
903
}
904

905
static int32_t metaBtimeIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
906
  return metaBtimeIdxUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
×
907
}
908

909
static int32_t metaBtimeIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
5,110✔
910
  return metaBtimeIdxUpsert(pMeta, pParam, META_TABLE_OP_DELETE);
5,110✔
911
}
912

913
// TTL Index
914
static int32_t metaTtlIdxUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
202,048✔
915
  const SMetaEntry *pEntry = pParam->pEntry;
202,048✔
916

917
  STtlUpdTtlCtx ctx = {
202,048✔
918
      .uid = pEntry->uid,
202,048✔
919
      .pTxn = pMeta->txn,
202,048✔
920
  };
921
  if (TSDB_CHILD_TABLE == pEntry->type) {
202,048✔
922
    ctx.ttlDays = pEntry->ctbEntry.ttlDays;
188,885✔
923
    ctx.changeTimeMs = pEntry->ctbEntry.btime;
188,885✔
924
  } else if (TSDB_NORMAL_TABLE == pEntry->type) {
13,163!
925
    ctx.ttlDays = pEntry->ntbEntry.ttlDays;
13,166✔
926
    ctx.changeTimeMs = pEntry->ntbEntry.btime;
13,166✔
927
  } else {
928
    return TSDB_CODE_INVALID_PARA;
×
929
  }
930

931
  int32_t ret = ttlMgrInsertTtl(pMeta->pTtlMgr, &ctx);
202,051✔
932
  if (ret < 0) {
202,048!
933
    metaError("vgId:%d, failed to insert ttl, uid: %" PRId64 " %s", TD_VID(pMeta->pVnode), pEntry->uid, tstrerror(ret));
×
934
  }
935
  return TSDB_CODE_SUCCESS;
202,045✔
936
}
937

938
static int32_t metaTtlIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
202,052✔
939
  return metaTtlIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
202,052✔
940
}
941

942
static int32_t metaTtlIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam);
943

944
static int32_t metaTtlIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
860✔
945
  int32_t code = TSDB_CODE_SUCCESS;
860✔
946

947
  const SMetaEntry *pEntry = pParam->pEntry;
860✔
948
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
860✔
949

950
  if ((pEntry->type == TSDB_CHILD_TABLE && pOldEntry->ctbEntry.ttlDays != pEntry->ctbEntry.ttlDays) ||
860✔
951
      (pEntry->type == TSDB_NORMAL_TABLE && pOldEntry->ntbEntry.ttlDays != pEntry->ntbEntry.ttlDays)) {
849✔
952
    code = metaTtlIdxDelete(pMeta, pParam);
18✔
953
    if (code) {
18!
954
      metaErr(TD_VID(pMeta->pVnode), code);
×
955
    }
956

957
    code = metaTtlIdxInsert(pMeta, pParam);
18✔
958
    if (code) {
18!
959
      metaErr(TD_VID(pMeta->pVnode), code);
×
960
    }
961
  }
962

963
  return TSDB_CODE_SUCCESS;
860✔
964
}
965

966
static int32_t metaTtlIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
5,128✔
967
  int32_t code = TSDB_CODE_SUCCESS;
5,128✔
968

969
  const SMetaEntry *pEntry = pParam->pOldEntry;
5,128✔
970
  STtlDelTtlCtx     ctx = {
5,128✔
971
          .uid = pEntry->uid,
5,128✔
972
          .pTxn = pMeta->txn,
5,128✔
973
  };
974

975
  if (TSDB_CHILD_TABLE == pEntry->type) {
5,128✔
976
    ctx.ttlDays = pEntry->ctbEntry.ttlDays;
3,444✔
977
  } else if (TSDB_NORMAL_TABLE == pEntry->type) {
1,684!
978
    ctx.ttlDays = pEntry->ntbEntry.ttlDays;
1,685✔
979
  } else {
980
    code = TSDB_CODE_INVALID_PARA;
×
981
  }
982

983
  if (TSDB_CODE_SUCCESS == code) {
5,128!
984
    int32_t ret = ttlMgrDeleteTtl(pMeta->pTtlMgr, &ctx);
5,129✔
985
    if (ret < 0) {
5,128!
986
      metaError("vgId:%d, failed to delete ttl, uid: %" PRId64 " %s", TD_VID(pMeta->pVnode), pEntry->uid,
×
987
                tstrerror(ret));
988
    }
989
  }
990
  return code;
5,128✔
991
}
992

993
static int32_t (*metaTableOpFn[META_TABLE_MAX][META_TABLE_OP_MAX])(SMeta *pMeta, const SMetaHandleParam *pParam) =
994
    {
995
        [META_ENTRY_TABLE] =
996
            {
997
                [META_TABLE_OP_INSERT] = metaEntryTableInsert,
998
                [META_TABLE_OP_UPDATA] = metaEntryTableUpdate,
999
                [META_TABLE_OP_DELETE] = metaEntryTableDelete,
1000
            },
1001
        [META_SCHEMA_TABLE] =
1002
            {
1003
                [META_TABLE_OP_INSERT] = metaSchemaTableInsert,
1004
                [META_TABLE_OP_UPDATA] = metaSchemaTableUpdate,
1005
                [META_TABLE_OP_DELETE] = metaSchemaTableDelete,
1006
            },
1007
        [META_UID_IDX] =
1008
            {
1009
                [META_TABLE_OP_INSERT] = metaUidIdxInsert,
1010
                [META_TABLE_OP_UPDATA] = metaUidIdxUpdate,
1011
                [META_TABLE_OP_DELETE] = metaUidIdxDelete,
1012
            },
1013
        [META_NAME_IDX] =
1014
            {
1015
                [META_TABLE_OP_INSERT] = metaNameIdxInsert,
1016
                [META_TABLE_OP_UPDATA] = metaNameIdxUpdate,
1017
                [META_TABLE_OP_DELETE] = metaNameIdxDelete,
1018
            },
1019
        [META_SUID_IDX] =
1020
            {
1021
                [META_TABLE_OP_INSERT] = metaSUidIdxInsert,
1022
                [META_TABLE_OP_UPDATA] = NULL,
1023
                [META_TABLE_OP_DELETE] = metaSUidIdxDelete,
1024
            },
1025
        [META_CHILD_IDX] =
1026
            {
1027
                [META_TABLE_OP_INSERT] = metaChildIdxInsert,
1028
                [META_TABLE_OP_UPDATA] = metaChildIdxUpdate,
1029
                [META_TABLE_OP_DELETE] = metaChildIdxDelete,
1030
            },
1031
        [META_TAG_IDX] =
1032
            {
1033
                [META_TABLE_OP_INSERT] = metaTagIdxInsert,
1034
                [META_TABLE_OP_UPDATA] = metaTagIdxUpdate,
1035
                [META_TABLE_OP_DELETE] = metaTagIdxDelete,
1036
            },
1037
        [META_BTIME_IDX] =
1038
            {
1039
                [META_TABLE_OP_INSERT] = metaBtimeIdxInsert,
1040
                [META_TABLE_OP_UPDATA] = metaBtimeIdxUpdate,
1041
                [META_TABLE_OP_DELETE] = metaBtimeIdxDelete,
1042
            },
1043
        [META_TTL_IDX] =
1044
            {
1045
                [META_TABLE_OP_INSERT] = metaTtlIdxInsert,
1046
                [META_TABLE_OP_UPDATA] = metaTtlIdxUpdate,
1047
                [META_TABLE_OP_DELETE] = metaTtlIdxDelete,
1048
            },
1049
};
1050

1051
static int32_t metaHandleSuperTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry) {
16,574✔
1052
  int32_t code = TSDB_CODE_SUCCESS;
16,574✔
1053

1054
  SMetaTableOp ops[] = {
16,574✔
1055
      {META_ENTRY_TABLE, META_TABLE_OP_INSERT},   //
1056
      {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  // TODO: here should be insert
1057
      {META_UID_IDX, META_TABLE_OP_INSERT},       //
1058
      {META_NAME_IDX, META_TABLE_OP_INSERT},      //
1059
      {META_SUID_IDX, META_TABLE_OP_INSERT},      //
1060
  };
1061

1062
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
99,333✔
1063
    SMetaTableOp          *op = &ops[i];
82,793✔
1064
    const SMetaHandleParam param = {
82,793✔
1065
        .pEntry = pEntry,
1066
    };
1067

1068
    code = metaTableOpFn[op->table][op->op](pMeta, &param);
82,793✔
1069
    if (TSDB_CODE_SUCCESS != code) {
82,684!
1070
      metaErr(TD_VID(pMeta->pVnode), code);
×
1071
      return code;
×
1072
    }
1073
  }
1074

1075
  return code;
16,540✔
1076
}
1077
static int32_t metaHandleSuperTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) {
16,334✔
1078
  int32_t code = TSDB_CODE_SUCCESS;
16,334✔
1079

1080
  metaWLock(pMeta);
16,334✔
1081
  code = metaHandleSuperTableCreateImpl(pMeta, pEntry);
16,616✔
1082
  metaULock(pMeta);
16,551✔
1083

1084
  if (TSDB_CODE_SUCCESS == code) {
16,626!
1085
    pMeta->pVnode->config.vndStats.numOfSTables++;
16,626✔
1086

1087
    metaInfo("vgId:%d, %s success, version:%" PRId64 " type:%d uid:%" PRId64 " name:%s", TD_VID(pMeta->pVnode),
16,626✔
1088
             __func__, pEntry->version, pEntry->type, pEntry->uid, pEntry->name);
1089
  } else {
1090
    metaErr(TD_VID(pMeta->pVnode), code);
×
1091
  }
1092
  return code;
16,638✔
1093
}
1094

1095
static int32_t metaHandleNormalTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry) {
13,159✔
1096
  int32_t code = TSDB_CODE_SUCCESS;
13,159✔
1097

1098
  SMetaTableOp ops[] = {
13,159✔
1099
      {META_ENTRY_TABLE, META_TABLE_OP_INSERT},   //
1100
      {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  // TODO: need to be insert
1101
      {META_UID_IDX, META_TABLE_OP_INSERT},       //
1102
      {META_NAME_IDX, META_TABLE_OP_INSERT},      //
1103
      {META_BTIME_IDX, META_TABLE_OP_INSERT},     //
1104
      {META_TTL_IDX, META_TABLE_OP_INSERT},       //
1105
  };
1106

1107
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
92,112✔
1108
    SMetaTableOp *op = &ops[i];
78,953✔
1109

1110
    SMetaHandleParam param = {
78,953✔
1111
        .pEntry = pEntry,
1112
    };
1113

1114
    code = metaTableOpFn[op->table][op->op](pMeta, &param);
78,953✔
1115
    if (TSDB_CODE_SUCCESS != code) {
78,953!
1116
      metaErr(TD_VID(pMeta->pVnode), code);
×
1117
      return code;
×
1118
    }
1119
  }
1120

1121
  return code;
13,159✔
1122
}
1123
static int32_t metaHandleNormalTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) {
13,159✔
1124
  int32_t code = TSDB_CODE_SUCCESS;
13,159✔
1125

1126
  // update TDB
1127
  metaWLock(pMeta);
13,159✔
1128
  code = metaHandleNormalTableCreateImpl(pMeta, pEntry);
13,159✔
1129
  metaULock(pMeta);
13,159✔
1130

1131
  // update other stuff
1132
  if (TSDB_CODE_SUCCESS == code) {
13,159!
1133
    pMeta->pVnode->config.vndStats.numOfNTables++;
13,159✔
1134
    pMeta->pVnode->config.vndStats.numOfNTimeSeries += pEntry->ntbEntry.schemaRow.nCols - 1;
13,159✔
1135

1136
    if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
13,159✔
1137
      int32_t rc = tsdbCacheNewTable(pMeta->pVnode->pTsdb, pEntry->uid, -1, &pEntry->ntbEntry.schemaRow);
28✔
1138
      if (rc < 0) {
28!
1139
        metaError("vgId:%d, failed to create table:%s since %s", TD_VID(pMeta->pVnode), pEntry->name, tstrerror(rc));
×
1140
      }
1141
    }
1142
  } else {
1143
    metaErr(TD_VID(pMeta->pVnode), code);
×
1144
  }
1145
  return code;
13,159✔
1146
}
1147

1148
static int32_t metaHandleChildTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry, const SMetaEntry *pSuperEntry) {
188,859✔
1149
  int32_t code = TSDB_CODE_SUCCESS;
188,859✔
1150

1151
  SMetaTableOp ops[] = {
188,859✔
1152
      {META_ENTRY_TABLE, META_TABLE_OP_INSERT},  //
1153
      {META_UID_IDX, META_TABLE_OP_INSERT},      //
1154
      {META_NAME_IDX, META_TABLE_OP_INSERT},     //
1155
      {META_CHILD_IDX, META_TABLE_OP_INSERT},    //
1156
      {META_TAG_IDX, META_TABLE_OP_INSERT},      //
1157
      {META_BTIME_IDX, META_TABLE_OP_INSERT},    //
1158
      {META_TTL_IDX, META_TABLE_OP_INSERT},      //
1159
  };
1160

1161
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
1,510,249✔
1162
    SMetaTableOp *op = &ops[i];
1,321,516✔
1163

1164
    SMetaHandleParam param = {
1,321,516✔
1165
        .pEntry = pEntry,
1166
        .pSuperEntry = pSuperEntry,
1167
    };
1168

1169
    code = metaTableOpFn[op->table][op->op](pMeta, &param);
1,321,516✔
1170
    if (TSDB_CODE_SUCCESS != code) {
1,321,394✔
1171
      metaErr(TD_VID(pMeta->pVnode), code);
4!
1172
      return code;
×
1173
    }
1174
  }
1175

1176
  if (TSDB_CODE_SUCCESS == code) {
188,733!
1177
    metaUpdateStbStats(pMeta, pSuperEntry->uid, 1, 0);
188,874✔
1178
    int32_t ret = metaUidCacheClear(pMeta, pSuperEntry->uid);
188,871✔
1179
    if (ret < 0) {
188,887!
1180
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1181
    }
1182

1183
    ret = metaTbGroupCacheClear(pMeta, pSuperEntry->uid);
188,887✔
1184
    if (ret < 0) {
188,875!
1185
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1186
    }
1187
  }
1188
  return code;
188,849✔
1189
}
1190

1191
static int32_t metaHandleChildTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) {
188,858✔
1192
  int32_t     code = TSDB_CODE_SUCCESS;
188,858✔
1193
  SMetaEntry *pSuperEntry = NULL;
188,858✔
1194

1195
  // get the super table entry
1196
  code = metaFetchEntryByUid(pMeta, pEntry->ctbEntry.suid, &pSuperEntry);
188,858✔
1197
  if (code) {
188,868!
1198
    metaErr(TD_VID(pMeta->pVnode), code);
×
1199
    return code;
×
1200
  }
1201

1202
  // update TDB
1203
  metaWLock(pMeta);
188,868✔
1204
  code = metaHandleChildTableCreateImpl(pMeta, pEntry, pSuperEntry);
188,868✔
1205
  metaULock(pMeta);
188,853✔
1206

1207
  // update other stuff
1208
  if (TSDB_CODE_SUCCESS == code) {
188,883!
1209
    pMeta->pVnode->config.vndStats.numOfCTables++;
188,883✔
1210

1211
    if (!metaTbInFilterCache(pMeta, pSuperEntry->name, 1)) {
188,883✔
1212
      int32_t nCols = 0;
188,866✔
1213
      int32_t ret = metaGetStbStats(pMeta->pVnode, pSuperEntry->uid, 0, &nCols);
188,866✔
1214
      if (ret < 0) {
188,870!
1215
        metaErr(TD_VID(pMeta->pVnode), ret);
×
1216
      }
1217
      pMeta->pVnode->config.vndStats.numOfNTimeSeries += (nCols - 1);
188,869✔
1218
    }
1219

1220
    if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
188,884✔
1221
      int32_t rc = tsdbCacheNewTable(pMeta->pVnode->pTsdb, pEntry->uid, pEntry->ctbEntry.suid, NULL);
556✔
1222
      if (rc < 0) {
556!
1223
        metaError("vgId:%d, %s failed at %s:%d since %s", TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__,
×
1224
                  tstrerror(rc));
1225
      }
1226
    }
1227

1228
  } else {
1229
    metaErr(TD_VID(pMeta->pVnode), code);
×
1230
  }
1231

1232
  metaFetchEntryFree(&pSuperEntry);
188,884✔
1233
  return code;
188,883✔
1234
}
1235

1236
static int32_t metaHandleNormalTableDropImpl(SMeta *pMeta, SMetaHandleParam *pParam) {
1,678✔
1237
  int32_t code = TSDB_CODE_SUCCESS;
1,678✔
1238

1239
  SMetaTableOp ops[] = {
1,678✔
1240
      {META_ENTRY_TABLE, META_TABLE_OP_DELETE},  //
1241
      {META_UID_IDX, META_TABLE_OP_DELETE},      //
1242
      {META_NAME_IDX, META_TABLE_OP_DELETE},     //
1243
      {META_BTIME_IDX, META_TABLE_OP_DELETE},    //
1244
      {META_TTL_IDX, META_TABLE_OP_DELETE},      //
1245

1246
      // {META_SCHEMA_TABLE, META_TABLE_OP_DELETE},  //
1247
  };
1248

1249
  for (int32_t i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
10,068✔
1250
    SMetaTableOp *op = &ops[i];
8,390✔
1251
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
8,390✔
1252
    if (code) {
8,390!
1253
      const SMetaEntry *pEntry = pParam->pEntry;
×
1254
      metaErr(TD_VID(pMeta->pVnode), code);
×
1255
    }
1256
  }
1257

1258
  return code;
1,678✔
1259
}
1260

1261
static int32_t metaHandleNormalTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) {
1,678✔
1262
  int32_t     code = TSDB_CODE_SUCCESS;
1,678✔
1263
  SMetaEntry *pOldEntry = NULL;
1,678✔
1264

1265
  // fetch the entry
1266
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
1,678✔
1267
  if (code) {
1,678!
1268
    metaErr(TD_VID(pMeta->pVnode), code);
×
1269
    return code;
×
1270
  }
1271

1272
  SMetaHandleParam param = {
1,678✔
1273
      .pEntry = pEntry,
1274
      .pOldEntry = pOldEntry,
1275
  };
1276

1277
  // do the drop
1278
  metaWLock(pMeta);
1,678✔
1279
  code = metaHandleNormalTableDropImpl(pMeta, &param);
1,678✔
1280
  metaULock(pMeta);
1,678✔
1281
  if (code) {
1,678!
1282
    metaErr(TD_VID(pMeta->pVnode), code);
×
1283
    metaFetchEntryFree(&pOldEntry);
×
1284
    return code;
×
1285
  }
1286

1287
  // update other stuff
1288
  pMeta->pVnode->config.vndStats.numOfNTables--;
1,678✔
1289
  pMeta->pVnode->config.vndStats.numOfNTimeSeries -= (pOldEntry->ntbEntry.schemaRow.nCols - 1);
1,678✔
1290

1291
#if 0
1292
  if (tbUids) {
1293
    if (taosArrayPush(tbUids, &uid) == NULL) {
1294
      rc = terrno;
1295
      goto _exit;
1296
    }
1297
  }
1298
#endif
1299

1300
  if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
1,678!
1301
    int32_t ret = tsdbCacheDropTable(pMeta->pVnode->pTsdb, pOldEntry->uid, 0, NULL);
×
1302
    if (ret < 0) {
×
1303
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1304
    }
1305
  }
1306

1307
  metaFetchEntryFree(&pOldEntry);
1,678✔
1308
  return code;
1,678✔
1309
}
1310

1311
static int32_t metaHandleChildTableDropImpl(SMeta *pMeta, const SMetaHandleParam *pParam, bool superDropped) {
3,432✔
1312
  int32_t code = TSDB_CODE_SUCCESS;
3,432✔
1313

1314
  const SMetaEntry *pEntry = pParam->pEntry;
3,432✔
1315
  const SMetaEntry *pChild = pParam->pOldEntry;
3,432✔
1316
  const SMetaEntry *pSuper = pParam->pSuperEntry;
3,432✔
1317

1318
  SMetaTableOp ops[] = {
3,432✔
1319
      {META_ENTRY_TABLE, META_TABLE_OP_DELETE},  //
1320
      {META_UID_IDX, META_TABLE_OP_DELETE},      //
1321
      {META_NAME_IDX, META_TABLE_OP_DELETE},     //
1322
      {META_CHILD_IDX, META_TABLE_OP_DELETE},    //
1323
      {META_TAG_IDX, META_TABLE_OP_DELETE},      //
1324
      {META_BTIME_IDX, META_TABLE_OP_DELETE},    //
1325
      {META_TTL_IDX, META_TABLE_OP_DELETE},      //
1326
  };
1327

1328
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
27,433✔
1329
    SMetaTableOp *op = &ops[i];
24,014✔
1330

1331
    if (op->table == META_ENTRY_TABLE && superDropped) {
24,014✔
1332
      continue;
3,213✔
1333
    }
1334

1335
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
20,801✔
1336
    if (code) {
20,792✔
1337
      metaErr(TD_VID(pMeta->pVnode), code);
4!
1338
      return code;
×
1339
    }
1340
  }
1341

1342
  --pMeta->pVnode->config.vndStats.numOfCTables;
3,419✔
1343
  metaUpdateStbStats(pMeta, pParam->pSuperEntry->uid, -1, 0);
3,419✔
1344
  int32_t ret = metaUidCacheClear(pMeta, pSuper->uid);
3,433✔
1345
  if (ret < 0) {
3,433!
1346
    metaErr(TD_VID(pMeta->pVnode), ret);
×
1347
  }
1348

1349
  ret = metaTbGroupCacheClear(pMeta, pSuper->uid);
3,433✔
1350
  if (ret < 0) {
3,433!
1351
    metaErr(TD_VID(pMeta->pVnode), ret);
×
1352
  }
1353
  return code;
3,433✔
1354
}
1355

1356
static int32_t metaHandleChildTableDrop(SMeta *pMeta, const SMetaEntry *pEntry, bool superDropped) {
3,431✔
1357
  int32_t     code = TSDB_CODE_SUCCESS;
3,431✔
1358
  SMetaEntry *pChild = NULL;
3,431✔
1359
  SMetaEntry *pSuper = NULL;
3,431✔
1360

1361
  // fetch old entry
1362
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pChild);
3,431✔
1363
  if (code) {
3,433!
1364
    metaErr(TD_VID(pMeta->pVnode), code);
×
1365
    return code;
×
1366
  }
1367

1368
  // fetch super entry
1369
  code = metaFetchEntryByUid(pMeta, pChild->ctbEntry.suid, &pSuper);
3,433✔
1370
  if (code) {
3,433!
1371
    metaErr(TD_VID(pMeta->pVnode), code);
×
1372
    metaFetchEntryFree(&pChild);
×
1373
    return code;
×
1374
  }
1375

1376
  SMetaHandleParam param = {
3,433✔
1377
      .pEntry = pEntry,
1378
      .pOldEntry = pChild,
1379
      .pSuperEntry = pSuper,
1380
  };
1381

1382
  // do the drop
1383
  metaWLock(pMeta);
3,433✔
1384
  code = metaHandleChildTableDropImpl(pMeta, &param, superDropped);
3,432✔
1385
  metaULock(pMeta);
3,432✔
1386
  if (code) {
3,432!
1387
    metaErr(TD_VID(pMeta->pVnode), code);
×
1388
    metaFetchEntryFree(&pChild);
×
1389
    metaFetchEntryFree(&pSuper);
×
1390
    return code;
×
1391
  }
1392

1393
  // do other stuff
1394
  if (!metaTbInFilterCache(pMeta, pSuper->name, 1)) {
3,432!
1395
    int32_t      nCols = 0;
3,433✔
1396
    SVnodeStats *pStats = &pMeta->pVnode->config.vndStats;
3,433✔
1397
    if (metaGetStbStats(pMeta->pVnode, pSuper->uid, NULL, &nCols) == 0) {
3,433!
1398
      pStats->numOfTimeSeries -= nCols - 1;
3,433✔
1399
    }
1400
  }
1401

1402
  if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
3,433✔
1403
    int32_t ret = tsdbCacheDropTable(pMeta->pVnode->pTsdb, pChild->uid, pSuper->uid, NULL);
9✔
1404
    if (ret < 0) {
9!
1405
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1406
    }
1407
  }
1408

1409
#if 0
1410
  if (tbUids) {
1411
    if (taosArrayPush(tbUids, &uid) == NULL) {
1412
      rc = terrno;
1413
      goto _exit;
1414
    }
1415
  }
1416

1417
  if ((type == TSDB_CHILD_TABLE) && tbUid) {
1418
    *tbUid = uid;
1419
  }
1420
#endif
1421
  metaFetchEntryFree(&pChild);
3,433✔
1422
  metaFetchEntryFree(&pSuper);
3,433✔
1423
  return code;
3,432✔
1424
}
1425

1426
static int32_t metaGetChildUidsOfSuperTable(SMeta *pMeta, tb_uid_t suid, SArray **childList) {
2,276✔
1427
  int32_t code = TSDB_CODE_SUCCESS;
2,276✔
1428
  void   *key = NULL;
2,276✔
1429
  int32_t keySize = 0;
2,276✔
1430
  int32_t c;
1431

1432
  *childList = taosArrayInit(64, sizeof(tb_uid_t));
2,276✔
1433
  if (*childList == NULL) {
2,280!
1434
    return terrno;
×
1435
  }
1436

1437
  TBC *cursor = NULL;
2,280✔
1438
  code = tdbTbcOpen(pMeta->pCtbIdx, &cursor, NULL);
2,280✔
1439
  if (code) {
2,276!
1440
    taosArrayDestroy(*childList);
×
1441
    *childList = NULL;
×
1442
    return code;
×
1443
  }
1444

1445
  int32_t rc = tdbTbcMoveTo(cursor,
2,276✔
1446
                            &(SCtbIdxKey){
2,276✔
1447
                                .suid = suid,
1448
                                .uid = INT64_MIN,
1449
                            },
1450
                            sizeof(SCtbIdxKey), &c);
1451
  if (rc < 0) {
2,277!
1452
    tdbTbcClose(cursor);
×
1453
    return 0;
×
1454
  }
1455

1456
  for (;;) {
1457
    if (tdbTbcNext(cursor, &key, &keySize, NULL, NULL) < 0) {
6,179✔
1458
      break;
1,027✔
1459
    }
1460

1461
    if (((SCtbIdxKey *)key)->suid < suid) {
5,148✔
1462
      continue;
207✔
1463
    } else if (((SCtbIdxKey *)key)->suid > suid) {
4,941✔
1464
      break;
1,250✔
1465
    }
1466

1467
    if (taosArrayPush(*childList, &(((SCtbIdxKey *)key)->uid)) == NULL) {
7,386!
1468
      tdbFreeClear(key);
×
1469
      tdbTbcClose(cursor);
×
1470
      taosArrayDestroy(*childList);
×
1471
      *childList = NULL;
×
1472
      return terrno;
×
1473
    }
1474
  }
1475

1476
  tdbTbcClose(cursor);
2,277✔
1477
  tdbFreeClear(key);
2,278✔
1478
  return code;
2,278✔
1479
}
1480

1481
static int32_t metaHandleSuperTableDropImpl(SMeta *pMeta, const SMetaHandleParam *pParam) {
2,088✔
1482
  int32_t           code = TSDB_CODE_SUCCESS;
2,088✔
1483
  const SMetaEntry *pEntry = pParam->pEntry;
2,088✔
1484

1485
  SMetaTableOp ops[] = {
2,088✔
1486
      {META_ENTRY_TABLE, META_TABLE_OP_DELETE},  //
1487
      {META_UID_IDX, META_TABLE_OP_DELETE},      //
1488
      {META_NAME_IDX, META_TABLE_OP_DELETE},     //
1489
      {META_SUID_IDX, META_TABLE_OP_DELETE},     //
1490

1491
      // {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  // TODO: here should be insert
1492
  };
1493

1494
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
10,442✔
1495
    SMetaTableOp *op = &ops[i];
8,354✔
1496

1497
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
8,354✔
1498
    if (TSDB_CODE_SUCCESS != code) {
8,354!
1499
      metaErr(TD_VID(pMeta->pVnode), code);
×
1500
      return code;
×
1501
    }
1502
  }
1503

1504
  int32_t ret = metaStatsCacheDrop(pMeta, pEntry->uid);
2,088✔
1505
  if (ret < 0) {
2,089✔
1506
    metaErr(TD_VID(pMeta->pVnode), ret);
237!
1507
  }
1508
  return code;
2,088✔
1509
}
1510

1511
static int32_t metaHandleNormalTableUpdateImpl(SMeta *pMeta, const SMetaHandleParam *pParam) {
192✔
1512
  int32_t code = TSDB_CODE_SUCCESS;
192✔
1513

1514
  const SMetaEntry *pEntry = pParam->pEntry;
192✔
1515

1516
  SMetaTableOp ops[] = {
192✔
1517
      {META_ENTRY_TABLE, META_TABLE_OP_UPDATA},   //
1518
      {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  //
1519
      {META_UID_IDX, META_TABLE_OP_UPDATA},       //
1520
      {META_TTL_IDX, META_TABLE_OP_UPDATA},       //
1521
  };
1522
  for (int32_t i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
960✔
1523
    SMetaTableOp *op = &ops[i];
768✔
1524
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
768✔
1525
    if (code) {
768!
1526
      metaErr(TD_VID(pMeta->pVnode), code);
×
1527
      return code;
×
1528
    }
1529
  }
1530
#if 0
1531
  if (metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs) < 0) {
1532
    metaError("vgId:%d, failed to update change time:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, entry.uid);
1533
  }
1534
#endif
1535
  return code;
192✔
1536
}
1537

1538
static int32_t metaHandleChildTableUpdateImpl(SMeta *pMeta, const SMetaHandleParam *pParam) {
668✔
1539
  int32_t code = TSDB_CODE_SUCCESS;
668✔
1540

1541
  const SMetaEntry *pEntry = pParam->pEntry;
668✔
1542
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
668✔
1543
  const SMetaEntry *pSuperEntry = pParam->pSuperEntry;
668✔
1544

1545
  SMetaTableOp ops[] = {
668✔
1546
      {META_ENTRY_TABLE, META_TABLE_OP_UPDATA},  //
1547
      {META_UID_IDX, META_TABLE_OP_UPDATA},      //
1548
      {META_TAG_IDX, META_TABLE_OP_UPDATA},      //
1549
      {META_CHILD_IDX, META_TABLE_OP_UPDATA},    //
1550
      {META_TTL_IDX, META_TABLE_OP_UPDATA},      //
1551
  };
1552

1553
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
4,008✔
1554
    SMetaTableOp *op = &ops[i];
3,340✔
1555
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
3,340✔
1556
    if (code) {
3,340!
1557
      metaErr(TD_VID(pMeta->pVnode), code);
×
1558
      return code;
×
1559
    }
1560
  }
1561

1562
  if (metaUidCacheClear(pMeta, pSuperEntry->uid) < 0) {
668!
1563
    metaErr(TD_VID(pMeta->pVnode), code);
×
1564
  }
1565

1566
  if (metaTbGroupCacheClear(pMeta, pSuperEntry->uid) < 0) {
668!
1567
    metaErr(TD_VID(pMeta->pVnode), code);
×
1568
  }
1569
  return code;
668✔
1570
#if 0
1571
  if (metaUpdateChangeTime(pMeta, ctbEntry.uid, pReq->ctimeMs) < 0) {
1572
    metaError("meta/table: failed to update change time:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid);
1573
  }
1574
#endif
1575
}
1576

1577
static int32_t metaHandleSuperTableUpdateImpl(SMeta *pMeta, SMetaHandleParam *pParam) {
6,130✔
1578
  int32_t code = TSDB_CODE_SUCCESS;
6,130✔
1579

1580
  const SMetaEntry *pEntry = pParam->pEntry;
6,130✔
1581
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
6,130✔
1582

1583
  SMetaTableOp ops[] = {
6,130✔
1584
      {META_ENTRY_TABLE, META_TABLE_OP_UPDATA},   //
1585
      {META_UID_IDX, META_TABLE_OP_UPDATA},       //
1586
      {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  //
1587
  };
1588

1589
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
24,517✔
1590
    SMetaTableOp *op = &ops[i];
18,387✔
1591
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
18,387✔
1592
    if (code) {
18,385!
1593
      metaErr(TD_VID(pMeta->pVnode), code);
×
1594
      return code;
×
1595
    }
1596
  }
1597

1598
  return code;
6,130✔
1599
}
1600

1601
static int32_t metaHandleSuperTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
6,127✔
1602
  int32_t code = TSDB_CODE_SUCCESS;
6,127✔
1603

1604
  SMetaEntry *pOldEntry = NULL;
6,127✔
1605

1606
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
6,127✔
1607
  if (code) {
6,130!
1608
    metaErr(TD_VID(pMeta->pVnode), code);
×
1609
    return code;
×
1610
  }
1611

1612
  SMetaHandleParam param = {
6,130✔
1613
      .pEntry = pEntry,
1614
      .pOldEntry = pOldEntry,
1615
  };
1616
  metaWLock(pMeta);
6,130✔
1617
  code = metaHandleSuperTableUpdateImpl(pMeta, &param);
6,131✔
1618
  metaULock(pMeta);
6,128✔
1619
  if (code) {
6,127!
1620
    metaErr(TD_VID(pMeta->pVnode), code);
×
1621
    metaFetchEntryFree(&pOldEntry);
×
1622
    return code;
×
1623
  }
1624

1625
  int     nCols = pEntry->stbEntry.schemaRow.nCols;
6,127✔
1626
  int     onCols = pOldEntry->stbEntry.schemaRow.nCols;
6,127✔
1627
  int32_t deltaCol = nCols - onCols;
6,127✔
1628
  bool    updStat = deltaCol != 0 && !metaTbInFilterCache(pMeta, pEntry->name, 1);
6,127!
1629

1630
  if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
6,130✔
1631
    STsdb  *pTsdb = pMeta->pVnode->pTsdb;
128✔
1632
    SArray *uids = NULL; /*taosArrayInit(8, sizeof(int64_t));
128✔
1633
     if (uids == NULL) {
1634
       metaErr(TD_VID(pMeta->pVnode), code);
1635
       metaFetchEntryFree(&pOldEntry);
1636
       return terrno;
1637
       }*/
1638
    if (deltaCol == 1) {
128✔
1639
      int16_t cid = pEntry->stbEntry.schemaRow.pSchema[nCols - 1].colId;
64✔
1640
      int8_t  col_type = pEntry->stbEntry.schemaRow.pSchema[nCols - 1].type;
64✔
1641

1642
      code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &uids);
64✔
1643
      if (code) {
63!
1644
        metaErr(TD_VID(pMeta->pVnode), code);
×
1645
        metaFetchEntryFree(&pOldEntry);
×
1646
        return code;
×
1647
      }
1648
      // TAOS_CHECK_RETURN(metaGetSubtables(pMeta, pEntry->uid, uids));
1649
      TAOS_CHECK_RETURN(tsdbCacheNewSTableColumn(pTsdb, uids, cid, col_type));
63!
1650
    } else if (deltaCol == -1) {
64!
1651
      int16_t cid = -1;
64✔
1652
      bool    hasPrimaryKey = false;
64✔
1653
      if (onCols >= 2) {
64!
1654
        hasPrimaryKey = (pOldEntry->stbEntry.schemaRow.pSchema[1].flags & COL_IS_KEY) ? true : false;
64✔
1655
      }
1656
      for (int i = 0, j = 0; i < nCols && j < onCols; ++i, ++j) {
416!
1657
        if (pEntry->stbEntry.schemaRow.pSchema[i].colId != pOldEntry->stbEntry.schemaRow.pSchema[j].colId) {
384✔
1658
          cid = pOldEntry->stbEntry.schemaRow.pSchema[j].colId;
32✔
1659
          break;
32✔
1660
        }
1661
      }
1662

1663
      if (cid != -1) {
64✔
1664
        code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &uids);
32✔
1665
        if (code) {
32!
1666
          metaErr(TD_VID(pMeta->pVnode), code);
×
1667
          metaFetchEntryFree(&pOldEntry);
×
1668
          return code;
×
1669
        }
1670
        // TAOS_CHECK_RETURN(metaGetSubtables(pMeta, pEntry->uid, uids));
1671
        TAOS_CHECK_RETURN(tsdbCacheDropSTableColumn(pTsdb, uids, cid, hasPrimaryKey));
32!
1672
      }
1673
    }
1674
    if (uids) taosArrayDestroy(uids);
128✔
1675

1676
    tsdbCacheInvalidateSchema(pTsdb, pEntry->uid, -1, pEntry->stbEntry.schemaRow.version);
128✔
1677
  }
1678

1679
  metaFetchEntryFree(&pOldEntry);
6,130✔
1680
  return code;
6,130✔
1681
}
1682

1683
static int32_t metaHandleChildTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
668✔
1684
  int32_t code = TSDB_CODE_SUCCESS;
668✔
1685

1686
  SMetaEntry *pOldEntry = NULL;
668✔
1687
  SMetaEntry *pSuperEntry = NULL;
668✔
1688

1689
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
668✔
1690
  if (code) {
668!
1691
    metaErr(TD_VID(pMeta->pVnode), code);
×
1692
    return code;
×
1693
  }
1694

1695
  code = metaFetchEntryByUid(pMeta, pEntry->ctbEntry.suid, &pSuperEntry);
668✔
1696
  if (code) {
668!
1697
    metaErr(TD_VID(pMeta->pVnode), code);
×
1698
    metaFetchEntryFree(&pOldEntry);
×
1699
    return code;
×
1700
  }
1701

1702
  SMetaHandleParam param = {
668✔
1703
      .pEntry = pEntry,
1704
      .pOldEntry = pOldEntry,
1705
      .pSuperEntry = pSuperEntry,
1706
  };
1707

1708
  metaWLock(pMeta);
668✔
1709
  code = metaHandleChildTableUpdateImpl(pMeta, &param);
668✔
1710
  metaULock(pMeta);
668✔
1711
  if (code) {
668!
1712
    metaErr(TD_VID(pMeta->pVnode), code);
×
1713
    metaFetchEntryFree(&pOldEntry);
×
1714
    metaFetchEntryFree(&pSuperEntry);
×
1715
    return code;
×
1716
  }
1717

1718
  metaFetchEntryFree(&pOldEntry);
668✔
1719
  metaFetchEntryFree(&pSuperEntry);
668✔
1720
  return code;
668✔
1721
}
1722

1723
static int32_t metaHandleNormalTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
192✔
1724
  int32_t     code = TSDB_CODE_SUCCESS;
192✔
1725
  SMetaEntry *pOldEntry = NULL;
192✔
1726

1727
  // fetch old entry
1728
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
192✔
1729
  if (code) {
192!
1730
    metaErr(TD_VID(pMeta->pVnode), code);
×
1731
    return code;
×
1732
  }
1733

1734
  // handle update
1735
  SMetaHandleParam param = {
192✔
1736
      .pEntry = pEntry,
1737
      .pOldEntry = pOldEntry,
1738
  };
1739
  metaWLock(pMeta);
192✔
1740
  code = metaHandleNormalTableUpdateImpl(pMeta, &param);
192✔
1741
  metaULock(pMeta);
192✔
1742
  if (code) {
192!
1743
    metaErr(TD_VID(pMeta->pVnode), code);
×
1744
    metaFetchEntryFree(&pOldEntry);
×
1745
    return code;
×
1746
  }
1747

1748
  // do other stuff
1749
  if (!TSDB_CACHE_NO(pMeta->pVnode->config) &&
192✔
1750
      pEntry->ntbEntry.schemaRow.version != pOldEntry->ntbEntry.schemaRow.version) {
6!
1751
#if 0
1752
    {  // for add column
1753
      int16_t cid = pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].colId;
1754
      int8_t  col_type = pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].type;
1755
      int32_t ret = tsdbCacheNewNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, col_type);
1756
      if (ret < 0) {
1757
        terrno = ret;
1758
        goto _err;
1759
      }
1760
    }
1761
    {  // for drop column
1762

1763
      if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
1764
        int16_t cid = pColumn->colId;
1765

1766
        if (tsdbCacheDropNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, hasPrimayKey) != 0) {
1767
          metaError("vgId:%d, failed to drop ntable column:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name,
1768
                    entry.uid);
1769
        }
1770
        tsdbCacheInvalidateSchema(pMeta->pVnode->pTsdb, 0, entry.uid, pSchema->version);
1771
      }
1772
    }
1773
    }
1774
#endif
1775
    tsdbCacheInvalidateSchema(pMeta->pVnode->pTsdb, 0, pEntry->uid, pEntry->ntbEntry.schemaRow.version);
6✔
1776
  }
1777
  metaTimeSeriesNotifyCheck(pMeta);
192✔
1778
  metaFetchEntryFree(&pOldEntry);
192✔
1779
  return code;
192✔
1780
}
1781

1782
static int32_t metaHandleSuperTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) {
2,080✔
1783
  int32_t     code = TSDB_CODE_SUCCESS;
2,080✔
1784
  SArray     *childList = NULL;
2,080✔
1785
  SMetaEntry *pOldEntry = NULL;
2,080✔
1786

1787
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
2,080✔
1788
  if (code) {
2,087!
1789
    metaErr(TD_VID(pMeta->pVnode), code);
×
1790
    return code;
×
1791
  }
1792

1793
  code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &childList);
2,087✔
1794
  if (code) {
2,088!
1795
    metaErr(TD_VID(pMeta->pVnode), code);
×
1796
    metaFetchEntryFree(&pOldEntry);
×
1797
    return code;
×
1798
  }
1799

1800
  if (tsdbCacheDropSubTables(pMeta->pVnode->pTsdb, childList, pEntry->uid) < 0) {
2,088!
1801
    metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pEntry->name,
×
1802
              pEntry->uid, tstrerror(terrno));
1803
  }
1804

1805
  // loop to drop all child tables
1806
  for (int32_t i = 0; i < taosArrayGetSize(childList); i++) {
5,301✔
1807
    SMetaEntry childEntry = {
6,424✔
1808
        .version = pEntry->version,
3,212✔
1809
        .uid = *(tb_uid_t *)taosArrayGet(childList, i),
3,212✔
1810
        .type = -TSDB_CHILD_TABLE,
1811
    };
1812

1813
    code = metaHandleChildTableDrop(pMeta, &childEntry, true);
3,212✔
1814
    if (code) {
3,212!
1815
      metaErr(TD_VID(pMeta->pVnode), code);
×
1816
    }
1817
  }
1818

1819
  // do drop super table
1820
  SMetaHandleParam param = {
2,088✔
1821
      .pEntry = pEntry,
1822
      .pOldEntry = pOldEntry,
1823
  };
1824
  metaWLock(pMeta);
2,088✔
1825
  code = metaHandleSuperTableDropImpl(pMeta, &param);
2,089✔
1826
  metaULock(pMeta);
2,088✔
1827
  if (code) {
2,088!
1828
    metaErr(TD_VID(pMeta->pVnode), code);
×
1829
    taosArrayDestroy(childList);
×
1830
    metaFetchEntryFree(&pOldEntry);
×
1831
    return code;
×
1832
  }
1833

1834
  // do other stuff
1835
  metaUpdTimeSeriesNum(pMeta);
2,088✔
1836

1837
  // free resource and return
1838
  taosArrayDestroy(childList);
2,088✔
1839
  metaFetchEntryFree(&pOldEntry);
2,089✔
1840
  return code;
2,089✔
1841
}
1842

1843
int32_t metaHandleEntry2(SMeta *pMeta, const SMetaEntry *pEntry) {
229,524✔
1844
  int32_t   code = TSDB_CODE_SUCCESS;
229,524✔
1845
  int32_t   vgId = TD_VID(pMeta->pVnode);
229,524✔
1846
  SMetaInfo info = {0};
229,524✔
1847
  int8_t    type = pEntry->type > 0 ? pEntry->type : -pEntry->type;
229,524✔
1848

1849
  if (NULL == pMeta || NULL == pEntry) {
229,524!
1850
    metaError("%s failed at %s:%d since invalid parameter", __func__, __FILE__, __LINE__);
×
1851
    return TSDB_CODE_INVALID_PARA;
×
1852
  }
1853

1854
  if (pEntry->type > 0) {
229,592✔
1855
    bool isExist = false;
225,624✔
1856
    if (TSDB_CODE_SUCCESS == metaGetInfo(pMeta, pEntry->uid, &info, NULL)) {
225,624✔
1857
      isExist = true;
6,989✔
1858
    }
1859

1860
    switch (type) {
225,664✔
1861
      case TSDB_SUPER_TABLE: {
22,757✔
1862
        if (isExist) {
22,757✔
1863
          code = metaHandleSuperTableUpdate(pMeta, pEntry);
6,129✔
1864
        } else {
1865
          code = metaHandleSuperTableCreate(pMeta, pEntry);
16,628✔
1866
        }
1867
        break;
22,768✔
1868
      }
1869
      case TSDB_CHILD_TABLE: {
189,546✔
1870
        if (isExist) {
189,546✔
1871
          code = metaHandleChildTableUpdate(pMeta, pEntry);
668✔
1872
        } else {
1873
          code = metaHandleChildTableCreate(pMeta, pEntry);
188,878✔
1874
        }
1875
        break;
189,541✔
1876
      }
1877
      case TSDB_NORMAL_TABLE: {
13,351✔
1878
        if (isExist) {
13,351✔
1879
          code = metaHandleNormalTableUpdate(pMeta, pEntry);
192✔
1880
        } else {
1881
          code = metaHandleNormalTableCreate(pMeta, pEntry);
13,159✔
1882
        }
1883
        break;
13,351✔
1884
      }
1885
      default: {
10✔
1886
        code = TSDB_CODE_INVALID_PARA;
10✔
1887
        break;
10✔
1888
      }
1889
    }
1890
  } else {
1891
    switch (type) {
3,968!
1892
      case TSDB_SUPER_TABLE: {
2,081✔
1893
        code = metaHandleSuperTableDrop(pMeta, pEntry);
2,081✔
1894
        break;
2,088✔
1895
      }
1896
      case TSDB_CHILD_TABLE: {
219✔
1897
        code = metaHandleChildTableDrop(pMeta, pEntry, false);
219✔
1898
        break;
219✔
1899
      }
1900
      case TSDB_NORMAL_TABLE: {
1,678✔
1901
        code = metaHandleNormalTableDrop(pMeta, pEntry);
1,678✔
1902
        break;
1,678✔
1903
      }
1904
      default: {
×
1905
        code = TSDB_CODE_INVALID_PARA;
×
1906
        break;
×
1907
      }
1908
    }
1909
  }
1910

1911
  if (TSDB_CODE_SUCCESS == code) {
229,645✔
1912
    pMeta->changed = true;
229,638✔
1913
    metaDebug("vgId:%d, %s success, version:%" PRId64 " type:%d uid:%" PRId64 " name:%s", vgId, __func__,
229,638✔
1914
              pEntry->version, pEntry->type, pEntry->uid, pEntry->type > 0 ? pEntry->name : "");
1915
  } else {
1916
    metaErr(vgId, code);
7!
1917
  }
1918
  TAOS_RETURN(code);
229,647✔
1919
}
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