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

taosdata / TDengine / #4870

26 Nov 2025 05:46AM UTC coverage: 64.545% (+0.006%) from 64.539%
#4870

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

768 of 945 new or added lines in 33 files covered. (81.27%)

2982 existing lines in 119 files now uncovered.

158219 of 245129 relevant lines covered (64.55%)

112474797.36 hits per line

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

74.28
/source/client/src/clientRawBlockWrite.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 "cJSON.h"
17
#include "clientInt.h"
18
#include "parser.h"
19
#include "tcol.h"
20
#include "tcompression.h"
21
#include "tdatablock.h"
22
#include "tdef.h"
23
#include "tglobal.h"
24
#include "tmsgtype.h"
25

26
#define RAW_NULL_CHECK(c) \
27
  do {                    \
28
    if (c == NULL) {      \
29
      code = terrno;      \
30
      goto end;           \
31
    }                     \
32
  } while (0)
33

34
#define RAW_FALSE_CHECK(c)           \
35
  do {                               \
36
    if (!c) {                        \
37
      code = TSDB_CODE_INVALID_PARA; \
38
      goto end;                      \
39
    }                                \
40
  } while (0)
41

42
#define RAW_RETURN_CHECK(c) \
43
  do {                      \
44
    code = c;               \
45
    if (code != 0) {        \
46
      goto end;             \
47
    }                       \
48
  } while (0)
49

50
#define LOG_ID_TAG   "connId:0x%" PRIx64 ", QID:0x%" PRIx64
51
#define LOG_ID_VALUE *(int64_t*)taos, pRequest->requestId
52

53
#define TMQ_META_VERSION "1.0"
54

55
static bool tmqAddJsonObjectItem(cJSON* object, const char* string, cJSON* item) {
226,767✔
56
  bool ret = cJSON_AddItemToObject(object, string, item);
226,767✔
57
  if (!ret) {
226,767✔
58
    cJSON_Delete(item);
×
59
  }
60
  return ret;
226,767✔
61
}
62
static bool tmqAddJsonArrayItem(cJSON* array, cJSON* item) {
40,812✔
63
  bool ret = cJSON_AddItemToArray(array, item);
40,812✔
64
  if (!ret) {
40,812✔
65
    cJSON_Delete(item);
×
66
  }
67
  return ret;
40,812✔
68
}
69

70
static int32_t  tmqWriteBatchMetaDataImpl(TAOS* taos, void* meta, uint32_t metaLen);
71
static tb_uid_t processSuid(tb_uid_t suid, char* db) {
3,755✔
72
  if (db == NULL) {
3,755✔
73
    return suid;
×
74
  }
75
  return suid + MurmurHash3_32(db, strlen(db));
3,755✔
76
}
77
static void buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* schemaTag, SExtSchema* pExtSchemas, char* name, int64_t id, int8_t t,
3,160✔
78
                                 SColCmprWrapper* pColCmprRow, cJSON** pJson) {
79
  if (schemaRow == NULL || name == NULL || pColCmprRow == NULL || pJson == NULL) {
3,160✔
80
    uError("invalid parameter, schemaRow:%p, name:%p, pColCmprRow:%p, pJson:%p", schemaRow, name, pColCmprRow, pJson);
×
81
    return;
×
82
  }
83
  int32_t code = TSDB_CODE_SUCCESS;
3,160✔
84
  int8_t  buildDefaultCompress = 0;
3,160✔
85
  if (pColCmprRow->nCols <= 0) {
3,160✔
86
    buildDefaultCompress = 1;
53✔
87
  }
88

89
  char*  string = NULL;
3,160✔
90
  cJSON* json = cJSON_CreateObject();
3,160✔
91
  RAW_NULL_CHECK(json);
3,160✔
92
  cJSON* type = cJSON_CreateString("create");
3,160✔
93
  RAW_NULL_CHECK(type);
3,160✔
94

95
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
3,160✔
96
  cJSON* tableType = cJSON_CreateString(t == TSDB_NORMAL_TABLE ? "normal" : "super");
3,160✔
97
  RAW_NULL_CHECK(tableType);
3,160✔
98
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableType", tableType));
3,160✔
99
  cJSON* tableName = cJSON_CreateString(name);
3,160✔
100
  RAW_NULL_CHECK(tableName);
3,160✔
101
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableName", tableName));
3,160✔
102

103
  cJSON* columns = cJSON_CreateArray();
3,160✔
104
  RAW_NULL_CHECK(columns);
3,160✔
105
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "columns", columns));
3,160✔
106

107
  for (int i = 0; i < schemaRow->nCols; i++) {
22,674✔
108
    cJSON* column = cJSON_CreateObject();
19,514✔
109
    RAW_NULL_CHECK(column);
19,514✔
110
    RAW_FALSE_CHECK(tmqAddJsonArrayItem(columns, column));
19,514✔
111
    SSchema* s = schemaRow->pSchema + i;
19,514✔
112
    cJSON*   cname = cJSON_CreateString(s->name);
19,514✔
113
    RAW_NULL_CHECK(cname);
19,514✔
114
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "name", cname));
19,514✔
115
    cJSON* ctype = cJSON_CreateNumber(s->type);
19,514✔
116
    RAW_NULL_CHECK(ctype);
19,514✔
117
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "type", ctype));
19,514✔
118
    if (s->type == TSDB_DATA_TYPE_BINARY || s->type == TSDB_DATA_TYPE_VARBINARY || s->type == TSDB_DATA_TYPE_GEOMETRY) {
21,133✔
119
      int32_t length = s->bytes - VARSTR_HEADER_SIZE;
1,619✔
120
      cJSON*  cbytes = cJSON_CreateNumber(length);
1,619✔
121
      RAW_NULL_CHECK(cbytes);
1,619✔
122
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "length", cbytes));
1,619✔
123
    } else if (s->type == TSDB_DATA_TYPE_NCHAR) {
17,895✔
124
      int32_t length = (s->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
273✔
125
      cJSON*  cbytes = cJSON_CreateNumber(length);
273✔
126
      RAW_NULL_CHECK(cbytes);
273✔
127
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "length", cbytes));
273✔
128
    } else if (IS_STR_DATA_BLOB(s->type)) {
17,622✔
129
      int32_t length = s->bytes - BLOBSTR_HEADER_SIZE;
×
130
      cJSON*  cbytes = cJSON_CreateNumber(length);
×
131
      RAW_NULL_CHECK(cbytes);
×
132
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "length", cbytes));
×
133
    } else if (s->type == TSDB_DATA_TYPE_DECIMAL || s->type == TSDB_DATA_TYPE_DECIMAL64) {
17,622✔
134
      int32_t length = pExtSchemas[i].typeMod;
151✔
135
      cJSON*  cbytes = cJSON_CreateNumber(length);
151✔
136
      RAW_NULL_CHECK(cbytes);
151✔
137
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "length", cbytes));
151✔
138
    }
139
    cJSON* isPk = cJSON_CreateBool(s->flags & COL_IS_KEY);
19,514✔
140
    RAW_NULL_CHECK(isPk);
19,514✔
141
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "isPrimarykey", isPk));
19,514✔
142

143
    if (pColCmprRow == NULL) {
19,514✔
144
      continue;
×
145
    }
146

147
    uint32_t alg = 0;
19,514✔
148
    if (buildDefaultCompress) {
19,514✔
149
      alg = createDefaultColCmprByType(s->type);
106✔
150
    } else {
151
      SColCmpr* pColCmpr = pColCmprRow->pColCmpr + i;
19,408✔
152
      alg = pColCmpr->alg;
19,408✔
153
    }
154
    const char* encode = columnEncodeStr(COMPRESS_L1_TYPE_U32(alg));
19,514✔
155
    RAW_NULL_CHECK(encode);
19,514✔
156
    const char* compress = columnCompressStr(COMPRESS_L2_TYPE_U32(alg));
19,514✔
157
    RAW_NULL_CHECK(compress);
19,514✔
158
    const char* level = columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(alg));
19,514✔
159
    RAW_NULL_CHECK(level);
19,514✔
160

161
    cJSON* encodeJson = cJSON_CreateString(encode);
19,514✔
162
    RAW_NULL_CHECK(encodeJson);
19,514✔
163
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "encode", encodeJson));
19,514✔
164

165
    cJSON* compressJson = cJSON_CreateString(compress);
19,514✔
166
    RAW_NULL_CHECK(compressJson);
19,514✔
167
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "compress", compressJson));
19,514✔
168

169
    cJSON* levelJson = cJSON_CreateString(level);
19,514✔
170
    RAW_NULL_CHECK(levelJson);
19,514✔
171
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "level", levelJson));
19,514✔
172
  }
173

174
  cJSON* tags = cJSON_CreateArray();
3,160✔
175
  RAW_NULL_CHECK(tags);
3,160✔
176
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tags", tags));
3,160✔
177

178
  for (int i = 0; schemaTag && i < schemaTag->nCols; i++) {
9,028✔
179
    cJSON* tag = cJSON_CreateObject();
5,868✔
180
    RAW_NULL_CHECK(tag);
5,868✔
181
    RAW_FALSE_CHECK(tmqAddJsonArrayItem(tags, tag));
5,868✔
182
    SSchema* s = schemaTag->pSchema + i;
5,868✔
183
    cJSON*   tname = cJSON_CreateString(s->name);
5,868✔
184
    RAW_NULL_CHECK(tname);
5,868✔
185
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "name", tname));
5,868✔
186
    cJSON* ttype = cJSON_CreateNumber(s->type);
5,868✔
187
    RAW_NULL_CHECK(ttype);
5,868✔
188
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "type", ttype));
5,868✔
189
    if (s->type == TSDB_DATA_TYPE_BINARY || s->type == TSDB_DATA_TYPE_VARBINARY || s->type == TSDB_DATA_TYPE_GEOMETRY) {
6,301✔
190
      int32_t length = s->bytes - VARSTR_HEADER_SIZE;
433✔
191
      cJSON*  cbytes = cJSON_CreateNumber(length);
433✔
192
      RAW_NULL_CHECK(cbytes);
433✔
193
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "length", cbytes));
433✔
194
    } else if (s->type == TSDB_DATA_TYPE_NCHAR) {
5,435✔
195
      int32_t length = (s->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
1,619✔
196
      cJSON*  cbytes = cJSON_CreateNumber(length);
1,619✔
197
      RAW_NULL_CHECK(cbytes);
1,619✔
198
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "length", cbytes));
1,619✔
199
    } else if (IS_STR_DATA_BLOB(s->type)) {
3,816✔
200
      int32_t length = s->bytes - BLOBSTR_HEADER_SIZE;
×
201
      cJSON*  cbytes = cJSON_CreateNumber(length);
×
202
      RAW_NULL_CHECK(cbytes);
×
203
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "length", cbytes));
×
204
    }
205
  }
206

207
end:
3,160✔
208
  *pJson = json;
3,160✔
209
}
210

211
static int32_t setCompressOption(cJSON* json, uint32_t para) {
×
212
  if (json == NULL) {
×
213
    return TSDB_CODE_INVALID_PARA;
×
214
  }
215
  uint8_t encode = COMPRESS_L1_TYPE_U32(para);
×
216
  int32_t code = 0;
×
217
  if (encode != 0) {
×
218
    const char* encodeStr = columnEncodeStr(encode);
×
219
    RAW_NULL_CHECK(encodeStr);
×
220
    cJSON* encodeJson = cJSON_CreateString(encodeStr);
×
221
    RAW_NULL_CHECK(encodeJson);
×
222
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "encode", encodeJson));
×
223
    return code;
×
224
  }
225
  uint8_t compress = COMPRESS_L2_TYPE_U32(para);
×
226
  if (compress != 0) {
×
227
    const char* compressStr = columnCompressStr(compress);
×
228
    RAW_NULL_CHECK(compressStr);
×
229
    cJSON* compressJson = cJSON_CreateString(compressStr);
×
230
    RAW_NULL_CHECK(compressJson);
×
231
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "compress", compressJson));
×
232
    return code;
×
233
  }
234
  uint8_t level = COMPRESS_L2_TYPE_LEVEL_U32(para);
×
235
  if (level != 0) {
×
236
    const char* levelStr = columnLevelStr(level);
×
237
    RAW_NULL_CHECK(levelStr);
×
238
    cJSON* levelJson = cJSON_CreateString(levelStr);
×
239
    RAW_NULL_CHECK(levelJson);
×
240
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "level", levelJson));
×
241
    return code;
×
242
  }
243

244
end:
×
245
  return code;
×
246
}
247
static void buildAlterSTableJson(void* alterData, int32_t alterDataLen, cJSON** pJson) {
1,385✔
248
  if (alterData == NULL || pJson == NULL) {
1,385✔
249
    uError("invalid parameter in %s", __func__);
×
250
    return;
×
251
  }
252
  SMAlterStbReq req = {0};
1,385✔
253
  cJSON*        json = NULL;
1,385✔
254
  char*         string = NULL;
1,385✔
255
  int32_t       code = 0;
1,385✔
256

257
  if (tDeserializeSMAlterStbReq(alterData, alterDataLen, &req) != 0) {
1,385✔
258
    goto end;
×
259
  }
260

261
  json = cJSON_CreateObject();
1,385✔
262
  RAW_NULL_CHECK(json);
1,385✔
263
  cJSON* type = cJSON_CreateString("alter");
1,385✔
264
  RAW_NULL_CHECK(type);
1,385✔
265
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
1,385✔
266
  SName name = {0};
1,385✔
267
  RAW_RETURN_CHECK(tNameFromString(&name, req.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE));
1,385✔
268
  cJSON* tableType = cJSON_CreateString("super");
1,385✔
269
  RAW_NULL_CHECK(tableType);
1,385✔
270
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableType", tableType));
1,385✔
271
  cJSON* tableName = cJSON_CreateString(name.tname);
1,385✔
272
  RAW_NULL_CHECK(tableName);
1,385✔
273
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableName", tableName));
1,385✔
274

275
  cJSON* alterType = cJSON_CreateNumber(req.alterType);
1,385✔
276
  RAW_NULL_CHECK(alterType);
1,385✔
277
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "alterType", alterType));
1,385✔
278
  switch (req.alterType) {
1,385✔
279
    case TSDB_ALTER_TABLE_ADD_TAG:
831✔
280
    case TSDB_ALTER_TABLE_ADD_COLUMN: {
281
      TAOS_FIELD* field = taosArrayGet(req.pFields, 0);
831✔
282
      RAW_NULL_CHECK(field);
831✔
283
      cJSON* colName = cJSON_CreateString(field->name);
831✔
284
      RAW_NULL_CHECK(colName);
831✔
285
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
831✔
286
      cJSON* colType = cJSON_CreateNumber(field->type);
831✔
287
      RAW_NULL_CHECK(colType);
831✔
288
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
831✔
289

290
      if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY ||
831✔
291
          field->type == TSDB_DATA_TYPE_GEOMETRY) {
831✔
292
        int32_t length = field->bytes - VARSTR_HEADER_SIZE;
277✔
293
        cJSON*  cbytes = cJSON_CreateNumber(length);
277✔
294
        RAW_NULL_CHECK(cbytes);
277✔
295
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
277✔
296
      } else if (field->type == TSDB_DATA_TYPE_NCHAR) {
554✔
297
        int32_t length = (field->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
298
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
299
        RAW_NULL_CHECK(cbytes);
×
300
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
301
      } else if (IS_STR_DATA_BLOB(field->type)) {
554✔
302
        int32_t length = field->bytes - BLOBSTR_HEADER_SIZE;
×
303
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
304
        RAW_NULL_CHECK(cbytes);
×
305
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
306
      }
307
      break;
831✔
308
    }
309
    case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION: {
×
310
      SFieldWithOptions* field = taosArrayGet(req.pFields, 0);
×
311
      RAW_NULL_CHECK(field);
×
312
      cJSON* colName = cJSON_CreateString(field->name);
×
313
      RAW_NULL_CHECK(colName);
×
314
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
×
315
      cJSON* colType = cJSON_CreateNumber(field->type);
×
316
      RAW_NULL_CHECK(colType);
×
317
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
×
318

319
      if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY ||
×
320
          field->type == TSDB_DATA_TYPE_GEOMETRY) {
×
321
        int32_t length = field->bytes - VARSTR_HEADER_SIZE;
×
322
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
323
        RAW_NULL_CHECK(cbytes);
×
324
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
325
      } else if (field->type == TSDB_DATA_TYPE_NCHAR) {
×
326
        int32_t length = (field->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
327
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
328
        RAW_NULL_CHECK(cbytes);
×
329
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
330
      } else if (IS_STR_DATA_BLOB(field->type)) {
×
331
        int32_t length = field->bytes - BLOBSTR_HEADER_SIZE;
×
332
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
333
        RAW_NULL_CHECK(cbytes);
×
334
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
335
      }
336

337
      RAW_RETURN_CHECK(setCompressOption(json, field->compress));
×
338
      break;
×
339
    }
340
    case TSDB_ALTER_TABLE_DROP_TAG:
277✔
341
    case TSDB_ALTER_TABLE_DROP_COLUMN: {
342
      TAOS_FIELD* field = taosArrayGet(req.pFields, 0);
277✔
343
      RAW_NULL_CHECK(field);
277✔
344
      cJSON* colName = cJSON_CreateString(field->name);
277✔
345
      RAW_NULL_CHECK(colName);
277✔
346
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
277✔
347
      break;
277✔
348
    }
349
    case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES:
277✔
350
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: {
351
      TAOS_FIELD* field = taosArrayGet(req.pFields, 0);
277✔
352
      RAW_NULL_CHECK(field);
277✔
353
      cJSON* colName = cJSON_CreateString(field->name);
277✔
354
      RAW_NULL_CHECK(colName);
277✔
355
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
277✔
356
      cJSON* colType = cJSON_CreateNumber(field->type);
277✔
357
      RAW_NULL_CHECK(colType);
277✔
358
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
277✔
359
      if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY ||
277✔
360
          field->type == TSDB_DATA_TYPE_GEOMETRY) {
277✔
361
        int32_t length = field->bytes - VARSTR_HEADER_SIZE;
277✔
362
        cJSON*  cbytes = cJSON_CreateNumber(length);
277✔
363
        RAW_NULL_CHECK(cbytes);
277✔
364
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
277✔
365
      } else if (field->type == TSDB_DATA_TYPE_NCHAR) {
×
366
        int32_t length = (field->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
367
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
368
        RAW_NULL_CHECK(cbytes);
×
369
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
370
      }
371
      break;
277✔
372
    }
373
    case TSDB_ALTER_TABLE_UPDATE_TAG_NAME:
×
374
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: {
375
      TAOS_FIELD* oldField = taosArrayGet(req.pFields, 0);
×
376
      RAW_NULL_CHECK(oldField);
×
377
      TAOS_FIELD* newField = taosArrayGet(req.pFields, 1);
×
378
      RAW_NULL_CHECK(newField);
×
379
      cJSON* colName = cJSON_CreateString(oldField->name);
×
380
      RAW_NULL_CHECK(colName);
×
381
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
×
382
      cJSON* colNewName = cJSON_CreateString(newField->name);
×
383
      RAW_NULL_CHECK(colNewName);
×
384
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colNewName", colNewName));
×
385
      break;
×
386
    }
387
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: {
×
388
      TAOS_FIELD* field = taosArrayGet(req.pFields, 0);
×
389
      RAW_NULL_CHECK(field);
×
390
      cJSON* colName = cJSON_CreateString(field->name);
×
391
      RAW_NULL_CHECK(colName);
×
392
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
×
393
      RAW_RETURN_CHECK(setCompressOption(json, field->bytes));
×
394
      break;
×
395
    }
396
    default:
×
397
      break;
×
398
  }
