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

taosdata / TDengine / #3660

15 Mar 2025 09:06AM UTC coverage: 62.039% (-1.3%) from 63.314%
#3660

push

travis-ci

web-flow
feat(stream): support stream processing for virtual tables (#30144)

* enh: add client processing

* enh: add mnode vtables processing

* enh: add mnode vtable processing

* enh: add normal child vtable support

* fix: compile issues

* fix: compile issues

* fix: create stream issues

* fix: multi stream scan issue

* fix: remove debug info

* fix: agg task and task level issues

* fix: correct task output type

* fix: split vtablescan from agg

* fix: memory leak issues

* fix: add limitations

* Update 09-error-code.md

* Update 09-error-code.md

* fix: remove usless case

* feat(stream): extract original table data in source scan task

Implemented functionality in the source task to extract data
corresponding to the virtual table from the original table using WAL.
The extracted data is then sent to the downstream merge task for further
processing.

* feat(stream): multi-way merge using loser tree in virtual merge task

Implemented multi-way merge in the merge task using a loser tree to
combine data from multiple original table into a single virtual table.
The merged virtual table data is then pushed downstream for further
processing.  Introduced memory limit handling during the merge process
with configurable behavior when the memory limit is reached.

* fix(test): remove useless cases

---------

Co-authored-by: dapan1121 <wpan@taosdata.com>
Co-authored-by: Pan Wei <72057773+dapan1121@users.noreply.github.com>

154078 of 317582 branches covered (48.52%)

Branch coverage included in aggregate %.

313 of 2391 new or added lines in 34 files covered. (13.09%)

26134 existing lines in 205 files now uncovered.

240261 of 318051 relevant lines covered (75.54%)

16655189.27 hits per line

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

43.73
/source/dnode/vnode/src/meta/metaTable2.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "meta.h"
17

18
extern int32_t metaHandleEntry2(SMeta *pMeta, const SMetaEntry *pEntry);
19
extern int32_t metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema, STableMetaRsp *pMetaRsp);
20
extern int32_t metaUpdateVtbMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema, SColRefWrapper *pRef,
21
                                    STableMetaRsp *pMetaRsp, int8_t tableType);
22
extern int32_t metaFetchEntryByUid(SMeta *pMeta, int64_t uid, SMetaEntry **ppEntry);
23
extern int32_t metaFetchEntryByName(SMeta *pMeta, const char *name, SMetaEntry **ppEntry);
24
extern void    metaFetchEntryFree(SMetaEntry **ppEntry);
25
extern int32_t updataTableColCmpr(SColCmprWrapper *pWp, SSchema *pSchema, int8_t add, uint32_t compress);
26
extern int32_t addTableExtSchema(SMetaEntry* pEntry, const SSchema* pColumn, int32_t newColNum, SExtSchema* pExtSchema);
27
extern int32_t dropTableExtSchema(SMetaEntry* pEntry, int32_t dropColId, int32_t newColNum);
28

29
static int32_t metaCheckCreateSuperTableReq(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
27,794✔
30
  int32_t   vgId = TD_VID(pMeta->pVnode);
27,794✔
31
  void     *value = NULL;
27,794✔
32
  int32_t   valueSize = 0;
27,794✔
33
  SMetaInfo info;
34

35
  // check name
36
  if (NULL == pReq->name || strlen(pReq->name) == 0) {
27,794!
UNCOV
37
    metaError("vgId:%d, %s failed at %s:%d since invalid name:%s, version:%" PRId64, vgId, __func__, __FILE__, __LINE__,
×
38
              pReq->name, version);
UNCOV
39
    return TSDB_CODE_INVALID_MSG;
×
40
  }
41

42
  int32_t r = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &value, &valueSize);
27,822✔
43
  if (r == 0) {  // name exists, check uid and type
27,720✔
44
    int64_t uid = *(tb_uid_t *)value;
58✔
45
    tdbFree(value);
58✔
46

47
    if (pReq->suid != uid) {
58✔
48
      metaError("vgId:%d, %s failed at %s:%d since table %s uid:%" PRId64 " already exists, request uid:%" PRId64
3!
49
                " version:%" PRId64,
50
                vgId, __func__, __FILE__, __LINE__, pReq->name, uid, pReq->suid, version);
51
      return TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
3✔
52
    }
53

54
    if (metaGetInfo(pMeta, uid, &info, NULL) == TSDB_CODE_NOT_FOUND) {
55!
UNCOV
55
      metaError("vgId:%d, %s failed at %s:%d since table %s uid:%" PRId64
×
56
                " not found, this is an internal error in meta, version:%" PRId64,
57
                vgId, __func__, __FILE__, __LINE__, pReq->name, uid, version);
UNCOV
58
      return TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
59
    }
60

61
    if (info.uid == info.suid) {
55!
62
      return TSDB_CODE_TDB_STB_ALREADY_EXIST;
55✔
63
    } else {
UNCOV
64
      metaError("vgId:%d, %s failed at %s:%d since table %s uid:%" PRId64
×
65
                " already exists but not a super table, version:%" PRId64,
66
                vgId, __func__, __FILE__, __LINE__, pReq->name, uid, version);
UNCOV
67
      return TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
×
68
    }
69
  }
70

71
  // check suid
72
  if (metaGetInfo(pMeta, pReq->suid, &info, NULL) != TSDB_CODE_NOT_FOUND) {
27,662!
UNCOV
73
    metaError("vgId:%d, %s failed at %s:%d since table with uid:%" PRId64 " already exist, name:%s version:%" PRId64,
×
74
              vgId, __func__, __FILE__, __LINE__, pReq->suid, pReq->name, version);
UNCOV
75
    return TSDB_CODE_INVALID_MSG;
×
76
  }
77

78
  return TSDB_CODE_SUCCESS;
27,737✔
79
}
80

81
static int32_t metaCheckDropTableReq(SMeta *pMeta, int64_t version, SVDropTbReq *pReq) {
2,648✔
82
  int32_t   code = TSDB_CODE_SUCCESS;
2,648✔
83
  void     *value = NULL;
2,648✔
84
  int32_t   valueSize = 0;
2,648✔
85
  SMetaInfo info;
86

87
  if (NULL == pReq->name || strlen(pReq->name) == 0) {
2,648!
UNCOV
88
    metaError("vgId:%d, %s failed at %s:%d since invalid name:%s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
89
              __FILE__, __LINE__, pReq->name, version);
UNCOV
90
    return TSDB_CODE_INVALID_MSG;
×
91
  }
92

93
  code = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &value, &valueSize);
2,648✔
94
  if (TSDB_CODE_SUCCESS != code) {
2,648!
95
    if (pReq->igNotExists) {
×
UNCOV
96
      metaTrace("vgId:%d, %s success since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
97
                pReq->name, version);
98
    } else {
UNCOV
99
      metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode),
×
100
                __func__, __FILE__, __LINE__, pReq->name, version);
101
    }
UNCOV
102
    return TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
103
  }
104
  pReq->uid = *(tb_uid_t *)value;
2,648✔
105
  tdbFreeClear(value);
2,648✔
106

107
  code = metaGetInfo(pMeta, pReq->uid, &info, NULL);
2,648✔
108
  if (TSDB_CODE_SUCCESS != code) {
2,648!
109
    metaError("vgId:%d, %s failed at %s:%d since table %s uid %" PRId64
×
110
              " not found, this is an internal error, version:%" PRId64,
111
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, pReq->uid, version);
UNCOV
112
    code = TSDB_CODE_INTERNAL_ERROR;
×
UNCOV
113
    return code;
×
114
  }
115
  pReq->suid = info.suid;
2,648✔
116

117
  return code;
2,648✔
118
}
119

120
static int32_t metaCheckDropSuperTableReq(SMeta *pMeta, int64_t version, SVDropStbReq *pReq) {
2,511✔
121
  int32_t   code = TSDB_CODE_SUCCESS;
2,511✔
122
  void     *value = NULL;
2,511✔
123
  int32_t   valueSize = 0;
2,511✔
124
  SMetaInfo info;
125

126
  if (NULL == pReq->name || strlen(pReq->name) == 0) {
2,511!
UNCOV
127
    metaError("vgId:%d, %s failed at %s:%d since invalid name:%s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
128
              __FILE__, __LINE__, pReq->name, version);
UNCOV
129
    return TSDB_CODE_INVALID_MSG;
×
130
  }
131

132
  code = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &value, &valueSize);
2,515✔
133
  if (code) {
2,514✔
134
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
3!
135
              __FILE__, __LINE__, pReq->name, version);
136
    return TSDB_CODE_TDB_STB_NOT_EXIST;
3✔
137
  } else {
138
    int64_t uid = *(int64_t *)value;
2,511✔
139
    tdbFreeClear(value);
2,511✔
140

141
    if (uid != pReq->suid) {
2,517✔
142
      metaError("vgId:%d, %s failed at %s:%d since table %s uid:%" PRId64 " not match, version:%" PRId64,
2!
143
                TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, pReq->suid, version);
144
      return TSDB_CODE_TDB_STB_NOT_EXIST;
2✔
145
    }
146
  }
147

148
  code = metaGetInfo(pMeta, pReq->suid, &info, NULL);
2,515✔
149
  if (code) {
2,511✔
150
    metaError("vgId:%d, %s failed at %s:%d since table %s uid %" PRId64
5!
151
              " not found, this is an internal error, version:%" PRId64,
152
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, pReq->suid, version);
UNCOV
153
    return TSDB_CODE_INTERNAL_ERROR;
×
154
  }
155
  if (info.suid != info.uid) {
2,506!
UNCOV
156
    metaError("vgId:%d, %s failed at %s:%d since table %s uid %" PRId64 " is not a super table, version:%" PRId64,
×
157
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, pReq->suid, version);
UNCOV
158
    return TSDB_CODE_INVALID_MSG;
×
159
  }
160
  return code;
2,506✔
161
}
162

163
// Create Super Table
164
int32_t metaCreateSuperTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
27,657✔
165
  int32_t code = TSDB_CODE_SUCCESS;
27,657✔
166

167
  // check request
168
  code = metaCheckCreateSuperTableReq(pMeta, version, pReq);
27,657✔
169
  if (code != TSDB_CODE_SUCCESS) {
27,778✔
170
    if (code == TSDB_CODE_TDB_STB_ALREADY_EXIST) {
58✔
171
      metaWarn("vgId:%d, super table %s uid:%" PRId64 " already exists, version:%" PRId64, TD_VID(pMeta->pVnode),
55!
172
               pReq->name, pReq->suid, version);
173
      TAOS_RETURN(TSDB_CODE_SUCCESS);
55✔
174
    } else {
175
      TAOS_RETURN(code);
3✔
176
    }
177
  }
178

179
  // handle entry
180
  SMetaEntry entry = {
27,720✔
181
      .version = version,
182
      .type = TSDB_SUPER_TABLE,
183
      .uid = pReq->suid,
27,720✔
184
      .name = pReq->name,
27,720✔
185
      .stbEntry.schemaRow = pReq->schemaRow,
186
      .stbEntry.schemaTag = pReq->schemaTag,
187
      .stbEntry.keep = pReq->keep,
27,720✔
188
  };
189
  if (pReq->rollup) {
27,720✔
190
    TABLE_SET_ROLLUP(entry.flags);
7✔
191
    entry.stbEntry.rsmaParam = pReq->rsmaParam;
7✔
192
  }
193
  if (pReq->colCmpred) {
27,720✔
194
    TABLE_SET_COL_COMPRESSED(entry.flags);
27,687✔
195
    entry.colCmpr = pReq->colCmpr;
27,687✔
196
  }
197

198
  entry.pExtSchemas = pReq->pExtSchemas;
27,720✔
199

200
  if (pReq->virtualStb) {
27,720!
UNCOV
201
    TABLE_SET_VIRTUAL(entry.flags);
×
202
  }
203

204
  code = metaHandleEntry2(pMeta, &entry);
27,720✔
205
  if (TSDB_CODE_SUCCESS == code) {
27,837!
206
    metaInfo("vgId:%d, super table %s suid:%" PRId64 " is created, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->name,
27,837!
207
             pReq->suid, version);
208
  } else {
UNCOV
209
    metaError("vgId:%d, failed to create stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
×
210
              pReq->suid, tstrerror(code));
211
  }
212
  TAOS_RETURN(code);
27,837✔
213
}
214

215
// Drop Super Table
216
int32_t metaDropSuperTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) {
2,512✔
217
  int32_t code = TSDB_CODE_SUCCESS;
2,512✔
218

219
  // check request
220
  code = metaCheckDropSuperTableReq(pMeta, verison, pReq);
2,512✔
221
  if (code) {
2,511✔
222
    TAOS_RETURN(code);
5✔
223
  }
224

225
  // handle entry
226
  SMetaEntry entry = {
2,506✔
227
      .version = verison,
228
      .type = -TSDB_SUPER_TABLE,
229
      .uid = pReq->suid,
2,506✔
230
  };
231
  code = metaHandleEntry2(pMeta, &entry);
2,506✔
232
  if (code) {
2,518!
UNCOV
233
    metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid,
×
234
              tstrerror(code));
235
  } else {
236
    metaInfo("vgId:%d, super table %s uid:%" PRId64 " is dropped, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->name,
2,518!
237
             pReq->suid, verison);
238
  }
239
  TAOS_RETURN(code);
2,518✔
240
}
241

242
// Alter Super Table
243

244
// Create Child Table
245
static int32_t metaCheckCreateChildTableReq(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
148,097✔
246
  int32_t   code = TSDB_CODE_SUCCESS;
148,097✔
247
  void     *value = NULL;
148,097✔
248
  int32_t   valueSize = 0;
148,097✔
249
  SMetaInfo info;
250

251
  if (NULL == pReq->name || strlen(pReq->name) == 0 || NULL == pReq->ctb.stbName || strlen(pReq->ctb.stbName) == 0 ||
148,097!
252
      pReq->ctb.suid == 0) {
148,099✔
253
    metaError("vgId:%d, %s failed at %s:%d since invalid name:%s stb name:%s, version:%" PRId64, TD_VID(pMeta->pVnode),
9!
254
              __func__, __FILE__, __LINE__, pReq->name, pReq->ctb.stbName, version);
UNCOV
255
    return TSDB_CODE_INVALID_MSG;
×
256
  }
257

258
  // check table existence
259
  if (tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &value, &valueSize) == 0) {
148,088✔
260
    pReq->uid = *(int64_t *)value;
10,457✔
261
    tdbFreeClear(value);
10,457✔
262

263
    if (metaGetInfo(pMeta, pReq->uid, &info, NULL) != 0) {
10,455!
UNCOV
264
      metaError("vgId:%d, %s failed at %s:%d since cannot find table with uid %" PRId64
×
265
                ", which is an internal error, version:%" PRId64,
266
                TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->uid, version);
UNCOV
267
      return TSDB_CODE_INTERNAL_ERROR;
×
268
    }
269

270
    // check table type
271
    if (info.suid == info.uid || info.suid == 0) {
10,454!
272
      metaError("vgId:%d, %s failed at %s:%d since table with uid %" PRId64 " is not a super table, version:%" PRId64,
9!
273
                TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->uid, version);
274
      return TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE;
9✔
275
    }
276

277
    // check suid
278
    if (info.suid != pReq->ctb.suid) {
10,445!
UNCOV
279
      metaError("vgId:%d, %s failed at %s:%d since table %s uid %" PRId64 " exists in another stable with uid %" PRId64
×
280
                " instead of stable with uid %" PRId64 " version:%" PRId64,
281
                TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, pReq->uid, info.suid, pReq->ctb.suid,
282
                version);
UNCOV
283
      return TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE;
×
284
    }
285

286
    return TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
10,445✔
287
  }
