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

taosdata / TDengine / #5048

10 May 2026 03:11AM UTC coverage: 73.222% (+0.07%) from 73.152%
#5048

push

travis-ci

web-flow
merge: from main to 3.0 branch #35290

353 of 452 new or added lines in 9 files covered. (78.1%)

587 existing lines in 140 files now uncovered.

278189 of 379928 relevant lines covered (73.22%)

135206397.85 hits per line

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

81.72
/include/common/tmsg.h
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
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

19
#include <stdint.h>
20
#include "taosdef.h"
21
#include "taoserror.h"
22
#include "tarray.h"
23
#include "tcoding.h"
24
#include "tcol.h"
25
#include "tencode.h"
26
#include "thash.h"
27
#include "tlist.h"
28
#include "tname.h"
29
#include "tpriv.h"
30
#include "trow.h"
31
#include "tuuid.h"
32

33
#ifdef __cplusplus
34
extern "C" {
35
#endif
36

37
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
38

39
#define TD_MSG_NUMBER_
40
#undef TD_MSG_DICT_
41
#undef TD_MSG_INFO_
42
#undef TD_MSG_TYPE_INFO_
43
#undef TD_MSG_RANGE_CODE_
44
#undef TD_MSG_SEG_CODE_
45
#include "tmsgdef.h"
46

47
#undef TD_MSG_NUMBER_
48
#undef TD_MSG_DICT_
49
#undef TD_MSG_INFO_
50
#undef TD_MSG_TYPE_INFO_
51
#undef TD_MSG_RANGE_CODE_
52
#define TD_MSG_SEG_CODE_
53
#include "tmsgdef.h"
54

55
#undef TD_MSG_NUMBER_
56
#undef TD_MSG_DICT_
57
#undef TD_MSG_INFO_
58
#undef TD_MSG_TYPE_INFO_
59
#undef TD_MSG_SEG_CODE_
60
#undef TD_MSG_RANGE_CODE_
61
#include "tmsgdef.h"
62

63
extern char*   tMsgInfo[];
64
extern int32_t tMsgDict[];
65
extern int32_t tMsgRangeDict[];
66

67
typedef uint16_t tmsg_t;
68

69
#define TMSG_SEG_CODE(TYPE) (((TYPE) & 0xff00) >> 8)
70
#define TMSG_SEG_SEQ(TYPE)  ((TYPE) & 0xff)
71
#define TMSG_INDEX(TYPE)    (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE))
72

73
#define DECODESQL()                                                              \
74
  do {                                                                           \
75
    if (!tDecodeIsEnd(&decoder)) {                                               \
76
      TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->sqlLen));                      \
77
      if (pReq->sqlLen > 0) {                                                    \
78
        TAOS_CHECK_EXIT(tDecodeBinaryAlloc(&decoder, (void**)&pReq->sql, NULL)); \
79
      }                                                                          \
80
    }                                                                            \
81
  } while (0)
82

83
#define ENCODESQL()                                                                      \
84
  do {                                                                                   \
85
    TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->sqlLen));                                 \
86
    if (pReq->sqlLen > 0) {                                                              \
87
      TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (const uint8_t*)pReq->sql, pReq->sqlLen)); \
88
    }                                                                                    \
89
  } while (0)
90

91
#define FREESQL()                \
92
  do {                           \
93
    if (pReq->sql != NULL) {     \
94
      taosMemoryFree(pReq->sql); \
95
    }                            \
96
    pReq->sql = NULL;            \
97
  } while (0)
98

99
static inline bool tmsgIsValid(tmsg_t type) {
2,147,483,647✔
100
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
101
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
2,147,483,647✔
102
  int    segIdx = TMSG_SEG_CODE(type);
2,147,483,647✔
103
  if (segIdx >= 0 && segIdx < maxSegIdx) {
2,147,483,647✔
104
    return type < tMsgRangeDict[segIdx];
2,147,483,647✔
105
  }
UNCOV
106
  return false;
×
107
}
108

109
#define TMSG_INFO(type) (tmsgIsValid(type) ? tMsgInfo[TMSG_INDEX(type)] : "unKnown")
110

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
2,147,483,647✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
2,147,483,647✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
2,147,483,647✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
2,147,483,647✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
2,147,483,647✔
119
}
120

121
/* ------------------------ OTHER DEFINITIONS ------------------------ */
122
// IE type
123
#define TSDB_IE_TYPE_SEC         1
124
#define TSDB_IE_TYPE_META        2
125
#define TSDB_IE_TYPE_MGMT_IP     3
126
#define TSDB_IE_TYPE_DNODE_CFG   4
127
#define TSDB_IE_TYPE_NEW_VERSION 5
128
#define TSDB_IE_TYPE_DNODE_EXT   6
129
#define TSDB_IE_TYPE_DNODE_STATE 7
130

131
enum {
132
  CONN_TYPE__QUERY = 1,
133
  CONN_TYPE__TMQ,
134
  CONN_TYPE__UDFD,
135
  CONN_TYPE__AUTH_TEST, // only for test authentication
136
  CONN_TYPE__MAX,
137
};
138

139
enum {
140
  HEARTBEAT_KEY_USER_AUTHINFO = 1,
141
  HEARTBEAT_KEY_DBINFO,
142
  HEARTBEAT_KEY_STBINFO,
143
  HEARTBEAT_KEY_TMQ,
144
  HEARTBEAT_KEY_DYN_VIEW,
145
  HEARTBEAT_KEY_VIEWINFO,
146
  HEARTBEAT_KEY_TSMA,
147
};
148

149
typedef enum _mgmt_table {
150
  TSDB_MGMT_TABLE_START,
151
  TSDB_MGMT_TABLE_DNODE,
152
  TSDB_MGMT_TABLE_MNODE,
153
  TSDB_MGMT_TABLE_MODULE,
154
  TSDB_MGMT_TABLE_QNODE,
155
  TSDB_MGMT_TABLE_SNODE,
156
  TSDB_MGMT_TABLE_BACKUP_NODE,  // no longer used
157
  TSDB_MGMT_TABLE_CLUSTER,
158
  TSDB_MGMT_TABLE_DB,
159
  TSDB_MGMT_TABLE_FUNC,
160
  TSDB_MGMT_TABLE_INDEX,
161
  TSDB_MGMT_TABLE_STB,
162
  TSDB_MGMT_TABLE_STREAMS,
163
  TSDB_MGMT_TABLE_TABLE,
164
  TSDB_MGMT_TABLE_TAG,
165
  TSDB_MGMT_TABLE_COL,
166
  TSDB_MGMT_TABLE_USER,
167
  TSDB_MGMT_TABLE_GRANTS,
168
  TSDB_MGMT_TABLE_VGROUP,
169
  TSDB_MGMT_TABLE_TOPICS,
170
  TSDB_MGMT_TABLE_CONSUMERS,
171
  TSDB_MGMT_TABLE_SUBSCRIPTIONS,
172
  TSDB_MGMT_TABLE_TRANS,
173
  TSDB_MGMT_TABLE_SMAS,
174
  TSDB_MGMT_TABLE_CONFIGS,
175
  TSDB_MGMT_TABLE_CONNS,
176
  TSDB_MGMT_TABLE_QUERIES,
177
  TSDB_MGMT_TABLE_VNODES,
178
  TSDB_MGMT_TABLE_APPS,
179
  TSDB_MGMT_TABLE_STREAM_TASKS,
180
  TSDB_MGMT_TABLE_STREAM_RECALCULATES,
181
  TSDB_MGMT_TABLE_PRIVILEGES,
182
  TSDB_MGMT_TABLE_VIEWS,
183
  TSDB_MGMT_TABLE_TSMAS,
184
  TSDB_MGMT_TABLE_COMPACT,
185
  TSDB_MGMT_TABLE_COMPACT_DETAIL,
186
  TSDB_MGMT_TABLE_GRANTS_FULL,
187
  TSDB_MGMT_TABLE_GRANTS_LOGS,
188
  TSDB_MGMT_TABLE_MACHINES,
189
  TSDB_MGMT_TABLE_ARBGROUP,
190
  TSDB_MGMT_TABLE_ENCRYPTIONS,
191
  TSDB_MGMT_TABLE_USER_FULL,
192
  TSDB_MGMT_TABLE_ANODE,
193
  TSDB_MGMT_TABLE_ANODE_FULL,
194
  TSDB_MGMT_TABLE_USAGE,
195
  TSDB_MGMT_TABLE_FILESETS,
196
  TSDB_MGMT_TABLE_TRANSACTION_DETAIL,
197
  TSDB_MGMT_TABLE_VC_COL,
198
  TSDB_MGMT_TABLE_BNODE,
199
  TSDB_MGMT_TABLE_MOUNT,
200
  TSDB_MGMT_TABLE_SSMIGRATE,
201
  TSDB_MGMT_TABLE_SCAN,
202
  TSDB_MGMT_TABLE_SCAN_DETAIL,
203
  TSDB_MGMT_TABLE_RSMA,
204
  TSDB_MGMT_TABLE_RETENTION,
205
  TSDB_MGMT_TABLE_RETENTION_DETAIL,
206
  TSDB_MGMT_TABLE_INSTANCE,
207
  TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS,
208
  TSDB_MGMT_TABLE_TOKEN,
209
  TSDB_MGMT_TABLE_ENCRYPT_STATUS,
210
  TSDB_MGMT_TABLE_ROLE,
211
  TSDB_MGMT_TABLE_ROLE_PRIVILEGES,
212
  TSDB_MGMT_TABLE_ROLE_COL_PRIVILEGES,
213
  TSDB_MGMT_TABLE_XNODES,
214
  TSDB_MGMT_TABLE_XNODE_TASKS,
215
  TSDB_MGMT_TABLE_XNODE_AGENTS,
216
  TSDB_MGMT_TABLE_XNODE_JOBS,
217
  TSDB_MGMT_TABLE_XNODE_FULL,
218
  TSDB_MGMT_TABLE_VIRTUAL_TABLES_REFERENCING,
219
  TSDB_MGMT_TABLE_SECURITY_POLICIES,
220
  TSDB_MGMT_TABLE_MAX,
221
} EShowType;
222

223
typedef enum {
224
  TSDB_OPTR_NORMAL = 0,  // default
225
  TSDB_OPTR_SSMIGRATE = 1,
226
  TSDB_OPTR_ROLLUP = 2,
227
} ETsdbOpType;
228

229
typedef enum {
230
  TSDB_TRIGGER_MANUAL = 0,  // default
231
  TSDB_TRIGGER_AUTO = 1,
232
} ETriggerType;
233

234
#define TSDB_ALTER_TABLE_ADD_TAG                         1
235
#define TSDB_ALTER_TABLE_DROP_TAG                        2
236
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
237
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4 // deprecated, kept for wire compatibility
238
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
239
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
240
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
241
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
242
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
243
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
244
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
245
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
246
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
247
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
248
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15 // deprecated, kept for wire compatibility
249
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
250
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
251
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
252
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL      19 // alter multiple tag values of multi tables
253
#define TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL      20 // alter multiple tag values of the child tables of a stable
254

255
#define TSDB_FILL_NONE        0
256
#define TSDB_FILL_NULL        1
257
#define TSDB_FILL_NULL_F      2
258
#define TSDB_FILL_SET_VALUE   3
259
#define TSDB_FILL_SET_VALUE_F 4
260
#define TSDB_FILL_LINEAR      5
261
#define TSDB_FILL_PREV        6
262
#define TSDB_FILL_NEXT        7
263
#define TSDB_FILL_NEAR        8
264

265

266
#define TSDB_ALTER_USER_BASIC_INFO             1
267
// these definitions start from 5 is to keep compatible with old versions
268
#define TSDB_ALTER_USER_ADD_PRIVILEGES         5
269
#define TSDB_ALTER_USER_DEL_PRIVILEGES         6
270

271

272
#define TSDB_ALTER_ROLE_LOCK            0x1
273
#define TSDB_ALTER_ROLE_ROLE            0x2
274
#define TSDB_ALTER_ROLE_PRIVILEGES      0x3
275
#define TSDB_ALTER_ROLE_MAX             0x4 // increase according to actual use
276

277
#define TSDB_ALTER_RSMA_FUNCTION        0x1
278

279
#define TSDB_KILL_MSG_LEN 30
280

281
#define TSDB_TABLE_NUM_UNIT 100000
282

283
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
284
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
285
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
286

287
#define TSDB_COL_NORMAL 0x0u  // the normal column of the table
288
#define TSDB_COL_TAG    0x1u  // the tag column type
289
#define TSDB_COL_UDC    0x2u  // the user specified normal string column, it is a dummy column
290
#define TSDB_COL_TMP    0x4u  // internal column generated by the previous operators
291
#define TSDB_COL_NULL   0x8u  // the column filter NULL or not
292

293
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
294
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
295
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
296
#define TSDB_COL_REQ_NULL(f)      (((f) & TSDB_COL_NULL) != 0)
297

298
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
299
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
300
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
301
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
302
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
303

304
typedef enum ENodeType {
305
  // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
306
  // VALUE, OPERATOR, FUNCTION and so on.
307
  QUERY_NODE_COLUMN = 1,
308
  QUERY_NODE_VALUE,
309
  QUERY_NODE_OPERATOR,
310
  QUERY_NODE_LOGIC_CONDITION,
311
  QUERY_NODE_FUNCTION,
312
  QUERY_NODE_REAL_TABLE,
313
  QUERY_NODE_TEMP_TABLE,
314
  QUERY_NODE_JOIN_TABLE,
315
  QUERY_NODE_GROUPING_SET,
316
  QUERY_NODE_ORDER_BY_EXPR,
317
  QUERY_NODE_LIMIT,
318
  QUERY_NODE_STATE_WINDOW,
319
  QUERY_NODE_SESSION_WINDOW,
320
  QUERY_NODE_INTERVAL_WINDOW,
321
  QUERY_NODE_NODE_LIST,
322
  QUERY_NODE_FILL,
323
  QUERY_NODE_RAW_EXPR,  // Only be used in parser module.
324
  QUERY_NODE_TARGET,
325
  QUERY_NODE_DATABLOCK_DESC,
326
  QUERY_NODE_SLOT_DESC,
327
  QUERY_NODE_COLUMN_DEF,
328
  QUERY_NODE_DOWNSTREAM_SOURCE,
329
  QUERY_NODE_DATABASE_OPTIONS,
330
  QUERY_NODE_TABLE_OPTIONS,
331
  QUERY_NODE_INDEX_OPTIONS,
332
  QUERY_NODE_EXPLAIN_OPTIONS,
333
  QUERY_NODE_LEFT_VALUE,
334
  QUERY_NODE_COLUMN_REF,
335
  QUERY_NODE_WHEN_THEN,
336
  QUERY_NODE_CASE_WHEN,
337
  QUERY_NODE_EVENT_WINDOW,
338
  QUERY_NODE_HINT,
339
  QUERY_NODE_VIEW,
340
  QUERY_NODE_WINDOW_OFFSET,
341
  QUERY_NODE_COUNT_WINDOW,
342
  QUERY_NODE_COLUMN_OPTIONS,
343
  QUERY_NODE_TSMA_OPTIONS,
344
  QUERY_NODE_ANOMALY_WINDOW,
345
  QUERY_NODE_RANGE_AROUND,
346
  QUERY_NODE_STREAM_NOTIFY_OPTIONS,
347
  QUERY_NODE_VIRTUAL_TABLE,
348
  QUERY_NODE_SLIDING_WINDOW,
349
  QUERY_NODE_PERIOD_WINDOW,
350
  QUERY_NODE_STREAM_TRIGGER,
351
  QUERY_NODE_STREAM,
352
  QUERY_NODE_STREAM_TAG_DEF,
353
  QUERY_NODE_EXTERNAL_WINDOW,
354
  QUERY_NODE_STREAM_TRIGGER_OPTIONS,
355
  QUERY_NODE_PLACE_HOLDER_TABLE,
356
  QUERY_NODE_TIME_RANGE,
357
  QUERY_NODE_STREAM_OUT_TABLE,
358
  QUERY_NODE_STREAM_CALC_RANGE,
359
  QUERY_NODE_COUNT_WINDOW_ARGS,
360
  QUERY_NODE_BNODE_OPTIONS,
361
  QUERY_NODE_DATE_TIME_RANGE,
362
  QUERY_NODE_IP_RANGE,
363
  QUERY_NODE_USER_OPTIONS,
364
  QUERY_NODE_REMOTE_VALUE,
365
  QUERY_NODE_TOKEN_OPTIONS,
366
  QUERY_NODE_TRUE_FOR,
367
  QUERY_NODE_REMOTE_VALUE_LIST,
368
  QUERY_NODE_SURROUND,
369
  QUERY_NODE_REMOTE_ROW,
370
  QUERY_NODE_REMOTE_ZERO_ROWS,
371
  QUERY_NODE_UPDATE_TAG_VALUE,
372
  QUERY_NODE_ALTER_TABLE_UPDATE_TAG_VAL_CLAUSE,
373
  QUERY_NODE_REMOTE_TABLE,
374

375
  // Statement nodes are used in parser and planner module.
376
  QUERY_NODE_SET_OPERATOR = 100,
377
  QUERY_NODE_SELECT_STMT,
378
  QUERY_NODE_VNODE_MODIFY_STMT,
379
  QUERY_NODE_CREATE_DATABASE_STMT,
380
  QUERY_NODE_DROP_DATABASE_STMT,
381
  QUERY_NODE_ALTER_DATABASE_STMT,
382
  QUERY_NODE_FLUSH_DATABASE_STMT,
383
  QUERY_NODE_TRIM_DATABASE_STMT,
384
  QUERY_NODE_CREATE_TABLE_STMT,
385
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
386
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
387
  QUERY_NODE_DROP_TABLE_CLAUSE,
388
  QUERY_NODE_DROP_TABLE_STMT,
389
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
390
  QUERY_NODE_ALTER_TABLE_STMT,
391
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
392
  QUERY_NODE_CREATE_USER_STMT,
393
  QUERY_NODE_ALTER_USER_STMT,
394
  QUERY_NODE_DROP_USER_STMT,
395
  QUERY_NODE_USE_DATABASE_STMT,
396
  QUERY_NODE_CREATE_DNODE_STMT,
397
  QUERY_NODE_DROP_DNODE_STMT,
398
  QUERY_NODE_ALTER_DNODE_STMT,
399
  QUERY_NODE_CREATE_INDEX_STMT,
400
  QUERY_NODE_DROP_INDEX_STMT,
401
  QUERY_NODE_CREATE_QNODE_STMT,
402
  QUERY_NODE_DROP_QNODE_STMT,
403
  QUERY_NODE_CREATE_BACKUP_NODE_STMT,  // no longer used
404
  QUERY_NODE_DROP_BACKUP_NODE_STMT,    // no longer used
405
  QUERY_NODE_CREATE_SNODE_STMT,
406
  QUERY_NODE_DROP_SNODE_STMT,
407
  QUERY_NODE_CREATE_MNODE_STMT,
408
  QUERY_NODE_DROP_MNODE_STMT,
409
  QUERY_NODE_CREATE_TOPIC_STMT,
410
  QUERY_NODE_DROP_TOPIC_STMT,
411
  QUERY_NODE_DROP_CGROUP_STMT,
412
  QUERY_NODE_ALTER_LOCAL_STMT,
413
  QUERY_NODE_EXPLAIN_STMT,
414
  QUERY_NODE_DESCRIBE_STMT,
415
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
416
  QUERY_NODE_COMPACT_DATABASE_STMT,
417
  QUERY_NODE_COMPACT_VGROUPS_STMT,
418
  QUERY_NODE_CREATE_FUNCTION_STMT,
419
  QUERY_NODE_DROP_FUNCTION_STMT,
420
  QUERY_NODE_CREATE_STREAM_STMT,
421
  QUERY_NODE_DROP_STREAM_STMT,
422
  QUERY_NODE_BALANCE_VGROUP_STMT,
423
  QUERY_NODE_MERGE_VGROUP_STMT,
424
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
425
  QUERY_NODE_SPLIT_VGROUP_STMT,
426
  QUERY_NODE_SYNCDB_STMT,
427
  QUERY_NODE_GRANT_STMT,
428
  QUERY_NODE_REVOKE_STMT,
429
  QUERY_NODE_ALTER_CLUSTER_STMT,
430
  QUERY_NODE_SSMIGRATE_DATABASE_STMT,
431
  QUERY_NODE_CREATE_TSMA_STMT,
432
  QUERY_NODE_DROP_TSMA_STMT,
433
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
434
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
435
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
436
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
437
  QUERY_NODE_CREATE_MOUNT_STMT,
438
  QUERY_NODE_DROP_MOUNT_STMT,
439
  QUERY_NODE_SCAN_DATABASE_STMT,
440
  QUERY_NODE_SCAN_VGROUPS_STMT,
441
  QUERY_NODE_TRIM_DATABASE_WAL_STMT,
442
  QUERY_NODE_ALTER_DNODES_RELOAD_TLS_STMT,
443
  QUERY_NODE_CREATE_TOKEN_STMT,
444
  QUERY_NODE_ALTER_TOKEN_STMT,
445
  QUERY_NODE_DROP_TOKEN_STMT,
446
  QUERY_NODE_ALTER_ENCRYPT_KEY_STMT,
447
  QUERY_NODE_CREATE_ROLE_STMT,
448
  QUERY_NODE_DROP_ROLE_STMT,
449
  QUERY_NODE_ALTER_ROLE_STMT,
450
  QUERY_NODE_CREATE_TOTP_SECRET_STMT,
451
  QUERY_NODE_DROP_TOTP_SECRET_STMT,
452
  QUERY_NODE_ALTER_KEY_EXPIRATION_STMT,
453

454
  // placeholder for [155, 180]
455
  QUERY_NODE_SHOW_CREATE_VIEW_STMT = 181,
456
  QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
457
  QUERY_NODE_SHOW_CREATE_TABLE_STMT,
458
  QUERY_NODE_SHOW_CREATE_STABLE_STMT,
459
  QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT,
460
  QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT,
461
  QUERY_NODE_SHOW_SCORES_STMT,
462
  QUERY_NODE_SHOW_TABLE_TAGS_STMT,
463
  QUERY_NODE_KILL_CONNECTION_STMT,
464
  QUERY_NODE_KILL_QUERY_STMT,
465
  QUERY_NODE_KILL_TRANSACTION_STMT,
466
  QUERY_NODE_KILL_COMPACT_STMT,
467
  QUERY_NODE_DELETE_STMT,
468
  QUERY_NODE_INSERT_STMT,
469
  QUERY_NODE_QUERY,
470
  QUERY_NODE_SHOW_DB_ALIVE_STMT,
471
  QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
472
  QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
473
  QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT,
474
  QUERY_NODE_RESTORE_DNODE_STMT,
475
  QUERY_NODE_RESTORE_QNODE_STMT,
476
  QUERY_NODE_RESTORE_MNODE_STMT,
477
  QUERY_NODE_RESTORE_VNODE_STMT,
478
  QUERY_NODE_PAUSE_STREAM_STMT,
479
  QUERY_NODE_RESUME_STREAM_STMT,
480
  QUERY_NODE_CREATE_VIEW_STMT,
481
  QUERY_NODE_DROP_VIEW_STMT,
482
  QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE,
483
  QUERY_NODE_CREATE_ANODE_STMT,
484
  QUERY_NODE_DROP_ANODE_STMT,
485
  QUERY_NODE_UPDATE_ANODE_STMT,
486
  QUERY_NODE_ASSIGN_LEADER_STMT,
487
  QUERY_NODE_SHOW_CREATE_TSMA_STMT,
488
  QUERY_NODE_SHOW_CREATE_VTABLE_STMT,
489
  QUERY_NODE_RECALCULATE_STREAM_STMT,
490
  QUERY_NODE_CREATE_BNODE_STMT,
491
  QUERY_NODE_DROP_BNODE_STMT,
492
  QUERY_NODE_KILL_SSMIGRATE_STMT,
493
  QUERY_NODE_KILL_SCAN_STMT,
494
  QUERY_NODE_CREATE_RSMA_STMT,
495
  QUERY_NODE_DROP_RSMA_STMT,
496
  QUERY_NODE_ALTER_RSMA_STMT,
497
  QUERY_NODE_SHOW_CREATE_RSMA_STMT,
498
  QUERY_NODE_ROLLUP_DATABASE_STMT,
499
  QUERY_NODE_ROLLUP_VGROUPS_STMT,
500
  QUERY_NODE_KILL_RETENTION_STMT,
501
  QUERY_NODE_SET_VGROUP_KEEP_VERSION_STMT,
502
  QUERY_NODE_CREATE_ENCRYPT_ALGORITHMS_STMT,
503
  QUERY_NODE_DROP_ENCRYPT_ALGR_STMT,
504

505
  // show statement nodes
506
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
507
  QUERY_NODE_SHOW_DNODES_STMT = 400,
508
  QUERY_NODE_SHOW_MNODES_STMT,
509
  QUERY_NODE_SHOW_MODULES_STMT,
510
  QUERY_NODE_SHOW_QNODES_STMT,
511
  QUERY_NODE_SHOW_SNODES_STMT,
512
  QUERY_NODE_SHOW_BACKUP_NODES_STMT,  // no longer used
513
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
514
  QUERY_NODE_SHOW_CLUSTER_STMT,
515
  QUERY_NODE_SHOW_DATABASES_STMT,
516
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
517
  QUERY_NODE_SHOW_INDEXES_STMT,
518
  QUERY_NODE_SHOW_STABLES_STMT,
519
  QUERY_NODE_SHOW_STREAMS_STMT,
520
  QUERY_NODE_SHOW_TABLES_STMT,
521
  QUERY_NODE_SHOW_TAGS_STMT,
522
  QUERY_NODE_SHOW_USERS_STMT,
523
  QUERY_NODE_SHOW_USERS_FULL_STMT,
524
  QUERY_NODE_SHOW_LICENCES_STMT,
525
  QUERY_NODE_SHOW_VGROUPS_STMT,
526
  QUERY_NODE_SHOW_TOPICS_STMT,
527
  QUERY_NODE_SHOW_CONSUMERS_STMT,
528
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
529
  QUERY_NODE_SHOW_QUERIES_STMT,
530
  QUERY_NODE_SHOW_APPS_STMT,
531
  QUERY_NODE_SHOW_VARIABLES_STMT,
532
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
533
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
534
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
535
  QUERY_NODE_SHOW_VNODES_STMT,
536
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
537
  QUERY_NODE_SHOW_VIEWS_STMT,
538
  QUERY_NODE_SHOW_COMPACTS_STMT,
539
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
540
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
541
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
542
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
543
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
544
  QUERY_NODE_SHOW_TSMAS_STMT,
545
  QUERY_NODE_SHOW_ANODES_STMT,
546
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
547
  QUERY_NODE_SHOW_USAGE_STMT,
548
  QUERY_NODE_SHOW_FILESETS_STMT,
549
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
550
  QUERY_NODE_SHOW_VTABLES_STMT,
551
  QUERY_NODE_SHOW_BNODES_STMT,
552
  QUERY_NODE_SHOW_MOUNTS_STMT,
553
  QUERY_NODE_SHOW_SSMIGRATES_STMT,
554
  QUERY_NODE_SHOW_SCANS_STMT,
555
  QUERY_NODE_SHOW_SCAN_DETAILS_STMT,
556
  QUERY_NODE_SHOW_RSMAS_STMT,
557
  QUERY_NODE_SHOW_RETENTIONS_STMT,
558
  QUERY_NODE_SHOW_RETENTION_DETAILS_STMT,
559
  QUERY_NODE_SHOW_INSTANCES_STMT,
560
  QUERY_NODE_SHOW_ENCRYPT_ALGORITHMS_STMT,
561
  // the order of QUERY_NODE_SHOW_* must be aligned with the order of `sysTableShowAdapter` defines.
562
  QUERY_NODE_SHOW_TOKENS_STMT,
563
  QUERY_NODE_SHOW_ENCRYPT_STATUS_STMT,
564
  QUERY_NODE_SHOW_ROLES_STMT,
565
  QUERY_NODE_SHOW_ROLE_PRIVILEGES_STMT,
566
  QUERY_NODE_SHOW_ROLE_COL_PRIVILEGES_STMT,
567
  QUERY_NODE_SHOW_XNODES_STMT,
568
  QUERY_NODE_SHOW_XNODE_TASKS_STMT,
569
  QUERY_NODE_SHOW_XNODE_AGENTS_STMT,
570
  QUERY_NODE_SHOW_XNODE_JOBS_STMT,
571
  QUERY_NODE_SHOW_VALIDATE_VTABLE_STMT,
572
  QUERY_NODE_SHOW_SECURITY_POLICIES_STMT,
573
  QUERY_NODE_SHOW_CPU_ALLOCATION_STMT,
574

575
  // logic plan node
576
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
577
  QUERY_NODE_LOGIC_PLAN_JOIN,
578
  QUERY_NODE_LOGIC_PLAN_AGG,
579
  QUERY_NODE_LOGIC_PLAN_PROJECT,
580
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
581
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
582
  QUERY_NODE_LOGIC_PLAN_MERGE,
583
  QUERY_NODE_LOGIC_PLAN_WINDOW,
584
  QUERY_NODE_LOGIC_PLAN_FILL,
585
  QUERY_NODE_LOGIC_PLAN_SORT,
586
  QUERY_NODE_LOGIC_PLAN_PARTITION,
587
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
588
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
589
  QUERY_NODE_LOGIC_SUBPLAN,
590
  QUERY_NODE_LOGIC_PLAN,
591
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
592
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
593
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
594
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
595
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
596

597
  // physical plan node
598
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
599
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
600
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
601
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
602
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
603
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
604
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
605
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
606
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
607
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
608
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
609
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
610
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
611
  QUERY_NODE_PHYSICAL_PLAN_SORT,
612
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
613
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
614
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
615
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
616
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_1,
617
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_2,
618
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_3,
619
  QUERY_NODE_PHYSICAL_PLAN_FILL,
620
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_4,
621
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
622
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_5,
623
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_6,
624
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_7,
625
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
626
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_8,
627
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
628
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_9,
629
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
630
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
631
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
632
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
633
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
634
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
635
  QUERY_NODE_PHYSICAL_SUBPLAN,
636
  QUERY_NODE_PHYSICAL_PLAN,
637
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
638
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
639
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_10,
640
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
641
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
642
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
643
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
644
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_11,
645
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_12,
646
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_13,
647
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
648
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_14,
649
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
650
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_15,
651
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_16,
652
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_17,
653
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_18,
654
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_19,
655
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_20,
656
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_21,
657
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_22,
658
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_23,
659
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_24,
660
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
661
  QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW,
662
  QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL,
663
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL,
664
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INSERT,
665
  QUERY_NODE_PHYSICAL_PLAN_ANALYSIS_FUNC,
666
  // xnode
667
  QUERY_NODE_CREATE_XNODE_STMT = 1200,  // Xnode
668
  QUERY_NODE_DROP_XNODE_STMT,
669
  QUERY_NODE_DRAIN_XNODE_STMT,
670
  QUERY_NODE_XNODE_TASK_OPTIONS,              // XNode task options
671
  QUERY_NODE_XNODE_TASK_SOURCE_OPT,           // XNode task source
672
  QUERY_NODE_XNODE_TASK_SINK_OPT,             // XNode task sink
673
  QUERY_NODE_CREATE_XNODE_TASK_STMT,          // XNode task
674
  QUERY_NODE_START_XNODE_TASK_STMT,           // XNode task
675
  QUERY_NODE_STOP_XNODE_TASK_STMT,            // XNode task
676
  QUERY_NODE_UPDATE_XNODE_TASK_STMT,          // XNode task
677
  QUERY_NODE_DROP_XNODE_TASK_STMT,            // XNode task
678
  QUERY_NODE_CREATE_XNODE_JOB_STMT,           // XNode job
679
  QUERY_NODE_ALTER_XNODE_JOB_STMT,            // XNode job
680
  QUERY_NODE_REBALANCE_XNODE_JOB_STMT,        // XNode job
681
  QUERY_NODE_REBALANCE_XNODE_JOB_WHERE_STMT,  // XNode job
682
  QUERY_NODE_DROP_XNODE_JOB_STMT,             // XNode job
683
  QUERY_NODE_CREATE_XNODE_AGENT_STMT,         // XNode agent
684
  QUERY_NODE_DROP_XNODE_AGENT_STMT,           // XNode agent
685
  QUERY_NODE_ALTER_XNODE_AGENT_STMT,          // XNode agent
686
  QUERY_NODE_ALTER_XNODE_STMT,                // Alter xnode
687
} ENodeType;
688