399

400
end:
1,385✔
401
  tFreeSMAltertbReq(&req);
1,385✔
402
  *pJson = json;
1,385✔
403
}
404

405
static void processCreateStb(SMqMetaRsp* metaRsp, cJSON** pJson) {
2,466✔
406
  if (metaRsp == NULL || pJson == NULL) {
2,466✔
407
    uError("invalid parameter in %s", __func__);
×
408
    return;
×
409
  }
410
  SVCreateStbReq req = {0};
2,466✔
411
  SDecoder       coder = {0};
2,466✔
412

413
  uDebug("create stable data:%p", metaRsp);
2,466✔
414
  // decode and process req
415
  void*   data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
2,466✔
416
  int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
2,466✔
417
  tDecoderInit(&coder, data, len);
2,466✔
418

419
  if (tDecodeSVCreateStbReq(&coder, &req) < 0) {
2,466✔
420
    goto end;
×
421
  }
422
  buildCreateTableJson(&req.schemaRow, &req.schemaTag, req.pExtSchemas, req.name, req.suid, TSDB_SUPER_TABLE, &req.colCmpr, pJson);
2,466✔
423

424
end:
2,466✔
425
  uDebug("create stable return");
2,466✔
426
  tDecoderClear(&coder);
2,466✔
427
}
428

429
static void processAlterStb(SMqMetaRsp* metaRsp, cJSON** pJson) {
1,385✔
430
  if (metaRsp == NULL || pJson == NULL) {
1,385✔
431
    uError("invalid parameter in %s", __func__);
×
432
    return;
×
433
  }
434
  SVCreateStbReq req = {0};
1,385✔
435
  SDecoder       coder = {0};
1,385✔
436
  uDebug("alter stable data:%p", metaRsp);
1,385✔
437

438
  // decode and process req
439
  void*   data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
1,385✔
440
  int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
1,385✔
441
  tDecoderInit(&coder, data, len);
1,385✔
442

443
  if (tDecodeSVCreateStbReq(&coder, &req) < 0) {
1,385✔
444
    goto end;
×
445
  }
446
  buildAlterSTableJson(req.alterOriData, req.alterOriDataLen, pJson);
1,385✔
447

448
end:
1,385✔
449
  uDebug("alter stable return");
1,385✔
450
  tDecoderClear(&coder);
1,385✔
451
}
452

453
static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq) {
4,822✔
454
  if (json == NULL || pCreateReq == NULL) {
4,822✔
455
    uError("invalid parameter in %s", __func__);
×
456
    return;
×
457
  }
458
  STag*   pTag = (STag*)pCreateReq->ctb.pTag;
4,822✔
459
  char*   sname = pCreateReq->ctb.stbName;
4,822✔
460
  char*   name = pCreateReq->name;
4,822✔
461
  SArray* tagName = pCreateReq->ctb.tagName;
4,822✔
462
  int64_t id = pCreateReq->uid;
4,822✔
463
  uint8_t tagNum = pCreateReq->ctb.tagNum;
4,822✔
464
  int32_t code = 0;
4,822✔
465
  SArray* pTagVals = NULL;
4,822✔
466
  char*   pJson = NULL;
4,822✔
467

468
  cJSON* tableName = cJSON_CreateString(name);
4,822✔
469
  RAW_NULL_CHECK(tableName);
4,822✔
470
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableName", tableName));
4,822✔
471
  cJSON* using = cJSON_CreateString(sname);
4,822✔
472
  RAW_NULL_CHECK(using);
4,822✔
473
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "using", using));
4,822✔
474
  cJSON* tagNumJson = cJSON_CreateNumber(tagNum);
4,822✔
475
  RAW_NULL_CHECK(tagNumJson);
4,822✔
476
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tagNum", tagNumJson));
4,822✔
477

478
  cJSON* tags = cJSON_CreateArray();
4,822✔
479
  RAW_NULL_CHECK(tags);
4,822✔
480
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tags", tags));
4,822✔
481
  RAW_RETURN_CHECK(tTagToValArray(pTag, &pTagVals));
4,822✔
482
  if (tTagIsJson(pTag)) {
4,822✔
483
    STag* p = (STag*)pTag;
630✔
484
    if (p->nTag == 0) {
630✔
485
      uError("p->nTag == 0");
315✔
486
      goto end;
315✔
487
    }
488
    parseTagDatatoJson(pTag, &pJson, NULL);
315✔
489
    RAW_NULL_CHECK(pJson);
315✔
490
    cJSON* tag = cJSON_CreateObject();
315✔
491
    RAW_NULL_CHECK(tag);
315✔
492
    RAW_FALSE_CHECK(tmqAddJsonArrayItem(tags, tag));
315✔
493
    STagVal* pTagVal = taosArrayGet(pTagVals, 0);
315✔
494
    RAW_NULL_CHECK(pTagVal);
315✔
495
    char* ptname = taosArrayGet(tagName, 0);
315✔
496
    RAW_NULL_CHECK(ptname);
315✔
497
    cJSON* tname = cJSON_CreateString(ptname);
315✔
498
    RAW_NULL_CHECK(tname);
315✔
499
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "name", tname));
315✔
500
    cJSON* ttype = cJSON_CreateNumber(TSDB_DATA_TYPE_JSON);
315✔
501
    RAW_NULL_CHECK(ttype);
315✔
502
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "type", ttype));
315✔
503
    cJSON* tvalue = cJSON_CreateString(pJson);
315✔
504
    RAW_NULL_CHECK(tvalue);
315✔
505
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "value", tvalue));
315✔
506
    goto end;
315✔
507
  }
508

509
  for (int i = 0; i < taosArrayGetSize(pTagVals); i++) {
14,333✔
510
    STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, i);
10,141✔
511
    RAW_NULL_CHECK(pTagVal);
10,141✔
512
    cJSON* tag = cJSON_CreateObject();
10,141✔
513
    RAW_NULL_CHECK(tag);
10,141✔
514
    RAW_FALSE_CHECK(tmqAddJsonArrayItem(tags, tag));
10,141✔
515
    char* ptname = taosArrayGet(tagName, i);
10,141✔
516
    RAW_NULL_CHECK(ptname);
10,141✔
517
    cJSON* tname = cJSON_CreateString(ptname);
10,141✔
518
    RAW_NULL_CHECK(tname);
10,141✔
519
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "name", tname));
10,141✔
520
    cJSON* ttype = cJSON_CreateNumber(pTagVal->type);
10,141✔
521
    RAW_NULL_CHECK(ttype);
10,141✔
522
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "type", ttype));
10,141✔
523

524
    cJSON* tvalue = NULL;
10,141✔
525
    if (IS_VAR_DATA_TYPE(pTagVal->type)) {
13,408✔
526
      if (IS_STR_DATA_BLOB(pTagVal->type)) {
3,267✔
527
        goto end;
×
528
      }
529
      int64_t bufSize = 0;
3,267✔
530
      if (pTagVal->type == TSDB_DATA_TYPE_VARBINARY) {
3,267✔
531
        bufSize = pTagVal->nData * 2 + 2 + 3;
×
532
      } else {
533
        bufSize = pTagVal->nData + 3;
3,267✔
534
      }
535
      char* buf = taosMemoryCalloc(bufSize, 1);
3,267✔
536
      RAW_NULL_CHECK(buf);
3,267✔
537
      if (dataConverToStr(buf, bufSize, pTagVal->type, pTagVal->pData, pTagVal->nData, NULL) != TSDB_CODE_SUCCESS) {
3,267✔
538
        taosMemoryFree(buf);
×
539
        goto end;
×
540
      }
541

542
      tvalue = cJSON_CreateString(buf);
3,267✔
543
      taosMemoryFree(buf);
3,267✔
544
      RAW_NULL_CHECK(tvalue);
3,267✔
545
    } else {
546
      double val = 0;
6,874✔
547
      GET_TYPED_DATA(val, double, pTagVal->type, &pTagVal->i64,
6,874✔
548
                     0);  // currently tag type can't be decimal, so pass 0 as typeMod
549
      tvalue = cJSON_CreateNumber(val);
6,874✔
550
      RAW_NULL_CHECK(tvalue);
6,874✔
551
    }
552

553
    RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "value", tvalue));
10,141✔
554
  }
555

556
end:
4,822✔
557
  taosMemoryFree(pJson);
4,822✔
558
  taosArrayDestroy(pTagVals);
4,822✔
559
}
560

561
static void buildCreateCTableJson(SVCreateTbReq* pCreateReq, int32_t nReqs, cJSON** pJson) {
3,668✔
562
  if (pJson == NULL || pCreateReq == NULL) {
3,668✔
563
    uError("invalid parameter in %s", __func__);
×
564
    return;
×
565
  }
566
  int32_t code = 0;
3,668✔
567
  char*   string = NULL;
3,668✔
568
  cJSON*  json = cJSON_CreateObject();
3,668✔
569
  RAW_NULL_CHECK(json);
3,668✔
570
  cJSON* type = cJSON_CreateString("create");
3,668✔
571
  RAW_NULL_CHECK(type);
3,668✔
572
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
3,668✔
573

574
  cJSON* tableType = cJSON_CreateString("child");
3,668✔
575
  RAW_NULL_CHECK(tableType);
3,668✔
576
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableType", tableType));
3,668✔
577

578
  buildChildElement(json, pCreateReq);
3,668✔
579
  cJSON* createList = cJSON_CreateArray();
3,668✔
580
  RAW_NULL_CHECK(createList);
3,668✔
581
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "createList", createList));
3,668✔
582

583
  for (int i = 0; nReqs > 1 && i < nReqs; i++) {
4,822✔
584
    cJSON* create = cJSON_CreateObject();
1,154✔
585
    RAW_NULL_CHECK(create);
1,154✔
586
    buildChildElement(create, pCreateReq + i);
1,154✔
587
    RAW_FALSE_CHECK(tmqAddJsonArrayItem(createList, create));
1,154✔
588
  }
589

590
end:
3,668✔
591
  *pJson = json;
3,668✔
592
}
593

594
static void processCreateTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
4,091✔
595
  if (pJson == NULL || metaRsp == NULL) {
4,091✔
596
    uError("invalid parameter in %s", __func__);
×
597
    return;
×
598
  }
599
  SDecoder           decoder = {0};
4,091✔
600
  SVCreateTbBatchReq req = {0};
4,091✔
601
  SVCreateTbReq*     pCreateReq;
602
  // decode
603
  uDebug("create table data:%p", metaRsp);
4,091✔
604
  void*   data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
4,091✔
605
  int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
4,091✔
606
  tDecoderInit(&decoder, data, len);
4,091✔
607
  if (tDecodeSVCreateTbBatchReq(&decoder, &req) < 0) {
4,091✔
608
    goto end;
×
609
  }
610

611
  // loop to create table
612
  if (req.nReqs > 0) {
4,091✔
613
    pCreateReq = req.pReqs;
4,091✔
614
    if (pCreateReq->type == TSDB_CHILD_TABLE) {
4,091✔
615
      buildCreateCTableJson(req.pReqs, req.nReqs, pJson);
3,450✔
616
    } else if (pCreateReq->type == TSDB_NORMAL_TABLE) {
641✔
617
      buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->pExtSchemas, pCreateReq->name, pCreateReq->uid, TSDB_NORMAL_TABLE,
641✔
618
                           &pCreateReq->colCmpr, pJson);
619
    }
620
  }
621

622
end:
4,091✔
623
  uDebug("create table return");
4,091✔
624
  tDeleteSVCreateTbBatchReq(&req);
4,091✔
625
  tDecoderClear(&decoder);
4,091✔
626
}
627

628
static void processAutoCreateTable(SMqDataRsp* rsp, char** string) {
271✔
629
  if (rsp == NULL || string == NULL) {
271✔
630
    uError("invalid parameter in %s", __func__);
×
631
    return;
×
632
  }
633
  SDecoder*      decoder = NULL;
271✔
634
  SVCreateTbReq* pCreateReq = NULL;
271✔
635
  int32_t        code = 0;
271✔
636
  uDebug("auto create table data:%p", rsp);
271✔
637
  if (rsp->createTableNum <= 0) {
271✔
638
    uError("processAutoCreateTable rsp->createTableNum <= 0");
×
639
    goto end;
×
640
  }
641

642
  decoder = taosMemoryCalloc(rsp->createTableNum, sizeof(SDecoder));
271✔
643
  RAW_NULL_CHECK(decoder);
271✔
644
  pCreateReq = taosMemoryCalloc(rsp->createTableNum, sizeof(SVCreateTbReq));
271✔
645
  RAW_NULL_CHECK(pCreateReq);
271✔
646

647
  // loop to create table
648
  for (int32_t iReq = 0; iReq < rsp->createTableNum; iReq++) {
801✔
649
    // decode
650
    void** data = taosArrayGet(rsp->createTableReq, iReq);
530✔
651
    RAW_NULL_CHECK(data);
530✔
652
    int32_t* len = taosArrayGet(rsp->createTableLen, iReq);
530✔
653
    RAW_NULL_CHECK(len);
530✔
654
    tDecoderInit(&decoder[iReq], *data, *len);
530✔
655
    if (tDecodeSVCreateTbReq(&decoder[iReq], pCreateReq + iReq) < 0) {
530✔
656
      goto end;
×
657
    }
658

659
    if (pCreateReq[iReq].type != TSDB_CHILD_TABLE && pCreateReq[iReq].type != TSDB_NORMAL_TABLE) {
530✔
660
      uError("processAutoCreateTable pCreateReq[iReq].type != TSDB_CHILD_TABLE");
×
661
      goto end;
×
662
    }
663
  }
664
  cJSON* pJson = NULL;
271✔
665
  if (pCreateReq->type == TSDB_NORMAL_TABLE) {
271✔
666
    buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->pExtSchemas, pCreateReq->name, pCreateReq->uid, TSDB_NORMAL_TABLE,
53✔
667
                         &pCreateReq->colCmpr, &pJson);
668
  } else if (pCreateReq->type == TSDB_CHILD_TABLE) {
218✔
669
    buildCreateCTableJson(pCreateReq, rsp->createTableNum, &pJson);
218✔
670
  }
671

672
  *string = cJSON_PrintUnformatted(pJson);
271✔
673
  cJSON_Delete(pJson);
271✔
674

675
end:
271✔
676
  uDebug("auto created table return, sql json:%s", *string);
271✔
677
  for (int i = 0; decoder && pCreateReq && i < rsp->createTableNum; i++) {
801✔
678
    tDecoderClear(&decoder[i]);
530✔
679
    taosMemoryFreeClear(pCreateReq[i].comment);
530✔
680
    if (pCreateReq[i].type == TSDB_CHILD_TABLE) {
530✔
681
      taosArrayDestroy(pCreateReq[i].ctb.tagName);
477✔
682
    }
683
  }
684
  taosMemoryFree(decoder);
271✔
685
  taosMemoryFree(pCreateReq);
271✔
686
}
687

688
static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
1,007✔
689
  if (pJson == NULL || metaRsp == NULL) {
1,007✔
690
    uError("invalid parameter in %s", __func__);
×
691
    return;
×
692
  }
693
  SDecoder     decoder = {0};
1,007✔
694
  SVAlterTbReq vAlterTbReq = {0};
1,007✔
695
  char*        string = NULL;
1,007✔
696
  cJSON*       json = NULL;
1,007✔
697
  int32_t      code = 0;
1,007✔
698

699
  uDebug("alter table data:%p", metaRsp);
1,007✔
700
  // decode
701
  void*   data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
1,007✔
702
  int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
1,007✔
703
  tDecoderInit(&decoder, data, len);
1,007✔
704
  if (tDecodeSVAlterTbReq(&decoder, &vAlterTbReq) < 0) {
1,007✔
705
    uError("tDecodeSVAlterTbReq error");
×
706
    goto end;
×
707
  }
708

709
  json = cJSON_CreateObject();
1,007✔
710
  RAW_NULL_CHECK(json);
1,007✔
711
  cJSON* type = cJSON_CreateString("alter");
1,007✔
712
  RAW_NULL_CHECK(type);
1,007✔
713
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
1,007✔
714
  cJSON* tableType = cJSON_CreateString(vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL ||
1,802✔
715
                                                vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL
795✔
716
                                            ? "child"
717
                                            : "normal");
718
  RAW_NULL_CHECK(tableType);
1,007✔
719
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableType", tableType));
1,007✔
720
  cJSON* tableName = cJSON_CreateString(vAlterTbReq.tbName);
1,007✔
721
  RAW_NULL_CHECK(tableName);
1,007✔
722
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableName", tableName));
1,007✔
723
  cJSON* alterType = cJSON_CreateNumber(vAlterTbReq.action);
1,007✔
724
  RAW_NULL_CHECK(alterType);
1,007✔
725
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "alterType", alterType));
1,007✔
726

727
  switch (vAlterTbReq.action) {
1,007✔
728
    case TSDB_ALTER_TABLE_ADD_COLUMN: {
159✔
729
      cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
159✔
730
      RAW_NULL_CHECK(colName);
159✔
731
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
159✔
732
      cJSON* colType = cJSON_CreateNumber(vAlterTbReq.type);
159✔
733
      RAW_NULL_CHECK(colType);
159✔
734
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
159✔
735

736
      if (vAlterTbReq.type == TSDB_DATA_TYPE_BINARY || vAlterTbReq.type == TSDB_DATA_TYPE_VARBINARY ||
159✔
737
          vAlterTbReq.type == TSDB_DATA_TYPE_GEOMETRY) {
159✔
738
        int32_t length = vAlterTbReq.bytes - VARSTR_HEADER_SIZE;
×
739
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
740
        RAW_NULL_CHECK(cbytes);
×
741
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
742
      } else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR) {
159✔
743
        int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
744
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
745
        RAW_NULL_CHECK(cbytes);
×
746
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
747
      }
748
      break;
159✔
749
    }
750
    case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION: {
×
751
      cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
×
752
      RAW_NULL_CHECK(colName);
×
753
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
×
754
      cJSON* colType = cJSON_CreateNumber(vAlterTbReq.type);
×
755
      RAW_NULL_CHECK(colType);
×
756
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
×
757

758
      if (vAlterTbReq.type == TSDB_DATA_TYPE_BINARY || vAlterTbReq.type == TSDB_DATA_TYPE_VARBINARY ||
×
759
          vAlterTbReq.type == TSDB_DATA_TYPE_GEOMETRY) {
×
760
        int32_t length = vAlterTbReq.bytes - VARSTR_HEADER_SIZE;
×
761
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
762
        RAW_NULL_CHECK(cbytes);
×
763
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
764
      } else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR) {
×
765
        int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
×
766
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
767
        RAW_NULL_CHECK(cbytes);
×
768
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
769
      }
770
      RAW_RETURN_CHECK(setCompressOption(json, vAlterTbReq.compress));
×
771
      break;
×
772
    }
773
    case TSDB_ALTER_TABLE_DROP_COLUMN: {
159✔
774
      cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
159✔
775
      RAW_NULL_CHECK(colName);
159✔
776
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
159✔
777
      break;
159✔
778
    }
