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

taosdata / TDengine / #3796

31 Mar 2025 10:39AM UTC coverage: 30.372% (-7.1%) from 37.443%
#3796

push

travis-ci

happyguoxy
test:add test cases

69287 of 309062 branches covered (22.42%)

Branch coverage included in aggregate %.

118044 of 307720 relevant lines covered (38.36%)

278592.15 hits per line

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

24.36
/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
extern SDmNotifyHandle dmNotifyHdl;
14

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

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

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

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

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

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

61
typedef struct {
62
  EMetaTable   table;
63
  EMetaTableOp op;
64
} SMetaTableOp;
65

66
int32_t metaFetchEntryByUid(SMeta *pMeta, int64_t uid, SMetaEntry **ppEntry) {
37✔
67
  int32_t code = TSDB_CODE_SUCCESS;
37✔
68
  void   *value = NULL;
37✔
69
  int32_t valueSize = 0;
37✔
70

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

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

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

92
  // decode entry
93
  SDecoder   decoder = {0};
37✔
94
  SMetaEntry entry = {0};
37✔
95

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

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

115
  tdbFreeClear(value);
37✔
116
  tDecoderClear(&decoder);
37✔
117
  return code;
37✔
118
}
119

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

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

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

141
void metaFetchEntryFree(SMetaEntry **ppEntry) { metaCloneEntryFree(ppEntry); }
37✔
142

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

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

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

164
  value = taosMemoryMalloc(valueSize);
40!
165
  if (NULL == value) {
40!
166
    metaErr(vgId, terrno);
×
167
    return terrno;
×
168
  }
169

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

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

197
static int32_t metaEntryTableInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
20✔
198
  return metaEntryTableUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
20✔
199
}
200

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

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

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

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

231
  // encode schema
232
  tEncodeSize(tEncodeSSchemaWrapper, pSchema, valueSize, code);
54!
233
  if (TSDB_CODE_SUCCESS != code) {
27!
234
    metaErr(vgId, code);
×
235
    return code;
×
236
  }
237

238
  value = taosMemoryMalloc(valueSize);
27!
239
  if (NULL == value) {
27!
240
    metaErr(vgId, terrno);
×
241
    return terrno;
×
242
  }
243

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

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

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

273
static int32_t metaAddOrDropTagIndexOfSuperTable(SMeta *pMeta, const SMetaHandleParam *pParam,
26✔
274
                                                 const SSchema *pOldColumn, const SSchema *pNewColumn) {
275
  int32_t code = TSDB_CODE_SUCCESS;
26✔
276

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

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

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

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

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

326
    STagIdxKey *pTagIdxKey = NULL;
×
327
    int32_t     tagIdxKeySize = 0;
×
328

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

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

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

365
    metaFetchTagIdxKeyFree(&pTagIdxKey);
×
366
    metaFetchEntryFree(&pChildEntry);
×
367
  }
368

369
  taosArrayDestroy(childTables);
×
370
  return code;
×
371
}
372

373
static int32_t metaAddOrDropColumnIndexOfVirtualSuperTable(SMeta *pMeta, const SMetaHandleParam *pParam,
×
374
                                                           const SSchema *pOldColumn, const SSchema *pNewColumn) {
375
  int32_t code = TSDB_CODE_SUCCESS;
×
376

377
  const SMetaEntry *pEntry = pParam->pEntry;
×
378
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
×
379
  enum { ADD_COLUMN, DROP_COLUMN } action;
380

381
  if (pOldColumn && pNewColumn) {
×
382
    return TSDB_CODE_SUCCESS;
×
383
  } else if (pOldColumn) {
×
384
    action = DROP_COLUMN;
×
385
  } else {
386
    action = ADD_COLUMN;
×
387
  }
388

389
  // fetch all child tables
390
  SArray *childTables = 0;
×
391
  code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &childTables);
×
392
  if (code) {
×
393
    metaErr(TD_VID(pMeta->pVnode), code);
×
394
    return code;
×
395
  }
396

397
  // do drop or add index
398
  for (int32_t i = 0; i < taosArrayGetSize(childTables); i++) {
×
399
    int64_t uid = *(int64_t *)taosArrayGet(childTables, i);
×
400

401
    // fetch child entry
402
    SMetaEntry *pChildEntry = NULL;
×
403
    code = metaFetchEntryByUid(pMeta, uid, &pChildEntry);
×
404
    if (code) {
×
405
      metaErr(TD_VID(pMeta->pVnode), code);
×
406
      taosArrayDestroy(childTables);
×
407
      return code;
×
408
    }
409

410
    SMetaHandleParam param = {
×
411
        .pEntry = pChildEntry
412
    };
413

414
    if (action == ADD_COLUMN) {
×
415
      code = updataTableColRef(&pChildEntry->colRef, pNewColumn, 1, NULL);
×
416
      if (code) {
×
417
        metaErr(TD_VID(pMeta->pVnode), code);
×
418
        taosArrayDestroy(childTables);
×
419
        metaFetchEntryFree(&pChildEntry);
×
420
        return code;
×
421
      }
422

423
      code = metaEntryTableUpdate(pMeta, &param);
×
424
      if (code) {
×
425
        metaErr(TD_VID(pMeta->pVnode), code);
×
426
        taosArrayDestroy(childTables);
×
427
        metaFetchEntryFree(&pChildEntry);
×
428
        return code;
×
429
      }
430
    } else {
431
      code = updataTableColRef(&pChildEntry->colRef, pOldColumn, 0, NULL);
×
432
      if (code) {
×
433
        metaErr(TD_VID(pMeta->pVnode), code);
×
434
        taosArrayDestroy(childTables);
×
435
        metaFetchEntryFree(&pChildEntry);
×
436
        return code;
×
437
      }
438

439
      code = metaEntryTableUpdate(pMeta, &param);
×
440
      if (code) {
×
441
        metaErr(TD_VID(pMeta->pVnode), code);
×
442
        taosArrayDestroy(childTables);
×
443
        metaFetchEntryFree(&pChildEntry);
×
444
        return code;
×
445
      }
446
    }
447
    metaFetchEntryFree(&pChildEntry);
×
448
  }
449

450
  taosArrayDestroy(childTables);
×
451
  return code;
×
452

453
}
454

455
static int32_t metaUpdateSuperTableTagSchema(SMeta *pMeta, const SMetaHandleParam *pParam) {
8✔
456
  int32_t               code = TSDB_CODE_SUCCESS;
8✔
457
  const SMetaEntry     *pEntry = pParam->pEntry;
8✔
458
  const SMetaEntry     *pOldEntry = pParam->pOldEntry;
8✔
459
  const SSchemaWrapper *pNewTagSchema = &pEntry->stbEntry.schemaTag;
8✔
460
  const SSchemaWrapper *pOldTagSchema = &pOldEntry->stbEntry.schemaTag;
8✔
461

462
  int32_t iOld = 0, iNew = 0;
8✔
463
  for (; iOld < pOldTagSchema->nCols && iNew < pNewTagSchema->nCols;) {
30✔
464
    SSchema *pOldColumn = pOldTagSchema->pSchema + iOld;
22✔
465
    SSchema *pNewColumn = pNewTagSchema->pSchema + iNew;
22✔
466

467
    if (pOldColumn->colId == pNewColumn->colId) {
22!
468
      code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, pOldColumn, pNewColumn);
22✔
469
      if (code) {
22!
470
        metaErr(TD_VID(pMeta->pVnode), code);
×
471
        return code;
×
472
      }
473

474
      iOld++;
22✔
475
      iNew++;
22✔
476
    } else if (pOldColumn->colId < pNewColumn->colId) {
×
477
      code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, pOldColumn, NULL);
×
478
      if (code) {
×
479
        metaErr(TD_VID(pMeta->pVnode), code);
×
480
        return code;
×
481
      }
482

483
      iOld++;
×
484
    } else {
485
      code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, NULL, pNewColumn);
×
486
      if (code) {
×
487
        metaErr(TD_VID(pMeta->pVnode), code);
×
488
        return code;
×
489
      }
490

491
      iNew++;
×
492
    }
493
  }
494

495
  for (; iOld < pOldTagSchema->nCols; iOld++) {
10✔
496
    SSchema *pOldColumn = pOldTagSchema->pSchema + iOld;
2✔
497
    code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, pOldColumn, NULL);
2✔
498
    if (code) {
2!
499
      metaErr(TD_VID(pMeta->pVnode), code);
×
500
      return code;
×
501
    }
502
  }
503

504
  for (; iNew < pNewTagSchema->nCols; iNew++) {
10✔
505
    SSchema *pNewColumn = pNewTagSchema->pSchema + iNew;
2✔
506
    code = metaAddOrDropTagIndexOfSuperTable(pMeta, pParam, NULL, pNewColumn);
2✔
507
    if (code) {
2!
508
      metaErr(TD_VID(pMeta->pVnode), code);
×
509
      return code;
×
510
    }
511
  }
512

513
  return code;
8✔
514
}
515

516
static int32_t metaUpdateSuperTableRowSchema(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
517
  int32_t               code = TSDB_CODE_SUCCESS;
×
518
  const SMetaEntry     *pEntry = pParam->pEntry;
×
519
  const SMetaEntry     *pOldEntry = pParam->pOldEntry;
×
520
  const SSchemaWrapper *pNewRowSchema = &pEntry->stbEntry.schemaRow;
×
521
  const SSchemaWrapper *pOldRowSchema = &pOldEntry->stbEntry.schemaRow;
×
522

523
  int32_t iOld = 0, iNew = 0;
×
524
  for (; iOld < pOldRowSchema->nCols && iNew < pNewRowSchema->nCols;) {
×
525
    SSchema *pOldColumn = pOldRowSchema->pSchema + iOld;
×
526
    SSchema *pNewColumn = pNewRowSchema->pSchema + iNew;
×
527

528
    if (pOldColumn->colId == pNewColumn->colId) {
×
529
      code = metaAddOrDropColumnIndexOfVirtualSuperTable(pMeta, pParam, pOldColumn, pNewColumn);
×
530
      if (code) {
×
531
        metaErr(TD_VID(pMeta->pVnode), code);
×
532
        return code;
×
533
      }
534

535
      iOld++;
×
536
      iNew++;
×
537
    } else if (pOldColumn->colId < pNewColumn->colId) {
×
538
      code = metaAddOrDropColumnIndexOfVirtualSuperTable(pMeta, pParam, pOldColumn, NULL);
×
539
      if (code) {
×
540
        metaErr(TD_VID(pMeta->pVnode), code);
×
541
        return code;
×
542
      }
543

544
      iOld++;
×
545
    } else {
546
      code = metaAddOrDropColumnIndexOfVirtualSuperTable(pMeta, pParam, NULL, pNewColumn);
×
547
      if (code) {
×
548
        metaErr(TD_VID(pMeta->pVnode), code);
×
549
        return code;
×
550
      }
551

552
      iNew++;
×
553
    }
554
  }
555

556
  for (; iOld < pOldRowSchema->nCols; iOld++) {
×
557
    SSchema *pOldColumn = pOldRowSchema->pSchema + iOld;
×
558
    code = metaAddOrDropColumnIndexOfVirtualSuperTable(pMeta, pParam, pOldColumn, NULL);
×
559
    if (code) {
×
560
      metaErr(TD_VID(pMeta->pVnode), code);
×
561
      return code;
×
562
    }
563
  }
564

565
  for (; iNew < pNewRowSchema->nCols; iNew++) {
×
566
    SSchema *pNewColumn = pNewRowSchema->pSchema + iNew;
×
567
    code = metaAddOrDropColumnIndexOfVirtualSuperTable(pMeta, pParam, NULL, pNewColumn);
×
568
    if (code) {
×
569
      metaErr(TD_VID(pMeta->pVnode), code);
×
570
      return code;
×
571
    }
572
  }
573

574
  return code;
×
575
}
576

577
static int32_t metaSchemaTableUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
35✔
578
  int32_t code = TSDB_CODE_SUCCESS;
35✔
579

580
  const SMetaEntry *pEntry = pParam->pEntry;
35✔
581
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
35✔
582

583
  if (NULL == pOldEntry) {
35✔
584
    return metaSchemaTableUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
19✔
585
  }
586

587
  if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
16!
588
    // check row schema
589
    if (pOldEntry->ntbEntry.schemaRow.version != pEntry->ntbEntry.schemaRow.version) {
×
590
      return metaSchemaTableUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
×
591
    }
