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

taosdata / TDengine / #3565

25 Dec 2024 05:34AM UTC coverage: 51.098% (-11.1%) from 62.21%
#3565

push

travis-ci

web-flow
Merge pull request #29316 from taosdata/enh/3.0/TD-33266

enh(ut):Add wal & config UT.

111558 of 284773 branches covered (39.17%)

Branch coverage included in aggregate %.

1 of 2 new or added lines in 2 files covered. (50.0%)

39015 existing lines in 102 files now uncovered.

177882 of 281666 relevant lines covered (63.15%)

15090998.35 hits per line

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

23.3
/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) {
36✔
65
  int32_t code = TSDB_CODE_SUCCESS;
36✔
66
  void   *value = NULL;
36✔
67
  int32_t valueSize = 0;
36✔
68

69
  // search uid index
70
  code = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &value, &valueSize);
36✔
71
  if (TSDB_CODE_SUCCESS != code) {
36!
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 = {
36✔
78
      .version = ((SUidIdxVal *)value)->version,
36✔
79
      .uid = uid,
80
  };
81
  tdbFreeClear(value);
36✔
82

83
  code = tdbTbGet(pMeta->pTbDb, &key, sizeof(key), &value, &valueSize);
36✔
84
  if (TSDB_CODE_SUCCESS != code) {
36!
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};
36✔
92
  SMetaEntry entry = {0};
36✔
93

94
  tDecoderInit(&decoder, value, valueSize);
36✔
95
  code = metaDecodeEntry(&decoder, &entry);
36✔
96
  if (code) {
36!
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);
36✔
105
  if (code) {
36!
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);
36✔
114
  tDecoderClear(&decoder);
36✔
115
  return code;
36✔
116
}
117

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

123
  code = tdbTbGet(pMeta->pNameIdx, name, strlen(name) + 1, &value, &valueSize);
16✔
124
  if (TSDB_CODE_SUCCESS != code) {
16!
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;
16✔
129
  tdbFreeClear(value);
16✔
130

131
  code = metaFetchEntryByUid(pMeta, uid, ppEntry);
16✔
132
  if (TSDB_CODE_SUCCESS != code) {
16!
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;
16✔
137
}
138

139
void metaFetchEntryFree(SMetaEntry **ppEntry) { metaCloneEntryFree(ppEntry); }
36✔
140

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

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

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

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

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

178
  // put to tdb
179
  if (META_TABLE_OP_INSERT == op) {
38✔
180
    code = tdbTbInsert(pMeta->pTbDb, &key, sizeof(key), value, valueSize, pMeta->txn);
18✔
181
  } else if (META_TABLE_OP_UPDATA == op) {
20✔
182
    code = tdbTbUpsert(pMeta->pTbDb, &key, sizeof(key), value, valueSize, pMeta->txn);
16✔
183
  } else if (META_TABLE_OP_DELETE == op) {
4!
184
    code = tdbTbInsert(pMeta->pTbDb, &key, sizeof(key), value, valueSize, pMeta->txn);
4✔
185
  } else {
186
    code = TSDB_CODE_INVALID_PARA;
×
187
  }
188
  if (TSDB_CODE_SUCCESS != code) {
38!
189
    metaErr(vgId, code);
×
190
  }
191
  taosMemoryFree(value);
38!
192
  return code;
38✔
193
}
194

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

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

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

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

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

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

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

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

252
  // put to tdb
253
  if (META_TABLE_OP_INSERT == op) {
26!
254
    code = tdbTbInsert(pMeta->pSkmDb, &key, sizeof(key), value, valueSize, pMeta->txn);
×
255
  } else if (META_TABLE_OP_UPDATA == op) {
26!
256
    code = tdbTbUpsert(pMeta->pSkmDb, &key, sizeof(key), value, valueSize, pMeta->txn);
26✔
257
  } else {
258
    code = TSDB_CODE_INVALID_PARA;
×
259
  }
260
  if (TSDB_CODE_SUCCESS != code) {
26!
261
    metaErr(vgId, code);
×
262
  }
263
  taosMemoryFree(value);
26!
264
  return code;