779
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: {
159✔
780
      cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
159✔
781
      RAW_NULL_CHECK(colName);
159✔
782
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
159✔
783
      cJSON* colType = cJSON_CreateNumber(vAlterTbReq.colModType);
159✔
784
      RAW_NULL_CHECK(colType);
159✔
785
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
159✔
786
      if (vAlterTbReq.colModType == TSDB_DATA_TYPE_BINARY || vAlterTbReq.colModType == TSDB_DATA_TYPE_VARBINARY ||
159✔
787
          vAlterTbReq.colModType == TSDB_DATA_TYPE_GEOMETRY) {
159✔
788
        int32_t length = vAlterTbReq.colModBytes - VARSTR_HEADER_SIZE;
×
789
        cJSON*  cbytes = cJSON_CreateNumber(length);
×
790
        RAW_NULL_CHECK(cbytes);
×
791
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
×
792
      } else if (vAlterTbReq.colModType == TSDB_DATA_TYPE_NCHAR) {
159✔
793
        int32_t length = (vAlterTbReq.colModBytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
159✔
794
        cJSON*  cbytes = cJSON_CreateNumber(length);
159✔
795
        RAW_NULL_CHECK(cbytes);
159✔
796
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
159✔
797
      }
798
      break;
159✔
799
    }
800
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: {
159✔
801
      cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
159✔
802
      RAW_NULL_CHECK(colName);
159✔
803
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
159✔
804
      cJSON* colNewName = cJSON_CreateString(vAlterTbReq.colNewName);
159✔
805
      RAW_NULL_CHECK(colNewName);
159✔
806
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colNewName", colNewName));
159✔
807
      break;
159✔
808
    }
809
    case TSDB_ALTER_TABLE_UPDATE_TAG_VAL: {
212✔
810
      cJSON* tagName = cJSON_CreateString(vAlterTbReq.tagName);
212✔
811
      RAW_NULL_CHECK(tagName);
212✔
812
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", tagName));
212✔
813

814
      bool isNull = vAlterTbReq.isNull;
212✔
815
      if (vAlterTbReq.tagType == TSDB_DATA_TYPE_JSON) {
212✔
816
        STag* jsonTag = (STag*)vAlterTbReq.pTagVal;
×
817
        if (jsonTag->nTag == 0) isNull = true;
×
818
      }
819
      if (!isNull) {
212✔
820
        char* buf = NULL;
212✔
821

822
        if (vAlterTbReq.tagType == TSDB_DATA_TYPE_JSON) {
212✔
823
          if (!tTagIsJson(vAlterTbReq.pTagVal)) {
×
824
            uError("processAlterTable isJson false");
×
825
            goto end;
×
826
          }
827
          parseTagDatatoJson(vAlterTbReq.pTagVal, &buf, NULL);
×
828
          if (buf == NULL) {
×
829
            uError("parseTagDatatoJson failed, buf == NULL");
×
830
            goto end;
×
831
          }
832
        } else {
833
          int64_t bufSize = 0;
212✔
834
          if (vAlterTbReq.tagType == TSDB_DATA_TYPE_VARBINARY) {
212✔
835
            bufSize = vAlterTbReq.nTagVal * 2 + 2 + 3;
×
836
          } else {
837
            bufSize = vAlterTbReq.nTagVal + 32;
212✔
838
          }
839
          buf = taosMemoryCalloc(bufSize, 1);
212✔
840
          RAW_NULL_CHECK(buf);
212✔
841
          if (dataConverToStr(buf, bufSize, vAlterTbReq.tagType, vAlterTbReq.pTagVal, vAlterTbReq.nTagVal, NULL) !=
212✔
842
              TSDB_CODE_SUCCESS) {
843
            taosMemoryFree(buf);
×
844
            goto end;
×
845
          }
846
        }
847

848
        cJSON* colValue = cJSON_CreateString(buf);
212✔
849
        taosMemoryFree(buf);
212✔
850
        RAW_NULL_CHECK(colValue);
212✔
851
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colValue", colValue));
212✔
852
      }
853

854
      cJSON* isNullCJson = cJSON_CreateBool(isNull);
212✔
855
      RAW_NULL_CHECK(isNullCJson);
212✔
856
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colValueNull", isNullCJson));
212✔
857
      break;
212✔
858
    }
859
    case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: {
×
860
      int32_t nTags = taosArrayGetSize(vAlterTbReq.pMultiTag);
×
861
      if (nTags <= 0) {
×
862
        uError("processAlterTable parse multi tags error");
×
863
        goto end;
×
864
      }
865

866
      cJSON* tags = cJSON_CreateArray();
×
867
      RAW_NULL_CHECK(tags);
×
868
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tags", tags));
×
869

870
      for (int32_t i = 0; i < nTags; i++) {
×
871
        cJSON* member = cJSON_CreateObject();
×
872
        RAW_NULL_CHECK(member);
×
873
        RAW_FALSE_CHECK(tmqAddJsonArrayItem(tags, member));
×
874

875
        SMultiTagUpateVal* pTagVal = taosArrayGet(vAlterTbReq.pMultiTag, i);
×
876
        cJSON*             tagName = cJSON_CreateString(pTagVal->tagName);
×
877
        RAW_NULL_CHECK(tagName);
×
878
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(member, "colName", tagName));
×
879

880
        if (pTagVal->tagType == TSDB_DATA_TYPE_JSON) {
×
881
          uError("processAlterTable isJson false");
×
882
          goto end;
×
883
        }
884
        bool isNull = pTagVal->isNull;
×
885
        if (!isNull) {
×
886
          int64_t bufSize = 0;
×
887
          if (pTagVal->tagType == TSDB_DATA_TYPE_VARBINARY) {
×
888
            bufSize = pTagVal->nTagVal * 2 + 2 + 3;
×
889
          } else {
890
            bufSize = pTagVal->nTagVal + 3;
×
891
          }
892
          char* buf = taosMemoryCalloc(bufSize, 1);
×
893
          RAW_NULL_CHECK(buf);
×
894
          if (dataConverToStr(buf, bufSize, pTagVal->tagType, pTagVal->pTagVal, pTagVal->nTagVal, NULL) !=
×
895
              TSDB_CODE_SUCCESS) {
896
            taosMemoryFree(buf);
×
897
            goto end;
×
898
          }
899
          cJSON* colValue = cJSON_CreateString(buf);
×
900
          taosMemoryFree(buf);
×
901
          RAW_NULL_CHECK(colValue);
×
902
          RAW_FALSE_CHECK(tmqAddJsonObjectItem(member, "colValue", colValue));
×
903
        }
904
        cJSON* isNullCJson = cJSON_CreateBool(isNull);
×
905
        RAW_NULL_CHECK(isNullCJson);
×
906
        RAW_FALSE_CHECK(tmqAddJsonObjectItem(member, "colValueNull", isNullCJson));
×
907
      }
908
      break;
×
909
    }
910

911
    case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: {
×
912
      cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
×
913
      RAW_NULL_CHECK(colName);
×
914
      RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
×
915
      RAW_RETURN_CHECK(setCompressOption(json, vAlterTbReq.compress));
×
916
      break;
×
917
    }
918
    default:
159✔
919
      break;
159✔
920
  }
921

922
end:
1,007✔
923
  uDebug("alter table return");
1,007✔
924
  if (vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL) {
1,007✔
925
    taosArrayDestroy(vAlterTbReq.pMultiTag);
×
926
  }
927
  tDecoderClear(&decoder);
1,007✔
928
  *pJson = json;
1,007✔
929
}
930

931
static void processDropSTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
256✔
932
  if (pJson == NULL || metaRsp == NULL) {
256✔
933
    uError("invalid parameter in %s", __func__);
×
934
    return;
×
935
  }
936
  SDecoder     decoder = {0};
256✔
937
  SVDropStbReq req = {0};
256✔
938
  cJSON*       json = NULL;
256✔
939
  int32_t      code = 0;
256✔
940

941
  uDebug("processDropSTable data:%p", metaRsp);
256✔
942

943
  // decode
944
  void*   data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
256✔
945
  int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
256✔
946
  tDecoderInit(&decoder, data, len);
256✔
947
  if (tDecodeSVDropStbReq(&decoder, &req) < 0) {
256✔
948
    uError("tDecodeSVDropStbReq failed");
×
949
    goto end;
×
950
  }
951

952
  json = cJSON_CreateObject();
256✔
953
  RAW_NULL_CHECK(json);
256✔
954
  cJSON* type = cJSON_CreateString("drop");
256✔
955
  RAW_NULL_CHECK(type);
256✔
956
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
256✔
957
  cJSON* tableType = cJSON_CreateString("super");
256✔
958
  RAW_NULL_CHECK(tableType);
256✔
959
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableType", tableType));
256✔
960
  cJSON* tableName = cJSON_CreateString(req.name);
256✔
961
  RAW_NULL_CHECK(tableName);
256✔
962
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableName", tableName));
256✔
963

964
end:
256✔
965
  uDebug("processDropSTable return");
256✔
966
  tDecoderClear(&decoder);
256✔
967
  *pJson = json;
256✔
968
}
969
static void processDeleteTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
106✔
970
  if (pJson == NULL || metaRsp == NULL) {
106✔
971
    uError("invalid parameter in %s", __func__);
×
972
    return;
×
973
  }
974
  SDeleteRes req = {0};
106✔
975
  SDecoder   coder = {0};
106✔
976
  cJSON*     json = NULL;
106✔
977
  int32_t    code = 0;
106✔
978

979
  uDebug("processDeleteTable data:%p", metaRsp);
106✔
980
  // decode and process req
981
  void*   data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
106✔
982
  int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
106✔
983

984
  tDecoderInit(&coder, data, len);
106✔
985
  if (tDecodeDeleteRes(&coder, &req) < 0) {
106✔
986
    uError("tDecodeDeleteRes failed");
×
987
    goto end;
×
988
  }
989

990
  //  getTbName(req.tableFName);
991
  char sql[256] = {0};
106✔
992
  (void)snprintf(sql, sizeof(sql), "delete from `%s` where `%s` >= %" PRId64 " and `%s` <= %" PRId64, req.tableFName,
106✔
993
                 req.tsColName, req.skey, req.tsColName, req.ekey);
994

995
  json = cJSON_CreateObject();
106✔
996
  RAW_NULL_CHECK(json);
106✔
997
  cJSON* type = cJSON_CreateString("delete");
106✔
998
  RAW_NULL_CHECK(type);
106✔
999
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
106✔
1000
  cJSON* sqlJson = cJSON_CreateString(sql);
106✔
1001
  RAW_NULL_CHECK(sqlJson);
106✔
1002
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "sql", sqlJson));
106✔
1003

1004
end:
106✔
1005
  uDebug("processDeleteTable return");
106✔
1006
  tDecoderClear(&coder);
106✔
1007
  *pJson = json;
106✔
1008
}
1009

1010
static void processDropTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
181✔
1011
  if (pJson == NULL || metaRsp == NULL) {
181✔
1012
    uError("invalid parameter in %s", __func__);
×
1013
    return;
×
1014
  }
1015
  SDecoder         decoder = {0};
181✔
1016
  SVDropTbBatchReq req = {0};
181✔
1017
  cJSON*           json = NULL;
181✔
1018
  int32_t          code = 0;
181✔
1019

1020
  uDebug("processDropTable data:%p", metaRsp);
181✔
1021
  // decode
1022
  void*   data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
181✔
1023
  int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
181✔
1024
  tDecoderInit(&decoder, data, len);
181✔
1025
  if (tDecodeSVDropTbBatchReq(&decoder, &req) < 0) {
181✔
1026
    uError("tDecodeSVDropTbBatchReq failed");
×
1027
    goto end;
×
1028
  }
1029

1030
  json = cJSON_CreateObject();
181✔
1031
  RAW_NULL_CHECK(json);
181✔
1032
  cJSON* type = cJSON_CreateString("drop");
181✔
1033
  RAW_NULL_CHECK(type);
181✔
1034
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
181✔
1035
  cJSON* tableNameList = cJSON_CreateArray();
181✔
1036
  RAW_NULL_CHECK(tableNameList);
181✔
1037
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableNameList", tableNameList));
181✔
1038

1039
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
415✔
1040
    SVDropTbReq* pDropTbReq = req.pReqs + iReq;
234✔
1041
    cJSON*       tableName = cJSON_CreateString(pDropTbReq->name);
234✔
1042
    RAW_NULL_CHECK(tableName);
234✔
1043
    RAW_FALSE_CHECK(tmqAddJsonArrayItem(tableNameList, tableName));
234✔
1044
  }
1045

1046
end:
181✔
1047
  uDebug("processDropTable return");
181✔
1048
  tDecoderClear(&decoder);
181✔
1049
  *pJson = json;
181✔
1050
}
1051

1052
static int32_t taosCreateStb(TAOS* taos, void* meta, uint32_t metaLen) {
3,755✔
1053
  if (taos == NULL || meta == NULL) {
3,755✔
1054
    uError("invalid parameter in %s", __func__);
×
1055
    return TSDB_CODE_INVALID_PARA;
×
1056
  }
1057
  SVCreateStbReq req = {0};
3,755✔
1058
  SDecoder       coder = {0};
3,755✔
1059
  SMCreateStbReq pReq = {0};
3,755✔
1060
  int32_t        code = TSDB_CODE_SUCCESS;
3,755✔
1061
  SRequestObj*   pRequest = NULL;
3,755✔
1062

1063
  RAW_RETURN_CHECK(buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0));
3,755✔
1064
  uDebug(LOG_ID_TAG " create stable, meta:%p, metaLen:%d", LOG_ID_VALUE, meta, metaLen);
3,755✔
1065
  pRequest->syncQuery = true;
3,755✔
1066
  if (!pRequest->pDb) {
3,755✔
1067
    code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1068
    goto end;
×
1069
  }
1070
  // decode and process req
1071
  void*    data = POINTER_SHIFT(meta, sizeof(SMsgHead));
3,755✔
1072
  uint32_t len = metaLen - sizeof(SMsgHead);
3,755✔
1073
  tDecoderInit(&coder, data, len);
3,755✔
1074
  if (tDecodeSVCreateStbReq(&coder, &req) < 0) {
3,755✔
1075
    code = TSDB_CODE_INVALID_PARA;
×
1076
    goto end;
×
1077
  }
1078

1079
  int8_t           createDefaultCompress = 0;
3,755✔
1080
  SColCmprWrapper* p = &req.colCmpr;
3,755✔
1081
  if (p->nCols == 0) {
3,755✔
1082
    createDefaultCompress = 1;
×
1083
  }
1084
  // build create stable
1085
  pReq.pColumns = taosArrayInit(req.schemaRow.nCols, sizeof(SFieldWithOptions));
3,755✔
1086
  RAW_NULL_CHECK(pReq.pColumns);
3,755✔
1087
  for (int32_t i = 0; i < req.schemaRow.nCols; i++) {
27,749✔
1088
    SSchema*          pSchema = req.schemaRow.pSchema + i;
23,994✔
1089
    SFieldWithOptions field = {.type = pSchema->type, .flags = pSchema->flags, .bytes = pSchema->bytes};
23,994✔
1090
    tstrncpy(field.name, pSchema->name, TSDB_COL_NAME_LEN);
23,994✔
1091

1092
    if (createDefaultCompress) {
23,994✔
1093
      field.compress = createDefaultColCmprByType(pSchema->type);
×
1094
    } else {
1095
      SColCmpr* pCmp = &req.colCmpr.pColCmpr[i];
23,994✔
1096
      field.compress = pCmp->alg;
23,994✔
1097
    }
1098
    if (req.pExtSchemas) field.typeMod = req.pExtSchemas[i].typeMod;
23,994✔
1099
    RAW_NULL_CHECK(taosArrayPush(pReq.pColumns, &field));
47,988✔
1100
  }
1101
  pReq.pTags = taosArrayInit(req.schemaTag.nCols, sizeof(SField));
3,755✔
1102
  RAW_NULL_CHECK(pReq.pTags);
3,755✔
1103
  for (int32_t i = 0; i < req.schemaTag.nCols; i++) {
13,959✔
1104
    SSchema* pSchema = req.schemaTag.pSchema + i;
10,204✔
1105
    SField   field = {.type = pSchema->type, .flags = pSchema->flags, .bytes = pSchema->bytes};
10,204✔
1106
    tstrncpy(field.name, pSchema->name, TSDB_COL_NAME_LEN);
10,204✔
1107
    RAW_NULL_CHECK(taosArrayPush(pReq.pTags, &field));
20,408✔
1108
  }
1109

1110
  pReq.colVer = req.schemaRow.version;
3,755✔
1111
  pReq.tagVer = req.schemaTag.version;
3,755✔
1112
  pReq.numOfColumns = req.schemaRow.nCols;
3,755✔
1113
  pReq.numOfTags = req.schemaTag.nCols;
3,755✔
1114
  pReq.commentLen = -1;
3,755✔
1115
  pReq.suid = processSuid(req.suid, pRequest->pDb);
3,755✔
1116
  pReq.source = TD_REQ_FROM_TAOX;
3,755✔
1117
  pReq.igExists = true;
3,755✔
1118

1119
  uDebug(LOG_ID_TAG " create stable name:%s suid:%" PRId64 " processSuid:%" PRId64, LOG_ID_VALUE, req.name, req.suid,
3,755✔
1120
         pReq.suid);
1121
  STscObj* pTscObj = pRequest->pTscObj;
3,755✔
1122
  SName    tableName = {0};
3,755✔
1123
  toName(pTscObj->acctId, pRequest->pDb, req.name, &tableName);
3,755✔
1124
  RAW_RETURN_CHECK(tNameExtractFullName(&tableName, pReq.name));
3,755✔
1125
  SCmdMsgInfo pCmdMsg = {0};
3,755✔
1126
  pCmdMsg.epSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
3,755✔
1127
  pCmdMsg.msgType = TDMT_MND_CREATE_STB;
3,755✔
1128
  pCmdMsg.msgLen = tSerializeSMCreateStbReq(NULL, 0, &pReq);
3,755✔
1129
  if (pCmdMsg.msgLen <= 0) {
3,755✔
1130
    code = TSDB_CODE_INVALID_PARA;
×
1131
    goto end;
×
1132
  }
1133
  pCmdMsg.pMsg = taosMemoryMalloc(pCmdMsg.msgLen);
3,755✔
1134
  RAW_NULL_CHECK(pCmdMsg.pMsg);
3,755✔
1135
  if (tSerializeSMCreateStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq) <= 0) {
3,755✔
1136
    code = TSDB_CODE_INVALID_PARA;
×
1137
    taosMemoryFree(pCmdMsg.pMsg);
×
1138
    goto end;
×
1139
  }
1140

1141
  SQuery pQuery = {0};
3,755✔
1142
  pQuery.execMode = QUERY_EXEC_MODE_RPC;
3,755✔
1143
  pQuery.pCmdMsg = &pCmdMsg;
3,755✔
1144
  pQuery.msgType = pQuery.pCmdMsg->msgType;
3,755✔
1145
  pQuery.stableQuery = true;
3,755✔
1146

1147
  launchQueryImpl(pRequest, &pQuery, true, NULL);  // ignore, because return value is pRequest
3,755✔
1148

1149
  taosMemoryFree(pCmdMsg.pMsg);
3,755✔
1150