592
  } else if (pEntry->type == TSDB_SUPER_TABLE) {
16!
593
    // check row schema
594
    if (pOldEntry->stbEntry.schemaRow.version != pEntry->stbEntry.schemaRow.version) {
16✔
595
      if (TABLE_IS_VIRTUAL(pEntry->flags)) {
8!
596
        return metaUpdateSuperTableRowSchema(pMeta, pParam);
×
597
      } else {
598
        return metaSchemaTableUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
8✔
599
      }
600

601
    }
602

603
    // check tag schema
604
    code = metaUpdateSuperTableTagSchema(pMeta, pParam);
8✔
605
    if (code) {
8!
606
      metaErr(TD_VID(pMeta->pVnode), code);
×
607
      return code;
×
608
    }
609

610
  } else {
611
    return TSDB_CODE_INVALID_PARA;
×
612
  }
613

614
  return TSDB_CODE_SUCCESS;
8✔
615
}
616

617
static int32_t metaSchemaTableDelete(SMeta *pMeta, const SMetaHandleParam *pEntry) {
×
618
  // TODO
619
  return TSDB_CODE_SUCCESS;
×
620
}
621

622
// Uid Index
623
static void metaBuildEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
36✔
624
  pInfo->uid = pEntry->uid;
36✔
625
  pInfo->version = pEntry->version;
36✔
626
  if (pEntry->type == TSDB_SUPER_TABLE) {
36✔
627
    pInfo->suid = pEntry->uid;
35✔
628
    pInfo->skmVer = pEntry->stbEntry.schemaRow.version;
35✔
629
  } else if (pEntry->type == TSDB_CHILD_TABLE || pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
1!
630
    pInfo->suid = pEntry->ctbEntry.suid;
1✔
631
    pInfo->skmVer = 0;
1✔
632
  } else if (pEntry->type == TSDB_NORMAL_TABLE || pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
×
633
    pInfo->suid = 0;
×
634
    pInfo->skmVer = pEntry->ntbEntry.schemaRow.version;
×
635
  }
636
}
36✔
637

638
static int32_t metaUidIdxUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
36✔
639
  int32_t code = TSDB_CODE_SUCCESS;
36✔
640
  int32_t vgId = TD_VID(pMeta->pVnode);
36✔
641

642
  const SMetaEntry *pEntry = pParam->pEntry;
36✔
643

644
  // update cache
645
  SMetaInfo info = {0};
36✔
646
  metaBuildEntryInfo(pEntry, &info);
36✔
647
  code = metaCacheUpsert(pMeta, &info);
36✔
648
  if (code) {
36!
649
    metaErr(vgId, code);
×
650
  }
651

652
  // put to tdb
653
  SUidIdxVal value = {
36✔
654
      .suid = info.suid,
36✔
655
      .skmVer = info.skmVer,
36✔
656
      .version = pEntry->version,
36✔
657
  };
658
  if (META_TABLE_OP_INSERT == op) {
36✔
659
    code = tdbTbInsert(pMeta->pUidIdx, &pEntry->uid, sizeof(pEntry->uid), &value, sizeof(value), pMeta->txn);
20✔
660
  } else if (META_TABLE_OP_UPDATA == op) {
16!
661
    code = tdbTbUpsert(pMeta->pUidIdx, &pEntry->uid, sizeof(pEntry->uid), &value, sizeof(value), pMeta->txn);
16✔
662
  }
663
  return code;
36✔
664
}
665

666
static int32_t metaUidIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
20✔
667
  return metaUidIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
20✔
668
}
669

670
static int32_t metaUidIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
16✔
671
  return metaUidIdxUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
16✔
672
}
673

674
static int32_t metaUidIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
4✔
675
  int32_t code = 0;
4✔
676

677
  const SMetaEntry *pEntry = pParam->pOldEntry;
4✔
678

679
  // delete tdb
680
  code = tdbTbDelete(pMeta->pUidIdx, &pEntry->uid, sizeof(pEntry->uid), pMeta->txn);
4✔
681
  if (code) {
4!
682
    metaErr(TD_VID(pMeta->pVnode), code);
×
683
  }
684

685
  // delete cache
686
  (void)metaCacheDrop(pMeta, pEntry->uid);
4✔
687
  return code;
4✔
688
}
689

690
// Name Index
691
static int32_t metaNameIdxUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
20✔
692
  int32_t code = TSDB_CODE_SUCCESS;
20✔
693

694
  const SMetaEntry *pEntry = pParam->pEntry;
20✔
695

696
  if (META_TABLE_OP_INSERT == op) {
20!
697
    code = tdbTbInsert(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, &pEntry->uid, sizeof(pEntry->uid),
20✔
698
                       pMeta->txn);
699
  } else if (META_TABLE_OP_UPDATA == op) {
×
700
    code = tdbTbUpsert(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, &pEntry->uid, sizeof(pEntry->uid),
×
701
                       pMeta->txn);
702
  } else {
703
    code = TSDB_CODE_INVALID_PARA;
×
704
  }
705
  return code;
20✔
706
}
707

708
static int32_t metaNameIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
20✔
709
  int32_t code = TSDB_CODE_SUCCESS;
20✔
710
  return metaNameIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
20✔
711
}
712

713
static int32_t metaNameIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
714
  return metaNameIdxUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
×
715
}
716

717
static int32_t metaNameIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
4✔
718
  int32_t code = TSDB_CODE_SUCCESS;
4✔
719

720
  const SMetaEntry *pEntry = pParam->pOldEntry;
4✔
721
  code = tdbTbDelete(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, pMeta->txn);
4✔
722
  if (code) {
4!
723
    metaErr(TD_VID(pMeta->pVnode), code);
×
724
  }
725
  return code;
4✔
726
}
727

728
// Suid Index
729
static int32_t metaSUidIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
19✔
730
  const SMetaEntry *pEntry = pParam->pEntry;
19✔
731

732
  int32_t code = tdbTbInsert(pMeta->pSuidIdx, &pEntry->uid, sizeof(pEntry->uid), NULL, 0, pMeta->txn);
19✔
733
  if (code) {
19!
734
    metaErr(TD_VID(pMeta->pVnode), code);
×
735
  }
736
  return code;
19✔
737
}
738

739
static int32_t metaSUidIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
4✔
740
  const SMetaEntry *pEntry = pParam->pOldEntry;
4✔
741

742
  int32_t code = tdbTbDelete(pMeta->pSuidIdx, &pEntry->uid, sizeof(pEntry->uid), pMeta->txn);
4✔
743
  if (code) {
4!
744
    metaErr(TD_VID(pMeta->pVnode), code);
×
745
  }
746
  return code;
4✔
747
}
748

749
// Child Index
750
static int32_t metaChildIdxUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
1✔
751
  int32_t code = TSDB_CODE_SUCCESS;
1✔
752

753
  const SMetaEntry *pEntry = pParam->pEntry;
1✔
754

755
  SCtbIdxKey key = {
1✔
756
      .suid = pEntry->ctbEntry.suid,
1✔
757
      .uid = pEntry->uid,
1✔
758
  };
759

760
  if (META_TABLE_OP_INSERT == op) {
1!
761
    code = tdbTbInsert(pMeta->pCtbIdx, &key, sizeof(key), pEntry->ctbEntry.pTags,
1✔
762
                       ((STag *)(pEntry->ctbEntry.pTags))->len, pMeta->txn);
1✔
763
  } else if (META_TABLE_OP_UPDATA == op) {
×
764
    code = tdbTbUpsert(pMeta->pCtbIdx, &key, sizeof(key), pEntry->ctbEntry.pTags,
×
765
                       ((STag *)(pEntry->ctbEntry.pTags))->len, pMeta->txn);
×
766
  } else {
767
    code = TSDB_CODE_INVALID_PARA;
×
768
  }
769
  return code;
1✔
770
}
771

772
static int32_t metaChildIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
1✔
773
  return metaChildIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
1✔
774
}
775

776
static int32_t metaChildIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
777
  const SMetaEntry *pEntry = pParam->pEntry;
×
778
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
×
779
  const SMetaEntry *pSuperEntry = pParam->pSuperEntry;
×
780

781
  const STag *pNewTags = (const STag *)pEntry->ctbEntry.pTags;
×
782
  const STag *pOldTags = (const STag *)pOldEntry->ctbEntry.pTags;
×
783
  if (pNewTags->len != pOldTags->len || memcmp(pNewTags, pOldTags, pNewTags->len)) {
×
784
    return metaChildIdxUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
×
785
  }
786
  return 0;
×
787
}
788

789
static int32_t metaChildIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
790
  const SMetaEntry *pEntry = pParam->pOldEntry;
×
791

792
  SCtbIdxKey key = {
×
793
      .suid = pEntry->ctbEntry.suid,
×
794
      .uid = pEntry->uid,
×
795
  };
796
  return tdbTbDelete(pMeta->pCtbIdx, &key, sizeof(key), pMeta->txn);
×
797
}
798

799
// Tag Index
800
static int32_t metaFetchTagIdxKey(SMeta *pMeta, const SMetaEntry *pEntry, const SSchema *pTagColumn,
1✔
801
                                  STagIdxKey **ppTagIdxKey, int32_t *pTagIdxKeySize) {
802
  int32_t code = TSDB_CODE_SUCCESS;
1✔
803

804
  STagIdxKey *pTagIdxKey = NULL;
1✔
805
  int32_t     nTagIdxKey;
806
  const void *pTagData = NULL;
1✔
807
  int32_t     nTagData = 0;
1✔
808

809
  STagVal tagVal = {
1✔
810
      .cid = pTagColumn->colId,
1✔
811
  };
812

813
  if (tTagGet((const STag *)pEntry->ctbEntry.pTags, &tagVal)) {
1!
814
    if (IS_VAR_DATA_TYPE(pTagColumn->type)) {
1!
815
      pTagData = tagVal.pData;
×
816
      nTagData = (int32_t)tagVal.nData;
×
817
    } else {
818
      pTagData = &(tagVal.i64);
1✔
819
      nTagData = tDataTypes[pTagColumn->type].bytes;
1✔
820
    }
821
  } else {
822
    if (!IS_VAR_DATA_TYPE(pTagColumn->type)) {
×
823
      nTagData = tDataTypes[pTagColumn->type].bytes;
×
824
    }
825
  }
826

827
  code = metaCreateTagIdxKey(pEntry->ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type,
1✔
828
                             pEntry->uid, &pTagIdxKey, &nTagIdxKey);
1✔
829
  if (code) {
1!
830
    metaErr(TD_VID(pMeta->pVnode), code);
×
831
    return code;
×
832
  }
833

834
  *ppTagIdxKey = pTagIdxKey;
1✔
835
  *pTagIdxKeySize = nTagIdxKey;
1✔
836
  return code;
1✔
837
}
838

839
static void metaFetchTagIdxKeyFree(STagIdxKey **ppTagIdxKey) {
1✔
840
  metaDestroyTagIdxKey(*ppTagIdxKey);
1✔
841
  *ppTagIdxKey = NULL;
1✔
842
}
1✔
843

844
static int32_t metaTagIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
1✔
845
  int32_t code = TSDB_CODE_SUCCESS;
1✔
846

847
  const SMetaEntry *pEntry = pParam->pEntry;
1✔
848
  const SMetaEntry *pSuperEntry = pParam->pSuperEntry;
1✔
849

850
  const SSchemaWrapper *pTagSchema = &pSuperEntry->stbEntry.schemaTag;
1✔
851
  if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
1!
852
    const SSchema *pTagColumn = &pTagSchema->pSchema[0];
×
853

854
    STagVal tagVal = {
×
855
        .cid = pTagColumn->colId,
×
856
    };
857

858
    const void *pTagData = pEntry->ctbEntry.pTags;
×
859
    int32_t     nTagData = ((const STag *)pEntry->ctbEntry.pTags)->len;
×
860
    code = metaSaveJsonVarToIdx(pMeta, pEntry, pTagColumn);
×
861
    if (code) {
×
862
      metaErr(TD_VID(pMeta->pVnode), code);
×
863
    }
864
  } else {
865
    for (int32_t i = 0; i < pTagSchema->nCols; i++) {
2✔
866
      STagIdxKey    *pTagIdxKey = NULL;
1✔
867
      int32_t        nTagIdxKey;
868
      const SSchema *pTagColumn = &pTagSchema->pSchema[i];
1✔
869

870
      if (!IS_IDX_ON(pTagColumn)) {
1!
871
        continue;
×
872
      }
873

874
      code = metaFetchTagIdxKey(pMeta, pEntry, pTagColumn, &pTagIdxKey, &nTagIdxKey);
1✔
875
      if (code) {
1!
876
        metaErr(TD_VID(pMeta->pVnode), code);
×
877
        return code;
×
878
      }
879

880
      code = tdbTbInsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn);
1✔
881
      if (code) {
1!
882
        metaErr(TD_VID(pMeta->pVnode), code);
×
883
        metaFetchTagIdxKeyFree(&pTagIdxKey);
×
884
        return code;
×
885
      }
886
      metaFetchTagIdxKeyFree(&pTagIdxKey);
1✔
887
    }