288

289
  // check super table existence
290
  if (tdbTbGet(pMeta->pNameIdx, pReq->ctb.stbName, strlen(pReq->ctb.stbName) + 1, &value, &valueSize) == 0) {
137,659!
291
    int64_t suid = *(int64_t *)value;
137,665✔
292
    tdbFreeClear(value);
137,665✔
293
    if (suid != pReq->ctb.suid) {
137,666!
UNCOV
294
      metaError("vgId:%d, %s failed at %s:%d since super table %s has uid %" PRId64 " instead of %" PRId64
×
295
                ", version:%" PRId64,
296
                TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->ctb.stbName, suid, pReq->ctb.suid, version);
UNCOV
297
      return TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
298
    }
299
  } else {
300
    metaError("vgId:%d, %s failed at %s:%d since super table %s does not eixst, version:%" PRId64,
×
301
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->ctb.stbName, version);
302
    return TSDB_CODE_PAR_TABLE_NOT_EXIST;
×
303
  }
304

305
  // check super table is a super table
306
  if (metaGetInfo(pMeta, pReq->ctb.suid, &info, NULL) != TSDB_CODE_SUCCESS) {
137,666!
UNCOV
307
    metaError("vgId:%d, %s failed at %s:%d since cannot find table with uid %" PRId64
×
308
              ", which is an internal error, version:%" PRId64,
309
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->ctb.suid, version);
UNCOV
310
    return TSDB_CODE_INTERNAL_ERROR;
×
311
  } else if (info.suid != info.uid) {
137,651!
UNCOV
312
    metaError("vgId:%d, %s failed at %s:%d since table with uid %" PRId64 " is not a super table, version:%" PRId64,
×
313
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->ctb.suid, version);
UNCOV
314
    return TSDB_CODE_INVALID_MSG;
×
315
  }
316

317
  // check grant
318
  if (!metaTbInFilterCache(pMeta, pReq->ctb.stbName, 1)) {
137,651!
319
    code = grantCheck(TSDB_GRANT_TIMESERIES);
137,644✔
320
    if (TSDB_CODE_SUCCESS != code) {
137,611!
UNCOV
321
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " name:%s", TD_VID(pMeta->pVnode), __func__,
×
322
                __FILE__, __LINE__, tstrerror(code), version, pReq->name);
323
    }
324
  }
325
  return code;
137,622✔
326
}
327

328
static int32_t metaBuildCreateChildTableRsp(SMeta *pMeta, const SMetaEntry *pEntry, STableMetaRsp **ppRsp) {
137,616✔
329
  int32_t code = TSDB_CODE_SUCCESS;
137,616✔
330

331
  if (NULL == ppRsp) {
137,616!
UNCOV
332
    return code;
×
333
  }
334

335
  *ppRsp = taosMemoryCalloc(1, sizeof(STableMetaRsp));
137,616!
336
  if (NULL == ppRsp) {
137,644!
UNCOV
337
    return terrno;
×
338
  }
339

340
  (*ppRsp)->tableType = TSDB_CHILD_TABLE;
137,644✔
341
  (*ppRsp)->tuid = pEntry->uid;
137,644✔
342
  (*ppRsp)->suid = pEntry->ctbEntry.suid;
137,644✔
343
  tstrncpy((*ppRsp)->tbName, pEntry->name, TSDB_TABLE_NAME_LEN);
137,644✔
344

345
  return code;
137,644✔
346
}
347

348
static int32_t metaCreateChildTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq, STableMetaRsp **ppRsp) {
148,102✔
349
  int32_t code = TSDB_CODE_SUCCESS;
148,102✔
350

351
  // check request
352
  code = metaCheckCreateChildTableReq(pMeta, version, pReq);
148,102✔
353
  if (code) {
148,072✔
354
    if (TSDB_CODE_TDB_TABLE_ALREADY_EXIST != code) {
10,454✔
355
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " name:%s", TD_VID(pMeta->pVnode), __func__,
9!
356
                __FILE__, __LINE__, tstrerror(code), version, pReq->name);
357
    }
358
    return code;
10,453✔
359
  }
360

361
  SMetaEntry entry = {
137,618✔
362
      .version = version,
363
      .type = TSDB_CHILD_TABLE,
364
      .uid = pReq->uid,
137,618✔
365
      .name = pReq->name,
137,618✔
366
      .ctbEntry.btime = pReq->btime,
137,618✔
367
      .ctbEntry.ttlDays = pReq->ttl,
137,618✔
368
      .ctbEntry.commentLen = pReq->commentLen,
137,618✔
369
      .ctbEntry.comment = pReq->comment,
137,618✔
370
      .ctbEntry.suid = pReq->ctb.suid,
137,618✔
371
      .ctbEntry.pTags = pReq->ctb.pTag,
137,618✔
372
  };
373

374
  // build response
375
  code = metaBuildCreateChildTableRsp(pMeta, &entry, ppRsp);
137,618✔
376
  if (code) {
137,656!
377
    metaError("vgId:%d, %s failed at %s:%d since %s", TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__,
×
378
              tstrerror(code));
379
  }
380

381
  // handle entry
382
  code = metaHandleEntry2(pMeta, &entry);
137,656✔
383
  if (TSDB_CODE_SUCCESS == code) {
137,643!
384
    metaInfo("vgId:%d, child table:%s uid %" PRId64 " suid:%" PRId64 " is created, version:%" PRId64,
137,648!
385
             TD_VID(pMeta->pVnode), pReq->name, pReq->uid, pReq->ctb.suid, version);
386
  } else {
UNCOV
387
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s suid:%" PRId64 " version:%" PRId64,
×
388
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, tstrerror(code), pReq->uid, pReq->name,
389
              pReq->ctb.suid, version);
390
  }
391
  return code;
137,675✔
392
}
393

394
// Drop Child Table
395

396
// Alter Child Table
397

398
// Create Normal Table
399
static int32_t metaCheckCreateNormalTableReq(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
14,344✔
400
  int32_t code = 0;
14,344✔
401
  void   *value = NULL;
14,344✔
402
  int32_t valueSize = 0;
14,344✔
403

404
  if (NULL == pReq->name || strlen(pReq->name) == 0) {
14,344!
405
    metaError("vgId:%d, %s failed at %s:%d since invalid name:%s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
1!
406
              __FILE__, __LINE__, pReq->name, version);
UNCOV
407
    return TSDB_CODE_INVALID_MSG;
×
408
  }
409

410
  // check name
411
  if (tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &value, &valueSize) == 0) {
14,343✔
412
    // for auto create table, we return the uid of the existing table
413
    pReq->uid = *(tb_uid_t *)value;
6✔
414
    tdbFree(value);
6✔
415
    return TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
6✔
416
  }
417

418
  // grant check
419
  code = grantCheck(TSDB_GRANT_TIMESERIES);
14,341✔
420
  if (code) {
14,341!
421
    metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " name:%s", TD_VID(pMeta->pVnode), __func__,
×
422
              __FILE__, __LINE__, tstrerror(code), version, pReq->name);
423
  }
424
  return code;
14,341✔
425
}
426

427
static int32_t metaBuildCreateNormalTableRsp(SMeta *pMeta, SMetaEntry *pEntry, STableMetaRsp **ppRsp) {
14,340✔
428
  int32_t code = TSDB_CODE_SUCCESS;
14,340✔
429

430
  if (NULL == ppRsp) {
14,340!
431
    return code;
×
432
  }
433

434
  *ppRsp = taosMemoryCalloc(1, sizeof(STableMetaRsp));
14,340!
435
  if (NULL == *ppRsp) {
14,341!
UNCOV
436
    return terrno;
×
437
  }
438

439
  code = metaUpdateMetaRsp(pEntry->uid, pEntry->name, &pEntry->ntbEntry.schemaRow, *ppRsp);
14,341✔
440
  if (code) {
14,342!
UNCOV
441
    taosMemoryFreeClear(*ppRsp);
×
UNCOV
442
    return code;
×
443
  }
444

445
  for (int32_t i = 0; i < pEntry->colCmpr.nCols; i++) {
158,140✔
446
    SColCmpr *p = &pEntry->colCmpr.pColCmpr[i];
143,798✔
447
    (*ppRsp)->pSchemaExt[i].colId = p->id;
143,798✔
448
    (*ppRsp)->pSchemaExt[i].compress = p->alg;
143,798✔
449
    if (pEntry->pExtSchemas) {
143,798✔
450
      (*ppRsp)->pSchemaExt[i].typeMod = pEntry->pExtSchemas[i].typeMod;
99✔
451
    }
452
  }
453

454
  return code;
14,342✔
455
}
456

457
static int32_t metaCreateNormalTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq, STableMetaRsp **ppRsp) {
14,345✔
458
  int32_t code = TSDB_CODE_SUCCESS;
14,345✔
459

460
  // check request
461
  code = metaCheckCreateNormalTableReq(pMeta, version, pReq);
14,345✔
462
  if (code) {
14,347✔
463
    if (TSDB_CODE_TDB_TABLE_ALREADY_EXIST != code) {
6!
UNCOV
464
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " name:%s", TD_VID(pMeta->pVnode), __func__,
×
465
                __FILE__, __LINE__, tstrerror(code), version, pReq->name);
466
    }
467
    TAOS_RETURN(code);
6✔
468
  }
469

470
  SMetaEntry entry = {
14,341✔
471
    .version = version,
472
    .type = TSDB_NORMAL_TABLE,
473
    .uid = pReq->uid,
14,341✔
474
    .name = pReq->name,
14,341✔
475
    .ntbEntry.btime = pReq->btime,
14,341✔
476
    .ntbEntry.ttlDays = pReq->ttl,
14,341✔
477
    .ntbEntry.commentLen = pReq->commentLen,
14,341✔
478
    .ntbEntry.comment = pReq->comment,
14,341✔
479
    .ntbEntry.schemaRow = pReq->ntb.schemaRow,
480
    .ntbEntry.ncid = pReq->ntb.schemaRow.pSchema[pReq->ntb.schemaRow.nCols - 1].colId + 1,
14,341✔
481
    .colCmpr = pReq->colCmpr,
482
    .pExtSchemas = pReq->pExtSchemas,
14,341✔
483
  };
484
  TABLE_SET_COL_COMPRESSED(entry.flags);
14,341✔
485

486
  // build response
487
  code = metaBuildCreateNormalTableRsp(pMeta, &entry, ppRsp);
14,341✔
488
  if (code) {
14,342!
UNCOV
489
    metaError("vgId:%d, %s failed at %s:%d since %s", TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__,
×
490
              tstrerror(code));
491
  }
492

493
  // handle entry
494
  code = metaHandleEntry2(pMeta, &entry);
14,342✔
495
  if (TSDB_CODE_SUCCESS == code) {
14,341!
496
    metaInfo("vgId:%d, normal table:%s uid %" PRId64 " is created, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->name,
14,341!
497
             pReq->uid, version);
498
  } else {
UNCOV
499
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
500
              __func__, __FILE__, __LINE__, tstrerror(code), pReq->uid, pReq->name, version);
501
  }
502
  TAOS_RETURN(code);
14,342✔
503
}
504

UNCOV
505
static int32_t metaBuildCreateVirtualNormalTableRsp(SMeta *pMeta, SMetaEntry *pEntry, STableMetaRsp **ppRsp) {
×
UNCOV
506
  int32_t code = TSDB_CODE_SUCCESS;
×
507

UNCOV
508
  if (NULL == ppRsp) {
×
UNCOV
509
    return code;
×
510
  }
511

UNCOV
512
  *ppRsp = taosMemoryCalloc(1, sizeof(STableMetaRsp));
×
513
  if (NULL == *ppRsp) {
×
514
    return terrno;
×
515
  }
516

517
  code = metaUpdateVtbMetaRsp(pEntry->uid, pEntry->name, &pEntry->ntbEntry.schemaRow, &pEntry->colRef, *ppRsp, TSDB_VIRTUAL_NORMAL_TABLE);
×
UNCOV
518
  if (code) {
×
UNCOV
519
    taosMemoryFreeClear(*ppRsp);
×
UNCOV
520
    return code;
×
521
  }
522

UNCOV
523
  return code;
×
524
}
525

UNCOV
526
static int32_t metaCreateVirtualNormalTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq, STableMetaRsp **ppRsp) {
×
527
  // check request
UNCOV
528
  int32_t code = metaCheckCreateNormalTableReq(pMeta, version, pReq);
×
UNCOV
529
  if (code) {
×
UNCOV
530
    if (TSDB_CODE_TDB_TABLE_ALREADY_EXIST != code) {
×
UNCOV
531
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " name:%s", TD_VID(pMeta->pVnode), __func__,
×
532
                __FILE__, __LINE__, tstrerror(code), version, pReq->name);
533
    }
UNCOV
534
    TAOS_RETURN(code);
×
535
  }
536

UNCOV
537
  SMetaEntry entry = {
×
538
      .version = version,
539
      .type = TSDB_VIRTUAL_NORMAL_TABLE,
UNCOV
540
      .uid = pReq->uid,
×
UNCOV
541
      .name = pReq->name,
×
UNCOV
542
      .ntbEntry.btime = pReq->btime,
×
UNCOV
543
      .ntbEntry.ttlDays = pReq->ttl,
×
UNCOV
544
      .ntbEntry.commentLen = pReq->commentLen,
×
UNCOV
545
      .ntbEntry.comment = pReq->comment,
×
546
      .ntbEntry.schemaRow = pReq->ntb.schemaRow,
UNCOV
547
      .ntbEntry.ncid = pReq->ntb.schemaRow.pSchema[pReq->ntb.schemaRow.nCols - 1].colId + 1,
×
548
      .colRef = pReq->colRef
549
  };
550

UNCOV
551
  code = metaBuildCreateVirtualNormalTableRsp(pMeta, &entry, ppRsp);
×
552
  if (code) {
×
UNCOV
553
    metaError("vgId:%d, %s failed at %s:%d since %s", TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__,
×
554
              tstrerror(code));
555
  }
556

557
  // handle entry
UNCOV
558
  code = metaHandleEntry2(pMeta, &entry);
×
UNCOV
559
  if (TSDB_CODE_SUCCESS == code) {
×
UNCOV
560
    metaInfo("vgId:%d, normal table:%s uid %" PRId64 " is created, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->name,
×
561
             pReq->uid, version);
562
  } else {
UNCOV
563
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
564
              __func__, __FILE__, __LINE__, tstrerror(code), pReq->uid, pReq->name, version);
565
  }
UNCOV
566
  TAOS_RETURN(code);
×
567
#if 0
568
  metaTimeSeriesNotifyCheck(pMeta);
569
#endif
570
}
571

UNCOV
572
static int32_t metaBuildCreateVirtualChildTableRsp(SMeta *pMeta, SMetaEntry *pEntry, STableMetaRsp **ppRsp) {
×
573
  int32_t code = TSDB_CODE_SUCCESS;
×
574

UNCOV
575
  if (NULL == ppRsp) {
×
576
    return code;
×
577
  }
578

UNCOV
579
  *ppRsp = taosMemoryCalloc(1, sizeof(STableMetaRsp));
×
UNCOV
580
  if (NULL == *ppRsp) {
×
UNCOV
581
    return terrno;
×
582
  }
583

UNCOV
584
  code = metaUpdateVtbMetaRsp(pEntry->uid, pEntry->name, NULL, &pEntry->colRef, *ppRsp, TSDB_VIRTUAL_CHILD_TABLE);
×
UNCOV
585
  if (code) {
×
UNCOV
586
    taosMemoryFreeClear(*ppRsp);
×
UNCOV
587
    return code;
×
588
  }
589
  (*ppRsp)->suid = pEntry->ctbEntry.suid;
×
590

591
  return code;
×
592
}
593