1151
  if (pRequest->code == TSDB_CODE_SUCCESS) {
3,755✔
1152
    SCatalog* pCatalog = NULL;
3,755✔
1153
    RAW_RETURN_CHECK(catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog));
3,755✔
1154
    RAW_RETURN_CHECK(catalogRemoveTableMeta(pCatalog, &tableName));
3,755✔
1155
  }
1156

1157
  code = pRequest->code;
3,755✔
1158

1159
end:
3,755✔
1160
  uDebug(LOG_ID_TAG " create stable return, msg:%s", LOG_ID_VALUE, tstrerror(code));
3,755✔
1161
  destroyRequest(pRequest);
3,755✔
1162
  tFreeSMCreateStbReq(&pReq);
3,755✔
1163
  tDecoderClear(&coder);
3,755✔
1164
  return code;
3,755✔
1165
}
1166

1167
static int32_t taosDropStb(TAOS* taos, void* meta, uint32_t metaLen) {
256✔
1168
  if (taos == NULL || meta == NULL) {
256✔
1169
    uError("invalid parameter in %s", __func__);
×
1170
    return TSDB_CODE_INVALID_PARA;
×
1171
  }
1172
  SVDropStbReq req = {0};
256✔
1173
  SDecoder     coder = {0};
256✔
1174
  SMDropStbReq pReq = {0};
256✔
1175
  int32_t      code = TSDB_CODE_SUCCESS;
256✔
1176
  SRequestObj* pRequest = NULL;
256✔
1177

1178
  RAW_RETURN_CHECK(buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0));
256✔
1179
  uDebug(LOG_ID_TAG " drop stable, meta:%p, metaLen:%d", LOG_ID_VALUE, meta, metaLen);
256✔
1180
  pRequest->syncQuery = true;
256✔
1181
  if (!pRequest->pDb) {
256✔
1182
    code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1183
    goto end;
×
1184
  }
1185
  // decode and process req
1186
  void*    data = POINTER_SHIFT(meta, sizeof(SMsgHead));
256✔
1187
  uint32_t len = metaLen - sizeof(SMsgHead);
256✔
1188
  tDecoderInit(&coder, data, len);
256✔
1189
  if (tDecodeSVDropStbReq(&coder, &req) < 0) {
256✔
1190
    code = TSDB_CODE_INVALID_PARA;
×
1191
    goto end;
×
1192
  }
1193

1194
  SCatalog* pCatalog = NULL;
256✔
1195
  RAW_RETURN_CHECK(catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog));
256✔
1196
  SRequestConnInfo conn = {.pTrans = pRequest->pTscObj->pAppInfo->pTransporter,
256✔
1197
                           .requestId = pRequest->requestId,
256✔
1198
                           .requestObjRefId = pRequest->self,
256✔
1199
                           .mgmtEps = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp)};
256✔
1200
  SName            pName = {0};
256✔
1201
  toName(pRequest->pTscObj->acctId, pRequest->pDb, req.name, &pName);
256✔
1202
  STableMeta* pTableMeta = NULL;
256✔
1203
  code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
256✔
1204
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
256✔
1205
    code = TSDB_CODE_SUCCESS;
50✔
1206
    taosMemoryFreeClear(pTableMeta);
50✔
1207
    goto end;
50✔
1208
  }
1209
  if (code != TSDB_CODE_SUCCESS) {
206✔
1210
    goto end;
×
1211
  }
1212
  pReq.suid = pTableMeta->uid;
206✔
1213
  taosMemoryFreeClear(pTableMeta);
206✔
1214

1215
  // build drop stable
1216
  pReq.igNotExists = true;
206✔
1217
  pReq.source = TD_REQ_FROM_TAOX;
206✔
1218
  //  pReq.suid = processSuid(req.suid, pRequest->pDb);
1219

1220
  uDebug(LOG_ID_TAG " drop stable name:%s suid:%" PRId64 " new suid:%" PRId64, LOG_ID_VALUE, req.name, req.suid,
206✔
1221
         pReq.suid);
1222
  STscObj* pTscObj = pRequest->pTscObj;
206✔
1223
  SName    tableName = {0};
206✔
1224
  toName(pTscObj->acctId, pRequest->pDb, req.name, &tableName);
206✔
1225
  if (tNameExtractFullName(&tableName, pReq.name) != 0) {
206✔
1226
    code = TSDB_CODE_INVALID_PARA;
×
1227
    goto end;
×
1228
  }
1229

1230
  SCmdMsgInfo pCmdMsg = {0};
206✔
1231
  pCmdMsg.epSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
206✔
1232
  pCmdMsg.msgType = TDMT_MND_DROP_STB;
206✔
1233
  pCmdMsg.msgLen = tSerializeSMDropStbReq(NULL, 0, &pReq);
206✔
1234
  if (pCmdMsg.msgLen <= 0) {
206✔
1235
    code = TSDB_CODE_INVALID_PARA;
×
1236
    goto end;
×
1237
  }
1238
  pCmdMsg.pMsg = taosMemoryMalloc(pCmdMsg.msgLen);
206✔
1239
  RAW_NULL_CHECK(pCmdMsg.pMsg);
206✔
1240
  if (tSerializeSMDropStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq) <= 0) {
206✔
1241
    code = TSDB_CODE_INVALID_PARA;
×
1242
    taosMemoryFree(pCmdMsg.pMsg);
×
1243
    goto end;
×
1244
  }
1245

1246
  SQuery pQuery = {0};
206✔
1247
  pQuery.execMode = QUERY_EXEC_MODE_RPC;
206✔
1248
  pQuery.pCmdMsg = &pCmdMsg;
206✔
1249
  pQuery.msgType = pQuery.pCmdMsg->msgType;
206✔
1250
  pQuery.stableQuery = true;
206✔
1251

1252
  launchQueryImpl(pRequest, &pQuery, true, NULL);  // ignore, because return value is pRequest
206✔
1253
  taosMemoryFree(pCmdMsg.pMsg);
206✔
1254
  if (pRequest->code == TSDB_CODE_SUCCESS) {
206✔
1255
    // ignore the error code
1256
    RAW_RETURN_CHECK(catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog));
206✔
1257
    RAW_RETURN_CHECK(catalogRemoveTableMeta(pCatalog, &tableName));
206✔
1258
  }
1259

1260
  code = pRequest->code;
206✔
1261

1262
end:
256✔
1263
  uDebug(LOG_ID_TAG " drop stable return, msg:%s", LOG_ID_VALUE, tstrerror(code));
256✔
1264
  destroyRequest(pRequest);
256✔
1265
  tDecoderClear(&coder);
256✔
1266
  return code;
256✔
1267
}
1268

1269
typedef struct SVgroupCreateTableBatch {
1270
  SVCreateTbBatchReq req;
1271
  SVgroupInfo        info;
1272
  char               dbName[TSDB_DB_NAME_LEN];
1273
} SVgroupCreateTableBatch;
1274

1275
static void destroyCreateTbReqBatch(void* data) {
4,001✔
1276
  if (data == NULL) {
4,001✔
1277
    uError("invalid parameter in %s", __func__);
×
1278
    return;
×
1279
  }
1280
  SVgroupCreateTableBatch* pTbBatch = (SVgroupCreateTableBatch*)data;
4,001✔
1281
  taosArrayDestroy(pTbBatch->req.pArray);
4,001✔
1282
}
1283

1284
static int32_t taosCreateTable(TAOS* taos, void* meta, uint32_t metaLen) {
3,942✔
1285
  if (taos == NULL || meta == NULL) {
3,942✔
1286
    uError("invalid parameter in %s", __func__);
×
1287
    return TSDB_CODE_INVALID_PARA;
×
1288
  }
1289
  SVCreateTbBatchReq req = {0};
3,942✔
1290
  SDecoder           coder = {0};
3,942✔
1291
  int32_t            code = TSDB_CODE_SUCCESS;
3,942✔
1292
  SRequestObj*       pRequest = NULL;
3,942✔
1293
  SQuery*            pQuery = NULL;
3,942✔
1294
  SHashObj*          pVgroupHashmap = NULL;
3,942✔
1295
  SArray*            pTagList = taosArrayInit(0, POINTER_BYTES);
3,942✔
1296
  RAW_NULL_CHECK(pTagList);
3,942✔
1297
  RAW_RETURN_CHECK(buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0));
3,942✔
1298
  uDebug(LOG_ID_TAG " create table, meta:%p, metaLen:%d", LOG_ID_VALUE, meta, metaLen);
3,942✔
1299

1300
  pRequest->syncQuery = true;
3,942✔
1301
  if (!pRequest->pDb) {
3,942✔
1302
    code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1303
    goto end;
×
1304
  }
1305
  // decode and process req
1306
  void*    data = POINTER_SHIFT(meta, sizeof(SMsgHead));
3,942✔
1307
  uint32_t len = metaLen - sizeof(SMsgHead);
3,942✔
1308
  tDecoderInit(&coder, data, len);
3,942✔
1309
  if (tDecodeSVCreateTbBatchReq(&coder, &req) < 0) {
3,942✔
1310
    code = TSDB_CODE_INVALID_PARA;
×
1311
    goto end;
×
1312
  }
1313

1314
  STscObj* pTscObj = pRequest->pTscObj;
3,942✔
1315

1316
  SVCreateTbReq* pCreateReq = NULL;
3,942✔
1317
  SCatalog*      pCatalog = NULL;
3,942✔
1318
  RAW_RETURN_CHECK(catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog));
3,942✔
1319
  pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
3,942✔
1320
  RAW_NULL_CHECK(pVgroupHashmap);
3,942✔
1321
  taosHashSetFreeFp(pVgroupHashmap, destroyCreateTbReqBatch);
3,942✔
1322

1323
  SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter,
3,942✔
1324
                           .requestId = pRequest->requestId,
3,942✔
1325
                           .requestObjRefId = pRequest->self,
3,942✔
1326
                           .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)};
3,942✔
1327

1328
  pRequest->tableList = taosArrayInit(req.nReqs, sizeof(SName));
3,942✔
1329
  RAW_NULL_CHECK(pRequest->tableList);
3,942✔
1330
  // loop to create table
1331
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
8,461✔
1332
    pCreateReq = req.pReqs + iReq;
4,519✔
1333

1334
    SVgroupInfo pInfo = {0};
4,519✔
1335
    SName       pName = {0};
4,519✔
1336
    toName(pTscObj->acctId, pRequest->pDb, pCreateReq->name, &pName);
4,519✔
1337
    code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &pInfo);
4,519✔
1338
    if (code != TSDB_CODE_SUCCESS) {
4,519✔
1339
      goto end;
×
1340
    }
1341

1342
    pCreateReq->flags |= TD_CREATE_IF_NOT_EXISTS;
4,519✔
1343
    // change tag cid to new cid
1344
    if (pCreateReq->type == TSDB_CHILD_TABLE) {
4,519✔
1345
      STableMeta* pTableMeta = NULL;
3,931✔
1346
      SName       sName = {0};
3,931✔
1347
      tb_uid_t    oldSuid = pCreateReq->ctb.suid;
3,931✔
1348
      //      pCreateReq->ctb.suid = processSuid(pCreateReq->ctb.suid, pRequest->pDb);
1349
      toName(pTscObj->acctId, pRequest->pDb, pCreateReq->ctb.stbName, &sName);
3,931✔
1350
      code = catalogGetTableMeta(pCatalog, &conn, &sName, &pTableMeta);
3,931✔
1351
      if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
3,931✔
1352
        code = TSDB_CODE_SUCCESS;
×
1353
        taosMemoryFreeClear(pTableMeta);
×
1354
        continue;
×
1355
      }
1356

1357
      if (code != TSDB_CODE_SUCCESS) {
3,931✔
1358
        goto end;
×
1359
      }
1360
      pCreateReq->ctb.suid = pTableMeta->uid;
3,931✔
1361

1362
      SArray* pTagVals = NULL;
3,931✔
1363
      code = tTagToValArray((STag*)pCreateReq->ctb.pTag, &pTagVals);
3,931✔
1364
      if (code != TSDB_CODE_SUCCESS) {
3,931✔
1365
        taosMemoryFreeClear(pTableMeta);
×
1366
        goto end;
×
1367
      }
1368

1369
      bool rebuildTag = false;
3,931✔
1370
      for (int32_t i = 0; i < taosArrayGetSize(pCreateReq->ctb.tagName); i++) {
12,171✔
1371
        char* tName = taosArrayGet(pCreateReq->ctb.tagName, i);
8,240✔
1372
        if (tName == NULL) {
8,240✔
1373
          continue;
×
1374
        }
1375
        for (int32_t j = pTableMeta->tableInfo.numOfColumns;
8,240✔
1376
             j < pTableMeta->tableInfo.numOfColumns + pTableMeta->tableInfo.numOfTags; j++) {
32,356✔
1377
          SSchema* tag = &pTableMeta->schema[j];
24,116✔
1378
          if (strcmp(tag->name, tName) == 0 && tag->type != TSDB_DATA_TYPE_JSON) {
24,116✔
1379
            STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, i);
7,766✔
1380
            if (pTagVal) {
7,766✔
1381
              if (pTagVal->cid != tag->colId) {
7,766✔
1382
                pTagVal->cid = tag->colId;
629✔
1383
                rebuildTag = true;
629✔
1384
              }
1385
            } else {
1386
              uError("create tb invalid data %s, size:%d index:%d cid:%d", pCreateReq->name,
×
1387
                     (int)taosArrayGetSize(pTagVals), i, tag->colId);
1388
            }
1389
          }
1390
        }
1391
      }
1392
      taosMemoryFreeClear(pTableMeta);
3,931✔
1393
      if (rebuildTag) {
3,931✔
1394
        STag* ppTag = NULL;
401✔
1395
        code = tTagNew(pTagVals, 1, false, &ppTag);
401✔
1396
        taosArrayDestroy(pTagVals);
401✔
1397
        pTagVals = NULL;
401✔
1398
        if (code != TSDB_CODE_SUCCESS) {
401✔
1399
          goto end;
×
1400
        }
1401
        if (NULL == taosArrayPush(pTagList, &ppTag)) {
401✔
1402
          tTagFree(ppTag);
×
1403
          goto end;
×
1404
        }
1405
        pCreateReq->ctb.pTag = (uint8_t*)ppTag;
401✔
1406
      }
1407
      taosArrayDestroy(pTagVals);
3,931✔
1408
    }
1409
    RAW_NULL_CHECK(taosArrayPush(pRequest->tableList, &pName));
9,038✔
1410

1411
    SVgroupCreateTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pInfo.vgId, sizeof(pInfo.vgId));
4,519✔
1412
    if (pTableBatch == NULL) {
4,519✔
1413
      SVgroupCreateTableBatch tBatch = {0};
4,001✔
1414
      tBatch.info = pInfo;
4,001✔
1415
      tstrncpy(tBatch.dbName, pRequest->pDb, TSDB_DB_NAME_LEN);
4,001✔
1416

1417
      tBatch.req.pArray = taosArrayInit(4, sizeof(struct SVCreateTbReq));
4,001✔
1418
      RAW_NULL_CHECK(tBatch.req.pArray);
4,001✔
1419
      RAW_NULL_CHECK(taosArrayPush(tBatch.req.pArray, pCreateReq));
8,002✔
1420
      tBatch.req.source = TD_REQ_FROM_TAOX;
4,001✔
1421
      RAW_RETURN_CHECK(taosHashPut(pVgroupHashmap, &pInfo.vgId, sizeof(pInfo.vgId), &tBatch, sizeof(tBatch)));
4,001✔
1422
    } else {  // add to the correct vgroup
1423
      RAW_NULL_CHECK(taosArrayPush(pTableBatch->req.pArray, pCreateReq));
1,036✔
1424
    }
1425
  }
1426

1427
  if (taosHashGetSize(pVgroupHashmap) == 0) {
3,942✔
1428
    goto end;
×
1429
  }
1430
  SArray* pBufArray = NULL;
3,942✔
1431
  RAW_RETURN_CHECK(serializeVgroupsCreateTableBatch(pVgroupHashmap, &pBufArray));
3,942✔
1432
  pQuery = NULL;
3,942✔
1433
  code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pQuery);
3,942✔
1434
  if (TSDB_CODE_SUCCESS != code) goto end;
3,942✔
1435
  pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
3,942✔
1436
  pQuery->msgType = TDMT_VND_CREATE_TABLE;
3,942✔
1437
  pQuery->stableQuery = false;
3,942✔
1438
  code = nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT, &pQuery->pRoot);
3,942✔
1439
  if (TSDB_CODE_SUCCESS != code) goto end;
3,942✔
1440
  RAW_NULL_CHECK(pQuery->pRoot);
3,942✔
1441

1442
  RAW_RETURN_CHECK(rewriteToVnodeModifyOpStmt(pQuery, pBufArray));
3,942✔
1443

1444
  launchQueryImpl(pRequest, pQuery, true, NULL);
3,942✔
1445
  if (pRequest->code == TSDB_CODE_SUCCESS) {
3,942✔
1446
    RAW_RETURN_CHECK(removeMeta(pTscObj, pRequest->tableList, false));
3,942✔
1447
  }
1448

1449
  code = pRequest->code;
3,942✔
1450

1451
end:
3,942✔
1452
  uDebug(LOG_ID_TAG " create table return, msg:%s", LOG_ID_VALUE, tstrerror(code));
3,942✔
1453
  tDeleteSVCreateTbBatchReq(&req);
3,942✔
1454

1455
  taosHashCleanup(pVgroupHashmap);
3,942✔
1456
  destroyRequest(pRequest);
3,942✔
1457
  tDecoderClear(&coder);
3,942✔
1458
  qDestroyQuery(pQuery);
3,942✔
1459
  taosArrayDestroyP(pTagList, NULL);
3,942✔
1460
  return code;
3,942✔
1461
}
1462

1463
typedef struct SVgroupDropTableBatch {
1464
  SVDropTbBatchReq req;
1465
  SVgroupInfo      info;
1466
  char             dbName[TSDB_DB_NAME_LEN];
1467
} SVgroupDropTableBatch;
1468

1469
static void destroyDropTbReqBatch(void* data) {
131✔
1470
  if (data == NULL) {
131✔
1471
    uError("invalid parameter in %s", __func__);
×
1472
    return;
×
1473
  }
1474
  SVgroupDropTableBatch* pTbBatch = (SVgroupDropTableBatch*)data;
131✔
1475
  taosArrayDestroy(pTbBatch->req.pArray);
131✔
1476
}
1477

1478
static int32_t taosDropTable(TAOS* taos, void* meta, uint32_t metaLen) {
181✔
1479
  if (taos == NULL || meta == NULL) {
181✔
1480
    uError("invalid parameter in %s", __func__);
×
1481
    return TSDB_CODE_INVALID_PARA;
×
1482
  }
1483
  SVDropTbBatchReq req = {0};
181✔
1484
  SDecoder         coder = {0};
181✔
1485
  int32_t          code = TSDB_CODE_SUCCESS;
181✔
1486
  SRequestObj*     pRequest = NULL;
181✔
1487
  SQuery*          pQuery = NULL;
181✔
1488
  SHashObj*        pVgroupHashmap = NULL;
181✔
1489

1490
  RAW_RETURN_CHECK(buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0));
181✔
1491
  uDebug(LOG_ID_TAG " drop table, meta:%p, len:%d", LOG_ID_VALUE, meta, metaLen);
181✔
1492