26✔
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,
26✔
272
                                                 const SSchema *pOldColumn, const SSchema *pNewColumn) {
273
  int32_t code = TSDB_CODE_SUCCESS;
26✔
274

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

279
  if (pOldColumn && pNewColumn) {
26✔
280
    if (IS_IDX_ON(pOldColumn) && IS_IDX_ON(pNewColumn)) {
22!
281
      return TSDB_CODE_SUCCESS;
8✔
282
    } else if (IS_IDX_ON(pOldColumn) && !IS_IDX_ON(pNewColumn)) {
14!
UNCOV
283
      action = DROP_INDEX;
×
284
    } else if (!IS_IDX_ON(pOldColumn) && IS_IDX_ON(pNewColumn)) {
14!
UNCOV
285
      action = ADD_INDEX;
×
286
    } else {
287
      return TSDB_CODE_SUCCESS;
14✔
288
    }
289
  } else if (pOldColumn) {
4✔
290
    if (IS_IDX_ON(pOldColumn)) {
2!
UNCOV
291
      action = DROP_INDEX;
×
292
    } else {
293
      return TSDB_CODE_SUCCESS;
2✔
294
    }
295
  } else {
296
    if (IS_IDX_ON(pNewColumn)) {
2!
297
      action = ADD_INDEX;
×
298
    } else {
299
      return TSDB_CODE_SUCCESS;
2✔
300
    }
301
  }
302

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

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

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

UNCOV
324
    STagIdxKey *pTagIdxKey = NULL;
×
UNCOV
325
    int32_t     tagIdxKeySize = 0;
×
326

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

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

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

UNCOV
363
    metaFetchTagIdxKeyFree(&pTagIdxKey);
×
UNCOV
364
    metaFetchEntryFree(&pChildEntry);
×
365
  }
366

UNCOV
367
  taosArrayDestroy(childTables);
×
UNCOV
368
  return code;
×
369
}
370

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

378
  int32_t iOld = 0, iNew = 0;
8✔
379
  for (; iOld < pOldTagSchema->nCols && iNew < pNewTagSchema->nCols;) {
30✔
380
    SSchema *pOldColumn = pOldTagSchema->pSchema + iOld;
22✔
381
    SSchema *pNewColumn = pNewTagSchema->pSchema + iNew;
22✔
382

383
    if (pOldColumn->colId == pNewColumn->colId) {
22!
384
      code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, pOldColumn, pNewColumn);
22✔
385
      if (code) {
22!
UNCOV
386
        metaErr(TD_VID(pMeta->pVnode), code);
×
387
        return code;
×
388
      }
389

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

UNCOV
399
      iOld++;
×
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++) {
10✔
412
    SSchema *pOldColumn = pOldTagSchema->pSchema + iOld;
2✔
413
    code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, pOldColumn, NULL);
2✔
414
    if (code) {
2!
UNCOV
415
      metaErr(TD_VID(pMeta->pVnode), code);
×
416
      return code;
×
417
    }
418
  }
419

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

429
  return code;
8✔
430
}
431

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

435
  const SMetaEntry *pEntry = pParam->pEntry;
34✔
436
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
34✔
437

438
  if (NULL == pOldEntry) {
34✔
439
    return metaSchemaTableUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
18✔
440
  }
441