UNCOV
594
static int32_t metaCreateVirtualChildTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq, STableMetaRsp **ppRsp) {
×
595
  // check request
UNCOV
596
  int32_t code = metaCheckCreateChildTableReq(pMeta, version, pReq);
×
UNCOV
597
  if (code) {
×
UNCOV
598
    if (TSDB_CODE_TDB_TABLE_ALREADY_EXIST != code) {
×
UNCOV
599
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " name:%s", TD_VID(pMeta->pVnode), __func__,
×
600
                __FILE__, __LINE__, tstrerror(code), version, pReq->name);
601
    }
602
    TAOS_RETURN(code);
×
603
  }
604

UNCOV
605
  SMetaEntry entry = {
×
606
      .version = version,
607
      .type = TSDB_VIRTUAL_CHILD_TABLE,
UNCOV
608
      .uid = pReq->uid,
×
609
      .name = pReq->name,
×
UNCOV
610
      .ctbEntry.btime = pReq->btime,
×
611
      .ctbEntry.ttlDays = pReq->ttl,
×
UNCOV
612
      .ctbEntry.commentLen = pReq->commentLen,
×
UNCOV
613
      .ctbEntry.comment = pReq->comment,
×
614
      .ctbEntry.suid = pReq->ctb.suid,
×
UNCOV
615
      .ctbEntry.pTags = pReq->ctb.pTag,
×
616
      .colRef = pReq->colRef
617
  };
618

UNCOV
619
  code = metaBuildCreateVirtualChildTableRsp(pMeta, &entry, ppRsp);
×
UNCOV
620
  if (code) {
×
UNCOV
621
    metaError("vgId:%d, %s failed at %s:%d since %s", TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__,
×
622
              tstrerror(code));
623
  }
624

625
  // handle entry
UNCOV
626
  code = metaHandleEntry2(pMeta, &entry);
×
UNCOV
627
  if (TSDB_CODE_SUCCESS == code) {
×
628
    metaInfo("vgId:%d, normal table:%s uid %" PRId64 " is created, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->name,
×
629
             pReq->uid, version);
630
  } else {
631
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
632
              __func__, __FILE__, __LINE__, tstrerror(code), pReq->uid, pReq->name, version);
633
  }
UNCOV
634
  TAOS_RETURN(code);
×
635
#if 0
636
  metaTimeSeriesNotifyCheck(pMeta);
637
#endif
638
}
639

640
// Drop Normal Table
641

642
// Alter Normal Table
643

644
int32_t metaCreateTable2(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq, STableMetaRsp **ppRsp) {
162,446✔
645
  int32_t code = TSDB_CODE_SUCCESS;
162,446✔
646
  if (TSDB_CHILD_TABLE == pReq->type) {
162,446✔
647
    code = metaCreateChildTable(pMeta, version, pReq, ppRsp);
148,108✔
648
  } else if (TSDB_NORMAL_TABLE == pReq->type) {
14,338!
649
    code = metaCreateNormalTable(pMeta, version, pReq, ppRsp);
14,347✔
UNCOV
650
  } else if (TSDB_VIRTUAL_NORMAL_TABLE == pReq->type) {
×
UNCOV
651
    code = metaCreateVirtualNormalTable(pMeta, version, pReq, ppRsp);
×
UNCOV
652
  } else if (TSDB_VIRTUAL_CHILD_TABLE == pReq->type) {
×
UNCOV
653
    code = metaCreateVirtualChildTable(pMeta, version, pReq, ppRsp);
×
654
  } else {
UNCOV
655
    code = TSDB_CODE_INVALID_MSG;
×
656
  }
657
  TAOS_RETURN(code);
162,467✔
658
}
659

660
int32_t metaDropTable2(SMeta *pMeta, int64_t version, SVDropTbReq *pReq) {
2,648✔
661
  int32_t code = TSDB_CODE_SUCCESS;
2,648✔
662

663
  // check request
664
  code = metaCheckDropTableReq(pMeta, version, pReq);
2,648✔
665
  if (code) {
2,648!
UNCOV
666
    if (TSDB_CODE_TDB_TABLE_NOT_EXIST != code) {
×
667
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " name:%s", TD_VID(pMeta->pVnode), __func__,
×
668
                __FILE__, __LINE__, tstrerror(code), version, pReq->name);
669
    }
670
    TAOS_RETURN(code);
×
671
  }
672

673
  if (pReq->suid == pReq->uid) {
2,648!
UNCOV
674
    code = TSDB_CODE_INVALID_PARA;
×
UNCOV
675
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
676
              __func__, __FILE__, __LINE__, tstrerror(code), pReq->uid, pReq->name, version);
UNCOV
677
    TAOS_RETURN(code);
×
678
  }
679

680
  SMetaEntry entry = {
2,648✔
681
      .version = version,
682
      .uid = pReq->uid,
2,648✔
683
  };
684

685
  if (pReq->isVirtual) {
2,648!
686
    if (pReq->suid == 0) {
×
UNCOV
687
      entry.type = -TSDB_VIRTUAL_NORMAL_TABLE;
×
688
    } else {
UNCOV
689
      entry.type = -TSDB_VIRTUAL_CHILD_TABLE;
×
690
    }
691
  } else {
692
    if (pReq->suid == 0) {
2,648✔
693
      entry.type = -TSDB_NORMAL_TABLE;
1,810✔
694
    } else {
695
      entry.type = -TSDB_CHILD_TABLE;
838✔
696
    }
697
  }
698
  code = metaHandleEntry2(pMeta, &entry);
2,648✔
699
  if (code) {
2,648!
UNCOV
700
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
701
              __func__, __FILE__, __LINE__, tstrerror(code), pReq->uid, pReq->name, version);
702
  } else {
703
    metaInfo("vgId:%d, table %s uid %" PRId64 " is dropped, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->name,
2,648!
704
             pReq->uid, version);
705
  }
706
  TAOS_RETURN(code);
2,648✔
707
}
708

709
static int32_t metaCheckAlterTableColumnReq(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
338✔
710
  int32_t code = 0;
338✔
711

712
  if (NULL == pReq->colName || strlen(pReq->colName) == 0) {
338!
713
    metaError("vgId:%d, %s failed at %s:%d since invalid column name:%s, version:%" PRId64, TD_VID(pMeta->pVnode),
×
714
              __func__, __FILE__, __LINE__, pReq->colName, version);
715
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
716
  }
717

718
  // check name
719
  void   *value = NULL;
338✔
720
  int32_t valueSize = 0;
338✔
721
  code = tdbTbGet(pMeta->pNameIdx, pReq->tbName, strlen(pReq->tbName) + 1, &value, &valueSize);
338✔
722
  if (code) {
338!
UNCOV
723
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
724
              __FILE__, __LINE__, pReq->tbName, version);
UNCOV
725
    code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
UNCOV
726
    TAOS_RETURN(code);
×
727
  }
728
  int64_t uid = *(int64_t *)value;
338✔
729
  tdbFreeClear(value);
338✔
730

731
  // check table type
732
  SMetaInfo info;
733
  if (metaGetInfo(pMeta, uid, &info, NULL) != 0) {
338!
UNCOV
734
    metaError("vgId:%d, %s failed at %s:%d since table %s uid %" PRId64
×
735
              " not found, this is an internal error in meta, version:%" PRId64,
736
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, uid, version);
UNCOV
737
    code = TSDB_CODE_INTERNAL_ERROR;
×
738
    TAOS_RETURN(code);
×
739
  }
740
  if (info.suid != 0 && pReq->action != TSDB_ALTER_TABLE_ALTER_COLUMN_REF && pReq->action != TSDB_ALTER_TABLE_REMOVE_COLUMN_REF) {
338!
741
    metaError("vgId:%d, %s failed at %s:%d since table %s uid %" PRId64 " is not a normal table, version:%" PRId64,
×
742
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, uid, version);
UNCOV
743
    code = TSDB_CODE_VND_INVALID_TABLE_ACTION;
×
UNCOV
744
    TAOS_RETURN(code);
×
745
  }
746

747
  // check grant
748
  code = grantCheck(TSDB_GRANT_TIMESERIES);
338✔
749
  if (code) {
338!
UNCOV
750
    metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64 " name:%s", TD_VID(pMeta->pVnode), __func__,
×
751
              __FILE__, __LINE__, tstrerror(code), version, pReq->tbName);
UNCOV
752
    TAOS_RETURN(code);
×
753
  }
754
  TAOS_RETURN(code);
338✔
755
}
756

757
int32_t metaAddTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp) {
147✔
758
  int32_t code = TSDB_CODE_SUCCESS;
147✔
759

760
  // check request
761
  code = metaCheckAlterTableColumnReq(pMeta, version, pReq);
147✔
762
  if (code) {
147!
UNCOV
763
    TAOS_RETURN(code);
×
764
  }
765

766
  // fetch old entry
767
  SMetaEntry *pEntry = NULL;
147✔
768
  code = metaFetchEntryByName(pMeta, pReq->tbName, &pEntry);
147✔
769
  if (code) {
147!
770
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
771
              __FILE__, __LINE__, pReq->tbName, version);
UNCOV
772
    TAOS_RETURN(code);
×
773
  }
774
  if (pEntry->version >= version) {
147!
UNCOV
775
    metaError("vgId:%d, %s failed at %s:%d since table %s version %" PRId64 " is not less than %" PRId64,
×
776
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, pEntry->version, version);
777
    metaFetchEntryFree(&pEntry);
×
UNCOV
778
    TAOS_RETURN(TSDB_CODE_INVALID_PARA);
×
779
  }
780

781
  // do add column
782
  int32_t         rowSize = 0;
147✔
783
  SSchemaWrapper *pSchema = &pEntry->ntbEntry.schemaRow;
147✔
784
  SSchema        *pColumn;
785
  SExtSchema      extSchema = {0};
147✔
786
  pEntry->version = version;
147✔
787
  for (int32_t i = 0; i < pSchema->nCols; i++) {
1,108✔
788
    pColumn = &pSchema->pSchema[i];
961✔
789
    if (strncmp(pColumn->name, pReq->colName, TSDB_COL_NAME_LEN) == 0) {
961!
UNCOV
790
      metaError("vgId:%d, %s failed at %s:%d since column %s already exists in table %s, version:%" PRId64,
×
791
                TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->colName, pReq->tbName, version);
UNCOV
792
      metaFetchEntryFree(&pEntry);
×
793
      TAOS_RETURN(TSDB_CODE_VND_COL_ALREADY_EXISTS);
×
794
    }
795
    rowSize += pColumn->bytes;
961✔
796
  }
797

798
  if (rowSize + pReq->bytes > TSDB_MAX_BYTES_PER_ROW) {
147!
UNCOV
799
    metaError("vgId:%d, %s failed at %s:%d since row size %d + %d > %d, version:%" PRId64, TD_VID(pMeta->pVnode),
×
800
              __func__, __FILE__, __LINE__, rowSize, pReq->bytes, TSDB_MAX_BYTES_PER_ROW, version);
UNCOV
801
    metaFetchEntryFree(&pEntry);
×
UNCOV
802
    TAOS_RETURN(TSDB_CODE_PAR_INVALID_ROW_LENGTH);
×
803
  }
804

805
  SSchema *pNewSchema = taosMemoryRealloc(pSchema->pSchema, sizeof(SSchema) * (pSchema->nCols + 1));
147!
806
  if (NULL == pNewSchema) {
147!
UNCOV
807
    metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
808
              __LINE__, tstrerror(terrno), version);
UNCOV
809
    metaFetchEntryFree(&pEntry);
×
UNCOV
810
    TAOS_RETURN(terrno);
×
811
  }
812
  pSchema->pSchema = pNewSchema;
147✔
813
  pSchema->version++;
147✔
814
  pSchema->nCols++;
147✔
815
  pColumn = &pSchema->pSchema[pSchema->nCols - 1];
147✔
816
  pColumn->bytes = pReq->bytes;
147✔
817
  pColumn->type = pReq->type;
147✔
818
  pColumn->flags = pReq->flags;
147✔
819
  pColumn->colId = pEntry->ntbEntry.ncid++;
147✔
820
  extSchema.typeMod = pReq->typeMod;
147✔
821
  tstrncpy(pColumn->name, pReq->colName, TSDB_COL_NAME_LEN);
147✔
822
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
147!
823
    SColRef tmpRef;
UNCOV
824
    if (TSDB_ALTER_TABLE_ADD_COLUMN == pReq->action) {
×
UNCOV
825
      tmpRef.hasRef = false;
×
826
      tmpRef.id = pColumn->colId;
×
827
    } else {
828
      tmpRef.hasRef = true;
×
UNCOV
829
      tmpRef.id = pColumn->colId;
×
UNCOV
830
      tstrncpy(tmpRef.refDbName, pReq->refDbName, TSDB_DB_NAME_LEN);
×
UNCOV
831
      tstrncpy(tmpRef.refTableName, pReq->refTbName, TSDB_TABLE_NAME_LEN);
×
832
      tstrncpy(tmpRef.refColName, pReq->refColName, TSDB_COL_NAME_LEN);
×
833
    }
834
    code = updataTableColRef(&pEntry->colRef, pColumn, 1, &tmpRef);
×
835
    if (code) {
×
UNCOV
836
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
837
                __LINE__, tstrerror(code), version);
UNCOV
838
      metaFetchEntryFree(&pEntry);
×
UNCOV
839
      TAOS_RETURN(code);
×
840
    }
841
  } else {
842
    uint32_t compress;
843
    if (TSDB_ALTER_TABLE_ADD_COLUMN == pReq->action) {
147✔
844
      compress = createDefaultColCmprByType(pColumn->type);
118✔
845
    } else {
846
      compress = pReq->compress;
29✔
847
    }
848
    code = updataTableColCmpr(&pEntry->colCmpr, pColumn, 1, compress);
147✔
849
    if (code) {
147!
UNCOV
850
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
851
                __LINE__, tstrerror(code), version);
UNCOV
852
      metaFetchEntryFree(&pEntry);
×
853
      TAOS_RETURN(code);
×
854
    }
855
  }
856
  code = addTableExtSchema(pEntry, pColumn, pSchema->nCols, &extSchema);
147✔
857
  if (code) {
147!
UNCOV
858
    metaError("vgId:%d, %s failed to add ext schema at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode),
×
859
              __func__, __FILE__, __LINE__, tstrerror(code), version);
UNCOV
860
    metaFetchEntryFree(&pEntry);
×
UNCOV
861
    TAOS_RETURN(code);
×
862
  }
863

864
  // do handle entry
865
  code = metaHandleEntry2(pMeta, pEntry);
147✔
866
  if (code) {
147!
UNCOV
867
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
868
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
UNCOV
869
    metaFetchEntryFree(&pEntry);
×
UNCOV
870
    TAOS_RETURN(code);
×
871
  } else {
872
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
147!
873
             pEntry->uid, version);
874
  }
875