1493
  pRequest->syncQuery = true;
181✔
1494
  if (!pRequest->pDb) {
181✔
1495
    code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1496
    goto end;
×
1497
  }
1498
  // decode and process req
1499
  void*    data = POINTER_SHIFT(meta, sizeof(SMsgHead));
181✔
1500
  uint32_t len = metaLen - sizeof(SMsgHead);
181✔
1501
  tDecoderInit(&coder, data, len);
181✔
1502
  if (tDecodeSVDropTbBatchReq(&coder, &req) < 0) {
181✔
1503
    code = TSDB_CODE_INVALID_PARA;
×
1504
    goto end;
×
1505
  }
1506

1507
  STscObj* pTscObj = pRequest->pTscObj;
181✔
1508

1509
  SVDropTbReq* pDropReq = NULL;
181✔
1510
  SCatalog*    pCatalog = NULL;
181✔
1511
  RAW_RETURN_CHECK(catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog));
181✔
1512

1513
  pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
181✔
1514
  RAW_NULL_CHECK(pVgroupHashmap);
181✔
1515
  taosHashSetFreeFp(pVgroupHashmap, destroyDropTbReqBatch);
181✔
1516

1517
  SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter,
181✔
1518
                           .requestId = pRequest->requestId,
181✔
1519
                           .requestObjRefId = pRequest->self,
181✔
1520
                           .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)};
181✔
1521
  pRequest->tableList = taosArrayInit(req.nReqs, sizeof(SName));
181✔
1522
  RAW_NULL_CHECK(pRequest->tableList);
181✔
1523
  // loop to create table
1524
  for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
415✔
1525
    pDropReq = req.pReqs + iReq;
234✔
1526
    pDropReq->igNotExists = true;
234✔
1527
    //    pDropReq->suid = processSuid(pDropReq->suid, pRequest->pDb);
1528

1529
    SVgroupInfo pInfo = {0};
234✔
1530
    SName       pName = {0};
234✔
1531
    toName(pTscObj->acctId, pRequest->pDb, pDropReq->name, &pName);
234✔
1532
    RAW_RETURN_CHECK(catalogGetTableHashVgroup(pCatalog, &conn, &pName, &pInfo));
234✔
1533

1534
    STableMeta* pTableMeta = NULL;
234✔
1535
    code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
234✔
1536
    if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
234✔
1537
      code = TSDB_CODE_SUCCESS;
50✔
1538
      taosMemoryFreeClear(pTableMeta);
50✔
1539
      continue;
50✔
1540
    }
1541
    if (code != TSDB_CODE_SUCCESS) {
184✔
1542
      goto end;
×
1543
    }
1544
    tb_uid_t oldSuid = pDropReq->suid;
184✔
1545
    pDropReq->suid = pTableMeta->suid;
184✔
1546
    taosMemoryFreeClear(pTableMeta);
184✔
1547
    uDebug(LOG_ID_TAG " drop table name:%s suid:%" PRId64 " new suid:%" PRId64, LOG_ID_VALUE, pDropReq->name, oldSuid,
184✔
1548
           pDropReq->suid);
1549

1550
    RAW_NULL_CHECK(taosArrayPush(pRequest->tableList, &pName));
368✔
1551
    SVgroupDropTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pInfo.vgId, sizeof(pInfo.vgId));
184✔
1552
    if (pTableBatch == NULL) {
184✔
1553
      SVgroupDropTableBatch tBatch = {0};
131✔
1554
      tBatch.info = pInfo;
131✔
1555
      tBatch.req.pArray = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVDropTbReq));
131✔
1556
      RAW_NULL_CHECK(tBatch.req.pArray);
131✔
1557
      RAW_NULL_CHECK(taosArrayPush(tBatch.req.pArray, pDropReq));
262✔
1558
      RAW_RETURN_CHECK(taosHashPut(pVgroupHashmap, &pInfo.vgId, sizeof(pInfo.vgId), &tBatch, sizeof(tBatch)));
131✔
1559
    } else {  // add to the correct vgroup
1560
      RAW_NULL_CHECK(taosArrayPush(pTableBatch->req.pArray, pDropReq));
106✔
1561
    }
1562
  }
1563

1564
  if (taosHashGetSize(pVgroupHashmap) == 0) {
181✔
1565
    goto end;
50✔
1566
  }
1567
  SArray* pBufArray = NULL;
131✔
1568
  RAW_RETURN_CHECK(serializeVgroupsDropTableBatch(pVgroupHashmap, &pBufArray));
131✔
1569
  code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pQuery);
131✔
1570
  if (TSDB_CODE_SUCCESS != code) goto end;
131✔
1571
  pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
131✔
1572
  pQuery->msgType = TDMT_VND_DROP_TABLE;
131✔
1573
  pQuery->stableQuery = false;
131✔
1574
  pQuery->pRoot = NULL;
131✔
1575
  code = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT, &pQuery->pRoot);
131✔
1576
  if (TSDB_CODE_SUCCESS != code) goto end;
131✔
1577
  RAW_RETURN_CHECK(rewriteToVnodeModifyOpStmt(pQuery, pBufArray));
131✔
1578

1579
  launchQueryImpl(pRequest, pQuery, true, NULL);
131✔
1580
  if (pRequest->code == TSDB_CODE_SUCCESS) {
131✔
1581
    RAW_RETURN_CHECK(removeMeta(pTscObj, pRequest->tableList, false));
131✔
1582
  }
1583
  code = pRequest->code;
131✔
1584

1585
end:
181✔
1586
  uDebug(LOG_ID_TAG " drop table return, msg:%s", LOG_ID_VALUE, tstrerror(code));
181✔
1587
  taosHashCleanup(pVgroupHashmap);
181✔
1588
  destroyRequest(pRequest);
181✔
1589
  tDecoderClear(&coder);
181✔
1590
  qDestroyQuery(pQuery);
181✔
1591
  return code;
181✔
1592
}
1593

1594
static int32_t taosDeleteData(TAOS* taos, void* meta, uint32_t metaLen) {
106✔
1595
  if (taos == NULL || meta == NULL) {
106✔
1596
    uError("invalid parameter in %s", __func__);
×
1597
    return TSDB_CODE_INVALID_PARA;
×
1598
  }
1599
  SDeleteRes req = {0};
106✔
1600
  SDecoder   coder = {0};
106✔
1601
  char       sql[256] = {0};
106✔
1602
  int32_t    code = TSDB_CODE_SUCCESS;
106✔
1603

1604
  uDebug("connId:0x%" PRIx64 " delete data, meta:%p, len:%d", *(int64_t*)taos, meta, metaLen);
106✔
1605

1606
  // decode and process req
1607
  void*    data = POINTER_SHIFT(meta, sizeof(SMsgHead));
106✔
1608
  uint32_t len = metaLen - sizeof(SMsgHead);
106✔
1609
  tDecoderInit(&coder, data, len);
106✔
1610
  if (tDecodeDeleteRes(&coder, &req) < 0) {
106✔
1611
    code = TSDB_CODE_INVALID_PARA;
×
1612
    goto end;
×
1613
  }
1614

1615
  (void)snprintf(sql, sizeof(sql), "delete from `%s` where `%s` >= %" PRId64 " and `%s` <= %" PRId64, req.tableFName,
106✔
1616
                 req.tsColName, req.skey, req.tsColName, req.ekey);
1617

1618
  TAOS_RES* res = taosQueryImpl(taos, sql, false, TD_REQ_FROM_TAOX);
106✔
1619
  RAW_NULL_CHECK(res);
106✔
1620
  SRequestObj* pRequest = (SRequestObj*)res;
106✔
1621
  code = pRequest->code;
106✔
1622
  if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_PAR_GET_META_ERROR) {
106✔
1623
    code = TSDB_CODE_SUCCESS;
25✔
1624
  }
1625
  taos_free_result(res);
106✔
1626

1627
end:
106✔
1628
  uDebug("connId:0x%" PRIx64 " delete data sql:%s, code:%s", *(int64_t*)taos, sql, tstrerror(code));
106✔
1629
  tDecoderClear(&coder);
106✔
1630
  return code;
106✔
1631
}
1632

1633
static int32_t taosAlterTable(TAOS* taos, void* meta, uint32_t metaLen) {
954✔
1634
  if (taos == NULL || meta == NULL) {
954✔
1635
    uError("invalid parameter in %s", __func__);
×
1636
    return TSDB_CODE_INVALID_PARA;
×
1637
  }
1638
  SVAlterTbReq   req = {0};
954✔
1639
  SDecoder       dcoder = {0};
954✔
1640
  int32_t        code = TSDB_CODE_SUCCESS;
954✔
1641
  SRequestObj*   pRequest = NULL;
954✔
1642
  SQuery*        pQuery = NULL;
954✔
1643
  SArray*        pArray = NULL;
954✔
1644
  SVgDataBlocks* pVgData = NULL;
954✔
1645

1646
  RAW_RETURN_CHECK(buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0));
954✔
1647
  uDebug(LOG_ID_TAG " alter table, meta:%p, len:%d", LOG_ID_VALUE, meta, metaLen);
954✔
1648
  pRequest->syncQuery = true;
954✔
1649
  if (!pRequest->pDb) {
954✔
1650
    code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1651
    goto end;
×
1652
  }
1653
  // decode and process req
1654
  void*    data = POINTER_SHIFT(meta, sizeof(SMsgHead));
954✔
1655
  uint32_t len = metaLen - sizeof(SMsgHead);
954✔
1656
  tDecoderInit(&dcoder, data, len);
954✔
1657
  if (tDecodeSVAlterTbReq(&dcoder, &req) < 0) {
954✔
1658
    code = TSDB_CODE_INVALID_PARA;
×
1659
    goto end;
×
1660
  }
1661

1662
  // do not deal TSDB_ALTER_TABLE_UPDATE_OPTIONS
1663
  if (req.action == TSDB_ALTER_TABLE_UPDATE_OPTIONS) {
954✔
1664
    goto end;
159✔
1665
  }
1666

1667
  STscObj*  pTscObj = pRequest->pTscObj;
795✔
1668
  SCatalog* pCatalog = NULL;
795✔
1669
  RAW_RETURN_CHECK(catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog));
795✔
1670
  SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter,
795✔
1671
                           .requestId = pRequest->requestId,
795✔
1672
                           .requestObjRefId = pRequest->self,
795✔
1673
                           .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)};
795✔
1674

1675
  SVgroupInfo pInfo = {0};
795✔
1676
  SName       pName = {0};
795✔
1677
  toName(pTscObj->acctId, pRequest->pDb, req.tbName, &pName);
795✔
1678
  RAW_RETURN_CHECK(catalogGetTableHashVgroup(pCatalog, &conn, &pName, &pInfo));
795✔
1679
  pArray = taosArrayInit(1, sizeof(void*));
795✔
1680
  RAW_NULL_CHECK(pArray);
795✔
1681

1682
  pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
795✔
1683
  RAW_NULL_CHECK(pVgData);
795✔
1684
  pVgData->vg = pInfo;
795✔
1685

1686
  int tlen = 0;
795✔
1687
  req.source = TD_REQ_FROM_TAOX;
795✔
1688
  tEncodeSize(tEncodeSVAlterTbReq, &req, tlen, code);
795✔
1689
  if (code != 0) {
795✔
1690
    code = terrno;
×
1691
    goto end;
×
1692
  }
1693
  tlen += sizeof(SMsgHead);
795✔
1694
  void* pMsg = taosMemoryMalloc(tlen);
795✔
1695
  RAW_NULL_CHECK(pMsg);
795✔
1696
  ((SMsgHead*)pMsg)->vgId = htonl(pInfo.vgId);
795✔
1697
  ((SMsgHead*)pMsg)->contLen = htonl(tlen);
795✔
1698
  void*    pBuf = POINTER_SHIFT(pMsg, sizeof(SMsgHead));
795✔
1699
  SEncoder coder = {0};
795✔
1700
  tEncoderInit(&coder, pBuf, tlen - sizeof(SMsgHead));
795✔
1701
  code = tEncodeSVAlterTbReq(&coder, &req);
795✔
1702
  if (code != 0) {
795✔
1703
    tEncoderClear(&coder);
×
1704
    code = terrno;
×
1705
    goto end;
×
1706
  }
1707
  tEncoderClear(&coder);
795✔
1708

1709
  pVgData->pData = pMsg;
795✔
1710
  pVgData->size = tlen;
795✔
1711

1712
  pVgData->numOfTables = 1;
795✔
1713
  RAW_NULL_CHECK(taosArrayPush(pArray, &pVgData));
795✔
1714

1715
  pQuery = NULL;
795✔
1716
  code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pQuery);
795✔
1717
  if (NULL == pQuery) goto end;
795✔
1718
  pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
795✔
1719
  pQuery->msgType = TDMT_VND_ALTER_TABLE;
795✔
1720
  pQuery->stableQuery = false;
795✔
1721
  pQuery->pRoot = NULL;
795✔
1722
  code = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, &pQuery->pRoot);
795✔
1723
  if (TSDB_CODE_SUCCESS != code) goto end;
795✔
1724
  RAW_RETURN_CHECK(rewriteToVnodeModifyOpStmt(pQuery, pArray));
795✔
1725

1726
  launchQueryImpl(pRequest, pQuery, true, NULL);
795✔
1727

1728
  pVgData = NULL;
795✔
1729
  pArray = NULL;
795✔
1730
  code = pRequest->code;
795✔
1731
  if (code == TSDB_CODE_TDB_TABLE_NOT_EXIST) {
795✔
1732
    code = TSDB_CODE_SUCCESS;
25✔
1733
  }
1734

1735
  if (pRequest->code == TSDB_CODE_SUCCESS) {
795✔
1736
    SExecResult* pRes = &pRequest->body.resInfo.execRes;
770✔
1737
    if (pRes->res != NULL) {
770✔
1738
      code = handleAlterTbExecRes(pRes->res, pCatalog);
636✔
1739
    }
1740
  }
1741
end:
954✔
1742
  uDebug(LOG_ID_TAG " alter table return, meta:%p, len:%d, msg:%s", LOG_ID_VALUE, meta, metaLen, tstrerror(code));
954✔
1743
  taosArrayDestroy(pArray);
954✔
1744
  if (pVgData) taosMemoryFreeClear(pVgData->pData);
954✔
1745
  taosMemoryFreeClear(pVgData);
954✔
1746
  destroyRequest(pRequest);
954✔
1747
  tDecoderClear(&dcoder);
954✔
1748
  qDestroyQuery(pQuery);
954✔
1749
  taosArrayDestroy(req.pMultiTag);
954✔
1750
  return code;
954✔
1751
}
1752

1753
int taos_write_raw_block_with_fields(TAOS* taos, int rows, char* pData, const char* tbname, TAOS_FIELD* fields,
33✔
1754
                                     int numFields) {
1755
  return taos_write_raw_block_with_fields_with_reqid(taos, rows, pData, tbname, fields, numFields, 0);
33✔
1756
}
1757

1758
int taos_write_raw_block_with_fields_with_reqid(TAOS* taos, int rows, char* pData, const char* tbname,
33✔
1759
                                                TAOS_FIELD* fields, int numFields, int64_t reqid) {
1760
  if (taos == NULL || pData == NULL || tbname == NULL) {
33✔
UNCOV
1761
    uError("invalid parameter in %s", __func__);
×
1762
    return TSDB_CODE_INVALID_PARA;
×
1763
  }
1764
  int32_t     code = TSDB_CODE_SUCCESS;
33✔
1765
  STableMeta* pTableMeta = NULL;
33✔
1766
  SQuery*     pQuery = NULL;
33✔
1767
  SHashObj*   pVgHash = NULL;
33✔
1768

1769
  SRequestObj* pRequest = NULL;
33✔
1770
  RAW_RETURN_CHECK(buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, reqid));
33✔
1771

1772
  uDebug(LOG_ID_TAG " write raw block with field, rows:%d, pData:%p, tbname:%s, fields:%p, numFields:%d", LOG_ID_VALUE,
33✔
1773
         rows, pData, tbname, fields, numFields);
1774

1775
  pRequest->syncQuery = true;
33✔
1776
  if (!pRequest->pDb) {
33✔
UNCOV
1777
    code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1778
    goto end;
×
1779
  }
1780

1781
  SName pName = {TSDB_TABLE_NAME_T, pRequest->pTscObj->acctId, {0}, {0}};
33✔
1782
  tstrncpy(pName.dbname, pRequest->pDb, sizeof(pName.dbname));
33✔
1783
  tstrncpy(pName.tname, tbname, sizeof(pName.tname));
33✔
1784

1785
  struct SCatalog* pCatalog = NULL;
33✔
1786
  RAW_RETURN_CHECK(catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog));
33✔
1787

1788
  SRequestConnInfo conn = {0};
33✔
1789
  conn.pTrans = pRequest->pTscObj->pAppInfo->pTransporter;
33✔
1790
  conn.requestId = pRequest->requestId;
33✔
1791
  conn.requestObjRefId = pRequest->self;
33✔
1792
  conn.mgmtEps = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
33✔
1793

1794
  SVgroupInfo vgData = {0};
33✔
1795
  RAW_RETURN_CHECK(catalogGetTableHashVgroup(pCatalog, &conn, &pName, &vgData));
33✔
1796
  RAW_RETURN_CHECK(catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta));
33✔
1797
  RAW_RETURN_CHECK(smlInitHandle(&pQuery));
33✔
1798
  pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
33✔
1799
  RAW_NULL_CHECK(pVgHash);
33✔
1800
  RAW_RETURN_CHECK(
33✔
1801
      taosHashPut(pVgHash, (const char*)&vgData.vgId, sizeof(vgData.vgId), (char*)&vgData, sizeof(vgData)));
1802
  RAW_RETURN_CHECK(rawBlockBindData(pQuery, pTableMeta, pData, NULL, fields, numFields, false, NULL, 0, false));
33✔
1803
  RAW_RETURN_CHECK(smlBuildOutput(pQuery, pVgHash));
33✔
1804

1805
  launchQueryImpl(pRequest, pQuery, true, NULL);
33✔
1806
  code = pRequest->code;
33✔
1807

1808
end:
33✔
1809
  uDebug(LOG_ID_TAG " write raw block with field return, msg:%s", LOG_ID_VALUE, tstrerror(code));
33✔
1810
  taosMemoryFreeClear(pTableMeta);
33✔
1811
  qDestroyQuery(pQuery);
33✔
1812
  destroyRequest(pRequest);
33✔
1813
  taosHashCleanup(pVgHash);
33✔
1814
  return code;
33✔
1815
}
1816

1817
int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname) {
231✔
1818
  return taos_write_raw_block_with_reqid(taos, rows, pData, tbname, 0);
231✔
1819
}
1820

1821
int taos_write_raw_block_with_reqid(TAOS* taos, int rows, char* pData, const char* tbname, int64_t reqid) {
231✔
1822
  if (taos == NULL || pData == NULL || tbname == NULL) {
231✔
UNCOV
1823
    return TSDB_CODE_INVALID_PARA;
×
1824
  }
1825
  int32_t     code = TSDB_CODE_SUCCESS;
231✔
1826
  STableMeta* pTableMeta = NULL;
231✔
1827
  SQuery*     pQuery = NULL;
231✔
1828
  SHashObj*   pVgHash = NULL;
231✔
1829

1830
  SRequestObj* pRequest = NULL;
231✔
1831
  RAW_RETURN_CHECK(buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, reqid));