442
  if (pEntry->type == TSDB_NORMAL_TABLE) {
16!
443
    // check row schema
UNCOV
444
    if (pOldEntry->ntbEntry.schemaRow.version != pEntry->ntbEntry.schemaRow.version) {
×
UNCOV
445
      return metaSchemaTableUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
×
446
    }
447
  } else if (pEntry->type == TSDB_SUPER_TABLE) {
16!
448
    // check row schema
449
    if (pOldEntry->stbEntry.schemaRow.version != pEntry->stbEntry.schemaRow.version) {
16✔
450
      return metaSchemaTableUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
8✔
451
    }
452

453
    // check tag schema
454
    code = metaUpdateSuperTableTagSchema(pMeta, pParam);
8✔
455
    if (code) {
8!
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;
8✔
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) {
34✔
474
  pInfo->uid = pEntry->uid;
34✔
475
  pInfo->version = pEntry->version;
34✔
476
  if (pEntry->type == TSDB_SUPER_TABLE) {
34!
477
    pInfo->suid = pEntry->uid;
34✔
478
    pInfo->skmVer = pEntry->stbEntry.schemaRow.version;
34✔
UNCOV
479
  } else if (pEntry->type == TSDB_CHILD_TABLE) {
×
UNCOV
480
    pInfo->suid = pEntry->ctbEntry.suid;
×
UNCOV
481
    pInfo->skmVer = 0;
×
UNCOV
482
  } else if (pEntry->type == TSDB_NORMAL_TABLE) {
×
UNCOV
483
    pInfo->suid = 0;
×
UNCOV
484
    pInfo->skmVer = pEntry->ntbEntry.schemaRow.version;
×
485
  }
486
}
34✔
487

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

492
  const SMetaEntry *pEntry = pParam->pEntry;
34✔
493

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

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

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

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

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

527
  const SMetaEntry *pEntry = pParam->pOldEntry;
4✔
528

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

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

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

544
  const SMetaEntry *pEntry = pParam->pEntry;
18✔
545

546
  if (META_TABLE_OP_INSERT == op) {
18!
547
    code = tdbTbInsert(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, &pEntry->uid, sizeof(pEntry->uid),
18✔
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;
18✔
556
}
557

558
static int32_t metaNameIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
18✔
559
  int32_t code = TSDB_CODE_SUCCESS;
18✔
560
  return metaNameIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
18✔
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) {
4✔
568
  int32_t code = TSDB_CODE_SUCCESS;
4✔
569

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

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

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

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

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

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

UNCOV
603
  const SMetaEntry *pEntry = pParam->pEntry;
×
604

UNCOV
605
  SCtbIdxKey key = {
×
UNCOV
606
      .suid = pEntry->ctbEntry.suid,
×
UNCOV
607
      .uid = pEntry->uid,
×
608
  };
609

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

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

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

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

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

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

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

UNCOV
654
  STagIdxKey *pTagIdxKey = NULL;
×
655
  int32_t     nTagIdxKey;
UNCOV
656
  const void *pTagData = NULL;
×
UNCOV
657
  int32_t     nTagData = 0;
×
658

UNCOV
659
  STagVal tagVal = {
×
UNCOV
660
      .cid = pTagColumn->colId,
×
661
  };
662

UNCOV
663
  if (tTagGet((const STag *)pEntry->ctbEntry.pTags, &tagVal)) {
×
UNCOV
664
    if (IS_VAR_DATA_TYPE(pTagColumn->type)) {
×
UNCOV
665
      pTagData = tagVal.pData;
×
UNCOV
666
      nTagData = (int32_t)tagVal.nData;
×
667
    } else {
UNCOV
668
      pTagData = &(tagVal.i64);
×
UNCOV
669
      nTagData = tDataTypes[pTagColumn->type].bytes;
×
670
    }
671
  } else {
UNCOV
672
    if (!IS_VAR_DATA_TYPE(pTagColumn->type)) {
×
UNCOV
673
      nTagData = tDataTypes[pTagColumn->type].bytes;
×
674
    }
675
  }
676

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

UNCOV
684
  *ppTagIdxKey = pTagIdxKey;
×
UNCOV
685
  *pTagIdxKeySize = nTagIdxKey;
×
UNCOV
686
  return code;
×
687
}
688

UNCOV
689
static void metaFetchTagIdxKeyFree(STagIdxKey **ppTagIdxKey) {
×
UNCOV
690
  metaDestroyTagIdxKey(*ppTagIdxKey);
×
UNCOV
691
  *ppTagIdxKey = NULL;
×
UNCOV
692
}
×
693

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

UNCOV
697
  const SMetaEntry *pEntry = pParam->pEntry;
×
UNCOV
698
  const SMetaEntry *pSuperEntry = pParam->pSuperEntry;
×
699

UNCOV
700
  const SSchemaWrapper *pTagSchema = &pSuperEntry->stbEntry.schemaTag;
×
UNCOV
701
  if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
×
UNCOV
702
    const SSchema *pTagColumn = &pTagSchema->pSchema[0];
×
703

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

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

UNCOV
720
      if (!IS_IDX_ON(pTagColumn)) {
×
UNCOV
721
        continue;
×
722
      }
723

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

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

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

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

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

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

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

UNCOV
772
      if (!IS_IDX_ON(pTagColumn)) {
×
UNCOV
773
        continue;
×
774
      }
775

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

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

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

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

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

UNCOV
812
      metaFetchTagIdxKeyFree(&pOldTagIdxKey);
×
UNCOV
813
      metaFetchTagIdxKeyFree(&pNewTagIdxKey);
×
814
    }