689
typedef struct {
690
  int32_t     vgId;
691
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
692
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
693
  const char* dbFName;
694
  const char* tbName;
695
} SBuildTableInput;
696

697
typedef struct {
698
  char    db[TSDB_DB_FNAME_LEN];
699
  int64_t dbId;
700
  int32_t vgVersion;
701
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
702
  int64_t stateTs;
703
} SBuildUseDBInput;
704

705
typedef struct SField {
706
  char    name[TSDB_COL_NAME_LEN];
707
  uint8_t type;
708
  int8_t  flags;
709
  int32_t bytes;
710
} SField;
711

712
typedef struct SFieldWithOptions {
713
  char     name[TSDB_COL_NAME_LEN];
714
  uint8_t  type;
715
  int8_t   flags;
716
  int32_t  bytes;
717
  uint32_t compress;
718
  STypeMod typeMod;
719
} SFieldWithOptions;
720

721
typedef struct SRetention {
722
  int64_t freq;
723
  int64_t keep;
724
  int8_t  freqUnit;
725
  int8_t  keepUnit;
726
} SRetention;
727

728
#define RETENTION_VALID(l, r) ((((l) == 0 && (r)->freq >= 0) || ((r)->freq > 0)) && ((r)->keep > 0))
729

730
#pragma pack(push, 1)
731
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
732
typedef struct SEp {
733
  char     fqdn[TSDB_FQDN_LEN];
734
  uint16_t port;
735
} SEp;
736

737
typedef struct {
738
  int32_t contLen;
739
  int32_t vgId;
740
} SMsgHead;
741

742
// Submit message for one table
743
typedef struct SSubmitBlk {
744
  int64_t uid;        // table unique id
745
  int64_t suid;       // stable id
746
  int32_t sversion;   // data schema version
747
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
748
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
749
  int32_t numOfRows;  // total number of rows in current submit block
750
  char    data[];
751
} SSubmitBlk;
752

753
// Submit message for this TSDB
754
typedef struct {
755
  SMsgHead header;
756
  int64_t  version;
757
  int32_t  length;
758
  int32_t  numOfBlocks;
759
  char     blocks[];
760
} SSubmitReq;
761

762
typedef struct {
763
  int32_t totalLen;
764
  int32_t len;
765
  STSRow* row;
766
} SSubmitBlkIter;
767

768
typedef struct {
769
  int32_t totalLen;
770
  int32_t len;
771
  // head of SSubmitBlk
772
  int64_t uid;        // table unique id
773
  int64_t suid;       // stable id
774
  int32_t sversion;   // data schema version
775
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
776
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
777
  int32_t numOfRows;  // total number of rows in current submit block
778
  // head of SSubmitBlk
779
  int32_t     numOfBlocks;
780
  const void* pMsg;
781
} SSubmitMsgIter;
782

783
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
784
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
785
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
786
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
787
// for debug
788
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
789

790
typedef struct {
791
  bool     hasRef;
792
  col_id_t id;
793
  char     refDbName[TSDB_DB_NAME_LEN];
794
  char     refTableName[TSDB_TABLE_NAME_LEN];
795
  char     refColName[TSDB_COL_NAME_LEN];
796
  char     colName[TSDB_COL_NAME_LEN];     // for tmq get json
797
} SColRef;
798

799
typedef struct {
800
  int32_t  nCols;
801
  int32_t  version;
802
  SColRef* pColRef;
803
  int32_t  nTagRefs;
804
  SColRef* pTagRef;
805
} SColRefWrapper;
806

807
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
808
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
809
typedef struct {
810
  int32_t vgId;
811
  SColRef colRef;
812
} SColRefEx;
813

814
typedef struct {
815
  int16_t colId;
816
  char    refDbName[TSDB_DB_NAME_LEN];
817
  char    refTableName[TSDB_TABLE_NAME_LEN];
818
  char    refColName[TSDB_COL_NAME_LEN];
819
} SRefColInfo;
820

821
typedef struct SVCTableRefCols {
822
  uint64_t     uid;
823
  int32_t      numOfSrcTbls;
824
  int32_t      numOfColRefs;
825
  SRefColInfo* refCols;
826
} SVCTableRefCols;
827

828
typedef struct SVCTableMergeInfo {
829
  uint64_t uid;
830
  int32_t  numOfSrcTbls;
831
} SVCTableMergeInfo;
832

833
typedef struct {
834
  int32_t    nCols;
835
  SColRefEx* pColRefEx;
836
} SColRefExWrapper;
837

838
struct SSchema {
839
  int8_t   type;
840
  int8_t   flags;
841
  col_id_t colId;
842
  int32_t  bytes;
843
  char     name[TSDB_COL_NAME_LEN];
844
};
845
struct SSchemaExt {
846
  col_id_t colId;
847
  uint32_t compress;
848
  STypeMod typeMod;
849
};
850

851
struct SSchemaRsma {
852
  int64_t    interval[2];
853
  int32_t    nFuncs;
854
  int8_t     tbType;
855
  tb_uid_t   tbUid;
856
  func_id_t* funcIds;
857
  char       tbName[TSDB_TABLE_NAME_LEN];
858
};
859

860
struct SSchema2 {
861
  int8_t   type;
862
  int8_t   flags;
863
  col_id_t colId;
864
  int32_t  bytes;
865
  char     name[TSDB_COL_NAME_LEN];
866
  uint32_t compress;
867
};
868

869
typedef struct {
870
  char        tbName[TSDB_TABLE_NAME_LEN];
871
  char        stbName[TSDB_TABLE_NAME_LEN];
872
  char        dbFName[TSDB_DB_FNAME_LEN];
873
  int64_t     dbId;
874
  int32_t     numOfTags;
875
  int32_t     numOfColumns;
876
  int8_t      precision;
877
  int8_t      tableType;
878
  int32_t     sversion;
879
  int32_t     tversion;
880
  int32_t     rversion;
881
  uint64_t    suid;
882
  uint64_t    tuid;
883
  int32_t     vgId;
884
  union {
885
    uint8_t flag;
886
    struct {
887
      uint8_t sysInfo : 1;
888
      uint8_t isAudit : 1;
889
      uint8_t privCat : 3;  // ESysTblPrivCat
890
      uint8_t secLvl : 3;
891
    };
892
  };
893
  int64_t     ownerId;
894
  SSchema*    pSchemas;
895
  SSchemaExt* pSchemaExt;
896
  int8_t      virtualStb;
897
  int32_t     numOfColRefs;
898
  SColRef*    pColRefs;
899
  int32_t     numOfTagRefs;
900
  SColRef*    pTagRefs;
901
  int8_t      secureDelete;
902
} STableMetaRsp;
903

904
typedef struct {
905
  int32_t        code;
906
  int64_t        uid;
907
  char*          tblFName;
908
  int32_t        numOfRows;
909
  int32_t        affectedRows;
910
  int64_t        sver;
911
  STableMetaRsp* pMeta;
912
} SSubmitBlkRsp;
913

914
typedef struct {
915
  int32_t numOfRows;
916
  int32_t affectedRows;
917
  int32_t nBlocks;
918
  union {
919
    SArray*        pArray;
920
    SSubmitBlkRsp* pBlocks;
921
  };
922
} SSubmitRsp;
923

924
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
925
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
926
// void    tFreeSSubmitBlkRsp(void* param);
927
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
928

929
#define COL_SMA_ON       ((int8_t)0x1)
930
#define COL_IDX_ON       ((int8_t)0x2)
931
#define COL_IS_KEY       ((int8_t)0x4)
932
#define COL_SET_NULL     ((int8_t)0x10)
933
#define COL_SET_VAL      ((int8_t)0x20)
934
#define COL_IS_SYSINFO   ((int8_t)0x40)
935
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
936
#define COL_REF_BY_STM   ((int8_t)0x08)
937

938
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
939
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
940

941
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
942
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
943
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
944

945
#define SSCHMEA_SET_IDX_ON(s) \
946
  do {                        \
947
    (s)->flags |= COL_IDX_ON; \
948
  } while (0)
949

950
#define SSCHMEA_SET_IDX_OFF(s)   \
951
  do {                           \
952
    (s)->flags &= (~COL_IDX_ON); \
953
  } while (0)
954

955
#define SSCHEMA_SET_TYPE_MOD(s)     \
956
  do {                              \
957
    (s)->flags |= COL_HAS_TYPE_MOD; \
958
  } while (0)
959

960
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
961

962
#define SSCHMEA_TYPE(s)  ((s)->type)
963
#define SSCHMEA_FLAGS(s) ((s)->flags)
964
#define SSCHMEA_COLID(s) ((s)->colId)
965
#define SSCHMEA_BYTES(s) ((s)->bytes)
966
#define SSCHMEA_NAME(s)  ((s)->name)
967

968
typedef struct {
969
  bool    tsEnableMonitor;
970
  int32_t tsMonitorInterval;
971
  int32_t tsSlowLogThreshold;
972
  int32_t tsSlowLogMaxLen;
973
  int32_t tsSlowLogScope;
974
  int32_t tsSlowLogThresholdTest;  // Obsolete
975
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
976
} SMonitorParas;
977

978
typedef struct {
979
  STypeMod typeMod;
980
} SExtSchema;
981

982
bool hasExtSchema(const SExtSchema* pExtSchema);
983

984
typedef struct {
985
  int32_t      nCols;
986
  int32_t      version;
987
  SSchema*     pSchema;
988
  SSchemaRsma* pRsma;
989
} SSchemaWrapper;
990

991
typedef struct {
992
  col_id_t id;
993
  uint32_t alg;
994
} SColCmpr;
995

996
typedef struct {
997
  int32_t   nCols;
998
  int32_t   version;
999
  SColCmpr* pColCmpr;
1000
} SColCmprWrapper;
1001

1002
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
1003
  if (pRef->pColRef) {
607,511✔
1004
    return TSDB_CODE_INVALID_PARA;
×
1005
  }
1006
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
607,511✔
1007
  if (pRef->pColRef == NULL) {
607,511✔
1008
    return terrno;
×
1009
  }
1010
  pRef->nCols = nCols;
607,511✔
1011
  for (int32_t i = 0; i < nCols; i++) {
161,952,054✔
1012
    pRef->pColRef[i].hasRef = false;
161,344,543✔
1013
    pRef->pColRef[i].id = (col_id_t)(i + 1);
161,344,543✔
1014
  }
1015
  return 0;
607,511✔
1016
}
1017

1018
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByTags(SColRefWrapper* pRef, int32_t nTags, col_id_t startColId) {
1019
  if (pRef->pTagRef) {
×
1020
    return TSDB_CODE_INVALID_PARA;
×
1021
  }
1022
  pRef->pTagRef = (SColRef*)taosMemoryCalloc(nTags, sizeof(SColRef));
×
1023
  if (pRef->pTagRef == NULL) {
×
1024
    return terrno;
×
1025
  }
1026
  pRef->nTagRefs = nTags;
×
1027
  for (int32_t i = 0; i < nTags; i++) {
×
1028
    pRef->pTagRef[i].hasRef = false;
×
1029
    pRef->pTagRef[i].id = (col_id_t)(startColId + i);
×
1030
  }
1031
  return 0;
×
1032
}
1033

1034
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
1035
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1036
    terrno = TSDB_CODE_INVALID_PARA;
1037
    return NULL;
1038
  }
1039

1040
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1041
  if (pDstWrapper == NULL) {
1042
    return NULL;
1043
  }
1044
  pDstWrapper->nCols = pSrcWrapper->nCols;
1045
  pDstWrapper->version = pSrcWrapper->version;
1046

1047
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1048
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1049
  if (pDstWrapper->pColCmpr == NULL) {
1050
    taosMemoryFree(pDstWrapper);
1051
    return NULL;
1052
  }
1053
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1054

1055
  return pDstWrapper;
1056
}
1057

1058
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1059
  if (!(!pCmpr->pColCmpr)) {
7,777,893✔
1060
    return TSDB_CODE_INVALID_PARA;
×
1061
  }
1062
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
7,777,893✔
1063
  if (pCmpr->pColCmpr == NULL) {
7,777,893✔
1064
    return terrno;
×
1065
  }
1066
  pCmpr->nCols = nCols;
7,777,893✔
1067
  return 0;
7,777,893✔
1068
}
1069

1070
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
1071
  pCmpr->nCols = pSchema->nCols;
1072
  if (!(!pCmpr->pColCmpr)) {
1073
    return TSDB_CODE_INVALID_PARA;
1074
  }
1075
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
1076
  if (pCmpr->pColCmpr == NULL) {
1077
    return terrno;
1078
  }
1079
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1080
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
1081
    SSchema*  pColSchema = &pSchema->pSchema[i];
1082
    pColCmpr->id = pColSchema->colId;
1083
    pColCmpr->alg = 0;
1084
  }
1085
  return 0;
1086
}
1087

1088
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1089
  if (pWrapper == NULL) return;
1090

1091
  taosMemoryFreeClear(pWrapper->pColCmpr);
1092
  taosMemoryFreeClear(pWrapper);
1093
}
1094
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1095
  if (pSchemaWrapper->pSchema == NULL) return NULL;
764,330,312✔
1096

1097
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
764,254,973✔
1098
  if (pSW == NULL) {
764,291,521✔
1099
    return NULL;
×
1100
  }
1101
  pSW->nCols = pSchemaWrapper->nCols;
764,291,521✔
1102
  pSW->version = pSchemaWrapper->version;
764,263,651✔
1103
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
764,109,099✔
1104
  if (pSW->pSchema == NULL) {
764,092,184✔
1105
    taosMemoryFree(pSW);
×
1106
    return NULL;
×
1107
  }
1108

1109
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
764,147,966✔
1110
  return pSW;
764,477,491✔
1111
}
1112

1113
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
215,596,923✔
1114
  if (pSchemaWrapper) {
1,715,199,817✔
1115
    taosMemoryFree(pSchemaWrapper->pSchema);
1,189,991,454✔
1116
    if (pSchemaWrapper->pRsma) {
1,189,905,827✔
1117
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
29,785✔
1118
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
29,785✔
1119
    }
1120
    taosMemoryFree(pSchemaWrapper);
1,189,780,005✔
1121
  }
1122
}
1,672,935,664✔
1123

1124
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1125
  if (pSchemaWrapper) {
1126
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1127
    if (pSchemaWrapper->pRsma) {
1128
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1129
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1130
    }
1131
  }
1132
}
1133

1134
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
7,988,969✔
1135
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,988,969✔
1136
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,989,586✔
1137
  }
1138
}
7,988,969✔
1139

1140
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1141
  int32_t tlen = 0;
3,180,568✔
1142
  tlen += taosEncodeFixedI8(buf, pSchema->type);
3,182,962✔
1143
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
3,180,568✔
1144
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
3,180,568✔
1145
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
3,180,568✔
1146
  tlen += taosEncodeString(buf, pSchema->name);
3,180,568✔
1147
  return tlen;
3,180,568✔
1148
}
1149

1150
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1151
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,416,803✔
1152
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,416,290✔
1153
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,416,290✔
1154
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,416,290✔
1155
  buf = taosDecodeStringTo(buf, pSchema->name);
1,416,290✔
1156
  return (void*)buf;
1,416,290✔
1157
}
1158

1159
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1160
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1161
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1162
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1163
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1164
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1165
  return 0;
2,147,483,647✔
1166
}
1167

1168
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1169
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1170
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1171
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1172
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1173
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1174
  return 0;
2,147,483,647✔
1175
}
1176

1177
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1178
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1179
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1180
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1181
  return 0;
2,147,483,647✔
1182
}
1183

1184
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1185
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1186
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1187
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1188
  return 0;
2,147,483,647✔
1189
}
1190

1191
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1192
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
973,464,196✔
1193
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
973,464,196✔
1194
  if (pColRef->hasRef) {
486,732,098✔
1195
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
645,742,564✔
1196
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
645,742,564✔
1197
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
645,742,564✔
1198
  }
1199
  return 0;
486,732,098✔
1200
}
1201

1202
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1203
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
487,273,348✔
1204
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
487,273,348✔
1205
  if (pColRef->hasRef) {
243,636,674✔
1206
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
161,660,787✔
1207
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
161,660,787✔
1208
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
161,660,787✔
1209
  }
1210

1211
  return 0;
243,636,674✔
1212
}
1213

1214
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1215
  int32_t tlen = 0;
537,442✔
1216
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
537,442✔
1217
  tlen += taosEncodeVariantI32(buf, pSW->version);
537,442✔
1218
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,718,010✔
1219
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
6,361,136✔
1220
  }
1221
  return tlen;
537,442✔
1222
}
1223

1224
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1225
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
230,248✔
1226
  buf = taosDecodeVariantI32(buf, &pSW->version);
230,248✔
1227
  if (pSW->nCols > 0) {
230,248✔
1228
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
230,248✔
1229
    if (pSW->pSchema == NULL) {
230,248✔
1230
      return NULL;
×
1231
    }
1232

1233
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,646,538✔
1234
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,832,580✔
1235
    }
1236
  } else {
1237
    pSW->pSchema = NULL;
×
1238
  }
1239
  return (void*)buf;
230,248✔
1240
}
1241

1242
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1243
  if (pSW == NULL) {
371,097,342✔
1244
    return TSDB_CODE_INVALID_PARA;
×
1245
  }
1246
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
742,085,749✔
1247
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
741,884,276✔
1248
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1249
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1250
  }
1251
  return 0;
371,332,126✔
1252
}
1253

1254
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1255
  if (pSW == NULL) {
163,185,520✔
1256
    return TSDB_CODE_INVALID_PARA;
×
1257
  }
1258
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
326,341,006✔
1259
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
326,319,092✔
1260

1261
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
163,163,606✔
1262
  if (pSW->pSchema == NULL) {
163,119,184✔
1263
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1264
  }
1265
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,667,121,438✔
1266
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1267
  }
1268

1269
  return 0;
163,207,204✔
1270
}
1271

1272
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1273
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1274
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1275

1276
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1277
  if (pSW->pSchema == NULL) {
2,147,483,647✔
1278
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1279
  }
1280
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1281
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1282
  }
1283

1284
  return 0;
2,147,483,647✔
1285
}
1286

1287
typedef struct {
1288
  char     name[TSDB_TABLE_FNAME_LEN];
1289
  int8_t   igExists;
1290
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1291
  int8_t   reserved[6];
1292
  tb_uid_t suid;
1293
  int64_t  delay1;
1294
  int64_t  delay2;
1295
  int64_t  watermark1;
1296
  int64_t  watermark2;
1297
  int32_t  ttl;
1298
  int32_t  colVer;
1299
  int32_t  tagVer;
1300
  int32_t  numOfColumns;
1301
  int32_t  numOfTags;
1302
  int32_t  numOfFuncs;
1303
  int32_t  commentLen;
1304
  int32_t  ast1Len;
1305
  int32_t  ast2Len;
1306
  SArray*  pColumns;  // array of SFieldWithOptions
1307
  SArray*  pTags;     // array of SField
1308
  SArray*  pFuncs;
1309
  char*    pComment;
1310
  char*    pAst1;
1311
  char*    pAst2;
1312
  int64_t  deleteMark1;
1313
  int64_t  deleteMark2;
1314
  int32_t  sqlLen;
1315
  char*    sql;
1316
  int64_t  keep;
1317
  int8_t   virtualStb;
1318
  int8_t   secureDelete;
1319
  int8_t   securityLevel;
1320
} SMCreateStbReq;
1321

1322
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1323
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1324
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1325

1326
typedef struct {
1327
  STableMetaRsp* pMeta;
1328
} SMCreateStbRsp;
1329

1330
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1331
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1332
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1333

1334
typedef struct {
1335
  char     name[TSDB_TABLE_FNAME_LEN];
1336
  int8_t   igNotExists;
1337
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1338
  int8_t   reserved[6];
1339
  tb_uid_t suid;
1340
  int32_t  sqlLen;
1341
  char*    sql;
1342
} SMDropStbReq;
1343

1344
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1345
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1346
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1347

1348
typedef struct {
1349
  char    name[TSDB_TABLE_FNAME_LEN];
1350
  int8_t  alterType;
1351
  int32_t numOfFields;
1352
  SArray* pFields;
1353
  int32_t ttl;
1354
  int32_t commentLen;
1355
  char*   comment;
1356
  int32_t sqlLen;
1357
  char*   sql;
1358
  int64_t keep;
1359
  SArray* pTypeMods;
1360
  int8_t  secureDelete;
1361
  int8_t  securityLevel;
1362
} SMAlterStbReq;
1363

1364
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1365
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1366
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1367

1368
typedef struct SEpSet {
1369
  int8_t inUse;
1370
  int8_t numOfEps;
1371
  SEp    eps[TSDB_MAX_REPLICA];
1372
} SEpSet;
1373

1374
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1375
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1376
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1377
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1378

1379
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1380
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1381

1382
typedef struct {
1383
  int8_t  connType;
1384
  int32_t pid;
1385
  int32_t totpCode;
1386
  char    app[TSDB_APP_NAME_LEN];
1387
  char    db[TSDB_DB_NAME_LEN];
1388
  char    user[TSDB_USER_LEN];
1389
  char    passwd[TSDB_PASSWORD_LEN];
1390
  char    token[TSDB_TOKEN_LEN];
1391
  int64_t startTime;
1392
  int64_t connectTime;
1393
  char    sVer[TSDB_VERSION_LEN];
1394
  char    signature[20]; // SHA1 produces a 20-byte signature
1395
} SConnectReq;
1396