231✔
1832

1833
  uDebug(LOG_ID_TAG " write raw block, rows:%d, pData:%p, tbname:%s", LOG_ID_VALUE, rows, pData, tbname);
231✔
1834

1835
  pRequest->syncQuery = true;
231✔
1836
  if (!pRequest->pDb) {
231✔
UNCOV
1837
    code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
1838
    goto end;
×
1839
  }
1840

1841
  SName pName = {TSDB_TABLE_NAME_T, pRequest->pTscObj->acctId, {0}, {0}};
231✔
1842
  tstrncpy(pName.dbname, pRequest->pDb, sizeof(pName.dbname));
231✔
1843
  tstrncpy(pName.tname, tbname, sizeof(pName.tname));
231✔
1844

1845
  struct SCatalog* pCatalog = NULL;
231✔
1846
  RAW_RETURN_CHECK(catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog));
231✔
1847

1848
  SRequestConnInfo conn = {0};
231✔
1849
  conn.pTrans = pRequest->pTscObj->pAppInfo->pTransporter;
231✔
1850
  conn.requestId = pRequest->requestId;
231✔
1851
  conn.requestObjRefId = pRequest->self;
231✔
1852
  conn.mgmtEps = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
231✔
1853

1854
  SVgroupInfo vgData = {0};
231✔
1855
  RAW_RETURN_CHECK(catalogGetTableHashVgroup(pCatalog, &conn, &pName, &vgData));
231✔
1856
  RAW_RETURN_CHECK(catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta));
231✔
1857
  RAW_RETURN_CHECK(smlInitHandle(&pQuery));
198✔
1858
  pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
198✔
1859
  RAW_NULL_CHECK(pVgHash);
198✔
1860
  RAW_RETURN_CHECK(
198✔
1861
      taosHashPut(pVgHash, (const char*)&vgData.vgId, sizeof(vgData.vgId), (char*)&vgData, sizeof(vgData)));
1862
  RAW_RETURN_CHECK(rawBlockBindData(pQuery, pTableMeta, pData, NULL, NULL, 0, false, NULL, 0, false));
198✔
1863
  RAW_RETURN_CHECK(smlBuildOutput(pQuery, pVgHash));
132✔
1864

1865
  launchQueryImpl(pRequest, pQuery, true, NULL);
132✔
1866
  code = pRequest->code;
132✔
1867

1868
end:
231✔
1869
  uDebug(LOG_ID_TAG " write raw block return, msg:%s", LOG_ID_VALUE, tstrerror(code));
231✔
1870
  taosMemoryFreeClear(pTableMeta);
231✔
1871
  qDestroyQuery(pQuery);
231✔
1872
  destroyRequest(pRequest);
231✔
1873
  taosHashCleanup(pVgHash);
231✔
1874
  return code;
231✔
1875
}
1876

1877
static void* getRawDataFromRes(void* pRetrieve) {
3,874✔
1878
  if (pRetrieve == NULL) {
3,874✔
UNCOV
1879
    uError("invalid parameter in %s", __func__);
×
1880
    return NULL;
×
1881
  }
1882
  void* rawData = NULL;
3,874✔
1883
  // deal with compatibility
1884
  if (*(int64_t*)pRetrieve == RETRIEVE_TABLE_RSP_VERSION) {
3,874✔
UNCOV
1885
    rawData = ((SRetrieveTableRsp*)pRetrieve)->data;
×
1886
  } else if (*(int64_t*)pRetrieve == RETRIEVE_TABLE_RSP_TMQ_VERSION ||
3,874✔
UNCOV
1887
             *(int64_t*)pRetrieve == RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION) {
×
1888
    rawData = ((SRetrieveTableRspForTmq*)pRetrieve)->data;
3,874✔
1889
  }
1890
  return rawData;
3,874✔
1891
}
1892

1893
static int32_t buildCreateTbMap(SMqDataRsp* rsp, SHashObj* pHashObj) {
165✔
1894
  if (rsp == NULL || pHashObj == NULL) {
165✔
UNCOV
1895
    uError("invalid parameter in %s", __func__);
×
1896
    return TSDB_CODE_INVALID_PARA;
×
1897
  }
1898
  // find schema data info
1899
  int32_t       code = 0;
165✔
1900
  SVCreateTbReq pCreateReq = {0};
165✔
1901
  SDecoder      decoderTmp = {0};
165✔
1902

1903
  for (int j = 0; j < rsp->createTableNum; j++) {
589✔
1904
    void** dataTmp = taosArrayGet(rsp->createTableReq, j);
424✔
1905
    RAW_NULL_CHECK(dataTmp);
424✔
1906
    int32_t* lenTmp = taosArrayGet(rsp->createTableLen, j);
424✔
1907
    RAW_NULL_CHECK(lenTmp);
424✔
1908

1909
    tDecoderInit(&decoderTmp, *dataTmp, *lenTmp);
424✔
1910
    RAW_RETURN_CHECK(tDecodeSVCreateTbReq(&decoderTmp, &pCreateReq));
424✔
1911

1912
    if (pCreateReq.type != TSDB_CHILD_TABLE) {
424✔
UNCOV
1913
      code = TSDB_CODE_INVALID_MSG;
×
1914
      goto end;
×
1915
    }
1916
    if (taosHashGet(pHashObj, pCreateReq.name, strlen(pCreateReq.name)) == NULL) {
424✔
1917
      RAW_RETURN_CHECK(
424✔
1918
          taosHashPut(pHashObj, pCreateReq.name, strlen(pCreateReq.name), &pCreateReq, sizeof(SVCreateTbReq)));
1919
    } else {
UNCOV
1920
      tDestroySVCreateTbReq(&pCreateReq, TSDB_MSG_FLG_DECODE);
×
1921
      pCreateReq = (SVCreateTbReq){0};
×
1922
    }
1923

1924
    tDecoderClear(&decoderTmp);
424✔
1925
  }
1926
  return 0;
165✔
1927

UNCOV
1928
end:
×
1929
  tDecoderClear(&decoderTmp);
×
1930
  tDestroySVCreateTbReq(&pCreateReq, TSDB_MSG_FLG_DECODE);
×
1931
  return code;
×
1932
}
1933

1934
typedef enum {
1935
  WRITE_RAW_INIT_START = 0,
1936
  WRITE_RAW_INIT_OK,
1937
  WRITE_RAW_INIT_FAIL,
1938
} WRITE_RAW_INIT_STATUS;
1939

1940
static SHashObj* writeRawCache = NULL;
1941
static int8_t    initFlag = 0;
1942
static int8_t    initedFlag = WRITE_RAW_INIT_START;
1943

1944
typedef struct {
1945
  SHashObj* pVgHash;
1946
  SHashObj* pNameHash;
1947
  SHashObj* pMetaHash;
1948
} rawCacheInfo;
1949

1950
typedef struct {
1951
  SVgroupInfo vgInfo;
1952
  int64_t     uid;
1953
  int64_t     suid;
1954
} tbInfo;
1955

1956
static void tmqFreeMeta(void* data) {
1,158✔
1957
  if (data == NULL) {
1,158✔
UNCOV
1958
    uError("invalid parameter in %s", __func__);
×
1959
    return;
×
1960
  }
1961
  STableMeta* pTableMeta = *(STableMeta**)data;
1,158✔
1962
  taosMemoryFree(pTableMeta);
1,158✔
1963
}
1964

UNCOV
1965
static void freeRawCache(void* data) {
×
1966
  if (data == NULL) {
×
1967
    uError("invalid parameter in %s", __func__);
×
1968
    return;
×
1969
  }
UNCOV
1970
  rawCacheInfo* pRawCache = (rawCacheInfo*)data;
×
1971
  taosHashCleanup(pRawCache->pMetaHash);
×
1972
  taosHashCleanup(pRawCache->pNameHash);
×
1973
  taosHashCleanup(pRawCache->pVgHash);
×
1974
}
1975

1976
static int32_t initRawCacheHash() {
428✔
1977
  if (writeRawCache == NULL) {
428✔
1978
    writeRawCache = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
428✔
1979
    if (writeRawCache == NULL) {
428✔
UNCOV
1980
      return terrno;
×
1981
    }
1982
    taosHashSetFreeFp(writeRawCache, freeRawCache);
428✔
1983
  }
1984
  return 0;
428✔
1985
}
1986

1987
static bool needRefreshMeta(void* rawData, STableMeta* pTableMeta, SSchemaWrapper* pSW) {
467✔
1988
  if (rawData == NULL || pSW == NULL) {
467✔
UNCOV
1989
    return false;
×
1990
  }
1991
  if (pTableMeta == NULL) {
467✔
UNCOV
1992
    uError("invalid parameter in %s", __func__);
×
1993
    return false;
×
1994
  }
1995
  char* p = (char*)rawData;
467✔
1996
  // | version | total length | total rows | blankFill | total columns | flag seg| block group id | column schema | each
1997
  // column length |
1998
  p += sizeof(int32_t);
467✔
1999
  p += sizeof(int32_t);
467✔
2000
  p += sizeof(int32_t);
467✔
2001
  p += sizeof(int32_t);
467✔
2002
  p += sizeof(int32_t);
467✔
2003
  p += sizeof(uint64_t);
467✔
2004
  int8_t* fields = p;
467✔
2005

2006
  if (pSW->nCols != pTableMeta->tableInfo.numOfColumns) {
467✔
2007
    return true;
140✔
2008
  }
2009

2010
  for (int i = 0; i < pSW->nCols; i++) {
1,716✔
2011
    int j = 0;
1,389✔
2012
    for (; j < pTableMeta->tableInfo.numOfColumns; j++) {
3,675✔
2013
      SSchema*    pColSchema = &pTableMeta->schema[j];
3,675✔
2014
      SSchemaExt* pColExtSchema = &pTableMeta->schemaExt[j];
3,675✔
2015
      char*       fieldName = pSW->pSchema[i].name;
3,675✔
2016

2017
      if (strcmp(pColSchema->name, fieldName) == 0) {
3,675✔
2018
        if (checkSchema(pColSchema, pColExtSchema, fields, NULL, 0) != 0) {
1,389✔
UNCOV
2019
          return true;
×
2020
        }
2021
        break;
1,389✔
2022
      }
2023
    }
2024
    fields += sizeof(int8_t) + sizeof(int32_t);
1,389✔
2025

2026
    if (j == pTableMeta->tableInfo.numOfColumns) return true;
1,389✔
2027
  }
2028
  return false;
327✔
2029
}
2030

2031
static int32_t getRawCache(SHashObj** pVgHash, SHashObj** pNameHash, SHashObj** pMetaHash, void* key) {
1,445✔
2032
  if (pVgHash == NULL || pNameHash == NULL || pMetaHash == NULL || key == NULL) {
1,445✔
UNCOV
2033
    uError("invalid parameter in %s", __func__);
×
2034
    return TSDB_CODE_INVALID_PARA;
×
2035
  }
2036
  int32_t code = 0;
1,445✔
2037
  void*   cacheInfo = taosHashGet(writeRawCache, &key, POINTER_BYTES);
1,445✔
2038
  if (cacheInfo == NULL) {
1,445✔
2039
    *pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
1,445✔
2040
    RAW_NULL_CHECK(*pVgHash);
1,445✔
2041
    *pNameHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
1,445✔
2042
    RAW_NULL_CHECK(*pNameHash);
1,445✔
2043
    *pMetaHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
1,445✔
2044
    RAW_NULL_CHECK(*pMetaHash);
1,445✔
2045
    taosHashSetFreeFp(*pMetaHash, tmqFreeMeta);
1,445✔
2046
    rawCacheInfo info = {*pVgHash, *pNameHash, *pMetaHash};
1,445✔
2047
    RAW_RETURN_CHECK(taosHashPut(writeRawCache, &key, POINTER_BYTES, &info, sizeof(rawCacheInfo)));
1,445✔
2048
  } else {
UNCOV
2049
    rawCacheInfo* info = (rawCacheInfo*)cacheInfo;
×
2050
    *pVgHash = info->pVgHash;
×
2051
    *pNameHash = info->pNameHash;
×
2052
    *pMetaHash = info->pMetaHash;
×
2053
  }
2054

2055
  return 0;
1,445✔
UNCOV
2056
end:
×
2057
  taosHashCleanup(*pMetaHash);
×
2058
  taosHashCleanup(*pNameHash);
×
2059
  taosHashCleanup(*pVgHash);
×
2060
  return code;
×
2061
}
2062

2063
static int32_t buildRawRequest(TAOS* taos, SRequestObj** pRequest, SCatalog** pCatalog, SRequestConnInfo* conn) {
1,445✔
2064
  if (taos == NULL || pRequest == NULL || pCatalog == NULL || conn == NULL) {
1,445✔
UNCOV
2065
    uError("invalid parameter in %s", __func__);
×
2066
    return TSDB_CODE_INVALID_PARA;
×
2067
  }
2068
  int32_t code = 0;
1,445✔
2069
  RAW_RETURN_CHECK(buildRequest(*(int64_t*)taos, "", 0, NULL, false, pRequest, 0));
1,445✔
2070
  (*pRequest)->syncQuery = true;
1,445✔
2071
  if (!(*pRequest)->pDb) {
1,445✔
UNCOV
2072
    code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
×
2073
    goto end;
×
2074
  }
2075

2076
  RAW_RETURN_CHECK(catalogGetHandle((*pRequest)->pTscObj->pAppInfo->clusterId, pCatalog));
1,445✔
2077
  conn->pTrans = (*pRequest)->pTscObj->pAppInfo->pTransporter;
1,445✔
2078
  conn->requestId = (*pRequest)->requestId;
1,445✔
2079
  conn->requestObjRefId = (*pRequest)->self;
1,445✔
2080
  conn->mgmtEps = getEpSet_s(&(*pRequest)->pTscObj->pAppInfo->mgmtEp);
1,445✔
2081

2082
end:
1,445✔
2083
  return code;
1,445✔
2084
}
2085

2086
typedef int32_t _raw_decode_func_(SDecoder* pDecoder, SMqDataRsp* pRsp);
2087
static int32_t  decodeRawData(SDecoder* decoder, void* data, uint32_t dataLen, _raw_decode_func_ func,
1,445✔
2088
                              SMqRspObj* rspObj) {
2089
  if (decoder == NULL || data == NULL || func == NULL || rspObj == NULL) {
1,445✔
UNCOV
2090
    uError("invalid parameter in %s", __func__);
×
2091
    return TSDB_CODE_INVALID_PARA;
×
2092
  }
2093
  int8_t dataVersion = *(int8_t*)data;
1,445✔
2094
  if (dataVersion >= MQ_DATA_RSP_VERSION) {
1,445✔
2095
    data = POINTER_SHIFT(data, sizeof(int8_t) + sizeof(int32_t));
1,445✔
2096
    if (dataLen < sizeof(int8_t) + sizeof(int32_t)) {
1,445✔
UNCOV
2097
      return TSDB_CODE_INVALID_PARA;
×
2098
    }
2099
    dataLen -= sizeof(int8_t) + sizeof(int32_t);
1,445✔
2100
  }
2101

2102
  rspObj->resIter = -1;
1,445✔
2103
  tDecoderInit(decoder, data, dataLen);
1,445✔
2104
  int32_t code = func(decoder, &rspObj->dataRsp);
1,445✔
2105
  if (code != 0) {
1,445✔
UNCOV
2106
    SET_ERROR_MSG("decode mq taosx data rsp failed");
×
2107
  }
2108
  return code;
1,445✔
2109
}
2110

2111
static int32_t processCacheMeta(SHashObj* pVgHash, SHashObj* pNameHash, SHashObj* pMetaHash,
3,874✔
2112
                                SVCreateTbReq* pCreateReqDst, SCatalog* pCatalog, SRequestConnInfo* conn, SName* pName,
2113
                                STableMeta** pMeta, SSchemaWrapper* pSW, void* rawData, int32_t retry) {
2114
  if (pVgHash == NULL || pNameHash == NULL || pMetaHash == NULL || pCatalog == NULL || conn == NULL || pName == NULL ||
3,874✔
2115
      pMeta == NULL) {
UNCOV
2116
    uError("invalid parameter in %s", __func__);
×
2117
    return TSDB_CODE_INVALID_PARA;
×
2118
  }
2119
  int32_t     code = 0;
3,874✔
2120
  STableMeta* pTableMeta = NULL;
3,874✔
2121
  tbInfo*     tmpInfo = (tbInfo*)taosHashGet(pNameHash, pName->tname, strlen(pName->tname));
3,874✔
2122
  if (tmpInfo == NULL || retry > 0) {
3,874✔
2123
    tbInfo info = {0};
3,407✔
2124

2125
    RAW_RETURN_CHECK(catalogGetTableHashVgroup(pCatalog, conn, pName, &info.vgInfo));
3,407✔
2126
    if (pCreateReqDst && tmpInfo == NULL) {  // change stable name to get meta
3,407✔
2127
      tstrncpy(pName->tname, pCreateReqDst->ctb.stbName, TSDB_TABLE_NAME_LEN);
424✔
2128
    }
2129
    RAW_RETURN_CHECK(catalogGetTableMeta(pCatalog, conn, pName, &pTableMeta));
3,407✔
2130
    info.uid = pTableMeta->uid;
3,407✔
2131
    if (pTableMeta->tableType == TSDB_CHILD_TABLE) {
3,407✔
2132
      info.suid = pTableMeta->suid;
2,526✔
2133
    } else {
2134
      info.suid = pTableMeta->uid;
881✔
2135
    }
2136
    code = taosHashPut(pMetaHash, &info.suid, LONG_BYTES, &pTableMeta, POINTER_BYTES);
3,407✔
2137
    if (code != 0) {
3,407✔
UNCOV
2138
      taosMemoryFree(pTableMeta);
×
2139
      goto end;
×
2140
    }
2141
    uDebug("put table meta to hash1, suid:%" PRId64 ", metaHashSIze:%d, nameHashSize:%d, vgHashSize:%d", info.suid, taosHashGetSize(pMetaHash),
3,407✔
2142
           taosHashGetSize(pNameHash), taosHashGetSize(pVgHash));
2143
    if (pCreateReqDst) {
3,407✔
2144
      pTableMeta->vgId = info.vgInfo.vgId;
424✔
2145
      pTableMeta->uid = pCreateReqDst->uid;
424✔
2146
      pCreateReqDst->ctb.suid = pTableMeta->suid;
424✔
2147
    }
2148

2149
    RAW_RETURN_CHECK(taosHashPut(pNameHash, pName->tname, strlen(pName->tname), &info, sizeof(tbInfo)));
3,407✔
2150
    tmpInfo = (tbInfo*)taosHashGet(pNameHash, pName->tname, strlen(pName->tname));
3,407✔
2151
    RAW_RETURN_CHECK(
3,407✔
2152
        taosHashPut(pVgHash, &info.vgInfo.vgId, sizeof(info.vgInfo.vgId), &info.vgInfo, sizeof(SVgroupInfo)));
2153
  }
2154

2155
  if (pTableMeta == NULL || retry > 0) {
3,874✔
2156
    STableMeta** pTableMetaTmp = (STableMeta**)taosHashGet(pMetaHash, &tmpInfo->suid, LONG_BYTES);
467✔
2157
    if (pTableMetaTmp == NULL || retry > 0 || needRefreshMeta(rawData, *pTableMetaTmp, pSW)) {
467✔
2158
      RAW_RETURN_CHECK(catalogGetTableMeta(pCatalog, conn, pName, &pTableMeta));
140✔
2159
      code = taosHashPut(pMetaHash, &tmpInfo->suid, LONG_BYTES, &pTableMeta, POINTER_BYTES);
140✔
2160
      if (code != 0) {
140✔
UNCOV
2161
        taosMemoryFree(pTableMeta);
×
2162
        goto end;
×
2163
      }
2164
      uDebug("put table meta to hash2, suid:%" PRId64 ", metaHashSIze:%d, nameHashSize:%d, vgHashSize:%d", tmpInfo->suid, taosHashGetSize(pMetaHash),
140✔
2165
      taosHashGetSize(pNameHash), taosHashGetSize(pVgHash));
2166
    } else {
2167
      pTableMeta = *pTableMetaTmp;
327✔
2168
      pTableMeta->uid = tmpInfo->uid;
327✔
2169
      pTableMeta->vgId = tmpInfo->vgInfo.vgId;
327✔
2170
    }
2171
  }
2172
  *pMeta = pTableMeta;
3,874✔
2173

2174
end:
3,874✔
2175
  return code;
3,874✔
2176
}
2177