876
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
147!
UNCOV
877
    if (metaUpdateVtbMetaRsp(pEntry->uid, pReq->tbName, pSchema, &pEntry->colRef, pRsp, pEntry->type) < 0) {
×
UNCOV
878
      metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
879
                __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
880
    } else {
UNCOV
881
      for (int32_t i = 0; i < pEntry->colRef.nCols; i++) {
×
UNCOV
882
        SColRef *p = &pEntry->colRef.pColRef[i];
×
883
        pRsp->pColRefs[i].hasRef = p->hasRef;
×
UNCOV
884
        pRsp->pColRefs[i].id = p->id;
×
UNCOV
885
        if (p->hasRef) {
×
UNCOV
886
          tstrncpy(pRsp->pColRefs[i].refDbName, p->refDbName, TSDB_DB_NAME_LEN);
×
UNCOV
887
          tstrncpy(pRsp->pColRefs[i].refTableName, p->refTableName, TSDB_TABLE_NAME_LEN);
×
UNCOV
888
          tstrncpy(pRsp->pColRefs[i].refColName, p->refColName, TSDB_COL_NAME_LEN);
×
889
        }
890
      }
891
    }
892
  } else {
893
    if (metaUpdateMetaRsp(pEntry->uid, pReq->tbName, pSchema, pRsp) < 0) {
147!
UNCOV
894
      metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
895
                __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
896
    } else {
897
      for (int32_t i = 0; i < pEntry->colCmpr.nCols; i++) {
1,255✔
898
        SColCmpr *p = &pEntry->colCmpr.pColCmpr[i];
1,108✔
899
        pRsp->pSchemaExt[i].colId = p->id;
1,108✔
900
        pRsp->pSchemaExt[i].compress = p->alg;
1,108✔
901
      }
902
    }
903
  }
904

905
  metaFetchEntryFree(&pEntry);
147✔
906
  TAOS_RETURN(code);
147✔
907
}
908

909
int32_t metaDropTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp) {
117✔
910
  int32_t code = TSDB_CODE_SUCCESS;
117✔
911

912
  // check request
913
  code = metaCheckAlterTableColumnReq(pMeta, version, pReq);
117✔
914
  if (code) {
117!
UNCOV
915
    TAOS_RETURN(code);
×
916
  }
917

918
  // fetch old entry
919
  SMetaEntry *pEntry = NULL;
117✔
920
  code = metaFetchEntryByName(pMeta, pReq->tbName, &pEntry);
117✔
921
  if (code) {
117!
UNCOV
922
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
923
              __FILE__, __LINE__, pReq->tbName, version);
UNCOV
924
    TAOS_RETURN(code);
×
925
  }
926

927
  if (pEntry->version >= version) {
117!
UNCOV
928
    metaError("vgId:%d, %s failed at %s:%d since table %s version %" PRId64 " is not less than %" PRId64,
×
929
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, pEntry->version, version);
UNCOV
930
    metaFetchEntryFree(&pEntry);
×
UNCOV
931
    TAOS_RETURN(TSDB_CODE_INVALID_PARA);
×
932
  }
933

934
  // search the column to drop
935
  SSchemaWrapper *pSchema = &pEntry->ntbEntry.schemaRow;
117✔
936
  SSchema        *pColumn = NULL;
117✔
937
  SSchema         tColumn;
938
  int32_t         iColumn = 0;
117✔
939
  for (; iColumn < pSchema->nCols; iColumn++) {
639!
940
    pColumn = &pSchema->pSchema[iColumn];
639✔
941
    if (strncmp(pColumn->name, pReq->colName, TSDB_COL_NAME_LEN) == 0) {
639✔
942
      break;
117✔
943
    }
944
  }
945

946
  if (iColumn == pSchema->nCols) {
117!
947
    metaError("vgId:%d, %s failed at %s:%d since column %s not found in table %s, version:%" PRId64,
×
948
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->colName, pReq->tbName, version);
UNCOV
949
    metaFetchEntryFree(&pEntry);
×
UNCOV
950
    TAOS_RETURN(TSDB_CODE_VND_COL_NOT_EXISTS);
×
951
  }
952

953
  if (pColumn->colId == 0 || pColumn->flags & COL_IS_KEY) {
117!
UNCOV
954
    metaError("vgId:%d, %s failed at %s:%d since column %s is primary key, version:%" PRId64, TD_VID(pMeta->pVnode),
×
955
              __func__, __FILE__, __LINE__, pReq->colName, version);
UNCOV
956
    metaFetchEntryFree(&pEntry);
×
UNCOV
957
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
958
  }
959

960
  if (tqCheckColModifiable(pMeta->pVnode->pTq, pEntry->uid, pColumn->colId) != 0) {
117✔
961
    metaError("vgId:%d, %s failed at %s:%d since column %s is not modifiable, version:%" PRId64, TD_VID(pMeta->pVnode),
11!
962
              __func__, __FILE__, __LINE__, pReq->colName, version);
963
    metaFetchEntryFree(&pEntry);
11✔
964
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
11✔
965
  }
966
  tColumn = *pColumn;
106✔
967

968
  // do drop column
969
  pEntry->version = version;
106✔
970
  if (pSchema->nCols - iColumn - 1 > 0) {
106✔
971
    memmove(pColumn, pColumn + 1, (pSchema->nCols - iColumn - 1) * sizeof(SSchema));
70✔
972
  }
973
  pSchema->nCols--;
106✔
974
  pSchema->version++;
106✔
975
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
106!
976
    code = updataTableColRef(&pEntry->colRef, &tColumn, 0, NULL);
×
UNCOV
977
    if (code) {
×
UNCOV
978
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
979
                __LINE__, tstrerror(code), version);
UNCOV
980
      metaFetchEntryFree(&pEntry);
×
UNCOV
981
      TAOS_RETURN(code);
×
982
    }
UNCOV
983
    if (pEntry->colRef.nCols != pSchema->nCols) {
×
984
      metaError("vgId:%d, %s failed at %s:%d since column count mismatch, version:%" PRId64, TD_VID(pMeta->pVnode),
×
985
                __func__, __FILE__, __LINE__, version);
UNCOV
986
      metaFetchEntryFree(&pEntry);
×
UNCOV
987
      TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
988
    }
989
  } else {
990
    code = updataTableColCmpr(&pEntry->colCmpr, &tColumn, 0, 0);
106✔
991
    if (code) {
106!
UNCOV
992
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
993
                __LINE__, tstrerror(code), version);
UNCOV
994
      metaFetchEntryFree(&pEntry);
×
UNCOV
995
      TAOS_RETURN(code);
×
996
    }
997
    if (pEntry->colCmpr.nCols != pSchema->nCols) {
106!
UNCOV
998
      metaError("vgId:%d, %s failed at %s:%d since column count mismatch, version:%" PRId64, TD_VID(pMeta->pVnode),
×
999
                __func__, __FILE__, __LINE__, version);
UNCOV
1000
      metaFetchEntryFree(&pEntry);
×
UNCOV
1001
      TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
1002
    }
1003
  }
1004

1005
  // update column extschema
1006
  code = dropTableExtSchema(pEntry, iColumn, pSchema->nCols);
106✔
1007
  if (code) {
106!
UNCOV
1008
    metaError("vgId:%d, %s failed to remove extschema at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1009
              __func__, __FILE__, __LINE__, tstrerror(code), version);
UNCOV
1010
    metaFetchEntryFree(&pEntry);
×
UNCOV
1011
    TAOS_RETURN(code);
×
1012
  }
1013

1014
  // do handle entry
1015
  code = metaHandleEntry2(pMeta, pEntry);
106✔
1016
  if (code) {
106!
UNCOV
1017
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1018
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
UNCOV
1019
    metaFetchEntryFree(&pEntry);
×
1020
  } else {
1021
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
106!
1022
             pEntry->uid, version);
1023
  }
1024

1025
  // build response
1026
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
106!
UNCOV
1027
    if (metaUpdateVtbMetaRsp(pEntry->uid, pReq->tbName, pSchema, &pEntry->colRef, pRsp, pEntry->type) < 0) {
×
UNCOV
1028
      metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1029
                __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
1030
    } else {
UNCOV
1031
      for (int32_t i = 0; i < pEntry->colRef.nCols; i++) {
×
UNCOV
1032
        SColRef *p = &pEntry->colRef.pColRef[i];
×
UNCOV
1033
        pRsp->pColRefs[i].hasRef = p->hasRef;
×
UNCOV
1034
        pRsp->pColRefs[i].id = p->id;
×
UNCOV
1035
        if (p->hasRef) {
×
1036
          tstrncpy(pRsp->pColRefs[i].refDbName, p->refDbName, TSDB_DB_NAME_LEN);
×
UNCOV
1037
          tstrncpy(pRsp->pColRefs[i].refTableName, p->refTableName, TSDB_TABLE_NAME_LEN);
×
1038
          tstrncpy(pRsp->pColRefs[i].refColName, p->refColName, TSDB_COL_NAME_LEN);
×
1039
        }
1040
      }
1041
    }
1042
  } else {
1043
    if (metaUpdateMetaRsp(pEntry->uid, pReq->tbName, pSchema, pRsp) < 0) {
106!
1044
      metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1045
                __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
1046
    } else {
1047
      for (int32_t i = 0; i < pEntry->colCmpr.nCols; i++) {
812✔
1048
        SColCmpr *p = &pEntry->colCmpr.pColCmpr[i];
706✔
1049
        pRsp->pSchemaExt[i].colId = p->id;
706✔
1050
        pRsp->pSchemaExt[i].compress = p->alg;
706✔
1051
      }
1052
    }
1053
  }
1054

1055
  metaFetchEntryFree(&pEntry);
106✔
1056
  TAOS_RETURN(code);
106✔
1057
}
1058

1059
int32_t metaAlterTableColumnName(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp) {
32✔
1060
  int32_t code = TSDB_CODE_SUCCESS;
32✔
1061

1062
  // check request
1063
  code = metaCheckAlterTableColumnReq(pMeta, version, pReq);
32✔
1064
  if (code) {
32!
UNCOV
1065
    TAOS_RETURN(code);
×
1066
  }
1067

1068
  if (NULL == pReq->colNewName) {
32!
UNCOV
1069
    metaError("vgId:%d, %s failed at %s:%d since invalid new column name, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1070
              __func__, __FILE__, __LINE__, version);
1071
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
1072
  }
1073

1074
  // fetch old entry
1075
  SMetaEntry *pEntry = NULL;
32✔
1076
  code = metaFetchEntryByName(pMeta, pReq->tbName, &pEntry);
32✔
1077
  if (code) {
32!
UNCOV
1078
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1079
              __FILE__, __LINE__, pReq->tbName, version);
UNCOV
1080
    TAOS_RETURN(code);
×
1081
  }
1082

1083
  if (pEntry->version >= version) {
32!
UNCOV
1084
    metaError("vgId:%d, %s failed at %s:%d since table %s version %" PRId64 " is not less than %" PRId64,
×
1085
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, pEntry->version, version);
1086
    metaFetchEntryFree(&pEntry);
×
1087
    TAOS_RETURN(TSDB_CODE_INVALID_PARA);
×
1088
  }
1089

1090
  // search the column to update
1091
  SSchemaWrapper *pSchema = &pEntry->ntbEntry.schemaRow;
32✔
1092
  SSchema        *pColumn = NULL;
32✔
1093
  int32_t         iColumn = 0;
32✔
1094
  for (int32_t i = 0; i < pSchema->nCols; i++) {
126!
1095
    if (strncmp(pSchema->pSchema[i].name, pReq->colName, TSDB_COL_NAME_LEN) == 0) {
126✔
1096
      pColumn = &pSchema->pSchema[i];
32✔
1097
      iColumn = i;
32✔
1098
      break;
32✔
1099
    }
1100
  }
1101

1102
  if (NULL == pColumn) {
32!
UNCOV
1103
    metaError("vgId:%d, %s failed at %s:%d since column id %d not found in table %s, version:%" PRId64,
×
1104
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->colId, pReq->tbName, version);
UNCOV
1105
    metaFetchEntryFree(&pEntry);
×
UNCOV
1106
    TAOS_RETURN(TSDB_CODE_VND_COL_NOT_EXISTS);
×
1107
  }
1108

1109
  if (tqCheckColModifiable(pMeta->pVnode->pTq, pEntry->uid, pColumn->colId) != 0) {
32✔
1110
    metaError("vgId:%d, %s failed at %s:%d since column %s is not modifiable, version:%" PRId64, TD_VID(pMeta->pVnode),
11!
1111
              __func__, __FILE__, __LINE__, pColumn->name, version);
1112
    metaFetchEntryFree(&pEntry);
11✔
1113
    TAOS_RETURN(TSDB_CODE_VND_COL_SUBSCRIBED);
11✔
1114
  }
1115

1116
  // do update column name
1117
  pEntry->version = version;
21✔
1118
  tstrncpy(pColumn->name, pReq->colNewName, TSDB_COL_NAME_LEN);
21✔
1119
  pSchema->version++;
21✔
1120

1121
  // do handle entry
1122
  code = metaHandleEntry2(pMeta, pEntry);
21✔
1123
  if (code) {
21!
1124
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1125
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
1126
    metaFetchEntryFree(&pEntry);
×
1127
    TAOS_RETURN(code);
×
1128
  } else {
1129
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
21!
1130
             pEntry->uid, version);
1131
  }
1132

1133
  // build response
1134
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
21!
UNCOV
1135
    if (metaUpdateVtbMetaRsp(pEntry->uid, pReq->tbName, pSchema, &pEntry->colRef, pRsp, pEntry->type) < 0) {
×
1136
      metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1137
                __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
1138
    } else {
1139
      for (int32_t i = 0; i < pEntry->colRef.nCols; i++) {
×
1140
        SColRef *p = &pEntry->colRef.pColRef[i];
×
1141
        pRsp->pColRefs[i].hasRef = p->hasRef;
×
UNCOV
1142
        pRsp->pColRefs[i].id = p->id;
×
UNCOV
1143
        if (p->hasRef) {
×
UNCOV
1144
          tstrncpy(pRsp->pColRefs[i].refDbName, p->refDbName, TSDB_DB_NAME_LEN);
×
UNCOV
1145
          tstrncpy(pRsp->pColRefs[i].refTableName, p->refTableName, TSDB_TABLE_NAME_LEN);
×
UNCOV
1146
          tstrncpy(pRsp->pColRefs[i].refColName, p->refColName, TSDB_COL_NAME_LEN);
×
1147
        }
1148
      }
1149
    }
1150
  } else {
1151
    if (metaUpdateMetaRsp(pEntry->uid, pReq->tbName, pSchema, pRsp) < 0) {
21!
UNCOV
1152
      metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1153
                __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
1154
    } else {
1155
      for (int32_t i = 0; i < pEntry->colCmpr.nCols; i++) {
121✔
1156
        SColCmpr *p = &pEntry->colCmpr.pColCmpr[i];
100✔
1157
        pRsp->pSchemaExt[i].colId = p->id;
100✔
1158
        pRsp->pSchemaExt[i].compress = p->alg;
100✔
1159
      }
1160
    }
1161
  }
1162

1163
  metaFetchEntryFree(&pEntry);
21✔
1164
  TAOS_RETURN(code);
21✔
1165
}
1166