1397
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1398
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1399
void    tSignConnectReq(SConnectReq* pReq);
1400
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1401

1402
typedef struct {
1403
  int64_t       clusterId;
1404
  int32_t       acctId;
1405
  uint32_t      connId;
1406
  int32_t       dnodeNum;
1407
  int8_t        superUser;
1408
  int8_t        sysInfo;
1409
  int8_t        connType;
1410
  int8_t        enableAuditDelete;
1411
  SEpSet        epSet;
1412
  int32_t       svrTimestamp;
1413
  int32_t       passVer;
1414
  int32_t       authVer;
1415
  char          sVer[TSDB_VERSION_LEN];
1416
  char          sDetailVer[128];
1417
  int64_t       whiteListVer;
1418
  int64_t       timeWhiteListVer;
1419
  int64_t       userId;
1420
  SMonitorParas monitorParas;
1421
  char          user[TSDB_USER_LEN];
1422
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1423
  int8_t        enableAuditSelect;
1424
  int8_t        enableAuditInsert;
1425
  int8_t        auditLevel;
1426
  union {
1427
    uint32_t flags;
1428
    struct {
1429
      uint32_t minSecLevel : 3;  // per-user
1430
      uint32_t maxSecLevel : 3;  // per-user
1431
      uint32_t sodInitial  : 1;  // cluster-wide: 1 = SoD still in initial phase
1432
      uint32_t macActive   : 1;  // cluster-wide: 1 = MAC mandatory mode activated
1433
      uint32_t reserved    : 24;
1434
    };
1435
  };
1436
} SConnectRsp;
1437

1438
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1439
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1440

1441
typedef struct {
1442
  char    user[TSDB_USER_LEN];
1443
  char    pass[TSDB_PASSWORD_LEN];
1444
  int32_t maxUsers;
1445
  int32_t maxDbs;
1446
  int32_t maxTimeSeries;
1447
  int32_t maxStreams;
1448
  int32_t accessState;  // Configured only by command
1449
  int64_t maxStorage;
1450
} SCreateAcctReq, SAlterAcctReq;
1451

1452
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1453
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1454

1455
typedef struct {
1456
  char    user[TSDB_USER_LEN];
1457
  int8_t  ignoreNotExists;
1458
  int32_t sqlLen;
1459
  char*   sql;
1460
} SDropUserReq, SDropAcctReq;
1461

1462
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1463
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1464
void    tFreeSDropUserReq(SDropUserReq* pReq);
1465

1466
typedef struct {
1467
  char name[TSDB_ROLE_LEN];
1468
  union {
1469
    uint8_t flag;
1470
    struct {
1471
      uint8_t ignoreExists : 1;
1472
      uint8_t reserve : 7;
1473
    };
1474
  };
1475
  int32_t sqlLen;
1476
  char*   sql;
1477
} SCreateRoleReq;
1478

1479
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1480
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1481
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1482

1483
typedef struct {
1484
  char name[TSDB_ROLE_LEN];
1485
  union {
1486
    uint8_t flag;
1487
    struct {
1488
      uint8_t ignoreNotExists : 1;
1489
      uint8_t reserve : 7;
1490
    };
1491
  };
1492
  int32_t sqlLen;
1493
  char*   sql;
1494
} SDropRoleReq;
1495

1496
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1497
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1498
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1499

1500
typedef struct {
1501
  SPrivSet privSet;
1502
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1503
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1504
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1505
  // delete can only specify conditions by cond and cannot specify columns
1506
  char*    cond;     // for table privileges
1507
  int32_t  condLen;  // for table privileges
1508
} SPrivSetReqArgs;
1509

1510
typedef struct {
1511
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1512
  uint8_t objType;    // none, db, table, view, rsma, topic, etc.
1513
  union {
1514
    uint32_t flag;
1515
    struct {
1516
      uint32_t lock : 1;     // lock or unlock role
1517
      uint32_t add : 1;      // add or remove
1518
      uint32_t sysPriv : 1;  // system or object privileges
1519
      uint32_t objLevel : 2;
1520
      uint32_t ignoreNotExists : 1;
1521
      uint32_t reserve : 26;
1522
    };
1523
  };
1524
  union {
1525
    SPrivSetReqArgs privileges;
1526
    char            roleName[TSDB_ROLE_LEN];
1527
  };
1528
  char    principal[TSDB_ROLE_LEN];      // role or user name
1529
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db
1530
  char    tblName[TSDB_TABLE_NAME_LEN];  // none, table, view, rsma, topic, etc.
1531
  int32_t sqlLen;
1532
  char*   sql;
1533
} SAlterRoleReq;
1534

1535
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1536
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1537
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1538

1539
typedef struct {
1540
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1541
  int32_t sqlLen;
1542
  char*   sql;
1543
} SDropEncryptAlgrReq;
1544

1545
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1546
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1547
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1548

1549
typedef struct SIpV4Range {
1550
  uint32_t ip;
1551
  uint32_t mask;
1552
} SIpV4Range;
1553

1554
typedef struct SIpv6Range {
1555
  uint64_t addr[2];
1556
  uint32_t mask;
1557
} SIpV6Range;
1558

1559
typedef struct {
1560
  int8_t type;   // 0: IPv4, 1: IPv6
1561
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1562
  union {
1563
    SIpV4Range ipV4;
1564
    SIpV6Range ipV6;
1565
  };
1566
} SIpRange;
1567

1568
typedef struct {
1569
  int32_t    num;
1570
  SIpV4Range pIpRange[];
1571
} SIpWhiteList;
1572

1573
typedef struct {
1574
  int32_t  num;
1575
  SIpRange pIpRanges[];
1576
} SIpWhiteListDual;
1577

1578
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1579
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1580
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1581
int32_t           createDefaultIp6Range(SIpRange* pRange);
1582
int32_t           createDefaultIp4Range(SIpRange* pRange);
1583

1584
typedef struct {
1585
  int32_t sessPerUser;
1586
  int32_t sessConnTime;
1587
  int32_t sessConnIdleTime;
1588
  int32_t sessMaxConcurrency;
1589
  int32_t sessMaxCallVnodeNum;
1590
} SUserSessCfg;
1591

1592
void initUserDefautSessCfg(SUserSessCfg* pCfg);
1593
// copyIpRange ensures that unused bytes are always zeroed, so that [pDst] can be used as a key in hash tables
1594
void copyIpRange(SIpRange* pDst, const SIpRange* pSrc);
1595

1596
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1597
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1598
typedef struct {
1599
  int16_t year;
1600
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1601
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1602
  int8_t hour;
1603
  int8_t minute;
1604
  int8_t neg;   // this is a negative entry
1605
  int32_t duration; // duration in minute
1606
} SDateTimeRange;
1607

1608
bool isValidDateTimeRange(SDateTimeRange* pRange);
1609
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1610
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1611

1612
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1613
typedef struct {
1614
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1615
  bool neg;         // this is a negative entry
1616
  int32_t duration; // duration in seconds
1617
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1618
} SDateTimeWhiteListItem;
1619

1620
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1621
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1622

1623
typedef struct {
1624
  int32_t num;
1625
  SDateTimeWhiteListItem ranges[];
1626
} SDateTimeWhiteList;
1627

1628
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1629
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1630

1631

1632
typedef struct {
1633
  int8_t createType;
1634

1635
  int8_t hasSessionPerUser;
1636
  int8_t hasConnectTime;
1637
  int8_t hasConnectIdleTime;
1638
  int8_t hasCallPerSession;
1639
  int8_t hasVnodePerCall;
1640
  int8_t hasFailedLoginAttempts;
1641
  int8_t hasPasswordLifeTime;
1642
  int8_t hasPasswordReuseTime;
1643
  int8_t hasPasswordReuseMax;
1644
  int8_t hasPasswordLockTime;
1645
  int8_t hasPasswordGraceTime;
1646
  int8_t hasInactiveAccountTime;
1647
  int8_t hasAllowTokenNum;
1648
  int8_t hasSecurityLevel;
1649

1650
  int8_t superUser;  // denote if it is a super user or not
1651
  int8_t ignoreExists;
1652

1653
  char   user[TSDB_USER_LEN];
1654
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1655
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1656

1657
  int8_t sysInfo;
1658
  int8_t createDb;
1659
  int8_t isImport;
1660
  int8_t changepass;
1661
  int8_t enable;
1662
  int8_t minSecLevel;
1663
  int8_t maxSecLevel;
1664

1665
  int8_t negIpRanges;
1666
  int8_t negTimeRanges;
1667

1668
  int32_t sessionPerUser;
1669
  int32_t connectTime;
1670
  int32_t connectIdleTime;
1671
  int32_t callPerSession;
1672
  int32_t vnodePerCall;
1673
  int32_t failedLoginAttempts;
1674
  int32_t passwordLifeTime;
1675
  int32_t passwordReuseTime;
1676
  int32_t passwordReuseMax;
1677
  int32_t passwordLockTime;
1678
  int32_t passwordGraceTime;
1679
  int32_t inactiveAccountTime;
1680
  int32_t allowTokenNum;
1681

1682
  int32_t         numIpRanges;
1683
  SIpRange*       pIpDualRanges;
1684
  int32_t         numTimeRanges;
1685
  SDateTimeRange* pTimeRanges;
1686

1687
  int32_t sqlLen;
1688
  char*   sql;
1689
} SCreateUserReq;
1690

1691
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1692
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1693
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1694

1695
typedef struct {
1696
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1697
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1698
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1699
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1700
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1701
  int32_t sqlLen;
1702
  char*   sql;
1703
} SCreateEncryptAlgrReq;
1704

1705
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1706
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1707
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1708

1709
typedef struct {
1710
  int32_t dnodeId;
1711
  int64_t analVer;
1712
} SRetrieveAnalyticsAlgoReq;
1713

1714
typedef struct {
1715
  int64_t   ver;
1716
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1717
} SRetrieveAnalyticAlgoRsp;
1718

1719
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1720
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1721
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1722
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1723
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1724

1725
typedef struct {
1726
  int8_t alterType;
1727

1728
  int8_t isView;
1729

1730
  int8_t hasPassword;
1731
  int8_t hasTotpseed;
1732
  int8_t hasEnable;
1733
  int8_t hasSysinfo;
1734
  int8_t hasCreatedb;
1735
  int8_t hasChangepass;
1736
  int8_t hasSessionPerUser;
1737
  int8_t hasConnectTime;
1738
  int8_t hasConnectIdleTime;
1739
  int8_t hasCallPerSession;
1740
  int8_t hasVnodePerCall;
1741
  int8_t hasFailedLoginAttempts;
1742
  int8_t hasPasswordLifeTime;
1743
  int8_t hasPasswordReuseTime;
1744
  int8_t hasPasswordReuseMax;
1745
  int8_t hasPasswordLockTime;
1746
  int8_t hasPasswordGraceTime;
1747
  int8_t hasInactiveAccountTime;
1748
  int8_t hasAllowTokenNum;
1749
  int8_t hasSecurityLevel;
1750

1751
  int8_t enable;
1752
  int8_t sysinfo;
1753
  int8_t createdb;
1754
  int8_t changepass;
1755
  int8_t minSecLevel;
1756
  int8_t maxSecLevel;
1757

1758
  char   user[TSDB_USER_LEN];
1759
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1760
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1761
  int32_t sessionPerUser;
1762
  int32_t connectTime;
1763
  int32_t connectIdleTime;
1764
  int32_t callPerSession;
1765
  int32_t vnodePerCall;
1766
  int32_t failedLoginAttempts;
1767
  int32_t passwordLifeTime;
1768
  int32_t passwordReuseTime;
1769
  int32_t passwordReuseMax;
1770
  int32_t passwordLockTime;
1771
  int32_t passwordGraceTime;
1772
  int32_t inactiveAccountTime;
1773
  int32_t allowTokenNum;
1774

1775
  int32_t         numIpRanges;
1776
  int32_t         numTimeRanges;
1777
  int32_t         numDropIpRanges;
1778
  int32_t         numDropTimeRanges;
1779
  SIpRange*       pIpRanges;
1780
  SDateTimeRange* pTimeRanges;
1781
  SIpRange*       pDropIpRanges;
1782
  SDateTimeRange* pDropTimeRanges;
1783
  SPrivSet        privileges;
1784

1785
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1786
  char        tabName[TSDB_TABLE_NAME_LEN];
1787
  char*       tagCond;
1788
  int32_t     tagCondLen;
1789
  int32_t     sqlLen;
1790
  char*       sql;
1791
} SAlterUserReq;
1792

1793
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1794
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1795
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1796

1797
typedef struct {
1798
  char    name[TSDB_TOKEN_NAME_LEN];
1799
  char    user[TSDB_USER_LEN];
1800
  int8_t  enable;
1801
  int8_t  ignoreExists;
1802
  int32_t ttl;
1803
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1804
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1805

1806
  int32_t sqlLen;
1807
  char*   sql;
1808
} SCreateTokenReq;
1809

1810
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1811
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1812
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1813

1814
typedef struct {
1815
  char name[TSDB_TOKEN_NAME_LEN];
1816
  char user[TSDB_USER_LEN];
1817
  char token[TSDB_TOKEN_LEN];
1818
} SCreateTokenRsp;
1819

1820
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1821
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1822
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1823

1824
typedef struct {
1825
  char    name[TSDB_TOKEN_NAME_LEN];
1826

1827
  int8_t hasEnable;
1828
  int8_t hasTtl;
1829
  int8_t hasProvider;
1830
  int8_t hasExtraInfo;
1831

1832
  int8_t  enable;
1833
  int32_t ttl;
1834
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1835
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1836

1837
  int32_t     sqlLen;
1838
  char*       sql;
1839
} SAlterTokenReq;
1840

1841
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1842
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1843
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1844

1845
typedef struct {
1846
  char    name[TSDB_TOKEN_NAME_LEN];
1847
  int8_t  ignoreNotExists;
1848
  int32_t sqlLen;
1849
  char*   sql;
1850
} SDropTokenReq;
1851

1852
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1853
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1854
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1855

1856
typedef struct {
1857
  char    user[TSDB_USER_LEN];
1858
  int32_t sqlLen;
1859
  char*   sql;
1860
} SCreateTotpSecretReq;
1861

1862
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1863
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1864
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1865

1866
typedef struct {
1867
  char user[TSDB_USER_LEN];
1868
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1869
} SCreateTotpSecretRsp;
1870

1871
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1872
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1873

1874
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1875
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1876
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1877
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1878

1879
typedef struct {
1880
  char user[TSDB_USER_LEN];
1881
} SGetUserAuthReq;
1882

1883
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1884
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1885

1886
typedef struct {
1887
  int8_t  enabled;
1888
  int32_t expireTime;
1889
} STokenStatus;
1890

1891
typedef struct {
1892
  char    user[TSDB_USER_LEN];
1893
  int64_t userId;
1894
  int32_t version;
1895
  int32_t passVer;
1896
  int8_t  superAuth;
1897
  int8_t  sysInfo;
1898
  int8_t  enable;
1899
  int8_t  dropped;
1900
  union {
1901
    uint8_t flags;
1902
    struct {
1903
      uint8_t minSecLevel    : 3;
1904
      uint8_t withInsertCond : 1;
1905
      uint8_t maxSecLevel    : 3;
1906
      uint8_t reserved       : 1;
1907
    };
1908
  };
1909
  SPrivSet  sysPrivs;
1910
  SHashObj* objPrivs;
1911
  SHashObj* selectTbs;
1912
  SHashObj* insertTbs;
1913
  SHashObj* deleteTbs;
1914
  SHashObj* ownedDbs;
1915
  int64_t   whiteListVer;
1916

1917
  SUserSessCfg sessCfg;
1918
  int64_t      timeWhiteListVer;
1919
  SHashObj*    tokens;
1920
} SGetUserAuthRsp;
1921

1922
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1923
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1924
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1925

1926
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1927
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1928
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1929
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1930

1931
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1932
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1933
typedef struct {
1934
  int64_t ver;
1935
  char    user[TSDB_USER_LEN];
1936
  int32_t numOfRange;
1937
  union {
1938
    SIpV4Range* pIpRanges;
1939
    SIpRange*   pIpDualRanges;
1940
  };
1941
} SUpdateUserIpWhite;
1942

1943
typedef struct {
1944
  int64_t             ver;
1945
  int                 numOfUser;
1946
  SUpdateUserIpWhite* pUserIpWhite;
1947
} SUpdateIpWhite;
1948

1949
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1950
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1951
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1952
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1953

1954
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1955
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1956
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1957

1958

1959
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1960
// corresponding response struct is different.
1961
typedef struct {
1962
  int64_t ver;
1963
} SRetrieveWhiteListReq;
1964

1965
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1966
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1967

1968

1969
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1970
// corresponding response struct is different.
1971
typedef struct {
1972
  char user[TSDB_USER_LEN];
1973
} SGetUserWhiteListReq;
1974

1975
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1976
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1977

1978
typedef struct {
1979
  char    user[TSDB_USER_LEN];
1980
  int32_t numWhiteLists;
1981
  union {
1982
    SIpV4Range* pWhiteLists;
1983
    SIpRange*   pWhiteListsDual;
1984
  };
1985
} SGetUserIpWhiteListRsp;
1986

1987
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1988
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1989
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1990
void    tIpRangeSetDefaultMask(SIpRange* range);
1991

1992
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1993
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1994
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1995

1996
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1997
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1998
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1999

2000
typedef struct {
2001
  int64_t ver;
2002
  char    user[TSDB_USER_LEN];
2003
  int32_t numWhiteLists;
2004
  SDateTimeWhiteListItem* pWhiteLists;
2005
} SUserDateTimeWhiteList;
2006

2007

2008
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
2009
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
2010
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
2011
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
2012

2013
typedef struct {
2014
  int64_t             ver;
2015
  int                 numOfUser;
2016
  SUserDateTimeWhiteList *pUsers;
2017
} SRetrieveDateTimeWhiteListRsp;
2018

2019
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
2020
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
2021
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
2022
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
2023

2024
/*
2025
 * for client side struct, only column id, type, bytes are necessary
2026
 * But for data in vnode side, we need all the following information.
2027
 */
2028
typedef struct {
2029
  union {
2030
    col_id_t colId;
2031
    int16_t  slotId;
2032
  };
2033

2034
  uint8_t precision;
2035
  uint8_t scale;
2036
  int32_t bytes;
2037
  int8_t  type;
2038
  uint8_t pk;
2039
  bool    noData;
2040
} SColumnInfo;
2041

2042
typedef struct STimeWindow {
2043
  TSKEY skey;
2044
  TSKEY ekey;
2045
} STimeWindow;
2046

2047
typedef struct SQueryHint {
2048
  bool batchScan;
2049
} SQueryHint;
2050

2051
typedef struct {
2052
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
2053
  int32_t tsLen;          // total length of ts comp block
2054
  int32_t tsNumOfBlocks;  // ts comp block numbers
2055
  int32_t tsOrder;        // ts comp block order
2056
} STsBufInfo;
2057

2058
typedef struct {
2059
  void*       timezone;
2060
  char        intervalUnit;
2061
  char        slidingUnit;
2062
  char        offsetUnit;
2063
  int8_t      precision;
2064
  int64_t     interval;
2065
  int64_t     sliding;
2066
  int64_t     offset;
2067
  STimeWindow timeRange;
2068
} SInterval;
2069

2070
typedef struct STbVerInfo {
2071
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2072
  int32_t sversion;
2073
  int32_t tversion;
2074
  int32_t rversion;  // virtual table's column ref's version
2075
} STbVerInfo;
2076

2077
typedef struct {
2078
  int32_t code;
2079
  int64_t affectedRows;
2080
  SArray* tbVerInfo;  // STbVerInfo
2081
} SQueryTableRsp;
2082

2083
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2084

2085
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2086

2087
typedef struct {
2088
  SMsgHead header;
2089
  char     dbFName[TSDB_DB_FNAME_LEN];
2090
  char     tbName[TSDB_TABLE_NAME_LEN];
2091
} STableCfgReq;
2092

2093
typedef struct {
2094
  char        tbName[TSDB_TABLE_NAME_LEN];
2095
  char        stbName[TSDB_TABLE_NAME_LEN];
2096
  char        dbFName[TSDB_DB_FNAME_LEN];
2097
  int32_t     numOfTags;
2098
  int32_t     numOfColumns;
2099
  int8_t      tableType;
2100
  int64_t     delay1;
2101
  int64_t     delay2;
2102
  int64_t     watermark1;
2103
  int64_t     watermark2;
2104
  int32_t     ttl;
2105
  int32_t     keep;
2106
  int64_t     ownerId;
2107
  SArray*     pFuncs;
2108
  int32_t     commentLen;
2109
  char*       pComment;
2110
  SSchema*    pSchemas;
2111
  int32_t     tagsLen;
2112
  char*       pTags;
2113
  SSchemaExt* pSchemaExt;
2114
  union {
2115
    uint8_t flag;
2116
    struct {
2117
      uint8_t virtualStb : 1;  // no compatibility problem for little-endian arch
2118
      uint8_t isAudit : 1;
2119
      uint8_t securityLevel : 3;
2120
      uint8_t reserve : 3;
2121
    };
2122
  };
2123
  SColRef* pColRefs;
2124
  int32_t  numOfTagRefs;
2125
  SColRef* pTagRefs;
2126
  int8_t   secureDelete;
2127
} STableCfg;
2128

2129
typedef STableCfg STableCfgRsp;
2130

2131
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2132
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2133

2134
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2135
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2136
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2137

2138
typedef struct {
2139
  SMsgHead header;
2140
  tb_uid_t suid;
2141
} SVSubTablesReq;
2142

2143
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2144
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2145

2146
typedef struct {
2147
  int32_t vgId;
2148
  SArray* pTables;  // SArray<SVCTableRefCols*>
2149
} SVSubTablesRsp;
2150

2151
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2152
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2153
void    tDestroySVSubTablesRsp(void* rsp);
2154

2155
typedef struct {
2156
  SMsgHead header;
2157
  tb_uid_t suid;
2158
} SVStbRefDbsReq;
2159

2160
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2161
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2162

2163
typedef struct {
2164
  int32_t vgId;
2165
  SArray* pDbs;  // SArray<char* (db name)>
2166
} SVStbRefDbsRsp;
2167

2168
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2169
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2170
void    tDestroySVStbRefDbsRsp(void* rsp);
2171

2172
typedef struct {
2173
  char    db[TSDB_DB_FNAME_LEN];
2174
  int32_t numOfVgroups;
2175
  int32_t numOfStables;  // single_stable
2176
  int32_t buffer;        // MB
2177
  int32_t pageSize;
2178
  int32_t pages;
2179
  int32_t cacheLastSize;
2180
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2181
  int32_t daysPerFile;
2182
  int32_t daysToKeep0;
2183
  int32_t daysToKeep1;
2184
  int32_t daysToKeep2;
2185
  int32_t keepTimeOffset;
2186
  int32_t minRows;
2187
  int32_t maxRows;
2188
  int32_t walFsyncPeriod;
2189
  int8_t  walLevel;
2190
  int8_t  precision;  // time resolution
2191
  int8_t  compression;
2192
  int8_t  replications;
2193
  int8_t  strict;
2194
  int8_t  cacheLast;
2195
  int8_t  schemaless;
2196
  int8_t  ignoreExist;
2197
  int32_t numOfRetensions;
2198
  SArray* pRetensions;  // SRetention
2199
  int32_t walRetentionPeriod;
2200
  int64_t walRetentionSize;
2201
  int32_t walRollPeriod;
2202
  int64_t walSegmentSize;
2203
  int32_t sstTrigger;
2204
  int16_t hashPrefix;
2205
  int16_t hashSuffix;
2206
  int32_t ssChunkSize;
2207
  int32_t ssKeepLocal;
2208
  int8_t  ssCompact;
2209
  int32_t tsdbPageSize;
2210
  int32_t sqlLen;
2211
  char*   sql;
2212
  int8_t  withArbitrator;
2213
  int8_t  encryptAlgorithm;
2214
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2215
  // 1. add auto-compact parameters
2216
  int32_t compactInterval;    // minutes
2217
  int32_t compactStartTime;   // minutes
2218
  int32_t compactEndTime;     // minutes
2219
  int8_t  compactTimeOffset;  // hour
2220
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2221
  int8_t  isAudit;
2222
  int8_t  allowDrop;
2223
  int8_t  secureDelete;
2224
  int8_t  securityLevel;
2225
} SCreateDbReq;
2226

2227
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2228
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2229
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2230

2231
typedef struct {
2232
  char    db[TSDB_DB_FNAME_LEN];
2233
  int32_t buffer;
2234
  int32_t pageSize;
2235
  int32_t pages;
2236
  int32_t cacheLastSize;
2237
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2238
  int32_t daysPerFile;
2239
  int32_t daysToKeep0;
2240
  int32_t daysToKeep1;
2241
  int32_t daysToKeep2;
2242
  int32_t keepTimeOffset;
2243
  int32_t walFsyncPeriod;
2244
  int8_t  walLevel;
2245
  int8_t  strict;
2246
  int8_t  cacheLast;
2247
  int8_t  replications;
2248
  int32_t sstTrigger;
2249
  int32_t minRows;
2250
  int32_t walRetentionPeriod;
2251
  int32_t walRetentionSize;
2252
  int32_t ssKeepLocal;
2253
  int8_t  ssCompact;
2254
  int32_t sqlLen;
2255
  char*   sql;
2256
  int8_t  withArbitrator;
2257
  // 1. add auto-compact parameters
2258
  int32_t compactInterval;
2259
  int32_t compactStartTime;
2260
  int32_t compactEndTime;
2261
  int8_t  compactTimeOffset;
2262
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2263
  int8_t  isAudit;
2264
  int8_t  allowDrop;
2265
  int8_t  secureDelete;  
2266
  int8_t  securityLevel;
2267
} SAlterDbReq;
2268

2269
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2270
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2271
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2272

2273
typedef struct {
2274
  char    db[TSDB_DB_FNAME_LEN];
2275
  int8_t  ignoreNotExists;
2276
  int8_t  force;
2277
  int32_t sqlLen;
2278
  char*   sql;
2279
} SDropDbReq;
2280

2281
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2282
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2283
void    tFreeSDropDbReq(SDropDbReq* pReq);
2284

2285
typedef struct {
2286
  char    db[TSDB_DB_FNAME_LEN];
2287
  int64_t uid;
2288
} SDropDbRsp;
2289

2290
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2291
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2292

2293
typedef struct {
2294
  char    name[TSDB_MOUNT_NAME_LEN];
2295
  int64_t uid;
2296
} SDropMountRsp;
2297

2298
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2299
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2300

2301
typedef struct {
2302
  char    db[TSDB_DB_FNAME_LEN];
2303
  int64_t dbId;
2304
  int32_t vgVersion;
2305
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2306
  int64_t stateTs;     // ms
2307
} SUseDbReq;
2308

2309
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2310
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2311