2178
static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, uint32_t dataLen) {
1,280✔
2179
  if (taos == NULL || data == NULL) {
1,280✔
UNCOV
2180
    uError("invalid parameter in %s", __func__);
×
2181
    return TSDB_CODE_INVALID_PARA;
×
2182
  }
2183
  int32_t   code = TSDB_CODE_SUCCESS;
1,280✔
2184
  SQuery*   pQuery = NULL;
1,280✔
2185
  SMqRspObj rspObj = {0};
1,280✔
2186
  SDecoder  decoder = {0};
1,280✔
2187

2188
  SRequestObj*     pRequest = NULL;
1,280✔
2189
  SCatalog*        pCatalog = NULL;
1,280✔
2190
  SRequestConnInfo conn = {0};
1,280✔
2191
  RAW_RETURN_CHECK(buildRawRequest(taos, &pRequest, &pCatalog, &conn));
1,280✔
2192
  uDebug(LOG_ID_TAG " write raw data, data:%p, dataLen:%d", LOG_ID_VALUE, data, dataLen);
1,280✔
2193
  RAW_RETURN_CHECK(decodeRawData(&decoder, data, dataLen, tDecodeMqDataRsp, &rspObj));
1,280✔
2194

2195
  SHashObj* pVgHash = NULL;
1,280✔
2196
  SHashObj* pNameHash = NULL;
1,280✔
2197
  SHashObj* pMetaHash = NULL;
1,280✔
2198
  RAW_RETURN_CHECK(getRawCache(&pVgHash, &pNameHash, &pMetaHash, taos));
1,280✔
2199
  int retry = 0;
1,280✔
2200
  while (1) {
2201
    RAW_RETURN_CHECK(smlInitHandle(&pQuery));
1,280✔
2202
    uDebug(LOG_ID_TAG " write raw meta data block num:%d", LOG_ID_VALUE, rspObj.dataRsp.blockNum);
1,280✔
2203
    while (++rspObj.resIter < rspObj.dataRsp.blockNum) {
4,412✔
2204
      if (!rspObj.dataRsp.withSchema) {
3,132✔
UNCOV
2205
        goto end;
×
2206
      }
2207

2208
      const char* tbName = (const char*)taosArrayGetP(rspObj.dataRsp.blockTbName, rspObj.resIter);
3,132✔
2209
      RAW_NULL_CHECK(tbName);
3,132✔
2210
      SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(rspObj.dataRsp.blockSchema, rspObj.resIter);
3,132✔
2211
      RAW_NULL_CHECK(pSW);
3,132✔
2212
      void* pRetrieve = taosArrayGetP(rspObj.dataRsp.blockData, rspObj.resIter);
3,132✔
2213
      RAW_NULL_CHECK(pRetrieve);
3,132✔
2214
      void* rawData = getRawDataFromRes(pRetrieve);
3,132✔
2215
      RAW_NULL_CHECK(rawData);
3,132✔
2216

2217
      uTrace(LOG_ID_TAG " write raw data block tbname:%s", LOG_ID_VALUE, tbName);
3,132✔
2218
      SName pName = {TSDB_TABLE_NAME_T, pRequest->pTscObj->acctId, {0}, {0}};
3,132✔
2219
      tstrncpy(pName.dbname, pRequest->pDb, TSDB_DB_NAME_LEN);
3,132✔
2220
      tstrncpy(pName.tname, tbName, TSDB_TABLE_NAME_LEN);
3,132✔
2221

2222
      STableMeta* pTableMeta = NULL;
3,132✔
2223
      RAW_RETURN_CHECK(processCacheMeta(pVgHash, pNameHash, pMetaHash, NULL, pCatalog, &conn, &pName, &pTableMeta, pSW,
3,132✔
2224
                                        rawData, retry));
2225
      char err[ERR_MSG_LEN] = {0};
3,132✔
2226
      code = rawBlockBindData(pQuery, pTableMeta, rawData, NULL, pSW, pSW->nCols, true, err, ERR_MSG_LEN, true);
3,132✔
2227
      if (code != TSDB_CODE_SUCCESS) {
3,132✔
UNCOV
2228
        SET_ERROR_MSG("table:%s, err:%s", pName.tname, err);
×
2229
        goto end;
×
2230
      }
2231
    }
2232
    RAW_RETURN_CHECK(smlBuildOutput(pQuery, pVgHash));
1,280✔
2233
    launchQueryImpl(pRequest, pQuery, true, NULL);
1,280✔
2234
    code = pRequest->code;
1,280✔
2235

2236
    if (NEED_CLIENT_HANDLE_ERROR(code) && retry++ < 3) {
1,280✔
UNCOV
2237
      uInfo("write raw retry:%d/3 end code:%d, msg:%s", retry, code, tstrerror(code));
×
2238
      qDestroyQuery(pQuery);
×
2239
      pQuery = NULL;
×
2240
      rspObj.resIter = -1;
×
2241
      continue;
×
2242
    }
2243
    break;
1,280✔
2244
  }
2245

2246
end:
1,280✔
2247
  uDebug(LOG_ID_TAG " write raw data return, msg:%s", LOG_ID_VALUE, tstrerror(code));
1,280✔
2248
  tDeleteMqDataRsp(&rspObj.dataRsp);
1,280✔
2249
  tDecoderClear(&decoder);
1,280✔
2250
  qDestroyQuery(pQuery);
1,280✔
2251
  destroyRequest(pRequest);
1,280✔
2252
  return code;
1,280✔
2253
}
2254

2255
static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, uint32_t dataLen) {
165✔
2256
  if (taos == NULL || data == NULL) {
165✔
UNCOV
2257
    uError("invalid parameter in %s", __func__);
×
2258
    return TSDB_CODE_INVALID_PARA;
×
2259
  }
2260
  int32_t   code = TSDB_CODE_SUCCESS;
165✔
2261
  SQuery*   pQuery = NULL;
165✔
2262
  SMqRspObj rspObj = {0};
165✔
2263
  SDecoder  decoder = {0};
165✔
2264
  SHashObj* pCreateTbHash = NULL;
165✔
2265

2266
  SRequestObj*     pRequest = NULL;
165✔
2267
  SCatalog*        pCatalog = NULL;
165✔
2268
  SRequestConnInfo conn = {0};
165✔
2269

2270
  RAW_RETURN_CHECK(buildRawRequest(taos, &pRequest, &pCatalog, &conn));
165✔
2271
  uDebug(LOG_ID_TAG " write raw metadata, data:%p, dataLen:%d", LOG_ID_VALUE, data, dataLen);
165✔
2272
  RAW_RETURN_CHECK(decodeRawData(&decoder, data, dataLen, tDecodeSTaosxRsp, &rspObj));
165✔
2273

2274
  pCreateTbHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
165✔
2275
  RAW_NULL_CHECK(pCreateTbHash);
165✔
2276
  RAW_RETURN_CHECK(buildCreateTbMap(&rspObj.dataRsp, pCreateTbHash));
165✔
2277

2278
  SHashObj* pVgHash = NULL;
165✔
2279
  SHashObj* pNameHash = NULL;
165✔
2280
  SHashObj* pMetaHash = NULL;
165✔
2281
  RAW_RETURN_CHECK(getRawCache(&pVgHash, &pNameHash, &pMetaHash, taos));
165✔
2282
  int retry = 0;
165✔
2283
  while (1) {
2284
    RAW_RETURN_CHECK(smlInitHandle(&pQuery));
165✔
2285
    uDebug(LOG_ID_TAG " write raw meta data block num:%d", LOG_ID_VALUE, rspObj.dataRsp.blockNum);
165✔
2286
    while (++rspObj.resIter < rspObj.dataRsp.blockNum) {
907✔
2287
      if (!rspObj.dataRsp.withSchema) {
742✔
UNCOV
2288
        goto end;
×
2289
      }
2290

2291
      const char* tbName = (const char*)taosArrayGetP(rspObj.dataRsp.blockTbName, rspObj.resIter);
742✔
2292
      RAW_NULL_CHECK(tbName);
742✔
2293
      SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(rspObj.dataRsp.blockSchema, rspObj.resIter);
742✔
2294
      RAW_NULL_CHECK(pSW);
742✔
2295
      void* pRetrieve = taosArrayGetP(rspObj.dataRsp.blockData, rspObj.resIter);
742✔
2296
      RAW_NULL_CHECK(pRetrieve);
742✔
2297
      void* rawData = getRawDataFromRes(pRetrieve);
742✔
2298
      RAW_NULL_CHECK(rawData);
742✔
2299

2300
      uTrace(LOG_ID_TAG " write raw data block tbname:%s", LOG_ID_VALUE, tbName);
742✔
2301
      SName pName = {TSDB_TABLE_NAME_T, pRequest->pTscObj->acctId, {0}, {0}};
742✔
2302
      tstrncpy(pName.dbname, pRequest->pDb, TSDB_DB_NAME_LEN);
742✔
2303
      tstrncpy(pName.tname, tbName, TSDB_TABLE_NAME_LEN);
742✔
2304

2305
      // find schema data info
2306
      SVCreateTbReq* pCreateReqDst = (SVCreateTbReq*)taosHashGet(pCreateTbHash, pName.tname, strlen(pName.tname));
742✔
2307
      STableMeta*    pTableMeta = NULL;
742✔
2308
      RAW_RETURN_CHECK(processCacheMeta(pVgHash, pNameHash, pMetaHash, pCreateReqDst, pCatalog, &conn, &pName,
742✔
2309
                                        &pTableMeta, pSW, rawData, retry));
2310
      char err[ERR_MSG_LEN] = {0};
742✔
2311
      code =
2312
          rawBlockBindData(pQuery, pTableMeta, rawData, pCreateReqDst, pSW, pSW->nCols, true, err, ERR_MSG_LEN, true);
742✔
2313
      if (code != TSDB_CODE_SUCCESS) {
742✔
UNCOV
2314
        SET_ERROR_MSG("table:%s, err:%s", pName.tname, err);
×
2315
        goto end;
×
2316
      }
2317
    }
2318
    RAW_RETURN_CHECK(smlBuildOutput(pQuery, pVgHash));
165✔
2319
    launchQueryImpl(pRequest, pQuery, true, NULL);
165✔
2320
    code = pRequest->code;
165✔
2321

2322
    if (NEED_CLIENT_HANDLE_ERROR(code) && retry++ < 3) {
165✔
UNCOV
2323
      uInfo("write raw retry:%d/3 end code:%d, msg:%s", retry, code, tstrerror(code));
×
2324
      qDestroyQuery(pQuery);
×
2325
      pQuery = NULL;
×
2326
      rspObj.resIter = -1;
×
2327
      continue;
×
2328
    }
2329
    break;
165✔
2330
  }
2331

2332
end:
165✔
2333
  uDebug(LOG_ID_TAG " write raw metadata return, msg:%s", LOG_ID_VALUE, tstrerror(code));
165✔
2334
  tDeleteSTaosxRsp(&rspObj.dataRsp);
165✔
2335
  void* pIter = taosHashIterate(pCreateTbHash, NULL);
165✔
2336
  while (pIter) {
589✔
2337
    tDestroySVCreateTbReq(pIter, TSDB_MSG_FLG_DECODE);
424✔
2338
    pIter = taosHashIterate(pCreateTbHash, pIter);
424✔
2339
  }
2340
  taosHashCleanup(pCreateTbHash);
165✔
2341
  tDecoderClear(&decoder);
165✔
2342
  qDestroyQuery(pQuery);
165✔
2343
  destroyRequest(pRequest);
165✔
2344
  return code;
165✔
2345
}
2346

UNCOV
2347
static int32_t tmqWriteRawRawDataImpl(TAOS* taos, void* data, uint32_t dataLen) {
×
2348
  if (taos == NULL || data == NULL) {
×
2349
    uError("invalid parameter in %s", __func__);
×
2350
    return TSDB_CODE_INVALID_PARA;
×
2351
  }
UNCOV
2352
  int32_t   code = TSDB_CODE_SUCCESS;
×
2353
  SQuery*   pQuery = NULL;
×
2354
  SHashObj* pVgroupHash = NULL;
×
2355
  SMqRspObj rspObj = {0};
×
2356
  SDecoder  decoder = {0};
×
2357

UNCOV
2358
  SRequestObj*     pRequest = NULL;
×
2359
  SCatalog*        pCatalog = NULL;
×
2360
  SRequestConnInfo conn = {0};
×
2361

UNCOV
2362
  RAW_RETURN_CHECK(buildRawRequest(taos, &pRequest, &pCatalog, &conn));
×
2363
  uDebug(LOG_ID_TAG " write raw rawdata, data:%p, dataLen:%d", LOG_ID_VALUE, data, dataLen);
×
2364
  RAW_RETURN_CHECK(decodeRawData(&decoder, data, dataLen, tDecodeMqDataRsp, &rspObj));
×
2365

UNCOV
2366
  SHashObj* pVgHash = NULL;
×
2367
  SHashObj* pNameHash = NULL;
×
2368
  SHashObj* pMetaHash = NULL;
×
2369
  RAW_RETURN_CHECK(getRawCache(&pVgHash, &pNameHash, &pMetaHash, taos));
×
2370
  int retry = 0;
×
2371
  while (1) {
×
2372
    RAW_RETURN_CHECK(smlInitHandle(&pQuery));
×
2373
    uDebug(LOG_ID_TAG " write raw rawdata block num:%d", LOG_ID_VALUE, rspObj.dataRsp.blockNum);
×
2374
    SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)(pQuery)->pRoot;
×
2375
    pVgroupHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
×
2376
    RAW_NULL_CHECK(pVgroupHash);
×
2377
    pStmt->pVgDataBlocks = taosArrayInit(8, POINTER_BYTES);
×
2378
    RAW_NULL_CHECK(pStmt->pVgDataBlocks);
×
2379

UNCOV
2380
    while (++rspObj.resIter < rspObj.dataRsp.blockNum) {
×
2381
      const char* tbName = (const char*)taosArrayGetP(rspObj.dataRsp.blockTbName, rspObj.resIter);
×
2382
      RAW_NULL_CHECK(tbName);
×
2383
      void* pRetrieve = taosArrayGetP(rspObj.dataRsp.blockData, rspObj.resIter);
×
2384
      RAW_NULL_CHECK(pRetrieve);
×
2385
      void* rawData = getRawDataFromRes(pRetrieve);
×
2386
      RAW_NULL_CHECK(rawData);
×
2387

UNCOV
2388
      uTrace(LOG_ID_TAG " write raw data block tbname:%s", LOG_ID_VALUE, tbName);
×
2389
      SName pName = {TSDB_TABLE_NAME_T, pRequest->pTscObj->acctId, {0}, {0}};
×
2390
      tstrncpy(pName.dbname, pRequest->pDb, TSDB_DB_NAME_LEN);
×
2391
      tstrncpy(pName.tname, tbName, TSDB_TABLE_NAME_LEN);
×
2392

2393
      // find schema data info
UNCOV
2394
      STableMeta* pTableMeta = NULL;
×
2395
      RAW_RETURN_CHECK(processCacheMeta(pVgHash, pNameHash, pMetaHash, NULL, pCatalog, &conn, &pName, &pTableMeta, NULL,
×
2396
                                        NULL, retry));
UNCOV
2397
      char err[ERR_MSG_LEN] = {0};
×
2398
      code = rawBlockBindRawData(pVgroupHash, pStmt->pVgDataBlocks, pTableMeta, rawData);
×
2399
      if (code != TSDB_CODE_SUCCESS) {
×
2400
        SET_ERROR_MSG("table:%s, err:%s", pName.tname, err);
×
2401
        goto end;
×
2402
      }
2403
    }
UNCOV
2404
    taosHashCleanup(pVgroupHash);
×
2405
    pVgroupHash = NULL;
×
2406

UNCOV
2407
    RAW_RETURN_CHECK(smlBuildOutputRaw(pQuery, pVgHash));
×
2408
    launchQueryImpl(pRequest, pQuery, true, NULL);
×
2409
    code = pRequest->code;
×
2410

UNCOV
2411
    if (NEED_CLIENT_HANDLE_ERROR(code) && retry++ < 3) {
×
2412
      uInfo("write raw retry:%d/3 end code:%d, msg:%s", retry, code, tstrerror(code));
×
2413
      qDestroyQuery(pQuery);
×
2414
      pQuery = NULL;
×
2415
      rspObj.resIter = -1;
×
2416
      continue;
×
2417
    }
UNCOV
2418
    break;
×
2419
  }
2420

UNCOV
2421
end:
×
2422
  uDebug(LOG_ID_TAG " write raw rawdata return, msg:%s", LOG_ID_VALUE, tstrerror(code));
×
2423
  tDeleteMqDataRsp(&rspObj.dataRsp);
×
2424
  tDecoderClear(&decoder);
×
2425
  qDestroyQuery(pQuery);
×
2426
  taosHashCleanup(pVgroupHash);
×
2427
  destroyRequest(pRequest);
×
2428
  return code;
×
2429
}
2430

2431
static void processSimpleMeta(SMqMetaRsp* pMetaRsp, cJSON** meta) {
9,492✔
2432
  if (pMetaRsp == NULL || meta == NULL) {
9,492✔
UNCOV
2433
    uError("invalid parameter in %s", __func__);
×
2434
    return;
×
2435
  }
2436
  if (pMetaRsp->resMsgType == TDMT_VND_CREATE_STB) {
9,492✔
2437
    processCreateStb(pMetaRsp, meta);
2,466✔
2438
  } else if (pMetaRsp->resMsgType == TDMT_VND_ALTER_STB) {
7,026✔
2439
    processAlterStb(pMetaRsp, meta);
1,385✔
2440
  } else if (pMetaRsp->resMsgType == TDMT_VND_DROP_STB) {
5,641✔
2441
    processDropSTable(pMetaRsp, meta);
256✔
2442
  } else if (pMetaRsp->resMsgType == TDMT_VND_CREATE_TABLE) {
5,385✔
2443
    processCreateTable(pMetaRsp, meta);
4,091✔
2444
  } else if (pMetaRsp->resMsgType == TDMT_VND_ALTER_TABLE) {
1,294✔
2445
    processAlterTable(pMetaRsp, meta);
1,007✔
2446
  } else if (pMetaRsp->resMsgType == TDMT_VND_DROP_TABLE) {
287✔
2447
    processDropTable(pMetaRsp, meta);
181✔
2448
  } else if (pMetaRsp->resMsgType == TDMT_VND_DELETE) {
106✔
2449
    processDeleteTable(pMetaRsp, meta);
106✔
2450
  }
2451
}
2452