815
  }
UNCOV
816
  return code;
×
817
}
818

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

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

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

UNCOV
842
      STagIdxKey *pTagIdxKey = NULL;
×
843
      int32_t     nTagIdxKey;
844

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

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

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

867
  const SMetaEntry *pEntry;
UNCOV
868
  if (META_TABLE_OP_DELETE == op) {
×
UNCOV
869
    pEntry = pParam->pOldEntry;
×
870
  } else {
UNCOV
871
    pEntry = pParam->pEntry;
×
872
  }
873

UNCOV
874
  SBtimeIdxKey key = {
×
UNCOV
875
      .uid = pEntry->uid,
×
876
  };
877

UNCOV
878
  if (TSDB_CHILD_TABLE == pEntry->type) {
×
UNCOV
879
    key.btime = pEntry->ctbEntry.btime;
×
UNCOV
880
  } else if (TSDB_NORMAL_TABLE == pEntry->type) {
×
UNCOV
881
    key.btime = pEntry->ntbEntry.btime;
×
882
  } else {
883
    return TSDB_CODE_INVALID_PARA;
×
884
  }
885

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

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

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

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

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

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

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

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

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

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

UNCOV
947
  const SMetaEntry *pEntry = pParam->pEntry;
×
UNCOV
948
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
×
949

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

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

UNCOV
963
  return TSDB_CODE_SUCCESS;
×
964
}
965

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

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

UNCOV
975
  if (TSDB_CHILD_TABLE == pEntry->type) {
×
UNCOV
976
    ctx.ttlDays = pEntry->ctbEntry.ttlDays;
×
UNCOV
977
  } else if (TSDB_NORMAL_TABLE == pEntry->type) {
×
UNCOV
978
    ctx.ttlDays = pEntry->ntbEntry.ttlDays;
×
979
  } else {
980
    code = TSDB_CODE_INVALID_PARA;
×
981
  }
982

UNCOV
983
  if (TSDB_CODE_SUCCESS == code) {
×
UNCOV
984
    int32_t ret = ttlMgrDeleteTtl(pMeta->pTtlMgr, &ctx);
×
UNCOV
985
    if (ret < 0) {
×
986
      metaError("vgId:%d, failed to delete ttl, uid: %" PRId64 " %s", TD_VID(pMeta->pVnode), pEntry->uid,
×
987
                tstrerror(ret));
988
    }
989
  }
UNCOV
990
  return code;