888
  }
889
  return code;
1✔
890
}
891

892
static int32_t metaTagIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
893
  int32_t code = TSDB_CODE_SUCCESS;
×
894

895
  const SMetaEntry     *pEntry = pParam->pEntry;
×
896
  const SMetaEntry     *pOldEntry = pParam->pOldEntry;
×
897
  const SMetaEntry     *pSuperEntry = pParam->pSuperEntry;
×
898
  const SSchemaWrapper *pTagSchema = &pSuperEntry->stbEntry.schemaTag;
×
899
  const STag           *pNewTags = (const STag *)pEntry->ctbEntry.pTags;
×
900
  const STag           *pOldTags = (const STag *)pOldEntry->ctbEntry.pTags;
×
901

902
  if (pNewTags->len == pOldTags->len && !memcmp(pNewTags, pOldTags, pNewTags->len)) {
×
903
    return code;
×
904
  }
905

906
  if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
×
907
    code = metaDelJsonVarFromIdx(pMeta, pOldEntry, &pTagSchema->pSchema[0]);
×
908
    if (code) {
×
909
      metaErr(TD_VID(pMeta->pVnode), code);
×
910
      return code;
×
911
    }
912

913
    code = metaSaveJsonVarToIdx(pMeta, pEntry, &pTagSchema->pSchema[0]);
×
914
    if (code) {
×
915
      metaErr(TD_VID(pMeta->pVnode), code);
×
916
      return code;
×
917
    }
918
  } else {
919
    for (int32_t i = 0; i < pTagSchema->nCols; i++) {
×
920
      const SSchema *pTagColumn = &pTagSchema->pSchema[i];
×
921

922
      if (!IS_IDX_ON(pTagColumn)) {
×
923
        continue;
×
924
      }
925

926
      STagIdxKey *pOldTagIdxKey = NULL;
×
927
      int32_t     oldTagIdxKeySize = 0;
×
928
      STagIdxKey *pNewTagIdxKey = NULL;
×
929
      int32_t     newTagIdxKeySize = 0;
×
930

931
      code = metaFetchTagIdxKey(pMeta, pOldEntry, pTagColumn, &pOldTagIdxKey, &oldTagIdxKeySize);
×
932
      if (code) {
×
933
        metaErr(TD_VID(pMeta->pVnode), code);
×
934
        return code;
×
935
      }
936

937
      code = metaFetchTagIdxKey(pMeta, pEntry, pTagColumn, &pNewTagIdxKey, &newTagIdxKeySize);
×
938
      if (code) {
×
939
        metaErr(TD_VID(pMeta->pVnode), code);
×
940
        metaFetchTagIdxKeyFree(&pOldTagIdxKey);
×
941
        return code;
×
942
      }
943

944
      if (tagIdxKeyCmpr(pOldTagIdxKey, oldTagIdxKeySize, pNewTagIdxKey, newTagIdxKeySize)) {
×
945
        code = tdbTbDelete(pMeta->pTagIdx, pOldTagIdxKey, oldTagIdxKeySize, pMeta->txn);
×
946
        if (code) {
×
947
          metaErr(TD_VID(pMeta->pVnode), code);
×
948
          metaFetchTagIdxKeyFree(&pOldTagIdxKey);
×
949
          metaFetchTagIdxKeyFree(&pNewTagIdxKey);
×
950
          return code;
×
951
        }
952

953
        code = tdbTbInsert(pMeta->pTagIdx, pNewTagIdxKey, newTagIdxKeySize, NULL, 0, pMeta->txn);
×
954
        if (code) {
×
955
          metaErr(TD_VID(pMeta->pVnode), code);
×
956
          metaFetchTagIdxKeyFree(&pOldTagIdxKey);
×
957
          metaFetchTagIdxKeyFree(&pNewTagIdxKey);
×
958
          return code;
×
959
        }
960
      }
961

962
      metaFetchTagIdxKeyFree(&pOldTagIdxKey);
×
963
      metaFetchTagIdxKeyFree(&pNewTagIdxKey);
×
964
    }
965
  }
966
  return code;
×
967
}
968

969
static int32_t metaTagIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
970
  int32_t code = TSDB_CODE_SUCCESS;
×
971

972
  const SMetaEntry     *pEntry = pParam->pEntry;
×
973
  const SMetaEntry     *pChild = pParam->pOldEntry;
×
974
  const SMetaEntry     *pSuper = pParam->pSuperEntry;
×
975
  const SSchemaWrapper *pTagSchema = &pSuper->stbEntry.schemaTag;
×
976
  const SSchema        *pTagColumn = NULL;
×
977
  const STag           *pTags = (const STag *)pChild->ctbEntry.pTags;
×
978

979
  if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
×
980
    pTagColumn = &pTagSchema->pSchema[0];
×
981
    code = metaDelJsonVarFromIdx(pMeta, pChild, pTagColumn);
×
982
    if (code) {
×
983
      metaErr(TD_VID(pMeta->pVnode), code);
×
984
    }
985
  } else {
986
    for (int32_t i = 0; i < pTagSchema->nCols; i++) {
×
987
      pTagColumn = &pTagSchema->pSchema[i];
×
988
      if (!IS_IDX_ON(pTagColumn)) {
×
989
        continue;
×
990
      }
991

992
      STagIdxKey *pTagIdxKey = NULL;
×
993
      int32_t     nTagIdxKey;
994

995
      code = metaFetchTagIdxKey(pMeta, pChild, pTagColumn, &pTagIdxKey, &nTagIdxKey);
×
996
      if (code) {
×
997
        metaErr(TD_VID(pMeta->pVnode), code);
×
998
        return code;
×
999
      }
1000

1001
      code = tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, pMeta->txn);
×
1002
      if (code) {
×
1003
        metaErr(TD_VID(pMeta->pVnode), code);
×
1004
        metaFetchTagIdxKeyFree(&pTagIdxKey);
×
1005
        return code;
×
1006
      }
1007
      metaFetchTagIdxKeyFree(&pTagIdxKey);
×
1008
    }
1009
  }
1010
  return code;
×
1011
}
1012

1013
// Btime Index
1014
static int32_t metaBtimeIdxUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
1✔
1015
  int32_t code = TSDB_CODE_SUCCESS;
1✔
1016

1017
  const SMetaEntry *pEntry;
1018
  if (META_TABLE_OP_DELETE == op) {
1!
1019
    pEntry = pParam->pOldEntry;
×
1020
  } else {
1021
    pEntry = pParam->pEntry;
1✔
1022
  }
1023

1024
  SBtimeIdxKey key = {
1✔
1025
      .uid = pEntry->uid,
1✔
1026
  };
1027

1028
  if (TSDB_CHILD_TABLE == pEntry->type || TSDB_VIRTUAL_CHILD_TABLE == pEntry->type) {
1!
1029
    key.btime = pEntry->ctbEntry.btime;
1✔
1030
  } else if (TSDB_NORMAL_TABLE == pEntry->type || TSDB_VIRTUAL_NORMAL_TABLE == pEntry->type) {
×
1031
    key.btime = pEntry->ntbEntry.btime;
×
1032
  } else {
1033
    return TSDB_CODE_INVALID_PARA;
×
1034
  }
1035

1036
  if (META_TABLE_OP_INSERT == op) {
1!
1037
    code = tdbTbInsert(pMeta->pBtimeIdx, &key, sizeof(key), NULL, 0, pMeta->txn);
1✔
1038
  } else if (META_TABLE_OP_UPDATA == op) {
×
1039
    code = tdbTbUpsert(pMeta->pBtimeIdx, &key, sizeof(key), NULL, 0, pMeta->txn);
×
1040
  } else if (META_TABLE_OP_DELETE == op) {
×
1041
    code = tdbTbDelete(pMeta->pBtimeIdx, &key, sizeof(key), pMeta->txn);
×
1042
  } else {
1043
    code = TSDB_CODE_INVALID_PARA;
×
1044
  }
1045
  if (code) {
1!
1046
    metaErr(TD_VID(pMeta->pVnode), code);
×
1047
  }
1048
  return code;
1✔
1049
}
1050

1051
static int32_t metaBtimeIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
1✔
1052
  return metaBtimeIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
1✔
1053
}
1054

1055
static int32_t metaBtimeIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
1056
  return metaBtimeIdxUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
×
1057
}
1058

1059
static int32_t metaBtimeIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
1060
  return metaBtimeIdxUpsert(pMeta, pParam, META_TABLE_OP_DELETE);
×
1061
}
1062

1063
// TTL Index
1064
static int32_t metaTtlIdxUpsert(SMeta *pMeta, const SMetaHandleParam *pParam, EMetaTableOp op) {
1✔
1065
  const SMetaEntry *pEntry = pParam->pEntry;
1✔
1066

1067
  STtlUpdTtlCtx ctx = {
1✔
1068
      .uid = pEntry->uid,
1✔
1069
      .pTxn = pMeta->txn,
1✔
1070
  };
1071
  if (TSDB_CHILD_TABLE == pEntry->type) {
1!
1072
    ctx.ttlDays = pEntry->ctbEntry.ttlDays;
1✔
1073
    ctx.changeTimeMs = pEntry->ctbEntry.btime;
1✔
1074
  } else if (TSDB_NORMAL_TABLE == pEntry->type) {
×
1075
    ctx.ttlDays = pEntry->ntbEntry.ttlDays;
×
1076
    ctx.changeTimeMs = pEntry->ntbEntry.btime;
×
1077
  } else {
1078
    return TSDB_CODE_INVALID_PARA;
×
1079
  }
1080

1081
  int32_t ret = ttlMgrInsertTtl(pMeta->pTtlMgr, &ctx);
1✔
1082
  if (ret < 0) {
1!
1083
    metaError("vgId:%d, failed to insert ttl, uid: %" PRId64 " %s", TD_VID(pMeta->pVnode), pEntry->uid, tstrerror(ret));
×
1084
  }
1085
  return TSDB_CODE_SUCCESS;
1✔
1086
}
1087

1088
static int32_t metaTtlIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
1✔
1089
  return metaTtlIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
1✔
1090
}
1091

1092
static int32_t metaTtlIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam);
1093

1094
static int32_t metaTtlIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
1095
  int32_t code = TSDB_CODE_SUCCESS;
×
1096

1097
  const SMetaEntry *pEntry = pParam->pEntry;
×
1098
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
×
1099

1100
  if ((pEntry->type == TSDB_CHILD_TABLE && pOldEntry->ctbEntry.ttlDays != pEntry->ctbEntry.ttlDays) ||
×
1101
      (pEntry->type == TSDB_NORMAL_TABLE && pOldEntry->ntbEntry.ttlDays != pEntry->ntbEntry.ttlDays)) {
×
1102
    code = metaTtlIdxDelete(pMeta, pParam);
×
1103
    if (code) {
×
1104
      metaErr(TD_VID(pMeta->pVnode), code);
×
1105
    }
1106

1107
    code = metaTtlIdxInsert(pMeta, pParam);
×
1108
    if (code) {
×
1109
      metaErr(TD_VID(pMeta->pVnode), code);
×
1110
    }
1111
  }
1112

1113
  return TSDB_CODE_SUCCESS;
×
1114
}
1115

1116
static int32_t metaTtlIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
1117
  int32_t code = TSDB_CODE_SUCCESS;
×
1118

1119
  const SMetaEntry *pEntry = pParam->pOldEntry;
×
1120
  STtlDelTtlCtx     ctx = {
×
1121
          .uid = pEntry->uid,
×
1122
          .pTxn = pMeta->txn,
×
1123
  };
1124

1125
  if (TSDB_CHILD_TABLE == pEntry->type) {
×
1126
    ctx.ttlDays = pEntry->ctbEntry.ttlDays;
×
1127
  } else if (TSDB_NORMAL_TABLE == pEntry->type) {
×
1128
    ctx.ttlDays = pEntry->ntbEntry.ttlDays;
×
1129
  } else {
1130
    code = TSDB_CODE_INVALID_PARA;
×
1131
  }
1132