2453
static void processBatchMetaToJson(SMqBatchMetaRsp* pMsgRsp, char** string) {
527✔
2454
  if (pMsgRsp == NULL || string == NULL) {
527✔
UNCOV
2455
    uError("invalid parameter in %s", __func__);
×
2456
    return;
×
2457
  }
2458
  SDecoder        coder = {0};
527✔
2459
  SMqBatchMetaRsp rsp = {0};
527✔
2460
  int32_t         code = 0;
527✔
2461
  cJSON*          pJson = NULL;
527✔
2462
  tDecoderInit(&coder, pMsgRsp->pMetaBuff, pMsgRsp->metaBuffLen);
527✔
2463
  if (tDecodeMqBatchMetaRsp(&coder, &rsp) < 0) {
527✔
UNCOV
2464
    goto end;
×
2465
  }
2466

2467
  pJson = cJSON_CreateObject();
527✔
2468
  RAW_NULL_CHECK(pJson);
527✔
2469
  RAW_FALSE_CHECK(cJSON_AddStringToObject(pJson, "tmq_meta_version", TMQ_META_VERSION));
527✔
2470
  cJSON* pMetaArr = cJSON_CreateArray();
527✔
2471
  RAW_NULL_CHECK(pMetaArr);
527✔
2472
  RAW_FALSE_CHECK(tmqAddJsonObjectItem(pJson, "metas", pMetaArr));
527✔
2473

2474
  int32_t num = taosArrayGetSize(rsp.batchMetaReq);
527✔
2475
  for (int32_t i = 0; i < num; i++) {
4,113✔
2476
    int32_t* len = taosArrayGet(rsp.batchMetaLen, i);
3,586✔
2477
    RAW_NULL_CHECK(len);
3,586✔
2478
    void* tmpBuf = taosArrayGetP(rsp.batchMetaReq, i);
3,586✔
2479
    RAW_NULL_CHECK(tmpBuf);
3,586✔
2480
    SDecoder   metaCoder = {0};
3,586✔
2481
    SMqMetaRsp metaRsp = {0};
3,586✔
2482
    tDecoderInit(&metaCoder, POINTER_SHIFT(tmpBuf, sizeof(SMqRspHead)), *len - sizeof(SMqRspHead));
3,586✔
2483
    if (tDecodeMqMetaRsp(&metaCoder, &metaRsp) < 0) {
3,586✔
UNCOV
2484
      goto end;
×
2485
    }
2486
    cJSON* pItem = NULL;
3,586✔
2487
    processSimpleMeta(&metaRsp, &pItem);
3,586✔
2488
    tDeleteMqMetaRsp(&metaRsp);
3,586✔
2489
    RAW_FALSE_CHECK(tmqAddJsonArrayItem(pMetaArr, pItem));
3,586✔
2490
  }
2491

2492
  tDeleteMqBatchMetaRsp(&rsp);
527✔
2493
  char* fullStr = cJSON_PrintUnformatted(pJson);
527✔
2494
  cJSON_Delete(pJson);
527✔
2495
  *string = fullStr;
527✔
2496
  return;
527✔
2497

UNCOV
2498
end:
×
2499
  cJSON_Delete(pJson);
×
2500
  tDeleteMqBatchMetaRsp(&rsp);
×
2501
}
2502

2503
char* tmq_get_json_meta(TAOS_RES* res) {
6,704✔
2504
  if (res == NULL) {
6,704✔
UNCOV
2505
    uError("invalid parameter in %s", __func__);
×
2506
    return NULL;
×
2507
  }
2508
  uDebug("tmq_get_json_meta res:%p", res);
6,704✔
2509
  if (!TD_RES_TMQ_META(res) && !TD_RES_TMQ_METADATA(res) && !TD_RES_TMQ_BATCH_META(res)) {
6,704✔
UNCOV
2510
    return NULL;
×
2511
  }
2512

2513
  char*      string = NULL;
6,704✔
2514
  SMqRspObj* rspObj = (SMqRspObj*)res;
6,704✔
2515
  if (TD_RES_TMQ_METADATA(res)) {
6,704✔
2516
    processAutoCreateTable(&rspObj->dataRsp, &string);
271✔
2517
  } else if (TD_RES_TMQ_BATCH_META(res)) {
6,433✔
2518
    processBatchMetaToJson(&rspObj->batchMetaRsp, &string);
527✔
2519
  } else if (TD_RES_TMQ_META(res)) {
5,906✔
2520
    cJSON* pJson = NULL;
5,906✔
2521
    processSimpleMeta(&rspObj->metaRsp, &pJson);
5,906✔
2522
    string = cJSON_PrintUnformatted(pJson);
5,906✔
2523
    cJSON_Delete(pJson);
5,906✔
2524
  } else {
UNCOV
2525
    uError("tmq_get_json_meta res:%d, invalid type", *(int8_t*)res);
×
2526
  }
2527

2528
  uDebug("tmq_get_json_meta string:%s", string);
6,704✔
2529
  return string;
6,704✔
2530
}
2531

2532
void tmq_free_json_meta(char* jsonMeta) { taosMemoryFreeClear(jsonMeta); }
8,037✔
2533

2534
static int32_t getOffSetLen(const SMqDataRsp* pRsp) {
1,445✔
2535
  if (pRsp == NULL) {
1,445✔
UNCOV
2536
    uError("invalid parameter in %s", __func__);
×
2537
    return TSDB_CODE_INVALID_PARA;
×
2538
  }
2539
  SEncoder coder = {0};
1,445✔
2540
  tEncoderInit(&coder, NULL, 0);
1,445✔
2541
  if (tEncodeSTqOffsetVal(&coder, &pRsp->reqOffset) < 0) return -1;
1,445✔
2542
  if (tEncodeSTqOffsetVal(&coder, &pRsp->rspOffset) < 0) return -1;
1,445✔
2543
  int32_t pos = coder.pos;
1,445✔
2544
  tEncoderClear(&coder);
1,445✔
2545
  return pos;
1,445✔
2546
}
2547

2548
typedef int32_t __encode_func__(SEncoder* pEncoder, const SMqDataRsp* pRsp);
2549
static int32_t  encodeMqDataRsp(__encode_func__* encodeFunc, SMqDataRsp* rspObj, tmq_raw_data* raw) {
1,445✔
2550
  if (raw == NULL || encodeFunc == NULL || rspObj == NULL) {
1,445✔
UNCOV
2551
    uError("invalid parameter in %s", __func__);
×
2552
    return TSDB_CODE_INVALID_PARA;
×
2553
  }
2554
  uint32_t len = 0;
1,445✔
2555
  int32_t  code = 0;
1,445✔
2556
  SEncoder encoder = {0};
1,445✔
2557
  void*    buf = NULL;
1,445✔
2558
  tEncodeSize(encodeFunc, rspObj, len, code);
1,445✔
2559
  if (code < 0) {
1,445✔
UNCOV
2560
    code = TSDB_CODE_INVALID_MSG;
×
2561
    goto FAILED;
×
2562
  }
2563
  len += sizeof(int8_t) + sizeof(int32_t);
1,445✔
2564
  buf = taosMemoryCalloc(1, len);
1,445✔
2565
  if (buf == NULL) {
1,445✔
UNCOV
2566
    code = terrno;
×
2567
    goto FAILED;
×
2568
  }
2569
  tEncoderInit(&encoder, buf, len);
1,445✔
2570
  if (tEncodeI8(&encoder, MQ_DATA_RSP_VERSION) < 0) {
1,445✔
UNCOV
2571
    code = TSDB_CODE_INVALID_MSG;
×
2572
    goto FAILED;
×
2573
  }
2574
  int32_t offsetLen = getOffSetLen(rspObj);
1,445✔
2575
  if (offsetLen <= 0) {
1,445✔
UNCOV
2576
    code = TSDB_CODE_INVALID_MSG;
×
2577
    goto FAILED;
×
2578
  }
2579
  if (tEncodeI32(&encoder, offsetLen) < 0) {
1,445✔
UNCOV
2580
    code = TSDB_CODE_INVALID_MSG;
×
2581
    goto FAILED;
×
2582
  }
2583
  if (encodeFunc(&encoder, rspObj) < 0) {
1,445✔
UNCOV
2584
    code = TSDB_CODE_INVALID_MSG;
×
2585
    goto FAILED;
×
2586
  }
2587
  tEncoderClear(&encoder);
1,445✔
2588

2589
  raw->raw = buf;
1,445✔
2590
  raw->raw_len = len;
1,445✔
2591
  return code;
1,445✔
UNCOV
2592
FAILED:
×
2593
  tEncoderClear(&encoder);
×
2594
  taosMemoryFree(buf);
×
2595
  return code;
×
2596
}
2597

2598
int32_t tmq_get_raw(TAOS_RES* res, tmq_raw_data* raw) {
8,317✔
2599
  if (raw == NULL || res == NULL) {
8,317✔
UNCOV
2600
    uError("invalid parameter in %s", __func__);
×
2601
    return TSDB_CODE_INVALID_PARA;
×
2602
  }
2603
  *raw = (tmq_raw_data){0};
8,317✔
2604
  SMqRspObj* rspObj = ((SMqRspObj*)res);
8,317✔
2605
  if (TD_RES_TMQ_META(res)) {
8,317✔
2606
    raw->raw = rspObj->metaRsp.metaRsp;
6,345✔
2607
    raw->raw_len = rspObj->metaRsp.metaRspLen >= 0 ? rspObj->metaRsp.metaRspLen : 0;
6,345✔
2608
    raw->raw_type = rspObj->metaRsp.resMsgType;
6,345✔
2609
    uDebug("tmq get raw type meta:%p", raw);
6,345✔
2610
  } else if (TD_RES_TMQ(res)) {
1,972✔
2611
    int32_t code = encodeMqDataRsp(tEncodeMqDataRsp, &rspObj->dataRsp, raw);
1,280✔
2612
    if (code != 0) {
1,280✔
UNCOV
2613
      uError("tmq get raw type error:%d", terrno);
×
2614
      return code;
×
2615
    }
2616
    raw->raw_type = RES_TYPE__TMQ;
1,280✔
2617
    uDebug("tmq get raw type data:%p", raw);
1,280✔
2618
  } else if (TD_RES_TMQ_METADATA(res)) {
692✔
2619
    int32_t code = encodeMqDataRsp(tEncodeSTaosxRsp, &rspObj->dataRsp, raw);
165✔
2620
    if (code != 0) {
165✔
UNCOV
2621
      uError("tmq get raw type error:%d", terrno);
×
2622
      return code;
×
2623
    }
2624
    raw->raw_type = RES_TYPE__TMQ_METADATA;
165✔
2625
    uDebug("tmq get raw type metadata:%p", raw);
165✔
2626
  } else if (TD_RES_TMQ_BATCH_META(res)) {
527✔
2627
    raw->raw = rspObj->batchMetaRsp.pMetaBuff;
527✔
2628
    raw->raw_len = rspObj->batchMetaRsp.metaBuffLen;
527✔
2629
    raw->raw_type = rspObj->resType;
527✔
2630
    uDebug("tmq get raw batch meta:%p", raw);
527✔
UNCOV
2631
  } else if (TD_RES_TMQ_RAW(res)) {
×
2632
    raw->raw = rspObj->dataRsp.rawData;
×
2633
    rspObj->dataRsp.rawData = NULL;
×
2634
    raw->raw_len = rspObj->dataRsp.len;
×
2635
    raw->raw_type = rspObj->resType;
×
2636
    uDebug("tmq get raw raw:%p", raw);
×
2637
  } else {
UNCOV
2638
    uError("tmq get raw error type:%d", *(int8_t*)res);
×
2639
    return TSDB_CODE_TMQ_INVALID_MSG;
×
2640
  }
2641
  return TSDB_CODE_SUCCESS;
8,317✔
2642
}
2643

2644
void tmq_free_raw(tmq_raw_data raw) {
8,317✔
2645
  uDebug("tmq free raw data type:%d", raw.raw_type);
8,317✔
2646
  if (raw.raw_type == RES_TYPE__TMQ || raw.raw_type == RES_TYPE__TMQ_METADATA) {
8,317✔
2647
    taosMemoryFree(raw.raw);
1,445✔
2648
  } else if (raw.raw_type == RES_TYPE__TMQ_RAWDATA && raw.raw != NULL) {
6,872✔
UNCOV
2649
    taosMemoryFree(POINTER_SHIFT(raw.raw, -sizeof(SMqRspHead)));
×
2650
  }
2651
  (void)memset(terrMsg, 0, ERR_MSG_LEN);
8,317✔
2652
}
8,317✔
2653

2654
static int32_t writeRawInit() {
11,166✔
2655
  while (atomic_load_8(&initedFlag) == WRITE_RAW_INIT_START) {
11,594✔
2656
    int8_t old = atomic_val_compare_exchange_8(&initFlag, 0, 1);
428✔
2657
    if (old == 0) {
428✔
2658
      int32_t code = initRawCacheHash();
428✔
2659
      if (code != 0) {
428✔
UNCOV
2660
        uError("tmq writeRawImpl init error:%d", code);
×
2661
        atomic_store_8(&initedFlag, WRITE_RAW_INIT_FAIL);
×
2662
        return code;
×
2663
      }
2664
      atomic_store_8(&initedFlag, WRITE_RAW_INIT_OK);
428✔
2665
    }
2666
  }
2667

2668
  if (atomic_load_8(&initedFlag) == WRITE_RAW_INIT_FAIL) {
11,166✔
UNCOV
2669
    return TSDB_CODE_INTERNAL_ERROR;
×
2670
  }
2671
  return 0;
11,166✔
2672
}
2673

2674
static int32_t writeRawImpl(TAOS* taos, void* buf, uint32_t len, uint16_t type) {
11,166✔
2675
  if (taos == NULL || buf == NULL) {
11,166✔
UNCOV
2676
    uError("invalid parameter in %s", __func__);
×
2677
    return TSDB_CODE_INVALID_PARA;
×
2678
  }
2679
  if (writeRawInit() != 0) {
11,166✔
UNCOV
2680
    return TSDB_CODE_INTERNAL_ERROR;
×
2681
  }
2682

2683
  if (type == TDMT_VND_CREATE_STB) {
11,166✔
2684
    return taosCreateStb(taos, buf, len);
2,370✔
2685
  } else if (type == TDMT_VND_ALTER_STB) {
8,796✔
2686
    return taosCreateStb(taos, buf, len);
1,385✔
2687
  } else if (type == TDMT_VND_DROP_STB) {
7,411✔
2688
    return taosDropStb(taos, buf, len);
256✔
2689
  } else if (type == TDMT_VND_CREATE_TABLE) {
7,155✔
2690
    return taosCreateTable(taos, buf, len);
3,942✔
2691
  } else if (type == TDMT_VND_ALTER_TABLE) {
3,213✔
2692
    return taosAlterTable(taos, buf, len);
954✔
2693
  } else if (type == TDMT_VND_DROP_TABLE) {
2,259✔
2694
    return taosDropTable(taos, buf, len);
181✔
2695
  } else if (type == TDMT_VND_DELETE) {
2,078✔
2696
    return taosDeleteData(taos, buf, len);
106✔
2697
  } else if (type == RES_TYPE__TMQ_METADATA) {
1,972✔
2698
    return tmqWriteRawMetaDataImpl(taos, buf, len);
165✔
2699
  } else if (type == RES_TYPE__TMQ_RAWDATA) {
1,807✔
UNCOV
2700
    return tmqWriteRawRawDataImpl(taos, buf, len);
×
2701
  } else if (type == RES_TYPE__TMQ) {
1,807✔
2702
    return tmqWriteRawDataImpl(taos, buf, len);
1,280✔
2703
  } else if (type == RES_TYPE__TMQ_BATCH_META) {
527✔
2704
    return tmqWriteBatchMetaDataImpl(taos, buf, len);
527✔
2705
  }
UNCOV
2706
  return TSDB_CODE_INVALID_PARA;
×
2707
}
2708

2709
int32_t tmq_write_raw(TAOS* taos, tmq_raw_data raw) {
7,992✔
2710
  if (taos == NULL || raw.raw == NULL || raw.raw_len <= 0) {
7,992✔
2711
    SET_ERROR_MSG("taos:%p or data:%p is NULL or raw_len <= 0", taos, raw.raw);
412✔
2712
    return TSDB_CODE_INVALID_PARA;
412✔
2713
  }
2714
  taosClearErrMsg();  // clear global error message
7,580✔
2715

2716
  return writeRawImpl(taos, raw.raw, raw.raw_len, raw.raw_type);
7,580✔
2717
}
2718

2719
static int32_t tmqWriteBatchMetaDataImpl(TAOS* taos, void* meta, uint32_t metaLen) {
527✔
2720
  if (taos == NULL || meta == NULL) {
527✔
UNCOV
2721
    uError("invalid parameter in %s", __func__);
×
2722
    return TSDB_CODE_INVALID_PARA;
×
2723
  }
2724
  SMqBatchMetaRsp rsp = {0};
527✔
2725
  SDecoder        coder = {0};
527✔
2726
  int32_t         code = TSDB_CODE_SUCCESS;
527✔
2727

2728
  // decode and process req
2729
  tDecoderInit(&coder, meta, metaLen);
527✔
2730
  if (tDecodeMqBatchMetaRsp(&coder, &rsp) < 0) {
527✔
UNCOV
2731
    code = TSDB_CODE_INVALID_PARA;
×
2732
    goto end;
×
2733
  }
2734
  int32_t num = taosArrayGetSize(rsp.batchMetaReq);
527✔
2735
  for (int32_t i = 0; i < num; i++) {
4,113✔
2736
    int32_t* len = taosArrayGet(rsp.batchMetaLen, i);
3,586✔
2737
    RAW_NULL_CHECK(len);
3,586✔
2738
    void* tmpBuf = taosArrayGetP(rsp.batchMetaReq, i);
3,586✔
2739
    RAW_NULL_CHECK(tmpBuf);
3,586✔
2740
    SDecoder   metaCoder = {0};
3,586✔
2741
    SMqMetaRsp metaRsp = {0};
3,586✔
2742
    tDecoderInit(&metaCoder, POINTER_SHIFT(tmpBuf, sizeof(SMqRspHead)), *len - sizeof(SMqRspHead));
3,586✔
2743
    if (tDecodeMqMetaRsp(&metaCoder, &metaRsp) < 0) {
3,586✔
UNCOV
2744
      code = TSDB_CODE_INVALID_PARA;
×
2745
      goto end;
×
2746
    }
2747
    code = writeRawImpl(taos, metaRsp.metaRsp, metaRsp.metaRspLen, metaRsp.resMsgType);
3,586✔
2748
    tDeleteMqMetaRsp(&metaRsp);
3,586✔
2749
    if (code != TSDB_CODE_SUCCESS) {
3,586✔
UNCOV
2750
      goto end;
×
2751
    }
2752
  }
2753

2754
end:
527✔
2755
  tDeleteMqBatchMetaRsp(&rsp);
527✔
2756
  return code;
527✔
2757
}
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