1167
int32_t metaAlterTableColumnBytes(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp) {
42✔
1168
  int32_t code = TSDB_CODE_SUCCESS;
42✔
1169

1170
  // check request
1171
  code = metaCheckAlterTableColumnReq(pMeta, version, pReq);
42✔
1172
  if (code) {
42!
UNCOV
1173
    TAOS_RETURN(code);
×
1174
  }
1175

1176
  // fetch old entry
1177
  SMetaEntry *pEntry = NULL;
42✔
1178
  code = metaFetchEntryByName(pMeta, pReq->tbName, &pEntry);
42✔
1179
  if (code) {
42!
UNCOV
1180
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1181
              __FILE__, __LINE__, pReq->tbName, version);
1182
    TAOS_RETURN(code);
×
1183
  }
1184

1185
  if (pEntry->version >= version) {
42!
UNCOV
1186
    metaError("vgId:%d, %s failed at %s:%d since table %s version %" PRId64 " is not less than %" PRId64,
×
1187
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, pEntry->version, version);
UNCOV
1188
    metaFetchEntryFree(&pEntry);
×
UNCOV
1189
    TAOS_RETURN(TSDB_CODE_INVALID_PARA);
×
1190
  }
1191

1192
  // search the column to update
1193
  SSchemaWrapper *pSchema = &pEntry->ntbEntry.schemaRow;
42✔
1194
  SSchema        *pColumn = NULL;
42✔
1195
  int32_t         iColumn = 0;
42✔
1196
  int32_t         rowSize = 0;
42✔
1197
  for (int32_t i = 0; i < pSchema->nCols; i++) {
200✔
1198
    if (strncmp(pSchema->pSchema[i].name, pReq->colName, TSDB_COL_NAME_LEN) == 0) {
158✔
1199
      pColumn = &pSchema->pSchema[i];
42✔
1200
      iColumn = i;
42✔
1201
    }
1202
    rowSize += pSchema->pSchema[i].bytes;
158✔
1203
  }
1204

1205
  if (NULL == pColumn) {
42!
UNCOV
1206
    metaError("vgId:%d, %s failed at %s:%d since column %s not found in table %s, version:%" PRId64,
×
1207
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->colName, pReq->tbName, version);
UNCOV
1208
    metaFetchEntryFree(&pEntry);
×
UNCOV
1209
    TAOS_RETURN(TSDB_CODE_VND_COL_NOT_EXISTS);
×
1210
  }
1211

1212
  if (!IS_VAR_DATA_TYPE(pColumn->type) || pColumn->bytes >= pReq->colModBytes) {
42!
UNCOV
1213
    metaError("vgId:%d, %s failed at %s:%d since column %s is not var data type or bytes %d >= %d, version:%" PRId64,
×
1214
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->colName, pColumn->bytes, pReq->colModBytes,
1215
              version);
1216
    metaFetchEntryFree(&pEntry);
×
UNCOV
1217
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
1218
  }
1219

1220
  if (tqCheckColModifiable(pMeta->pVnode->pTq, pEntry->uid, pColumn->colId) != 0) {
42✔
1221
    metaError("vgId:%d, %s failed at %s:%d since column %s is not modifiable, version:%" PRId64, TD_VID(pMeta->pVnode),
13!
1222
              __func__, __FILE__, __LINE__, pReq->colName, version);
1223
    metaFetchEntryFree(&pEntry);
13✔
1224
    TAOS_RETURN(TSDB_CODE_VND_COL_SUBSCRIBED);
13✔
1225
  }
1226

1227
  if (rowSize + pReq->colModBytes - pColumn->bytes > TSDB_MAX_BYTES_PER_ROW) {
29!
1228
    metaError("vgId:%d, %s failed at %s:%d since row size %d + %d - %d > %d, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1229
              __func__, __FILE__, __LINE__, rowSize, pReq->colModBytes, pColumn->bytes, TSDB_MAX_BYTES_PER_ROW,
1230
              version);
UNCOV
1231
    metaFetchEntryFree(&pEntry);
×
UNCOV
1232
    TAOS_RETURN(TSDB_CODE_PAR_INVALID_ROW_LENGTH);
×
1233
  }
1234

1235
  // do change the column bytes
1236
  pEntry->version = version;
29✔
1237
  pSchema->version++;
29✔
1238
  pColumn->bytes = pReq->colModBytes;
29✔
1239

1240
  // do handle entry
1241
  code = metaHandleEntry2(pMeta, pEntry);
29✔
1242
  if (code) {
29!
UNCOV
1243
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1244
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
UNCOV
1245
    metaFetchEntryFree(&pEntry);
×
UNCOV
1246
    TAOS_RETURN(code);
×
1247
  } else {
1248
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
29!
1249
             pEntry->uid, version);
1250
  }
1251

1252
  // build response
1253
  if (pEntry->type == TSDB_VIRTUAL_NORMAL_TABLE) {
29!
UNCOV
1254
    if (metaUpdateVtbMetaRsp(pEntry->uid, pReq->tbName, pSchema, &pEntry->colRef, pRsp, pEntry->type) < 0) {
×
UNCOV
1255
      metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1256
                __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
1257
    } else {
UNCOV
1258
      for (int32_t i = 0; i < pEntry->colRef.nCols; i++) {
×
1259
        SColRef *p = &pEntry->colRef.pColRef[i];
×
1260
        pRsp->pColRefs[i].hasRef = p->hasRef;
×
1261
        pRsp->pColRefs[i].id = p->id;
×
1262
        if (p->hasRef) {
×
UNCOV
1263
          tstrncpy(pRsp->pColRefs[i].refDbName, p->refDbName, TSDB_DB_NAME_LEN);
×
UNCOV
1264
          tstrncpy(pRsp->pColRefs[i].refTableName, p->refTableName, TSDB_TABLE_NAME_LEN);
×
UNCOV
1265
          tstrncpy(pRsp->pColRefs[i].refColName, p->refColName, TSDB_COL_NAME_LEN);
×
1266
        }
1267
      }
1268
    }
1269
  } else {
1270
    if (metaUpdateMetaRsp(pEntry->uid, pReq->tbName, pSchema, pRsp) < 0) {
29!
UNCOV
1271
      metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1272
                __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
1273
    } else {
1274
      for (int32_t i = 0; i < pEntry->colCmpr.nCols; i++) {
137✔
1275
        SColCmpr *p = &pEntry->colCmpr.pColCmpr[i];
108✔
1276
        pRsp->pSchemaExt[i].colId = p->id;
108✔
1277
        pRsp->pSchemaExt[i].compress = p->alg;
108✔
1278
      }
1279
    }
1280
  }
1281

1282
  metaFetchEntryFree(&pEntry);
29✔
1283
  TAOS_RETURN(code);
29✔
1284
}
1285

1286
static int32_t metaCheckUpdateTableTagValReq(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
656✔
1287
  int32_t code = 0;
656✔
1288

1289
  // check tag name
1290
  if (NULL == pReq->tagName || strlen(pReq->tagName) == 0) {
656!
1291
    metaError("vgId:%d, %s failed at %s:%d since invalid tag name:%s, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1292
              __func__, __FILE__, __LINE__, pReq->tagName, version);
UNCOV
1293
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
1294
  }
1295

1296
  // check name
1297
  void   *value = NULL;
656✔
1298
  int32_t valueSize = 0;
656✔
1299
  code = tdbTbGet(pMeta->pNameIdx, pReq->tbName, strlen(pReq->tbName) + 1, &value, &valueSize);
656✔
1300
  if (code) {
656✔
1301
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
1!
1302
              __FILE__, __LINE__, pReq->tbName, version);
1303
    code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
1✔
1304
    TAOS_RETURN(code);
1✔
1305
  }
1306
  tdbFreeClear(value);
655✔
1307

1308
  TAOS_RETURN(code);
655✔
1309
}
1310

1311
int32_t metaUpdateTableTagValue(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
656✔
1312
  int32_t code = TSDB_CODE_SUCCESS;
656✔
1313

1314
  // check request
1315
  code = metaCheckUpdateTableTagValReq(pMeta, version, pReq);
656✔
1316
  if (code) {
656✔
1317
    TAOS_RETURN(code);
1✔
1318
  }
1319

1320
  // fetch child entry
1321
  SMetaEntry *pChild = NULL;
655✔
1322
  code = metaFetchEntryByName(pMeta, pReq->tbName, &pChild);
655✔
1323
  if (code) {
655!
1324
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1325
              __FILE__, __LINE__, pReq->tbName, version);
1326
    TAOS_RETURN(code);
×
1327
  }
1328

1329
  if (pChild->type != TSDB_CHILD_TABLE && pChild->type != TSDB_VIRTUAL_CHILD_TABLE) {
655!
UNCOV
1330
    metaError("vgId:%d, %s failed at %s:%d since table %s is not a child table, version:%" PRId64,
×
1331
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, version);
UNCOV
1332
    metaFetchEntryFree(&pChild);
×
1333
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
1334
  }
1335

1336
  // fetch super entry
1337
  SMetaEntry *pSuper = NULL;
655✔
1338
  code = metaFetchEntryByUid(pMeta, pChild->ctbEntry.suid, &pSuper);
655✔
1339
  if (code) {
655!
UNCOV
1340
    metaError("vgId:%d, %s failed at %s:%d since super table uid %" PRId64 " not found, version:%" PRId64,
×
1341
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pChild->ctbEntry.suid, version);
UNCOV
1342
    metaFetchEntryFree(&pChild);
×
UNCOV
1343
    TAOS_RETURN(TSDB_CODE_INTERNAL_ERROR);
×
1344
  }
1345

1346
  // search the tag to update
1347
  SSchemaWrapper *pTagSchema = &pSuper->stbEntry.schemaTag;
655✔
1348
  SSchema        *pColumn = NULL;
655✔
1349
  int32_t         iColumn = 0;
655✔
1350
  for (int32_t i = 0; i < pTagSchema->nCols; i++) {
1,549!
1351
    if (strncmp(pTagSchema->pSchema[i].name, pReq->tagName, TSDB_COL_NAME_LEN) == 0) {
1,549✔
1352
      pColumn = &pTagSchema->pSchema[i];
655✔
1353
      iColumn = i;
655✔
1354
      break;
655✔
1355
    }
1356
  }
1357

1358
  if (NULL == pColumn) {
655!
UNCOV
1359
    metaError("vgId:%d, %s failed at %s:%d since tag %s not found in table %s, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1360
              __func__, __FILE__, __LINE__, pReq->tagName, pReq->tbName, version);
UNCOV
1361
    metaFetchEntryFree(&pChild);
×
UNCOV
1362
    metaFetchEntryFree(&pSuper);
×
UNCOV
1363
    TAOS_RETURN(TSDB_CODE_VND_COL_NOT_EXISTS);
×
1364
  }
1365

1366
  // do change tag value
1367
  pChild->version = version;
655✔
1368
  if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
655✔
1369
    void *pNewTag = taosMemoryRealloc(pChild->ctbEntry.pTags, pReq->nTagVal);
20!
1370
    if (NULL == pNewTag) {
20!
1371
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1372
                __LINE__, tstrerror(terrno), version);
UNCOV
1373
      metaFetchEntryFree(&pChild);
×
UNCOV
1374
      metaFetchEntryFree(&pSuper);
×
UNCOV
1375
      TAOS_RETURN(terrno);
×
1376
    }
1377
    pChild->ctbEntry.pTags = pNewTag;
20✔
1378
    memcpy(pChild->ctbEntry.pTags, pReq->pTagVal, pReq->nTagVal);
20✔
1379
  } else {
1380
    STag *pOldTag = (STag *)pChild->ctbEntry.pTags;
635✔
1381

1382
    SArray *pTagArray = taosArrayInit(pTagSchema->nCols, sizeof(STagVal));
635✔
1383
    if (NULL == pTagArray) {
635!
UNCOV
1384
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1385
                __LINE__, tstrerror(terrno), version);
UNCOV
1386
      metaFetchEntryFree(&pChild);
×
UNCOV
1387
      metaFetchEntryFree(&pSuper);
×
UNCOV
1388
      TAOS_RETURN(terrno);
×
1389
    }
1390

1391
    for (int32_t i = 0; i < pTagSchema->nCols; i++) {
2,701✔
1392
      STagVal value = {
2,066✔
1393
          .type = pTagSchema->pSchema[i].type,
2,066✔
1394
          .cid = pTagSchema->pSchema[i].colId,
2,066✔
1395
      };
1396

1397
      if (iColumn == i) {
2,066✔
1398
        if (pReq->isNull) {
635✔
1399
          continue;
412✔
1400
        }
1401
        if (IS_VAR_DATA_TYPE(value.type)) {
588!
1402
          value.pData = pReq->pTagVal;
204✔
1403
          value.nData = pReq->nTagVal;
204✔
1404
        } else {
1405
          memcpy(&value.i64, pReq->pTagVal, pReq->nTagVal);
384✔
1406
        }
1407
      } else if (!tTagGet(pOldTag, &value)) {
1,431✔
1408
        continue;
365✔
1409
      }
1410

1411
      if (NULL == taosArrayPush(pTagArray, &value)) {
1,654!
UNCOV
1412
        metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1413
                  __LINE__, tstrerror(terrno), version);
UNCOV
1414
        taosArrayDestroy(pTagArray);
×
UNCOV
1415
        metaFetchEntryFree(&pChild);
×
UNCOV
1416
        metaFetchEntryFree(&pSuper);
×
UNCOV
1417
        TAOS_RETURN(terrno);
×
1418
      }
1419
    }
1420

1421
    STag *pNewTag = NULL;
635✔
1422
    code = tTagNew(pTagArray, pTagSchema->version, false, &pNewTag);
635✔
1423
    if (code) {
635!
UNCOV
1424
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1425
                __LINE__, tstrerror(code), version);
1426
      taosArrayDestroy(pTagArray);
×
UNCOV
1427
      metaFetchEntryFree(&pChild);
×
1428
      metaFetchEntryFree(&pSuper);
×
1429
      TAOS_RETURN(code);
×
1430
    }
1431
    taosArrayDestroy(pTagArray);
635✔
1432
    taosMemoryFree(pChild->ctbEntry.pTags);
635!
1433
    pChild->ctbEntry.pTags = (uint8_t *)pNewTag;
635✔
1434
  }
1435

1436
  // do handle entry
1437
  code = metaHandleEntry2(pMeta, pChild);
655✔
1438
  if (code) {
655!
1439
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1440
              __func__, __FILE__, __LINE__, tstrerror(code), pChild->uid, pReq->tbName, version);
1441
    metaFetchEntryFree(&pChild);
×
1442
    metaFetchEntryFree(&pSuper);
×
UNCOV
1443
    TAOS_RETURN(code);
×
1444
  } else {
1445
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
655!
1446
             pChild->uid, version);
1447
  }
1448

1449
  // free resource and return
1450
  metaFetchEntryFree(&pChild);
655✔
1451
  metaFetchEntryFree(&pSuper);
655✔
1452
  TAOS_RETURN(code);
655✔
1453
}
1454

1455
static int32_t metaCheckUpdateTableMultiTagValueReq(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
5✔
1456
  int32_t code = 0;
5✔
1457

1458
  // check tag name
1459
  if (NULL == pReq->pMultiTag || taosArrayGetSize(pReq->pMultiTag) == 0) {
5!
UNCOV
1460
    metaError("vgId:%d, %s failed at %s:%d since invalid tag name, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1461
              __FILE__, __LINE__, version);
UNCOV
1462
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
1463
  }
1464

1465
  // check name
1466
  void   *value = NULL;
5✔
1467
  int32_t valueSize = 0;
5✔
1468
  code = tdbTbGet(pMeta->pNameIdx, pReq->tbName, strlen(pReq->tbName) + 1, &value, &valueSize);
5✔
1469
  if (code) {
5!
UNCOV
1470
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1471
              __FILE__, __LINE__, pReq->tbName, version);
UNCOV
1472
    code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
×
1473
    TAOS_RETURN(code);
×
1474
  }