1133
  if (TSDB_CODE_SUCCESS == code) {
×
1134
    int32_t ret = ttlMgrDeleteTtl(pMeta->pTtlMgr, &ctx);
×
1135
    if (ret < 0) {
×
1136
      metaError("vgId:%d, failed to delete ttl, uid: %" PRId64 " %s", TD_VID(pMeta->pVnode), pEntry->uid,
×
1137
                tstrerror(ret));
1138
    }
1139
  }
1140
  return code;
×
1141
}
1142

1143
static void metaTimeSeriesNotifyCheck(SMeta *pMeta) {
5✔
1144
#if defined(TD_ENTERPRISE)
1145
  int64_t nTimeSeries = metaGetTimeSeriesNum(pMeta, 0);
5✔
1146
  int64_t deltaTS = nTimeSeries - pMeta->pVnode->config.vndStats.numOfReportedTimeSeries;
5✔
1147
  if (deltaTS > tsTimeSeriesThreshold) {
5!
1148
    if (0 == atomic_val_compare_exchange_8(&dmNotifyHdl.state, 1, 2)) {
×
1149
      if (tsem_post(&dmNotifyHdl.sem) != 0) {
×
1150
        metaError("vgId:%d, failed to post semaphore, errno:%d", TD_VID(pMeta->pVnode), ERRNO);
×
1151
      }
1152
    }
1153
  }
1154
#endif
1155
}
5✔
1156

1157
static int32_t (*metaTableOpFn[META_TABLE_MAX][META_TABLE_OP_MAX])(SMeta *pMeta, const SMetaHandleParam *pParam) =
1158
    {
1159
        [META_ENTRY_TABLE] =
1160
            {
1161
                [META_TABLE_OP_INSERT] = metaEntryTableInsert,
1162
                [META_TABLE_OP_UPDATA] = metaEntryTableUpdate,
1163
                [META_TABLE_OP_DELETE] = metaEntryTableDelete,
1164
            },
1165
        [META_SCHEMA_TABLE] =
1166
            {
1167
                [META_TABLE_OP_INSERT] = metaSchemaTableInsert,
1168
                [META_TABLE_OP_UPDATA] = metaSchemaTableUpdate,
1169
                [META_TABLE_OP_DELETE] = metaSchemaTableDelete,
1170
            },
1171
        [META_UID_IDX] =
1172
            {
1173
                [META_TABLE_OP_INSERT] = metaUidIdxInsert,
1174
                [META_TABLE_OP_UPDATA] = metaUidIdxUpdate,
1175
                [META_TABLE_OP_DELETE] = metaUidIdxDelete,
1176
            },
1177
        [META_NAME_IDX] =
1178
            {
1179
                [META_TABLE_OP_INSERT] = metaNameIdxInsert,
1180
                [META_TABLE_OP_UPDATA] = metaNameIdxUpdate,
1181
                [META_TABLE_OP_DELETE] = metaNameIdxDelete,
1182
            },
1183
        [META_SUID_IDX] =
1184
            {
1185
                [META_TABLE_OP_INSERT] = metaSUidIdxInsert,
1186
                [META_TABLE_OP_UPDATA] = NULL,
1187
                [META_TABLE_OP_DELETE] = metaSUidIdxDelete,
1188
            },
1189
        [META_CHILD_IDX] =
1190
            {
1191
                [META_TABLE_OP_INSERT] = metaChildIdxInsert,
1192
                [META_TABLE_OP_UPDATA] = metaChildIdxUpdate,
1193
                [META_TABLE_OP_DELETE] = metaChildIdxDelete,
1194
            },
1195
        [META_TAG_IDX] =
1196
            {
1197
                [META_TABLE_OP_INSERT] = metaTagIdxInsert,
1198
                [META_TABLE_OP_UPDATA] = metaTagIdxUpdate,
1199
                [META_TABLE_OP_DELETE] = metaTagIdxDelete,
1200
            },
1201
        [META_BTIME_IDX] =
1202
            {
1203
                [META_TABLE_OP_INSERT] = metaBtimeIdxInsert,
1204
                [META_TABLE_OP_UPDATA] = metaBtimeIdxUpdate,
1205
                [META_TABLE_OP_DELETE] = metaBtimeIdxDelete,
1206
            },
1207
        [META_TTL_IDX] =
1208
            {
1209
                [META_TABLE_OP_INSERT] = metaTtlIdxInsert,
1210
                [META_TABLE_OP_UPDATA] = metaTtlIdxUpdate,
1211
                [META_TABLE_OP_DELETE] = metaTtlIdxDelete,
1212
            },
1213
};
1214

1215
static int32_t metaHandleSuperTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry) {
19✔
1216
  int32_t code = TSDB_CODE_SUCCESS;
19✔
1217

1218
  SMetaTableOp ops[] = {
19✔
1219
      {META_ENTRY_TABLE, META_TABLE_OP_INSERT},   //
1220
      {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  // TODO: here should be insert
1221
      {META_UID_IDX, META_TABLE_OP_INSERT},       //
1222
      {META_NAME_IDX, META_TABLE_OP_INSERT},      //
1223
      {META_SUID_IDX, META_TABLE_OP_INSERT},      //
1224
  };
1225

1226
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
114✔
1227
    SMetaTableOp          *op = &ops[i];
95✔
1228
    const SMetaHandleParam param = {
95✔
1229
        .pEntry = pEntry,
1230
    };
1231
    code = metaTableOpFn[op->table][op->op](pMeta, &param);
95✔
1232
    if (TSDB_CODE_SUCCESS != code) {
95!
1233
      metaErr(TD_VID(pMeta->pVnode), code);
×
1234
      return code;
×
1235
    }
1236
  }
1237

1238
  return code;
19✔
1239
}
1240
static int32_t metaHandleSuperTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) {
19✔
1241
  int32_t code = TSDB_CODE_SUCCESS;
19✔
1242

1243
  metaWLock(pMeta);
19✔
1244
  code = metaHandleSuperTableCreateImpl(pMeta, pEntry);
19✔
1245
  metaULock(pMeta);
19✔
1246

1247
  if (TSDB_CODE_SUCCESS == code) {
19!
1248
    pMeta->pVnode->config.vndStats.numOfSTables++;
19✔
1249

1250
    metaInfo("vgId:%d, %s success, version:%" PRId64 " type:%d uid:%" PRId64 " name:%s", TD_VID(pMeta->pVnode),
19!
1251
             __func__, pEntry->version, pEntry->type, pEntry->uid, pEntry->name);
1252
  } else {
1253
    metaErr(TD_VID(pMeta->pVnode), code);
×
1254
  }
1255
  return code;
19✔
1256
}
1257

1258
static int32_t metaHandleNormalTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry) {
×
1259
  int32_t code = TSDB_CODE_SUCCESS;
×
1260

1261
  SMetaTableOp ops[] = {
×
1262
      {META_ENTRY_TABLE, META_TABLE_OP_INSERT},   //
1263
      {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  // TODO: need to be insert
1264
      {META_UID_IDX, META_TABLE_OP_INSERT},       //
1265
      {META_NAME_IDX, META_TABLE_OP_INSERT},      //
1266
      {META_BTIME_IDX, META_TABLE_OP_INSERT},     //
1267
      {META_TTL_IDX, META_TABLE_OP_INSERT},       //
1268
  };
1269

1270
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
1271
    SMetaTableOp *op = &ops[i];
×
1272

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

1277
    code = metaTableOpFn[op->table][op->op](pMeta, &param);
×
1278
    if (TSDB_CODE_SUCCESS != code) {
×
1279
      metaErr(TD_VID(pMeta->pVnode), code);
×
1280
      return code;
×
1281
    }
1282
  }
1283

1284
  return code;
×
1285
}
1286
static int32_t metaHandleNormalTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) {
×
1287
  int32_t code = TSDB_CODE_SUCCESS;
×
1288

1289
  // update TDB
1290
  metaWLock(pMeta);
×
1291
  code = metaHandleNormalTableCreateImpl(pMeta, pEntry);
×
1292
  metaULock(pMeta);
×
1293

1294
  // update other stuff
1295
  if (TSDB_CODE_SUCCESS == code) {
×
1296
    pMeta->pVnode->config.vndStats.numOfNTables++;
×
1297
    pMeta->pVnode->config.vndStats.numOfNTimeSeries += pEntry->ntbEntry.schemaRow.nCols - 1;
×
1298

1299
    if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
×
1300
      int32_t rc = tsdbCacheNewTable(pMeta->pVnode->pTsdb, pEntry->uid, -1, &pEntry->ntbEntry.schemaRow);
×
1301
      if (rc < 0) {
×
1302
        metaError("vgId:%d, failed to create table:%s since %s", TD_VID(pMeta->pVnode), pEntry->name, tstrerror(rc));
×
1303
      }
1304
    }
1305
    metaTimeSeriesNotifyCheck(pMeta);
×
1306
  } else {
1307
    metaErr(TD_VID(pMeta->pVnode), code);
×
1308
  }
1309
  return code;
×
1310
}
1311

1312
static int32_t metaHandleChildTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry, const SMetaEntry *pSuperEntry) {
1✔
1313
  int32_t code = TSDB_CODE_SUCCESS;
1✔
1314

1315
  SMetaTableOp ops[] = {
1✔
1316
      {META_ENTRY_TABLE, META_TABLE_OP_INSERT},  //
1317
      {META_UID_IDX, META_TABLE_OP_INSERT},      //
1318
      {META_NAME_IDX, META_TABLE_OP_INSERT},     //
1319
      {META_CHILD_IDX, META_TABLE_OP_INSERT},    //
1320
      {META_TAG_IDX, META_TABLE_OP_INSERT},      //
1321
      {META_BTIME_IDX, META_TABLE_OP_INSERT},    //
1322
      {META_TTL_IDX, META_TABLE_OP_INSERT},      //
1323
  };
1324

1325
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
8✔
1326
    SMetaTableOp *op = &ops[i];
7✔
1327

1328
    SMetaHandleParam param = {
7✔
1329
        .pEntry = pEntry,
1330
        .pSuperEntry = pSuperEntry,
1331
    };
1332

1333
    code = metaTableOpFn[op->table][op->op](pMeta, &param);
7✔
1334
    if (TSDB_CODE_SUCCESS != code) {
7!
1335
      metaErr(TD_VID(pMeta->pVnode), code);
×
1336
      return code;
×
1337
    }
1338
  }
1339

1340
  if (TSDB_CODE_SUCCESS == code) {
1!
1341
    metaUpdateStbStats(pMeta, pSuperEntry->uid, 1, 0, -1);
1✔
1342
    int32_t ret = metaUidCacheClear(pMeta, pSuperEntry->uid);
1✔
1343
    if (ret < 0) {
1!
1344
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1345
    }
1346

1347
    ret = metaTbGroupCacheClear(pMeta, pSuperEntry->uid);
1✔
1348
    if (ret < 0) {
1!
1349
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1350
    }
1351
  }
1352
  return code;
1✔
1353
}
1354

1355
static int32_t metaHandleChildTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) {
1✔
1356
  int32_t     code = TSDB_CODE_SUCCESS;
1✔
1357
  SMetaEntry *pSuperEntry = NULL;
1✔
1358

1359
  // get the super table entry
1360
  code = metaFetchEntryByUid(pMeta, pEntry->ctbEntry.suid, &pSuperEntry);
1✔
1361
  if (code) {
1!
1362
    metaErr(TD_VID(pMeta->pVnode), code);
×
1363
    return code;
×
1364
  }
1365

1366
  // update TDB
1367
  metaWLock(pMeta);
1✔
1368
  code = metaHandleChildTableCreateImpl(pMeta, pEntry, pSuperEntry);
1✔
1369
  metaULock(pMeta);
1✔
1370

1371
  // update other stuff
1372
  if (TSDB_CODE_SUCCESS == code) {
1!
1373
    pMeta->pVnode->config.vndStats.numOfCTables++;
1✔
1374

1375
    if (!metaTbInFilterCache(pMeta, pSuperEntry->name, 1)) {
1!
1376
      int32_t nCols = 0;
1✔
1377
      int32_t ret = metaGetStbStats(pMeta->pVnode, pSuperEntry->uid, 0, &nCols);
1✔
1378
      if (ret < 0) {
1!
1379
        metaErr(TD_VID(pMeta->pVnode), ret);
×
1380
      }
1381
      pMeta->pVnode->config.vndStats.numOfTimeSeries += (nCols > 0 ? nCols - 1 : 0);
1!
1382
    }
1383

1384
    if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
1!
1385
      int32_t rc = tsdbCacheNewTable(pMeta->pVnode->pTsdb, pEntry->uid, pEntry->ctbEntry.suid, NULL);
×
1386
      if (rc < 0) {
×
1387
        metaError("vgId:%d, %s failed at %s:%d since %s", TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__,
×
1388
                  tstrerror(rc));
1389
      }
1390
    }
1391

1392
  } else {
1393
    metaErr(TD_VID(pMeta->pVnode), code);
×
1394
  }