2312
typedef struct {
2313
  char    db[TSDB_DB_FNAME_LEN];
2314
  int64_t uid;
2315
  int32_t vgVersion;
2316
  int32_t vgNum;
2317
  int16_t hashPrefix;
2318
  int16_t hashSuffix;
2319
  int8_t  hashMethod;
2320
  union {
2321
    uint8_t flags;
2322
    struct {
2323
      uint8_t isMount : 1;  // TS-5868
2324
      uint8_t padding : 7;
2325
    };
2326
  };
2327
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2328
  int32_t errCode;
2329
  int64_t stateTs;  // ms
2330
} SUseDbRsp;
2331

2332
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2333
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2334
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2335
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2336
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2337

2338
typedef struct {
2339
  char db[TSDB_DB_FNAME_LEN];
2340
} SDbCfgReq;
2341

2342
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2343
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2344

2345
typedef struct {
2346
  char db[TSDB_DB_FNAME_LEN];
2347
} SSsMigrateDbReq;
2348

2349
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2350
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2351

2352
typedef struct {
2353
  int32_t ssMigrateId;
2354
  bool    bAccepted;
2355
} SSsMigrateDbRsp;
2356

2357
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2358
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2359

2360
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2361
typedef struct {
2362
  int32_t ssMigrateId;
2363
} SListSsMigrateFileSetsReq;
2364

2365
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2366
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2367

2368
typedef struct {
2369
  int32_t ssMigrateId;
2370
  int32_t vgId;       // vgroup id
2371
  SArray* pFileSets;  // SArray<int32_t>
2372
} SListSsMigrateFileSetsRsp;
2373

2374
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2375
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2376
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2377

2378
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2379
typedef struct {
2380
  int32_t ssMigrateId;
2381
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2382
  int32_t fid;
2383
  int64_t startTimeSec;
2384
} SSsMigrateFileSetReq;
2385

2386
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2387
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2388

2389
typedef struct {
2390
  int32_t ssMigrateId;
2391
  int32_t nodeId;  // node id of the leader vnode
2392
  int32_t vgId;
2393
  int32_t fid;
2394
} SSsMigrateFileSetRsp;
2395

2396
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2397
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2398

2399
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2400
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2401
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2402
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2403
#define SSMIGRATE_FILESET_STATE_FAILED      4
2404

2405
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2406
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2407
// while as a request, the 'state' field is not used.
2408
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2409
typedef struct {
2410
  int32_t ssMigrateId;  // ss migrate id
2411
  int32_t nodeId;       // node id of the leader vnode
2412
  int32_t vgId;         // vgroup id
2413
  int32_t fid;          // file set id
2414
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2415
} SSsMigrateProgress;
2416

2417
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2418
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2419

2420
// Request for TDMT_MND_KILL_SSMIGRATE
2421
typedef struct {
2422
  int32_t ssMigrateId;
2423
  int32_t sqlLen;
2424
  char*   sql;
2425
} SKillSsMigrateReq;
2426

2427
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2428
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2429
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2430

2431
// Request for TDMT_VND_KILL_SSMIGRATE
2432
typedef struct {
2433
  int32_t ssMigrateId;
2434
} SVnodeKillSsMigrateReq;
2435

2436
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2437
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2438

2439
typedef struct {
2440
  int32_t vgId;
2441
  int64_t keepVersion;
2442
} SMndSetVgroupKeepVersionReq;
2443

2444
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2445
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2446

2447
typedef struct {
2448
  int32_t timestampSec;
2449
  int32_t ttlDropMaxCount;
2450
  int32_t nUids;
2451
  SArray* pTbUids;
2452
} SVDropTtlTableReq;
2453

2454
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2455
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2456

2457
typedef struct {
2458
  char    db[TSDB_DB_FNAME_LEN];
2459
  int64_t dbId;
2460
  int64_t ownerId;
2461
  int32_t cfgVersion;
2462
  int32_t numOfVgroups;
2463
  int32_t numOfStables;
2464
  int32_t buffer;
2465
  int32_t cacheSize;
2466
  int32_t cacheShardBits;
2467
  int32_t pageSize;
2468
  int32_t pages;
2469
  int32_t daysPerFile;
2470
  int32_t daysToKeep0;
2471
  int32_t daysToKeep1;
2472
  int32_t daysToKeep2;
2473
  int32_t keepTimeOffset;
2474
  int32_t minRows;
2475
  int32_t maxRows;
2476
  int32_t walFsyncPeriod;
2477
  int16_t hashPrefix;
2478
  int16_t hashSuffix;
2479
  int8_t  hashMethod;
2480
  int8_t  walLevel;
2481
  int8_t  precision;
2482
  int8_t  compression;
2483
  int8_t  replications;
2484
  int8_t  strict;
2485
  int8_t  cacheLast;
2486
  int8_t  encryptAlgr;
2487
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2488
  int32_t ssChunkSize;
2489
  int32_t ssKeepLocal;
2490
  int8_t  ssCompact;
2491
  union {
2492
    uint8_t flags;
2493
    struct {
2494
      uint8_t isMount : 1;    // TS-5868
2495
      uint8_t allowDrop : 1;  // TS-7232
2496
      uint8_t securityLevel : 3;   // 6671585124
2497
      uint8_t padding : 3;
2498
    };
2499
  };
2500
  int8_t  compactTimeOffset;
2501
  int32_t compactInterval;
2502
  int32_t compactStartTime;
2503
  int32_t compactEndTime;
2504
  int32_t tsdbPageSize;
2505
  int32_t walRetentionPeriod;
2506
  int32_t walRollPeriod;
2507
  int64_t walRetentionSize;
2508
  int64_t walSegmentSize;
2509
  int32_t numOfRetensions;
2510
  SArray* pRetensions;
2511
  int8_t  schemaless;
2512
  int16_t sstTrigger;
2513
  int8_t  withArbitrator;
2514
  int8_t  isAudit;
2515
  int8_t  secureDelete;
2516
} SDbCfgRsp;
2517

2518
typedef SDbCfgRsp SDbCfgInfo;
2519

2520
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2521
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2522
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2523
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2524
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2525

2526
typedef struct {
2527
  int32_t rowNum;
2528
} SQnodeListReq;
2529

2530
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2531
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2532

2533
typedef struct {
2534
  int32_t rowNum;
2535
} SDnodeListReq;
2536

2537
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2538

2539
typedef struct {
2540
  int32_t useless;  // useless
2541
} SServerVerReq;
2542

2543
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2544
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2545

2546
typedef struct {
2547
  char ver[TSDB_VERSION_LEN];
2548
} SServerVerRsp;
2549

2550
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2551
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2552

2553
typedef struct SQueryNodeAddr {
2554
  int32_t nodeId;  // vgId or qnodeId
2555
  SEpSet  epSet;
2556
} SQueryNodeAddr;
2557

2558
typedef struct {
2559
  SQueryNodeAddr addr;
2560
  uint64_t       load;
2561
} SQueryNodeLoad;
2562

2563
typedef struct {
2564
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2565
} SQnodeListRsp;
2566

2567
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2568
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2569
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2570

2571

2572
typedef struct SDownstreamSourceNode {
2573
  ENodeType      type;
2574
  SQueryNodeAddr addr;
2575
  uint64_t       clientId;
2576
  uint64_t       taskId;
2577
  uint64_t       sId;
2578
  uint64_t       srcTaskId;
2579
  int32_t        execId;
2580
  int32_t        fetchMsgType;
2581
  bool           localExec;
2582
} SDownstreamSourceNode;
2583

2584

2585

2586
typedef struct SDNodeAddr {
2587
  int32_t nodeId;  // dnodeId
2588
  SEpSet  epSet;
2589
} SDNodeAddr;
2590

2591
typedef struct {
2592
  SArray* dnodeList;  // SArray<SDNodeAddr>
2593
} SDnodeListRsp;
2594

2595
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2596
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2597
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2598

2599
typedef struct {
2600
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2601
} STableTSMAInfoRsp;
2602

2603
typedef struct {
2604
  SUseDbRsp*         useDbRsp;
2605
  SDbCfgRsp*         cfgRsp;
2606
  STableTSMAInfoRsp* pTsmaRsp;
2607
  int32_t            dbTsmaVersion;
2608
  char               db[TSDB_DB_FNAME_LEN];
2609
  int64_t            dbId;
2610
} SDbHbRsp;
2611

2612
typedef struct {
2613
  SArray* pArray;  // Array of SDbHbRsp
2614
} SDbHbBatchRsp;
2615

2616
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2617
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2618
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2619

2620
typedef struct {
2621
  SArray* pArray;  // Array of SGetUserAuthRsp
2622
} SUserAuthBatchRsp;
2623

2624
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2625
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2626
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2627

2628
typedef struct {
2629
  char        db[TSDB_DB_FNAME_LEN];
2630
  STimeWindow timeRange;
2631
  int32_t     sqlLen;
2632
  char*       sql;
2633
  SArray*     vgroupIds;
2634
  int32_t     compactId;
2635
  int8_t      metaOnly;
2636
  int8_t      force;
2637
} SCompactDbReq;
2638

2639
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2640
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2641
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2642

2643
typedef struct {
2644
  union {
2645
    int32_t compactId;
2646
    int32_t id;
2647
  };
2648
  int8_t bAccepted;
2649
} SCompactDbRsp;
2650

2651
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2652
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2653

2654
typedef struct {
2655
  union {
2656
    int32_t compactId;
2657
    int32_t id;
2658
  };
2659
  int32_t sqlLen;
2660
  char*   sql;
2661
} SKillCompactReq;
2662

2663
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2664
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2665
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2666

2667
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2668
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2669

2670
typedef struct {
2671
  char    name[TSDB_FUNC_NAME_LEN];
2672
  int8_t  igExists;
2673
  int8_t  funcType;
2674
  int8_t  scriptType;
2675
  int8_t  outputType;
2676
  int32_t outputLen;
2677
  int32_t bufSize;
2678
  int32_t codeLen;
2679
  int64_t signature;
2680
  char*   pComment;
2681
  char*   pCode;
2682
  int8_t  orReplace;
2683
} SCreateFuncReq;
2684

2685
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2686
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2687
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2688

2689
typedef struct {
2690
  char   name[TSDB_FUNC_NAME_LEN];
2691
  int8_t igNotExists;
2692
} SDropFuncReq;
2693

2694
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2695
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2696

2697
typedef struct {
2698
  int32_t numOfFuncs;
2699
  bool    ignoreCodeComment;
2700
  SArray* pFuncNames;
2701
} SRetrieveFuncReq;
2702

2703
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2704
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2705
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2706

2707
typedef struct {
2708
  char    name[TSDB_FUNC_NAME_LEN];
2709
  int8_t  funcType;
2710
  int8_t  scriptType;
2711
  int8_t  outputType;
2712
  int32_t outputLen;
2713
  int32_t bufSize;
2714
  int64_t signature;
2715
  int32_t commentSize;
2716
  int32_t codeSize;
2717
  char*   pComment;
2718
  char*   pCode;
2719
} SFuncInfo;
2720

2721
typedef struct {
2722
  int32_t funcVersion;
2723
  int64_t funcCreatedTime;
2724
} SFuncExtraInfo;
2725

2726
typedef struct {
2727
  int32_t numOfFuncs;
2728
  SArray* pFuncInfos;
2729
  SArray* pFuncExtraInfos;
2730
} SRetrieveFuncRsp;
2731

2732
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2733
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2734
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2735
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2736

2737
typedef struct {
2738
  int32_t       statusInterval;
2739
  /*
2740
    Local timezone UTC offset in seconds (east-positive, e.g. +28800 for
2741
    Asia/Shanghai).  Derived from taosGetLocalTimezoneOffset() on each
2742
    status report.  Paired with the timezone string in
2743
    mndCheckClusterCfgPara: a mismatch is reported only when both the
2744
    timezone string AND this offset differ.
2745
  */
2746
  int64_t       checkTime;
2747
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2748
  char          locale[TD_LOCALE_LEN];      // tsLocale
2749
  char          charset[TD_LOCALE_LEN];     // tsCharset
2750
  int8_t        ttlChangeOnWrite;
2751
  int8_t        enableWhiteList;
2752
  int8_t        encryptionKeyStat;
2753
  uint32_t      encryptionKeyChksum;
2754
  SMonitorParas monitorParas;
2755
  int32_t       statusIntervalMs;
2756
} SClusterCfg;
2757

2758
typedef struct {
2759
  int32_t openVnodes;
2760
  int32_t dropVnodes;
2761
  int32_t totalVnodes;
2762
  int32_t masterNum;
2763
  int64_t numOfSelectReqs;
2764
  int64_t numOfInsertReqs;
2765
  int64_t numOfInsertSuccessReqs;
2766
  int64_t numOfBatchInsertReqs;
2767
  int64_t numOfBatchInsertSuccessReqs;
2768
  int64_t errors;
2769
} SVnodesStat;
2770

2771
typedef struct {
2772
  int32_t vgId;
2773
  int8_t  syncState;
2774
  int8_t  syncRestore;
2775
  int64_t syncTerm;
2776
  int64_t roleTimeMs;
2777
  int64_t startTimeMs;
2778
  int8_t  syncCanRead;
2779
  int64_t cacheUsage;
2780
  int64_t numOfTables;
2781
  int64_t numOfTimeSeries;
2782
  int64_t totalStorage;
2783
  int64_t compStorage;
2784
  int64_t pointsWritten;
2785
  int64_t numOfSelectReqs;
2786
  int64_t numOfInsertReqs;
2787
  int64_t numOfInsertSuccessReqs;
2788
  int64_t numOfBatchInsertReqs;
2789
  int64_t numOfBatchInsertSuccessReqs;
2790
  int32_t numOfCachedTables;
2791
  int32_t learnerProgress;  // use one reservered
2792
  int64_t syncAppliedIndex;
2793
  int64_t syncCommitIndex;
2794
  int64_t bufferSegmentUsed;
2795
  int64_t bufferSegmentSize;
2796
  int32_t snapSeq;
2797
  int64_t syncTotalIndex;
2798
} SVnodeLoad;
2799

2800
typedef struct {
2801
  int64_t total_requests;
2802
  int64_t total_rows;
2803
  int64_t total_bytes;
2804
  double  write_size;
2805
  double  cache_hit_ratio;
2806
  int64_t rpc_queue_wait;
2807
  int64_t preprocess_time;
2808

2809
  int64_t memory_table_size;
2810
  int64_t commit_count;
2811
  int64_t merge_count;
2812
  double  commit_time;
2813
  double  merge_time;
2814
  int64_t block_commit_time;
2815
  int64_t memtable_wait_time;
2816
} SVnodeMetrics;
2817

2818
typedef struct {
2819
  int32_t     vgId;
2820
  int64_t     numOfTables;
2821
  int64_t     memSize;
2822
  int64_t     l1Size;
2823
  int64_t     l2Size;
2824
  int64_t     l3Size;
2825
  int64_t     cacheSize;
2826
  int64_t     walSize;
2827
  int64_t     metaSize;
2828
  int64_t     rawDataSize;
2829
  int64_t     ssSize;
2830
  const char* dbname;
2831
  int8_t      estimateRawData;
2832
} SDbSizeStatisInfo;
2833

2834
typedef struct {
2835
  int32_t vgId;
2836
  int64_t nTimeSeries;
2837
} SVnodeLoadLite;
2838

2839
typedef struct {
2840
  int8_t  syncState;
2841
  int64_t syncTerm;
2842
  int8_t  syncRestore;
2843
  int64_t roleTimeMs;
2844
} SMnodeLoad;
2845

2846
typedef struct {
2847
  int32_t dnodeId;
2848
  int64_t numOfProcessedQuery;
2849
  int64_t numOfProcessedCQuery;
2850
  int64_t numOfProcessedFetch;
2851
  int64_t numOfProcessedDrop;
2852
  int64_t numOfProcessedNotify;
2853
  int64_t numOfProcessedHb;
2854
  int64_t numOfProcessedDelete;
2855
  int64_t cacheDataSize;
2856
  int64_t numOfQueryInQueue;
2857
  int64_t numOfFetchInQueue;
2858
  int64_t timeInQueryQueue;
2859
  int64_t timeInFetchQueue;
2860
} SQnodeLoad;
2861

2862
typedef struct {
2863
  int32_t     sver;      // software version
2864
  int64_t     dnodeVer;  // dnode table version in sdb
2865
  int32_t     dnodeId;
2866
  int64_t     clusterId;
2867
  int64_t     rebootTime;
2868
  int64_t     updateTime;
2869
  float       numOfCores;
2870
  int32_t     numOfSupportVnodes;
2871
  int32_t     numOfDiskCfg;
2872
  int64_t     memTotal;
2873
  int64_t     memAvail;
2874
  char        dnodeEp[TSDB_EP_LEN];
2875
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2876
  SMnodeLoad  mload;
2877
  SQnodeLoad  qload;
2878
  SClusterCfg clusterCfg;
2879
  SArray*     pVloads;  // array of SVnodeLoad
2880
  int32_t     statusSeq;
2881
  int64_t     ipWhiteVer;
2882
  int64_t     timeWhiteVer;
2883
  int64_t     analVer;
2884
  int64_t     timestamp;
2885
  char        auditDB[TSDB_DB_FNAME_LEN];
2886
  char        auditToken[TSDB_TOKEN_LEN];
2887
  SEpSet      auditEpSet;
2888
  int32_t     auditVgId;
2889
} SStatusReq;
2890

2891
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2892
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2893
void    tFreeSStatusReq(SStatusReq* pReq);
2894

2895
typedef struct {
2896
  int32_t forceReadConfig;
2897
  int32_t cver;
2898
  SArray* array;
2899
} SConfigReq;
2900

2901
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2902
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2903
void    tFreeSConfigReq(SConfigReq* pReq);
2904

2905
typedef struct {
2906
  int32_t dnodeId;
2907
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2908
} SDnodeInfoReq;
2909

2910
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2911
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2912

2913
typedef enum {
2914
  MONITOR_TYPE_COUNTER = 0,
2915
  MONITOR_TYPE_SLOW_LOG = 1,
2916
} MONITOR_TYPE;
2917

2918
typedef struct {
2919
  int32_t      contLen;
2920
  char*        pCont;
2921
  MONITOR_TYPE type;
2922
} SStatisReq;
2923

2924
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2925
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2926
void    tFreeSStatisReq(SStatisReq* pReq);
2927

2928
typedef struct {
2929
  char    db[TSDB_DB_FNAME_LEN];
2930
  char    table[TSDB_TABLE_NAME_LEN];
2931
  char    operation[AUDIT_OPERATION_LEN];
2932
  int32_t sqlLen;
2933
  char*   pSql;
2934
  double  duration;
2935
  int64_t affectedRows;
2936
} SAuditReq;
2937
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2938
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2939
void    tFreeSAuditReq(SAuditReq* pReq);
2940

2941
typedef struct {
2942
  SArray* auditArr;
2943
} SBatchAuditReq;
2944
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2945
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2946
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2947

2948
typedef struct {
2949
  int32_t dnodeId;
2950
  int64_t clusterId;
2951
  SArray* pVloads;
2952
} SNotifyReq;
2953

2954
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2955
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2956
void    tFreeSNotifyReq(SNotifyReq* pReq);
2957

2958
typedef struct {
2959
  int32_t dnodeId;
2960
  int64_t clusterId;
2961
} SDnodeCfg;
2962

2963
typedef struct {
2964
  int32_t id;
2965
  int8_t  isMnode;
2966
  SEp     ep;
2967
} SDnodeEp;
2968

2969
typedef struct {
2970
  int32_t id;
2971
  int8_t  isMnode;
2972
  int8_t  offlineReason;
2973
  SEp     ep;
2974
  char    active[TSDB_ACTIVE_KEY_LEN];
2975
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2976
} SDnodeInfo;
2977

2978
typedef struct {
2979
  int64_t   dnodeVer;
2980
  SDnodeCfg dnodeCfg;
2981
  SArray*   pDnodeEps;  // Array of SDnodeEp
2982
  int32_t   statusSeq;
2983
  int64_t   ipWhiteVer;
2984
  int64_t   analVer;
2985
  int64_t   timeWhiteVer;
2986
  char      auditDB[TSDB_DB_FNAME_LEN];
2987
  char      auditToken[TSDB_TOKEN_LEN];
2988
  SEpSet    auditEpSet;
2989
  int32_t   auditVgId;
2990
} SStatusRsp;
2991

2992
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2993
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2994
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2995

2996
typedef struct {
2997
  int32_t forceReadConfig;
2998
  int32_t isConifgVerified;
2999
  int32_t isVersionVerified;
3000
  int32_t cver;
3001
  SArray* array;
3002
} SConfigRsp;
3003

3004
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
3005
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
3006
void    tFreeSConfigRsp(SConfigRsp* pRsp);
3007

3008
typedef struct {
3009
  int32_t dnodeId;
3010
  int32_t keyVersion;  // Local key version
3011
} SKeySyncReq;
3012

3013
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
3014
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
3015

3016
typedef struct {
3017
  int32_t keyVersion;        // mnode's key version
3018
  int8_t  needUpdate;        // 1 if dnode needs to update keys
3019
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
3020
  char    svrKey[129];       // Server key (if needUpdate)
3021
  char    dbKey[129];        // Database key (if needUpdate)
3022
  char    cfgKey[129];       // Config key (if needUpdate)
3023
  char    metaKey[129];      // Metadata key (if needUpdate)
3024
  char    dataKey[129];      // Data key (if needUpdate)
3025
  int32_t algorithm;         // Encryption algorithm for master keys
3026
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
3027
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
3028
  int64_t createTime;        // Key creation time
3029
  int64_t svrKeyUpdateTime;  // Server key update time
3030
  int64_t dbKeyUpdateTime;   // Database key update time
3031
} SKeySyncRsp;
3032

3033
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
3034
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
3035

3036
typedef struct {
3037
  int32_t reserved;
3038
} SMTimerReq;
3039

3040
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
3041
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
3042

3043
typedef struct SOrphanTask {
3044
  int64_t streamId;
3045
  int32_t taskId;
3046
  int32_t nodeId;
3047
} SOrphanTask;
3048

3049
typedef struct SMStreamDropOrphanMsg {
3050
  SArray* pList;  // SArray<SOrphanTask>
3051
} SMStreamDropOrphanMsg;
3052

3053
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
3054
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
3055
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
3056

3057
typedef struct {
3058
  int32_t  id;
3059
  uint16_t port;                 // node sync Port
3060
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
3061
} SReplica;
3062

3063
typedef struct {
3064
  int32_t  vgId;
3065
  char     db[TSDB_DB_FNAME_LEN];
3066
  int64_t  dbUid;
3067
  int32_t  vgVersion;
3068
  int32_t  numOfStables;
3069
  int32_t  buffer;
3070
  int32_t  pageSize;
3071
  int32_t  pages;
3072
  int32_t  cacheLastSize;
3073
  int32_t  cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3074
  int32_t  daysPerFile;
3075
  int32_t  daysToKeep0;
3076
  int32_t  daysToKeep1;
3077
  int32_t  daysToKeep2;
3078
  int32_t  keepTimeOffset;
3079
  int32_t  minRows;
3080
  int32_t  maxRows;
3081
  int32_t  walFsyncPeriod;
3082
  uint32_t hashBegin;
3083
  uint32_t hashEnd;
3084
  int8_t   hashMethod;
3085
  int8_t   walLevel;
3086
  int8_t   precision;
3087
  int8_t   compression;
3088
  int8_t   strict;
3089
  int8_t   cacheLast;
3090
  int8_t   isTsma;
3091
  int8_t   replica;
3092
  int8_t   selfIndex;
3093
  SReplica replicas[TSDB_MAX_REPLICA];
3094
  int32_t  numOfRetensions;
3095
  SArray*  pRetensions;  // SRetention
3096
  void*    pTsma;
3097
  int32_t  walRetentionPeriod;
3098
  int64_t  walRetentionSize;
3099
  int32_t  walRollPeriod;
3100
  int64_t  walSegmentSize;
3101
  int16_t  sstTrigger;
3102
  int16_t  hashPrefix;
3103
  int16_t  hashSuffix;
3104
  int32_t  tsdbPageSize;
3105
  int32_t  ssChunkSize;
3106
  int32_t  ssKeepLocal;
3107
  int8_t   ssCompact;
3108
  int64_t  reserved[6];
3109
  int8_t   learnerReplica;
3110
  int8_t   learnerSelfIndex;
3111
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3112
  int32_t  changeVersion;
3113
  int8_t   encryptAlgorithm;
3114
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
3115
  union {
3116
    uint8_t flags;
3117
    struct {
3118
      uint8_t isAudit : 1;
3119
      uint8_t allowDrop : 1;
3120
      uint8_t securityLevel : 3;   // 6671585124
3121
      uint8_t padding : 3;
3122
    };
3123
  };
3124
  int8_t secureDelete;
3125
} SCreateVnodeReq;
3126

3127
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3128
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3129
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3130

3131
typedef struct {
3132
  union {
3133
    int32_t compactId;
3134
    int32_t id;
3135
  };
3136
  int32_t vgId;
3137
  int32_t dnodeId;
3138
} SQueryCompactProgressReq;
3139

3140
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3141
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3142

3143
typedef struct {
3144
  union {
3145
    int32_t compactId;
3146
    int32_t id;
3147
  };
3148
  int32_t vgId;
3149
  int32_t dnodeId;
3150
  int32_t numberFileset;
3151
  int32_t finished;
3152
  int32_t progress;
3153
  int64_t remainingTime;
3154
} SQueryCompactProgressRsp;
3155

3156
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3157
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3158

3159
typedef struct {
3160
  int32_t compactId;
3161
} SDnodeQueryCompactProgressReq;
3162

3163
int32_t tSerializeSDnodeQueryCompactProgressReq(void *buf, int32_t bufLen, SDnodeQueryCompactProgressReq *pReq);
3164
int32_t tDeserializeSDnodeQueryCompactProgressReq(void *buf, int32_t bufLen, SDnodeQueryCompactProgressReq *pReq);
3165

3166
typedef struct {
3167
  int32_t                   dnodeId;
3168
  int32_t                   numOfVnodes;
3169
  SQueryCompactProgressRsp *vnodeProgress;  // array of numOfVnodes elements
3170
} SDnodeQueryCompactProgressRsp;
3171

3172
int32_t tSerializeSDnodeQueryCompactProgressRsp(void *buf, int32_t bufLen, SDnodeQueryCompactProgressRsp *pRsp);
3173
int32_t tDeserializeSDnodeQueryCompactProgressRsp(void *buf, int32_t bufLen, SDnodeQueryCompactProgressRsp *pRsp);
3174
void    tFreeSDnodeQueryCompactProgressRsp(SDnodeQueryCompactProgressRsp *pRsp);
3175

3176
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3177
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3178

3179
typedef struct {
3180
  int32_t vgId;
3181
  int32_t dnodeId;
3182
  int64_t dbUid;
3183
  char    db[TSDB_DB_FNAME_LEN];
3184
  int64_t reserved[8];
3185
} SDropVnodeReq;
3186

3187
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3188
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3189