1475
  tdbFreeClear(value);
5✔
1476

1477
  if (taosArrayGetSize(pReq->pMultiTag) == 0) {
5!
UNCOV
1478
    metaError("vgId:%d, %s failed at %s:%d since invalid tag name, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1479
              __FILE__, __LINE__, version);
UNCOV
1480
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
1481
  }
1482

1483
  TAOS_RETURN(code);
5✔
1484
}
1485

1486
int32_t metaUpdateTableMultiTagValue(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
5✔
1487
  int32_t code = TSDB_CODE_SUCCESS;
5✔
1488

1489
  code = metaCheckUpdateTableMultiTagValueReq(pMeta, version, pReq);
5✔
1490
  if (code) {
5!
UNCOV
1491
    TAOS_RETURN(code);
×
1492
  }
1493

1494
  // fetch child entry
1495
  SMetaEntry *pChild = NULL;
5✔
1496
  code = metaFetchEntryByName(pMeta, pReq->tbName, &pChild);
5✔
1497
  if (code) {
5!
UNCOV
1498
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1499
              __FILE__, __LINE__, pReq->tbName, version);
UNCOV
1500
    TAOS_RETURN(code);
×
1501
  }
1502

1503
  if (pChild->type != TSDB_CHILD_TABLE) {
5!
UNCOV
1504
    metaError("vgId:%d, %s failed at %s:%d since table %s is not a child table, version:%" PRId64,
×
1505
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, version);
UNCOV
1506
    metaFetchEntryFree(&pChild);
×
UNCOV
1507
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
1508
  }
1509

1510
  // fetch super entry
1511
  SMetaEntry *pSuper = NULL;
5✔
1512
  code = metaFetchEntryByUid(pMeta, pChild->ctbEntry.suid, &pSuper);
5✔
1513
  if (code) {
5!
1514
    metaError("vgId:%d, %s failed at %s:%d since super table uid %" PRId64 " not found, version:%" PRId64,
×
1515
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pChild->ctbEntry.suid, version);
UNCOV
1516
    metaFetchEntryFree(&pChild);
×
1517
    TAOS_RETURN(TSDB_CODE_INTERNAL_ERROR);
×
1518
  }
1519

1520
  // search the tags to update
1521
  SSchemaWrapper *pTagSchema = &pSuper->stbEntry.schemaTag;
5✔
1522

1523
  if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
5!
UNCOV
1524
    metaError("vgId:%d, %s failed at %s:%d since table %s has no tag, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1525
              __func__, __FILE__, __LINE__, pReq->tbName, version);
1526
    metaFetchEntryFree(&pChild);
×
UNCOV
1527
    metaFetchEntryFree(&pSuper);
×
1528
    TAOS_RETURN(TSDB_CODE_VND_COL_NOT_EXISTS);
×
1529
  }
1530

1531
  // do check if tag name exists
1532
  SHashObj *pTagTable =
1533
      taosHashInit(pTagSchema->nCols, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
5✔
1534
  if (pTagTable == NULL) {
5!
UNCOV
1535
    metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1536
              __LINE__, tstrerror(terrno), version);
UNCOV
1537
    metaFetchEntryFree(&pChild);
×
UNCOV
1538
    metaFetchEntryFree(&pSuper);
×
UNCOV
1539
    TAOS_RETURN(terrno);
×
1540
  }
1541

1542
  for (int32_t i = 0; i < taosArrayGetSize(pReq->pMultiTag); i++) {
35✔
1543
    SMultiTagUpateVal *pTagVal = taosArrayGet(pReq->pMultiTag, i);
30✔
1544
    if (taosHashPut(pTagTable, pTagVal->tagName, strlen(pTagVal->tagName), pTagVal, sizeof(*pTagVal)) != 0) {
30!
1545
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1546
                __LINE__, tstrerror(terrno), version);
UNCOV
1547
      taosHashCleanup(pTagTable);
×
UNCOV
1548
      metaFetchEntryFree(&pChild);
×
UNCOV
1549
      metaFetchEntryFree(&pSuper);
×
UNCOV
1550
      TAOS_RETURN(terrno);
×
1551
    }
1552
  }
1553

1554
  int32_t numOfChangedTags = 0;
5✔
1555
  for (int32_t i = 0; i < pTagSchema->nCols; i++) {
40✔
1556
    taosHashGet(pTagTable, pTagSchema->pSchema[i].name, strlen(pTagSchema->pSchema[i].name)) != NULL
35✔
1557
        ? numOfChangedTags++
30✔
1558
        : 0;
35✔
1559
  }
1560
  if (numOfChangedTags < taosHashGetSize(pTagTable)) {
5!
UNCOV
1561
    metaError("vgId:%d, %s failed at %s:%d since tag count mismatch, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1562
              __FILE__, __LINE__, version);
UNCOV
1563
    taosHashCleanup(pTagTable);
×
1564
    metaFetchEntryFree(&pChild);
×
UNCOV
1565
    metaFetchEntryFree(&pSuper);
×
UNCOV
1566
    TAOS_RETURN(TSDB_CODE_VND_COL_NOT_EXISTS);
×
1567
  }
1568

1569
  // do change tag value
1570
  pChild->version = version;
5✔
1571
  const STag *pOldTag = (const STag *)pChild->ctbEntry.pTags;
5✔
1572
  SArray     *pTagArray = taosArrayInit(pTagSchema->nCols, sizeof(STagVal));
5✔
1573
  if (NULL == pTagArray) {
5!
UNCOV
1574
    metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1575
              __LINE__, tstrerror(terrno), version);
UNCOV
1576
    taosHashCleanup(pTagTable);
×
UNCOV
1577
    metaFetchEntryFree(&pChild);
×
UNCOV
1578
    metaFetchEntryFree(&pSuper);
×
UNCOV
1579
    TAOS_RETURN(terrno);
×
1580
  }
1581

1582
  for (int32_t i = 0; i < pTagSchema->nCols; i++) {
40✔
1583
    SSchema *pCol = &pTagSchema->pSchema[i];
35✔
1584
    STagVal  value = {
35✔
1585
         .cid = pCol->colId,
35✔
1586
    };
1587

1588
    SMultiTagUpateVal *pTagVal = taosHashGet(pTagTable, pCol->name, strlen(pCol->name));
35✔
1589
    if (pTagVal == NULL) {
35✔
1590
      if (!tTagGet(pOldTag, &value)) {
5!
1591
        continue;
6✔
1592
      }
1593
    } else {
1594
      value.type = pCol->type;
30✔
1595
      if (pTagVal->isNull) {
30✔
1596
        continue;
6✔
1597
      }
1598

1599
      if (IS_VAR_DATA_TYPE(pCol->type)) {
24!
1600
        value.pData = pTagVal->pTagVal;
4✔
1601
        value.nData = pTagVal->nTagVal;
4✔
1602
      } else {
1603
        memcpy(&value.i64, pTagVal->pTagVal, pTagVal->nTagVal);
20✔
1604
      }
1605
    }
1606

1607
    if (taosArrayPush(pTagArray, &value) == NULL) {
29!
UNCOV
1608
      metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1609
                __LINE__, tstrerror(terrno), version);
UNCOV
1610
      taosHashCleanup(pTagTable);
×
UNCOV
1611
      taosArrayDestroy(pTagArray);
×
UNCOV
1612
      metaFetchEntryFree(&pChild);
×
UNCOV
1613
      metaFetchEntryFree(&pSuper);
×
UNCOV
1614
      TAOS_RETURN(terrno);
×
1615
    }
1616
  }
1617

1618
  STag *pNewTag = NULL;
5✔
1619
  code = tTagNew(pTagArray, pTagSchema->version, false, &pNewTag);
5✔
1620
  if (code) {
5!
UNCOV
1621
    metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1622
              __LINE__, tstrerror(code), version);
UNCOV
1623
    taosHashCleanup(pTagTable);
×
UNCOV
1624
    taosArrayDestroy(pTagArray);
×
1625
    metaFetchEntryFree(&pChild);
×
UNCOV
1626
    metaFetchEntryFree(&pSuper);
×
1627
    TAOS_RETURN(code);
×
1628
  }
1629
  taosArrayDestroy(pTagArray);
5✔
1630
  taosMemoryFree(pChild->ctbEntry.pTags);
5!
1631
  pChild->ctbEntry.pTags = (uint8_t *)pNewTag;
5✔
1632

1633
  // do handle entry
1634
  code = metaHandleEntry2(pMeta, pChild);
5✔
1635
  if (code) {
5!
1636
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1637
              __func__, __FILE__, __LINE__, tstrerror(code), pChild->uid, pReq->tbName, version);
UNCOV
1638
    taosHashCleanup(pTagTable);
×
UNCOV
1639
    metaFetchEntryFree(&pChild);
×
UNCOV
1640
    metaFetchEntryFree(&pSuper);
×
UNCOV
1641
    TAOS_RETURN(code);
×
1642
  } else {
1643
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
5!
1644
             pChild->uid, version);
1645
  }
1646

1647
  taosHashCleanup(pTagTable);
5✔
1648
  metaFetchEntryFree(&pChild);
5✔
1649
  metaFetchEntryFree(&pSuper);
5✔
1650
  TAOS_RETURN(code);
5✔
1651
}
1652

1653
static int32_t metaCheckUpdateTableOptionsReq(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
78✔
1654
  int32_t code = TSDB_CODE_SUCCESS;
78✔
1655

1656
  if (pReq->tbName == NULL || strlen(pReq->tbName) == 0) {
78!
UNCOV
1657
    metaError("vgId:%d, %s failed at %s:%d since invalid table name, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1658
              __FILE__, __LINE__, version);
UNCOV
1659
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
1660
  }
1661

1662
  return code;
78✔
1663
}
1664

1665
int32_t metaUpdateTableOptions2(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
78✔
1666
  int32_t code = 0;
78✔
1667

1668
  code = metaCheckUpdateTableOptionsReq(pMeta, version, pReq);
78✔
1669
  if (code) {
78!
UNCOV
1670
    TAOS_RETURN(code);
×
1671
  }
1672

1673
  // fetch entry
1674
  SMetaEntry *pEntry = NULL;
78✔
1675
  code = metaFetchEntryByName(pMeta, pReq->tbName, &pEntry);
78✔
1676
  if (code) {
78!
1677
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1678
              __FILE__, __LINE__, pReq->tbName, version);
1679
    TAOS_RETURN(code);
×
1680
  }
1681

1682
  // do change the entry
1683
  pEntry->version = version;
78✔
1684
  if (pEntry->type == TSDB_CHILD_TABLE) {
78✔
1685
    if (pReq->updateTTL) {
40✔
1686
      pEntry->ctbEntry.ttlDays = pReq->newTTL;
15✔
1687
    }
1688
    if (pReq->newCommentLen >= 0) {
40✔
1689
      char *pNewComment = NULL;
25✔
1690
      if (pReq->newCommentLen) {
25✔
1691
        pNewComment = taosMemoryRealloc(pEntry->ctbEntry.comment, pReq->newCommentLen + 1);
20!
1692
        if (NULL == pNewComment) {
20!
UNCOV
1693
          metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1694
                    __LINE__, tstrerror(terrno), version);
UNCOV
1695
          metaFetchEntryFree(&pEntry);
×
UNCOV
1696
          TAOS_RETURN(terrno);
×
1697
        }
1698
        memcpy(pNewComment, pReq->newComment, pReq->newCommentLen + 1);
20✔
1699
      } else {
1700
        taosMemoryFreeClear(pEntry->ctbEntry.comment);
5!
1701
      }
1702
      pEntry->ctbEntry.comment = pNewComment;
25✔
1703
      pEntry->ctbEntry.commentLen = pReq->newCommentLen;
25✔
1704
    }
1705
  } else if (pEntry->type == TSDB_NORMAL_TABLE) {
38!
1706
    if (pReq->updateTTL) {
38✔
1707
      pEntry->ntbEntry.ttlDays = pReq->newTTL;
12✔
1708
    }
1709
    if (pReq->newCommentLen >= 0) {
38✔
1710
      char *pNewComment = NULL;
26✔
1711
      if (pReq->newCommentLen > 0) {
26✔
1712
        pNewComment = taosMemoryRealloc(pEntry->ntbEntry.comment, pReq->newCommentLen + 1);
21!
1713
        if (NULL == pNewComment) {
21!
UNCOV
1714
          metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
×
1715
                    __LINE__, tstrerror(terrno), version);
UNCOV
1716
          metaFetchEntryFree(&pEntry);
×
UNCOV
1717
          TAOS_RETURN(terrno);
×
1718
        }
1719
        memcpy(pNewComment, pReq->newComment, pReq->newCommentLen + 1);
21✔
1720
      } else {
1721
        taosMemoryFreeClear(pEntry->ntbEntry.comment);
5!
1722
      }
1723
      pEntry->ntbEntry.comment = pNewComment;
26✔
1724
      pEntry->ntbEntry.commentLen = pReq->newCommentLen;
26✔
1725
    }
1726
  } else {
UNCOV
1727
    metaError("vgId:%d, %s failed at %s:%d since table %s type %d is invalid, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1728
              __func__, __FILE__, __LINE__, pReq->tbName, pEntry->type, version);
UNCOV
1729
    metaFetchEntryFree(&pEntry);
×
UNCOV
1730
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
1731
  }
1732

1733
  // do handle entry
1734
  code = metaHandleEntry2(pMeta, pEntry);
78✔
1735
  if (code) {
78!
UNCOV
1736
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1737
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
UNCOV
1738
    metaFetchEntryFree(&pEntry);
×
1739
    TAOS_RETURN(code);
×
1740
  } else {
1741
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
78!
1742
             pEntry->uid, version);
1743
  }
1744

1745
  metaFetchEntryFree(&pEntry);
78✔
1746
  TAOS_RETURN(code);
78✔
1747
}
1748

1749
int32_t metaUpdateTableColCompress2(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
5✔
1750
  int32_t code = TSDB_CODE_SUCCESS;
5✔
1751

1752
  if (NULL == pReq->tbName || strlen(pReq->tbName) == 0) {
5!
1753
    metaError("vgId:%d, %s failed at %s:%d since invalid table name, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1754
              __FILE__, __LINE__, version);
UNCOV
1755
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
1756
  }
1757

1758
  SMetaEntry *pEntry = NULL;
5✔
1759
  code = metaFetchEntryByName(pMeta, pReq->tbName, &pEntry);
5✔
1760
  if (code) {
5!
UNCOV
1761
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1762
              __FILE__, __LINE__, pReq->tbName, version);
UNCOV
1763
    TAOS_RETURN(code);
×
1764
  }
1765

1766
  if (pEntry->version >= version) {
5!
UNCOV
1767
    metaError("vgId:%d, %s failed at %s:%d since table %s version %" PRId64 " is not less than %" PRId64,
×
1768
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, pEntry->version, version);
UNCOV
1769
    metaFetchEntryFree(&pEntry);
×
UNCOV
1770
    TAOS_RETURN(TSDB_CODE_INVALID_PARA);
×
1771
  }
1772