1395
  metaTimeSeriesNotifyCheck(pMeta);
1✔
1396
  metaFetchEntryFree(&pSuperEntry);
1✔
1397
  return code;
1✔
1398
}
1399

1400
static int32_t metaHandleVirtualNormalTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry) {
×
1401
  int32_t code = TSDB_CODE_SUCCESS;
×
1402

1403
  SMetaTableOp ops[] = {
×
1404
      {META_ENTRY_TABLE, META_TABLE_OP_INSERT},   //
1405
      {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  // TODO: need to be insert
1406
      {META_UID_IDX, META_TABLE_OP_INSERT},       //
1407
      {META_NAME_IDX, META_TABLE_OP_INSERT},      //
1408
      {META_BTIME_IDX, META_TABLE_OP_INSERT},     //
1409
  };
1410

1411
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
1412
    SMetaTableOp *op = &ops[i];
×
1413

1414
    SMetaHandleParam param = {
×
1415
        .pEntry = pEntry,
1416
    };
1417

1418
    code = metaTableOpFn[op->table][op->op](pMeta, &param);
×
1419
    if (TSDB_CODE_SUCCESS != code) {
×
1420
      metaErr(TD_VID(pMeta->pVnode), code);
×
1421
      return code;
×
1422
    }
1423
  }
1424

1425
  return code;
×
1426
}
1427

1428
static int32_t metaHandleVirtualNormalTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) {
×
1429
  int32_t code = TSDB_CODE_SUCCESS;
×
1430

1431
  // update TDB
1432
  metaWLock(pMeta);
×
1433
  code = metaHandleVirtualNormalTableCreateImpl(pMeta, pEntry);
×
1434
  metaULock(pMeta);
×
1435

1436
  // update other stuff
1437
  if (TSDB_CODE_SUCCESS == code) {
×
1438
    pMeta->pVnode->config.vndStats.numOfVTables++;
×
1439
  } else {
1440
    metaErr(TD_VID(pMeta->pVnode), code);
×
1441
  }
1442
  return code;
×
1443
}
1444

1445
static int32_t metaHandleVirtualChildTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry, const SMetaEntry *pSuperEntry) {
×
1446
  int32_t code = TSDB_CODE_SUCCESS;
×
1447

1448
  SMetaTableOp ops[] = {
×
1449
      {META_ENTRY_TABLE, META_TABLE_OP_INSERT},  //
1450
      {META_UID_IDX, META_TABLE_OP_INSERT},      //
1451
      {META_NAME_IDX, META_TABLE_OP_INSERT},     //
1452
      {META_CHILD_IDX, META_TABLE_OP_INSERT},    //
1453
      {META_TAG_IDX, META_TABLE_OP_INSERT},      //
1454
      {META_BTIME_IDX, META_TABLE_OP_INSERT},    //
1455
  };
1456

1457
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
1458
    SMetaTableOp *op = &ops[i];
×
1459

1460
    SMetaHandleParam param = {
×
1461
        .pEntry = pEntry,
1462
        .pSuperEntry = pSuperEntry,
1463
    };
1464

1465
    code = metaTableOpFn[op->table][op->op](pMeta, &param);
×
1466
    if (TSDB_CODE_SUCCESS != code) {
×
1467
      metaErr(TD_VID(pMeta->pVnode), code);
×
1468
      return code;
×
1469
    }
1470
  }
1471

1472
  if (TSDB_CODE_SUCCESS == code) {
×
1473
    metaUpdateStbStats(pMeta, pSuperEntry->uid, 1, 0, -1);
×
1474
    int32_t ret = metaUidCacheClear(pMeta, pSuperEntry->uid);
×
1475
    if (ret < 0) {
×
1476
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1477
    }
1478

1479
    ret = metaTbGroupCacheClear(pMeta, pSuperEntry->uid);
×
1480
    if (ret < 0) {
×
1481
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1482
    }
1483
  }
1484

1485
  return code;
×
1486
}
1487

1488
static int32_t metaHandleVirtualChildTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) {
×
1489
  int32_t     code = TSDB_CODE_SUCCESS;
×
1490
  SMetaEntry *pSuperEntry = NULL;
×
1491

1492
  // get the super table entry
1493
  code = metaFetchEntryByUid(pMeta, pEntry->ctbEntry.suid, &pSuperEntry);
×
1494
  if (code) {
×
1495
    metaErr(TD_VID(pMeta->pVnode), code);
×
1496
    return code;
×
1497
  }
1498

1499
  // update TDB
1500
  metaWLock(pMeta);
×
1501
  code = metaHandleVirtualChildTableCreateImpl(pMeta, pEntry, pSuperEntry);
×
1502
  metaULock(pMeta);
×
1503

1504
  // update other stuff
1505
  if (TSDB_CODE_SUCCESS == code) {
×
1506
    pMeta->pVnode->config.vndStats.numOfVCTables++;
×
1507
  } else {
1508
    metaErr(TD_VID(pMeta->pVnode), code);
×
1509
  }
1510

1511
  metaFetchEntryFree(&pSuperEntry);
×
1512
  return code;
×
1513
}
1514

1515
static int32_t metaHandleNormalTableDropImpl(SMeta *pMeta, SMetaHandleParam *pParam) {
×
1516
  int32_t code = TSDB_CODE_SUCCESS;
×
1517

1518
  SMetaTableOp ops[] = {
×
1519
      {META_ENTRY_TABLE, META_TABLE_OP_DELETE},  //
1520
      {META_UID_IDX, META_TABLE_OP_DELETE},      //
1521
      {META_NAME_IDX, META_TABLE_OP_DELETE},     //
1522
      {META_BTIME_IDX, META_TABLE_OP_DELETE},    //
1523
      {META_TTL_IDX, META_TABLE_OP_DELETE},      //
1524

1525
      // {META_SCHEMA_TABLE, META_TABLE_OP_DELETE},  //
1526
  };
1527

1528
  for (int32_t i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
1529
    SMetaTableOp *op = &ops[i];
×
1530
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
×
1531
    if (code) {
×
1532
      const SMetaEntry *pEntry = pParam->pEntry;
×
1533
      metaErr(TD_VID(pMeta->pVnode), code);
×
1534
    }
1535
  }
1536

1537
  return code;
×
1538
}
1539

1540
static int32_t metaHandleNormalTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) {
×
1541
  int32_t     code = TSDB_CODE_SUCCESS;
×
1542
  SMetaEntry *pOldEntry = NULL;
×
1543

1544
  // fetch the entry
1545
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
×
1546
  if (code) {
×
1547
    metaErr(TD_VID(pMeta->pVnode), code);
×
1548
    return code;
×
1549
  }
1550

1551
  SMetaHandleParam param = {
×
1552
      .pEntry = pEntry,
1553
      .pOldEntry = pOldEntry,
1554
  };
1555

1556
  // do the drop
1557
  metaWLock(pMeta);
×
1558
  code = metaHandleNormalTableDropImpl(pMeta, &param);
×
1559
  metaULock(pMeta);
×
1560
  if (code) {
×
1561
    metaErr(TD_VID(pMeta->pVnode), code);
×
1562
    metaFetchEntryFree(&pOldEntry);
×
1563
    return code;
×
1564
  }
1565

1566
  // update other stuff
1567
  pMeta->pVnode->config.vndStats.numOfNTables--;
×
1568
  pMeta->pVnode->config.vndStats.numOfNTimeSeries -= (pOldEntry->ntbEntry.schemaRow.nCols - 1);
×
1569

1570
#if 0
1571
  if (tbUids) {
1572
    if (taosArrayPush(tbUids, &uid) == NULL) {
1573
      rc = terrno;
1574
      goto _exit;
1575
    }
1576
  }
1577
#endif
1578

1579
  if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
×
1580
    int32_t ret = tsdbCacheDropTable(pMeta->pVnode->pTsdb, pOldEntry->uid, 0, NULL);
×
1581
    if (ret < 0) {
×
1582
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1583
    }
1584
  }
1585

1586
  metaFetchEntryFree(&pOldEntry);
×
1587
  return code;
×
1588
}
1589

1590
static int32_t metaHandleChildTableDropImpl(SMeta *pMeta, const SMetaHandleParam *pParam, bool superDropped) {
×
1591
  int32_t code = TSDB_CODE_SUCCESS;
×
1592

1593
  const SMetaEntry *pEntry = pParam->pEntry;
×
1594
  const SMetaEntry *pChild = pParam->pOldEntry;
×
1595
  const SMetaEntry *pSuper = pParam->pSuperEntry;
×
1596

1597
  SMetaTableOp ops[] = {
×
1598
      {META_ENTRY_TABLE, META_TABLE_OP_DELETE},  //
1599
      {META_UID_IDX, META_TABLE_OP_DELETE},      //
1600
      {META_NAME_IDX, META_TABLE_OP_DELETE},     //
1601
      {META_CHILD_IDX, META_TABLE_OP_DELETE},    //
1602
      {META_TAG_IDX, META_TABLE_OP_DELETE},      //
1603
      {META_BTIME_IDX, META_TABLE_OP_DELETE},    //
1604
      {META_TTL_IDX, META_TABLE_OP_DELETE},      //
1605
  };
1606

1607
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
1608
    SMetaTableOp *op = &ops[i];
×
1609

1610
    if (op->table == META_ENTRY_TABLE && superDropped) {
×
1611
      continue;
×
1612
    }
1613

1614
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
×
1615
    if (code) {
×
1616
      metaErr(TD_VID(pMeta->pVnode), code);
×
1617
      return code;
×
1618
    }
1619
  }
1620

1621
  --pMeta->pVnode->config.vndStats.numOfCTables;
×
1622
  metaUpdateStbStats(pMeta, pParam->pSuperEntry->uid, -1, 0, -1);
×
1623
  int32_t ret = metaUidCacheClear(pMeta, pSuper->uid);
×
1624
  if (ret < 0) {
×
1625
    metaErr(TD_VID(pMeta->pVnode), ret);
×
1626
  }
1627

1628
  ret = metaTbGroupCacheClear(pMeta, pSuper->uid);
×
1629
  if (ret < 0) {
×
1630
    metaErr(TD_VID(pMeta->pVnode), ret);
×
1631
  }
1632
  return code;
×
1633
}
1634

1635
static int32_t metaHandleChildTableDrop(SMeta *pMeta, const SMetaEntry *pEntry, bool superDropped) {
×
1636
  int32_t     code = TSDB_CODE_SUCCESS;
×
1637
  SMetaEntry *pChild = NULL;
×
1638
  SMetaEntry *pSuper = NULL;
×
1639

1640
  // fetch old entry
1641
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pChild);
×
1642
  if (code) {
×
1643
    metaErr(TD_VID(pMeta->pVnode), code);
×
1644
    return code;
×
1645
  }
1646

1647
  // fetch super entry
1648
  code = metaFetchEntryByUid(pMeta, pChild->ctbEntry.suid, &pSuper);
×
1649
  if (code) {
×
1650
    metaErr(TD_VID(pMeta->pVnode), code);
×
1651
    metaFetchEntryFree(&pChild);
×
1652
    return code;
×
1653
  }
1654

1655
  SMetaHandleParam param = {
×
1656
      .pEntry = pEntry,
1657
      .pOldEntry = pChild,
1658
      .pSuperEntry = pSuper,
1659
  };
1660

1661
  // do the drop
1662
  metaWLock(pMeta);
×
1663
  code = metaHandleChildTableDropImpl(pMeta, &param, superDropped);
×
1664
  metaULock(pMeta);
×
1665
  if (code) {
×
1666
    metaErr(TD_VID(pMeta->pVnode), code);
×
1667
    metaFetchEntryFree(&pChild);
×
1668
    metaFetchEntryFree(&pSuper);
×
1669
    return code;
×
1670
  }
1671

1672
  // do other stuff