3190
typedef struct {
3191
  char    colName[TSDB_COL_NAME_LEN];
3192
  char    stb[TSDB_TABLE_FNAME_LEN];
3193
  int64_t stbUid;
3194
  int64_t dbUid;
3195
  int64_t reserved[8];
3196
} SDropIndexReq;
3197

3198
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3199
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3200

3201
typedef struct {
3202
  int64_t dbUid;
3203
  char    db[TSDB_DB_FNAME_LEN];
3204
  union {
3205
    int64_t compactStartTime;
3206
    int64_t startTime;
3207
  };
3208

3209
  STimeWindow tw;
3210
  union {
3211
    int32_t compactId;
3212
    int32_t id;
3213
  };
3214
  int8_t metaOnly;
3215
  union {
3216
    uint16_t flags;
3217
    struct {
3218
      uint16_t optrType : 3;     // ETsdbOpType
3219
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3220
      uint16_t reserved : 12;
3221
    };
3222
  };
3223
  int8_t force;  // force compact
3224
} SCompactVnodeReq;
3225

3226
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3227
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3228

3229
typedef struct {
3230
  union {
3231
    int32_t compactId;
3232
    int32_t taskId;
3233
  };
3234
  int32_t vgId;
3235
  int32_t dnodeId;
3236
} SVKillCompactReq;
3237

3238
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3239
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3240

3241
typedef SVKillCompactReq SVKillRetentionReq;
3242

3243
typedef struct {
3244
  char        db[TSDB_DB_FNAME_LEN];
3245
  int32_t     maxSpeed;
3246
  int32_t     sqlLen;
3247
  char*       sql;
3248
  SArray*     vgroupIds;
3249
  STimeWindow tw;  // unit is second
3250
  union {
3251
    uint32_t flags;
3252
    struct {
3253
      uint32_t optrType : 3;     // ETsdbOpType
3254
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3255
      uint32_t reserved : 28;
3256
    };
3257
  };
3258
} STrimDbReq;
3259

3260
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3261
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3262
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3263

3264
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3265

3266
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3267
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3268

3269
typedef struct {
3270
  int32_t vgVersion;
3271
  int32_t buffer;
3272
  int32_t pageSize;
3273
  int32_t pages;
3274
  int32_t cacheLastSize;
3275
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3276
  int32_t daysPerFile;
3277
  int32_t daysToKeep0;
3278
  int32_t daysToKeep1;
3279
  int32_t daysToKeep2;
3280
  int32_t keepTimeOffset;
3281
  int32_t walFsyncPeriod;
3282
  int8_t  walLevel;
3283
  int8_t  strict;
3284
  int8_t  cacheLast;
3285
  int64_t reserved[7];
3286
  // 1st modification
3287
  int16_t sttTrigger;
3288
  int32_t minRows;
3289
  // 2nd modification
3290
  int32_t walRetentionPeriod;
3291
  int32_t walRetentionSize;
3292
  int32_t ssKeepLocal;
3293
  int8_t  ssCompact;
3294
  int8_t  allowDrop;
3295
  int8_t  secureDelete;
3296
  int8_t  securityLevel;
3297
} SAlterVnodeConfigReq;
3298

3299
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3300
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3301

3302
typedef struct {
3303
  int32_t  vgId;
3304
  int8_t   strict;
3305
  int8_t   selfIndex;
3306
  int8_t   replica;
3307
  SReplica replicas[TSDB_MAX_REPLICA];
3308
  int64_t  reserved[8];
3309
  int8_t   learnerSelfIndex;
3310
  int8_t   learnerReplica;
3311
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3312
  int32_t  changeVersion;
3313
  int32_t  electBaseLine;
3314
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3315

3316
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3317
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3318

3319
typedef struct {
3320
  int32_t vgId;
3321
  int8_t  disable;
3322
} SDisableVnodeWriteReq;
3323

3324
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3325
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3326

3327
typedef struct {
3328
  int32_t  srcVgId;
3329
  int32_t  dstVgId;
3330
  uint32_t hashBegin;
3331
  uint32_t hashEnd;
3332
  int32_t  changeVersion;
3333
  int32_t  reserved;
3334
} SAlterVnodeHashRangeReq;
3335

3336
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3337
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3338

3339
#define REQ_OPT_TBNAME 0x0
3340
#define REQ_OPT_TBUID  0x01
3341
typedef struct {
3342
  SMsgHead header;
3343
  char     dbFName[TSDB_DB_FNAME_LEN];
3344
  char     tbName[TSDB_TABLE_NAME_LEN];
3345
  uint8_t  option;
3346
  uint8_t  autoCreateCtb;
3347
} STableInfoReq;
3348

3349
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3350
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3351

3352
typedef struct {
3353
  int8_t  metaClone;  // create local clone of the cached table meta
3354
  int32_t numOfVgroups;
3355
  int32_t numOfTables;
3356
  int32_t numOfUdfs;
3357
  char    tableNames[];
3358
} SMultiTableInfoReq;
3359

3360
// todo refactor
3361
typedef struct SVgroupInfo {
3362
  int32_t  vgId;
3363
  uint32_t hashBegin;
3364
  uint32_t hashEnd;
3365
  SEpSet   epSet;
3366
  union {
3367
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3368
    int32_t taskId;      // used in stream
3369
  };
3370
} SVgroupInfo;
3371

3372
typedef struct {
3373
  int32_t     numOfVgroups;
3374
  SVgroupInfo vgroups[];
3375
} SVgroupsInfo;
3376

3377
typedef struct {
3378
  STableMetaRsp* pMeta;
3379
} SMAlterStbRsp;
3380

3381
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3382
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3383
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3384

3385
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3386
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3387
void    tFreeSTableMetaRsp(void* pRsp);
3388
void    tFreeSTableIndexRsp(void* info);
3389

3390
typedef struct {
3391
  SArray* pMetaRsp;   // Array of STableMetaRsp
3392
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3393
} SSTbHbRsp;
3394

3395
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3396
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3397
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3398

3399
typedef struct {
3400
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3401
} SViewHbRsp;
3402

3403
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3404
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3405
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3406

3407
typedef struct {
3408
  int32_t numOfTables;
3409
  int32_t numOfVgroup;
3410
  int32_t numOfUdf;
3411
  int32_t contLen;
3412
  int8_t  compressed;  // denote if compressed or not
3413
  int32_t rawLen;      // size before compress
3414
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3415
  char    meta[];
3416
} SMultiTableMeta;
3417

3418
typedef struct {
3419
  int32_t dataLen;
3420
  char    name[TSDB_TABLE_FNAME_LEN];
3421
  char*   data;
3422
} STagData;
3423

3424
typedef struct {
3425
  int32_t  opType;
3426
  uint32_t valLen;
3427
  char*    val;
3428
} SShowVariablesReq;
3429

3430
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3431
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3432
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3433

3434
typedef struct {
3435
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3436
  char value[TSDB_CONFIG_PATH_LEN + 1];
3437
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3438
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3439
  char info[TSDB_CONFIG_INFO_LEN + 1];
3440
} SVariablesInfo;
3441

3442
typedef struct {
3443
  SArray* variables;  // SArray<SVariablesInfo>
3444
} SShowVariablesRsp;
3445

3446
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3447
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3448

3449
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3450

3451
/*
3452
 * sql: show tables like '%a_%'
3453
 * payload is the query condition, e.g., '%a_%'
3454
 * payloadLen is the length of payload
3455
 */
3456
typedef struct {
3457
  int32_t type;
3458
  char    db[TSDB_DB_FNAME_LEN];
3459
  int32_t payloadLen;
3460
  char*   payload;
3461
} SShowReq;
3462

3463
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3464
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3465
void tFreeSShowReq(SShowReq* pReq);
3466

3467
typedef struct {
3468
  int64_t       showId;
3469
  STableMetaRsp tableMeta;
3470
} SShowRsp, SVShowTablesRsp;
3471

3472
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3473
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3474
// void    tFreeSShowRsp(SShowRsp* pRsp);
3475

3476
typedef struct {
3477
  char    db[TSDB_DB_FNAME_LEN];
3478
  char    tb[TSDB_TABLE_NAME_LEN];
3479
  char    user[TSDB_USER_LEN];
3480
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3481
  int64_t showId;
3482
  int64_t compactId;  // for compact
3483
  bool    withFull;   // for show users full
3484
} SRetrieveTableReq;
3485

3486
typedef struct SSysTableSchema {
3487
  int8_t   type;
3488
  col_id_t colId;
3489
  int32_t  bytes;
3490
} SSysTableSchema;
3491

3492
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3493
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3494

3495
#define RETRIEVE_TABLE_RSP_VERSION         0
3496
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3497
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3498

3499
typedef struct {
3500
  int64_t useconds;
3501
  int8_t  completed;  // all results are returned to client
3502
  int8_t  precision;
3503
  int8_t  compressed;
3504
  int8_t  streamBlockType;
3505
  int32_t payloadLen;
3506
  int32_t compLen;
3507
  int32_t numOfBlocks;
3508
  int64_t numOfRows;  // from int32_t change to int64_t
3509
  int64_t numOfCols;
3510
  int64_t skey;
3511
  int64_t ekey;
3512
  int64_t version;                         // for stream
3513
  TSKEY   watermark;                       // for stream
3514
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3515
  char    data[];
3516
} SRetrieveTableRsp;
3517

3518
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3519

3520
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3521
  do {                                          \
3522
    ((int32_t*)(_p))[0] = (_compLen);           \
3523
    ((int32_t*)(_p))[1] = (_fullLen);           \
3524
  } while (0);
3525

3526
typedef struct {
3527
  int64_t version;
3528
  int64_t numOfRows;
3529
  int8_t  compressed;
3530
  int8_t  precision;
3531
  char    data[];
3532
} SRetrieveTableRspForTmq;
3533

3534
typedef struct {
3535
  int64_t handle;
3536
  int64_t useconds;
3537
  int8_t  completed;  // all results are returned to client
3538
  int8_t  precision;
3539
  int8_t  compressed;
3540
  int32_t compLen;
3541
  int32_t numOfRows;
3542
  int32_t fullLen;
3543
  char    data[];
3544
} SRetrieveMetaTableRsp;
3545

3546
typedef struct SExplainExecInfo {
3547
  /* the number of rows returned */
3548
  uint64_t numOfRows;
3549
  uint32_t verboseLen;
3550
  void*    verboseInfo;
3551

3552
  /* the timestamp when the operator is created */
3553
  TSKEY    execCreate;
3554
  /* the first timestamp when the operator's next interface is called */
3555
  TSKEY    execStart;
3556
  /* the timestamp when the first row is returned */
3557
  TSKEY    execFirstRow;
3558
  /* the timestamp when the last row is returned */
3559
  TSKEY    execLastRow;
3560
  /* the number of times the operator's next interface is called */
3561
  uint32_t execTimes;
3562
  /**
3563
    the time elapsed for executing the operator's next interface,
3564
    not including waiting time for data from downstream
3565
  */
3566
  TSKEY    execElapsed;
3567
  /* the time elapsed for waiting for data from downstream */
3568
  TSKEY    inputWaitElapsed;
3569
  /* the time elapsed for waiting call from upstream */
3570
  TSKEY    outputWaitElapsed;
3571
  /* the number of rows input */
3572
  uint64_t inputRows;
3573

3574
  int32_t  vgId;
3575
} SExplainExecInfo;
3576

3577
typedef struct {
3578
  int32_t           numOfPlans;
3579
  SExplainExecInfo* subplanInfo;
3580
} SExplainRsp;
3581

3582
typedef struct {
3583
  SExplainRsp rsp;
3584
  uint64_t    qId;
3585
  uint64_t    cId;
3586
  uint64_t    tId;
3587
  int64_t     rId;
3588
  int32_t     eId;
3589
} SExplainLocalRsp;
3590

3591
typedef struct STableScanAnalyzeInfo {
3592
  int64_t totalBlocks;
3593
  int64_t fileLoadBlocks;
3594
  double  fileLoadElapsed;
3595
  int64_t sttLoadBlocks;
3596
  double  sttLoadElapsed;
3597
  int64_t memLoadBlocks;
3598
  double  memLoadElapsed;
3599
  int64_t smaLoadBlocks;
3600
  double  smaLoadElapsed;
3601
  int64_t composedBlocks;
3602
  double  composedElapsed;
3603
  
3604
  uint64_t checkRows;
3605

3606
  uint64_t skipBlocks;
3607
  uint64_t filterOutBlocks;
3608
  double   filterTime;
3609
} STableScanAnalyzeInfo;
3610

3611
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3612
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3613
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3614

3615
typedef struct {
3616
  char    config[TSDB_DNODE_CONFIG_LEN];
3617
  char    value[TSDB_CLUSTER_VALUE_LEN];
3618
  int32_t sqlLen;
3619
  char*   sql;
3620
} SMCfgClusterReq;
3621

3622
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3623
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3624
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3625

3626
typedef struct {
3627
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3628
  int32_t port;
3629
  int32_t sqlLen;
3630
  char*   sql;
3631
} SCreateDnodeReq;
3632

3633
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3634
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3635
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3636

3637
typedef struct {
3638
  int32_t dnodeId;
3639
  char    fqdn[TSDB_FQDN_LEN];
3640
  int32_t port;
3641
  int8_t  force;
3642
  int8_t  unsafe;
3643
  int32_t sqlLen;
3644
  char*   sql;
3645
} SDropDnodeReq;
3646

3647
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3648
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3649
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3650

3651
enum {
3652
  RESTORE_TYPE__ALL = 1,
3653
  RESTORE_TYPE__MNODE,
3654
  RESTORE_TYPE__VNODE,
3655
  RESTORE_TYPE__QNODE,
3656
};
3657

3658
typedef struct {
3659
  int32_t dnodeId;
3660
  int8_t  restoreType;
3661
  int32_t sqlLen;
3662
  char*   sql;
3663
  int32_t vgId;
3664
} SRestoreDnodeReq;
3665

3666
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3667
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3668
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3669

3670
typedef struct {
3671
  int32_t dnodeId;
3672
  char    config[TSDB_DNODE_CONFIG_LEN];
3673
  char    value[TSDB_DNODE_VALUE_LEN];
3674
  int32_t sqlLen;
3675
  char*   sql;
3676
} SMCfgDnodeReq;
3677

3678
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3679
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3680
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3681

3682
typedef struct {
3683
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3684
  char    newKey[ENCRYPT_KEY_LEN + 1];
3685
  int32_t sqlLen;
3686
  char*   sql;
3687
} SMAlterEncryptKeyReq;
3688

3689
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3690
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3691
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3692

3693
typedef struct {
3694
  int32_t days;
3695
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3696
  int32_t sqlLen;
3697
  char*   sql;
3698
} SMAlterKeyExpirationReq;
3699

3700
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3701
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3702
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3703

3704
typedef struct {
3705
  char    config[TSDB_DNODE_CONFIG_LEN];
3706
  char    value[TSDB_DNODE_VALUE_LEN];
3707
  int32_t version;
3708
} SDCfgDnodeReq;
3709

3710
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3711
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3712

3713
typedef struct {
3714
  int32_t dnodeId;
3715
  int32_t sqlLen;
3716
  char*   sql;
3717
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3718
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3719

3720
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3721
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3722

3723
typedef struct {
3724
  int32_t nodeId;
3725
  SEpSet  epSet;
3726
} SNodeEpSet;
3727

3728
typedef struct {
3729
  int32_t    snodeId;
3730
  SNodeEpSet leaders[2];
3731
  SNodeEpSet replica;
3732
  int32_t    sqlLen;
3733
  char*      sql;
3734
} SDCreateSnodeReq;
3735

3736
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3737
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3738
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3739

3740
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3741
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3742
typedef struct {
3743
  int8_t   replica;
3744
  SReplica replicas[TSDB_MAX_REPLICA];
3745
  int8_t   learnerReplica;
3746
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3747
  int64_t  lastIndex;
3748
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3749
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3750

3751
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3752
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3753

3754
typedef struct {
3755
  int32_t urlLen;
3756
  int32_t sqlLen;
3757
  char*   url;
3758
  char*   sql;
3759
} SMCreateAnodeReq;
3760

3761
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3762
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3763
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3764

3765
typedef struct {
3766
  int32_t anodeId;
3767
  int32_t sqlLen;
3768
  char*   sql;
3769
} SMDropAnodeReq, SMUpdateAnodeReq;
3770

3771
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3772
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3773
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3774
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3775
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3776
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3777

3778
typedef struct {
3779
  int32_t dnodeId;
3780
  int32_t bnodeProto;
3781
  int32_t sqlLen;
3782
  char*   sql;
3783
} SMCreateBnodeReq, SDCreateBnodeReq;
3784

3785
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3786
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3787
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3788

3789
typedef struct {
3790
  int32_t dnodeId;
3791
  int32_t sqlLen;
3792
  char*   sql;
3793
} SMDropBnodeReq, SDDropBnodeReq;
3794

3795
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3796
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3797
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3798

3799
typedef struct {
3800
  bool        shouldFree;
3801
  int32_t     len;
3802
  const char* ptr;
3803
} CowStr;
3804
/**
3805
 * @brief Create a CowStr object.
3806
 *
3807
 * @param len: length of the string.
3808
 * @param ptr: pointer to the string input.
3809
 * @param shouldClone: whether to clone the string.
3810
 * @return CowStr object.
3811
 */
3812
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3813
/**
3814
 * @brief Set a CowStr object with given string.
3815
 *
3816
 * @param cow: pointer to the CowStr object.
3817
 * @param len: length of the string.
3818
 * @param ptr: pointer to the string input.
3819
 * @param shouldFree: whether to free the string.
3820
 */
3821
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3822
/**
3823
 * @brief Clone a CowStr object without copy the string.
3824
 *
3825
 * @param cow: pointer to the CowStr object.
3826
 * @return CowStr object.
3827
 */
3828
CowStr xCloneRefCowStr(CowStr* cow);
3829
/**
3830
 * @brief Convert a CowStr object to a string.
3831
 *
3832
 * @param cow: pointer to the CowStr object.
3833
 */
3834
char* xCowStrToStr(CowStr* cow);
3835
/**
3836
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3837
 *
3838
 * @param cow: pointer to the CowStr object.
3839
 */
3840
void xFreeCowStr(CowStr* cow);
3841
/**
3842
 * @brief Encode and push a CowStr object into the encoder.
3843
 *
3844
 * @param encoder
3845
 * @param cow
3846
 * @return int32_t
3847
 */
3848
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3849
/**
3850
 * @brief Decode a CowStr from the encoder.
3851
 *
3852
 * @param decoder
3853
 * @param cow
3854
 * @param shouldClone
3855
 * @return int32_t
3856
 */
3857
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3858

3859
typedef struct {
3860
  int32_t sqlLen;
3861
  int32_t urlLen;
3862
  int32_t userLen;
3863
  int32_t passLen;
3864
  int32_t passIsMd5;
3865
  char*   sql;
3866
  char*   url;
3867
  char*   user;
3868
  char*   pass;
3869
  CowStr  token;
3870
} SMCreateXnodeReq, SDCreateXnodeReq;
3871

3872
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3873
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3874
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3875

3876
typedef struct {
3877
  int32_t xnodeId;
3878
  int32_t force;
3879
  int32_t urlLen;
3880
  int32_t sqlLen;
3881
  char*   url;
3882
  char*   sql;
3883
} SMDropXnodeReq, SDDropXnodeReq;
3884

3885
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3886
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3887
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3888

3889
typedef struct {
3890
  int32_t id;
3891
  CowStr  token;
3892
  CowStr  user;
3893
  CowStr  pass;
3894
  int32_t urlLen;
3895
  int32_t sqlLen;
3896
  char*   url;
3897
  char*   sql;
3898
} SMUpdateXnodeReq;
3899
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3900
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3901
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3902

3903
typedef struct {
3904
  int32_t xnodeId;
3905
  int32_t sqlLen;
3906
  char*   sql;
3907
} SMDrainXnodeReq;
3908
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3909
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3910
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3911
typedef enum {
3912
  XNODE_TASK_SOURCE_DSN = 1,
3913
  XNODE_TASK_SOURCE_DATABASE,
3914
  XNODE_TASK_SOURCE_TOPIC,
3915
} ENodeXTaskSourceType;
3916

3917
typedef enum {
3918
  XNODE_TASK_SINK_DSN = 1,
3919
  XNODE_TASK_SINK_DATABASE,
3920
} ENodeXTaskSinkType;
3921

3922
typedef struct {
3923
  ENodeXTaskSourceType type;
3924
  CowStr               cstr;
3925
} xTaskSource;
3926
/**
3927
 * @brief Deallocate a xTaskSource object.
3928
 *
3929
 * @param source ptr
3930
 */
3931
void xFreeTaskSource(xTaskSource* source);
3932
/**
3933
 * @brief Create a xTaskSource object with cloned source string.
3934
 *
3935
 * @param sourceType: source type.
3936
 * @param len: length of source string.
3937
 * @param source: source string ptr.
3938
 * @return xTaskSource object
3939
 */
3940
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3941
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3942
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3943
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3944
const char* xGetTaskSourceStr(xTaskSource* source);
3945
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3946
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3947

3948
typedef struct {
3949
  ENodeXTaskSinkType type;
3950
  CowStr             cstr;
3951
} xTaskSink;
3952
/**
3953
 * @brief Deallocate a xTaskSink object.
3954
 *
3955
 * @param sink ptr
3956
 */
3957
void xFreeTaskSink(xTaskSink* sink);
3958
/**
3959
 * @brief Create a xTaskSink object with cloned name string.
3960
 *
3961
 * @param sinkType: sink type.
3962
 * @param len: length of sink string.
3963
 * @param ptr: sink string ptr.
3964
 * @return xTaskSink object
3965
 */
3966
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3967
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3968
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3969
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3970
const char* xGetTaskSinkStr(xTaskSink* sink);
3971
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3972
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3973

3974
typedef struct {
3975
  int32_t via;
3976
  CowStr  parser;
3977
  // CowStr  reason;
3978
  CowStr  trigger;
3979
  CowStr  health;
3980
  int32_t optionsNum;
3981
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3982
} xTaskOptions;
3983
/**
3984
 * @brief Deallocate a xTaskOptions object.
3985
 *
3986
 * @param options ptr
3987
 */
3988
void    xFreeTaskOptions(xTaskOptions* options);
3989
void    printXnodeTaskOptions(xTaskOptions* options);
3990
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3991
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3992

3993
typedef struct {
3994
  int32_t sqlLen;
3995
  char*   sql;
3996
  int32_t      xnodeId;
3997
  CowStr       name;
3998
  xTaskSource  source;
3999
  xTaskSink    sink;
4000
  xTaskOptions options;
4001
} SMCreateXnodeTaskReq;
4002
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
4003
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
4004
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
4005

4006
typedef struct {
4007
  int32_t     tid;
4008
  CowStr      name;
4009
  int32_t     via;
4010
  int32_t     xnodeId;
4011
  CowStr      status;
4012
  xTaskSource source;
4013
  xTaskSink   sink;
4014
  CowStr      parser;
4015
  CowStr      reason;
4016
  CowStr      updateName;
4017
  CowStr      labels;
4018
  int32_t     sqlLen;
4019
  char*       sql;
4020
} SMUpdateXnodeTaskReq;
4021
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
4022
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
4023
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
4024

4025
typedef struct {
4026
  int32_t id;
4027
  bool    force;
4028
  CowStr  name;
4029
  int32_t sqlLen;
4030
  char*   sql;
4031
} SMDropXnodeTaskReq;
4032
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
4033
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
4034
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
4035

4036
typedef struct {
4037
  int32_t tid;
4038
  CowStr  name;
4039
  int32_t sqlLen;
4040
  char*   sql;
4041
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
4042
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
4043
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
4044
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
4045

4046
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
4047
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
4048
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
4049

4050
typedef struct {
4051
  int32_t tid;
4052
  int32_t via;
4053
  int32_t xnodeId;
4054
  CowStr  status;
4055
  CowStr  config;
4056
  CowStr  reason;
4057
  int32_t sqlLen;
4058
  char*   sql;
4059
} SMCreateXnodeJobReq;
4060
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
4061
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
4062
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
4063

4064
typedef struct {
4065
  int32_t jid;
4066
  int32_t via;
4067
  int32_t xnodeId;
4068
  CowStr  status;
4069
  int32_t configLen;
4070
  int32_t reasonLen;
4071
  int32_t sqlLen;
4072
  char*   config;
4073
  char*   reason;
4074
  char*   sql;
4075
} SMUpdateXnodeJobReq;
4076
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4077
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4078
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
4079

4080
typedef struct {
4081
  int32_t jid;
4082
  int32_t xnodeId;
4083
  int32_t sqlLen;
4084
  char*   sql;
4085
} SMRebalanceXnodeJobReq;
4086
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4087
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4088
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
4089

4090
typedef struct {
4091
  CowStr  ast;
4092
  int32_t sqlLen;
4093
  char*   sql;
4094
} SMRebalanceXnodeJobsWhereReq;
4095
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4096
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4097
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
4098

4099
typedef struct {
4100
  int32_t jid;
4101
  CowStr  ast;
4102
  int32_t sqlLen;
4103
  char*   sql;
4104
} SMDropXnodeJobReq;
4105
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4106
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4107
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
4108

4109
typedef struct {
4110
  int32_t      sqlLen;
4111
  char*        sql;
4112
  CowStr       name;
4113
  CowStr       status;
4114
  xTaskOptions options;
4115
} SMCreateXnodeAgentReq;
4116
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4117
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4118
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
4119

4120
typedef struct {
4121
  int32_t      sqlLen;
4122
  char*        sql;
4123
  int32_t      id;
4124
  CowStr       name;
4125
  xTaskOptions options;
4126
} SMUpdateXnodeAgentReq;
4127
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4128
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4129
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
4130

4131
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4132
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4133
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4134
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4135

4136
typedef struct {
4137
  int32_t vgId;
4138
  int32_t hbSeq;
4139
} SVArbHbReqMember;
4140

4141
typedef struct {
4142
  int32_t dnodeId;
4143
  char*   arbToken;
4144
  int64_t arbTerm;
4145
  SArray* hbMembers;  // SVArbHbReqMember
4146
} SVArbHeartBeatReq;
4147

4148
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4149
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4150
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4151

4152
typedef struct {
4153
  int32_t vgId;
4154
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4155
  int32_t hbSeq;
4156
} SVArbHbRspMember;
4157

4158
typedef struct {
4159
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4160
  int32_t dnodeId;
4161
  SArray* hbMembers;  // SVArbHbRspMember
4162
} SVArbHeartBeatRsp;
4163

4164
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4165
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4166
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4167

4168
typedef struct {
4169
  char*   arbToken;
4170
  int64_t arbTerm;
4171
  char*   member0Token;
4172
  char*   member1Token;
4173
} SVArbCheckSyncReq;
4174

4175
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4176
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4177
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4178

4179
typedef struct {
4180
  char*   arbToken;
4181
  char*   member0Token;
4182
  char*   member1Token;
4183
  int32_t vgId;
4184
  int32_t errCode;
4185
} SVArbCheckSyncRsp;
4186

4187
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4188
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4189
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4190

4191
typedef struct {
4192
  char*   arbToken;
4193
  int64_t arbTerm;
4194
  char*   memberToken;
4195
  int8_t  force;
4196
} SVArbSetAssignedLeaderReq;
4197

4198
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4199
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4200
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4201

4202
typedef struct {
4203
  char* data;
4204
} SVAuditRecordReq;
4205
int32_t tSerializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4206
int32_t tDeserializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4207
void    tFreeSVAuditRecordReq(SVAuditRecordReq* pReq);
4208

4209
typedef struct {
4210
  char*   arbToken;
4211
  char*   memberToken;
4212
  int32_t vgId;
4213
} SVArbSetAssignedLeaderRsp;
4214

4215
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4216
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4217
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4218

4219
typedef struct {
4220
  int32_t dnodeId;
4221
  char*   token;
4222
} SMArbUpdateGroupMember;
4223

4224
typedef struct {
4225
  int32_t dnodeId;
4226
  char*   token;
4227
  int8_t  acked;
4228
} SMArbUpdateGroupAssigned;
4229

4230
typedef struct {
4231
  int32_t                  vgId;
4232
  int64_t                  dbUid;
4233
  SMArbUpdateGroupMember   members[2];
4234
  int8_t                   isSync;
4235
  int8_t                   assignedAcked;
4236
  SMArbUpdateGroupAssigned assignedLeader;
4237
  int64_t                  version;
4238
  int32_t                  code;
4239
  int64_t                  updateTimeMs;
4240
} SMArbUpdateGroup;
4241

4242
typedef struct {
4243
  SArray* updateArray;  // SMArbUpdateGroup
4244
} SMArbUpdateGroupBatchReq;
4245

4246
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4247
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4248
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4249

4250
typedef struct {
4251
  char queryStrId[TSDB_QUERY_ID_LEN];
4252
} SKillQueryReq;
4253

4254
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4255
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4256

4257
typedef struct {
4258
  uint32_t connId;
4259
} SKillConnReq;
4260

4261
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4262
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4263

4264
typedef struct {
4265
  int32_t transId;
4266
} SKillTransReq;
4267

4268
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4269
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4270

4271
typedef struct {
4272
  int32_t useless;  // useless
4273
  int32_t sqlLen;
4274
  char*   sql;
4275
} SBalanceVgroupReq;
4276

4277
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4278
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4279
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4280

4281
typedef struct {
4282
  int32_t useless;  // useless
4283
  int32_t sqlLen;
4284
  char*   sql;
4285
} SAssignLeaderReq;
4286

4287
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4288
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4289
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4290
typedef struct {
4291
  int32_t vgId1;
4292
  int32_t vgId2;
4293
} SMergeVgroupReq;
4294

4295
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4296
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4297

4298
typedef struct {
4299
  int32_t vgId;
4300
  int32_t dnodeId1;
4301
  int32_t dnodeId2;
4302
  int32_t dnodeId3;
4303
  int32_t sqlLen;
4304
  char*   sql;
4305
} SRedistributeVgroupReq;
4306

4307
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4308
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4309
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4310

4311
typedef struct {
4312
  int32_t reserved;
4313
  int32_t vgId;
4314
  int32_t sqlLen;
4315
  char*   sql;
4316
  char    db[TSDB_DB_FNAME_LEN];
4317
} SBalanceVgroupLeaderReq;
4318

4319
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4320
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4321
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4322

4323
typedef struct {
4324
  int32_t vgId;
4325
} SForceBecomeFollowerReq;
4326

4327
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4328
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4329

4330
typedef struct {
4331
  int32_t vgId;
4332
  bool    force;
4333
} SSplitVgroupReq;
4334

4335
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4336
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4337

4338
typedef struct {
4339
  char user[TSDB_USER_LEN];
4340
  char spi;
4341
  char encrypt;
4342
  char secret[TSDB_PASSWORD_LEN];
4343
  char ckey[TSDB_PASSWORD_LEN];
4344
} SAuthReq, SAuthRsp;
4345

4346
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4347
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4348

4349
typedef struct {
4350
  int32_t statusCode;
4351
  char    details[1024];
4352
} SServerStatusRsp;
4353

4354
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4355
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4356

4357
/**
4358
 * The layout of the query message payload is as following:
4359
 * +--------------------+---------------------------------+
4360
 * |Sql statement       | Physical plan                   |
4361
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4362
 * +--------------------+---------------------------------+
4363
 */
4364
typedef struct SSubQueryMsg {
4365
  SMsgHead header;
4366
  uint64_t sId;
4367
  uint64_t queryId;
4368
  uint64_t clientId;
4369
  uint64_t taskId;
4370
  int64_t  refId;
4371
  int32_t  execId;
4372
  int32_t  msgMask;
4373
  int32_t  subQType;
4374
  int8_t   taskType;
4375
  int8_t   explain;
4376
  int8_t   needFetch;
4377
  int8_t   compress;
4378
  uint32_t sqlLen;
4379
  char*    sql;
4380
  uint32_t msgLen;
4381
  char*    msg;
4382
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4383
} SSubQueryMsg;
4384

4385
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4386
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4387
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4388

4389
typedef struct {
4390
  SMsgHead header;
4391
  uint64_t sId;
4392
  uint64_t queryId;
4393
  uint64_t taskId;
4394
} SSinkDataReq;
4395

4396
typedef struct {
4397
  SMsgHead header;
4398
  uint64_t sId;
4399
  uint64_t queryId;
4400
  uint64_t clientId;
4401
  uint64_t taskId;
4402
  int32_t  execId;
4403
} SQueryContinueReq;
4404

4405
typedef struct {
4406
  SMsgHead header;
4407
  uint64_t sId;
4408
  uint64_t queryId;
4409
  uint64_t taskId;
4410
} SResReadyReq;
4411

4412
typedef struct {
4413
  int32_t code;
4414
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4415
  int32_t sversion;
4416
  int32_t tversion;
4417
} SResReadyRsp;
4418

4419
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4420

4421
typedef struct SOperatorParam {
4422
  int32_t opType;
4423
  int32_t downstreamIdx;
4424
  void*   value;
4425
  SArray* pChildren;  // SArray<SOperatorParam*>
4426
  bool    reUse;
4427
} SOperatorParam;
4428

4429
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4430

4431
// virtual table's colId to origin table's colname
4432
typedef struct SColIdNameKV {
4433
  col_id_t colId;
4434
  char     colName[TSDB_COL_NAME_LEN];
4435
} SColIdNameKV;
4436

4437
#define COL_MASK_ON   ((int8_t)0x1)
4438
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4439
#define COL_SET_MASK_ON(c)     \
4440
  do {                         \
4441
    (c)->flags |= COL_MASK_ON; \
4442
  } while (0)
4443

4444
typedef struct SColNameFlag {
4445
  col_id_t colId;
4446
  char     colName[TSDB_COL_NAME_LEN];
4447
  int8_t   flags;  // 0x01: COL_MASK_ON
4448
} SColNameFlag;
4449

4450
typedef struct SColIdPair {
4451
  col_id_t  vtbColId;
4452
  col_id_t  orgColId;
4453
  SDataType type;
4454
} SColIdPair;
4455

4456
typedef struct SColIdSlotIdPair {
4457
  int32_t  vtbSlotId;
4458
  col_id_t orgColId;
4459
} SColIdSlotIdPair;
4460

4461
typedef struct SOrgTbInfo {
4462
  int32_t vgId;
4463
  char    tbName[TSDB_TABLE_FNAME_LEN];
4464
  SArray* colMap;  // SArray<SColIdNameKV>
4465
} SOrgTbInfo;
4466

4467
void destroySOrgTbInfo(void *info);
4468

4469
typedef enum {
4470
  DYN_TYPE_STB_JOIN = 1,
4471
  DYN_TYPE_VSTB_SINGLE_SCAN,
4472
  DYN_TYPE_VSTB_BATCH_SCAN,
4473
  DYN_TYPE_VSTB_WIN_SCAN,
4474
} ETableScanDynType;
4475

4476
typedef enum {
4477
  DYN_TYPE_SCAN_PARAM = 1,
4478
  NOTIFY_TYPE_SCAN_PARAM,
4479
} ETableScanGetParamType;
4480

4481
typedef struct STableScanOperatorParam {
4482
  ETableScanGetParamType paramType;
4483
  /* for building scan data source */
4484
  bool                   tableSeq;
4485
  bool                   isNewParam;
4486
  uint64_t               groupid;
4487
  SArray*                pUidList;
4488
  SOrgTbInfo*            pOrgTbInfo;
4489
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4490
  SArray*                pTagList;
4491
  STimeWindow            window;
4492
  ETableScanDynType      dynType;
4493
  /* for notifying source step done */
4494
  bool                   notifyToProcess;  // received notify STEP DONE message
4495
  TSKEY                  notifyTs;         // notify timestamp
4496
} STableScanOperatorParam;
4497

4498
typedef struct STagScanOperatorParam {
4499
  tb_uid_t vcUid;
4500
} STagScanOperatorParam;
4501

4502
typedef struct SRefColIdGroup {
4503
  SArray* pSlotIdList;  // SArray<int32_t>
4504
} SRefColIdGroup;
4505

4506
typedef struct SVTableScanOperatorParam {
4507
  uint64_t        uid;
4508
  STimeWindow     window;
4509
  SOperatorParam* pTagScanOp;
4510
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4511
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4512
} SVTableScanOperatorParam;
4513

4514
typedef struct SMergeOperatorParam {
4515
  int32_t         winNum;
4516
} SMergeOperatorParam;
4517

4518
typedef struct SAggOperatorParam {
4519
  bool            needCleanRes;
4520
} SAggOperatorParam;
4521

4522
typedef struct SExternalWindowOperatorParam {
4523
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4524
} SExternalWindowOperatorParam;
4525

4526
typedef struct SDynQueryCtrlOperatorParam {
4527
  STimeWindow    window;
4528
} SDynQueryCtrlOperatorParam;
4529

4530
struct SStreamRuntimeFuncInfo;
4531
typedef struct {
4532
  SMsgHead        header;
4533
  uint64_t        sId;
4534
  uint64_t        queryId;
4535
  uint64_t        clientId;
4536
  uint64_t        taskId;
4537
  uint64_t        srcTaskId;  // used for subQ
4538
  uint64_t        blockIdx;   // used for subQ
4539
  int32_t         execId;
4540
  SOperatorParam* pOpParam;
4541

4542
  // used for new-stream
4543
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4544
  bool                           reset;
4545
  bool                           dynTbname;
4546
  // used for new-stream
4547
} SResFetchReq;
4548

4549
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamRtInfo, bool needStreamGrpInfo);
4550
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4551
void    tDestroySResFetchReq(SResFetchReq* pReq);
4552
typedef struct {
4553
  SMsgHead header;
4554
  uint64_t clientId;
4555
} SSchTasksStatusReq;
4556

4557
typedef struct {
4558
  uint64_t queryId;
4559
  uint64_t clientId;
4560
  uint64_t taskId;
4561
  int64_t  refId;
4562
  int32_t  subJobId;
4563
  int32_t  execId;
4564
  int8_t   status;
4565
} STaskStatus;
4566

4567
typedef struct {
4568
  int64_t refId;
4569
  SArray* taskStatus;  // SArray<STaskStatus>
4570
} SSchedulerStatusRsp;
4571

4572
typedef struct {
4573
  uint64_t queryId;
4574
  uint64_t taskId;
4575
  int8_t   action;
4576
} STaskAction;
4577

4578
typedef struct SQueryNodeEpId {
4579
  int32_t nodeId;  // vgId or qnodeId
4580
  SEp     ep;
4581
} SQueryNodeEpId;
4582

4583
typedef struct {
4584
  SMsgHead       header;
4585
  uint64_t       clientId;
4586
  SQueryNodeEpId epId;
4587
  SArray*        taskAction;  // SArray<STaskAction>
4588
} SSchedulerHbReq;
4589

4590
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4591
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4592
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4593

4594
typedef struct {
4595
  SQueryNodeEpId epId;
4596
  SArray*        taskStatus;  // SArray<STaskStatus>
4597
} SSchedulerHbRsp;
4598

4599
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4600
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4601
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4602

4603
typedef struct {
4604
  SMsgHead header;
4605
  uint64_t sId;
4606
  uint64_t queryId;
4607
  uint64_t clientId;
4608
  uint64_t taskId;
4609
  int64_t  refId;
4610
  int32_t  execId;
4611
} STaskCancelReq;
4612

4613
typedef struct {
4614
  int32_t code;
4615
} STaskCancelRsp;
4616

4617
typedef struct {
4618
  SMsgHead header;
4619
  uint64_t sId;
4620
  uint64_t queryId;
4621
  uint64_t clientId;
4622
  uint64_t taskId;
4623
  int64_t  refId;
4624
  int32_t  execId;
4625
} STaskDropReq;
4626

4627
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4628
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4629

4630
typedef enum {
4631
  TASK_NOTIFY_FINISHED = 1,
4632
} ETaskNotifyType;
4633

4634
typedef struct {
4635
  SMsgHead        header;
4636
  uint64_t        sId;
4637
  uint64_t        queryId;
4638
  uint64_t        clientId;
4639
  uint64_t        taskId;
4640
  int64_t         refId;
4641
  int32_t         execId;
4642
  ETaskNotifyType type;
4643
} STaskNotifyReq;
4644

4645
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4646
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4647

4648
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4649
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4650

4651
typedef struct {
4652
  int32_t code;
4653
} STaskDropRsp;
4654

4655
#define STREAM_TRIGGER_AT_ONCE                 1
4656
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4657
#define STREAM_TRIGGER_MAX_DELAY               3
4658
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4659
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4660

4661
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4662
#define STREAM_FILL_HISTORY_ON        1
4663
#define STREAM_FILL_HISTORY_OFF       0
4664
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4665
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4666
#define STREAM_CREATE_STABLE_TRUE     1
4667
#define STREAM_CREATE_STABLE_FALSE    0
4668

4669
typedef struct SVgroupVer {
4670
  int32_t vgId;
4671
  int64_t ver;
4672
} SVgroupVer;
4673

4674
enum {
4675
  TOPIC_SUB_TYPE__DB = 1,
4676
  TOPIC_SUB_TYPE__TABLE,
4677
  TOPIC_SUB_TYPE__COLUMN,
4678
};
4679

4680
#define DEFAULT_MAX_POLL_INTERVAL  300000
4681
#define DEFAULT_SESSION_TIMEOUT    12000
4682
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4683
#define DEFAULT_MIN_POLL_ROWS      4096
4684

4685
typedef struct {
4686
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4687
  int8_t igExists;
4688
  int8_t subType;
4689
  int8_t withMeta;
4690
  char*  sql;
4691
  char   subDbName[TSDB_DB_FNAME_LEN];
4692
  char*  ast;
4693
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4694
  int8_t reload;
4695
} SCMCreateTopicReq;
4696

4697
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4698
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4699
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4700

4701
typedef struct {
4702
  int64_t consumerId;
4703
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4704

4705
typedef struct {
4706
  int64_t consumerId;
4707
  char    cgroup[TSDB_CGROUP_LEN];
4708
  char    clientId[TSDB_CLIENT_ID_LEN];
4709
  char    user[TSDB_USER_LEN];
4710
  char    fqdn[TSDB_FQDN_LEN];
4711
  SArray* topicNames;  // SArray<char**>
4712

4713
  int8_t  withTbName;
4714
  int8_t  autoCommit;
4715
  int32_t autoCommitInterval;
4716
  int8_t  resetOffsetCfg;
4717
  int8_t  enableReplay;
4718
  int8_t  enableBatchMeta;
4719
  int32_t sessionTimeoutMs;
4720
  int32_t maxPollIntervalMs;
4721
  int64_t ownerId;
4722
} SCMSubscribeReq;
4723

4724
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4725
  int32_t tlen = 0;
800,530✔
4726
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
800,530✔
4727
  tlen += taosEncodeString(buf, pReq->cgroup);
800,530✔
4728
  tlen += taosEncodeString(buf, pReq->clientId);
800,530✔
4729

4730
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
800,530✔
4731
  tlen += taosEncodeFixedI32(buf, topicNum);
800,530✔
4732

4733
  for (int32_t i = 0; i < topicNum; i++) {
1,120,700✔
4734
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
640,340✔
4735
  }
4736

4737
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
800,530✔
4738
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
800,530✔
4739
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
800,530✔
4740
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
800,530✔
4741
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
800,530✔
4742
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
800,530✔
4743
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
800,530✔
4744
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
800,530✔
4745
  tlen += taosEncodeString(buf, pReq->user);
800,530✔
4746
  tlen += taosEncodeString(buf, pReq->fqdn);
800,530✔
4747

4748
  return tlen;
800,530✔
4749
}
4750

4751
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4752
  void* start = buf;
428,616✔
4753
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
428,616✔
4754
  buf = taosDecodeStringTo(buf, pReq->cgroup);
428,616✔
4755
  buf = taosDecodeStringTo(buf, pReq->clientId);
428,616✔
4756

4757
  int32_t topicNum = 0;
428,616✔
4758
  buf = taosDecodeFixedI32(buf, &topicNum);
428,616✔
4759

4760
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
428,616✔
4761
  if (pReq->topicNames == NULL) {
428,616✔
4762
    return terrno;
×
4763
  }
4764
  for (int32_t i = 0; i < topicNum; i++) {
622,975✔
4765
    char* name = NULL;
194,359✔
4766
    buf = taosDecodeString(buf, &name);
194,359✔
4767
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
388,718✔
4768
      return terrno;
×
4769
    }
4770
  }
4771

4772
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
428,616✔
4773
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
428,616✔
4774
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
428,616✔
4775
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
428,616✔
4776
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
428,616✔
4777
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
428,616✔
4778
  if ((char*)buf - (char*)start < len) {
428,616✔
4779
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
428,616✔
4780
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
428,616✔
4781
    buf = taosDecodeStringTo(buf, pReq->user);
428,616✔
4782
    buf = taosDecodeStringTo(buf, pReq->fqdn);
857,232✔
4783
  } else {
4784
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
4785
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4786
  }
4787

4788
  return 0;
428,616✔
4789
}
4790

4791
typedef struct {
4792
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4793
  SArray* removedConsumers;  // SArray<int64_t>
4794
  SArray* newConsumers;      // SArray<int64_t>
4795
} SMqRebInfo;
4796

4797
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4798
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
387,743✔
4799
  if (pRebInfo == NULL) {
387,743✔
4800
    return NULL;
×
4801
  }
4802
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
387,743✔
4803
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
387,743✔
4804
  if (pRebInfo->removedConsumers == NULL) {
387,743✔
4805
    goto _err;
×
4806
  }
4807
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
387,743✔
4808
  if (pRebInfo->newConsumers == NULL) {
387,743✔
4809
    goto _err;
×
4810
  }
4811
  return pRebInfo;
387,743✔
4812
_err:
×
4813
  taosArrayDestroy(pRebInfo->removedConsumers);
×
4814
  taosArrayDestroy(pRebInfo->newConsumers);
×
4815
  taosMemoryFreeClear(pRebInfo);
×
4816
  return NULL;
×
4817
}
4818