1773
  if (pEntry->type != TSDB_NORMAL_TABLE && pEntry->type != TSDB_SUPER_TABLE) {
5!
1774
    metaError("vgId:%d, %s failed at %s:%d since table %s type %d is invalid, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1775
              __func__, __FILE__, __LINE__, pReq->tbName, pEntry->type, version);
UNCOV
1776
    metaFetchEntryFree(&pEntry);
×
UNCOV
1777
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
1778
  }
1779

1780
  // do change the entry
1781
  int8_t           updated = 0;
5✔
1782
  SColCmprWrapper *wp = &pEntry->colCmpr;
5✔
1783
  for (int32_t i = 0; i < wp->nCols; i++) {
40✔
1784
    SColCmpr *p = &wp->pColCmpr[i];
35✔
1785
    if (p->id == pReq->colId) {
35✔
1786
      uint32_t dst = 0;
5✔
1787
      updated = tUpdateCompress(p->alg, pReq->compress, TSDB_COLVAL_COMPRESS_DISABLED, TSDB_COLVAL_LEVEL_DISABLED,
5✔
1788
                                TSDB_COLVAL_LEVEL_MEDIUM, &dst);
1789
      if (updated > 0) {
5!
1790
        p->alg = dst;
5✔
1791
      }
1792
    }
1793
  }
1794

1795
  if (updated == 0) {
5!
1796
    code = TSDB_CODE_VND_COLUMN_COMPRESS_ALREADY_EXIST;
×
1797
    metaError("vgId:%d, %s failed at %s:%d since column %d compress level is not changed, version:%" PRId64,
×
1798
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->colId, version);
1799
    metaFetchEntryFree(&pEntry);
×
UNCOV
1800
    TAOS_RETURN(code);
×
1801
  } else if (updated < 0) {
5!
1802
    code = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR;
×
UNCOV
1803
    metaError("vgId:%d, %s failed at %s:%d since column %d compress level is invalid, version:%" PRId64,
×
1804
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->colId, version);
UNCOV
1805
    metaFetchEntryFree(&pEntry);
×
UNCOV
1806
    TAOS_RETURN(code);
×
1807
  }
1808

1809
  pEntry->version = version;
5✔
1810

1811
  // do handle entry
1812
  code = metaHandleEntry2(pMeta, pEntry);
5✔
1813
  if (code) {
5!
1814
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1815
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
1816
    metaFetchEntryFree(&pEntry);
×
UNCOV
1817
    TAOS_RETURN(code);
×
1818
  } else {
1819
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
5!
1820
             pEntry->uid, version);
1821
  }
1822

1823
  metaFetchEntryFree(&pEntry);
5✔
1824
  TAOS_RETURN(code);
5✔
1825
}
1826

UNCOV
1827
int32_t metaAlterTableColumnRef(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp) {
×
UNCOV
1828
  int32_t code = TSDB_CODE_SUCCESS;
×
1829

1830
  // check request
UNCOV
1831
  code = metaCheckAlterTableColumnReq(pMeta, version, pReq);
×
UNCOV
1832
  if (code) {
×
UNCOV
1833
    TAOS_RETURN(code);
×
1834
  }
1835

UNCOV
1836
  if (NULL == pReq->refDbName) {
×
UNCOV
1837
    metaError("vgId:%d, %s failed at %s:%d since invalid ref db name, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1838
              __func__, __FILE__, __LINE__, version);
UNCOV
1839
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
1840
  }
1841

UNCOV
1842
  if (NULL == pReq->refTbName) {
×
UNCOV
1843
    metaError("vgId:%d, %s failed at %s:%d since invalid ref table name, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1844
              __func__, __FILE__, __LINE__, version);
UNCOV
1845
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
1846
  }
1847

UNCOV
1848
  if (NULL == pReq->refColName) {
×
UNCOV
1849
    metaError("vgId:%d, %s failed at %s:%d since invalid ref Col name, version:%" PRId64, TD_VID(pMeta->pVnode),
×
1850
              __func__, __FILE__, __LINE__, version);
UNCOV
1851
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
1852
  }
1853

1854

1855
  // fetch old entry
UNCOV
1856
  SMetaEntry *pEntry = NULL;
×
UNCOV
1857
  code = metaFetchEntryByName(pMeta, pReq->tbName, &pEntry);
×
UNCOV
1858
  if (code) {
×
UNCOV
1859
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1860
              __FILE__, __LINE__, pReq->tbName, version);
UNCOV
1861
    TAOS_RETURN(code);
×
1862
  }
1863

UNCOV
1864
  if (pEntry->version >= version) {
×
UNCOV
1865
    metaError("vgId:%d, %s failed at %s:%d since table %s version %" PRId64 " is not less than %" PRId64,
×
1866
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, pEntry->version, version);
UNCOV
1867
    metaFetchEntryFree(&pEntry);
×
UNCOV
1868
    TAOS_RETURN(TSDB_CODE_INVALID_PARA);
×
1869
  }
1870

1871
  // fetch super entry
UNCOV
1872
  SMetaEntry *pSuper = NULL;
×
UNCOV
1873
  if (pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
×
UNCOV
1874
    code = metaFetchEntryByUid(pMeta, pEntry->ctbEntry.suid, &pSuper);
×
UNCOV
1875
    if (code) {
×
UNCOV
1876
      metaError("vgId:%d, %s failed at %s:%d since super table uid %" PRId64 " not found, version:%" PRId64,
×
1877
                TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pEntry->ctbEntry.suid, version);
UNCOV
1878
      metaFetchEntryFree(&pEntry);
×
UNCOV
1879
      TAOS_RETURN(TSDB_CODE_INTERNAL_ERROR);
×
1880
    }
1881
  }
1882

1883
  // search the column to update
UNCOV
1884
  SSchemaWrapper *pSchema = pEntry->type == TSDB_VIRTUAL_CHILD_TABLE ? &pSuper->stbEntry.schemaRow : &pEntry->ntbEntry.schemaRow;
×
UNCOV
1885
  SColRef        *pColRef = NULL;
×
UNCOV
1886
  int32_t         iColumn = 0;
×
UNCOV
1887
  for (int32_t i = 0; i < pSchema->nCols; i++) {
×
UNCOV
1888
    if (strncmp(pSchema->pSchema[i].name, pReq->colName, TSDB_COL_NAME_LEN) == 0) {
×
UNCOV
1889
      pColRef = &pEntry->colRef.pColRef[i];
×
UNCOV
1890
      iColumn = i;
×
UNCOV
1891
      break;
×
1892
    }
1893
  }
1894

UNCOV
1895
  if (NULL == pColRef) {
×
UNCOV
1896
    metaError("vgId:%d, %s failed at %s:%d since column id %d not found in table %s, version:%" PRId64,
×
1897
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->colId, pReq->tbName, version);
UNCOV
1898
    metaFetchEntryFree(&pEntry);
×
UNCOV
1899
    metaFetchEntryFree(&pSuper);
×
UNCOV
1900
    TAOS_RETURN(TSDB_CODE_VND_COL_NOT_EXISTS);
×
1901
  }
1902

1903
  // do update column name
UNCOV
1904
  pEntry->version = version;
×
UNCOV
1905
  pColRef->hasRef = true;
×
UNCOV
1906
  pColRef->id = pSchema->pSchema[iColumn].colId;
×
UNCOV
1907
  tstrncpy(pColRef->refDbName, pReq->refDbName, TSDB_DB_NAME_LEN);
×
UNCOV
1908
  tstrncpy(pColRef->refTableName, pReq->refTbName, TSDB_TABLE_NAME_LEN);
×
UNCOV
1909
  tstrncpy(pColRef->refColName, pReq->refColName, TSDB_COL_NAME_LEN);
×
UNCOV
1910
  pSchema->version++;
×
1911

1912
  // do handle entry
UNCOV
1913
  code = metaHandleEntry2(pMeta, pEntry);
×
UNCOV
1914
  if (code) {
×
UNCOV
1915
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1916
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
UNCOV
1917
    metaFetchEntryFree(&pEntry);
×
UNCOV
1918
    metaFetchEntryFree(&pSuper);
×
UNCOV
1919
    TAOS_RETURN(code);
×
1920
  } else {
UNCOV
1921
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
×
1922
             pEntry->uid, version);
1923
  }
1924

1925
  // build response
UNCOV
1926
  if (metaUpdateVtbMetaRsp(pEntry->uid, pReq->tbName, pSchema, &pEntry->colRef, pRsp, pEntry->type) < 0) {
×
UNCOV
1927
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
1928
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
1929
  } else {
UNCOV
1930
    for (int32_t i = 0; i < pEntry->colRef.nCols; i++) {
×
UNCOV
1931
      SColRef *p = &pEntry->colRef.pColRef[i];
×
UNCOV
1932
      pRsp->pColRefs[i].hasRef = p->hasRef;
×
UNCOV
1933
      pRsp->pColRefs[i].id = p->id;
×
UNCOV
1934
      if (p->hasRef) {
×
UNCOV
1935
        tstrncpy(pRsp->pColRefs[i].refDbName, p->refDbName, TSDB_DB_NAME_LEN);
×
UNCOV
1936
        tstrncpy(pRsp->pColRefs[i].refTableName, p->refTableName, TSDB_TABLE_NAME_LEN);
×
UNCOV
1937
        tstrncpy(pRsp->pColRefs[i].refColName, p->refColName, TSDB_COL_NAME_LEN);
×
1938
      }
1939
    }
1940
  }
1941

UNCOV
1942
  metaFetchEntryFree(&pEntry);
×
UNCOV
1943
  metaFetchEntryFree(&pSuper);
×
UNCOV
1944
  TAOS_RETURN(code);
×
1945
}
1946

UNCOV
1947
int32_t metaRemoveTableColumnRef(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp) {
×
UNCOV
1948
  int32_t code = TSDB_CODE_SUCCESS;
×
1949

1950
  // check request
UNCOV
1951
  code = metaCheckAlterTableColumnReq(pMeta, version, pReq);
×
UNCOV
1952
  if (code) {
×
UNCOV
1953
    TAOS_RETURN(code);
×
1954
  }
1955

1956
  // fetch old entry
UNCOV
1957
  SMetaEntry *pEntry = NULL;
×
UNCOV
1958
  code = metaFetchEntryByName(pMeta, pReq->tbName, &pEntry);
×
UNCOV
1959
  if (code) {
×
UNCOV
1960
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
1961
              __FILE__, __LINE__, pReq->tbName, version);
UNCOV
1962
    TAOS_RETURN(code);
×
1963
  }
1964

UNCOV
1965
  if (pEntry->version >= version) {
×
UNCOV
1966
    metaError("vgId:%d, %s failed at %s:%d since table %s version %" PRId64 " is not less than %" PRId64,
×
1967
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->tbName, pEntry->version, version);
UNCOV
1968
    metaFetchEntryFree(&pEntry);
×
UNCOV
1969
    TAOS_RETURN(TSDB_CODE_INVALID_PARA);
×
1970
  }
1971

1972
  // fetch super entry
UNCOV
1973
  SMetaEntry *pSuper = NULL;
×
UNCOV
1974
  if (pEntry->type == TSDB_VIRTUAL_CHILD_TABLE) {
×
UNCOV
1975
    code = metaFetchEntryByUid(pMeta, pEntry->ctbEntry.suid, &pSuper);
×
UNCOV
1976
    if (code) {
×
UNCOV
1977
      metaError("vgId:%d, %s failed at %s:%d since super table uid %" PRId64 " not found, version:%" PRId64,
×
1978
                TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pEntry->ctbEntry.suid, version);
UNCOV
1979
      metaFetchEntryFree(&pEntry);
×
UNCOV
1980
      TAOS_RETURN(TSDB_CODE_INTERNAL_ERROR);
×
1981
    }
1982
  }
1983

1984
  // search the column to update
UNCOV
1985
  SSchemaWrapper *pSchema = pEntry->type == TSDB_VIRTUAL_CHILD_TABLE ? &pSuper->stbEntry.schemaRow : &pEntry->ntbEntry.schemaRow;
×
UNCOV
1986
  SColRef        *pColRef = NULL;
×
UNCOV
1987
  int32_t         iColumn = 0;
×
UNCOV
1988
  for (int32_t i = 0; i < pSchema->nCols; i++) {
×
UNCOV
1989
    if (strncmp(pSchema->pSchema[i].name, pReq->colName, TSDB_COL_NAME_LEN) == 0) {
×
UNCOV
1990
      pColRef = &pEntry->colRef.pColRef[i];
×
UNCOV
1991
      iColumn = i;
×
UNCOV
1992
      break;
×
1993
    }
1994
  }
1995

UNCOV
1996
  if (NULL == pColRef) {
×
UNCOV
1997
    metaError("vgId:%d, %s failed at %s:%d since column id %d not found in table %s, version:%" PRId64,
×
1998
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, iColumn + 1, pReq->tbName, version);
UNCOV
1999
    metaFetchEntryFree(&pEntry);
×
UNCOV
2000
    metaFetchEntryFree(&pSuper);
×
UNCOV
2001
    TAOS_RETURN(TSDB_CODE_VND_COL_NOT_EXISTS);
×
2002
  }
2003

2004
  // do update column name
UNCOV
2005
  pEntry->version = version;
×
UNCOV
2006
  pColRef->hasRef = false;
×
UNCOV
2007
  pColRef->id = pSchema->pSchema[iColumn].colId;
×
UNCOV
2008
  pSchema->version++;
×
2009

2010
  // do handle entry
UNCOV
2011
  code = metaHandleEntry2(pMeta, pEntry);
×
UNCOV
2012
  if (code) {
×
UNCOV
2013
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
2014
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
UNCOV
2015
    metaFetchEntryFree(&pEntry);
×
UNCOV
2016
    metaFetchEntryFree(&pSuper);
×
UNCOV
2017
    TAOS_RETURN(code);
×
2018
  } else {
UNCOV
2019
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
×
2020
             pEntry->uid, version);
2021
  }
2022

2023
  // build response
UNCOV
2024
  if (metaUpdateVtbMetaRsp(pEntry->uid, pReq->tbName, pSchema, &pEntry->colRef, pRsp, pEntry->type) < 0) {
×
UNCOV
2025
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
2026
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
2027
  } else {
UNCOV
2028
    for (int32_t i = 0; i < pEntry->colRef.nCols; i++) {
×
UNCOV
2029
      SColRef *p = &pEntry->colRef.pColRef[i];
×
UNCOV
2030
      pRsp->pColRefs[i].hasRef = p->hasRef;
×
UNCOV
2031
      pRsp->pColRefs[i].id = p->id;
×
UNCOV
2032
      if (p->hasRef) {
×
UNCOV
2033
        tstrncpy(pRsp->pColRefs[i].refDbName, p->refDbName, TSDB_DB_NAME_LEN);
×
UNCOV
2034
        tstrncpy(pRsp->pColRefs[i].refTableName, p->refTableName, TSDB_TABLE_NAME_LEN);
×
UNCOV
2035
        tstrncpy(pRsp->pColRefs[i].refColName, p->refColName, TSDB_COL_NAME_LEN);
×
2036
      }
2037
    }
2038
  }
2039

UNCOV
2040
  metaFetchEntryFree(&pEntry);
×
UNCOV
2041
  metaFetchEntryFree(&pSuper);
×
UNCOV
2042
  TAOS_RETURN(code);
×
2043
}
2044

2045
int32_t metaAddIndexToSuperTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
945✔
2046
  int32_t code = TSDB_CODE_SUCCESS;
945✔
2047