1673
  if (!metaTbInFilterCache(pMeta, pSuper->name, 1)) {
×
1674
    int32_t      nCols = 0;
×
1675
    SVnodeStats *pStats = &pMeta->pVnode->config.vndStats;
×
1676
    if (metaGetStbStats(pMeta->pVnode, pSuper->uid, NULL, &nCols) == 0) {
×
1677
      pStats->numOfTimeSeries -= nCols - 1;
×
1678
    }
1679
  }
1680

1681
  if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
×
1682
    int32_t ret = tsdbCacheDropTable(pMeta->pVnode->pTsdb, pChild->uid, pSuper->uid, NULL);
×
1683
    if (ret < 0) {
×
1684
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1685
    }
1686
  }
1687

1688
#if 0
1689
  if (tbUids) {
1690
    if (taosArrayPush(tbUids, &uid) == NULL) {
1691
      rc = terrno;
1692
      goto _exit;
1693
    }
1694
  }
1695

1696
  if ((type == TSDB_CHILD_TABLE) && tbUid) {
1697
    *tbUid = uid;
1698
  }
1699
#endif
1700
  metaFetchEntryFree(&pChild);
×
1701
  metaFetchEntryFree(&pSuper);
×
1702
  return code;
×
1703
}
1704

1705
static int32_t metaHandleVirtualNormalTableDropImpl(SMeta *pMeta, SMetaHandleParam *pParam) {
×
1706
  int32_t code = TSDB_CODE_SUCCESS;
×
1707

1708
  SMetaTableOp ops[] = {
×
1709
      {META_ENTRY_TABLE, META_TABLE_OP_DELETE},  //
1710
      {META_UID_IDX, META_TABLE_OP_DELETE},      //
1711
      {META_NAME_IDX, META_TABLE_OP_DELETE},     //
1712
      {META_BTIME_IDX, META_TABLE_OP_DELETE},    //
1713

1714
      // {META_SCHEMA_TABLE, META_TABLE_OP_DELETE},  //
1715
  };
1716

1717
  for (int32_t i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
1718
    SMetaTableOp *op = &ops[i];
×
1719
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
×
1720
    if (code) {
×
1721
      const SMetaEntry *pEntry = pParam->pEntry;
×
1722
      metaErr(TD_VID(pMeta->pVnode), code);
×
1723
    }
1724
  }
1725

1726
  return code;
×
1727
}
1728

1729
static int32_t metaHandleVirtualNormalTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) {
×
1730
  int32_t     code = TSDB_CODE_SUCCESS;
×
1731
  SMetaEntry *pOldEntry = NULL;
×
1732

1733
  // fetch the entry
1734
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
×
1735
  if (code) {
×
1736
    metaErr(TD_VID(pMeta->pVnode), code);
×
1737
    return code;
×
1738
  }
1739

1740
  SMetaHandleParam param = {
×
1741
      .pEntry = pEntry,
1742
      .pOldEntry = pOldEntry,
1743
  };
1744

1745
  // do the drop
1746
  metaWLock(pMeta);
×
1747
  code = metaHandleVirtualNormalTableDropImpl(pMeta, &param);
×
1748
  metaULock(pMeta);
×
1749
  if (code) {
×
1750
    metaErr(TD_VID(pMeta->pVnode), code);
×
1751
    metaFetchEntryFree(&pOldEntry);
×
1752
    return code;
×
1753
  }
1754

1755
  // update other stuff
1756
  pMeta->pVnode->config.vndStats.numOfVTables--;
×
1757

1758
#if 0
1759
  if (tbUids) {
1760
    if (taosArrayPush(tbUids, &uid) == NULL) {
1761
      rc = terrno;
1762
      goto _exit;
1763
    }
1764
  }
1765
#endif
1766

1767
  if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
×
1768
    int32_t ret = tsdbCacheDropTable(pMeta->pVnode->pTsdb, pOldEntry->uid, 0, NULL);
×
1769
    if (ret < 0) {
×
1770
      metaErr(TD_VID(pMeta->pVnode), ret);
×
1771
    }
1772
  }
1773

1774
  metaFetchEntryFree(&pOldEntry);
×
1775
  return code;
×
1776
}
1777

1778
static int32_t metaHandleVirtualChildTableDropImpl(SMeta *pMeta, const SMetaHandleParam *pParam, bool superDropped) {
×
1779
  int32_t code = TSDB_CODE_SUCCESS;
×
1780

1781
  const SMetaEntry *pEntry = pParam->pEntry;
×
1782
  const SMetaEntry *pChild = pParam->pOldEntry;
×
1783
  const SMetaEntry *pSuper = pParam->pSuperEntry;
×
1784

1785
  SMetaTableOp ops[] = {
×
1786
      {META_ENTRY_TABLE, META_TABLE_OP_DELETE},  //
1787
      {META_UID_IDX, META_TABLE_OP_DELETE},      //
1788
      {META_NAME_IDX, META_TABLE_OP_DELETE},     //
1789
      {META_CHILD_IDX, META_TABLE_OP_DELETE},    //
1790
      {META_TAG_IDX, META_TABLE_OP_DELETE},      //
1791
      {META_BTIME_IDX, META_TABLE_OP_DELETE},    //
1792
  };
1793

1794
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
1795
    SMetaTableOp *op = &ops[i];
×
1796

1797
    if (op->table == META_ENTRY_TABLE && superDropped) {
×
1798
      continue;
×
1799
    }
1800

1801
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
×
1802
    if (code) {
×
1803
      metaErr(TD_VID(pMeta->pVnode), code);
×
1804
      return code;
×
1805
    }
1806
  }
1807

1808
  --pMeta->pVnode->config.vndStats.numOfVCTables;
×
1809
  metaUpdateStbStats(pMeta, pParam->pSuperEntry->uid, -1, 0, -1);
×
1810
  int32_t ret = metaUidCacheClear(pMeta, pSuper->uid);
×
1811
  if (ret < 0) {
×
1812
    metaErr(TD_VID(pMeta->pVnode), ret);
×
1813
  }
1814

1815
  ret = metaTbGroupCacheClear(pMeta, pSuper->uid);
×
1816
  if (ret < 0) {
×
1817
    metaErr(TD_VID(pMeta->pVnode), ret);
×
1818
  }
1819
  return code;
×
1820
}
1821

1822
static int32_t metaHandleVirtualChildTableDrop(SMeta *pMeta, const SMetaEntry *pEntry, bool superDropped) {
×
1823
  int32_t     code = TSDB_CODE_SUCCESS;
×
1824
  SMetaEntry *pChild = NULL;
×
1825
  SMetaEntry *pSuper = NULL;
×
1826

1827
  // fetch old entry
1828
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pChild);
×
1829
  if (code) {
×
1830
    metaErr(TD_VID(pMeta->pVnode), code);
×
1831
    return code;
×
1832
  }
1833

1834
  // fetch super entry
1835
  code = metaFetchEntryByUid(pMeta, pChild->ctbEntry.suid, &pSuper);
×
1836
  if (code) {
×
1837
    metaErr(TD_VID(pMeta->pVnode), code);
×
1838
    metaFetchEntryFree(&pChild);
×
1839
    return code;
×
1840
  }
1841

1842
  SMetaHandleParam param = {
×
1843
      .pEntry = pEntry,
1844
      .pOldEntry = pChild,
1845
      .pSuperEntry = pSuper,
1846
  };
1847

1848
  // do the drop
1849
  metaWLock(pMeta);
×
1850
  code = metaHandleVirtualChildTableDropImpl(pMeta, &param, superDropped);
×
1851
  metaULock(pMeta);
×
1852
  if (code) {
×
1853
    metaErr(TD_VID(pMeta->pVnode), code);
×
1854
    metaFetchEntryFree(&pChild);
×
1855
    metaFetchEntryFree(&pSuper);
×
1856
    return code;
×
1857
  }
1858

1859
  metaFetchEntryFree(&pChild);
×
1860
  metaFetchEntryFree(&pSuper);
×
1861
  return code;
×
1862
}
1863

1864
static int32_t metaGetChildUidsOfSuperTable(SMeta *pMeta, tb_uid_t suid, SArray **childList) {
4✔
1865
  int32_t code = TSDB_CODE_SUCCESS;
4✔
1866
  void   *key = NULL;
4✔
1867
  int32_t keySize = 0;
4✔
1868
  int32_t c;
1869

1870
  *childList = taosArrayInit(64, sizeof(tb_uid_t));
4✔
1871
  if (*childList == NULL) {
4!
1872
    return terrno;
×
1873
  }
1874

1875
  TBC *cursor = NULL;
4✔
1876
  code = tdbTbcOpen(pMeta->pCtbIdx, &cursor, NULL);
4✔
1877
  if (code) {
4!
1878
    taosArrayDestroy(*childList);
×
1879
    *childList = NULL;
×
1880
    return code;
×
1881
  }
1882

1883
  int32_t rc = tdbTbcMoveTo(cursor,
4✔
1884
                            &(SCtbIdxKey){
4✔
1885
                                .suid = suid,
1886
                                .uid = INT64_MIN,
1887
                            },
1888
                            sizeof(SCtbIdxKey), &c);
1889
  if (rc < 0) {
4!
1890
    tdbTbcClose(cursor);
×
1891
    return 0;
×
1892
  }
1893

1894
  for (;;) {
1895
    if (tdbTbcNext(cursor, &key, &keySize, NULL, NULL) < 0) {
4!
1896
      break;
4✔
1897
    }
1898

1899
    if (((SCtbIdxKey *)key)->suid < suid) {
×
1900
      continue;
×
1901
    } else if (((SCtbIdxKey *)key)->suid > suid) {
×
1902
      break;
×
1903
    }
1904

1905
    if (taosArrayPush(*childList, &(((SCtbIdxKey *)key)->uid)) == NULL) {
×
1906
      tdbFreeClear(key);
×
1907
      tdbTbcClose(cursor);
×
1908
      taosArrayDestroy(*childList);
×
1909
      *childList = NULL;
×
1910
      return terrno;
×
1911
    }
1912
  }
1913

1914
  tdbTbcClose(cursor);
4✔
1915
  tdbFreeClear(key);
4✔
1916
  return code;
4✔
1917
}
1918

1919
static int32_t metaHandleSuperTableDropImpl(SMeta *pMeta, const SMetaHandleParam *pParam) {
4✔
1920
  int32_t           code = TSDB_CODE_SUCCESS;
4✔
1921
  const SMetaEntry *pEntry = pParam->pEntry;
4✔
1922

1923
  SMetaTableOp ops[] = {
4✔
1924
      {META_ENTRY_TABLE, META_TABLE_OP_DELETE},  //
1925
      {META_UID_IDX, META_TABLE_OP_DELETE},      //
1926
      {META_NAME_IDX, META_TABLE_OP_DELETE},     //
1927
      {META_SUID_IDX, META_TABLE_OP_DELETE},     //
1928

1929
      // {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  // TODO: here should be insert
1930
  };
1931

1932
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
20✔
1933
    SMetaTableOp *op = &ops[i];
16✔
1934

1935
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
16✔
1936
    if (TSDB_CODE_SUCCESS != code) {
16!
1937
      metaErr(TD_VID(pMeta->pVnode), code);
×
1938
      return code;
×
1939
    }
1940
  }
1941

1942
  int32_t ret = metaStatsCacheDrop(pMeta, pEntry->uid);
4✔
1943
  if (ret < 0) {
4!
1944
    metaErr(TD_VID(pMeta->pVnode), ret);
4!
1945
  }
1946
  return code;
4✔
1947
}
1948