4819
typedef struct {
4820
  int64_t streamId;
4821
  int64_t checkpointId;
4822
  char    streamName[TSDB_STREAM_FNAME_LEN];
4823
} SMStreamDoCheckpointMsg;
4824

4825
typedef struct {
4826
  int64_t status;
4827
} SMVSubscribeRsp;
4828

4829
typedef struct {
4830
  char    name[TSDB_TOPIC_FNAME_LEN];
4831
  int8_t  igNotExists;
4832
  int32_t sqlLen;
4833
  char*   sql;
4834
  int8_t  force;
4835
} SMDropTopicReq;
4836

4837
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4838
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4839
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4840

4841
typedef struct {
4842
  char    name[TSDB_TOPIC_FNAME_LEN];
4843
  int8_t  igNotExists;
4844
  int32_t sqlLen;
4845
  char*   sql;
4846
} SMReloadTopicReq;
4847

4848
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4849
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4850
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4851

4852
typedef struct {
4853
  char   topic[TSDB_TOPIC_FNAME_LEN];
4854
  char   cgroup[TSDB_CGROUP_LEN];
4855
  int8_t igNotExists;
4856
  int8_t force;
4857
} SMDropCgroupReq;
4858

4859
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4860
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4861

4862
typedef struct {
4863
  int8_t reserved;
4864
} SMDropCgroupRsp;
4865

4866
typedef struct {
4867
  char    name[TSDB_TABLE_FNAME_LEN];
4868
  int8_t  alterType;
4869
  SSchema schema;
4870
} SAlterTopicReq;
4871

4872
typedef struct {
4873
  SMsgHead head;
4874
  char     name[TSDB_TABLE_FNAME_LEN];
4875
  int64_t  tuid;
4876
  int32_t  sverson;
4877
  int32_t  execLen;
4878
  char*    executor;
4879
  int32_t  sqlLen;
4880
  char*    sql;
4881
} SDCreateTopicReq;
4882

4883
typedef struct {
4884
  SMsgHead head;
4885
  char     name[TSDB_TABLE_FNAME_LEN];
4886
  int64_t  tuid;
4887
} SDDropTopicReq;
4888

4889
typedef struct {
4890
  char*      name;
4891
  int64_t    uid;
4892
  int64_t    interval[2];
4893
  int8_t     intervalUnit;
4894
  int16_t    nFuncs;
4895
  col_id_t*  funcColIds;  // column ids specified by user
4896
  func_id_t* funcIds;     // function ids specified by user
4897
} SRSmaParam;
4898

4899
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4900
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4901

4902
// TDMT_VND_CREATE_STB ==============
4903
typedef struct SVCreateStbReq {
4904
  char*           name;
4905
  tb_uid_t        suid;
4906
  int8_t          rollup;
4907
  SSchemaWrapper  schemaRow;
4908
  SSchemaWrapper  schemaTag;
4909
  SRSmaParam      rsmaParam;
4910
  int32_t         alterOriDataLen;
4911
  void*           alterOriData;
4912
  int8_t          source;
4913
  int8_t          colCmpred;
4914
  SColCmprWrapper colCmpr;
4915
  int64_t         keep;
4916
  int64_t         ownerId;
4917
  SExtSchema*     pExtSchemas;
4918
  int8_t          virtualStb;
4919
  int8_t          secureDelete;
4920
  int8_t          securityLevel;
4921
} SVCreateStbReq;
4922

4923
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4924
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4925

4926
// TDMT_VND_DROP_STB ==============
4927
typedef struct SVDropStbReq {
4928
  char*    name;
4929
  tb_uid_t suid;
4930
} SVDropStbReq;
4931

4932
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4933
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4934

4935
// TDMT_VND_CREATE_TABLE ==============
4936
#define TD_CREATE_IF_NOT_EXISTS       0x1
4937
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4938
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4939
typedef struct SVCreateTbReq {
4940
  int32_t  flags;
4941
  char*    name;
4942
  tb_uid_t uid;
4943
  int64_t  btime;
4944
  int32_t  ttl;
4945
  int32_t  commentLen;
4946
  char*    comment;
4947
  int8_t   type;
4948
  union {
4949
    struct {
4950
      char*    stbName;  // super table name
4951
      uint8_t  tagNum;
4952
      tb_uid_t suid;
4953
      SArray*  tagName;
4954
      uint8_t* pTag;
4955
    } ctb;
4956
    struct {
4957
      SSchemaWrapper schemaRow;
4958
      int64_t        userId;
4959
    } ntb;
4960
  };
4961
  int32_t         sqlLen;
4962
  char*           sql;
4963
  SColCmprWrapper colCmpr;
4964
  SExtSchema*     pExtSchemas;
4965
  SColRefWrapper  colRef;  // col reference for virtual table
4966
} SVCreateTbReq;
4967

4968
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4969
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4970
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4971
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4972

4973
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4974
  if (NULL == req) {
2,147,483,647✔
4975
    return;
2,147,483,647✔
4976
  }
4977

4978
  taosMemoryFreeClear(req->sql);
84,363,908✔
4979
  taosMemoryFreeClear(req->name);
84,359,039✔
4980
  taosMemoryFreeClear(req->comment);
84,352,465✔
4981
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
84,336,545✔
4982
    taosMemoryFreeClear(req->ctb.pTag);
76,179,913✔
4983
    taosMemoryFreeClear(req->ctb.stbName);
76,156,789✔
4984
    taosArrayDestroy(req->ctb.tagName);
76,164,677✔
4985
    req->ctb.tagName = NULL;
76,136,561✔
4986
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
8,174,334✔
4987
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
8,174,828✔
4988
  }
4989
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
84,319,152✔
4990
  taosMemoryFreeClear(req->pExtSchemas);
84,337,870✔
4991
  taosMemoryFreeClear(req->colRef.pColRef);
84,328,453✔
4992
  taosMemoryFreeClear(req->colRef.pTagRef);
84,334,230✔
4993
}
4994

4995
typedef struct {
4996
  int32_t nReqs;
4997
  union {
4998
    SVCreateTbReq* pReqs;
4999
    SArray*        pArray;
5000
  };
5001
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
5002
} SVCreateTbBatchReq;
5003

5004
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
5005
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
5006
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
5007

5008
typedef struct {
5009
  int32_t        code;
5010
  int32_t        index;  // index in batch req, start from 0
5011
  STableMetaRsp* pMeta;
5012
} SVCreateTbRsp, SVUpdateTbRsp;
5013

5014
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
5015
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
5016
void tFreeSVCreateTbRsp(void* param);
5017

5018
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
5019
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
5020

5021
typedef struct {
5022
  int32_t nRsps;
5023
  union {
5024
    SVCreateTbRsp* pRsps;
5025
    SArray*        pArray;
5026
  };
5027
} SVCreateTbBatchRsp;
5028

5029
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
5030
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
5031

5032
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
5033
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
5034

5035
// TDMT_VND_DROP_TABLE =================
5036
typedef struct {
5037
  char*    name;
5038
  uint64_t suid;  // for tmq in wal format
5039
  int64_t  uid;
5040
  int8_t   igNotExists;
5041
  int8_t   isVirtual;
5042
} SVDropTbReq;
5043

5044
typedef struct {
5045
  int32_t code;
5046
} SVDropTbRsp;
5047

5048
typedef struct {
5049
  int32_t nReqs;
5050
  union {
5051
    SVDropTbReq* pReqs;
5052
    SArray*      pArray;
5053
  };
5054
} SVDropTbBatchReq;
5055

5056
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
5057
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
5058

5059
typedef struct {
5060
  int32_t nRsps;
5061
  union {
5062
    SVDropTbRsp* pRsps;
5063
    SArray*      pArray;
5064
  };
5065
} SVDropTbBatchRsp;
5066

5067
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
5068
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
5069