2048
  if (NULL == pReq->name || strlen(pReq->name) == 0) {
945!
UNCOV
2049
    metaError("vgId:%d, %s failed at %s:%d since invalid table name, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
2050
              __FILE__, __LINE__, version);
UNCOV
2051
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
2052
  }
2053

2054
  SMetaEntry *pEntry = NULL;
945✔
2055
  code = metaFetchEntryByName(pMeta, pReq->name, &pEntry);
945✔
2056
  if (code) {
945!
UNCOV
2057
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
2058
              __FILE__, __LINE__, pReq->name, version);
UNCOV
2059
    TAOS_RETURN(code);
×
2060
  }
2061

2062
  if (pEntry->type != TSDB_SUPER_TABLE) {
945!
UNCOV
2063
    metaError("vgId:%d, %s failed at %s:%d since table %s type %d is invalid, version:%" PRId64, TD_VID(pMeta->pVnode),
×
2064
              __func__, __FILE__, __LINE__, pReq->name, pEntry->type, version);
UNCOV
2065
    metaFetchEntryFree(&pEntry);
×
UNCOV
2066
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
2067
  }
2068

2069
  if (pEntry->uid != pReq->suid) {
945!
UNCOV
2070
    metaError("vgId:%d, %s failed at %s:%d since table %s uid %" PRId64 " is not equal to %" PRId64
×
2071
              ", version:%" PRId64,
2072
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, pEntry->uid, pReq->suid, version);
UNCOV
2073
    metaFetchEntryFree(&pEntry);
×
UNCOV
2074
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
2075
  }
2076

2077
  // if (pEntry->stbEntry.schemaTag.version >= pReq->schemaTag.version) {
2078
  //   metaError("vgId:%d, %s failed at %s:%d since table %s tag schema version %d is not less than %d, version:%"
2079
  //   PRId64,
2080
  //             TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, pEntry->stbEntry.schemaTag.version,
2081
  //             pReq->schemaTag.version, version);
2082
  //   metaFetchEntryFree(&pEntry);
2083
  //   TAOS_RETURN(TSDB_CODE_INVALID_MSG);
2084
  // }
2085

2086
  // do change the entry
2087
  SSchemaWrapper *pOldTagSchema = &pEntry->stbEntry.schemaTag;
945✔
2088
  SSchemaWrapper *pNewTagSchema = &pReq->schemaTag;
945✔
2089
  if (pOldTagSchema->nCols == 1 && pOldTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
945!
UNCOV
2090
    metaError("vgId:%d, %s failed at %s:%d since table %s has no tag, version:%" PRId64, TD_VID(pMeta->pVnode),
×
2091
              __func__, __FILE__, __LINE__, pReq->name, version);
UNCOV
2092
    metaFetchEntryFree(&pEntry);
×
UNCOV
2093
    TAOS_RETURN(TSDB_CODE_VND_COL_NOT_EXISTS);
×
2094
  }
2095

2096
  if (pOldTagSchema->nCols != pNewTagSchema->nCols) {
945!
UNCOV
2097
    metaError(
×
2098
        "vgId:%d, %s failed at %s:%d since table %s tag schema column count %d is not equal to %d, version:%" PRId64,
2099
        TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, pOldTagSchema->nCols, pNewTagSchema->nCols,
2100
        version);
UNCOV
2101
    metaFetchEntryFree(&pEntry);
×
UNCOV
2102
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
2103
  }
2104

2105
  // if (pOldTagSchema->version >= pNewTagSchema->version) {
2106
  //   metaError("vgId:%d, %s failed at %s:%d since table %s tag schema version %d is not less than %d, version:%"
2107
  //   PRId64,
2108
  //             TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, pOldTagSchema->version,
2109
  //             pNewTagSchema->version, version);
2110
  //   metaFetchEntryFree(&pEntry);
2111
  //   TAOS_RETURN(TSDB_CODE_INVALID_MSG);
2112
  // }
2113

2114
  int32_t numOfChangedTags = 0;
945✔
2115
  for (int32_t i = 0; i < pOldTagSchema->nCols; i++) {
14,950✔
2116
    SSchema *pOldColumn = pOldTagSchema->pSchema + i;
14,005✔
2117
    SSchema *pNewColumn = pNewTagSchema->pSchema + i;
14,005✔
2118

2119
    if (pOldColumn->type != pNewColumn->type || pOldColumn->colId != pNewColumn->colId ||
14,005!
2120
        strncmp(pOldColumn->name, pNewColumn->name, sizeof(pNewColumn->name))) {
14,005!
UNCOV
2121
      metaError("vgId:%d, %s failed at %s:%d since table %s tag schema column %d is not equal, version:%" PRId64,
×
2122
                TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, i, version);
UNCOV
2123
      metaFetchEntryFree(&pEntry);
×
UNCOV
2124
      TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
2125
    }
2126

2127
    if (IS_IDX_ON(pNewColumn) && !IS_IDX_ON(pOldColumn)) {
14,005✔
2128
      numOfChangedTags++;
945✔
2129
      SSCHMEA_SET_IDX_ON(pOldColumn);
945✔
2130
    } else if (!IS_IDX_ON(pNewColumn) && IS_IDX_ON(pOldColumn)) {
13,060!
UNCOV
2131
      metaError("vgId:%d, %s failed at %s:%d since table %s tag schema column %d is not equal, version:%" PRId64,
×
2132
                TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, i, version);
UNCOV
2133
      metaFetchEntryFree(&pEntry);
×
UNCOV
2134
      TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
2135
    }
2136
  }
2137

2138
  if (numOfChangedTags != 1) {
945!
UNCOV
2139
    metaError(
×
2140
        "vgId:%d, %s failed at %s:%d since table %s tag schema column count %d is not equal to 1, version:%" PRId64,
2141
        TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->name, numOfChangedTags, version);
UNCOV
2142
    metaFetchEntryFree(&pEntry);
×
UNCOV
2143
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
2144
  }
2145

2146
  pEntry->version = version;
945✔
2147
  pEntry->stbEntry.schemaTag.version = pNewTagSchema->version;
945✔
2148

2149
  // do handle the entry
2150
  code = metaHandleEntry2(pMeta, pEntry);
945✔
2151
  if (code) {
945!
UNCOV
2152
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
2153
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->name, version);
UNCOV
2154
    metaFetchEntryFree(&pEntry);
×
UNCOV
2155
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
2156
  } else {
2157
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->name,
945!
2158
             pEntry->uid, version);
2159
  }
2160

2161
  metaFetchEntryFree(&pEntry);
945✔
2162
  TAOS_RETURN(code);
945✔
2163
}
2164

2165
int32_t metaDropIndexFromSuperTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) {
2,130✔
2166
  int32_t code = TSDB_CODE_SUCCESS;
2,130✔
2167

2168
  if (strlen(pReq->colName) == 0 || strlen(pReq->stb) == 0) {
2,130!
UNCOV
2169
    metaError("vgId:%d, %s failed at %s:%d since invalid table name or column name, version:%" PRId64,
×
2170
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, version);
UNCOV
2171
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
2172
  }
2173

2174
  SMetaEntry *pEntry = NULL;
2,130✔
2175
  code = metaFetchEntryByUid(pMeta, pReq->stbUid, &pEntry);
2,130✔
2176
  if (code) {
2,130!
UNCOV
2177
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
2178
              __FILE__, __LINE__, pReq->stb, version);
UNCOV
2179
    TAOS_RETURN(code);
×
2180
  }
2181

2182
  if (TSDB_SUPER_TABLE != pEntry->type) {
2,130!
UNCOV
2183
    metaError("vgId:%d, %s failed at %s:%d since table %s type %d is invalid, version:%" PRId64, TD_VID(pMeta->pVnode),
×
2184
              __func__, __FILE__, __LINE__, pReq->stb, pEntry->type, version);
UNCOV
2185
    metaFetchEntryFree(&pEntry);
×
UNCOV
2186
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
2187
  }
2188

2189
  SSchemaWrapper *pTagSchema = &pEntry->stbEntry.schemaTag;
2,130✔
2190
  if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
2,130!
UNCOV
2191
    metaError("vgId:%d, %s failed at %s:%d since table %s has no tag, version:%" PRId64, TD_VID(pMeta->pVnode),
×
2192
              __func__, __FILE__, __LINE__, pReq->stb, version);
UNCOV
2193
    metaFetchEntryFree(&pEntry);
×
UNCOV
2194
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
2195
  }
2196

2197
  // search and set the tag index off
2198
  int32_t numOfChangedTags = 0;
2,130✔
2199
  for (int32_t i = 0; i < pTagSchema->nCols; i++) {
6,736!
2200
    SSchema *pCol = pTagSchema->pSchema + i;
6,736✔
2201
    if (0 == strncmp(pCol->name, pReq->colName, sizeof(pReq->colName))) {
6,736✔
2202
      if (!IS_IDX_ON(pCol)) {
2,130!
UNCOV
2203
        metaError("vgId:%d, %s failed at %s:%d since table %s column %s is not indexed, version:%" PRId64,
×
2204
                  TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->stb, pReq->colName, version);
UNCOV
2205
        metaFetchEntryFree(&pEntry);
×
UNCOV
2206
        TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
2207
      }
2208
      numOfChangedTags++;
2,130✔
2209
      SSCHMEA_SET_IDX_OFF(pCol);
2,130✔
2210
      break;
2,130✔
2211
    }
2212
  }
2213

2214
  if (numOfChangedTags != 1) {
2,130!
UNCOV
2215
    metaError("vgId:%d, %s failed at %s:%d since table %s column %s is not found, version:%" PRId64,
×
2216
              TD_VID(pMeta->pVnode), __func__, __FILE__, __LINE__, pReq->stb, pReq->colName, version);
UNCOV
2217
    metaFetchEntryFree(&pEntry);
×
UNCOV
2218
    TAOS_RETURN(TSDB_CODE_VND_COL_NOT_EXISTS);
×
2219
  }
2220

2221
  // do handle the entry
2222
  pEntry->version = version;
2,130✔
2223
  pTagSchema->version++;
2,130✔
2224
  code = metaHandleEntry2(pMeta, pEntry);
2,130✔
2225
  if (code) {
2,130!
UNCOV
2226
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
2227
              __func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->stb, version);
UNCOV
2228
    metaFetchEntryFree(&pEntry);
×
UNCOV
2229
    TAOS_RETURN(code);
×
2230
  } else {
2231
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->stb,
2,130!
2232
             pEntry->uid, version);
2233
  }
2234

2235
  metaFetchEntryFree(&pEntry);
2,130✔
2236
  TAOS_RETURN(code);
2,130✔
2237
}
2238

2239
int32_t metaAlterSuperTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
6,433✔
2240
  int32_t code = TSDB_CODE_SUCCESS;
6,433✔
2241

2242
  if (NULL == pReq->name || strlen(pReq->name) == 0) {
6,433!
UNCOV
2243
    metaError("vgId:%d, %s failed at %s:%d since invalid table name, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
×
2244
              __FILE__, __LINE__, version);
UNCOV
2245
    TAOS_RETURN(TSDB_CODE_INVALID_MSG);
×
2246
  }
2247

2248
  SMetaEntry *pEntry = NULL;
6,438✔
2249
  code = metaFetchEntryByName(pMeta, pReq->name, &pEntry);
6,438✔
2250
  if (code) {
6,436✔
2251
    metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
2!
2252
              __FILE__, __LINE__, pReq->name, version);
2253
    TAOS_RETURN(TSDB_CODE_TDB_STB_NOT_EXIST);
2✔
2254
  }
2255

2256
  if (pEntry->type != TSDB_SUPER_TABLE) {
6,434!
UNCOV
2257
    metaError("vgId:%d, %s failed at %s:%d since table %s type %d is invalid, version:%" PRId64, TD_VID(pMeta->pVnode),
×
2258
              __func__, __FILE__, __LINE__, pReq->name, pEntry->type, version);
UNCOV
2259
    metaFetchEntryFree(&pEntry);
×
UNCOV
2260
    TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
×
2261
  }
2262

2263
  SMetaEntry entry = {
6,434✔
2264
      .version = version,
2265
      .type = TSDB_SUPER_TABLE,
2266
      .uid = pReq->suid,
6,434✔
2267
      .name = pReq->name,
6,434✔
2268
      .stbEntry.schemaRow = pReq->schemaRow,
2269
      .stbEntry.schemaTag = pReq->schemaTag,
2270
      .stbEntry.keep = pReq->keep,
6,434✔
2271
      .colCmpr = pReq->colCmpr,
2272
      .pExtSchemas = pReq->pExtSchemas,
6,434✔
2273
  };
2274
  TABLE_SET_COL_COMPRESSED(entry.flags);
6,434✔
2275
  if (pReq->virtualStb) {
6,434!
UNCOV
2276
    TABLE_SET_VIRTUAL(entry.flags);
×
2277
  }
2278

2279
  // do handle the entry
2280
  code = metaHandleEntry2(pMeta, &entry);
6,434✔
2281
  if (code) {
6,440!
UNCOV
2282
    metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
×
2283
              __func__, __FILE__, __LINE__, tstrerror(code), pReq->suid, pReq->name, version);
UNCOV
2284
    metaFetchEntryFree(&pEntry);
×
UNCOV
2285
    TAOS_RETURN(code);
×
2286
  } else {
2287
    metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->name,
6,440✔
2288
             pReq->suid, version);
2289
  }
2290

2291
  metaFetchEntryFree(&pEntry);
6,446✔
2292
  TAOS_RETURN(code);
6,444✔
2293
}
2294

UNCOV
2295
int32_t metaDropMultipleTables(SMeta *pMeta, int64_t version, SArray *uidArray) {
×
UNCOV
2296
  int32_t code = 0;
×
2297

UNCOV
2298
  if (taosArrayGetSize(uidArray) == 0) {
×
UNCOV
2299
    return TSDB_CODE_SUCCESS;
×
2300
  }
2301

UNCOV
2302
  for (int32_t i = 0; i < taosArrayGetSize(uidArray); i++) {
×
UNCOV
2303
    tb_uid_t  uid = *(tb_uid_t *)taosArrayGet(uidArray, i);
×
2304
    SMetaInfo info;
UNCOV
2305
    code = metaGetInfo(pMeta, uid, &info, NULL);
×
UNCOV
2306
    if (code) {
×
UNCOV
2307
      metaError("vgId:%d, %s failed at %s:%d since table uid %" PRId64 " not found, code:%d", TD_VID(pMeta->pVnode),
×
2308
                __func__, __FILE__, __LINE__, uid, code);
UNCOV
2309
      return code;
×
2310
    }
2311

UNCOV
2312
    SMetaEntry entry = {
×
2313
        .version = version,
2314
        .uid = uid,
2315
    };
2316

UNCOV
2317
    if (info.suid == 0) {
×
UNCOV
2318
      entry.type = -TSDB_NORMAL_TABLE;
×
UNCOV
2319
    } else if (info.suid == uid) {
×
UNCOV
2320
      entry.type = -TSDB_SUPER_TABLE;
×
2321
    } else {
UNCOV
2322
      entry.type = -TSDB_CHILD_TABLE;
×
2323
    }
UNCOV
2324
    code = metaHandleEntry2(pMeta, &entry);
×
UNCOV
2325
    if (code) {
×
UNCOV
2326
      metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " version:%" PRId64, TD_VID(pMeta->pVnode),
×
2327
                __func__, __FILE__, __LINE__, tstrerror(code), uid, version);
UNCOV
2328
      return code;
×
2329
    }
2330
  }
UNCOV
2331
  return code;
×
2332
}
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