1949
static int32_t metaHandleNormalTableUpdateImpl(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
1950
  int32_t code = TSDB_CODE_SUCCESS;
×
1951

1952
  const SMetaEntry *pEntry = pParam->pEntry;
×
1953

1954
  SMetaTableOp ops[] = {
×
1955
      {META_ENTRY_TABLE, META_TABLE_OP_UPDATA},   //
1956
      {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  //
1957
      {META_UID_IDX, META_TABLE_OP_UPDATA},       //
1958
      {META_TTL_IDX, META_TABLE_OP_UPDATA},       //
1959
  };
1960
  for (int32_t i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
1961
    SMetaTableOp *op = &ops[i];
×
1962
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
×
1963
    if (code) {
×
1964
      metaErr(TD_VID(pMeta->pVnode), code);
×
1965
      return code;
×
1966
    }
1967
  }
1968
#if 0
1969
  if (metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs) < 0) {
1970
    metaError("vgId:%d, failed to update change time:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, entry.uid);
1971
  }
1972
#endif
1973
  return code;
×
1974
}
1975

1976
static int32_t metaHandleVirtualNormalTableUpdateImpl(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
1977
  int32_t code = TSDB_CODE_SUCCESS;
×
1978

1979
  const SMetaEntry *pEntry = pParam->pEntry;
×
1980

1981
  SMetaTableOp ops[] = {
×
1982
      {META_ENTRY_TABLE, META_TABLE_OP_UPDATA},   //
1983
      {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  //
1984
      {META_UID_IDX, META_TABLE_OP_UPDATA},       //
1985
  };
1986
  for (int32_t i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
1987
    SMetaTableOp *op = &ops[i];
×
1988
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
×
1989
    if (code) {
×
1990
      metaErr(TD_VID(pMeta->pVnode), code);
×
1991
      return code;
×
1992
    }
1993
  }
1994
#if 0
1995
  if (metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs) < 0) {
1996
    metaError("vgId:%d, failed to update change time:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, entry.uid);
1997
  }
1998
#endif
1999
  return code;
×
2000
}
2001

2002
static int32_t metaHandleVirtualChildTableUpdateImpl(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
2003
  int32_t code = TSDB_CODE_SUCCESS;
×
2004

2005
  const SMetaEntry *pEntry = pParam->pEntry;
×
2006
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
×
2007
  const SMetaEntry *pSuperEntry = pParam->pSuperEntry;
×
2008

2009
  SMetaTableOp ops[] = {
×
2010
      {META_ENTRY_TABLE, META_TABLE_OP_UPDATA},  //
2011
      {META_UID_IDX, META_TABLE_OP_UPDATA},      //
2012
      {META_TAG_IDX, META_TABLE_OP_UPDATA},      //
2013
      {META_CHILD_IDX, META_TABLE_OP_UPDATA},    //
2014
  };
2015

2016
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
2017
    SMetaTableOp *op = &ops[i];
×
2018
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
×
2019
    if (code) {
×
2020
      metaErr(TD_VID(pMeta->pVnode), code);
×
2021
      return code;
×
2022
    }
2023
  }
2024

2025
  if (metaUidCacheClear(pMeta, pSuperEntry->uid) < 0) {
×
2026
    metaErr(TD_VID(pMeta->pVnode), code);
×
2027
  }
2028

2029
  if (metaTbGroupCacheClear(pMeta, pSuperEntry->uid) < 0) {
×
2030
    metaErr(TD_VID(pMeta->pVnode), code);
×
2031
  }
2032
  return code;
×
2033
}
2034

2035
static int32_t metaHandleChildTableUpdateImpl(SMeta *pMeta, const SMetaHandleParam *pParam) {
×
2036
  int32_t code = TSDB_CODE_SUCCESS;
×
2037

2038
  const SMetaEntry *pEntry = pParam->pEntry;
×
2039
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
×
2040
  const SMetaEntry *pSuperEntry = pParam->pSuperEntry;
×
2041

2042
  SMetaTableOp ops[] = {
×
2043
      {META_ENTRY_TABLE, META_TABLE_OP_UPDATA},  //
2044
      {META_UID_IDX, META_TABLE_OP_UPDATA},      //
2045
      {META_TAG_IDX, META_TABLE_OP_UPDATA},      //
2046
      {META_CHILD_IDX, META_TABLE_OP_UPDATA},    //
2047
      {META_TTL_IDX, META_TABLE_OP_UPDATA},      //
2048
  };
2049

2050
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
×
2051
    SMetaTableOp *op = &ops[i];
×
2052
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
×
2053
    if (code) {
×
2054
      metaErr(TD_VID(pMeta->pVnode), code);
×
2055
      return code;
×
2056
    }
2057
  }
2058

2059
  if (metaUidCacheClear(pMeta, pSuperEntry->uid) < 0) {
×
2060
    metaErr(TD_VID(pMeta->pVnode), code);
×
2061
  }
2062

2063
  if (metaTbGroupCacheClear(pMeta, pSuperEntry->uid) < 0) {
×
2064
    metaErr(TD_VID(pMeta->pVnode), code);
×
2065
  }
2066
  return code;
×
2067
#if 0
2068
  if (metaUpdateChangeTime(pMeta, ctbEntry.uid, pReq->ctimeMs) < 0) {
2069
    metaError("meta/table: failed to update change time:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid);
2070
  }
2071
#endif
2072
}
2073

2074
static int32_t metaHandleSuperTableUpdateImpl(SMeta *pMeta, SMetaHandleParam *pParam) {
16✔
2075
  int32_t code = TSDB_CODE_SUCCESS;
16✔
2076

2077
  const SMetaEntry *pEntry = pParam->pEntry;
16✔
2078
  const SMetaEntry *pOldEntry = pParam->pOldEntry;
16✔
2079

2080
  SMetaTableOp ops[] = {
16✔
2081
      {META_ENTRY_TABLE, META_TABLE_OP_UPDATA},   //
2082
      {META_UID_IDX, META_TABLE_OP_UPDATA},       //
2083
      {META_SCHEMA_TABLE, META_TABLE_OP_UPDATA},  //
2084
  };
2085

2086
  for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
64✔
2087
    SMetaTableOp *op = &ops[i];
48✔
2088
    code = metaTableOpFn[op->table][op->op](pMeta, pParam);
48✔
2089
    if (code) {
48!
2090
      metaErr(TD_VID(pMeta->pVnode), code);
×
2091
      return code;
×
2092
    }
2093
  }
2094

2095
  if (TSDB_CODE_SUCCESS == code) {
16!
2096
    metaUpdateStbStats(pMeta, pEntry->uid, 0, pEntry->stbEntry.schemaRow.nCols - pOldEntry->stbEntry.schemaRow.nCols,
16✔
2097
                       pEntry->stbEntry.keep);
16✔
2098
  }
2099

2100
  return code;
16✔
2101
}
2102

2103
static int32_t metaHandleSuperTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
16✔
2104
  int32_t code = TSDB_CODE_SUCCESS;
16✔
2105

2106
  SMetaEntry *pOldEntry = NULL;
16✔
2107

2108
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
16✔
2109
  if (code) {
16!
2110
    metaErr(TD_VID(pMeta->pVnode), code);
×
2111
    return code;
×
2112
  }
2113

2114
  SMetaHandleParam param = {
16✔
2115
      .pEntry = pEntry,
2116
      .pOldEntry = pOldEntry,
2117
  };
2118
  metaWLock(pMeta);
16✔
2119
  code = metaHandleSuperTableUpdateImpl(pMeta, &param);
16✔
2120
  metaULock(pMeta);
16✔
2121
  if (code) {
16!
2122
    metaErr(TD_VID(pMeta->pVnode), code);
×
2123
    metaFetchEntryFree(&pOldEntry);
×
2124
    return code;
×
2125
  }
2126

2127
  int     nCols = pEntry->stbEntry.schemaRow.nCols;
16✔
2128
  int     onCols = pOldEntry->stbEntry.schemaRow.nCols;
16✔
2129
  int32_t deltaCol = nCols - onCols;
16✔
2130
  bool    updStat = deltaCol != 0 && !metaTbInFilterCache(pMeta, pEntry->name, 1);
16!
2131

2132
  if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
16!
2133
    STsdb  *pTsdb = pMeta->pVnode->pTsdb;
×
2134
    SArray *uids = NULL; /*taosArrayInit(8, sizeof(int64_t));
×
2135
     if (uids == NULL) {
2136
       metaErr(TD_VID(pMeta->pVnode), code);
2137
       metaFetchEntryFree(&pOldEntry);
2138
       return terrno;
2139
       }*/
2140
    if (deltaCol == 1) {
×
2141
      int16_t cid = pEntry->stbEntry.schemaRow.pSchema[nCols - 1].colId;
×
2142
      int8_t  col_type = pEntry->stbEntry.schemaRow.pSchema[nCols - 1].type;
×
2143

2144
      code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &uids);
×
2145
      if (code) {
×
2146
        metaErr(TD_VID(pMeta->pVnode), code);
×
2147
        metaFetchEntryFree(&pOldEntry);
×
2148
        return code;
×
2149
      }
2150
      TAOS_CHECK_RETURN(tsdbCacheNewSTableColumn(pTsdb, uids, cid, col_type));
×
2151
    } else if (deltaCol == -1) {
×
2152
      int16_t cid = -1;
×
2153
      bool    hasPrimaryKey = false;
×
2154
      if (onCols >= 2) {
×
2155
        hasPrimaryKey = (pOldEntry->stbEntry.schemaRow.pSchema[1].flags & COL_IS_KEY) ? true : false;
×
2156
      }
2157
      for (int i = 0, j = 0; i < nCols && j < onCols; ++i, ++j) {
×
2158
        if (pEntry->stbEntry.schemaRow.pSchema[i].colId != pOldEntry->stbEntry.schemaRow.pSchema[j].colId) {
×
2159
          cid = pOldEntry->stbEntry.schemaRow.pSchema[j].colId;
×
2160
          break;
×
2161
        }
2162
      }
2163

2164
      if (cid != -1) {
×
2165
        code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &uids);
×
2166
        if (code) {
×
2167
          metaErr(TD_VID(pMeta->pVnode), code);
×
2168
          metaFetchEntryFree(&pOldEntry);
×
2169
          return code;
×
2170
        }
2171
        TAOS_CHECK_RETURN(tsdbCacheDropSTableColumn(pTsdb, uids, cid, hasPrimaryKey));
×
2172
      }
2173
    }
2174
    if (uids) taosArrayDestroy(uids);
×
2175

2176
    tsdbCacheInvalidateSchema(pTsdb, pEntry->uid, -1, pEntry->stbEntry.schemaRow.version);
×
2177
  }
2178
  if (updStat) {
16✔
2179
    int64_t ctbNum = 0;
6✔
2180
    int32_t ret = metaGetStbStats(pMeta->pVnode, pEntry->uid, &ctbNum, NULL);
6✔
2181
    if (ret < 0) {
6!
2182
      metaError("vgId:%d, failed to get stb stats:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pEntry->name,
×
2183
                pEntry->uid, tstrerror(ret));
2184
    }
2185
    pMeta->pVnode->config.vndStats.numOfTimeSeries += (ctbNum * deltaCol);
6✔
2186
    if (deltaCol > 0) metaTimeSeriesNotifyCheck(pMeta);
6✔
2187
  }
2188
  metaFetchEntryFree(&pOldEntry);
16✔
2189
  return code;
16✔
2190
}
2191

2192
static int32_t metaHandleChildTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
×
2193
  int32_t code = TSDB_CODE_SUCCESS;
×
2194

2195
  SMetaEntry *pOldEntry = NULL;
×
2196
  SMetaEntry *pSuperEntry = NULL;
×
2197

2198
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
×
2199
  if (code) {
×
2200
    metaErr(TD_VID(pMeta->pVnode), code);
×
2201
    return code;
×
2202
  }
2203

2204
  code = metaFetchEntryByUid(pMeta, pEntry->ctbEntry.suid, &pSuperEntry);
×
2205
  if (code) {
×
2206
    metaErr(TD_VID(pMeta->pVnode), code);
×
2207
    metaFetchEntryFree(&pOldEntry);
×
2208
    return code;
×
2209
  }
2210

2211
  SMetaHandleParam param = {
×
2212
      .pEntry = pEntry,
2213
      .pOldEntry = pOldEntry,
2214
      .pSuperEntry = pSuperEntry,
2215
  };
2216

2217
  metaWLock(pMeta);
×
2218
  code = metaHandleChildTableUpdateImpl(pMeta, &param);
×
2219
  metaULock(pMeta);
×
2220
  if (code) {
×
2221
    metaErr(TD_VID(pMeta->pVnode), code);
×
2222
    metaFetchEntryFree(&pOldEntry);
×
2223
    metaFetchEntryFree(&pSuperEntry);
×
2224
    return code;
×
2225
  }
2226

2227
  metaFetchEntryFree(&pOldEntry);
×
2228
  metaFetchEntryFree(&pSuperEntry);
×
2229
  return code;
×
2230
}
2231

2232
static int32_t metaHandleNormalTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
×
2233
  int32_t     code = TSDB_CODE_SUCCESS;
×
2234
  SMetaEntry *pOldEntry = NULL;
×
2235

2236
  // fetch old entry
2237
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
×
2238
  if (code) {
×
2239
    metaErr(TD_VID(pMeta->pVnode), code);
×
2240
    return code;
×
2241
  }
2242

2243
  // handle update
2244
  SMetaHandleParam param = {
×
2245
      .pEntry = pEntry,
2246
      .pOldEntry = pOldEntry,
2247
  };
2248
  metaWLock(pMeta);