5070
// TDMT_VND_ALTER_TABLE =====================
5071
typedef struct SUpdatedTagVal {
5072
  char*    tagName;
5073
  int32_t  colId;
5074
  int8_t   tagType;
5075
  int8_t   tagFree;
5076
  uint32_t nTagVal;
5077
  uint8_t* pTagVal;
5078
  int8_t   isNull;
5079
  SArray*  pTagArray;
5080
  // NOTE: regexp and replacement are only a temporary solution for tag value update,
5081
  // they should be replaced by a more generic solution in the future for full expression
5082
  // support
5083
  char*    regexp;
5084
  char*    replacement;
5085
} SUpdatedTagVal;
5086

5087
typedef struct SUpdateTableTagVal {
5088
  char *tbName;
5089
  SArray* tags; // Array of SUpdatedTagVal
5090
} SUpdateTableTagVal;
5091

5092
typedef struct SVAlterTbReq {
5093
  char*   tbName;
5094
  int8_t  action;
5095
  char*   colName;
5096
  int32_t colId;
5097
  // TSDB_ALTER_TABLE_ADD_COLUMN
5098
  int8_t  type;
5099
  int8_t  flags;
5100
  int32_t bytes;
5101
  // TSDB_ALTER_TABLE_DROP_COLUMN
5102
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
5103
  int8_t   colModType;
5104
  int32_t  colModBytes;
5105
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
5106
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
5107
  int8_t   isNull;
5108
  int8_t   tagType;
5109
  int8_t   tagFree;
5110
  uint32_t nTagVal;
5111
  uint8_t* pTagVal;
5112
  SArray*  pTagArray;
5113
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
5114
  int8_t   updateTTL;
5115
  int32_t  newTTL;
5116
  int32_t  newCommentLen;
5117
  char*    newComment;
5118
  int64_t  ctimeMs;    // fill by vnode
5119
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
5120
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
5121
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS and TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL
5122
  SArray*  tables;     // Array of SUpdateTableTagVal, for TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL
5123
  int32_t  whereLen;   // [whereLen] & [where] are for TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL,
5124
  uint8_t* where;      // [where] is the encode where condition.
5125
  // for Add column
5126
  STypeMod typeMod;
5127
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
5128
  char* refDbName;
5129
  char* refTbName;
5130
  char* refColName;
5131
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
5132
} SVAlterTbReq;
5133

5134
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
5135
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
5136
void    destroyAlterTbReq(SVAlterTbReq* pReq);
5137
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
5138
void    tfreeMultiTagUpateVal(void* pMultiTag);
5139
void    tfreeUpdateTableTagVal(void* pMultiTable);
5140

5141
typedef struct {
5142
  int32_t        code;
5143
  STableMetaRsp* pMeta;
5144
} SVAlterTbRsp;
5145

5146
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
5147
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
5148
// ======================
5149

5150
typedef struct {
5151
  SMsgHead head;
5152
  int64_t  uid;
5153
  int32_t  tid;
5154
  int16_t  tversion;
5155
  int16_t  colId;
5156
  int8_t   type;
5157
  int16_t  bytes;
5158
  int32_t  tagValLen;
5159
  int16_t  numOfTags;
5160
  int32_t  schemaLen;
5161
  char     data[];
5162
} SUpdateTagValReq;
5163

5164
typedef struct {
5165
  SMsgHead head;
5166
} SUpdateTagValRsp;
5167

5168
typedef struct {
5169
  SMsgHead head;
5170
} SVShowTablesReq;
5171

5172
typedef struct {
5173
  SMsgHead head;
5174
  int32_t  id;
5175
} SVShowTablesFetchReq;
5176

5177
typedef struct {
5178
  int64_t useconds;
5179
  int8_t  completed;  // all results are returned to client
5180
  int8_t  precision;
5181
  int8_t  compressed;
5182
  int32_t compLen;
5183
  int32_t numOfRows;
5184
  char    data[];
5185
} SVShowTablesFetchRsp;
5186

5187
typedef struct {
5188
  int64_t consumerId;
5189
  int32_t epoch;
5190
  char    cgroup[TSDB_CGROUP_LEN];
5191
} SMqAskEpReq;
5192

5193
typedef struct {
5194
  int32_t key;
5195
  int32_t valueLen;
5196
  void*   value;
5197
} SKv;
5198

5199
typedef struct {
5200
  int64_t tscRid;
5201
  int8_t  connType;
5202
} SClientHbKey;
5203

5204
typedef struct {
5205
  int64_t tid;
5206
  char    status[TSDB_JOB_STATUS_LEN];
5207
  int64_t startTs;  // sub-task first execution start time, us
5208
} SQuerySubDesc;
5209

5210
typedef enum EQueryExecPhase {
5211
  /* Main phases: 0-9 */
5212
  QUERY_PHASE_NONE     = 0,
5213
  QUERY_PHASE_PARSE    = 1,
5214
  QUERY_PHASE_CATALOG  = 2,
5215
  QUERY_PHASE_PLAN     = 3,
5216
  QUERY_PHASE_SCHEDULE = 4,
5217
  QUERY_PHASE_EXECUTE  = 5,
5218
  QUERY_PHASE_FETCH    = 6,
5219
  QUERY_PHASE_DONE     = 7,
5220

5221
  /* SCHEDULE sub-phases: 4x */
5222
  QUERY_PHASE_SCHEDULE_ANALYSIS       = 41,
5223
  QUERY_PHASE_SCHEDULE_PLANNING       = 42,
5224
  QUERY_PHASE_SCHEDULE_NODE_SELECTION = 43,
5225

5226
  /* EXECUTE sub-phases: 5x */
5227
  QUERY_PHASE_EXEC_DATA_QUERY       = 51,
5228
  QUERY_PHASE_EXEC_MERGE_QUERY      = 52,
5229
  QUERY_PHASE_EXEC_WAITING_CHILDREN = 53,
5230

5231
  /* FETCH sub-phases: 6x */
5232
  QUERY_PHASE_FETCH_IN_PROGRESS = 60,  // A single fetch operation is in progress
5233
  QUERY_PHASE_FETCH_RETURNED    = 61,  // Data returned to client, business logic processing
5234
} EQueryExecPhase;
5235

5236
const char* queryPhaseStr(int32_t phase);
5237

5238
typedef struct {
5239
  char     sql[TSDB_SHOW_SQL_LEN];
5240
  uint64_t queryId;
5241
  int64_t  useconds;
5242
  int64_t  stime;  // timestamp precision ms
5243
  int64_t  reqRid;
5244
  bool     stableQuery;
5245
  bool     isSubQuery;
5246
  char     fqdn[TSDB_FQDN_LEN];
5247
  int32_t  subPlanNum;
5248
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5249
  int32_t  execPhase;       // EQueryExecPhase
5250
  int64_t  phaseStartTime;  // when current phase started, ms
5251
} SQueryDesc;
5252

5253
typedef struct {
5254
  uint32_t connId;
5255
  SArray*  queryDesc;  // SArray<SQueryDesc>
5256
} SQueryHbReqBasic;
5257

5258
typedef struct {
5259
  uint32_t connId;
5260
  uint64_t killRid;
5261
  int32_t  totalDnodes;
5262
  int32_t  onlineDnodes;
5263
  int8_t   killConnection;
5264
  int8_t   align[3];
5265
  SEpSet   epSet;
5266
  SArray*  pQnodeList;
5267
} SQueryHbRspBasic;
5268

5269
typedef struct SAppClusterSummary {
5270
  uint64_t numOfInsertsReq;
5271
  uint64_t numOfInsertRows;
5272
  uint64_t insertElapsedTime;
5273
  uint64_t insertBytes;  // submit to tsdb since launched.
5274

5275
  uint64_t fetchBytes;
5276
  uint64_t numOfQueryReq;
5277
  uint64_t queryElapsedTime;
5278
  uint64_t numOfSlowQueries;
5279
  uint64_t totalRequests;
5280
  uint64_t currentRequests;  // the number of SRequestObj
5281
} SAppClusterSummary;
5282

5283
typedef struct {
5284
  int64_t            appId;
5285
  int32_t            pid;
5286
  char               name[TSDB_APP_NAME_LEN];
5287
  int64_t            startTime;
5288
  SAppClusterSummary summary;
5289
} SAppHbReq;
5290

5291
typedef struct {
5292
  SClientHbKey      connKey;
5293
  int64_t           clusterId;
5294
  SAppHbReq         app;
5295
  SQueryHbReqBasic* query;
5296
  SHashObj*         info;  // hash<Skv.key, Skv>
5297
  char              user[TSDB_USER_LEN];
5298
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5299
  char              userApp[TSDB_APP_NAME_LEN];
5300
  uint32_t          userIp;
5301
  SIpRange          userDualIp;
5302
  char              sVer[TSDB_VERSION_LEN];
5303
  char              cInfo[CONNECTOR_INFO_LEN];
5304
} SClientHbReq;
5305

5306
typedef struct {
5307
  int64_t reqId;
5308
  SArray* reqs;  // SArray<SClientHbReq>
5309
  int64_t ipWhiteListVer;
5310
} SClientHbBatchReq;
5311

5312
typedef struct {
5313
  SClientHbKey      connKey;
5314
  int32_t           status;
5315
  SQueryHbRspBasic* query;
5316
  SArray*           info;  // Array<Skv>
5317
} SClientHbRsp;
5318

5319
typedef struct {
5320
  int64_t       reqId;
5321
  int64_t       rspId;
5322
  int32_t       svrTimestamp;
5323
  SArray*       rsps;  // SArray<SClientHbRsp>
5324
  SMonitorParas monitorParas;
5325
  int8_t        enableAuditDelete;
5326
  int8_t        enableStrongPass;
5327
  int8_t        enableAuditSelect;
5328
  int8_t        enableAuditInsert;
5329
  int8_t        auditLevel;
5330
  union {
5331
    uint32_t flags;
5332
    struct {
5333
      uint32_t sodInitial : 1;   // cluster-wide: 1 = SoD still in initial phase
5334
      uint32_t macActive  : 1;   // cluster-wide: 1 = MAC mandatory mode activated
5335
      uint32_t reserved   : 30;
5336
    };
5337
  };
5338
} SClientHbBatchRsp;
5339

5340
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
445,528,383✔
5341

5342
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5343
  void* pIter = taosHashIterate(info, NULL);
68,596,130✔
5344
  while (pIter != NULL) {
161,352,779✔
5345
    SKv* kv = (SKv*)pIter;
92,750,269✔
5346
    taosMemoryFreeClear(kv->value);
92,750,269✔
5347
    pIter = taosHashIterate(info, pIter);
92,749,565✔
5348
  }
5349
}
68,602,510✔
5350

5351
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
46,687,063✔
5352
  SQueryDesc* desc = (SQueryDesc*)pDesc;
46,687,063✔
5353
  if (desc->subDesc) {
46,687,063✔
5354
    taosArrayDestroy(desc->subDesc);
33,416,450✔
5355
    desc->subDesc = NULL;
33,415,623✔
5356
  }
5357
}
46,687,032✔
5358

5359
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
79,110,435✔
5360
  SClientHbReq* req = (SClientHbReq*)pReq;
169,084,858✔
5361
  if (req->query) {
169,084,858✔
5362
    if (req->query->queryDesc) {
79,109,563✔
5363
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
36,225,773✔
5364
    }
5365
    taosMemoryFreeClear(req->query);
79,107,545✔
5366
  }
5367

5368
  if (req->info) {
169,084,545✔
5369
    tFreeReqKvHash(req->info);
68,596,866✔
5370
    taosHashCleanup(req->info);
68,602,510✔
5371
    req->info = NULL;
68,599,198✔
5372
  }
5373
}
128,560,132✔
5374

5375
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5376
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5377

5378
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5379
  if (pReq == NULL) return;
33,569,515✔
5380
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
33,569,515✔
5381
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
33,569,515✔
5382
  taosMemoryFree(pReq);
33,569,515✔
5383
}
5384

5385
static FORCE_INLINE void tFreeClientKv(void* pKv) {
92,408,613✔
5386
  SKv* kv = (SKv*)pKv;
92,408,613✔
5387
  if (kv) {
92,408,613✔
5388
    taosMemoryFreeClear(kv->value);
92,408,613✔
5389
  }
5390
}
92,410,741✔
5391

5392
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
78,770,323✔
5393
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
78,770,323✔
5394
  if (rsp->query) {
78,770,323✔
5395
    taosArrayDestroy(rsp->query->pQnodeList);
78,759,769✔
5396
    taosMemoryFreeClear(rsp->query);
78,757,341✔
5397
  }
5398
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
78,768,828✔
5399
}
40,188,522✔
5400

5401
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5402
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
64,158,736✔
5403
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
64,158,736✔
5404
}
64,156,662✔
5405

5406
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5407
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5408
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5409

5410
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5411
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
364,702,034✔
5412
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
364,699,833✔
5413
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
364,698,074✔
5414
  return 0;
182,347,368✔
5415
}
5416

5417
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5418
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
181,703,861✔
5419
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
181,705,075✔
5420

5421
  if (pKv->valueLen < 0) {
90,852,488✔
5422
    return TSDB_CODE_INVALID_MSG;
×
5423
  }
5424

5425
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
90,850,442✔
5426
  if (pKv->value == NULL) {
90,849,221✔
5427
    return TSDB_CODE_OUT_OF_MEMORY;
×
5428
  }
5429
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
90,849,903✔
5430
  return 0;
90,853,095✔
5431
}
5432

5433
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5434
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
310,296,089✔
5435
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
310,288,678✔
5436
  return 0;
155,145,485✔
5437
}
5438

5439
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5440
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
154,479,130✔
5441
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
154,480,844✔
5442
  return 0;
77,239,567✔
5443
}
5444

5445
typedef struct {
5446
  int32_t vgId;
5447
  // TODO stas
5448
} SMqReportVgInfo;
5449

5450
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5451
  int32_t tlen = 0;
5452
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5453
  return tlen;
5454
}
5455

5456
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5457
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5458
  return buf;
5459
}
5460

5461
typedef struct {
5462
  int32_t epoch;
5463
  int64_t topicUid;
5464
  char    name[TSDB_TOPIC_FNAME_LEN];
5465
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5466
} SMqTopicInfo;
5467

5468
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5469
  int32_t tlen = 0;
5470
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5471
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5472
  tlen += taosEncodeString(buf, pTopicInfo->name);
5473
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5474
  tlen += taosEncodeFixedI32(buf, sz);
5475
  for (int32_t i = 0; i < sz; i++) {
5476
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5477
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5478
  }
5479
  return tlen;
5480
}
5481

5482
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5483
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5484
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5485
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5486
  int32_t sz;
5487
  buf = taosDecodeFixedI32(buf, &sz);
5488
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5489
    return NULL;
5490
  }
5491
  for (int32_t i = 0; i < sz; i++) {
5492
    SMqReportVgInfo vgInfo;
5493
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5494
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5495
      return NULL;
5496
    }
5497
  }
5498
  return buf;
5499
}
5500

5501
typedef struct {
5502
  int32_t status;  // ask hb endpoint
5503
  int32_t epoch;
5504
  int64_t consumerId;
5505
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5506
} SMqReportReq;
5507

5508
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5509
  int32_t tlen = 0;
5510
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5511
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5512
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5513
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5514
  tlen += taosEncodeFixedI32(buf, sz);
5515
  for (int32_t i = 0; i < sz; i++) {
5516
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5517
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5518
  }
5519
  return tlen;
5520
}
5521

5522
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5523
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5524
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5525
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5526
  int32_t sz;
5527
  buf = taosDecodeFixedI32(buf, &sz);
5528
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5529
    return NULL;
5530
  }
5531
  for (int32_t i = 0; i < sz; i++) {
5532
    SMqTopicInfo topicInfo;
5533
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5534
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5535
      return NULL;
5536
    }
5537
  }
5538
  return buf;
5539
}
5540

5541
typedef struct {
5542
  SMsgHead head;
5543
  int64_t  leftForVer;
5544
  int32_t  vgId;
5545
  int64_t  consumerId;
5546
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5547
} SMqVDeleteReq;
5548

5549
typedef struct {
5550
  int8_t reserved;
5551
} SMqVDeleteRsp;
5552

5553
typedef struct {
5554
  char**  name;
5555
  int32_t count;
5556
  int8_t  igNotExists;
5557
} SMDropStreamReq;
5558

5559
typedef struct {
5560
  int8_t reserved;
5561
} SMDropStreamRsp;
5562

5563
typedef struct {
5564
  SMsgHead head;
5565
  int64_t  resetRelHalt;  // reset related stream task halt status
5566
  int64_t  streamId;
5567
  int32_t  taskId;
5568
} SVDropStreamTaskReq;
5569

5570
typedef struct {
5571
  int8_t reserved;
5572
} SVDropStreamTaskRsp;
5573

5574
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5575
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5576
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5577

5578
typedef struct {
5579
  char*  name;
5580
  int8_t igNotExists;
5581
} SMPauseStreamReq;
5582

5583
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5584
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5585
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5586

5587
typedef struct {
5588
  char*  name;
5589
  int8_t igNotExists;
5590
  int8_t igUntreated;
5591
} SMResumeStreamReq;
5592

5593
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5594
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5595
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5596

5597
typedef struct {
5598
  char*       name;
5599
  int8_t      calcAll;
5600
  STimeWindow timeRange;
5601
} SMRecalcStreamReq;
5602

5603
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5604
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5605
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5606

5607
typedef struct SVndSetKeepVersionReq {
5608
  int64_t keepVersion;
5609
} SVndSetKeepVersionReq;
5610

5611
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5612
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5613

5614
typedef struct SVUpdateCheckpointInfoReq {
5615
  SMsgHead head;
5616
  int64_t  streamId;
5617
  int32_t  taskId;
5618
  int64_t  checkpointId;
5619
  int64_t  checkpointVer;
5620
  int64_t  checkpointTs;
5621
  int32_t  transId;
5622
  int64_t  hStreamId;  // add encode/decode
5623
  int64_t  hTaskId;
5624
  int8_t   dropRelHTask;
5625
} SVUpdateCheckpointInfoReq;
5626

5627
typedef struct {
5628
  int64_t        leftForVer;
5629
  int32_t        vgId;
5630
  int64_t        oldConsumerId;
5631
  int64_t        newConsumerId;
5632
  char           subKey[TSDB_SUBSCRIBE_KEY_LEN];
5633
  int8_t         subType;
5634
  int8_t         withMeta;
5635
  char*          qmsg;  // SubPlanToString
5636
  SSchemaWrapper schema;
5637
  int64_t        suid;
5638
} SMqRebVgReq;
5639

5640
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5641
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5642

5643
// tqOffset
5644
enum {
5645
  TMQ_OFFSET__RESET_NONE = -3,
5646
  TMQ_OFFSET__RESET_EARLIEST = -2,
5647
  TMQ_OFFSET__RESET_LATEST = -1,
5648
  TMQ_OFFSET__LOG = 1,
5649
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5650
  TMQ_OFFSET__SNAPSHOT_META = 3,
5651
};
5652

5653
enum {
5654
  ONLY_DATA = 0,
5655
  WITH_META = 1,
5656
  ONLY_META = 2,
5657
};
5658

5659
#define TQ_OFFSET_VERSION 1
5660

5661
typedef struct {
5662
  int8_t type;
5663
  union {
5664
    // snapshot
5665
    struct {
5666
      int64_t uid;
5667
      int64_t ts;
5668
      SValue  primaryKey;
5669
    };
5670
    // log
5671
    struct {
5672
      int64_t version;
5673
    };
5674
  };
5675
} STqOffsetVal;
5676

5677
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5678
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
13,064,912✔
5679
  pOffsetVal->uid = uid;
13,063,540✔
5680
  pOffsetVal->ts = ts;
13,064,198✔
5681
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
13,064,212✔
5682
    taosMemoryFree(pOffsetVal->primaryKey.pData);
333✔
5683
  }
5684
  pOffsetVal->primaryKey = primaryKey;
13,063,562✔
5685
}
13,063,862✔
5686

5687
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5688
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
58,329✔
5689
  pOffsetVal->uid = uid;
58,329✔
5690
}
58,329✔
5691

5692
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5693
  pOffsetVal->type = TMQ_OFFSET__LOG;
314,067,964✔
5694
  pOffsetVal->version = ver;
314,066,225✔
5695
}
314,069,733✔
5696

5697
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5698
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5699
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5700
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5701
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5702
void    tOffsetDestroy(void* pVal);
5703

5704
typedef struct {
5705
  STqOffsetVal val;
5706
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5707
} STqOffset;
5708

5709
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5710
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5711
void    tDeleteSTqOffset(void* val);
5712

5713
typedef struct SMqVgOffset {
5714
  int64_t   consumerId;
5715
  STqOffset offset;
5716
} SMqVgOffset;
5717

5718
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5719
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5720

5721
typedef struct {
5722
  char    name[TSDB_TABLE_FNAME_LEN];
5723
  char    stb[TSDB_TABLE_FNAME_LEN];
5724
  int8_t  igExists;
5725
  int8_t  intervalUnit;
5726
  int8_t  slidingUnit;
5727
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5728
  int32_t dstVgId;   // for stream
5729
  int64_t interval;
5730
  int64_t offset;
5731
  int64_t sliding;
5732
  int64_t maxDelay;
5733
  int64_t watermark;
5734
  int32_t exprLen;        // strlen + 1
5735
  int32_t tagsFilterLen;  // strlen + 1
5736
  int32_t sqlLen;         // strlen + 1
5737
  int32_t astLen;         // strlen + 1
5738
  char*   expr;
5739
  char*   tagsFilter;
5740
  char*   sql;
5741
  char*   ast;
5742
  int64_t deleteMark;
5743
  int64_t lastTs;
5744
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5745
  SArray* pVgroupVerList;
5746
  int8_t  recursiveTsma;
5747
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5748
  char*   createStreamReq;
5749
  int32_t streamReqLen;
5750
  char*   dropStreamReq;
5751
  int32_t dropStreamReqLen;
5752
  int64_t uid;
5753
} SMCreateSmaReq;
5754

5755
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5756
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5757
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5758

5759
typedef struct {
5760
  char    name[TSDB_TABLE_FNAME_LEN];
5761
  int8_t  igNotExists;
5762
  char*   dropStreamReq;
5763
  int32_t dropStreamReqLen;
5764
} SMDropSmaReq;
5765

5766
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5767
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5768
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5769

5770
typedef struct {
5771
  char name[TSDB_TABLE_NAME_LEN];
5772
  union {
5773
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5774
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5775
  };
5776
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5777
  union {
5778
    int8_t igExists;   // used by mnode
5779
    int8_t alterType;  // used by vnode
5780
  };
5781
  int8_t     intervalUnit;
5782
  int16_t    nFuncs;       // number of functions specified by user
5783
  col_id_t*  funcColIds;   // column ids specified by user
5784
  func_id_t* funcIds;      // function ids specified by user
5785
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5786
  int64_t    tbUid;
5787
  int64_t    uid;     // rsma uid
5788
  int32_t    sqlLen;  // strlen + 1
5789
  char*      sql;
5790
} SMCreateRsmaReq;
5791

5792
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5793
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5794
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5795

5796
typedef SMCreateRsmaReq SVCreateRsmaReq;
5797

5798
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5799
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5800
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5801

5802
typedef SMCreateRsmaReq SVAlterRsmaReq;
5803

5804
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5805
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5806
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5807

5808
typedef struct {
5809
  char       name[TSDB_TABLE_NAME_LEN];
5810
  int8_t     alterType;
5811
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5812
  int8_t     igNotExists;
5813
  int16_t    nFuncs;      // number of functions specified by user
5814
  col_id_t*  funcColIds;  // column ids specified by user
5815
  func_id_t* funcIds;     // function ids specified by user
5816
  int32_t    sqlLen;      // strlen + 1
5817
  char*      sql;
5818
} SMAlterRsmaReq;
5819

5820
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5821
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5822
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5823

5824
typedef struct {
5825
  int64_t    id;
5826
  char       name[TSDB_TABLE_NAME_LEN];
5827
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5828
  int64_t    ownerId;
5829
  int32_t    code;
5830
  int32_t    version;
5831
  int8_t     tbType;
5832
  int8_t     intervalUnit;
5833
  col_id_t   nFuncs;
5834
  col_id_t   nColNames;
5835
  int64_t    interval[2];
5836
  col_id_t*  funcColIds;
5837
  func_id_t* funcIds;
5838
  SArray*    colNames;
5839
} SRsmaInfoRsp;
5840

5841
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5842
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5843
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5844

5845
typedef struct {
5846
  char   name[TSDB_TABLE_FNAME_LEN];
5847
  int8_t igNotExists;
5848
} SMDropRsmaReq;
5849

5850
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5851
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5852

5853
typedef struct {
5854
  char    name[TSDB_TABLE_NAME_LEN];
5855
  char    tbName[TSDB_TABLE_NAME_LEN];
5856
  int64_t uid;
5857
  int64_t tbUid;
5858
  int8_t  tbType;
5859
} SVDropRsmaReq;
5860

5861
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5862
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5863

5864
typedef struct {
5865
  char   dbFName[TSDB_DB_FNAME_LEN];
5866
  char   stbName[TSDB_TABLE_NAME_LEN];
5867
  char   colName[TSDB_COL_NAME_LEN];
5868
  char   idxName[TSDB_INDEX_FNAME_LEN];
5869
  int8_t idxType;
5870
} SCreateTagIndexReq;
5871

5872
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5873
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5874

5875
typedef SMDropSmaReq SDropTagIndexReq;
5876

5877
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5878
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5879

5880
typedef struct {
5881
  int8_t         version;       // for compatibility(default 0)
5882
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5883
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5884
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5885
  int32_t        dstVgId;
5886
  char           indexName[TSDB_INDEX_NAME_LEN];
5887
  int32_t        exprLen;
5888
  int32_t        tagsFilterLen;
5889
  int64_t        indexUid;
5890
  tb_uid_t       tableUid;  // super/child/common table uid
5891
  tb_uid_t       dstTbUid;  // for dstVgroup
5892
  int64_t        interval;
5893
  int64_t        offset;  // use unit by precision of DB
5894
  int64_t        sliding;
5895
  char*          dstTbName;  // for dstVgroup
5896
  char*          expr;       // sma expression
5897
  char*          tagsFilter;
5898
  SSchemaWrapper schemaRow;  // for dstVgroup
5899
  SSchemaWrapper schemaTag;  // for dstVgroup
5900
} STSma;                     // Time-range-wise SMA
5901

5902
typedef STSma SVCreateTSmaReq;
5903

5904
typedef struct {
5905
  int8_t  type;  // 0 status report, 1 update data
5906
  int64_t indexUid;
5907
  int64_t skey;  // start TS key of interval/sliding window
5908
} STSmaMsg;
5909

5910
typedef struct {
5911
  int64_t indexUid;
5912
  char    indexName[TSDB_INDEX_NAME_LEN];
5913
} SVDropTSmaReq;
5914

5915
typedef struct {
5916
  int tmp;  // TODO: to avoid compile error
5917
} SVCreateTSmaRsp, SVDropTSmaRsp;
5918