×
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) {
18✔
1052
  int32_t code = TSDB_CODE_SUCCESS;
18✔
1053

1054
  SMetaTableOp ops[] = {
18✔
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++) {
108✔
1063
    SMetaTableOp          *op = &ops[i];
90✔
1064
    const SMetaHandleParam param = {
90✔
1065
        .pEntry = pEntry,
1066
    };
1067

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

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

1080
  metaWLock(pMeta);
18✔
1081
  code = metaHandleSuperTableCreateImpl(pMeta, pEntry);
18✔
1082
  metaULock(pMeta);
18✔
1083

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

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

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

UNCOV
1098
  SMetaTableOp ops[] = {
×
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

UNCOV
1107
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
UNCOV
1108
    SMetaTableOp *op = &ops[i];
×
1109

UNCOV
1110
    SMetaHandleParam param = {
×
1111
        .pEntry = pEntry,
1112
    };
1113

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

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

1126
  // update TDB
UNCOV
1127
  metaWLock(pMeta);
×
UNCOV
1128
  code = metaHandleNormalTableCreateImpl(pMeta, pEntry);
×
UNCOV
1129
  metaULock(pMeta);
×
1130

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

UNCOV
1136
    if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
×
UNCOV
1137
      int32_t rc = tsdbCacheNewTable(pMeta->pVnode->pTsdb, pEntry->uid, -1, &pEntry->ntbEntry.schemaRow);
×
UNCOV
1138
      if (rc < 0) {
×
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
  }
UNCOV
1145
  return code;
×
1146
}
1147

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

UNCOV
1151
  SMetaTableOp ops[] = {
×
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

UNCOV
1161
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
UNCOV
1162
    SMetaTableOp *op = &ops[i];
×
1163

UNCOV
1164
    SMetaHandleParam param = {
×
1165
        .pEntry = pEntry,
1166
        .pSuperEntry = pSuperEntry,
1167
    };
1168

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

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

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

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

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

1202
  // update TDB
UNCOV
1203
  metaWLock(pMeta);
×
UNCOV
1204
  code = metaHandleChildTableCreateImpl(pMeta, pEntry, pSuperEntry);
×
UNCOV
1205
  metaULock(pMeta);
×
1206

1207
  // update other stuff
UNCOV
1208
  if (TSDB_CODE_SUCCESS == code) {
×
UNCOV
1209
    pMeta->pVnode->config.vndStats.numOfCTables++;
×
1210

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

UNCOV
1220
    if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
×
UNCOV
1221
      int32_t rc = tsdbCacheNewTable(pMeta->pVnode->pTsdb, pEntry->uid, pEntry->ctbEntry.suid, NULL);
×
UNCOV
1222
      if (rc < 0) {
×
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

UNCOV
1232
  metaFetchEntryFree(&pSuperEntry);
×
UNCOV
1233
  return code;
×
1234
}
1235

UNCOV
1236
static int32_t metaHandleNormalTableDropImpl(SMeta *pMeta, SMetaHandleParam *pParam) {
×
UNCOV
1237
  int32_t code = TSDB_CODE_SUCCESS;
×
1238

UNCOV
1239
  SMetaTableOp ops[] = {
×
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

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

UNCOV
1258
  return code;
×
1259
}
1260

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

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

UNCOV
1272
  SMetaHandleParam param = {
×
1273
      .pEntry = pEntry,
1274
      .pOldEntry = pOldEntry,
1275
  };
1276

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

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

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

UNCOV
1300
  if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
×
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

UNCOV
1307
  metaFetchEntryFree(&pOldEntry);
×
UNCOV
1308
  return code;
×
1309
}
1310

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

UNCOV
1314
  const SMetaEntry *pEntry = pParam->pEntry;
×
UNCOV
1315
  const SMetaEntry *pChild = pParam->pOldEntry;
×
UNCOV
1316
  const SMetaEntry *pSuper = pParam->pSuperEntry;
×
1317

UNCOV
1318
  SMetaTableOp ops[] = {
×
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

UNCOV
1328
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
UNCOV
1329
    SMetaTableOp *op = &ops[i];
×
1330

UNCOV
1331
    if (op->table == META_ENTRY_TABLE && superDropped) {
×
UNCOV
1332
      continue;
×
1333
    }
1334

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

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

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

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

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

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

UNCOV
1376
  SMetaHandleParam param = {
×
1377
      .pEntry = pEntry,
1378
      .pOldEntry = pChild,
1379
      .pSuperEntry = pSuper,
1380
  };
1381

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

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

UNCOV
1402
  if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
×
UNCOV
1403
    int32_t ret = tsdbCacheDropTable(pMeta->pVnode->pTsdb, pChild->uid, pSuper->uid, NULL);
×
UNCOV
1404
    if (ret < 0) {
×
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
UNCOV
1421
  metaFetchEntryFree(&pChild);
×
UNCOV
1422
  metaFetchEntryFree(&pSuper);
×
UNCOV
1423
  return code;
×
1424
}
1425

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

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

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

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

1456
  for (;;) {
1457
    if (tdbTbcNext(cursor, &key, &keySize, NULL, NULL) < 0) {
4!
1458
      break;
4✔
1459
    }
1460

UNCOV
1461
    if (((SCtbIdxKey *)key)->suid < suid) {
×
UNCOV
1462
      continue;
×
UNCOV
1463
    } else if (((SCtbIdxKey *)key)->suid > suid) {
×
UNCOV
1464
      break;
×
1465
    }
1466

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

1476
  tdbTbcClose(cursor);
4✔
1477
  tdbFreeClear(key);
4✔
1478
  return code;
4✔
1479
}
1480

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

1485
  SMetaTableOp ops[] = {
4✔
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++) {
19✔
1495
    SMetaTableOp *op = &ops[i];
16✔
1496

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

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

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

UNCOV
1514
  const SMetaEntry *pEntry = pParam->pEntry;
×
1515

UNCOV
1516
  SMetaTableOp ops[] = {
×
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
  };
UNCOV
1522
  for (int32_t i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
UNCOV
1523
    SMetaTableOp *op = &ops[i];
×
UNCOV
1524
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
×
UNCOV
1525
    if (code) {
×
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
UNCOV
1535
  return code;
×
1536
}
1537

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

UNCOV
1541
  const SMetaEntry *pEntry = pParam->pEntry;
×
UNCOV
1542
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
×
UNCOV
1543
  const SMetaEntry *pSuperEntry = pParam->pSuperEntry;
×
1544

UNCOV
1545
  SMetaTableOp ops[] = {
×
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

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

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

UNCOV
1566
  if (metaTbGroupCacheClear(pMeta, pSuperEntry->uid) < 0) {
×
1567
    metaErr(TD_VID(pMeta->pVnode), code);
×
1568
  }
UNCOV
1569
  return code;
×
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) {
16✔
1578
  int32_t code = TSDB_CODE_SUCCESS;
16✔
1579

1580
  const SMetaEntry *pEntry = pParam->pEntry;
16✔
1581
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
16✔
1582

1583
  SMetaTableOp ops[] = {
16✔
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++) {
64✔
1590
    SMetaTableOp *op = &ops[i];
48✔
1591
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
48✔
1592
    if (code) {
48!
1593
      metaErr(TD_VID(pMeta->pVnode), code);
×
1594
      return code;
×
1595
    }
1596
  }
1597

1598
  return code;
16✔
1599
}
1600

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

1604
  SMetaEntry *pOldEntry = NULL;
16✔
1605

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

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

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

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

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

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

UNCOV
1674
    tsdbCacheInvalidateSchema(pTsdb, pEntry->uid, -1, pEntry->stbEntry.schemaRow.version);
×
1675
  }
1676

1677
  metaFetchEntryFree(&pOldEntry);
16✔
1678
  return code;
16✔
1679
}
1680

UNCOV
1681
static int32_t metaHandleChildTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
×
UNCOV
1682
  int32_t code = TSDB_CODE_SUCCESS;
×
1683

UNCOV
1684
  SMetaEntry *pOldEntry = NULL;
×
UNCOV
1685
  SMetaEntry *pSuperEntry = NULL;
×
1686

UNCOV
1687
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
×
UNCOV
1688
  if (code) {
×
UNCOV
1689
    metaErr(TD_VID(pMeta->pVnode), code);
×
UNCOV
1690
    return code;
×
1691
  }
1692

UNCOV
1693
  code = metaFetchEntryByUid(pMeta, pEntry->ctbEntry.suid, &pSuperEntry);
×
UNCOV
1694
  if (code) {
×
UNCOV
1695
    metaErr(TD_VID(pMeta->pVnode), code);
×
UNCOV
1696
    metaFetchEntryFree(&pOldEntry);
×
1697
    return code;
×
1698
  }
1699

UNCOV
1700
  SMetaHandleParam param = {
×
1701
      .pEntry = pEntry,
1702
      .pOldEntry = pOldEntry,
1703
      .pSuperEntry = pSuperEntry,
1704
  };
1705

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

UNCOV
1716
  metaFetchEntryFree(&pOldEntry);
×
UNCOV
1717
  metaFetchEntryFree(&pSuperEntry);
×
UNCOV
1718
  return code;
×
1719
}
1720

UNCOV
1721
static int32_t metaHandleNormalTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
×
UNCOV
1722
  int32_t     code = TSDB_CODE_SUCCESS;
×
UNCOV
1723
  SMetaEntry *pOldEntry = NULL;
×
1724

1725
  // fetch old entry
UNCOV
1726
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
×
UNCOV
1727
  if (code) {
×
UNCOV
1728
    metaErr(TD_VID(pMeta->pVnode), code);
×
UNCOV
1729
    return code;
×
1730
  }
1731

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

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

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

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

1780
static int32_t metaHandleSuperTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) {
4✔
1781
  int32_t     code = TSDB_CODE_SUCCESS;
4✔
1782
  SArray     *childList = NULL;
4✔
1783
  SMetaEntry *pOldEntry = NULL;
4✔
1784

1785
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
4✔
1786
  if (code) {
4!
UNCOV
1787
    metaErr(TD_VID(pMeta->pVnode), code);
×
UNCOV
1788
    return code;
×
1789
  }
1790

1791
  code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &childList);
4✔
1792
  if (code) {
4!
UNCOV
1793
    metaErr(TD_VID(pMeta->pVnode), code);
×
UNCOV
1794
    metaFetchEntryFree(&pOldEntry);
×
1795
    return code;
×
1796
  }
1797

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

1803
  // loop to drop all child tables
1804
  for (int32_t i = 0; i < taosArrayGetSize(childList); i++) {
4!
UNCOV
1805
    SMetaEntry childEntry = {
×
UNCOV
1806
        .version = pEntry->version,
×
UNCOV
1807
        .uid = *(tb_uid_t *)taosArrayGet(childList, i),
×
1808
        .type = -TSDB_CHILD_TABLE,
1809
    };
1810

UNCOV
1811
    code = metaHandleChildTableDrop(pMeta, &childEntry, true);
×
UNCOV
1812
    if (code) {
×
UNCOV
1813
      metaErr(TD_VID(pMeta->pVnode), code);
×
1814
    }
1815
  }
1816

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

1832
  // do other stuff
1833
  metaUpdTimeSeriesNum(pMeta);
4✔
1834

1835
  // free resource and return
1836
  taosArrayDestroy(childList);
4✔
1837
  metaFetchEntryFree(&pOldEntry);
4✔
1838
  return code;
4✔
1839
}
1840

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

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

1852
  if (pEntry->type > 0) {
38✔
1853
    bool isExist = false;
34✔
1854
    if (TSDB_CODE_SUCCESS == metaGetInfo(pMeta, pEntry->uid, &info, NULL)) {
34✔
1855
      isExist = true;
16✔
1856
    }
1857

1858
    switch (type) {
34!
1859
      case TSDB_SUPER_TABLE: {
34✔
1860
        if (isExist) {
34✔
1861
          code = metaHandleSuperTableUpdate(pMeta, pEntry);
16✔
1862
        } else {
1863
          code = metaHandleSuperTableCreate(pMeta, pEntry);
18✔
1864
        }
1865
        break;
34✔
1866
      }
UNCOV
1867
      case TSDB_CHILD_TABLE: {
×
UNCOV
1868
        if (isExist) {
×
UNCOV
1869
          code = metaHandleChildTableUpdate(pMeta, pEntry);
×
1870
        } else {
UNCOV
1871
          code = metaHandleChildTableCreate(pMeta, pEntry);
×
1872
        }
UNCOV
1873
        break;
×
1874
      }
UNCOV
1875
      case TSDB_NORMAL_TABLE: {
×
UNCOV
1876
        if (isExist) {
×
UNCOV
1877
          code = metaHandleNormalTableUpdate(pMeta, pEntry);
×
1878
        } else {
UNCOV
1879
          code = metaHandleNormalTableCreate(pMeta, pEntry);
×
1880
        }
UNCOV
1881
        break;
×
1882
      }
UNCOV
1883
      default: {
×
UNCOV
1884
        code = TSDB_CODE_INVALID_PARA;
×
1885
        break;
×
1886
      }
1887
    }
1888
  } else {
1889
    switch (type) {
4!
1890
      case TSDB_SUPER_TABLE: {
4✔
1891
        code = metaHandleSuperTableDrop(pMeta, pEntry);
4✔
1892
        break;
4✔
1893
      }
UNCOV
1894
      case TSDB_CHILD_TABLE: {
×
UNCOV
1895
        code = metaHandleChildTableDrop(pMeta, pEntry, false);
×
UNCOV
1896
        break;
×
1897
      }
UNCOV
1898
      case TSDB_NORMAL_TABLE: {
×
UNCOV
1899
        code = metaHandleNormalTableDrop(pMeta, pEntry);
×
UNCOV
1900
        break;
×
1901
      }
UNCOV
1902
      default: {
×
UNCOV
1903
        code = TSDB_CODE_INVALID_PARA;
×
UNCOV
1904
        break;
×
1905
      }
1906
    }
1907
  }
1908

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