×
2249
  code = metaHandleNormalTableUpdateImpl(pMeta, &param);
×
2250
  metaULock(pMeta);
×
2251
  if (code) {
×
2252
    metaErr(TD_VID(pMeta->pVnode), code);
×
2253
    metaFetchEntryFree(&pOldEntry);
×
2254
    return code;
×
2255
  }
2256

2257
  // do other stuff
2258
  if (!TSDB_CACHE_NO(pMeta->pVnode->config) &&
×
2259
      pEntry->ntbEntry.schemaRow.version != pOldEntry->ntbEntry.schemaRow.version) {
×
2260
#if 0
2261
    {  // for add column
2262
      int16_t cid = pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].colId;
2263
      int8_t  col_type = pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].type;
2264
      int32_t ret = tsdbCacheNewNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, col_type);
2265
      if (ret < 0) {
2266
        terrno = ret;
2267
        goto _err;
2268
      }
2269
    }
2270
    {  // for drop column
2271

2272
      if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
2273
        int16_t cid = pColumn->colId;
2274

2275
        if (tsdbCacheDropNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, hasPrimayKey) != 0) {
2276
          metaError("vgId:%d, failed to drop ntable column:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name,
2277
                    entry.uid);
2278
        }
2279
        tsdbCacheInvalidateSchema(pMeta->pVnode->pTsdb, 0, entry.uid, pSchema->version);
2280
      }
2281
    }
2282
    }
2283
#endif
2284
    tsdbCacheInvalidateSchema(pMeta->pVnode->pTsdb, 0, pEntry->uid, pEntry->ntbEntry.schemaRow.version);
×
2285
  }
2286
  int32_t deltaCol = pEntry->ntbEntry.schemaRow.nCols - pOldEntry->ntbEntry.schemaRow.nCols;
×
2287
  pMeta->pVnode->config.vndStats.numOfNTimeSeries += deltaCol;  
×
2288
  if (deltaCol > 0) metaTimeSeriesNotifyCheck(pMeta);
×
2289
  metaFetchEntryFree(&pOldEntry);
×
2290
  return code;
×
2291
}
2292

2293
static int32_t metaHandleVirtualNormalTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
×
2294
  int32_t     code = TSDB_CODE_SUCCESS;
×
2295
  SMetaEntry *pOldEntry = NULL;
×
2296

2297
  // fetch old entry
2298
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
×
2299
  if (code) {
×
2300
    metaErr(TD_VID(pMeta->pVnode), code);
×
2301
    return code;
×
2302
  }
2303

2304
  // handle update
2305
  SMetaHandleParam param = {
×
2306
      .pEntry = pEntry,
2307
      .pOldEntry = pOldEntry,
2308
  };
2309
  metaWLock(pMeta);
×
2310
  code = metaHandleVirtualNormalTableUpdateImpl(pMeta, &param);
×
2311
  metaULock(pMeta);
×
2312
  if (code) {
×
2313
    metaErr(TD_VID(pMeta->pVnode), code);
×
2314
    metaFetchEntryFree(&pOldEntry);
×
2315
    return code;
×
2316
  }
2317

2318
  metaTimeSeriesNotifyCheck(pMeta);
×
2319
  metaFetchEntryFree(&pOldEntry);
×
2320
  return code;
×
2321
}
2322

2323
static int32_t metaHandleVirtualChildTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
×
2324
  int32_t code = TSDB_CODE_SUCCESS;
×
2325

2326
  SMetaEntry *pOldEntry = NULL;
×
2327
  SMetaEntry *pSuperEntry = NULL;
×
2328

2329
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
×
2330
  if (code) {
×
2331
    metaErr(TD_VID(pMeta->pVnode), code);
×
2332
    return code;
×
2333
  }
2334

2335
  code = metaFetchEntryByUid(pMeta, pEntry->ctbEntry.suid, &pSuperEntry);
×
2336
  if (code) {
×
2337
    metaErr(TD_VID(pMeta->pVnode), code);
×
2338
    metaFetchEntryFree(&pOldEntry);
×
2339
    return code;
×
2340
  }
2341

2342
  SMetaHandleParam param = {
×
2343
      .pEntry = pEntry,
2344
      .pOldEntry = pOldEntry,
2345
      .pSuperEntry = pSuperEntry,
2346
  };
2347

2348
  metaWLock(pMeta);
×
2349
  code = metaHandleVirtualChildTableUpdateImpl(pMeta, &param);
×
2350
  metaULock(pMeta);
×
2351
  if (code) {
×
2352
    metaErr(TD_VID(pMeta->pVnode), code);
×
2353
    metaFetchEntryFree(&pOldEntry);
×
2354
    metaFetchEntryFree(&pSuperEntry);
×
2355
    return code;
×
2356
  }
2357

2358
  metaFetchEntryFree(&pOldEntry);
×
2359
  metaFetchEntryFree(&pSuperEntry);
×
2360
  return code;
×
2361
}
2362

2363
static int32_t metaHandleSuperTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) {
4✔
2364
  int32_t     code = TSDB_CODE_SUCCESS;
4✔
2365
  SArray     *childList = NULL;
4✔
2366
  SMetaEntry *pOldEntry = NULL;
4✔
2367

2368
  code = metaFetchEntryByUid(pMeta, pEntry->uid, &pOldEntry);
4✔
2369
  if (code) {
4!
2370
    metaErr(TD_VID(pMeta->pVnode), code);
×
2371
    return code;
×
2372
  }
2373

2374
  code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &childList);
4✔
2375
  if (code) {
4!
2376
    metaErr(TD_VID(pMeta->pVnode), code);
×
2377
    metaFetchEntryFree(&pOldEntry);
×
2378
    return code;
×
2379
  }
2380

2381
  if (tsdbCacheDropSubTables(pMeta->pVnode->pTsdb, childList, pEntry->uid) < 0) {
4!
2382
    metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pEntry->name,
×
2383
              pEntry->uid, tstrerror(terrno));
2384
  }
2385

2386
  // loop to drop all child tables
2387
  for (int32_t i = 0; i < taosArrayGetSize(childList); i++) {
4!
2388
    SMetaEntry childEntry = {
×
2389
        .version = pEntry->version,
×
2390
        .uid = *(tb_uid_t *)taosArrayGet(childList, i),
×
2391
        .type = -TSDB_CHILD_TABLE,
2392
    };
2393

2394
    code = metaHandleChildTableDrop(pMeta, &childEntry, true);
×
2395
    if (code) {
×
2396
      metaErr(TD_VID(pMeta->pVnode), code);
×
2397
    }
2398
  }
2399

2400
  // do drop super table
2401
  SMetaHandleParam param = {
4✔
2402
      .pEntry = pEntry,
2403
      .pOldEntry = pOldEntry,
2404
  };
2405
  metaWLock(pMeta);
4✔
2406
  code = metaHandleSuperTableDropImpl(pMeta, &param);
4✔
2407
  metaULock(pMeta);
4✔
2408
  if (code) {
4!
2409
    metaErr(TD_VID(pMeta->pVnode), code);
×
2410
    taosArrayDestroy(childList);
×
2411
    metaFetchEntryFree(&pOldEntry);
×
2412
    return code;
×
2413
  }
2414

2415
  // do other stuff
2416
  metaUpdTimeSeriesNum(pMeta);
4✔
2417

2418
  // free resource and return
2419
  taosArrayDestroy(childList);
4✔
2420
  metaFetchEntryFree(&pOldEntry);
4✔
2421
  return code;
4✔
2422
}
2423

2424
int32_t metaHandleEntry2(SMeta *pMeta, const SMetaEntry *pEntry) {
40✔
2425
  int32_t   code = TSDB_CODE_SUCCESS;
40✔
2426
  int32_t   vgId = TD_VID(pMeta->pVnode);
40✔
2427
  SMetaInfo info = {0};
40✔
2428
  int8_t    type = pEntry->type > 0 ? pEntry->type : -pEntry->type;
40✔
2429

2430
  if (NULL == pMeta || NULL == pEntry) {
40!
2431
    metaError("%s failed at %s:%d since invalid parameter", __func__, __FILE__, __LINE__);
×
2432
    return TSDB_CODE_INVALID_PARA;
×
2433
  }
2434

2435
  if (pEntry->type > 0) {
40✔
2436
    bool isExist = false;
36✔
2437
    if (TSDB_CODE_SUCCESS == metaGetInfo(pMeta, pEntry->uid, &info, NULL)) {
36✔
2438
      isExist = true;
16✔
2439
    }
2440

2441
    switch (type) {
36!
2442
      case TSDB_SUPER_TABLE: {
35✔
2443
        if (isExist) {
35✔
2444
          code = metaHandleSuperTableUpdate(pMeta, pEntry);
16✔
2445
        } else {
2446
          code = metaHandleSuperTableCreate(pMeta, pEntry);
19✔
2447
        }
2448
        break;
35✔
2449
      }
2450
      case TSDB_CHILD_TABLE: {
1✔
2451
        if (isExist) {
1!
2452
          code = metaHandleChildTableUpdate(pMeta, pEntry);
×
2453
        } else {
2454
          code = metaHandleChildTableCreate(pMeta, pEntry);
1✔
2455
        }
2456
        break;
1✔
2457
      }
2458
      case TSDB_NORMAL_TABLE: {
×
2459
        if (isExist) {
×
2460
          code = metaHandleNormalTableUpdate(pMeta, pEntry);
×
2461
        } else {
2462
          code = metaHandleNormalTableCreate(pMeta, pEntry);
×
2463
        }
2464
        break;
×
2465
      }
2466
      case TSDB_VIRTUAL_NORMAL_TABLE: {
×
2467
        if (isExist) {
×
2468
          code = metaHandleVirtualNormalTableUpdate(pMeta, pEntry);
×
2469
        } else {
2470
          code = metaHandleVirtualNormalTableCreate(pMeta, pEntry);
×
2471
        }
2472
        break;
×
2473
      }
2474
      case TSDB_VIRTUAL_CHILD_TABLE: {
×
2475
        if (isExist) {
×
2476
          code = metaHandleVirtualChildTableUpdate(pMeta, pEntry);
×
2477
        } else {
2478
          code = metaHandleVirtualChildTableCreate(pMeta, pEntry);
×
2479
        }
2480
        break;
×
2481
      }
2482
      default: {
×
2483
        code = TSDB_CODE_INVALID_PARA;
×
2484
        break;
×
2485
      }
2486
    }
2487
  } else {
2488
    switch (type) {
4!
2489
      case TSDB_SUPER_TABLE: {
4✔
2490
        code = metaHandleSuperTableDrop(pMeta, pEntry);
4✔
2491
        break;
4✔
2492
      }
2493
      case TSDB_CHILD_TABLE: {
×
2494
        code = metaHandleChildTableDrop(pMeta, pEntry, false);
×
2495
        break;
×
2496
      }
2497
      case TSDB_NORMAL_TABLE: {
×
2498
        code = metaHandleNormalTableDrop(pMeta, pEntry);
×
2499
        break;
×
2500
      }
2501
      case TSDB_VIRTUAL_NORMAL_TABLE: {
×
2502
        code = metaHandleVirtualNormalTableDrop(pMeta, pEntry);
×
2503
        break;
×
2504
      }
2505
      case TSDB_VIRTUAL_CHILD_TABLE: {
×
2506
        code = metaHandleVirtualChildTableDrop(pMeta, pEntry, false);
×
2507
        break;
×
2508
      }
2509
      default: {
×
2510
        code = TSDB_CODE_INVALID_PARA;
×
2511
        break;
×
2512
      }
2513
    }
2514
  }
2515

2516
  if (TSDB_CODE_SUCCESS == code) {
40!
2517
    pMeta->changed = true;
40✔
2518
    metaDebug("vgId:%d, index:%" PRId64 ", handle meta entry success, type:%d tb:%s uid:%" PRId64, vgId, pEntry->version,
40!
2519
              pEntry->type, pEntry->type > 0 ? pEntry->name : "", pEntry->uid);
2520
  } else {
2521
    metaErr(vgId, code);
×
2522
  }
2523
  TAOS_RETURN(code);
40✔
2524
}
2525

2526
void metaHandleSyncEntry(SMeta *pMeta, const SMetaEntry *pEntry) {
×
2527
  int32_t code = TSDB_CODE_SUCCESS;
×
2528
  code = metaHandleEntry2(pMeta, pEntry);
×
2529
  if (code) {
×
2530
    metaErr(TD_VID(pMeta->pVnode), code);
×
2531
  }
2532
  return;
×
2533
}
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