5919
#if 0
5920
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5921
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5922
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5923
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5924
#endif
5925

5926
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5927
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5928
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5929
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5930

5931
typedef struct {
5932
  int32_t number;
5933
  STSma*  tSma;
5934
} STSmaWrapper;
5935

5936
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5937
  if (pSma) {
×
5938
    taosMemoryFreeClear(pSma->dstTbName);
×
5939
    taosMemoryFreeClear(pSma->expr);
×
5940
    taosMemoryFreeClear(pSma->tagsFilter);
×
5941
  }
5942
}
×
5943

5944
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5945
  if (pSW) {
×
5946
    if (pSW->tSma) {
×
5947
      if (deepCopy) {
×
5948
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
5949
          tDestroyTSma(pSW->tSma + i);
×
5950
        }
5951
      }
5952
      taosMemoryFreeClear(pSW->tSma);
×
5953
    }
5954
  }
5955
}
×
5956

5957
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5958
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5959
  taosMemoryFreeClear(pSW);
×
5960
  return NULL;
×
5961
}
5962

5963
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5964
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5965

5966
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5967
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5968

5969
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5970
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5971
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5972
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5973
  }
5974
  return 0;
×
5975
}
5976

5977
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5978
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5979
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5980
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5981
  }
5982
  return 0;
×
5983
}
5984

5985
typedef struct {
5986
  int idx;
5987
} SMCreateFullTextReq;
5988

5989
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5990
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5991
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5992

5993
typedef struct {
5994
  char   name[TSDB_TABLE_FNAME_LEN];
5995
  int8_t igNotExists;
5996
} SMDropFullTextReq;
5997

5998
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5999
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
6000

6001
typedef struct {
6002
  char indexFName[TSDB_INDEX_FNAME_LEN];
6003
} SUserIndexReq;
6004

6005
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
6006
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
6007

6008
typedef struct {
6009
  char dbFName[TSDB_DB_FNAME_LEN];
6010
  char tblFName[TSDB_TABLE_FNAME_LEN];
6011
  char colName[TSDB_COL_NAME_LEN];
6012
  char owner[TSDB_USER_LEN];
6013
  char indexType[TSDB_INDEX_TYPE_LEN];
6014
  char indexExts[TSDB_INDEX_EXTS_LEN];
6015
} SUserIndexRsp;
6016

6017
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
6018
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
6019

6020
typedef struct {
6021
  char tbFName[TSDB_TABLE_FNAME_LEN];
6022
} STableIndexReq;
6023

6024
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
6025
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
6026

6027
typedef struct {
6028
  int8_t  intervalUnit;
6029
  int8_t  slidingUnit;
6030
  int64_t interval;
6031
  int64_t offset;
6032
  int64_t sliding;
6033
  int64_t dstTbUid;
6034
  int32_t dstVgId;
6035
  SEpSet  epSet;
6036
  char*   expr;
6037
} STableIndexInfo;
6038

6039
typedef struct {
6040
  char     tbName[TSDB_TABLE_NAME_LEN];
6041
  char     dbFName[TSDB_DB_FNAME_LEN];
6042
  uint64_t suid;
6043
  int32_t  version;
6044
  int32_t  indexSize;
6045
  SArray*  pIndex;  // STableIndexInfo
6046
} STableIndexRsp;
6047

6048
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
6049
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
6050
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
6051

6052
void tFreeSTableIndexInfo(void* pInfo);
6053

6054
typedef struct {
6055
  int8_t  mqMsgType;
6056
  int32_t code;
6057
  int32_t epoch;
6058
  int64_t consumerId;
6059
  int64_t walsver;
6060
  int64_t walever;
6061
} SMqRspHead;
6062

6063
typedef struct {
6064
  SMsgHead     head;
6065
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
6066
  int8_t       withTbName;
6067
  int8_t       useSnapshot;
6068
  int32_t      epoch;
6069
  uint64_t     reqId;
6070
  int64_t      consumerId;
6071
  int64_t      timeout;
6072
  STqOffsetVal reqOffset;
6073
  int8_t       enableReplay;
6074
  int8_t       sourceExcluded;
6075
  int8_t       rawData;
6076
  int32_t      minPollRows;
6077
  int8_t       enableBatchMeta;
6078
  SHashObj*    uidHash;  // to find if uid is duplicated
6079
} SMqPollReq;
6080

6081
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
6082
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
6083
void    tDestroySMqPollReq(SMqPollReq* pReq);
6084

6085
typedef struct {
6086
  int32_t vgId;
6087
  int64_t offset;
6088
  SEpSet  epSet;
6089
} SMqSubVgEp;
6090

6091
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
6092
  int32_t tlen = 0;
2,317,106✔
6093
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,317,106✔
6094
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,317,106✔
6095
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,317,106✔
6096
  return tlen;
2,317,106✔
6097
}
6098

6099
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
6100
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,140,772✔
6101
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,140,772✔
6102
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,140,772✔
6103
  return buf;
1,140,772✔
6104
}
6105

6106
typedef struct {
6107
  char    topic[TSDB_TOPIC_FNAME_LEN];
6108
  char    db[TSDB_DB_FNAME_LEN];
6109
  SArray* vgs;  // SArray<SMqSubVgEp>
6110
} SMqSubTopicEp;
6111

6112
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
6113
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
6114
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
6115

6116
typedef struct {
6117
  SMqRspHead   head;
6118
  STqOffsetVal rspOffset;
6119
  int16_t      resMsgType;
6120
  int32_t      metaRspLen;
6121
  void*        metaRsp;
6122
} SMqMetaRsp;
6123

6124
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
6125
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
6126
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
6127

6128
#define MQ_DATA_RSP_VERSION 100
6129

6130
typedef struct {
6131
  SMqRspHead   head;
6132
  STqOffsetVal rspOffset;
6133
  STqOffsetVal reqOffset;
6134
  int32_t      blockNum;
6135
  int8_t       withTbName;
6136
  int8_t       withSchema;
6137
  SArray*      blockDataLen;
6138
  SArray*      blockData;
6139
  SArray*      blockTbName;
6140
  SArray*      blockSchema;
6141

6142
  union {
6143
    struct {
6144
      int64_t sleepTime;
6145
    };
6146
    struct {
6147
      int32_t createTableNum;
6148
      SArray* createTableLen;
6149
      SArray* createTableReq;
6150
    };
6151
    struct {
6152
      int32_t len;
6153
      void*   rawData;
6154
    };
6155
  };
6156
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
6157
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
6158
  bool  timeout;
6159
} SMqDataRsp;
6160

6161
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
6162
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6163
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6164
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
6165
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
6166

6167
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
6168
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6169
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
6170

6171
typedef struct SMqBatchMetaRsp {
6172
  SMqRspHead   head;  // not serialize
6173
  STqOffsetVal rspOffset;
6174
  SArray*      batchMetaLen;
6175
  SArray*      batchMetaReq;
6176
  void*        pMetaBuff;    // not serialize
6177
  uint32_t     metaBuffLen;  // not serialize
6178
} SMqBatchMetaRsp;
6179

6180
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
6181
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6182
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6183
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
6184

6185
typedef struct {
6186
  int32_t code;
6187
  SArray* topics;  // SArray<SMqSubTopicEp>
6188
} SMqAskEpRsp;
6189

6190
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6191
  int32_t tlen = 0;
9,510,049✔
6192
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6193
  int32_t sz = taosArrayGetSize(pRsp->topics);
9,510,049✔
6194
  tlen += taosEncodeFixedI32(buf, sz);
9,511,236✔
6195
  for (int32_t i = 0; i < sz; i++) {
11,293,126✔
6196
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,783,048✔
6197
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,783,048✔
6198
  }
6199
  tlen += taosEncodeFixedI32(buf, pRsp->code);
9,510,078✔
6200

6201
  return tlen;
9,510,850✔
6202
}
6203

6204
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6205
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6206
  int32_t sz;
4,125,286✔
6207
  buf = taosDecodeFixedI32(buf, &sz);
4,202,359✔
6208
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
4,202,359✔
6209
  if (pRsp->topics == NULL) {
4,202,359✔
6210
    return NULL;
×
6211
  }
6212
  for (int32_t i = 0; i < sz; i++) {
5,039,189✔
6213
    SMqSubTopicEp topicEp;
824,563✔
6214
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
836,830✔
6215
    if (buf == NULL) {
836,830✔
6216
      return NULL;
×
6217
    }
6218
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,673,660✔
6219
      return NULL;
×
6220
    }
6221
  }
6222
  buf = taosDecodeFixedI32(buf, &pRsp->code);
4,202,359✔
6223

6224
  return buf;
4,202,359✔
6225
}
6226

6227
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6228
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
32,427,395✔
6229
}
32,426,594✔
6230

6231
typedef struct {
6232
  int32_t      vgId;
6233
  STqOffsetVal offset;
6234
  int64_t      rows;
6235
  int64_t      ever;
6236
} OffsetRows;
6237

6238
typedef struct {
6239
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6240
  SArray* offsetRows;
6241
} TopicOffsetRows;
6242

6243
typedef struct {
6244
  int64_t consumerId;
6245
  int32_t epoch;
6246
  SArray* topics;
6247
  int8_t  pollFlag;
6248
} SMqHbReq;
6249

6250
typedef struct {
6251
  char   topic[TSDB_TOPIC_FNAME_LEN];
6252
  int8_t noPrivilege;
6253
} STopicPrivilege;
6254

6255
typedef struct {
6256
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6257
  int32_t debugFlag;
6258
} SMqHbRsp;
6259

6260
#define TD_AUTO_CREATE_TABLE 0x1
6261
typedef struct {
6262
  int64_t       suid;
6263
  int64_t       uid;
6264
  int32_t       sver;
6265
  uint32_t      nData;
6266
  uint8_t*      pData;
6267
  SVCreateTbReq cTbReq;
6268
} SVSubmitBlk;
6269

6270
typedef struct {
6271
  SMsgHead header;
6272
  uint64_t sId;
6273
  uint64_t queryId;
6274
  uint64_t clientId;
6275
  uint64_t taskId;
6276
  uint32_t sqlLen;
6277
  uint32_t phyLen;
6278
  char*    sql;
6279
  char*    msg;
6280
  int8_t   source;
6281
  int8_t   secureDelete;
6282
} SVDeleteReq;
6283

6284
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6285
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6286

6287
typedef struct {
6288
  int64_t affectedRows;
6289
} SVDeleteRsp;
6290

6291
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6292
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6293

6294
typedef struct SDeleteRes {
6295
  uint64_t suid;
6296
  SArray*  uidList;
6297
  int64_t  skey;
6298
  int64_t  ekey;
6299
  int64_t  affectedRows;
6300
  char     tableFName[TSDB_TABLE_NAME_LEN];
6301
  char     tsColName[TSDB_COL_NAME_LEN];
6302
  int64_t  ctimeMs;  // fill by vnode
6303
  int8_t   source;
6304
  int8_t   secureDelete;  // force physical overwrite
6305
} SDeleteRes;
6306

6307
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6308
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6309

6310
typedef struct {
6311
  // int64_t uid;
6312
  char    tbname[TSDB_TABLE_NAME_LEN];
6313
  int64_t startTs;
6314
  int64_t endTs;
6315
} SSingleDeleteReq;
6316

6317
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6318
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6319

6320
typedef struct {
6321
  int64_t suid;
6322
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6323
  int64_t ctimeMs;     // fill by vnode
6324
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6325
} SBatchDeleteReq;
6326

6327
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6328
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6329
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6330

6331
typedef struct {
6332
  int32_t msgIdx;
6333
  int32_t msgType;
6334
  int32_t msgLen;
6335
  void*   msg;
6336
} SBatchMsg;
6337

6338
typedef struct {
6339
  SMsgHead header;
6340
  SArray*  pMsgs;  // SArray<SBatchMsg>
6341
} SBatchReq;
6342

6343
typedef struct {
6344
  int32_t reqType;
6345
  int32_t msgIdx;
6346
  int32_t msgLen;
6347
  int32_t rspCode;
6348
  void*   msg;
6349
} SBatchRspMsg;
6350

6351
typedef struct {
6352
  SArray* pRsps;  // SArray<SBatchRspMsg>
6353
} SBatchRsp;
6354

6355
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6356
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6357
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
108,785,330✔
6358
  if (NULL == msg) {
108,785,330✔
6359
    return;
×
6360
  }
6361
  SBatchMsg* pMsg = (SBatchMsg*)msg;
108,785,330✔
6362
  taosMemoryFree(pMsg->msg);
108,785,330✔
6363
}
6364

6365
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6366
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6367

6368
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
149,762,666✔
6369
  if (NULL == p) {
149,762,666✔
6370
    return;
×
6371
  }
6372

6373
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
149,762,666✔
6374
  taosMemoryFree(pRsp->msg);
149,762,666✔
6375
}
6376

6377
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6378
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6379
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6380
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6381
void    tDestroySMqHbReq(SMqHbReq* pReq);
6382

6383
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6384
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6385
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6386

6387
#define TD_REQ_FROM_APP               0x0
6388
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6389
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6390
#define SUBMIT_REQ_FROM_FILE          0x4
6391
#define TD_REQ_FROM_TAOX              0x8
6392
#define TD_REQ_FROM_SML               0x10
6393
#define SUBMIT_REQUEST_VERSION        (2)
6394
#define SUBMIT_REQ_WITH_BLOB          0x10
6395
#define SUBMIT_REQ_SCHEMA_RES         0x20
6396
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6397

6398
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6399

6400
typedef struct {
6401
  int32_t        flags;
6402
  SVCreateTbReq* pCreateTbReq;
6403
  int64_t        suid;
6404
  int64_t        uid;
6405
  int32_t        sver;
6406
  union {
6407
    SArray* aRowP;
6408
    SArray* aCol;
6409
  };
6410
  int64_t   ctimeMs;
6411
  SBlobSet* pBlobSet;
6412
} SSubmitTbData;
6413

6414
typedef struct {
6415
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6416
  SArray* aSubmitBlobData;
6417
  bool    raw;
6418
} SSubmitReq2;
6419

6420
typedef struct {
6421
  SMsgHead header;
6422
  int64_t  version;
6423
  char     data[];  // SSubmitReq2
6424
} SSubmitReq2Msg;
6425

6426
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6427
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6428
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6429
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6430
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6431

6432
typedef struct {
6433
  int32_t affectedRows;
6434
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6435
} SSubmitRsp2;
6436

6437
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6438
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6439
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6440

6441
#define TSDB_MSG_FLG_ENCODE 0x1
6442
#define TSDB_MSG_FLG_DECODE 0x2
6443
#define TSDB_MSG_FLG_CMPT   0x3
6444

6445
typedef struct {
6446
  union {
6447
    struct {
6448
      void*   msgStr;
6449
      int32_t msgLen;
6450
      int64_t ver;
6451
    };
6452
    void* pDataBlock;
6453
  };
6454
} SPackedData;
6455

6456
typedef struct {
6457
  char     fullname[TSDB_VIEW_FNAME_LEN];
6458
  char     name[TSDB_VIEW_NAME_LEN];
6459
  char     dbFName[TSDB_DB_FNAME_LEN];
6460
  char*    querySql;
6461
  char*    sql;
6462
  int8_t   orReplace;
6463
  int8_t   precision;
6464
  int32_t  numOfCols;
6465
  SSchema* pSchema;
6466
} SCMCreateViewReq;
6467

6468
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6469
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6470
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6471

6472
typedef struct {
6473
  char   fullname[TSDB_VIEW_FNAME_LEN];
6474
  char   name[TSDB_VIEW_NAME_LEN];
6475
  char   dbFName[TSDB_DB_FNAME_LEN];
6476
  char*  sql;
6477
  int8_t igNotExists;
6478
} SCMDropViewReq;
6479

6480
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6481
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6482
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6483

6484
typedef struct {
6485
  char fullname[TSDB_VIEW_FNAME_LEN];
6486
} SViewMetaReq;
6487
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6488
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6489

6490
typedef struct {
6491
  char     name[TSDB_VIEW_NAME_LEN];
6492
  char     dbFName[TSDB_DB_FNAME_LEN];
6493
  char*    createUser;
6494
  int64_t  ownerId;
6495
  uint64_t dbId;
6496
  uint64_t viewId;
6497
  char*    querySql;
6498
  int8_t   precision;
6499
  int8_t   type;
6500
  int32_t  version;
6501
  int32_t  numOfCols;
6502
  SSchema* pSchema;
6503
} SViewMetaRsp;
6504
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6505
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6506
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6507
typedef struct {
6508
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6509
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6510
} STableTSMAInfoReq;
6511

6512
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6513
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6514

6515
typedef struct {
6516
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6517
  union {
6518
    uint8_t flags;
6519
    struct {
6520
      uint8_t withColName : 1;
6521
      uint8_t reserved : 7;
6522
    };
6523
  };
6524

6525
} SRsmaInfoReq;
6526

6527
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6528
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6529

6530
typedef struct {
6531
  int32_t  funcId;
6532
  col_id_t colId;
6533
} STableTSMAFuncInfo;
6534

6535
typedef struct {
6536
  char     name[TSDB_TABLE_NAME_LEN];
6537
  uint64_t tsmaId;
6538
  char     targetTb[TSDB_TABLE_NAME_LEN];
6539
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6540
  char     tb[TSDB_TABLE_NAME_LEN];
6541
  char     dbFName[TSDB_DB_FNAME_LEN];
6542
  uint64_t suid;
6543
  uint64_t destTbUid;
6544
  uint64_t dbId;
6545
  int32_t  version;
6546
  int64_t  interval;
6547
  int8_t   unit;
6548
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6549
  SArray*  pTags;      // SArray<SSchema>
6550
  SArray*  pUsedCols;  // SArray<SSchema>
6551
  char*    ast;
6552

6553
  int64_t streamUid;
6554
  int64_t reqTs;
6555
  int64_t rspTs;
6556
  int64_t delayDuration;  // ms
6557
  bool    fillHistoryFinished;
6558

6559
  void* streamAddr;  // for stream task, the address of the stream task
6560
} STableTSMAInfo;
6561

6562
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6563
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6564
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6565
void    tFreeTableTSMAInfo(void* p);
6566
void    tFreeAndClearTableTSMAInfo(void* p);
6567
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6568

6569
#define STSMAHbRsp            STableTSMAInfoRsp
6570
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6571
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6572
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6573

6574
typedef struct SDropCtbWithTsmaSingleVgReq {
6575
  SVgroupInfo vgInfo;
6576
  SArray*     pTbs;  // SVDropTbReq
6577
} SMDropTbReqsOnSingleVg;
6578

6579
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6580
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6581
void    tFreeSMDropTbReqOnSingleVg(void* p);
6582

6583
typedef struct SDropTbsReq {
6584
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6585
} SMDropTbsReq;
6586

6587
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6588
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6589
void    tFreeSMDropTbsReq(void*);
6590

6591
typedef struct SVFetchTtlExpiredTbsRsp {
6592
  SArray* pExpiredTbs;  // SVDropTbReq
6593
  int32_t vgId;
6594
} SVFetchTtlExpiredTbsRsp;
6595

6596
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6597
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6598

6599
void tFreeFetchTtlExpiredTbsRsp(void* p);
6600

6601
void setDefaultOptionsForField(SFieldWithOptions* field);
6602
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6603

6604
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6605
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6606

6607
typedef struct {
6608
  char    id[TSDB_INSTANCE_ID_LEN];
6609
  char    type[TSDB_INSTANCE_TYPE_LEN];
6610
  char    desc[TSDB_INSTANCE_DESC_LEN];
6611
  int32_t expire;
6612
} SInstanceRegisterReq;
6613

6614
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6615
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6616

6617
typedef struct {
6618
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6619
} SInstanceListReq;
6620

6621
typedef struct {
6622
  int32_t count;
6623
  char**  ids;  // Array of instance IDs
6624
} SInstanceListRsp;
6625

6626
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6627
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6628
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6629
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6630

6631
#ifdef USE_MOUNT
6632
typedef struct {
6633
  char     mountName[TSDB_MOUNT_NAME_LEN];
6634
  int8_t   ignoreExist;
6635
  int16_t  nMounts;
6636
  int32_t* dnodeIds;
6637
  char**   mountPaths;
6638
  int32_t  sqlLen;
6639
  char*    sql;
6640
} SCreateMountReq;
6641

6642
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6643
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6644
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6645

6646
typedef struct {
6647
  char    mountName[TSDB_MOUNT_NAME_LEN];
6648
  int8_t  ignoreNotExists;
6649
  int32_t sqlLen;
6650
  char*   sql;
6651
} SDropMountReq;
6652

6653
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6654
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6655
void    tFreeSDropMountReq(SDropMountReq* pReq);
6656

6657
typedef struct {
6658
  char     mountName[TSDB_MOUNT_NAME_LEN];
6659
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6660
  int64_t  mountUid;
6661
  int32_t  dnodeId;
6662
  uint32_t valLen;
6663
  int8_t   ignoreExist;
6664
  void*    pVal;
6665
} SRetrieveMountPathReq;
6666

6667
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6668
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6669

6670
typedef struct {
6671
  // path
6672
  int32_t diskPrimary;
6673
  // vgInfo
6674
  int32_t  vgId;
6675
  int32_t  cacheLastSize;
6676
  int32_t  szPage;
6677
  int32_t  szCache;
6678
  uint64_t szBuf;
6679
  int8_t   cacheLast;
6680
  int8_t   standby;
6681
  int8_t   hashMethod;
6682
  uint32_t hashBegin;
6683
  uint32_t hashEnd;
6684
  int16_t  hashPrefix;
6685
  int16_t  hashSuffix;
6686
  int16_t  sttTrigger;
6687
  // syncInfo
6688
  int32_t replications;
6689
  // tsdbInfo
6690
  int8_t  precision;
6691
  int8_t  compression;
6692
  int8_t  slLevel;
6693
  int32_t daysPerFile;
6694
  int32_t keep0;
6695
  int32_t keep1;
6696
  int32_t keep2;
6697
  int32_t keepTimeOffset;
6698
  int32_t minRows;
6699
  int32_t maxRows;
6700
  int32_t tsdbPageSize;
6701
  int32_t ssChunkSize;
6702
  int32_t ssKeepLocal;
6703
  int8_t  ssCompact;
6704
  union {
6705
    uint8_t flags;
6706
    struct {
6707
      uint8_t isAudit : 1;
6708
      uint8_t allowDrop : 1;
6709
      uint8_t securityLevel : 3;
6710
      uint8_t reserved : 3;
6711
    };
6712
  };
6713
  int8_t secureDelete;
6714
  // walInfo
6715
  int32_t walFsyncPeriod;      // millisecond
6716
  int32_t walRetentionPeriod;  // secs
6717
  int32_t walRollPeriod;       // secs
6718
  int64_t walRetentionSize;
6719
  int64_t walSegSize;
6720
  int32_t walLevel;
6721
  // encryptInfo
6722
  int32_t encryptAlgorithm;
6723
  // SVState
6724
  int64_t committed;
6725
  int64_t commitID;
6726
  int64_t commitTerm;
6727
  // stats
6728
  int64_t numOfSTables;
6729
  int64_t numOfCTables;
6730
  int64_t numOfNTables;
6731
  // dbInfo
6732
  uint64_t dbId;
6733
} SMountVgInfo;
6734

6735
typedef struct {
6736
  SMCreateStbReq req;
6737
  SArray*        pColExts;  // element: column id
6738
  SArray*        pTagExts;  // element: tag id
6739
} SMountStbInfo;
6740

6741
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6742
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6743

6744
typedef struct {
6745
  char     dbName[TSDB_DB_FNAME_LEN];
6746
  uint64_t dbId;
6747
  SArray*  pVgs;   // SMountVgInfo
6748
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6749
} SMountDbInfo;
6750

6751
typedef struct {
6752
  // common fields
6753
  char     mountName[TSDB_MOUNT_NAME_LEN];
6754
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6755
  int8_t   ignoreExist;
6756
  int64_t  mountUid;
6757
  int64_t  clusterId;
6758
  int32_t  dnodeId;
6759
  uint32_t valLen;
6760
  void*    pVal;
6761

6762
  // response fields
6763
  SArray* pDbs;  // SMountDbInfo
6764

6765
  // memory fields, no serialized
6766
  SArray*   pDisks[TFS_MAX_TIERS];
6767
  TdFilePtr pFile;
6768
} SMountInfo;
6769

6770
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6771
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6772
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6773

6774
typedef struct {
6775
  SCreateVnodeReq createReq;
6776
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6777
  char            mountName[TSDB_MOUNT_NAME_LEN];
6778
  int64_t         mountId;
6779
  int32_t         diskPrimary;
6780
  int32_t         mountVgId;
6781
  int64_t         committed;
6782
  int64_t         commitID;
6783
  int64_t         commitTerm;
6784
  int64_t         numOfSTables;
6785
  int64_t         numOfCTables;
6786
  int64_t         numOfNTables;
6787
} SMountVnodeReq;
6788

6789
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6790
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6791
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6792

6793
#endif  // USE_MOUNT
6794

6795
#pragma pack(pop)
6796

6797
typedef struct {
6798
  char        db[TSDB_DB_FNAME_LEN];
6799
  STimeWindow timeRange;
6800
  int32_t     sqlLen;
6801
  char*       sql;
6802
  SArray*     vgroupIds;
6803
} SScanDbReq;
6804

6805
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6806
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6807
void    tFreeSScanDbReq(SScanDbReq* pReq);
6808

6809
typedef struct {
6810
  int32_t scanId;
6811
  int8_t  bAccepted;
6812
} SScanDbRsp;
6813

6814
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6815
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6816

6817
typedef struct {
6818
  int32_t scanId;
6819
  int32_t sqlLen;
6820
  char*   sql;
6821
} SKillScanReq;
6822

6823
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6824
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6825
void    tFreeSKillScanReq(SKillScanReq* pReq);
6826

6827
typedef struct {
6828
  int32_t scanId;
6829
  int32_t vgId;
6830
  int32_t dnodeId;
6831
} SVKillScanReq;
6832

6833
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6834
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6835

6836
typedef struct {
6837
  int32_t scanId;
6838
  int32_t vgId;
6839
  int32_t dnodeId;
6840
  int32_t numberFileset;
6841
  int32_t finished;
6842
  int32_t progress;
6843
  int64_t remainingTime;
6844
} SQueryScanProgressRsp;
6845

6846
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6847
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6848

6849
typedef struct {
6850
  int32_t scanId;
6851
  int32_t vgId;
6852
  int32_t dnodeId;
6853
} SQueryScanProgressReq;
6854

6855
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6856
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6857

6858
typedef struct {
6859
  int64_t     dbUid;
6860
  char        db[TSDB_DB_FNAME_LEN];
6861
  int64_t     scanStartTime;
6862
  STimeWindow tw;
6863
  int32_t     scanId;
6864
} SScanVnodeReq;
6865

6866
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6867
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6868

6869
#ifdef __cplusplus
6870
}
6871
#endif
6872

6873
#endif /*_TD_COMMON_TAOS_MSG_H_*/
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