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

taosdata / TDengine / #4949

05 Feb 2026 06:58AM UTC coverage: 66.973% (+0.1%) from 66.866%
#4949

push

travis-ci

web-flow
enh: [6690002267] Enh virtual super table scan. (#34481)

50 of 59 new or added lines in 3 files covered. (84.75%)

3548 existing lines in 127 files now uncovered.

205730 of 307182 relevant lines covered (66.97%)

125825389.62 hits per line

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

84.4
/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
  }
106
  return false;
617✔
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
992,384,002✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
948,678,761✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,941,062,763✔
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_MAX,
219
} EShowType;
220

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

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

232
#define TSDB_ALTER_TABLE_ADD_TAG                         1
233
#define TSDB_ALTER_TABLE_DROP_TAG                        2
234
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
235
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4
236
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
237
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
238
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
239
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
240
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
241
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
242
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
243
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
244
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
245
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
246
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15
247
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
248
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
249
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
250

251
#define TSDB_FILL_NONE        0
252
#define TSDB_FILL_NULL        1
253
#define TSDB_FILL_NULL_F      2
254
#define TSDB_FILL_SET_VALUE   3
255
#define TSDB_FILL_SET_VALUE_F 4
256
#define TSDB_FILL_LINEAR      5
257
#define TSDB_FILL_PREV        6
258
#define TSDB_FILL_NEXT        7
259
#define TSDB_FILL_NEAR        8
260

261

262
#define TSDB_ALTER_USER_BASIC_INFO             1
263
// these definitions start from 5 is to keep compatible with old versions
264
#define TSDB_ALTER_USER_ADD_PRIVILEGES         5
265
#define TSDB_ALTER_USER_DEL_PRIVILEGES         6
266

267

268
#define TSDB_ALTER_ROLE_LOCK            0x1
269
#define TSDB_ALTER_ROLE_ROLE            0x2
270
#define TSDB_ALTER_ROLE_PRIVILEGES      0x3
271
#define TSDB_ALTER_ROLE_MAX             0x4 // increase according to actual use
272

273
#define TSDB_ALTER_RSMA_FUNCTION        0x1
274

275
#define TSDB_KILL_MSG_LEN 30
276

277
#define TSDB_TABLE_NUM_UNIT 100000
278

279
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
280
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
281
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
282

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

289
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
290
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
291
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
292
#define TSDB_COL_REQ_NULL(f)      (((f) & TSDB_COL_NULL) != 0)
293

294
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
295
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
296
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
297
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
298
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
299

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

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

445

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

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

564
  // logic plan node
565
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
566
  QUERY_NODE_LOGIC_PLAN_JOIN,
567
  QUERY_NODE_LOGIC_PLAN_AGG,
568
  QUERY_NODE_LOGIC_PLAN_PROJECT,
569
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
570
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
571
  QUERY_NODE_LOGIC_PLAN_MERGE,
572
  QUERY_NODE_LOGIC_PLAN_WINDOW,
573
  QUERY_NODE_LOGIC_PLAN_FILL,
574
  QUERY_NODE_LOGIC_PLAN_SORT,
575
  QUERY_NODE_LOGIC_PLAN_PARTITION,
576
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
577
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
578
  QUERY_NODE_LOGIC_SUBPLAN,
579
  QUERY_NODE_LOGIC_PLAN,
580
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
581
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
582
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
583
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
584
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
585

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

678
typedef struct {
679
  int32_t     vgId;
680
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
681
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
682
  const char* dbFName;
683
  const char* tbName;
684
} SBuildTableInput;
685

686
typedef struct {
687
  char    db[TSDB_DB_FNAME_LEN];
688
  int64_t dbId;
689
  int32_t vgVersion;
690
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
691
  int64_t stateTs;
692
} SBuildUseDBInput;
693

694
typedef struct SField {
695
  char    name[TSDB_COL_NAME_LEN];
696
  uint8_t type;
697
  int8_t  flags;
698
  int32_t bytes;
699
} SField;
700

701
typedef struct SFieldWithOptions {
702
  char     name[TSDB_COL_NAME_LEN];
703
  uint8_t  type;
704
  int8_t   flags;
705
  int32_t  bytes;
706
  uint32_t compress;
707
  STypeMod typeMod;
708
} SFieldWithOptions;
709

710
typedef struct SRetention {
711
  int64_t freq;
712
  int64_t keep;
713
  int8_t  freqUnit;
714
  int8_t  keepUnit;
715
} SRetention;
716

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

719
#pragma pack(push, 1)
720
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
721
typedef struct SEp {
722
  char     fqdn[TSDB_FQDN_LEN];
723
  uint16_t port;
724
} SEp;
725

726
typedef struct {
727
  int32_t contLen;
728
  int32_t vgId;
729
} SMsgHead;
730

731
// Submit message for one table
732
typedef struct SSubmitBlk {
733
  int64_t uid;        // table unique id
734
  int64_t suid;       // stable id
735
  int32_t sversion;   // data schema version
736
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
737
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
738
  int32_t numOfRows;  // total number of rows in current submit block
739
  char    data[];
740
} SSubmitBlk;
741

742
// Submit message for this TSDB
743
typedef struct {
744
  SMsgHead header;
745
  int64_t  version;
746
  int32_t  length;
747
  int32_t  numOfBlocks;
748
  char     blocks[];
749
} SSubmitReq;
750

751
typedef struct {
752
  int32_t totalLen;
753
  int32_t len;
754
  STSRow* row;
755
} SSubmitBlkIter;
756

757
typedef struct {
758
  int32_t totalLen;
759
  int32_t len;
760
  // head of SSubmitBlk
761
  int64_t uid;        // table unique id
762
  int64_t suid;       // stable id
763
  int32_t sversion;   // data schema version
764
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
765
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
766
  int32_t numOfRows;  // total number of rows in current submit block
767
  // head of SSubmitBlk
768
  int32_t     numOfBlocks;
769
  const void* pMsg;
770
} SSubmitMsgIter;
771

772
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
773
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
774
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
775
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
776
// for debug
777
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
778

779
typedef struct {
780
  bool     hasRef;
781
  col_id_t id;
782
  char     refDbName[TSDB_DB_NAME_LEN];
783
  char     refTableName[TSDB_TABLE_NAME_LEN];
784
  char     refColName[TSDB_COL_NAME_LEN];
785
} SColRef;
786

787
typedef struct {
788
  int32_t  nCols;
789
  int32_t  version;
790
  SColRef* pColRef;
791
} SColRefWrapper;
792

793
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
794
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
795
typedef struct {
796
  int32_t vgId;
797
  SColRef colRef;
798
} SColRefEx;
799

800
typedef struct {
801
  int16_t colId;
802
  char    refDbName[TSDB_DB_NAME_LEN];
803
  char    refTableName[TSDB_TABLE_NAME_LEN];
804
  char    refColName[TSDB_COL_NAME_LEN];
805
} SRefColInfo;
806

807
typedef struct SVCTableRefCols {
808
  uint64_t     uid;
809
  int32_t      numOfSrcTbls;
810
  int32_t      numOfColRefs;
811
  SRefColInfo* refCols;
812
} SVCTableRefCols;
813

814
typedef struct SVCTableMergeInfo {
815
  uint64_t uid;
816
  int32_t  numOfSrcTbls;
817
} SVCTableMergeInfo;
818

819
typedef struct {
820
  int32_t    nCols;
821
  SColRefEx* pColRefEx;
822
} SColRefExWrapper;
823

824
struct SSchema {
825
  int8_t   type;
826
  int8_t   flags;
827
  col_id_t colId;
828
  int32_t  bytes;
829
  char     name[TSDB_COL_NAME_LEN];
830
};
831
struct SSchemaExt {
832
  col_id_t colId;
833
  uint32_t compress;
834
  STypeMod typeMod;
835
};
836

837
struct SSchemaRsma {
838
  int64_t    interval[2];
839
  int32_t    nFuncs;
840
  int8_t     tbType;
841
  tb_uid_t   tbUid;
842
  func_id_t* funcIds;
843
  char       tbName[TSDB_TABLE_NAME_LEN];
844
};
845

846
struct SSchema2 {
847
  int8_t   type;
848
  int8_t   flags;
849
  col_id_t colId;
850
  int32_t  bytes;
851
  char     name[TSDB_COL_NAME_LEN];
852
  uint32_t compress;
853
};
854

855
typedef struct {
856
  char        tbName[TSDB_TABLE_NAME_LEN];
857
  char        stbName[TSDB_TABLE_NAME_LEN];
858
  char        dbFName[TSDB_DB_FNAME_LEN];
859
  int64_t     dbId;
860
  int32_t     numOfTags;
861
  int32_t     numOfColumns;
862
  int8_t      precision;
863
  int8_t      tableType;
864
  int32_t     sversion;
865
  int32_t     tversion;
866
  int32_t     rversion;
867
  uint64_t    suid;
868
  uint64_t    tuid;
869
  int32_t     vgId;
870
  union {
871
    uint8_t flag;
872
    struct {
873
      uint8_t sysInfo : 1;
874
      uint8_t isAudit : 1;
875
      uint8_t privCat : 3;  // ESysTblPrivCat
876
      uint8_t reserved : 3;
877
    };
878
  };
879
  int64_t     ownerId;
880
  SSchema*    pSchemas;
881
  SSchemaExt* pSchemaExt;
882
  int8_t      virtualStb;
883
  int32_t     numOfColRefs;
884
  SColRef*    pColRefs;
885
} STableMetaRsp;
886

887
typedef struct {
888
  int32_t        code;
889
  int64_t        uid;
890
  char*          tblFName;
891
  int32_t        numOfRows;
892
  int32_t        affectedRows;
893
  int64_t        sver;
894
  STableMetaRsp* pMeta;
895
} SSubmitBlkRsp;
896

897
typedef struct {
898
  int32_t numOfRows;
899
  int32_t affectedRows;
900
  int32_t nBlocks;
901
  union {
902
    SArray*        pArray;
903
    SSubmitBlkRsp* pBlocks;
904
  };
905
} SSubmitRsp;
906

907
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
908
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
909
// void    tFreeSSubmitBlkRsp(void* param);
910
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
911

912
#define COL_SMA_ON       ((int8_t)0x1)
913
#define COL_IDX_ON       ((int8_t)0x2)
914
#define COL_IS_KEY       ((int8_t)0x4)
915
#define COL_SET_NULL     ((int8_t)0x10)
916
#define COL_SET_VAL      ((int8_t)0x20)
917
#define COL_IS_SYSINFO   ((int8_t)0x40)
918
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
919
#define COL_REF_BY_STM   ((int8_t)0x08)
920

921
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
922
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
923

924
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
925
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
926
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
927

928
#define SSCHMEA_SET_IDX_ON(s) \
929
  do {                        \
930
    (s)->flags |= COL_IDX_ON; \
931
  } while (0)
932

933
#define SSCHMEA_SET_IDX_OFF(s)   \
934
  do {                           \
935
    (s)->flags &= (~COL_IDX_ON); \
936
  } while (0)
937

938
#define SSCHEMA_SET_TYPE_MOD(s)     \
939
  do {                              \
940
    (s)->flags |= COL_HAS_TYPE_MOD; \
941
  } while (0)
942

943
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
944

945
#define SSCHMEA_TYPE(s)  ((s)->type)
946
#define SSCHMEA_FLAGS(s) ((s)->flags)
947
#define SSCHMEA_COLID(s) ((s)->colId)
948
#define SSCHMEA_BYTES(s) ((s)->bytes)
949
#define SSCHMEA_NAME(s)  ((s)->name)
950

951
typedef struct {
952
  bool    tsEnableMonitor;
953
  int32_t tsMonitorInterval;
954
  int32_t tsSlowLogThreshold;
955
  int32_t tsSlowLogMaxLen;
956
  int32_t tsSlowLogScope;
957
  int32_t tsSlowLogThresholdTest;  // Obsolete
958
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
959
} SMonitorParas;
960

961
typedef struct {
962
  STypeMod typeMod;
963
} SExtSchema;
964

965
bool hasExtSchema(const SExtSchema* pExtSchema);
966

967
typedef struct {
968
  int32_t      nCols;
969
  int32_t      version;
970
  SSchema*     pSchema;
971
  SSchemaRsma* pRsma;
972
} SSchemaWrapper;
973

974
typedef struct {
975
  col_id_t id;
976
  uint32_t alg;
977
} SColCmpr;
978

979
typedef struct {
980
  int32_t   nCols;
981
  int32_t   version;
982
  SColCmpr* pColCmpr;
983
} SColCmprWrapper;
984

985
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
986
  if (pRef->pColRef) {
351,609✔
UNCOV
987
    return TSDB_CODE_INVALID_PARA;
×
988
  }
989
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
351,609✔
990
  if (pRef->pColRef == NULL) {
351,609✔
UNCOV
991
    return terrno;
×
992
  }
993
  pRef->nCols = nCols;
351,609✔
994
  for (int32_t i = 0; i < nCols; i++) {
145,026,205✔
995
    pRef->pColRef[i].hasRef = false;
144,674,596✔
996
    pRef->pColRef[i].id = (col_id_t)(i + 1);
144,674,596✔
997
  }
998
  return 0;
351,609✔
999
}
1000

1001
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
1002
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1003
    terrno = TSDB_CODE_INVALID_PARA;
1004
    return NULL;
1005
  }
1006

1007
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1008
  if (pDstWrapper == NULL) {
1009
    return NULL;
1010
  }
1011
  pDstWrapper->nCols = pSrcWrapper->nCols;
1012
  pDstWrapper->version = pSrcWrapper->version;
1013

1014
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1015
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1016
  if (pDstWrapper->pColCmpr == NULL) {
1017
    taosMemoryFree(pDstWrapper);
1018
    return NULL;
1019
  }
1020
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1021

1022
  return pDstWrapper;
1023
}
1024

1025
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1026
  if (!(!pCmpr->pColCmpr)) {
6,515,026✔
UNCOV
1027
    return TSDB_CODE_INVALID_PARA;
×
1028
  }
1029
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
6,515,026✔
1030
  if (pCmpr->pColCmpr == NULL) {
6,515,026✔
UNCOV
1031
    return terrno;
×
1032
  }
1033
  pCmpr->nCols = nCols;
6,515,026✔
1034
  return 0;
6,515,026✔
1035
}
1036

1037
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
1038
  pCmpr->nCols = pSchema->nCols;
1039
  if (!(!pCmpr->pColCmpr)) {
1040
    return TSDB_CODE_INVALID_PARA;
1041
  }
1042
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
1043
  if (pCmpr->pColCmpr == NULL) {
1044
    return terrno;
1045
  }
1046
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1047
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
1048
    SSchema*  pColSchema = &pSchema->pSchema[i];
1049
    pColCmpr->id = pColSchema->colId;
1050
    pColCmpr->alg = 0;
1051
  }
1052
  return 0;
1053
}
1054

1055
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1056
  if (pWrapper == NULL) return;
1057

1058
  taosMemoryFreeClear(pWrapper->pColCmpr);
1059
  taosMemoryFreeClear(pWrapper);
1060
}
1061
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1062
  if (pSchemaWrapper->pSchema == NULL) return NULL;
581,179,962✔
1063

1064
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
581,076,154✔
1065
  if (pSW == NULL) {
581,102,420✔
UNCOV
1066
    return NULL;
×
1067
  }
1068
  pSW->nCols = pSchemaWrapper->nCols;
581,102,420✔
1069
  pSW->version = pSchemaWrapper->version;
581,153,788✔
1070
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
581,219,067✔
1071
  if (pSW->pSchema == NULL) {
581,002,338✔
1072
    taosMemoryFree(pSW);
×
UNCOV
1073
    return NULL;
×
1074
  }
1075

1076
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
581,013,240✔
1077
  return pSW;
581,276,289✔
1078
}
1079

1080
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
307,724,755✔
1081
  if (pSchemaWrapper) {
1,654,786,975✔
1082
    taosMemoryFree(pSchemaWrapper->pSchema);
937,081,935✔
1083
    if (pSchemaWrapper->pRsma) {
936,995,058✔
1084
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
25,848✔
1085
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
25,848✔
1086
    }
1087
    taosMemoryFree(pSchemaWrapper);
936,992,195✔
1088
  }
1089
}
1,613,074,994✔
1090

1091
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1092
  if (pSchemaWrapper) {
1093
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1094
    if (pSchemaWrapper->pRsma) {
1095
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1096
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1097
    }
1098
  }
1099
}
1100

1101
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
7,196,138✔
1102
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,196,138✔
1103
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,197,012✔
1104
  }
1105
}
7,196,278✔
1106

1107
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1108
  int32_t tlen = 0;
2,560,580✔
1109
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,561,828✔
1110
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,560,580✔
1111
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,560,580✔
1112
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,560,580✔
1113
  tlen += taosEncodeString(buf, pSchema->name);
2,560,580✔
1114
  return tlen;
2,560,580✔
1115
}
1116

1117
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1118
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,163,258✔
1119
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,162,946✔
1120
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,162,946✔
1121
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,162,946✔
1122
  buf = taosDecodeStringTo(buf, pSchema->name);
1,162,946✔
1123
  return (void*)buf;
1,162,946✔
1124
}
1125

1126
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1127
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1128
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1129
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1130
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1131
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1132
  return 0;
2,147,483,647✔
1133
}
1134

1135
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1136
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1137
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1138
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1139
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1140
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1141
  return 0;
2,147,483,647✔
1142
}
1143

1144
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1145
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1146
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1147
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1148
  return 0;
2,147,483,647✔
1149
}
1150

1151
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1152
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1153
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1154
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1155
  return 0;
2,147,483,647✔
1156
}
1157

1158
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1159
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
875,932,892✔
1160
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
875,932,892✔
1161
  if (pColRef->hasRef) {
437,966,446✔
1162
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
581,496,352✔
1163
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
581,496,352✔
1164
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
581,496,352✔
1165
  }
1166
  return 0;
437,966,446✔
1167
}
1168

1169
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1170
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
438,297,170✔
1171
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
438,297,170✔
1172
  if (pColRef->hasRef) {
219,148,585✔
1173
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
145,518,022✔
1174
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
145,518,022✔
1175
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
145,518,022✔
1176
  }
1177

1178
  return 0;
219,148,585✔
1179
}
1180

1181
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1182
  int32_t tlen = 0;
422,086✔
1183
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
422,086✔
1184
  tlen += taosEncodeVariantI32(buf, pSW->version);
422,086✔
1185
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,982,666✔
1186
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,121,160✔
1187
  }
1188
  return tlen;
422,086✔
1189
}
1190

1191
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1192
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
184,916✔
1193
  buf = taosDecodeVariantI32(buf, &pSW->version);
184,916✔
1194
  if (pSW->nCols > 0) {
184,916✔
1195
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
184,916✔
1196
    if (pSW->pSchema == NULL) {
184,916✔
UNCOV
1197
      return NULL;
×
1198
    }
1199

1200
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,347,862✔
1201
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,325,892✔
1202
    }
1203
  } else {
UNCOV
1204
    pSW->pSchema = NULL;
×
1205
  }
1206
  return (void*)buf;
184,916✔
1207
}
1208

1209
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1210
  if (pSW == NULL) {
464,100,163✔
UNCOV
1211
    return TSDB_CODE_INVALID_PARA;
×
1212
  }
1213
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
928,164,628✔
1214
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
928,113,010✔
1215
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1216
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1217
  }
1218
  return 0;
464,249,585✔
1219
}
1220

1221
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1222
  if (pSW == NULL) {
184,911,103✔
UNCOV
1223
    return TSDB_CODE_INVALID_PARA;
×
1224
  }
1225
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
369,744,923✔
1226
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
369,735,516✔
1227

1228
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
184,901,696✔
1229
  if (pSW->pSchema == NULL) {
184,854,981✔
UNCOV
1230
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1231
  }
1232
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,698,698,189✔
1233
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1234
  }
1235

1236
  return 0;
184,938,831✔
1237
}
1238

1239
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1240
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1241
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1242

1243
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1244
  if (pSW->pSchema == NULL) {
1,703,589,884✔
UNCOV
1245
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1246
  }
1247
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1248
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1249
  }
1250

1251
  return 0;
1,704,292,621✔
1252
}
1253

1254
typedef struct {
1255
  char     name[TSDB_TABLE_FNAME_LEN];
1256
  int8_t   igExists;
1257
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1258
  int8_t   reserved[6];
1259
  tb_uid_t suid;
1260
  int64_t  delay1;
1261
  int64_t  delay2;
1262
  int64_t  watermark1;
1263
  int64_t  watermark2;
1264
  int32_t  ttl;
1265
  int32_t  colVer;
1266
  int32_t  tagVer;
1267
  int32_t  numOfColumns;
1268
  int32_t  numOfTags;
1269
  int32_t  numOfFuncs;
1270
  int32_t  commentLen;
1271
  int32_t  ast1Len;
1272
  int32_t  ast2Len;
1273
  SArray*  pColumns;  // array of SFieldWithOptions
1274
  SArray*  pTags;     // array of SField
1275
  SArray*  pFuncs;
1276
  char*    pComment;
1277
  char*    pAst1;
1278
  char*    pAst2;
1279
  int64_t  deleteMark1;
1280
  int64_t  deleteMark2;
1281
  int32_t  sqlLen;
1282
  char*    sql;
1283
  int64_t  keep;
1284
  int8_t   virtualStb;
1285
} SMCreateStbReq;
1286

1287
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1288
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1289
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1290

1291
typedef struct {
1292
  STableMetaRsp* pMeta;
1293
} SMCreateStbRsp;
1294

1295
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1296
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1297
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1298

1299
typedef struct {
1300
  char     name[TSDB_TABLE_FNAME_LEN];
1301
  int8_t   igNotExists;
1302
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1303
  int8_t   reserved[6];
1304
  tb_uid_t suid;
1305
  int32_t  sqlLen;
1306
  char*    sql;
1307
} SMDropStbReq;
1308

1309
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1310
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1311
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1312

1313
typedef struct {
1314
  char    name[TSDB_TABLE_FNAME_LEN];
1315
  int8_t  alterType;
1316
  int32_t numOfFields;
1317
  SArray* pFields;
1318
  int32_t ttl;
1319
  int32_t commentLen;
1320
  char*   comment;
1321
  int32_t sqlLen;
1322
  char*   sql;
1323
  int64_t keep;
1324
  SArray* pTypeMods;
1325
} SMAlterStbReq;
1326

1327
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1328
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1329
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1330

1331
typedef struct SEpSet {
1332
  int8_t inUse;
1333
  int8_t numOfEps;
1334
  SEp    eps[TSDB_MAX_REPLICA];
1335
} SEpSet;
1336

1337
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1338
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1339
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1340
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1341

1342
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1343
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1344

1345
typedef struct {
1346
  int8_t  connType;
1347
  int32_t pid;
1348
  int32_t totpCode;
1349
  char    app[TSDB_APP_NAME_LEN];
1350
  char    db[TSDB_DB_NAME_LEN];
1351
  char    user[TSDB_USER_LEN];
1352
  char    passwd[TSDB_PASSWORD_LEN];
1353
  char    token[TSDB_TOKEN_LEN];
1354
  int64_t startTime;
1355
  int64_t connectTime;
1356
  char    sVer[TSDB_VERSION_LEN];
1357
  char    signature[20]; // SHA1 produces a 20-byte signature
1358
} SConnectReq;
1359

1360
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1361
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1362
void    tSignConnectReq(SConnectReq* pReq);
1363
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1364

1365
typedef struct {
1366
  int64_t       clusterId;
1367
  int32_t       acctId;
1368
  uint32_t      connId;
1369
  int32_t       dnodeNum;
1370
  int8_t        superUser;
1371
  int8_t        sysInfo;
1372
  int8_t        connType;
1373
  int8_t        enableAuditDelete;
1374
  SEpSet        epSet;
1375
  int32_t       svrTimestamp;
1376
  int32_t       passVer;
1377
  int32_t       authVer;
1378
  char          sVer[TSDB_VERSION_LEN];
1379
  char          sDetailVer[128];
1380
  int64_t       whiteListVer;
1381
  int64_t       timeWhiteListVer;
1382
  int64_t       userId;
1383
  SMonitorParas monitorParas;
1384
  char          user[TSDB_USER_LEN];
1385
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1386
  int8_t        enableAuditSelect;
1387
  int8_t        enableAuditInsert;
1388
  int8_t        auditLevel;
1389
} SConnectRsp;
1390

1391
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1392
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1393

1394
typedef struct {
1395
  char    user[TSDB_USER_LEN];
1396
  char    pass[TSDB_PASSWORD_LEN];
1397
  int32_t maxUsers;
1398
  int32_t maxDbs;
1399
  int32_t maxTimeSeries;
1400
  int32_t maxStreams;
1401
  int32_t accessState;  // Configured only by command
1402
  int64_t maxStorage;
1403
} SCreateAcctReq, SAlterAcctReq;
1404

1405
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1406
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1407

1408
typedef struct {
1409
  char    user[TSDB_USER_LEN];
1410
  int8_t  ignoreNotExists;
1411
  int32_t sqlLen;
1412
  char*   sql;
1413
} SDropUserReq, SDropAcctReq;
1414

1415
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1416
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1417
void    tFreeSDropUserReq(SDropUserReq* pReq);
1418

1419
typedef struct {
1420
  char name[TSDB_ROLE_LEN];
1421
  union {
1422
    uint8_t flag;
1423
    struct {
1424
      uint8_t ignoreExists : 1;
1425
      uint8_t reserve : 7;
1426
    };
1427
  };
1428
  int32_t sqlLen;
1429
  char*   sql;
1430
} SCreateRoleReq;
1431

1432
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1433
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1434
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1435

1436
typedef struct {
1437
  char name[TSDB_ROLE_LEN];
1438
  union {
1439
    uint8_t flag;
1440
    struct {
1441
      uint8_t ignoreNotExists : 1;
1442
      uint8_t reserve : 7;
1443
    };
1444
  };
1445
  int32_t sqlLen;
1446
  char*   sql;
1447
} SDropRoleReq;
1448

1449
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1450
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1451
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1452

1453
typedef struct {
1454
  SPrivSet privSet;
1455
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1456
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1457
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1458
  // delete can only specify conditions by cond and cannot specify columns
1459
  char*    cond;     // for table privileges
1460
  int32_t  condLen;  // for table privileges
1461
} SPrivSetReqArgs;
1462

1463
typedef struct {
1464
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1465
  uint8_t objType;    // db, table, view, rsma, topic, etc.
1466
  union {
1467
    uint32_t flag;
1468
    struct {
1469
      uint32_t lock : 1;     // lock or unlock role
1470
      uint32_t add : 1;      // add or remove
1471
      uint32_t sysPriv : 1;  // system or object privileges
1472
      uint32_t objLevel : 2;
1473
      uint32_t ignoreNotExists : 1;
1474
      uint32_t reserve : 26;
1475
    };
1476
  };
1477
  union {
1478
    SPrivSetReqArgs privileges;
1479
    char            roleName[TSDB_ROLE_LEN];
1480
  };
1481
  char    principal[TSDB_ROLE_LEN];      // role or user name
1482
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db
1483
  char    tblName[TSDB_TABLE_NAME_LEN];  // table, view, rsma, topic, etc.
1484
  int32_t sqlLen;
1485
  char*   sql;
1486
} SAlterRoleReq;
1487

1488
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1489
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1490
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1491

1492
typedef struct {
1493
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1494
  int32_t sqlLen;
1495
  char*   sql;
1496
} SDropEncryptAlgrReq;
1497

1498
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1499
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1500
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1501

1502
typedef struct SIpV4Range {
1503
  uint32_t ip;
1504
  uint32_t mask;
1505
} SIpV4Range;
1506

1507
typedef struct SIpv6Range {
1508
  uint64_t addr[2];
1509
  uint32_t mask;
1510
} SIpV6Range;
1511

1512
typedef struct {
1513
  int8_t type;   // 0: IPv4, 1: IPv6
1514
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1515
  union {
1516
    SIpV4Range ipV4;
1517
    SIpV6Range ipV6;
1518
  };
1519
} SIpRange;
1520

1521
typedef struct {
1522
  int32_t    num;
1523
  SIpV4Range pIpRange[];
1524
} SIpWhiteList;
1525

1526
typedef struct {
1527
  int32_t  num;
1528
  SIpRange pIpRanges[];
1529
} SIpWhiteListDual;
1530

1531
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1532
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1533
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1534
int32_t           createDefaultIp6Range(SIpRange* pRange);
1535
int32_t           createDefaultIp4Range(SIpRange* pRange);
1536

1537
typedef struct {
1538
  int32_t sessPerUser;
1539
  int32_t sessConnTime;
1540
  int32_t sessConnIdleTime;
1541
  int32_t sessMaxConcurrency;
1542
  int32_t sessMaxCallVnodeNum;
1543
} SUserSessCfg;
1544

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

1549
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1550
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1551
typedef struct {
1552
  int16_t year;
1553
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1554
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1555
  int8_t hour;
1556
  int8_t minute;
1557
  int8_t neg;   // this is a negative entry
1558
  int32_t duration; // duration in minute
1559
} SDateTimeRange;
1560

1561
bool isValidDateTimeRange(SDateTimeRange* pRange);
1562
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1563
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1564

1565
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1566
typedef struct {
1567
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1568
  bool neg;         // this is a negative entry
1569
  int32_t duration; // duration in seconds
1570
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1571
} SDateTimeWhiteListItem;
1572

1573
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1574
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1575

1576
typedef struct {
1577
  int32_t num;
1578
  SDateTimeWhiteListItem ranges[];
1579
} SDateTimeWhiteList;
1580

1581
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1582
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1583

1584

1585
typedef struct {
1586
  int8_t createType;
1587
  int8_t superUser;  // denote if it is a super user or not
1588
  int8_t ignoreExists;
1589

1590
  char   user[TSDB_USER_LEN];
1591
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1592
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1593

1594
  int8_t sysInfo;
1595
  int8_t createDb;
1596
  int8_t isImport;
1597
  int8_t changepass;
1598
  int8_t enable;
1599

1600
  int8_t negIpRanges;
1601
  int8_t negTimeRanges;
1602

1603
  int32_t sessionPerUser;
1604
  int32_t connectTime;
1605
  int32_t connectIdleTime;
1606
  int32_t callPerSession;
1607
  int32_t vnodePerCall;
1608
  int32_t failedLoginAttempts;
1609
  int32_t passwordLifeTime;
1610
  int32_t passwordReuseTime;
1611
  int32_t passwordReuseMax;
1612
  int32_t passwordLockTime;
1613
  int32_t passwordGraceTime;
1614
  int32_t inactiveAccountTime;
1615
  int32_t allowTokenNum;
1616

1617
  int32_t         numIpRanges;
1618
  SIpRange*       pIpDualRanges;
1619
  int32_t         numTimeRanges;
1620
  SDateTimeRange* pTimeRanges;
1621

1622
  int32_t sqlLen;
1623
  char*   sql;
1624
} SCreateUserReq;
1625

1626
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1627
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1628
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1629

1630
typedef struct {
1631
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1632
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1633
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1634
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1635
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1636
  int32_t sqlLen;
1637
  char*   sql;
1638
} SCreateEncryptAlgrReq;
1639

1640
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1641
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1642
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1643

1644
typedef struct {
1645
  int32_t dnodeId;
1646
  int64_t analVer;
1647
} SRetrieveAnalyticsAlgoReq;
1648

1649
typedef struct {
1650
  int64_t   ver;
1651
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1652
} SRetrieveAnalyticAlgoRsp;
1653

1654
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1655
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1656
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1657
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1658
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1659

1660
typedef struct {
1661
  int8_t alterType;
1662

1663
  int8_t isView;
1664

1665
  int8_t hasPassword;
1666
  int8_t hasTotpseed;
1667
  int8_t hasEnable;
1668
  int8_t hasSysinfo;
1669
  int8_t hasCreatedb;
1670
  int8_t hasChangepass;
1671
  int8_t hasSessionPerUser;
1672
  int8_t hasConnectTime;
1673
  int8_t hasConnectIdleTime;
1674
  int8_t hasCallPerSession;
1675
  int8_t hasVnodePerCall;
1676
  int8_t hasFailedLoginAttempts;
1677
  int8_t hasPasswordLifeTime;
1678
  int8_t hasPasswordReuseTime;
1679
  int8_t hasPasswordReuseMax;
1680
  int8_t hasPasswordLockTime;
1681
  int8_t hasPasswordGraceTime;
1682
  int8_t hasInactiveAccountTime;
1683
  int8_t hasAllowTokenNum;
1684

1685
  int8_t enable;
1686
  int8_t sysinfo;
1687
  int8_t createdb;
1688
  int8_t changepass;
1689

1690
  char   user[TSDB_USER_LEN];
1691
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1692
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1693
  int32_t sessionPerUser;
1694
  int32_t connectTime;
1695
  int32_t connectIdleTime;
1696
  int32_t callPerSession;
1697
  int32_t vnodePerCall;
1698
  int32_t failedLoginAttempts;
1699
  int32_t passwordLifeTime;
1700
  int32_t passwordReuseTime;
1701
  int32_t passwordReuseMax;
1702
  int32_t passwordLockTime;
1703
  int32_t passwordGraceTime;
1704
  int32_t inactiveAccountTime;
1705
  int32_t allowTokenNum;
1706

1707
  int32_t         numIpRanges;
1708
  int32_t         numTimeRanges;
1709
  int32_t         numDropIpRanges;
1710
  int32_t         numDropTimeRanges;
1711
  SIpRange*       pIpRanges;
1712
  SDateTimeRange* pTimeRanges;
1713
  SIpRange*       pDropIpRanges;
1714
  SDateTimeRange* pDropTimeRanges;
1715
  SPrivSet        privileges;
1716

1717
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1718
  char        tabName[TSDB_TABLE_NAME_LEN];
1719
  char*       tagCond;
1720
  int32_t     tagCondLen;
1721
  int32_t     sqlLen;
1722
  char*       sql;
1723
} SAlterUserReq;
1724

1725
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1726
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1727
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1728

1729
typedef struct {
1730
  char    name[TSDB_TOKEN_NAME_LEN];
1731
  char    user[TSDB_USER_LEN];
1732
  int8_t  enable;
1733
  int8_t  ignoreExists;
1734
  int32_t ttl;
1735
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1736
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1737

1738
  int32_t sqlLen;
1739
  char*   sql;
1740
} SCreateTokenReq;
1741

1742
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1743
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1744
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1745

1746
typedef struct {
1747
  char name[TSDB_TOKEN_NAME_LEN];
1748
  char user[TSDB_USER_LEN];
1749
  char token[TSDB_TOKEN_LEN];
1750
} SCreateTokenRsp;
1751

1752
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1753
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1754
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1755

1756
typedef struct {
1757
  char    name[TSDB_TOKEN_NAME_LEN];
1758

1759
  int8_t hasEnable;
1760
  int8_t hasTtl;
1761
  int8_t hasProvider;
1762
  int8_t hasExtraInfo;
1763

1764
  int8_t  enable;
1765
  int32_t ttl;
1766
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1767
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1768

1769
  int32_t     sqlLen;
1770
  char*       sql;
1771
} SAlterTokenReq;
1772

1773
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1774
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1775
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1776

1777
typedef struct {
1778
  char    name[TSDB_TOKEN_NAME_LEN];
1779
  int8_t  ignoreNotExists;
1780
  int32_t sqlLen;
1781
  char*   sql;
1782
} SDropTokenReq;
1783

1784
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1785
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1786
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1787

1788
typedef struct {
1789
  char    user[TSDB_USER_LEN];
1790
  int32_t sqlLen;
1791
  char*   sql;
1792
} SCreateTotpSecretReq;
1793

1794
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1795
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1796
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1797

1798
typedef struct {
1799
  char user[TSDB_USER_LEN];
1800
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1801
} SCreateTotpSecretRsp;
1802

1803
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1804
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1805

1806
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1807
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1808
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1809
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1810

1811
typedef struct {
1812
  char user[TSDB_USER_LEN];
1813
} SGetUserAuthReq;
1814

1815
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1816
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1817

1818
typedef struct {
1819
  int8_t  enabled;
1820
  int32_t expireTime;
1821
} STokenStatus;
1822

1823
typedef struct {
1824
  char    user[TSDB_USER_LEN];
1825
  int64_t userId;
1826
  int32_t version;
1827
  int32_t passVer;
1828
  int8_t  superAuth;
1829
  int8_t  sysInfo;
1830
  int8_t  enable;
1831
  int8_t  dropped;
1832
  union {
1833
    uint8_t flags;
1834
    struct {
1835
      uint8_t privLevel : 3;
1836
      uint8_t withInsertCond : 1;
1837
      uint8_t reserve : 4;
1838
    };
1839
  };
1840
  SPrivSet  sysPrivs;
1841
  SHashObj* objPrivs;
1842
  SHashObj* selectTbs;
1843
  SHashObj* insertTbs;
1844
  SHashObj* deleteTbs;
1845
  SHashObj* ownedDbs;
1846
  int64_t   whiteListVer;
1847

1848
  SUserSessCfg sessCfg;
1849
  int64_t      timeWhiteListVer;
1850
  SHashObj*    tokens;
1851
} SGetUserAuthRsp;
1852

1853
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1854
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1855
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1856

1857
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1858
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1859
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1860
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1861

1862
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1863
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1864
typedef struct {
1865
  int64_t ver;
1866
  char    user[TSDB_USER_LEN];
1867
  int32_t numOfRange;
1868
  union {
1869
    SIpV4Range* pIpRanges;
1870
    SIpRange*   pIpDualRanges;
1871
  };
1872
} SUpdateUserIpWhite;
1873

1874
typedef struct {
1875
  int64_t             ver;
1876
  int                 numOfUser;
1877
  SUpdateUserIpWhite* pUserIpWhite;
1878
} SUpdateIpWhite;
1879

1880
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1881
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1882
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1883
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1884

1885
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1886
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1887
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1888

1889

1890
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1891
// corresponding response struct is different.
1892
typedef struct {
1893
  int64_t ver;
1894
} SRetrieveWhiteListReq;
1895

1896
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1897
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1898

1899

1900
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1901
// corresponding response struct is different.
1902
typedef struct {
1903
  char user[TSDB_USER_LEN];
1904
} SGetUserWhiteListReq;
1905

1906
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1907
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1908

1909
typedef struct {
1910
  char    user[TSDB_USER_LEN];
1911
  int32_t numWhiteLists;
1912
  union {
1913
    SIpV4Range* pWhiteLists;
1914
    SIpRange*   pWhiteListsDual;
1915
  };
1916
} SGetUserIpWhiteListRsp;
1917

1918
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1919
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1920
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1921
void    tIpRangeSetDefaultMask(SIpRange* range);
1922

1923
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1924
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1925
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1926

1927
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1928
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1929
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1930

1931
typedef struct {
1932
  int64_t ver;
1933
  char    user[TSDB_USER_LEN];
1934
  int32_t numWhiteLists;
1935
  SDateTimeWhiteListItem* pWhiteLists;
1936
} SUserDateTimeWhiteList;
1937

1938

1939
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1940
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1941
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1942
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1943

1944
typedef struct {
1945
  int64_t             ver;
1946
  int                 numOfUser;
1947
  SUserDateTimeWhiteList *pUsers;
1948
} SRetrieveDateTimeWhiteListRsp;
1949

1950
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1951
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1952
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1953
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1954

1955
/*
1956
 * for client side struct, only column id, type, bytes are necessary
1957
 * But for data in vnode side, we need all the following information.
1958
 */
1959
typedef struct {
1960
  union {
1961
    col_id_t colId;
1962
    int16_t  slotId;
1963
  };
1964

1965
  uint8_t precision;
1966
  uint8_t scale;
1967
  int32_t bytes;
1968
  int8_t  type;
1969
  uint8_t pk;
1970
  bool    noData;
1971
} SColumnInfo;
1972

1973
typedef struct STimeWindow {
1974
  TSKEY skey;
1975
  TSKEY ekey;
1976
} STimeWindow;
1977

1978
typedef struct SQueryHint {
1979
  bool batchScan;
1980
} SQueryHint;
1981

1982
typedef struct {
1983
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1984
  int32_t tsLen;          // total length of ts comp block
1985
  int32_t tsNumOfBlocks;  // ts comp block numbers
1986
  int32_t tsOrder;        // ts comp block order
1987
} STsBufInfo;
1988

1989
typedef struct {
1990
  void*       timezone;
1991
  char        intervalUnit;
1992
  char        slidingUnit;
1993
  char        offsetUnit;
1994
  int8_t      precision;
1995
  int64_t     interval;
1996
  int64_t     sliding;
1997
  int64_t     offset;
1998
  STimeWindow timeRange;
1999
} SInterval;
2000

2001
typedef struct STbVerInfo {
2002
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2003
  int32_t sversion;
2004
  int32_t tversion;
2005
  int32_t rversion;  // virtual table's column ref's version
2006
} STbVerInfo;
2007

2008
typedef struct {
2009
  int32_t code;
2010
  int64_t affectedRows;
2011
  SArray* tbVerInfo;  // STbVerInfo
2012
} SQueryTableRsp;
2013

2014
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2015

2016
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2017

2018
typedef struct {
2019
  SMsgHead header;
2020
  char     dbFName[TSDB_DB_FNAME_LEN];
2021
  char     tbName[TSDB_TABLE_NAME_LEN];
2022
} STableCfgReq;
2023

2024
typedef struct {
2025
  char        tbName[TSDB_TABLE_NAME_LEN];
2026
  char        stbName[TSDB_TABLE_NAME_LEN];
2027
  char        dbFName[TSDB_DB_FNAME_LEN];
2028
  int32_t     numOfTags;
2029
  int32_t     numOfColumns;
2030
  int8_t      tableType;
2031
  int64_t     delay1;
2032
  int64_t     delay2;
2033
  int64_t     watermark1;
2034
  int64_t     watermark2;
2035
  int32_t     ttl;
2036
  int32_t     keep;
2037
  int64_t     ownerId;
2038
  SArray*     pFuncs;
2039
  int32_t     commentLen;
2040
  char*       pComment;
2041
  SSchema*    pSchemas;
2042
  int32_t     tagsLen;
2043
  char*       pTags;
2044
  SSchemaExt* pSchemaExt;
2045
  union {
2046
    uint8_t flag;
2047
    struct {
2048
      uint8_t virtualStb : 1;  // no compatibility problem for little-endian arch
2049
      uint8_t isAudit : 1;
2050
      uint8_t reserve : 6;
2051
    };
2052
  };
2053
  SColRef* pColRefs;
2054
} STableCfg;
2055

2056
typedef STableCfg STableCfgRsp;
2057

2058
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2059
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2060

2061
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2062
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2063
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2064

2065
typedef struct {
2066
  SMsgHead header;
2067
  tb_uid_t suid;
2068
} SVSubTablesReq;
2069

2070
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2071
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2072

2073
typedef struct {
2074
  int32_t vgId;
2075
  SArray* pTables;  // SArray<SVCTableRefCols*>
2076
} SVSubTablesRsp;
2077

2078
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2079
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2080
void    tDestroySVSubTablesRsp(void* rsp);
2081

2082
typedef struct {
2083
  SMsgHead header;
2084
  tb_uid_t suid;
2085
} SVStbRefDbsReq;
2086

2087
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2088
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2089

2090
typedef struct {
2091
  int32_t vgId;
2092
  SArray* pDbs;  // SArray<char* (db name)>
2093
} SVStbRefDbsRsp;
2094

2095
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2096
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2097
void    tDestroySVStbRefDbsRsp(void* rsp);
2098

2099
typedef struct {
2100
  char    db[TSDB_DB_FNAME_LEN];
2101
  int32_t numOfVgroups;
2102
  int32_t numOfStables;  // single_stable
2103
  int32_t buffer;        // MB
2104
  int32_t pageSize;
2105
  int32_t pages;
2106
  int32_t cacheLastSize;
2107
  int32_t daysPerFile;
2108
  int32_t daysToKeep0;
2109
  int32_t daysToKeep1;
2110
  int32_t daysToKeep2;
2111
  int32_t keepTimeOffset;
2112
  int32_t minRows;
2113
  int32_t maxRows;
2114
  int32_t walFsyncPeriod;
2115
  int8_t  walLevel;
2116
  int8_t  precision;  // time resolution
2117
  int8_t  compression;
2118
  int8_t  replications;
2119
  int8_t  strict;
2120
  int8_t  cacheLast;
2121
  int8_t  schemaless;
2122
  int8_t  ignoreExist;
2123
  int32_t numOfRetensions;
2124
  SArray* pRetensions;  // SRetention
2125
  int32_t walRetentionPeriod;
2126
  int64_t walRetentionSize;
2127
  int32_t walRollPeriod;
2128
  int64_t walSegmentSize;
2129
  int32_t sstTrigger;
2130
  int16_t hashPrefix;
2131
  int16_t hashSuffix;
2132
  int32_t ssChunkSize;
2133
  int32_t ssKeepLocal;
2134
  int8_t  ssCompact;
2135
  int32_t tsdbPageSize;
2136
  int32_t sqlLen;
2137
  char*   sql;
2138
  int8_t  withArbitrator;
2139
  int8_t  encryptAlgorithm;
2140
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2141
  // 1. add auto-compact parameters
2142
  int32_t compactInterval;    // minutes
2143
  int32_t compactStartTime;   // minutes
2144
  int32_t compactEndTime;     // minutes
2145
  int8_t  compactTimeOffset;  // hour
2146
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2147
  int8_t  isAudit;
2148
  int8_t  allowDrop;
2149
} SCreateDbReq;
2150

2151
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2152
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2153
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2154

2155
typedef struct {
2156
  char    db[TSDB_DB_FNAME_LEN];
2157
  int32_t buffer;
2158
  int32_t pageSize;
2159
  int32_t pages;
2160
  int32_t cacheLastSize;
2161
  int32_t daysPerFile;
2162
  int32_t daysToKeep0;
2163
  int32_t daysToKeep1;
2164
  int32_t daysToKeep2;
2165
  int32_t keepTimeOffset;
2166
  int32_t walFsyncPeriod;
2167
  int8_t  walLevel;
2168
  int8_t  strict;
2169
  int8_t  cacheLast;
2170
  int8_t  replications;
2171
  int32_t sstTrigger;
2172
  int32_t minRows;
2173
  int32_t walRetentionPeriod;
2174
  int32_t walRetentionSize;
2175
  int32_t ssKeepLocal;
2176
  int8_t  ssCompact;
2177
  int32_t sqlLen;
2178
  char*   sql;
2179
  int8_t  withArbitrator;
2180
  // 1. add auto-compact parameters
2181
  int32_t compactInterval;
2182
  int32_t compactStartTime;
2183
  int32_t compactEndTime;
2184
  int8_t  compactTimeOffset;
2185
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2186
  int8_t  isAudit;
2187
  int8_t  allowDrop;
2188
} SAlterDbReq;
2189

2190
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2191
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2192
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2193

2194
typedef struct {
2195
  char    db[TSDB_DB_FNAME_LEN];
2196
  int8_t  ignoreNotExists;
2197
  int8_t  force;
2198
  int32_t sqlLen;
2199
  char*   sql;
2200
} SDropDbReq;
2201

2202
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2203
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2204
void    tFreeSDropDbReq(SDropDbReq* pReq);
2205

2206
typedef struct {
2207
  char    db[TSDB_DB_FNAME_LEN];
2208
  int64_t uid;
2209
} SDropDbRsp;
2210

2211
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2212
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2213

2214
typedef struct {
2215
  char    name[TSDB_MOUNT_NAME_LEN];
2216
  int64_t uid;
2217
} SDropMountRsp;
2218

2219
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2220
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2221

2222
typedef struct {
2223
  char    db[TSDB_DB_FNAME_LEN];
2224
  int64_t dbId;
2225
  int32_t vgVersion;
2226
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2227
  int64_t stateTs;     // ms
2228
} SUseDbReq;
2229

2230
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2231
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2232

2233
typedef struct {
2234
  char    db[TSDB_DB_FNAME_LEN];
2235
  int64_t uid;
2236
  int32_t vgVersion;
2237
  int32_t vgNum;
2238
  int16_t hashPrefix;
2239
  int16_t hashSuffix;
2240
  int8_t  hashMethod;
2241
  union {
2242
    uint8_t flags;
2243
    struct {
2244
      uint8_t isMount : 1;  // TS-5868
2245
      uint8_t padding : 7;
2246
    };
2247
  };
2248
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2249
  int32_t errCode;
2250
  int64_t stateTs;  // ms
2251
} SUseDbRsp;
2252

2253
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2254
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2255
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2256
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2257
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2258

2259
typedef struct {
2260
  char db[TSDB_DB_FNAME_LEN];
2261
} SDbCfgReq;
2262

2263
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2264
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2265

2266
typedef struct {
2267
  char db[TSDB_DB_FNAME_LEN];
2268
} SSsMigrateDbReq;
2269

2270
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2271
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2272

2273
typedef struct {
2274
  int32_t ssMigrateId;
2275
  bool    bAccepted;
2276
} SSsMigrateDbRsp;
2277

2278
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2279
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2280

2281
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2282
typedef struct {
2283
  int32_t ssMigrateId;
2284
} SListSsMigrateFileSetsReq;
2285

2286
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2287
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2288

2289
typedef struct {
2290
  int32_t ssMigrateId;
2291
  int32_t vgId;       // vgroup id
2292
  SArray* pFileSets;  // SArray<int32_t>
2293
} SListSsMigrateFileSetsRsp;
2294

2295
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2296
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2297
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2298

2299
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2300
typedef struct {
2301
  int32_t ssMigrateId;
2302
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2303
  int32_t fid;
2304
  int64_t startTimeSec;
2305
} SSsMigrateFileSetReq;
2306

2307
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2308
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2309

2310
typedef struct {
2311
  int32_t ssMigrateId;
2312
  int32_t nodeId;  // node id of the leader vnode
2313
  int32_t vgId;
2314
  int32_t fid;
2315
} SSsMigrateFileSetRsp;
2316

2317
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2318
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2319

2320
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2321
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2322
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2323
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2324
#define SSMIGRATE_FILESET_STATE_FAILED      4
2325

2326
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2327
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2328
// while as a request, the 'state' field is not used.
2329
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2330
typedef struct {
2331
  int32_t ssMigrateId;  // ss migrate id
2332
  int32_t nodeId;       // node id of the leader vnode
2333
  int32_t vgId;         // vgroup id
2334
  int32_t fid;          // file set id
2335
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2336
} SSsMigrateProgress;
2337

2338
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2339
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2340

2341
// Request for TDMT_MND_KILL_SSMIGRATE
2342
typedef struct {
2343
  int32_t ssMigrateId;
2344
  int32_t sqlLen;
2345
  char*   sql;
2346
} SKillSsMigrateReq;
2347

2348
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2349
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2350
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2351

2352
// Request for TDMT_VND_KILL_SSMIGRATE
2353
typedef struct {
2354
  int32_t ssMigrateId;
2355
} SVnodeKillSsMigrateReq;
2356

2357
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2358
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2359

2360
typedef struct {
2361
  int32_t vgId;
2362
  int64_t keepVersion;
2363
} SMndSetVgroupKeepVersionReq;
2364

2365
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2366
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2367

2368
typedef struct {
2369
  int32_t timestampSec;
2370
  int32_t ttlDropMaxCount;
2371
  int32_t nUids;
2372
  SArray* pTbUids;
2373
} SVDropTtlTableReq;
2374

2375
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2376
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2377

2378
typedef struct {
2379
  char    db[TSDB_DB_FNAME_LEN];
2380
  int64_t dbId;
2381
  int64_t ownerId;
2382
  int32_t cfgVersion;
2383
  int32_t numOfVgroups;
2384
  int32_t numOfStables;
2385
  int32_t buffer;
2386
  int32_t cacheSize;
2387
  int32_t pageSize;
2388
  int32_t pages;
2389
  int32_t daysPerFile;
2390
  int32_t daysToKeep0;
2391
  int32_t daysToKeep1;
2392
  int32_t daysToKeep2;
2393
  int32_t keepTimeOffset;
2394
  int32_t minRows;
2395
  int32_t maxRows;
2396
  int32_t walFsyncPeriod;
2397
  int16_t hashPrefix;
2398
  int16_t hashSuffix;
2399
  int8_t  hashMethod;
2400
  int8_t  walLevel;
2401
  int8_t  precision;
2402
  int8_t  compression;
2403
  int8_t  replications;
2404
  int8_t  strict;
2405
  int8_t  cacheLast;
2406
  int8_t  encryptAlgr;
2407
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2408
  int32_t ssChunkSize;
2409
  int32_t ssKeepLocal;
2410
  int8_t  ssCompact;
2411
  union {
2412
    uint8_t flags;
2413
    struct {
2414
      uint8_t isMount : 1;    // TS-5868
2415
      uint8_t allowDrop : 1;  // TS-7232
2416
      uint8_t padding : 6;
2417
    };
2418
  };
2419
  int8_t  compactTimeOffset;
2420
  int32_t compactInterval;
2421
  int32_t compactStartTime;
2422
  int32_t compactEndTime;
2423
  int32_t tsdbPageSize;
2424
  int32_t walRetentionPeriod;
2425
  int32_t walRollPeriod;
2426
  int64_t walRetentionSize;
2427
  int64_t walSegmentSize;
2428
  int32_t numOfRetensions;
2429
  SArray* pRetensions;
2430
  int8_t  schemaless;
2431
  int16_t sstTrigger;
2432
  int8_t  withArbitrator;
2433
  int8_t  isAudit;
2434
} SDbCfgRsp;
2435

2436
typedef SDbCfgRsp SDbCfgInfo;
2437

2438
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2439
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2440
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2441
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2442
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2443

2444
typedef struct {
2445
  int32_t rowNum;
2446
} SQnodeListReq;
2447

2448
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2449
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2450

2451
typedef struct {
2452
  int32_t rowNum;
2453
} SDnodeListReq;
2454

2455
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2456

2457
typedef struct {
2458
  int32_t useless;  // useless
2459
} SServerVerReq;
2460

2461
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2462
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2463

2464
typedef struct {
2465
  char ver[TSDB_VERSION_LEN];
2466
} SServerVerRsp;
2467

2468
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2469
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2470

2471
typedef struct SQueryNodeAddr {
2472
  int32_t nodeId;  // vgId or qnodeId
2473
  SEpSet  epSet;
2474
} SQueryNodeAddr;
2475

2476
typedef struct {
2477
  SQueryNodeAddr addr;
2478
  uint64_t       load;
2479
} SQueryNodeLoad;
2480

2481
typedef struct {
2482
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2483
} SQnodeListRsp;
2484

2485
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2486
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2487
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2488

2489

2490
typedef struct SDownstreamSourceNode {
2491
  ENodeType      type;
2492
  SQueryNodeAddr addr;
2493
  uint64_t       clientId;
2494
  uint64_t       taskId;
2495
  uint64_t       sId;
2496
  uint64_t       srcTaskId;
2497
  int32_t        execId;
2498
  int32_t        fetchMsgType;
2499
  bool           localExec;
2500
} SDownstreamSourceNode;
2501

2502

2503

2504
typedef struct SDNodeAddr {
2505
  int32_t nodeId;  // dnodeId
2506
  SEpSet  epSet;
2507
} SDNodeAddr;
2508

2509
typedef struct {
2510
  SArray* dnodeList;  // SArray<SDNodeAddr>
2511
} SDnodeListRsp;
2512

2513
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2514
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2515
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2516

2517
typedef struct {
2518
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2519
} STableTSMAInfoRsp;
2520

2521
typedef struct {
2522
  SUseDbRsp*         useDbRsp;
2523
  SDbCfgRsp*         cfgRsp;
2524
  STableTSMAInfoRsp* pTsmaRsp;
2525
  int32_t            dbTsmaVersion;
2526
  char               db[TSDB_DB_FNAME_LEN];
2527
  int64_t            dbId;
2528
} SDbHbRsp;
2529

2530
typedef struct {
2531
  SArray* pArray;  // Array of SDbHbRsp
2532
} SDbHbBatchRsp;
2533

2534
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2535
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2536
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2537

2538
typedef struct {
2539
  SArray* pArray;  // Array of SGetUserAuthRsp
2540
} SUserAuthBatchRsp;
2541

2542
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2543
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2544
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2545

2546
typedef struct {
2547
  char        db[TSDB_DB_FNAME_LEN];
2548
  STimeWindow timeRange;
2549
  int32_t     sqlLen;
2550
  char*       sql;
2551
  SArray*     vgroupIds;
2552
  int32_t     compactId;
2553
  int8_t      metaOnly;
2554
  int8_t      force;
2555
} SCompactDbReq;
2556

2557
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2558
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2559
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2560

2561
typedef struct {
2562
  union {
2563
    int32_t compactId;
2564
    int32_t id;
2565
  };
2566
  int8_t bAccepted;
2567
} SCompactDbRsp;
2568

2569
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2570
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2571

2572
typedef struct {
2573
  union {
2574
    int32_t compactId;
2575
    int32_t id;
2576
  };
2577
  int32_t sqlLen;
2578
  char*   sql;
2579
} SKillCompactReq;
2580

2581
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2582
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2583
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2584

2585
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2586
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2587

2588
typedef struct {
2589
  char    name[TSDB_FUNC_NAME_LEN];
2590
  int8_t  igExists;
2591
  int8_t  funcType;
2592
  int8_t  scriptType;
2593
  int8_t  outputType;
2594
  int32_t outputLen;
2595
  int32_t bufSize;
2596
  int32_t codeLen;
2597
  int64_t signature;
2598
  char*   pComment;
2599
  char*   pCode;
2600
  int8_t  orReplace;
2601
} SCreateFuncReq;
2602

2603
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2604
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2605
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2606

2607
typedef struct {
2608
  char   name[TSDB_FUNC_NAME_LEN];
2609
  int8_t igNotExists;
2610
} SDropFuncReq;
2611

2612
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2613
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2614

2615
typedef struct {
2616
  int32_t numOfFuncs;
2617
  bool    ignoreCodeComment;
2618
  SArray* pFuncNames;
2619
} SRetrieveFuncReq;
2620

2621
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2622
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2623
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2624

2625
typedef struct {
2626
  char    name[TSDB_FUNC_NAME_LEN];
2627
  int8_t  funcType;
2628
  int8_t  scriptType;
2629
  int8_t  outputType;
2630
  int32_t outputLen;
2631
  int32_t bufSize;
2632
  int64_t signature;
2633
  int32_t commentSize;
2634
  int32_t codeSize;
2635
  char*   pComment;
2636
  char*   pCode;
2637
} SFuncInfo;
2638

2639
typedef struct {
2640
  int32_t funcVersion;
2641
  int64_t funcCreatedTime;
2642
} SFuncExtraInfo;
2643

2644
typedef struct {
2645
  int32_t numOfFuncs;
2646
  SArray* pFuncInfos;
2647
  SArray* pFuncExtraInfos;
2648
} SRetrieveFuncRsp;
2649

2650
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2651
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2652
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2653
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2654

2655
typedef struct {
2656
  int32_t       statusInterval;
2657
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2658
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2659
  char          locale[TD_LOCALE_LEN];      // tsLocale
2660
  char          charset[TD_LOCALE_LEN];     // tsCharset
2661
  int8_t        ttlChangeOnWrite;
2662
  int8_t        enableWhiteList;
2663
  int8_t        encryptionKeyStat;
2664
  uint32_t      encryptionKeyChksum;
2665
  SMonitorParas monitorParas;
2666
  int32_t       statusIntervalMs;
2667
} SClusterCfg;
2668

2669
typedef struct {
2670
  int32_t openVnodes;
2671
  int32_t dropVnodes;
2672
  int32_t totalVnodes;
2673
  int32_t masterNum;
2674
  int64_t numOfSelectReqs;
2675
  int64_t numOfInsertReqs;
2676
  int64_t numOfInsertSuccessReqs;
2677
  int64_t numOfBatchInsertReqs;
2678
  int64_t numOfBatchInsertSuccessReqs;
2679
  int64_t errors;
2680
} SVnodesStat;
2681

2682
typedef struct {
2683
  int32_t vgId;
2684
  int8_t  syncState;
2685
  int8_t  syncRestore;
2686
  int64_t syncTerm;
2687
  int64_t roleTimeMs;
2688
  int64_t startTimeMs;
2689
  int8_t  syncCanRead;
2690
  int64_t cacheUsage;
2691
  int64_t numOfTables;
2692
  int64_t numOfTimeSeries;
2693
  int64_t totalStorage;
2694
  int64_t compStorage;
2695
  int64_t pointsWritten;
2696
  int64_t numOfSelectReqs;
2697
  int64_t numOfInsertReqs;
2698
  int64_t numOfInsertSuccessReqs;
2699
  int64_t numOfBatchInsertReqs;
2700
  int64_t numOfBatchInsertSuccessReqs;
2701
  int32_t numOfCachedTables;
2702
  int32_t learnerProgress;  // use one reservered
2703
  int64_t syncAppliedIndex;
2704
  int64_t syncCommitIndex;
2705
  int64_t bufferSegmentUsed;
2706
  int64_t bufferSegmentSize;
2707
  int32_t snapSeq;
2708
  int64_t syncTotalIndex;
2709
} SVnodeLoad;
2710

2711
typedef struct {
2712
  int64_t total_requests;
2713
  int64_t total_rows;
2714
  int64_t total_bytes;
2715
  double  write_size;
2716
  double  cache_hit_ratio;
2717
  int64_t rpc_queue_wait;
2718
  int64_t preprocess_time;
2719

2720
  int64_t memory_table_size;
2721
  int64_t commit_count;
2722
  int64_t merge_count;
2723
  double  commit_time;
2724
  double  merge_time;
2725
  int64_t block_commit_time;
2726
  int64_t memtable_wait_time;
2727
} SVnodeMetrics;
2728

2729
typedef struct {
2730
  int32_t     vgId;
2731
  int64_t     numOfTables;
2732
  int64_t     memSize;
2733
  int64_t     l1Size;
2734
  int64_t     l2Size;
2735
  int64_t     l3Size;
2736
  int64_t     cacheSize;
2737
  int64_t     walSize;
2738
  int64_t     metaSize;
2739
  int64_t     rawDataSize;
2740
  int64_t     ssSize;
2741
  const char* dbname;
2742
  int8_t      estimateRawData;
2743
} SDbSizeStatisInfo;
2744

2745
typedef struct {
2746
  int32_t vgId;
2747
  int64_t nTimeSeries;
2748
} SVnodeLoadLite;
2749

2750
typedef struct {
2751
  int8_t  syncState;
2752
  int64_t syncTerm;
2753
  int8_t  syncRestore;
2754
  int64_t roleTimeMs;
2755
} SMnodeLoad;
2756

2757
typedef struct {
2758
  int32_t dnodeId;
2759
  int64_t numOfProcessedQuery;
2760
  int64_t numOfProcessedCQuery;
2761
  int64_t numOfProcessedFetch;
2762
  int64_t numOfProcessedDrop;
2763
  int64_t numOfProcessedNotify;
2764
  int64_t numOfProcessedHb;
2765
  int64_t numOfProcessedDelete;
2766
  int64_t cacheDataSize;
2767
  int64_t numOfQueryInQueue;
2768
  int64_t numOfFetchInQueue;
2769
  int64_t timeInQueryQueue;
2770
  int64_t timeInFetchQueue;
2771
} SQnodeLoad;
2772

2773
typedef struct {
2774
  int32_t     sver;      // software version
2775
  int64_t     dnodeVer;  // dnode table version in sdb
2776
  int32_t     dnodeId;
2777
  int64_t     clusterId;
2778
  int64_t     rebootTime;
2779
  int64_t     updateTime;
2780
  float       numOfCores;
2781
  int32_t     numOfSupportVnodes;
2782
  int32_t     numOfDiskCfg;
2783
  int64_t     memTotal;
2784
  int64_t     memAvail;
2785
  char        dnodeEp[TSDB_EP_LEN];
2786
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2787
  SMnodeLoad  mload;
2788
  SQnodeLoad  qload;
2789
  SClusterCfg clusterCfg;
2790
  SArray*     pVloads;  // array of SVnodeLoad
2791
  int32_t     statusSeq;
2792
  int64_t     ipWhiteVer;
2793
  int64_t     timeWhiteVer;
2794
  int64_t     analVer;
2795
  int64_t     timestamp;
2796
  char        auditDB[TSDB_DB_FNAME_LEN];
2797
  char        auditToken[TSDB_TOKEN_LEN];
2798
} SStatusReq;
2799

2800
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2801
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2802
void    tFreeSStatusReq(SStatusReq* pReq);
2803

2804
typedef struct {
2805
  int32_t forceReadConfig;
2806
  int32_t cver;
2807
  SArray* array;
2808
} SConfigReq;
2809

2810
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2811
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2812
void    tFreeSConfigReq(SConfigReq* pReq);
2813

2814
typedef struct {
2815
  int32_t dnodeId;
2816
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2817
} SDnodeInfoReq;
2818

2819
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2820
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2821

2822
typedef enum {
2823
  MONITOR_TYPE_COUNTER = 0,
2824
  MONITOR_TYPE_SLOW_LOG = 1,
2825
} MONITOR_TYPE;
2826

2827
typedef struct {
2828
  int32_t      contLen;
2829
  char*        pCont;
2830
  MONITOR_TYPE type;
2831
} SStatisReq;
2832

2833
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2834
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2835
void    tFreeSStatisReq(SStatisReq* pReq);
2836

2837
typedef struct {
2838
  char    db[TSDB_DB_FNAME_LEN];
2839
  char    table[TSDB_TABLE_NAME_LEN];
2840
  char    operation[AUDIT_OPERATION_LEN];
2841
  int32_t sqlLen;
2842
  char*   pSql;
2843
  double  duration;
2844
  int64_t affectedRows;
2845
} SAuditReq;
2846
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2847
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2848
void    tFreeSAuditReq(SAuditReq* pReq);
2849

2850
typedef struct {
2851
  SArray* auditArr;
2852
} SBatchAuditReq;
2853
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2854
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2855
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2856

2857
typedef struct {
2858
  int32_t dnodeId;
2859
  int64_t clusterId;
2860
  SArray* pVloads;
2861
} SNotifyReq;
2862

2863
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2864
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2865
void    tFreeSNotifyReq(SNotifyReq* pReq);
2866

2867
typedef struct {
2868
  int32_t dnodeId;
2869
  int64_t clusterId;
2870
} SDnodeCfg;
2871

2872
typedef struct {
2873
  int32_t id;
2874
  int8_t  isMnode;
2875
  SEp     ep;
2876
} SDnodeEp;
2877

2878
typedef struct {
2879
  int32_t id;
2880
  int8_t  isMnode;
2881
  int8_t  offlineReason;
2882
  SEp     ep;
2883
  char    active[TSDB_ACTIVE_KEY_LEN];
2884
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2885
} SDnodeInfo;
2886

2887
typedef struct {
2888
  int64_t   dnodeVer;
2889
  SDnodeCfg dnodeCfg;
2890
  SArray*   pDnodeEps;  // Array of SDnodeEp
2891
  int32_t   statusSeq;
2892
  int64_t   ipWhiteVer;
2893
  int64_t   analVer;
2894
  int64_t   timeWhiteVer;
2895
  char      auditDB[TSDB_DB_FNAME_LEN];
2896
  char      auditToken[TSDB_TOKEN_LEN];
2897
} SStatusRsp;
2898

2899
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2900
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2901
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2902

2903
typedef struct {
2904
  int32_t forceReadConfig;
2905
  int32_t isConifgVerified;
2906
  int32_t isVersionVerified;
2907
  int32_t cver;
2908
  SArray* array;
2909
} SConfigRsp;
2910

2911
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2912
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2913
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2914

2915
typedef struct {
2916
  int32_t dnodeId;
2917
  int32_t keyVersion;  // Local key version
2918
} SKeySyncReq;
2919

2920
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2921
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2922

2923
typedef struct {
2924
  int32_t keyVersion;        // mnode's key version
2925
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2926
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2927
  char    svrKey[129];       // Server key (if needUpdate)
2928
  char    dbKey[129];        // Database key (if needUpdate)
2929
  char    cfgKey[129];       // Config key (if needUpdate)
2930
  char    metaKey[129];      // Metadata key (if needUpdate)
2931
  char    dataKey[129];      // Data key (if needUpdate)
2932
  int32_t algorithm;         // Encryption algorithm for master keys
2933
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2934
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2935
  int64_t createTime;        // Key creation time
2936
  int64_t svrKeyUpdateTime;  // Server key update time
2937
  int64_t dbKeyUpdateTime;   // Database key update time
2938
} SKeySyncRsp;
2939

2940
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2941
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2942

2943
typedef struct {
2944
  int32_t reserved;
2945
} SMTimerReq;
2946

2947
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2948
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2949

2950
typedef struct SOrphanTask {
2951
  int64_t streamId;
2952
  int32_t taskId;
2953
  int32_t nodeId;
2954
} SOrphanTask;
2955

2956
typedef struct SMStreamDropOrphanMsg {
2957
  SArray* pList;  // SArray<SOrphanTask>
2958
} SMStreamDropOrphanMsg;
2959

2960
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2961
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2962
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2963

2964
typedef struct {
2965
  int32_t  id;
2966
  uint16_t port;                 // node sync Port
2967
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2968
} SReplica;
2969

2970
typedef struct {
2971
  int32_t  vgId;
2972
  char     db[TSDB_DB_FNAME_LEN];
2973
  int64_t  dbUid;
2974
  int32_t  vgVersion;
2975
  int32_t  numOfStables;
2976
  int32_t  buffer;
2977
  int32_t  pageSize;
2978
  int32_t  pages;
2979
  int32_t  cacheLastSize;
2980
  int32_t  daysPerFile;
2981
  int32_t  daysToKeep0;
2982
  int32_t  daysToKeep1;
2983
  int32_t  daysToKeep2;
2984
  int32_t  keepTimeOffset;
2985
  int32_t  minRows;
2986
  int32_t  maxRows;
2987
  int32_t  walFsyncPeriod;
2988
  uint32_t hashBegin;
2989
  uint32_t hashEnd;
2990
  int8_t   hashMethod;
2991
  int8_t   walLevel;
2992
  int8_t   precision;
2993
  int8_t   compression;
2994
  int8_t   strict;
2995
  int8_t   cacheLast;
2996
  int8_t   isTsma;
2997
  int8_t   replica;
2998
  int8_t   selfIndex;
2999
  SReplica replicas[TSDB_MAX_REPLICA];
3000
  int32_t  numOfRetensions;
3001
  SArray*  pRetensions;  // SRetention
3002
  void*    pTsma;
3003
  int32_t  walRetentionPeriod;
3004
  int64_t  walRetentionSize;
3005
  int32_t  walRollPeriod;
3006
  int64_t  walSegmentSize;
3007
  int16_t  sstTrigger;
3008
  int16_t  hashPrefix;
3009
  int16_t  hashSuffix;
3010
  int32_t  tsdbPageSize;
3011
  int32_t  ssChunkSize;
3012
  int32_t  ssKeepLocal;
3013
  int8_t   ssCompact;
3014
  int64_t  reserved[6];
3015
  int8_t   learnerReplica;
3016
  int8_t   learnerSelfIndex;
3017
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3018
  int32_t  changeVersion;
3019
  int8_t   encryptAlgorithm;
3020
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
3021
  union {
3022
    uint8_t flags;
3023
    struct {
3024
      uint8_t isAudit : 1;
3025
      uint8_t allowDrop : 1;
3026
      uint8_t padding : 6;
3027
    };
3028
  };
3029
} SCreateVnodeReq;
3030

3031
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3032
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3033
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3034

3035
typedef struct {
3036
  union {
3037
    int32_t compactId;
3038
    int32_t id;
3039
  };
3040
  int32_t vgId;
3041
  int32_t dnodeId;
3042
} SQueryCompactProgressReq;
3043

3044
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3045
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3046

3047
typedef struct {
3048
  union {
3049
    int32_t compactId;
3050
    int32_t id;
3051
  };
3052
  int32_t vgId;
3053
  int32_t dnodeId;
3054
  int32_t numberFileset;
3055
  int32_t finished;
3056
  int32_t progress;
3057
  int64_t remainingTime;
3058
} SQueryCompactProgressRsp;
3059

3060
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3061
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3062

3063
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3064
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3065

3066
typedef struct {
3067
  int32_t vgId;
3068
  int32_t dnodeId;
3069
  int64_t dbUid;
3070
  char    db[TSDB_DB_FNAME_LEN];
3071
  int64_t reserved[8];
3072
} SDropVnodeReq;
3073

3074
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3075
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3076

3077
typedef struct {
3078
  char    colName[TSDB_COL_NAME_LEN];
3079
  char    stb[TSDB_TABLE_FNAME_LEN];
3080
  int64_t stbUid;
3081
  int64_t dbUid;
3082
  int64_t reserved[8];
3083
} SDropIndexReq;
3084

3085
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3086
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3087

3088
typedef struct {
3089
  int64_t dbUid;
3090
  char    db[TSDB_DB_FNAME_LEN];
3091
  union {
3092
    int64_t compactStartTime;
3093
    int64_t startTime;
3094
  };
3095

3096
  STimeWindow tw;
3097
  union {
3098
    int32_t compactId;
3099
    int32_t id;
3100
  };
3101
  int8_t metaOnly;
3102
  union {
3103
    uint16_t flags;
3104
    struct {
3105
      uint16_t optrType : 3;     // ETsdbOpType
3106
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3107
      uint16_t reserved : 12;
3108
    };
3109
  };
3110
  int8_t force;  // force compact
3111
} SCompactVnodeReq;
3112

3113
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3114
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3115

3116
typedef struct {
3117
  union {
3118
    int32_t compactId;
3119
    int32_t taskId;
3120
  };
3121
  int32_t vgId;
3122
  int32_t dnodeId;
3123
} SVKillCompactReq;
3124

3125
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3126
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3127

3128
typedef SVKillCompactReq SVKillRetentionReq;
3129

3130
typedef struct {
3131
  char        db[TSDB_DB_FNAME_LEN];
3132
  int32_t     maxSpeed;
3133
  int32_t     sqlLen;
3134
  char*       sql;
3135
  SArray*     vgroupIds;
3136
  STimeWindow tw;  // unit is second
3137
  union {
3138
    uint32_t flags;
3139
    struct {
3140
      uint32_t optrType : 3;     // ETsdbOpType
3141
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3142
      uint32_t reserved : 28;
3143
    };
3144
  };
3145
} STrimDbReq;
3146

3147
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3148
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3149
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3150

3151
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3152

3153
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3154
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3155

3156
typedef struct {
3157
  int32_t vgVersion;
3158
  int32_t buffer;
3159
  int32_t pageSize;
3160
  int32_t pages;
3161
  int32_t cacheLastSize;
3162
  int32_t daysPerFile;
3163
  int32_t daysToKeep0;
3164
  int32_t daysToKeep1;
3165
  int32_t daysToKeep2;
3166
  int32_t keepTimeOffset;
3167
  int32_t walFsyncPeriod;
3168
  int8_t  walLevel;
3169
  int8_t  strict;
3170
  int8_t  cacheLast;
3171
  int64_t reserved[7];
3172
  // 1st modification
3173
  int16_t sttTrigger;
3174
  int32_t minRows;
3175
  // 2nd modification
3176
  int32_t walRetentionPeriod;
3177
  int32_t walRetentionSize;
3178
  int32_t ssKeepLocal;
3179
  int8_t  ssCompact;
3180
  int8_t  allowDrop;
3181
} SAlterVnodeConfigReq;
3182

3183
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3184
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3185

3186
typedef struct {
3187
  int32_t  vgId;
3188
  int8_t   strict;
3189
  int8_t   selfIndex;
3190
  int8_t   replica;
3191
  SReplica replicas[TSDB_MAX_REPLICA];
3192
  int64_t  reserved[8];
3193
  int8_t   learnerSelfIndex;
3194
  int8_t   learnerReplica;
3195
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3196
  int32_t  changeVersion;
3197
  int32_t  electBaseLine;
3198
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3199

3200
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3201
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3202

3203
typedef struct {
3204
  int32_t vgId;
3205
  int8_t  disable;
3206
} SDisableVnodeWriteReq;
3207

3208
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3209
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3210

3211
typedef struct {
3212
  int32_t  srcVgId;
3213
  int32_t  dstVgId;
3214
  uint32_t hashBegin;
3215
  uint32_t hashEnd;
3216
  int32_t  changeVersion;
3217
  int32_t  reserved;
3218
} SAlterVnodeHashRangeReq;
3219

3220
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3221
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3222

3223
#define REQ_OPT_TBNAME 0x0
3224
#define REQ_OPT_TBUID  0x01
3225
typedef struct {
3226
  SMsgHead header;
3227
  char     dbFName[TSDB_DB_FNAME_LEN];
3228
  char     tbName[TSDB_TABLE_NAME_LEN];
3229
  uint8_t  option;
3230
  uint8_t  autoCreateCtb;
3231
} STableInfoReq;
3232

3233
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3234
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3235

3236
typedef struct {
3237
  int8_t  metaClone;  // create local clone of the cached table meta
3238
  int32_t numOfVgroups;
3239
  int32_t numOfTables;
3240
  int32_t numOfUdfs;
3241
  char    tableNames[];
3242
} SMultiTableInfoReq;
3243

3244
// todo refactor
3245
typedef struct SVgroupInfo {
3246
  int32_t  vgId;
3247
  uint32_t hashBegin;
3248
  uint32_t hashEnd;
3249
  SEpSet   epSet;
3250
  union {
3251
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3252
    int32_t taskId;      // used in stream
3253
  };
3254
} SVgroupInfo;
3255

3256
typedef struct {
3257
  int32_t     numOfVgroups;
3258
  SVgroupInfo vgroups[];
3259
} SVgroupsInfo;
3260

3261
typedef struct {
3262
  STableMetaRsp* pMeta;
3263
} SMAlterStbRsp;
3264

3265
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3266
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3267
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3268

3269
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3270
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3271
void    tFreeSTableMetaRsp(void* pRsp);
3272
void    tFreeSTableIndexRsp(void* info);
3273

3274
typedef struct {
3275
  SArray* pMetaRsp;   // Array of STableMetaRsp
3276
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3277
} SSTbHbRsp;
3278

3279
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3280
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3281
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3282

3283
typedef struct {
3284
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3285
} SViewHbRsp;
3286

3287
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3288
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3289
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3290

3291
typedef struct {
3292
  int32_t numOfTables;
3293
  int32_t numOfVgroup;
3294
  int32_t numOfUdf;
3295
  int32_t contLen;
3296
  int8_t  compressed;  // denote if compressed or not
3297
  int32_t rawLen;      // size before compress
3298
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3299
  char    meta[];
3300
} SMultiTableMeta;
3301

3302
typedef struct {
3303
  int32_t dataLen;
3304
  char    name[TSDB_TABLE_FNAME_LEN];
3305
  char*   data;
3306
} STagData;
3307

3308
typedef struct {
3309
  int32_t  opType;
3310
  uint32_t valLen;
3311
  char*    val;
3312
} SShowVariablesReq;
3313

3314
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3315
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3316
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3317

3318
typedef struct {
3319
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3320
  char value[TSDB_CONFIG_PATH_LEN + 1];
3321
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3322
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3323
  char info[TSDB_CONFIG_INFO_LEN + 1];
3324
} SVariablesInfo;
3325

3326
typedef struct {
3327
  SArray* variables;  // SArray<SVariablesInfo>
3328
} SShowVariablesRsp;
3329

3330
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3331
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3332

3333
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3334

3335
/*
3336
 * sql: show tables like '%a_%'
3337
 * payload is the query condition, e.g., '%a_%'
3338
 * payloadLen is the length of payload
3339
 */
3340
typedef struct {
3341
  int32_t type;
3342
  char    db[TSDB_DB_FNAME_LEN];
3343
  int32_t payloadLen;
3344
  char*   payload;
3345
} SShowReq;
3346

3347
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3348
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3349
void tFreeSShowReq(SShowReq* pReq);
3350

3351
typedef struct {
3352
  int64_t       showId;
3353
  STableMetaRsp tableMeta;
3354
} SShowRsp, SVShowTablesRsp;
3355

3356
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3357
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3358
// void    tFreeSShowRsp(SShowRsp* pRsp);
3359

3360
typedef struct {
3361
  char    db[TSDB_DB_FNAME_LEN];
3362
  char    tb[TSDB_TABLE_NAME_LEN];
3363
  char    user[TSDB_USER_LEN];
3364
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3365
  int64_t showId;
3366
  int64_t compactId;  // for compact
3367
  bool    withFull;   // for show users full
3368
} SRetrieveTableReq;
3369

3370
typedef struct SSysTableSchema {
3371
  int8_t   type;
3372
  col_id_t colId;
3373
  int32_t  bytes;
3374
} SSysTableSchema;
3375

3376
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3377
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3378

3379
#define RETRIEVE_TABLE_RSP_VERSION         0
3380
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3381
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3382

3383
typedef struct {
3384
  int64_t useconds;
3385
  int8_t  completed;  // all results are returned to client
3386
  int8_t  precision;
3387
  int8_t  compressed;
3388
  int8_t  streamBlockType;
3389
  int32_t payloadLen;
3390
  int32_t compLen;
3391
  int32_t numOfBlocks;
3392
  int64_t numOfRows;  // from int32_t change to int64_t
3393
  int64_t numOfCols;
3394
  int64_t skey;
3395
  int64_t ekey;
3396
  int64_t version;                         // for stream
3397
  TSKEY   watermark;                       // for stream
3398
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3399
  char    data[];
3400
} SRetrieveTableRsp;
3401

3402
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3403

3404
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3405
  do {                                          \
3406
    ((int32_t*)(_p))[0] = (_compLen);           \
3407
    ((int32_t*)(_p))[1] = (_fullLen);           \
3408
  } while (0);
3409

3410
typedef struct {
3411
  int64_t version;
3412
  int64_t numOfRows;
3413
  int8_t  compressed;
3414
  int8_t  precision;
3415
  char    data[];
3416
} SRetrieveTableRspForTmq;
3417

3418
typedef struct {
3419
  int64_t handle;
3420
  int64_t useconds;
3421
  int8_t  completed;  // all results are returned to client
3422
  int8_t  precision;
3423
  int8_t  compressed;
3424
  int32_t compLen;
3425
  int32_t numOfRows;
3426
  int32_t fullLen;
3427
  char    data[];
3428
} SRetrieveMetaTableRsp;
3429

3430
typedef struct SExplainExecInfo {
3431
  double   startupCost;
3432
  double   totalCost;
3433
  uint64_t numOfRows;
3434
  uint32_t verboseLen;
3435
  void*    verboseInfo;
3436
} SExplainExecInfo;
3437

3438
typedef struct {
3439
  int32_t           numOfPlans;
3440
  SExplainExecInfo* subplanInfo;
3441
} SExplainRsp;
3442

3443
typedef struct {
3444
  SExplainRsp rsp;
3445
  uint64_t    qId;
3446
  uint64_t    cId;
3447
  uint64_t    tId;
3448
  int64_t     rId;
3449
  int32_t     eId;
3450
} SExplainLocalRsp;
3451

3452
typedef struct STableScanAnalyzeInfo {
3453
  uint64_t totalRows;
3454
  uint64_t totalCheckedRows;
3455
  uint32_t totalBlocks;
3456
  uint32_t loadBlocks;
3457
  uint32_t loadBlockStatis;
3458
  uint32_t skipBlocks;
3459
  uint32_t filterOutBlocks;
3460
  double   elapsedTime;
3461
  double   filterTime;
3462
} STableScanAnalyzeInfo;
3463

3464
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3465
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3466
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3467

3468
typedef struct {
3469
  char    config[TSDB_DNODE_CONFIG_LEN];
3470
  char    value[TSDB_CLUSTER_VALUE_LEN];
3471
  int32_t sqlLen;
3472
  char*   sql;
3473
} SMCfgClusterReq;
3474

3475
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3476
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3477
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3478

3479
typedef struct {
3480
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3481
  int32_t port;
3482
  int32_t sqlLen;
3483
  char*   sql;
3484
} SCreateDnodeReq;
3485

3486
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3487
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3488
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3489

3490
typedef struct {
3491
  int32_t dnodeId;
3492
  char    fqdn[TSDB_FQDN_LEN];
3493
  int32_t port;
3494
  int8_t  force;
3495
  int8_t  unsafe;
3496
  int32_t sqlLen;
3497
  char*   sql;
3498
} SDropDnodeReq;
3499

3500
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3501
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3502
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3503

3504
enum {
3505
  RESTORE_TYPE__ALL = 1,
3506
  RESTORE_TYPE__MNODE,
3507
  RESTORE_TYPE__VNODE,
3508
  RESTORE_TYPE__QNODE,
3509
};
3510

3511
typedef struct {
3512
  int32_t dnodeId;
3513
  int8_t  restoreType;
3514
  int32_t sqlLen;
3515
  char*   sql;
3516
} SRestoreDnodeReq;
3517

3518
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3519
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3520
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3521

3522
typedef struct {
3523
  int32_t dnodeId;
3524
  char    config[TSDB_DNODE_CONFIG_LEN];
3525
  char    value[TSDB_DNODE_VALUE_LEN];
3526
  int32_t sqlLen;
3527
  char*   sql;
3528
} SMCfgDnodeReq;
3529

3530
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3531
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3532
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3533

3534
typedef struct {
3535
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3536
  char    newKey[ENCRYPT_KEY_LEN + 1];
3537
  int32_t sqlLen;
3538
  char*   sql;
3539
} SMAlterEncryptKeyReq;
3540

3541
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3542
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3543
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3544

3545
typedef struct {
3546
  int32_t days;
3547
  char    strategy[64];
3548
  int32_t sqlLen;
3549
  char*   sql;
3550
} SMAlterKeyExpirationReq;
3551

3552
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3553
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3554
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3555

3556
typedef struct {
3557
  char    config[TSDB_DNODE_CONFIG_LEN];
3558
  char    value[TSDB_DNODE_VALUE_LEN];
3559
  int32_t version;
3560
} SDCfgDnodeReq;
3561

3562
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3563
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3564

3565
typedef struct {
3566
  int32_t dnodeId;
3567
  int32_t sqlLen;
3568
  char*   sql;
3569
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3570
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3571

3572
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3573
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3574

3575
typedef struct {
3576
  int32_t nodeId;
3577
  SEpSet  epSet;
3578
} SNodeEpSet;
3579

3580
typedef struct {
3581
  int32_t    snodeId;
3582
  SNodeEpSet leaders[2];
3583
  SNodeEpSet replica;
3584
  int32_t    sqlLen;
3585
  char*      sql;
3586
} SDCreateSnodeReq;
3587

3588
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3589
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3590
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3591

3592
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3593
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3594
typedef struct {
3595
  int8_t   replica;
3596
  SReplica replicas[TSDB_MAX_REPLICA];
3597
  int8_t   learnerReplica;
3598
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3599
  int64_t  lastIndex;
3600
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3601
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3602

3603
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3604
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3605

3606
typedef struct {
3607
  int32_t urlLen;
3608
  int32_t sqlLen;
3609
  char*   url;
3610
  char*   sql;
3611
} SMCreateAnodeReq;
3612

3613
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3614
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3615
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3616

3617
typedef struct {
3618
  int32_t anodeId;
3619
  int32_t sqlLen;
3620
  char*   sql;
3621
} SMDropAnodeReq, SMUpdateAnodeReq;
3622

3623
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3624
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3625
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3626
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3627
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3628
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3629

3630
typedef struct {
3631
  int32_t dnodeId;
3632
  int32_t bnodeProto;
3633
  int32_t sqlLen;
3634
  char*   sql;
3635
} SMCreateBnodeReq, SDCreateBnodeReq;
3636

3637
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3638
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3639
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3640

3641
typedef struct {
3642
  int32_t dnodeId;
3643
  int32_t sqlLen;
3644
  char*   sql;
3645
} SMDropBnodeReq, SDDropBnodeReq;
3646

3647
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3648
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3649
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3650

3651
typedef struct {
3652
  int32_t sqlLen;
3653
  int32_t urlLen;
3654
  int32_t userLen;
3655
  int32_t passLen;
3656
  int32_t passIsMd5;
3657
  char*   sql;
3658
  char*   url;
3659
  char*   user;
3660
  char*   pass;
3661
} SMCreateXnodeReq, SDCreateXnodeReq;
3662

3663
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3664
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3665
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3666

3667
typedef struct {
3668
  int32_t xnodeId;
3669
  int32_t force;
3670
  int32_t urlLen;
3671
  int32_t sqlLen;
3672
  char*   url;
3673
  char*   sql;
3674
} SMDropXnodeReq, SMUpdateXnodeReq, SDDropXnodeReq;
3675

3676
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3677
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3678
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3679
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3680
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3681
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3682

3683
typedef struct {
3684
  int32_t xnodeId;
3685
  int32_t sqlLen;
3686
  char*   sql;
3687
} SMDrainXnodeReq;
3688
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3689
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3690
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3691

3692
typedef struct {
3693
  bool        shouldFree;
3694
  int32_t     len;
3695
  const char* ptr;
3696
} CowStr;
3697
/**
3698
 * @brief Create a CowStr object.
3699
 *
3700
 * @param len: length of the string.
3701
 * @param ptr: pointer to the string input.
3702
 * @param shouldClone: whether to clone the string.
3703
 * @return CowStr object.
3704
 */
3705
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3706
/**
3707
 * @brief Set a CowStr object with given string.
3708
 *
3709
 * @param cow: pointer to the CowStr object.
3710
 * @param len: length of the string.
3711
 * @param ptr: pointer to the string input.
3712
 * @param shouldFree: whether to free the string.
3713
 */
3714
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3715
/**
3716
 * @brief Clone a CowStr object without copy the string.
3717
 *
3718
 * @param cow: pointer to the CowStr object.
3719
 * @return CowStr object.
3720
 */
3721
CowStr xCloneRefCowStr(CowStr* cow);
3722
/**
3723
 * @brief Convert a CowStr object to a string.
3724
 *
3725
 * @param cow: pointer to the CowStr object.
3726
 */
3727
char* xCowStrToStr(CowStr* cow);
3728
/**
3729
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3730
 *
3731
 * @param cow: pointer to the CowStr object.
3732
 */
3733
void xFreeCowStr(CowStr* cow);
3734
/**
3735
 * @brief Encode and push a CowStr object into the encoder.
3736
 *
3737
 * @param encoder
3738
 * @param cow
3739
 * @return int32_t
3740
 */
3741
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3742
/**
3743
 * @brief Decode a CowStr from the encoder.
3744
 *
3745
 * @param decoder
3746
 * @param cow
3747
 * @param shouldClone
3748
 * @return int32_t
3749
 */
3750
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3751

3752
typedef enum {
3753
  XNODE_TASK_SOURCE_DSN = 1,
3754
  XNODE_TASK_SOURCE_DATABASE,
3755
  XNODE_TASK_SOURCE_TOPIC,
3756
} ENodeXTaskSourceType;
3757

3758
typedef enum {
3759
  XNODE_TASK_SINK_DSN = 1,
3760
  XNODE_TASK_SINK_DATABASE,
3761
} ENodeXTaskSinkType;
3762

3763
typedef struct {
3764
  ENodeXTaskSourceType type;
3765
  CowStr               cstr;
3766
} xTaskSource;
3767
/**
3768
 * @brief Deallocate a xTaskSource object.
3769
 *
3770
 * @param source ptr
3771
 */
3772
void xFreeTaskSource(xTaskSource* source);
3773
/**
3774
 * @brief Create a xTaskSource object with cloned source string.
3775
 *
3776
 * @param sourceType: source type.
3777
 * @param len: length of source string.
3778
 * @param source: source string ptr.
3779
 * @return xTaskSource object
3780
 */
3781
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3782
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3783
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3784
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3785
const char* xGetTaskSourceStr(xTaskSource* source);
3786
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3787
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3788

3789
typedef struct {
3790
  ENodeXTaskSinkType type;
3791
  CowStr             cstr;
3792
} xTaskSink;
3793
/**
3794
 * @brief Deallocate a xTaskSink object.
3795
 *
3796
 * @param sink ptr
3797
 */
3798
void xFreeTaskSink(xTaskSink* sink);
3799
/**
3800
 * @brief Create a xTaskSink object with cloned name string.
3801
 *
3802
 * @param sinkType: sink type.
3803
 * @param len: length of sink string.
3804
 * @param ptr: sink string ptr.
3805
 * @return xTaskSink object
3806
 */
3807
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3808
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3809
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3810
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3811
const char* xGetTaskSinkStr(xTaskSink* sink);
3812
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3813
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3814

3815
typedef struct {
3816
  int32_t via;
3817
  CowStr  parser;
3818
  // CowStr  reason;
3819
  CowStr  trigger;
3820
  CowStr  health;
3821
  int32_t optionsNum;
3822
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3823
} xTaskOptions;
3824
/**
3825
 * @brief Deallocate a xTaskOptions object.
3826
 *
3827
 * @param options ptr
3828
 */
3829
void    xFreeTaskOptions(xTaskOptions* options);
3830
void    printXnodeTaskOptions(xTaskOptions* options);
3831
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3832
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3833

3834
typedef struct {
3835
  int32_t sqlLen;
3836
  char*   sql;
3837
  int32_t      xnodeId;
3838
  CowStr       name;
3839
  xTaskSource  source;
3840
  xTaskSink    sink;
3841
  xTaskOptions options;
3842
} SMCreateXnodeTaskReq;
3843
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3844
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3845
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3846

3847
typedef struct {
3848
  int32_t     tid;
3849
  CowStr      name;
3850
  int32_t     via;
3851
  int32_t     xnodeId;
3852
  CowStr      status;
3853
  xTaskSource source;
3854
  xTaskSink   sink;
3855
  CowStr      parser;
3856
  CowStr      reason;
3857
  CowStr      updateName;
3858
  CowStr      labels;
3859
  int32_t     sqlLen;
3860
  char*       sql;
3861
} SMUpdateXnodeTaskReq;
3862
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3863
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3864
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3865

3866
typedef struct {
3867
  int32_t id;
3868
  bool    force;
3869
  CowStr  name;
3870
  int32_t sqlLen;
3871
  char*   sql;
3872
} SMDropXnodeTaskReq;
3873
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3874
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3875
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3876

3877
typedef struct {
3878
  int32_t tid;
3879
  CowStr  name;
3880
  int32_t sqlLen;
3881
  char*   sql;
3882
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3883
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3884
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3885
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3886

3887
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3888
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3889
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3890

3891
typedef struct {
3892
  int32_t tid;
3893
  int32_t via;
3894
  int32_t xnodeId;
3895
  CowStr  status;
3896
  CowStr  config;
3897
  CowStr  reason;
3898
  int32_t sqlLen;
3899
  char*   sql;
3900
} SMCreateXnodeJobReq;
3901
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3902
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3903
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3904

3905
typedef struct {
3906
  int32_t jid;
3907
  int32_t via;
3908
  int32_t xnodeId;
3909
  CowStr  status;
3910
  int32_t configLen;
3911
  int32_t reasonLen;
3912
  int32_t sqlLen;
3913
  char*   config;
3914
  char*   reason;
3915
  char*   sql;
3916
} SMUpdateXnodeJobReq;
3917
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3918
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3919
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3920

3921
typedef struct {
3922
  int32_t jid;
3923
  int32_t xnodeId;
3924
  int32_t sqlLen;
3925
  char*   sql;
3926
} SMRebalanceXnodeJobReq;
3927
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3928
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3929
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3930

3931
typedef struct {
3932
  CowStr  ast;
3933
  int32_t sqlLen;
3934
  char*   sql;
3935
} SMRebalanceXnodeJobsWhereReq;
3936
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3937
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3938
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3939

3940
typedef struct {
3941
  int32_t jid;
3942
  CowStr  ast;
3943
  int32_t sqlLen;
3944
  char*   sql;
3945
} SMDropXnodeJobReq;
3946
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3947
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3948
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3949

3950
typedef struct {
3951
  int32_t      sqlLen;
3952
  char*        sql;
3953
  CowStr       name;
3954
  CowStr       status;
3955
  xTaskOptions options;
3956
} SMCreateXnodeAgentReq;
3957
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3958
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3959
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
3960

3961
typedef struct {
3962
  int32_t      sqlLen;
3963
  char*        sql;
3964
  int32_t      id;
3965
  CowStr       name;
3966
  xTaskOptions options;
3967
} SMUpdateXnodeAgentReq;
3968
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3969
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3970
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
3971

3972
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
3973
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
3974
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
3975
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
3976

3977
typedef struct {
3978
  int32_t vgId;
3979
  int32_t hbSeq;
3980
} SVArbHbReqMember;
3981

3982
typedef struct {
3983
  int32_t dnodeId;
3984
  char*   arbToken;
3985
  int64_t arbTerm;
3986
  SArray* hbMembers;  // SVArbHbReqMember
3987
} SVArbHeartBeatReq;
3988

3989
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3990
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3991
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3992

3993
typedef struct {
3994
  int32_t vgId;
3995
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3996
  int32_t hbSeq;
3997
} SVArbHbRspMember;
3998

3999
typedef struct {
4000
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4001
  int32_t dnodeId;
4002
  SArray* hbMembers;  // SVArbHbRspMember
4003
} SVArbHeartBeatRsp;
4004

4005
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4006
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4007
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4008

4009
typedef struct {
4010
  char*   arbToken;
4011
  int64_t arbTerm;
4012
  char*   member0Token;
4013
  char*   member1Token;
4014
} SVArbCheckSyncReq;
4015

4016
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4017
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4018
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4019

4020
typedef struct {
4021
  char*   arbToken;
4022
  char*   member0Token;
4023
  char*   member1Token;
4024
  int32_t vgId;
4025
  int32_t errCode;
4026
} SVArbCheckSyncRsp;
4027

4028
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4029
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4030
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4031

4032
typedef struct {
4033
  char*   arbToken;
4034
  int64_t arbTerm;
4035
  char*   memberToken;
4036
  int8_t  force;
4037
} SVArbSetAssignedLeaderReq;
4038

4039
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4040
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4041
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4042

4043
typedef struct {
4044
  char*   arbToken;
4045
  char*   memberToken;
4046
  int32_t vgId;
4047
} SVArbSetAssignedLeaderRsp;
4048

4049
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4050
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4051
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4052

4053
typedef struct {
4054
  int32_t dnodeId;
4055
  char*   token;
4056
} SMArbUpdateGroupMember;
4057

4058
typedef struct {
4059
  int32_t dnodeId;
4060
  char*   token;
4061
  int8_t  acked;
4062
} SMArbUpdateGroupAssigned;
4063

4064
typedef struct {
4065
  int32_t                  vgId;
4066
  int64_t                  dbUid;
4067
  SMArbUpdateGroupMember   members[2];
4068
  int8_t                   isSync;
4069
  int8_t                   assignedAcked;
4070
  SMArbUpdateGroupAssigned assignedLeader;
4071
  int64_t                  version;
4072
  int32_t                  code;
4073
  int64_t                  updateTimeMs;
4074
} SMArbUpdateGroup;
4075

4076
typedef struct {
4077
  SArray* updateArray;  // SMArbUpdateGroup
4078
} SMArbUpdateGroupBatchReq;
4079

4080
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4081
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4082
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4083

4084
typedef struct {
4085
  char queryStrId[TSDB_QUERY_ID_LEN];
4086
} SKillQueryReq;
4087

4088
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4089
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4090

4091
typedef struct {
4092
  uint32_t connId;
4093
} SKillConnReq;
4094

4095
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4096
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4097

4098
typedef struct {
4099
  int32_t transId;
4100
} SKillTransReq;
4101

4102
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4103
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4104

4105
typedef struct {
4106
  int32_t useless;  // useless
4107
  int32_t sqlLen;
4108
  char*   sql;
4109
} SBalanceVgroupReq;
4110

4111
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4112
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4113
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4114

4115
typedef struct {
4116
  int32_t useless;  // useless
4117
  int32_t sqlLen;
4118
  char*   sql;
4119
} SAssignLeaderReq;
4120

4121
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4122
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4123
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4124
typedef struct {
4125
  int32_t vgId1;
4126
  int32_t vgId2;
4127
} SMergeVgroupReq;
4128

4129
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4130
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4131

4132
typedef struct {
4133
  int32_t vgId;
4134
  int32_t dnodeId1;
4135
  int32_t dnodeId2;
4136
  int32_t dnodeId3;
4137
  int32_t sqlLen;
4138
  char*   sql;
4139
} SRedistributeVgroupReq;
4140

4141
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4142
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4143
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4144

4145
typedef struct {
4146
  int32_t reserved;
4147
  int32_t vgId;
4148
  int32_t sqlLen;
4149
  char*   sql;
4150
  char    db[TSDB_DB_FNAME_LEN];
4151
} SBalanceVgroupLeaderReq;
4152

4153
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4154
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4155
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4156

4157
typedef struct {
4158
  int32_t vgId;
4159
} SForceBecomeFollowerReq;
4160

4161
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4162
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4163

4164
typedef struct {
4165
  int32_t vgId;
4166
  bool    force;
4167
} SSplitVgroupReq;
4168

4169
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4170
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4171

4172
typedef struct {
4173
  char user[TSDB_USER_LEN];
4174
  char spi;
4175
  char encrypt;
4176
  char secret[TSDB_PASSWORD_LEN];
4177
  char ckey[TSDB_PASSWORD_LEN];
4178
} SAuthReq, SAuthRsp;
4179

4180
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4181
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4182

4183
typedef struct {
4184
  int32_t statusCode;
4185
  char    details[1024];
4186
} SServerStatusRsp;
4187

4188
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4189
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4190

4191
/**
4192
 * The layout of the query message payload is as following:
4193
 * +--------------------+---------------------------------+
4194
 * |Sql statement       | Physical plan                   |
4195
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4196
 * +--------------------+---------------------------------+
4197
 */
4198
typedef struct SSubQueryMsg {
4199
  SMsgHead header;
4200
  uint64_t sId;
4201
  uint64_t queryId;
4202
  uint64_t clientId;
4203
  uint64_t taskId;
4204
  int64_t  refId;
4205
  int32_t  execId;
4206
  int32_t  msgMask;
4207
  int32_t  subQType;
4208
  int8_t   taskType;
4209
  int8_t   explain;
4210
  int8_t   needFetch;
4211
  int8_t   compress;
4212
  uint32_t sqlLen;
4213
  char*    sql;
4214
  uint32_t msgLen;
4215
  char*    msg;
4216
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4217
} SSubQueryMsg;
4218

4219
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4220
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4221
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4222

4223
typedef struct {
4224
  SMsgHead header;
4225
  uint64_t sId;
4226
  uint64_t queryId;
4227
  uint64_t taskId;
4228
} SSinkDataReq;
4229

4230
typedef struct {
4231
  SMsgHead header;
4232
  uint64_t sId;
4233
  uint64_t queryId;
4234
  uint64_t clientId;
4235
  uint64_t taskId;
4236
  int32_t  execId;
4237
} SQueryContinueReq;
4238

4239
typedef struct {
4240
  SMsgHead header;
4241
  uint64_t sId;
4242
  uint64_t queryId;
4243
  uint64_t taskId;
4244
} SResReadyReq;
4245

4246
typedef struct {
4247
  int32_t code;
4248
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4249
  int32_t sversion;
4250
  int32_t tversion;
4251
} SResReadyRsp;
4252

4253
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4254

4255
typedef struct SOperatorParam {
4256
  int32_t opType;
4257
  int32_t downstreamIdx;
4258
  void*   value;
4259
  SArray* pChildren;  // SArray<SOperatorParam*>
4260
  bool    reUse;
4261
} SOperatorParam;
4262

4263
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4264

4265
// virtual table's colId to origin table's colname
4266
typedef struct SColIdNameKV {
4267
  col_id_t colId;
4268
  char     colName[TSDB_COL_NAME_LEN];
4269
} SColIdNameKV;
4270

4271
#define COL_MASK_ON   ((int8_t)0x1)
4272
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4273
#define COL_SET_MASK_ON(c)     \
4274
  do {                         \
4275
    (c)->flags |= COL_MASK_ON; \
4276
  } while (0)
4277

4278
typedef struct SColNameFlag {
4279
  col_id_t colId;
4280
  char     colName[TSDB_COL_NAME_LEN];
4281
  int8_t   flags;  // 0x01: COL_MASK_ON
4282
} SColNameFlag;
4283

4284
typedef struct SColIdPair {
4285
  col_id_t  vtbColId;
4286
  col_id_t  orgColId;
4287
  SDataType type;
4288
} SColIdPair;
4289

4290
typedef struct SColIdSlotIdPair {
4291
  int32_t  vtbSlotId;
4292
  col_id_t orgColId;
4293
} SColIdSlotIdPair;
4294

4295
typedef struct SOrgTbInfo {
4296
  int32_t vgId;
4297
  char    tbName[TSDB_TABLE_FNAME_LEN];
4298
  SArray* colMap;  // SArray<SColIdNameKV>
4299
} SOrgTbInfo;
4300

4301
void destroySOrgTbInfo(void *info);
4302

4303
typedef enum {
4304
  DYN_TYPE_STB_JOIN = 1,
4305
  DYN_TYPE_VSTB_SINGLE_SCAN,
4306
  DYN_TYPE_VSTB_BATCH_SCAN,
4307
  DYN_TYPE_VSTB_WIN_SCAN,
4308
} ETableScanDynType;
4309

4310
typedef enum {
4311
  DYN_TYPE_SCAN_PARAM = 1,
4312
  NOTIFY_TYPE_SCAN_PARAM,
4313
} ETableScanGetParamType;
4314

4315
typedef struct STableScanOperatorParam {
4316
  ETableScanGetParamType paramType;
4317
  /* for building scan data source */
4318
  bool                   tableSeq;
4319
  bool                   isNewParam;
4320
  uint64_t               groupid;
4321
  SArray*                pUidList;
4322
  SOrgTbInfo*            pOrgTbInfo;
4323
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4324
  SArray*                pTagList;
4325
  STimeWindow            window;
4326
  ETableScanDynType      dynType;
4327
  /* for notifying source step done */
4328
  bool                   notifyToProcess;  // received notify STEP DONE message
4329
  TSKEY                  notifyTs;         // notify timestamp
4330
} STableScanOperatorParam;
4331

4332
typedef struct STagScanOperatorParam {
4333
  tb_uid_t vcUid;
4334
} STagScanOperatorParam;
4335

4336
typedef struct SRefColIdGroup {
4337
  SArray* pSlotIdList;  // SArray<int32_t>
4338
} SRefColIdGroup;
4339

4340
typedef struct SVTableScanOperatorParam {
4341
  uint64_t        uid;
4342
  STimeWindow     window;
4343
  SOperatorParam* pTagScanOp;
4344
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4345
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4346
} SVTableScanOperatorParam;
4347

4348
typedef struct SMergeOperatorParam {
4349
  int32_t         winNum;
4350
} SMergeOperatorParam;
4351

4352
typedef struct SAggOperatorParam {
4353
  bool            needCleanRes;
4354
} SAggOperatorParam;
4355

4356
typedef struct SExternalWindowOperatorParam {
4357
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4358
} SExternalWindowOperatorParam;
4359

4360
typedef struct SDynQueryCtrlOperatorParam {
4361
  STimeWindow    window;
4362
} SDynQueryCtrlOperatorParam;
4363

4364
struct SStreamRuntimeFuncInfo;
4365
typedef struct {
4366
  SMsgHead        header;
4367
  uint64_t        sId;
4368
  uint64_t        queryId;
4369
  uint64_t        clientId;
4370
  uint64_t        taskId;
4371
  uint64_t        srcTaskId;  // used for subQ
4372
  uint64_t        blockIdx;   // used for subQ
4373
  int32_t         execId;
4374
  SOperatorParam* pOpParam;
4375

4376
  // used for new-stream
4377
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4378
  bool                           reset;
4379
  bool                           dynTbname;
4380
  // used for new-stream
4381
} SResFetchReq;
4382

4383
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4384
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4385
void    tDestroySResFetchReq(SResFetchReq* pReq);
4386
typedef struct {
4387
  SMsgHead header;
4388
  uint64_t clientId;
4389
} SSchTasksStatusReq;
4390

4391
typedef struct {
4392
  uint64_t queryId;
4393
  uint64_t clientId;
4394
  uint64_t taskId;
4395
  int64_t  refId;
4396
  int32_t  subJobId;
4397
  int32_t  execId;
4398
  int8_t   status;
4399
} STaskStatus;
4400

4401
typedef struct {
4402
  int64_t refId;
4403
  SArray* taskStatus;  // SArray<STaskStatus>
4404
} SSchedulerStatusRsp;
4405

4406
typedef struct {
4407
  uint64_t queryId;
4408
  uint64_t taskId;
4409
  int8_t   action;
4410
} STaskAction;
4411

4412
typedef struct SQueryNodeEpId {
4413
  int32_t nodeId;  // vgId or qnodeId
4414
  SEp     ep;
4415
} SQueryNodeEpId;
4416

4417
typedef struct {
4418
  SMsgHead       header;
4419
  uint64_t       clientId;
4420
  SQueryNodeEpId epId;
4421
  SArray*        taskAction;  // SArray<STaskAction>
4422
} SSchedulerHbReq;
4423

4424
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4425
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4426
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4427

4428
typedef struct {
4429
  SQueryNodeEpId epId;
4430
  SArray*        taskStatus;  // SArray<STaskStatus>
4431
} SSchedulerHbRsp;
4432

4433
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4434
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4435
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4436

4437
typedef struct {
4438
  SMsgHead header;
4439
  uint64_t sId;
4440
  uint64_t queryId;
4441
  uint64_t clientId;
4442
  uint64_t taskId;
4443
  int64_t  refId;
4444
  int32_t  execId;
4445
} STaskCancelReq;
4446

4447
typedef struct {
4448
  int32_t code;
4449
} STaskCancelRsp;
4450

4451
typedef struct {
4452
  SMsgHead header;
4453
  uint64_t sId;
4454
  uint64_t queryId;
4455
  uint64_t clientId;
4456
  uint64_t taskId;
4457
  int64_t  refId;
4458
  int32_t  execId;
4459
} STaskDropReq;
4460

4461
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4462
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4463

4464
typedef enum {
4465
  TASK_NOTIFY_FINISHED = 1,
4466
} ETaskNotifyType;
4467

4468
typedef struct {
4469
  SMsgHead        header;
4470
  uint64_t        sId;
4471
  uint64_t        queryId;
4472
  uint64_t        clientId;
4473
  uint64_t        taskId;
4474
  int64_t         refId;
4475
  int32_t         execId;
4476
  ETaskNotifyType type;
4477
} STaskNotifyReq;
4478

4479
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4480
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4481

4482
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4483
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4484

4485
typedef struct {
4486
  int32_t code;
4487
} STaskDropRsp;
4488

4489
#define STREAM_TRIGGER_AT_ONCE                 1
4490
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4491
#define STREAM_TRIGGER_MAX_DELAY               3
4492
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4493
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4494

4495
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4496
#define STREAM_FILL_HISTORY_ON        1
4497
#define STREAM_FILL_HISTORY_OFF       0
4498
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4499
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4500
#define STREAM_CREATE_STABLE_TRUE     1
4501
#define STREAM_CREATE_STABLE_FALSE    0
4502

4503
typedef struct SVgroupVer {
4504
  int32_t vgId;
4505
  int64_t ver;
4506
} SVgroupVer;
4507

4508
typedef struct STaskNotifyEventStat {
4509
  int64_t notifyEventAddTimes;     // call times of add function
4510
  int64_t notifyEventAddElems;     // elements added by add function
4511
  double  notifyEventAddCostSec;   // time cost of add function
4512
  int64_t notifyEventPushTimes;    // call times of push function
4513
  int64_t notifyEventPushElems;    // elements pushed by push function
4514
  double  notifyEventPushCostSec;  // time cost of push function
4515
  int64_t notifyEventPackTimes;    // call times of pack function
4516
  int64_t notifyEventPackElems;    // elements packed by pack function
4517
  double  notifyEventPackCostSec;  // time cost of pack function
4518
  int64_t notifyEventSendTimes;    // call times of send function
4519
  int64_t notifyEventSendElems;    // elements sent by send function
4520
  double  notifyEventSendCostSec;  // time cost of send function
4521
  int64_t notifyEventHoldElems;    // elements hold due to watermark
4522
} STaskNotifyEventStat;
4523

4524
enum {
4525
  TOPIC_SUB_TYPE__DB = 1,
4526
  TOPIC_SUB_TYPE__TABLE,
4527
  TOPIC_SUB_TYPE__COLUMN,
4528
};
4529

4530
#define DEFAULT_MAX_POLL_INTERVAL  300000
4531
#define DEFAULT_SESSION_TIMEOUT    12000
4532
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4533
#define DEFAULT_MIN_POLL_ROWS      4096
4534

4535
typedef struct {
4536
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4537
  int8_t igExists;
4538
  int8_t subType;
4539
  int8_t withMeta;
4540
  char*  sql;
4541
  char   subDbName[TSDB_DB_FNAME_LEN];
4542
  char*  ast;
4543
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4544
  int8_t reload;
4545
} SCMCreateTopicReq;
4546

4547
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4548
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4549
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4550

4551
typedef struct {
4552
  int64_t consumerId;
4553
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4554

4555
typedef struct {
4556
  int64_t consumerId;
4557
  char    cgroup[TSDB_CGROUP_LEN];
4558
  char    clientId[TSDB_CLIENT_ID_LEN];
4559
  char    user[TSDB_USER_LEN];
4560
  char    fqdn[TSDB_FQDN_LEN];
4561
  SArray* topicNames;  // SArray<char**>
4562

4563
  int8_t  withTbName;
4564
  int8_t  autoCommit;
4565
  int32_t autoCommitInterval;
4566
  int8_t  resetOffsetCfg;
4567
  int8_t  enableReplay;
4568
  int8_t  enableBatchMeta;
4569
  int32_t sessionTimeoutMs;
4570
  int32_t maxPollIntervalMs;
4571
  int64_t ownerId;
4572
} SCMSubscribeReq;
4573

4574
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4575
  int32_t tlen = 0;
678,572✔
4576
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
678,572✔
4577
  tlen += taosEncodeString(buf, pReq->cgroup);
678,572✔
4578
  tlen += taosEncodeString(buf, pReq->clientId);
678,572✔
4579

4580
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
678,572✔
4581
  tlen += taosEncodeFixedI32(buf, topicNum);
678,562✔
4582

4583
  for (int32_t i = 0; i < topicNum; i++) {
944,130✔
4584
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
531,136✔
4585
  }
4586

4587
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
678,562✔
4588
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
678,562✔
4589
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
678,562✔
4590
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
678,562✔
4591
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
678,562✔
4592
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
678,562✔
4593
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
678,562✔
4594
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
678,562✔
4595
  tlen += taosEncodeString(buf, pReq->user);
678,562✔
4596
  tlen += taosEncodeString(buf, pReq->fqdn);
678,562✔
4597

4598
  return tlen;
678,562✔
4599
}
4600

4601
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4602
  void* start = buf;
350,254✔
4603
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
350,254✔
4604
  buf = taosDecodeStringTo(buf, pReq->cgroup);
350,254✔
4605
  buf = taosDecodeStringTo(buf, pReq->clientId);
350,254✔
4606

4607
  int32_t topicNum = 0;
350,254✔
4608
  buf = taosDecodeFixedI32(buf, &topicNum);
350,254✔
4609

4610
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
350,254✔
4611
  if (pReq->topicNames == NULL) {
350,254✔
UNCOV
4612
    return terrno;
×
4613
  }
4614
  for (int32_t i = 0; i < topicNum; i++) {
507,443✔
4615
    char* name = NULL;
157,189✔
4616
    buf = taosDecodeString(buf, &name);
157,189✔
4617
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
314,378✔
UNCOV
4618
      return terrno;
×
4619
    }
4620
  }
4621

4622
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
350,254✔
4623
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
350,254✔
4624
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
350,254✔
4625
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
350,254✔
4626
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
350,254✔
4627
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
350,254✔
4628
  if ((char*)buf - (char*)start < len) {
350,254✔
4629
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
350,254✔
4630
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
350,254✔
4631
    buf = taosDecodeStringTo(buf, pReq->user);
350,254✔
4632
    buf = taosDecodeStringTo(buf, pReq->fqdn);
700,508✔
4633
  } else {
4634
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4635
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4636
  }
4637

4638
  return 0;
350,254✔
4639
}
4640

4641
typedef struct {
4642
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4643
  SArray* removedConsumers;  // SArray<int64_t>
4644
  SArray* newConsumers;      // SArray<int64_t>
4645
} SMqRebInfo;
4646

4647
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4648
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
325,185✔
4649
  if (pRebInfo == NULL) {
325,185✔
UNCOV
4650
    return NULL;
×
4651
  }
4652
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
325,185✔
4653
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
325,185✔
4654
  if (pRebInfo->removedConsumers == NULL) {
325,185✔
UNCOV
4655
    goto _err;
×
4656
  }
4657
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
325,185✔
4658
  if (pRebInfo->newConsumers == NULL) {
325,185✔
UNCOV
4659
    goto _err;
×
4660
  }
4661
  return pRebInfo;
325,185✔
4662
_err:
×
4663
  taosArrayDestroy(pRebInfo->removedConsumers);
×
4664
  taosArrayDestroy(pRebInfo->newConsumers);
×
4665
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
4666
  return NULL;
×
4667
}
4668

4669
typedef struct {
4670
  int64_t streamId;
4671
  int64_t checkpointId;
4672
  char    streamName[TSDB_STREAM_FNAME_LEN];
4673
} SMStreamDoCheckpointMsg;
4674

4675
typedef struct {
4676
  int64_t status;
4677
} SMVSubscribeRsp;
4678

4679
typedef struct {
4680
  char    name[TSDB_TOPIC_FNAME_LEN];
4681
  int8_t  igNotExists;
4682
  int32_t sqlLen;
4683
  char*   sql;
4684
  int8_t  force;
4685
} SMDropTopicReq;
4686

4687
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4688
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4689
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4690

4691
typedef struct {
4692
  char    name[TSDB_TOPIC_FNAME_LEN];
4693
  int8_t  igNotExists;
4694
  int32_t sqlLen;
4695
  char*   sql;
4696
} SMReloadTopicReq;
4697

4698
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4699
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4700
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4701

4702
typedef struct {
4703
  char   topic[TSDB_TOPIC_FNAME_LEN];
4704
  char   cgroup[TSDB_CGROUP_LEN];
4705
  int8_t igNotExists;
4706
  int8_t force;
4707
} SMDropCgroupReq;
4708

4709
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4710
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4711

4712
typedef struct {
4713
  int8_t reserved;
4714
} SMDropCgroupRsp;
4715

4716
typedef struct {
4717
  char    name[TSDB_TABLE_FNAME_LEN];
4718
  int8_t  alterType;
4719
  SSchema schema;
4720
} SAlterTopicReq;
4721

4722
typedef struct {
4723
  SMsgHead head;
4724
  char     name[TSDB_TABLE_FNAME_LEN];
4725
  int64_t  tuid;
4726
  int32_t  sverson;
4727
  int32_t  execLen;
4728
  char*    executor;
4729
  int32_t  sqlLen;
4730
  char*    sql;
4731
} SDCreateTopicReq;
4732

4733
typedef struct {
4734
  SMsgHead head;
4735
  char     name[TSDB_TABLE_FNAME_LEN];
4736
  int64_t  tuid;
4737
} SDDropTopicReq;
4738

4739
typedef struct {
4740
  char*      name;
4741
  int64_t    uid;
4742
  int64_t    interval[2];
4743
  int8_t     intervalUnit;
4744
  int16_t    nFuncs;
4745
  col_id_t*  funcColIds;  // column ids specified by user
4746
  func_id_t* funcIds;     // function ids specified by user
4747
} SRSmaParam;
4748

4749
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4750
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4751

4752
// TDMT_VND_CREATE_STB ==============
4753
typedef struct SVCreateStbReq {
4754
  char*           name;
4755
  tb_uid_t        suid;
4756
  int8_t          rollup;
4757
  SSchemaWrapper  schemaRow;
4758
  SSchemaWrapper  schemaTag;
4759
  SRSmaParam      rsmaParam;
4760
  int32_t         alterOriDataLen;
4761
  void*           alterOriData;
4762
  int8_t          source;
4763
  int8_t          colCmpred;
4764
  SColCmprWrapper colCmpr;
4765
  int64_t         keep;
4766
  int64_t         ownerId;
4767
  SExtSchema*     pExtSchemas;
4768
  int8_t          virtualStb;
4769
} SVCreateStbReq;
4770

4771
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4772
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4773

4774
// TDMT_VND_DROP_STB ==============
4775
typedef struct SVDropStbReq {
4776
  char*    name;
4777
  tb_uid_t suid;
4778
} SVDropStbReq;
4779

4780
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4781
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4782

4783
// TDMT_VND_CREATE_TABLE ==============
4784
#define TD_CREATE_IF_NOT_EXISTS       0x1
4785
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4786
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4787
typedef struct SVCreateTbReq {
4788
  int32_t  flags;
4789
  char*    name;
4790
  tb_uid_t uid;
4791
  int64_t  btime;
4792
  int32_t  ttl;
4793
  int32_t  commentLen;
4794
  char*    comment;
4795
  int8_t   type;
4796
  union {
4797
    struct {
4798
      char*    stbName;  // super table name
4799
      uint8_t  tagNum;
4800
      tb_uid_t suid;
4801
      SArray*  tagName;
4802
      uint8_t* pTag;
4803
    } ctb;
4804
    struct {
4805
      SSchemaWrapper schemaRow;
4806
      int64_t        userId;
4807
    } ntb;
4808
  };
4809
  int32_t         sqlLen;
4810
  char*           sql;
4811
  SColCmprWrapper colCmpr;
4812
  SExtSchema*     pExtSchemas;
4813
  SColRefWrapper  colRef;  // col reference for virtual table
4814
} SVCreateTbReq;
4815

4816
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4817
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4818
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4819
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4820

4821
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4822
  if (NULL == req) {
2,147,483,647✔
4823
    return;
2,147,483,647✔
4824
  }
4825

4826
  taosMemoryFreeClear(req->sql);
73,893,579✔
4827
  taosMemoryFreeClear(req->name);
73,892,859✔
4828
  taosMemoryFreeClear(req->comment);
73,901,670✔
4829
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
73,896,689✔
4830
    taosMemoryFreeClear(req->ctb.pTag);
67,127,865✔
4831
    taosMemoryFreeClear(req->ctb.stbName);
67,115,513✔
4832
    taosArrayDestroy(req->ctb.tagName);
67,146,567✔
4833
    req->ctb.tagName = NULL;
67,083,681✔
4834
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
6,773,616✔
4835
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
6,773,616✔
4836
  }
4837
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
73,854,290✔
4838
  taosMemoryFreeClear(req->pExtSchemas);
73,891,556✔
4839
  taosMemoryFreeClear(req->colRef.pColRef);
73,897,906✔
4840
}
4841

4842
typedef struct {
4843
  int32_t nReqs;
4844
  union {
4845
    SVCreateTbReq* pReqs;
4846
    SArray*        pArray;
4847
  };
4848
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4849
} SVCreateTbBatchReq;
4850

4851
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4852
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4853
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4854

4855
typedef struct {
4856
  int32_t        code;
4857
  STableMetaRsp* pMeta;
4858
} SVCreateTbRsp, SVUpdateTbRsp;
4859

4860
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4861
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4862
void tFreeSVCreateTbRsp(void* param);
4863

4864
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4865
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4866

4867
typedef struct {
4868
  int32_t nRsps;
4869
  union {
4870
    SVCreateTbRsp* pRsps;
4871
    SArray*        pArray;
4872
  };
4873
} SVCreateTbBatchRsp;
4874

4875
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4876
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4877

4878
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4879
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4880

4881
// TDMT_VND_DROP_TABLE =================
4882
typedef struct {
4883
  char*    name;
4884
  uint64_t suid;  // for tmq in wal format
4885
  int64_t  uid;
4886
  int8_t   igNotExists;
4887
  int8_t   isVirtual;
4888
} SVDropTbReq;
4889

4890
typedef struct {
4891
  int32_t code;
4892
} SVDropTbRsp;
4893

4894
typedef struct {
4895
  int32_t nReqs;
4896
  union {
4897
    SVDropTbReq* pReqs;
4898
    SArray*      pArray;
4899
  };
4900
} SVDropTbBatchReq;
4901

4902
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4903
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4904

4905
typedef struct {
4906
  int32_t nRsps;
4907
  union {
4908
    SVDropTbRsp* pRsps;
4909
    SArray*      pArray;
4910
  };
4911
} SVDropTbBatchRsp;
4912

4913
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4914
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4915

4916
// TDMT_VND_ALTER_TABLE =====================
4917
typedef struct SMultiTagUpateVal {
4918
  char*    tagName;
4919
  int32_t  colId;
4920
  int8_t   tagType;
4921
  int8_t   tagFree;
4922
  uint32_t nTagVal;
4923
  uint8_t* pTagVal;
4924
  int8_t   isNull;
4925
  SArray*  pTagArray;
4926
} SMultiTagUpateVal;
4927
typedef struct SVAlterTbReq {
4928
  char*   tbName;
4929
  int8_t  action;
4930
  char*   colName;
4931
  int32_t colId;
4932
  // TSDB_ALTER_TABLE_ADD_COLUMN
4933
  int8_t  type;
4934
  int8_t  flags;
4935
  int32_t bytes;
4936
  // TSDB_ALTER_TABLE_DROP_COLUMN
4937
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4938
  int8_t   colModType;
4939
  int32_t  colModBytes;
4940
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4941
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4942
  int8_t   isNull;
4943
  int8_t   tagType;
4944
  int8_t   tagFree;
4945
  uint32_t nTagVal;
4946
  uint8_t* pTagVal;
4947
  SArray*  pTagArray;
4948
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4949
  int8_t   updateTTL;
4950
  int32_t  newTTL;
4951
  int32_t  newCommentLen;
4952
  char*    newComment;
4953
  int64_t  ctimeMs;    // fill by vnode
4954
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4955
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4956
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4957
  // for Add column
4958
  STypeMod typeMod;
4959
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4960
  char* refDbName;
4961
  char* refTbName;
4962
  char* refColName;
4963
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4964
} SVAlterTbReq;
4965

4966
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4967
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4968
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4969
void    tfreeMultiTagUpateVal(void* pMultiTag);
4970

4971
typedef struct {
4972
  int32_t        code;
4973
  STableMetaRsp* pMeta;
4974
} SVAlterTbRsp;
4975

4976
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4977
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4978
// ======================
4979

4980
typedef struct {
4981
  SMsgHead head;
4982
  int64_t  uid;
4983
  int32_t  tid;
4984
  int16_t  tversion;
4985
  int16_t  colId;
4986
  int8_t   type;
4987
  int16_t  bytes;
4988
  int32_t  tagValLen;
4989
  int16_t  numOfTags;
4990
  int32_t  schemaLen;
4991
  char     data[];
4992
} SUpdateTagValReq;
4993

4994
typedef struct {
4995
  SMsgHead head;
4996
} SUpdateTagValRsp;
4997

4998
typedef struct {
4999
  SMsgHead head;
5000
} SVShowTablesReq;
5001

5002
typedef struct {
5003
  SMsgHead head;
5004
  int32_t  id;
5005
} SVShowTablesFetchReq;
5006

5007
typedef struct {
5008
  int64_t useconds;
5009
  int8_t  completed;  // all results are returned to client
5010
  int8_t  precision;
5011
  int8_t  compressed;
5012
  int32_t compLen;
5013
  int32_t numOfRows;
5014
  char    data[];
5015
} SVShowTablesFetchRsp;
5016

5017
typedef struct {
5018
  int64_t consumerId;
5019
  int32_t epoch;
5020
  char    cgroup[TSDB_CGROUP_LEN];
5021
} SMqAskEpReq;
5022

5023
typedef struct {
5024
  int32_t key;
5025
  int32_t valueLen;
5026
  void*   value;
5027
} SKv;
5028

5029
typedef struct {
5030
  int64_t tscRid;
5031
  int8_t  connType;
5032
} SClientHbKey;
5033

5034
typedef struct {
5035
  int64_t tid;
5036
  char    status[TSDB_JOB_STATUS_LEN];
5037
} SQuerySubDesc;
5038

5039
typedef struct {
5040
  char     sql[TSDB_SHOW_SQL_LEN];
5041
  uint64_t queryId;
5042
  int64_t  useconds;
5043
  int64_t  stime;  // timestamp precision ms
5044
  int64_t  reqRid;
5045
  bool     stableQuery;
5046
  bool     isSubQuery;
5047
  char     fqdn[TSDB_FQDN_LEN];
5048
  int32_t  subPlanNum;
5049
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5050
} SQueryDesc;
5051

5052
typedef struct {
5053
  uint32_t connId;
5054
  SArray*  queryDesc;  // SArray<SQueryDesc>
5055
} SQueryHbReqBasic;
5056

5057
typedef struct {
5058
  uint32_t connId;
5059
  uint64_t killRid;
5060
  int32_t  totalDnodes;
5061
  int32_t  onlineDnodes;
5062
  int8_t   killConnection;
5063
  int8_t   align[3];
5064
  SEpSet   epSet;
5065
  SArray*  pQnodeList;
5066
} SQueryHbRspBasic;
5067

5068
typedef struct SAppClusterSummary {
5069
  uint64_t numOfInsertsReq;
5070
  uint64_t numOfInsertRows;
5071
  uint64_t insertElapsedTime;
5072
  uint64_t insertBytes;  // submit to tsdb since launched.
5073

5074
  uint64_t fetchBytes;
5075
  uint64_t numOfQueryReq;
5076
  uint64_t queryElapsedTime;
5077
  uint64_t numOfSlowQueries;
5078
  uint64_t totalRequests;
5079
  uint64_t currentRequests;  // the number of SRequestObj
5080
} SAppClusterSummary;
5081

5082
typedef struct {
5083
  int64_t            appId;
5084
  int32_t            pid;
5085
  char               name[TSDB_APP_NAME_LEN];
5086
  int64_t            startTime;
5087
  SAppClusterSummary summary;
5088
} SAppHbReq;
5089

5090
typedef struct {
5091
  SClientHbKey      connKey;
5092
  int64_t           clusterId;
5093
  SAppHbReq         app;
5094
  SQueryHbReqBasic* query;
5095
  SHashObj*         info;  // hash<Skv.key, Skv>
5096
  char              user[TSDB_USER_LEN];
5097
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5098
  char              userApp[TSDB_APP_NAME_LEN];
5099
  uint32_t          userIp;
5100
  SIpRange          userDualIp;
5101
  char              sVer[TSDB_VERSION_LEN];
5102
  char              cInfo[CONNECTOR_INFO_LEN];
5103
} SClientHbReq;
5104

5105
typedef struct {
5106
  int64_t reqId;
5107
  SArray* reqs;  // SArray<SClientHbReq>
5108
  int64_t ipWhiteListVer;
5109
} SClientHbBatchReq;
5110

5111
typedef struct {
5112
  SClientHbKey      connKey;
5113
  int32_t           status;
5114
  SQueryHbRspBasic* query;
5115
  SArray*           info;  // Array<Skv>
5116
} SClientHbRsp;
5117

5118
typedef struct {
5119
  int64_t       reqId;
5120
  int64_t       rspId;
5121
  int32_t       svrTimestamp;
5122
  SArray*       rsps;  // SArray<SClientHbRsp>
5123
  SMonitorParas monitorParas;
5124
  int8_t        enableAuditDelete;
5125
  int8_t        enableStrongPass;
5126
  int8_t        enableAuditSelect;
5127
  int8_t        enableAuditInsert;
5128
  int8_t        auditLevel;
5129
} SClientHbBatchRsp;
5130

5131
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
72,958,983✔
5132

5133
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5134
  void* pIter = taosHashIterate(info, NULL);
50,709,318✔
5135
  while (pIter != NULL) {
118,132,454✔
5136
    SKv* kv = (SKv*)pIter;
67,422,818✔
5137
    taosMemoryFreeClear(kv->value);
67,422,818✔
5138
    pIter = taosHashIterate(info, pIter);
67,423,438✔
5139
  }
5140
}
50,709,636✔
5141

5142
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
32,567,085✔
5143
  SQueryDesc* desc = (SQueryDesc*)pDesc;
32,567,085✔
5144
  if (desc->subDesc) {
32,567,085✔
5145
    taosArrayDestroy(desc->subDesc);
23,187,129✔
5146
    desc->subDesc = NULL;
23,185,358✔
5147
  }
5148
}
32,566,345✔
5149

5150
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
58,014,515✔
5151
  SClientHbReq* req = (SClientHbReq*)pReq;
60,430,997✔
5152
  if (req->query) {
60,430,997✔
5153
    if (req->query->queryDesc) {
58,013,895✔
5154
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
26,792,813✔
5155
    }
5156
    taosMemoryFreeClear(req->query);
58,012,774✔
5157
  }
5158

5159
  if (req->info) {
60,431,030✔
5160
    tFreeReqKvHash(req->info);
50,707,945✔
5161
    taosHashCleanup(req->info);
50,709,636✔
5162
    req->info = NULL;
50,708,714✔
5163
  }
5164
}
30,574,935✔
5165

5166
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5167
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5168

5169
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5170
  if (pReq == NULL) return;
24,783,985✔
5171
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
24,783,985✔
5172
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
24,783,985✔
5173
  taosMemoryFree(pReq);
24,783,985✔
5174
}
5175

5176
static FORCE_INLINE void tFreeClientKv(void* pKv) {
67,201,336✔
5177
  SKv* kv = (SKv*)pKv;
67,201,336✔
5178
  if (kv) {
67,201,336✔
5179
    taosMemoryFreeClear(kv->value);
67,201,336✔
5180
  }
5181
}
67,200,954✔
5182

5183
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
57,829,154✔
5184
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
57,829,154✔
5185
  if (rsp->query) {
57,829,154✔
5186
    taosArrayDestroy(rsp->query->pQnodeList);
57,822,692✔
5187
    taosMemoryFreeClear(rsp->query);
57,824,116✔
5188
  }
5189
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
57,835,058✔
5190
}
29,673,789✔
5191

5192
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5193
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
47,652,561✔
5194
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
47,652,561✔
5195
}
47,657,609✔
5196

5197
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5198
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5199
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5200

5201
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5202
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
422,648,323✔
5203
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
422,650,355✔
5204
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
422,653,705✔
5205
  return 0;
211,327,412✔
5206
}
5207

5208
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5209
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
138,480,763✔
5210
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
138,480,763✔
5211
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
69,240,578✔
5212
  if (pKv->value == NULL) {
69,239,842✔
UNCOV
5213
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5214
  }
5215
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
69,240,521✔
5216
  return 0;
69,240,286✔
5217
}
5218

5219
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5220
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
363,329,060✔
5221
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
363,320,859✔
5222
  return 0;
181,661,616✔
5223
}
5224

5225
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5226
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
119,615,969✔
5227
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
119,617,857✔
5228
  return 0;
59,809,851✔
5229
}
5230

5231
typedef struct {
5232
  int32_t vgId;
5233
  // TODO stas
5234
} SMqReportVgInfo;
5235

5236
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5237
  int32_t tlen = 0;
5238
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5239
  return tlen;
5240
}
5241

5242
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5243
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5244
  return buf;
5245
}
5246

5247
typedef struct {
5248
  int32_t epoch;
5249
  int64_t topicUid;
5250
  char    name[TSDB_TOPIC_FNAME_LEN];
5251
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5252
} SMqTopicInfo;
5253

5254
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5255
  int32_t tlen = 0;
5256
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5257
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5258
  tlen += taosEncodeString(buf, pTopicInfo->name);
5259
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5260
  tlen += taosEncodeFixedI32(buf, sz);
5261
  for (int32_t i = 0; i < sz; i++) {
5262
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5263
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5264
  }
5265
  return tlen;
5266
}
5267

5268
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5269
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5270
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5271
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5272
  int32_t sz;
5273
  buf = taosDecodeFixedI32(buf, &sz);
5274
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5275
    return NULL;
5276
  }
5277
  for (int32_t i = 0; i < sz; i++) {
5278
    SMqReportVgInfo vgInfo;
5279
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5280
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5281
      return NULL;
5282
    }
5283
  }
5284
  return buf;
5285
}
5286

5287
typedef struct {
5288
  int32_t status;  // ask hb endpoint
5289
  int32_t epoch;
5290
  int64_t consumerId;
5291
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5292
} SMqReportReq;
5293

5294
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5295
  int32_t tlen = 0;
5296
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5297
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5298
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5299
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5300
  tlen += taosEncodeFixedI32(buf, sz);
5301
  for (int32_t i = 0; i < sz; i++) {
5302
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5303
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5304
  }
5305
  return tlen;
5306
}
5307

5308
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5309
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5310
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5311
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5312
  int32_t sz;
5313
  buf = taosDecodeFixedI32(buf, &sz);
5314
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5315
    return NULL;
5316
  }
5317
  for (int32_t i = 0; i < sz; i++) {
5318
    SMqTopicInfo topicInfo;
5319
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5320
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5321
      return NULL;
5322
    }
5323
  }
5324
  return buf;
5325
}
5326

5327
typedef struct {
5328
  SMsgHead head;
5329
  int64_t  leftForVer;
5330
  int32_t  vgId;
5331
  int64_t  consumerId;
5332
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5333
} SMqVDeleteReq;
5334

5335
typedef struct {
5336
  int8_t reserved;
5337
} SMqVDeleteRsp;
5338

5339
typedef struct {
5340
  char**  name;
5341
  int32_t count;
5342
  int8_t igNotExists;
5343
} SMDropStreamReq;
5344

5345
typedef struct {
5346
  int8_t reserved;
5347
} SMDropStreamRsp;
5348

5349
typedef struct {
5350
  SMsgHead head;
5351
  int64_t  resetRelHalt;  // reset related stream task halt status
5352
  int64_t  streamId;
5353
  int32_t  taskId;
5354
} SVDropStreamTaskReq;
5355

5356
typedef struct {
5357
  int8_t reserved;
5358
} SVDropStreamTaskRsp;
5359

5360
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5361
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5362
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5363

5364
typedef struct {
5365
  char*  name;
5366
  int8_t igNotExists;
5367
} SMPauseStreamReq;
5368

5369
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5370
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5371
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5372

5373
typedef struct {
5374
  char*  name;
5375
  int8_t igNotExists;
5376
  int8_t igUntreated;
5377
} SMResumeStreamReq;
5378

5379
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5380
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5381
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5382

5383
typedef struct {
5384
  char*       name;
5385
  int8_t      calcAll;
5386
  STimeWindow timeRange;
5387
} SMRecalcStreamReq;
5388

5389
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5390
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5391
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5392

5393

5394
typedef struct SVndSetKeepVersionReq {
5395
  int64_t keepVersion;
5396
} SVndSetKeepVersionReq;
5397

5398
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5399
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5400

5401
typedef struct SVUpdateCheckpointInfoReq {
5402
  SMsgHead head;
5403
  int64_t  streamId;
5404
  int32_t  taskId;
5405
  int64_t  checkpointId;
5406
  int64_t  checkpointVer;
5407
  int64_t  checkpointTs;
5408
  int32_t  transId;
5409
  int64_t  hStreamId;  // add encode/decode
5410
  int64_t  hTaskId;
5411
  int8_t   dropRelHTask;
5412
} SVUpdateCheckpointInfoReq;
5413

5414
typedef struct {
5415
  int64_t leftForVer;
5416
  int32_t vgId;
5417
  int64_t oldConsumerId;
5418
  int64_t newConsumerId;
5419
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5420
  int8_t  subType;
5421
  int8_t  withMeta;
5422
  char*   qmsg;  // SubPlanToString
5423
  SSchemaWrapper schema;
5424
  int64_t suid;
5425
} SMqRebVgReq;
5426

5427
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5428
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5429

5430
// tqOffset
5431
enum {
5432
  TMQ_OFFSET__RESET_NONE = -3,
5433
  TMQ_OFFSET__RESET_EARLIEST = -2,
5434
  TMQ_OFFSET__RESET_LATEST = -1,
5435
  TMQ_OFFSET__LOG = 1,
5436
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5437
  TMQ_OFFSET__SNAPSHOT_META = 3,
5438
};
5439

5440
enum {
5441
  WITH_DATA = 0,
5442
  WITH_META = 1,
5443
  ONLY_META = 2,
5444
};
5445

5446
#define TQ_OFFSET_VERSION 1
5447

5448
typedef struct {
5449
  int8_t type;
5450
  union {
5451
    // snapshot
5452
    struct {
5453
      int64_t uid;
5454
      int64_t ts;
5455
      SValue  primaryKey;
5456
    };
5457
    // log
5458
    struct {
5459
      int64_t version;
5460
    };
5461
  };
5462
} STqOffsetVal;
5463

5464
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5465
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,485,621✔
5466
  pOffsetVal->uid = uid;
7,485,121✔
5467
  pOffsetVal->ts = ts;
7,486,297✔
5468
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,485,993✔
5469
    taosMemoryFree(pOffsetVal->primaryKey.pData);
297✔
5470
  }
5471
  pOffsetVal->primaryKey = primaryKey;
7,485,351✔
5472
}
7,485,682✔
5473

5474
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5475
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
40,958✔
5476
  pOffsetVal->uid = uid;
40,958✔
5477
}
40,958✔
5478

5479
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5480
  pOffsetVal->type = TMQ_OFFSET__LOG;
123,517,214✔
5481
  pOffsetVal->version = ver;
123,516,299✔
5482
}
123,509,676✔
5483

5484
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5485
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5486
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5487
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5488
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5489
void    tOffsetDestroy(void* pVal);
5490

5491
typedef struct {
5492
  STqOffsetVal val;
5493
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5494
} STqOffset;
5495

5496
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5497
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5498
void    tDeleteSTqOffset(void* val);
5499

5500
typedef struct SMqVgOffset {
5501
  int64_t   consumerId;
5502
  STqOffset offset;
5503
} SMqVgOffset;
5504

5505
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5506
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5507

5508
typedef struct {
5509
  char    name[TSDB_TABLE_FNAME_LEN];
5510
  char    stb[TSDB_TABLE_FNAME_LEN];
5511
  int8_t  igExists;
5512
  int8_t  intervalUnit;
5513
  int8_t  slidingUnit;
5514
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5515
  int32_t dstVgId;   // for stream
5516
  int64_t interval;
5517
  int64_t offset;
5518
  int64_t sliding;
5519
  int64_t maxDelay;
5520
  int64_t watermark;
5521
  int32_t exprLen;        // strlen + 1
5522
  int32_t tagsFilterLen;  // strlen + 1
5523
  int32_t sqlLen;         // strlen + 1
5524
  int32_t astLen;         // strlen + 1
5525
  char*   expr;
5526
  char*   tagsFilter;
5527
  char*   sql;
5528
  char*   ast;
5529
  int64_t deleteMark;
5530
  int64_t lastTs;
5531
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5532
  SArray* pVgroupVerList;
5533
  int8_t  recursiveTsma;
5534
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5535
  char*   createStreamReq;
5536
  int32_t streamReqLen;
5537
  char*   dropStreamReq;
5538
  int32_t dropStreamReqLen;
5539
  int64_t uid;
5540
} SMCreateSmaReq;
5541

5542
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5543
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5544
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5545

5546
typedef struct {
5547
  char    name[TSDB_TABLE_FNAME_LEN];
5548
  int8_t  igNotExists;
5549
  char*   dropStreamReq;
5550
  int32_t dropStreamReqLen;
5551
} SMDropSmaReq;
5552

5553
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5554
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5555
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5556

5557
typedef struct {
5558
  char name[TSDB_TABLE_NAME_LEN];
5559
  union {
5560
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5561
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5562
  };
5563
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5564
  union {
5565
    int8_t igExists;   // used by mnode
5566
    int8_t alterType;  // used by vnode
5567
  };
5568
  int8_t     intervalUnit;
5569
  int16_t    nFuncs;       // number of functions specified by user
5570
  col_id_t*  funcColIds;   // column ids specified by user
5571
  func_id_t* funcIds;      // function ids specified by user
5572
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5573
  int64_t    tbUid;
5574
  int64_t    uid;     // rsma uid
5575
  int32_t    sqlLen;  // strlen + 1
5576
  char*      sql;
5577
} SMCreateRsmaReq;
5578

5579
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5580
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5581
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5582

5583
typedef SMCreateRsmaReq SVCreateRsmaReq;
5584

5585
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5586
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5587
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5588

5589
typedef SMCreateRsmaReq SVAlterRsmaReq;
5590

5591
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5592
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5593
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5594

5595
typedef struct {
5596
  char       name[TSDB_TABLE_NAME_LEN];
5597
  int8_t     alterType;
5598
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5599
  int8_t     igNotExists;
5600
  int16_t    nFuncs;      // number of functions specified by user
5601
  col_id_t*  funcColIds;  // column ids specified by user
5602
  func_id_t* funcIds;     // function ids specified by user
5603
  int32_t    sqlLen;      // strlen + 1
5604
  char*      sql;
5605
} SMAlterRsmaReq;
5606

5607
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5608
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5609
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5610

5611
typedef struct {
5612
  int64_t    id;
5613
  char       name[TSDB_TABLE_NAME_LEN];
5614
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5615
  int64_t    ownerId;
5616
  int32_t    code;
5617
  int32_t    version;
5618
  int8_t     tbType;
5619
  int8_t     intervalUnit;
5620
  col_id_t   nFuncs;
5621
  col_id_t   nColNames;
5622
  int64_t    interval[2];
5623
  col_id_t*  funcColIds;
5624
  func_id_t* funcIds;
5625
  SArray*    colNames;
5626
} SRsmaInfoRsp;
5627

5628
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5629
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5630
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5631

5632
typedef struct {
5633
  char   name[TSDB_TABLE_FNAME_LEN];
5634
  int8_t igNotExists;
5635
} SMDropRsmaReq;
5636

5637
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5638
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5639

5640
typedef struct {
5641
  char    name[TSDB_TABLE_NAME_LEN];
5642
  char    tbName[TSDB_TABLE_NAME_LEN];
5643
  int64_t uid;
5644
  int64_t tbUid;
5645
  int8_t  tbType;
5646
} SVDropRsmaReq;
5647

5648
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5649
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5650

5651
typedef struct {
5652
  char   dbFName[TSDB_DB_FNAME_LEN];
5653
  char   stbName[TSDB_TABLE_NAME_LEN];
5654
  char   colName[TSDB_COL_NAME_LEN];
5655
  char   idxName[TSDB_INDEX_FNAME_LEN];
5656
  int8_t idxType;
5657
} SCreateTagIndexReq;
5658

5659
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5660
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5661

5662
typedef SMDropSmaReq SDropTagIndexReq;
5663

5664
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5665
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5666

5667
typedef struct {
5668
  int8_t         version;       // for compatibility(default 0)
5669
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5670
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5671
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5672
  int32_t        dstVgId;
5673
  char           indexName[TSDB_INDEX_NAME_LEN];
5674
  int32_t        exprLen;
5675
  int32_t        tagsFilterLen;
5676
  int64_t        indexUid;
5677
  tb_uid_t       tableUid;  // super/child/common table uid
5678
  tb_uid_t       dstTbUid;  // for dstVgroup
5679
  int64_t        interval;
5680
  int64_t        offset;  // use unit by precision of DB
5681
  int64_t        sliding;
5682
  char*          dstTbName;  // for dstVgroup
5683
  char*          expr;       // sma expression
5684
  char*          tagsFilter;
5685
  SSchemaWrapper schemaRow;  // for dstVgroup
5686
  SSchemaWrapper schemaTag;  // for dstVgroup
5687
} STSma;                     // Time-range-wise SMA
5688

5689
typedef STSma SVCreateTSmaReq;
5690

5691
typedef struct {
5692
  int8_t  type;  // 0 status report, 1 update data
5693
  int64_t indexUid;
5694
  int64_t skey;  // start TS key of interval/sliding window
5695
} STSmaMsg;
5696

5697
typedef struct {
5698
  int64_t indexUid;
5699
  char    indexName[TSDB_INDEX_NAME_LEN];
5700
} SVDropTSmaReq;
5701

5702
typedef struct {
5703
  int tmp;  // TODO: to avoid compile error
5704
} SVCreateTSmaRsp, SVDropTSmaRsp;
5705

5706
#if 0
5707
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5708
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5709
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5710
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5711
#endif
5712

5713
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5714
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5715
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5716
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5717

5718
typedef struct {
5719
  int32_t number;
5720
  STSma*  tSma;
5721
} STSmaWrapper;
5722

5723
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5724
  if (pSma) {
×
5725
    taosMemoryFreeClear(pSma->dstTbName);
×
5726
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
5727
    taosMemoryFreeClear(pSma->tagsFilter);
×
5728
  }
UNCOV
5729
}
×
5730

5731
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5732
  if (pSW) {
×
5733
    if (pSW->tSma) {
×
5734
      if (deepCopy) {
×
5735
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5736
          tDestroyTSma(pSW->tSma + i);
×
5737
        }
5738
      }
UNCOV
5739
      taosMemoryFreeClear(pSW->tSma);
×
5740
    }
5741
  }
UNCOV
5742
}
×
5743

5744
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5745
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5746
  taosMemoryFreeClear(pSW);
×
UNCOV
5747
  return NULL;
×
5748
}
5749

5750
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5751
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5752

5753
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5754
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5755

5756
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5757
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5758
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5759
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5760
  }
UNCOV
5761
  return 0;
×
5762
}
5763

5764
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5765
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5766
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5767
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5768
  }
UNCOV
5769
  return 0;
×
5770
}
5771

5772
typedef struct {
5773
  int idx;
5774
} SMCreateFullTextReq;
5775

5776
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5777
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5778
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5779

5780
typedef struct {
5781
  char   name[TSDB_TABLE_FNAME_LEN];
5782
  int8_t igNotExists;
5783
} SMDropFullTextReq;
5784

5785
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5786
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5787

5788
typedef struct {
5789
  char indexFName[TSDB_INDEX_FNAME_LEN];
5790
} SUserIndexReq;
5791

5792
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5793
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5794

5795
typedef struct {
5796
  char dbFName[TSDB_DB_FNAME_LEN];
5797
  char tblFName[TSDB_TABLE_FNAME_LEN];
5798
  char colName[TSDB_COL_NAME_LEN];
5799
  char owner[TSDB_USER_LEN];
5800
  char indexType[TSDB_INDEX_TYPE_LEN];
5801
  char indexExts[TSDB_INDEX_EXTS_LEN];
5802
} SUserIndexRsp;
5803

5804
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5805
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5806

5807
typedef struct {
5808
  char tbFName[TSDB_TABLE_FNAME_LEN];
5809
} STableIndexReq;
5810

5811
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5812
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5813

5814
typedef struct {
5815
  int8_t  intervalUnit;
5816
  int8_t  slidingUnit;
5817
  int64_t interval;
5818
  int64_t offset;
5819
  int64_t sliding;
5820
  int64_t dstTbUid;
5821
  int32_t dstVgId;
5822
  SEpSet  epSet;
5823
  char*   expr;
5824
} STableIndexInfo;
5825

5826
typedef struct {
5827
  char     tbName[TSDB_TABLE_NAME_LEN];
5828
  char     dbFName[TSDB_DB_FNAME_LEN];
5829
  uint64_t suid;
5830
  int32_t  version;
5831
  int32_t  indexSize;
5832
  SArray*  pIndex;  // STableIndexInfo
5833
} STableIndexRsp;
5834

5835
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5836
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5837
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5838

5839
void tFreeSTableIndexInfo(void* pInfo);
5840

5841
typedef struct {
5842
  int8_t  mqMsgType;
5843
  int32_t code;
5844
  int32_t epoch;
5845
  int64_t consumerId;
5846
  int64_t walsver;
5847
  int64_t walever;
5848
} SMqRspHead;
5849

5850
typedef struct {
5851
  SMsgHead     head;
5852
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5853
  int8_t       withTbName;
5854
  int8_t       useSnapshot;
5855
  int32_t      epoch;
5856
  uint64_t     reqId;
5857
  int64_t      consumerId;
5858
  int64_t      timeout;
5859
  STqOffsetVal reqOffset;
5860
  int8_t       enableReplay;
5861
  int8_t       sourceExcluded;
5862
  int8_t       rawData;
5863
  int32_t      minPollRows;
5864
  int8_t       enableBatchMeta;
5865
  SHashObj*    uidHash;  // to find if uid is duplicated
5866
} SMqPollReq;
5867

5868
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5869
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5870
void    tDestroySMqPollReq(SMqPollReq* pReq);
5871

5872
typedef struct {
5873
  int32_t vgId;
5874
  int64_t offset;
5875
  SEpSet  epSet;
5876
} SMqSubVgEp;
5877

5878
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5879
  int32_t tlen = 0;
2,549,144✔
5880
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,549,144✔
5881
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,549,144✔
5882
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,549,144✔
5883
  return tlen;
2,549,144✔
5884
}
5885

5886
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5887
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,265,553✔
5888
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,265,553✔
5889
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,265,553✔
5890
  return buf;
1,265,553✔
5891
}
5892

5893
typedef struct {
5894
  char           topic[TSDB_TOPIC_FNAME_LEN];
5895
  char           db[TSDB_DB_FNAME_LEN];
5896
  SArray*        vgs;  // SArray<SMqSubVgEp>
5897
} SMqSubTopicEp;
5898

5899
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5900
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5901
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5902

5903
typedef struct {
5904
  SMqRspHead   head;
5905
  STqOffsetVal rspOffset;
5906
  int16_t      resMsgType;
5907
  int32_t      metaRspLen;
5908
  void*        metaRsp;
5909
} SMqMetaRsp;
5910

5911
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5912
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5913
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5914

5915
#define MQ_DATA_RSP_VERSION 100
5916

5917
typedef struct {
5918
  SMqRspHead   head;
5919
  STqOffsetVal rspOffset;
5920
  STqOffsetVal reqOffset;
5921
  int32_t      blockNum;
5922
  int8_t       withTbName;
5923
  int8_t       withSchema;
5924
  SArray*      blockDataLen;
5925
  SArray*      blockData;
5926
  SArray*      blockTbName;
5927
  SArray*      blockSchema;
5928

5929
  union {
5930
    struct {
5931
      int64_t sleepTime;
5932
    };
5933
    struct {
5934
      int32_t createTableNum;
5935
      SArray* createTableLen;
5936
      SArray* createTableReq;
5937
    };
5938
    struct {
5939
      int32_t len;
5940
      void*   rawData;
5941
    };
5942
  };
5943
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5944
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5945
} SMqDataRsp;
5946

5947
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5948
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5949
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5950
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5951
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5952

5953
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5954
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5955
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5956

5957
typedef struct SMqBatchMetaRsp {
5958
  SMqRspHead   head;  // not serialize
5959
  STqOffsetVal rspOffset;
5960
  SArray*      batchMetaLen;
5961
  SArray*      batchMetaReq;
5962
  void*        pMetaBuff;    // not serialize
5963
  uint32_t     metaBuffLen;  // not serialize
5964
} SMqBatchMetaRsp;
5965

5966
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5967
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5968
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5969
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5970

5971
typedef struct {
5972
  int32_t    code;
5973
  SArray*    topics;  // SArray<SMqSubTopicEp>
5974
} SMqAskEpRsp;
5975

5976
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5977
  int32_t tlen = 0;
7,835,643✔
5978
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5979
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,835,643✔
5980
  tlen += taosEncodeFixedI32(buf, sz);
7,835,948✔
5981
  for (int32_t i = 0; i < sz; i++) {
9,745,076✔
5982
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,909,748✔
5983
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,909,748✔
5984
  }
5985
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,835,328✔
5986

5987
  return tlen;
7,836,289✔
5988
}
5989

5990
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5991
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5992
  int32_t sz;
3,302,285✔
5993
  buf = taosDecodeFixedI32(buf, &sz);
3,378,444✔
5994
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,378,444✔
5995
  if (pRsp->topics == NULL) {
3,378,444✔
UNCOV
5996
    return NULL;
×
5997
  }
5998
  for (int32_t i = 0; i < sz; i++) {
4,318,624✔
5999
    SMqSubTopicEp topicEp;
926,850✔
6000
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
940,180✔
6001
    if (buf == NULL) {
940,180✔
UNCOV
6002
      return NULL;
×
6003
    }
6004
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,880,360✔
UNCOV
6005
      return NULL;
×
6006
    }
6007
  }
6008
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,378,444✔
6009

6010
  return buf;
3,378,444✔
6011
}
6012

6013
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6014
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,695,574✔
6015
}
9,693,647✔
6016

6017
typedef struct {
6018
  int32_t      vgId;
6019
  STqOffsetVal offset;
6020
  int64_t      rows;
6021
  int64_t      ever;
6022
} OffsetRows;
6023

6024
typedef struct {
6025
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6026
  SArray* offsetRows;
6027
} TopicOffsetRows;
6028

6029
typedef struct {
6030
  int64_t consumerId;
6031
  int32_t epoch;
6032
  SArray* topics;
6033
  int8_t  pollFlag;
6034
} SMqHbReq;
6035

6036
typedef struct {
6037
  char   topic[TSDB_TOPIC_FNAME_LEN];
6038
  int8_t noPrivilege;
6039
} STopicPrivilege;
6040

6041
typedef struct {
6042
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6043
  int32_t debugFlag;
6044
} SMqHbRsp;
6045

6046
typedef struct {
6047
  SMsgHead head;
6048
  int64_t  consumerId;
6049
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6050
} SMqSeekReq;
6051

6052
#define TD_AUTO_CREATE_TABLE 0x1
6053
typedef struct {
6054
  int64_t       suid;
6055
  int64_t       uid;
6056
  int32_t       sver;
6057
  uint32_t      nData;
6058
  uint8_t*      pData;
6059
  SVCreateTbReq cTbReq;
6060
} SVSubmitBlk;
6061

6062
typedef struct {
6063
  SMsgHead header;
6064
  uint64_t sId;
6065
  uint64_t queryId;
6066
  uint64_t clientId;
6067
  uint64_t taskId;
6068
  uint32_t sqlLen;
6069
  uint32_t phyLen;
6070
  char*    sql;
6071
  char*    msg;
6072
  int8_t   source;
6073
} SVDeleteReq;
6074

6075
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6076
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6077

6078
typedef struct {
6079
  int64_t affectedRows;
6080
} SVDeleteRsp;
6081

6082
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6083
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6084

6085
typedef struct SDeleteRes {
6086
  uint64_t suid;
6087
  SArray*  uidList;
6088
  int64_t  skey;
6089
  int64_t  ekey;
6090
  int64_t  affectedRows;
6091
  char     tableFName[TSDB_TABLE_NAME_LEN];
6092
  char     tsColName[TSDB_COL_NAME_LEN];
6093
  int64_t  ctimeMs;  // fill by vnode
6094
  int8_t   source;
6095
} SDeleteRes;
6096

6097
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6098
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6099

6100
typedef struct {
6101
  // int64_t uid;
6102
  char    tbname[TSDB_TABLE_NAME_LEN];
6103
  int64_t startTs;
6104
  int64_t endTs;
6105
} SSingleDeleteReq;
6106

6107
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6108
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6109

6110
typedef struct {
6111
  int64_t suid;
6112
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6113
  int64_t ctimeMs;     // fill by vnode
6114
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6115
} SBatchDeleteReq;
6116

6117
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6118
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6119
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6120

6121
typedef struct {
6122
  int32_t msgIdx;
6123
  int32_t msgType;
6124
  int32_t msgLen;
6125
  void*   msg;
6126
} SBatchMsg;
6127

6128
typedef struct {
6129
  SMsgHead header;
6130
  SArray*  pMsgs;  // SArray<SBatchMsg>
6131
} SBatchReq;
6132

6133
typedef struct {
6134
  int32_t reqType;
6135
  int32_t msgIdx;
6136
  int32_t msgLen;
6137
  int32_t rspCode;
6138
  void*   msg;
6139
} SBatchRspMsg;
6140

6141
typedef struct {
6142
  SArray* pRsps;  // SArray<SBatchRspMsg>
6143
} SBatchRsp;
6144

6145
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6146
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6147
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
89,394,782✔
6148
  if (NULL == msg) {
89,394,782✔
UNCOV
6149
    return;
×
6150
  }
6151
  SBatchMsg* pMsg = (SBatchMsg*)msg;
89,394,782✔
6152
  taosMemoryFree(pMsg->msg);
89,394,782✔
6153
}
6154

6155
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6156
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6157

6158
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
127,305,722✔
6159
  if (NULL == p) {
127,305,722✔
UNCOV
6160
    return;
×
6161
  }
6162

6163
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
127,305,722✔
6164
  taosMemoryFree(pRsp->msg);
127,305,722✔
6165
}
6166

6167
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6168
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6169
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6170
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6171
void    tDestroySMqHbReq(SMqHbReq* pReq);
6172

6173
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6174
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6175
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6176

6177
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6178
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6179

6180
#define TD_REQ_FROM_APP               0x0
6181
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6182
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6183
#define SUBMIT_REQ_FROM_FILE          0x4
6184
#define TD_REQ_FROM_TAOX              0x8
6185
#define TD_REQ_FROM_SML               0x10
6186
#define SUBMIT_REQUEST_VERSION        (2)
6187
#define SUBMIT_REQ_WITH_BLOB          0x10
6188
#define SUBMIT_REQ_SCHEMA_RES         0x20
6189
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6190

6191
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6192

6193
typedef struct {
6194
  int32_t        flags;
6195
  SVCreateTbReq* pCreateTbReq;
6196
  int64_t        suid;
6197
  int64_t        uid;
6198
  int32_t        sver;
6199
  union {
6200
    SArray* aRowP;
6201
    SArray* aCol;
6202
  };
6203
  int64_t   ctimeMs;
6204
  SBlobSet* pBlobSet;
6205
} SSubmitTbData;
6206

6207
typedef struct {
6208
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6209
  SArray* aSubmitBlobData;
6210
  bool    raw;
6211
} SSubmitReq2;
6212

6213
typedef struct {
6214
  SMsgHead header;
6215
  int64_t  version;
6216
  char     data[];  // SSubmitReq2
6217
} SSubmitReq2Msg;
6218

6219
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6220
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6221
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6222
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6223
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6224

6225
typedef struct {
6226
  int32_t affectedRows;
6227
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6228
} SSubmitRsp2;
6229

6230
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6231
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6232
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6233

6234
#define TSDB_MSG_FLG_ENCODE 0x1
6235
#define TSDB_MSG_FLG_DECODE 0x2
6236
#define TSDB_MSG_FLG_CMPT   0x3
6237

6238
typedef struct {
6239
  union {
6240
    struct {
6241
      void*   msgStr;
6242
      int32_t msgLen;
6243
      int64_t ver;
6244
    };
6245
    void* pDataBlock;
6246
  };
6247
} SPackedData;
6248

6249
typedef struct {
6250
  char     fullname[TSDB_VIEW_FNAME_LEN];
6251
  char     name[TSDB_VIEW_NAME_LEN];
6252
  char     dbFName[TSDB_DB_FNAME_LEN];
6253
  char*    querySql;
6254
  char*    sql;
6255
  int8_t   orReplace;
6256
  int8_t   precision;
6257
  int32_t  numOfCols;
6258
  SSchema* pSchema;
6259
} SCMCreateViewReq;
6260

6261
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6262
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6263
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6264

6265
typedef struct {
6266
  char   fullname[TSDB_VIEW_FNAME_LEN];
6267
  char   name[TSDB_VIEW_NAME_LEN];
6268
  char   dbFName[TSDB_DB_FNAME_LEN];
6269
  char*  sql;
6270
  int8_t igNotExists;
6271
} SCMDropViewReq;
6272

6273
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6274
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6275
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6276

6277
typedef struct {
6278
  char fullname[TSDB_VIEW_FNAME_LEN];
6279
} SViewMetaReq;
6280
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6281
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6282

6283
typedef struct {
6284
  char     name[TSDB_VIEW_NAME_LEN];
6285
  char     dbFName[TSDB_DB_FNAME_LEN];
6286
  char*    createUser;
6287
  int64_t  ownerId;
6288
  uint64_t dbId;
6289
  uint64_t viewId;
6290
  char*    querySql;
6291
  int8_t   precision;
6292
  int8_t   type;
6293
  int32_t  version;
6294
  int32_t  numOfCols;
6295
  SSchema* pSchema;
6296
} SViewMetaRsp;
6297
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6298
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6299
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6300
typedef struct {
6301
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6302
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6303
} STableTSMAInfoReq;
6304

6305
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6306
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6307

6308
typedef struct {
6309
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6310
  union {
6311
    uint8_t flags;
6312
    struct {
6313
      uint8_t withColName : 1;
6314
      uint8_t reserved : 7;
6315
    };
6316
  };
6317

6318
} SRsmaInfoReq;
6319

6320
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6321
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6322

6323
typedef struct {
6324
  int32_t  funcId;
6325
  col_id_t colId;
6326
} STableTSMAFuncInfo;
6327

6328
typedef struct {
6329
  char     name[TSDB_TABLE_NAME_LEN];
6330
  uint64_t tsmaId;
6331
  char     targetTb[TSDB_TABLE_NAME_LEN];
6332
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6333
  char     tb[TSDB_TABLE_NAME_LEN];
6334
  char     dbFName[TSDB_DB_FNAME_LEN];
6335
  uint64_t suid;
6336
  uint64_t destTbUid;
6337
  uint64_t dbId;
6338
  int32_t  version;
6339
  int64_t  interval;
6340
  int8_t   unit;
6341
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6342
  SArray*  pTags;      // SArray<SSchema>
6343
  SArray*  pUsedCols;  // SArray<SSchema>
6344
  char*    ast;
6345

6346
  int64_t streamUid;
6347
  int64_t reqTs;
6348
  int64_t rspTs;
6349
  int64_t delayDuration;  // ms
6350
  bool    fillHistoryFinished;
6351

6352
  void* streamAddr;  // for stream task, the address of the stream task
6353
} STableTSMAInfo;
6354

6355
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6356
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6357
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6358
void    tFreeTableTSMAInfo(void* p);
6359
void    tFreeAndClearTableTSMAInfo(void* p);
6360
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6361

6362
#define STSMAHbRsp            STableTSMAInfoRsp
6363
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6364
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6365
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6366

6367
typedef struct SDropCtbWithTsmaSingleVgReq {
6368
  SVgroupInfo vgInfo;
6369
  SArray*     pTbs;  // SVDropTbReq
6370
} SMDropTbReqsOnSingleVg;
6371

6372
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6373
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6374
void    tFreeSMDropTbReqOnSingleVg(void* p);
6375

6376
typedef struct SDropTbsReq {
6377
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6378
} SMDropTbsReq;
6379

6380
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6381
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6382
void    tFreeSMDropTbsReq(void*);
6383

6384
typedef struct SVFetchTtlExpiredTbsRsp {
6385
  SArray* pExpiredTbs;  // SVDropTbReq
6386
  int32_t vgId;
6387
} SVFetchTtlExpiredTbsRsp;
6388

6389
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6390
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6391

6392
void tFreeFetchTtlExpiredTbsRsp(void* p);
6393

6394
void setDefaultOptionsForField(SFieldWithOptions* field);
6395
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6396

6397
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6398
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6399

6400

6401
typedef struct {
6402
  char    id[TSDB_INSTANCE_ID_LEN];
6403
  char    type[TSDB_INSTANCE_TYPE_LEN];
6404
  char    desc[TSDB_INSTANCE_DESC_LEN];
6405
  int32_t expire;
6406
} SInstanceRegisterReq;
6407

6408
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6409
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6410

6411
typedef struct {
6412
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6413
} SInstanceListReq;
6414

6415
typedef struct {
6416
  int32_t count;
6417
  char**  ids;  // Array of instance IDs
6418
} SInstanceListRsp;
6419

6420
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6421
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6422
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6423
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6424

6425
#ifdef USE_MOUNT
6426
typedef struct {
6427
  char     mountName[TSDB_MOUNT_NAME_LEN];
6428
  int8_t   ignoreExist;
6429
  int16_t  nMounts;
6430
  int32_t* dnodeIds;
6431
  char**   mountPaths;
6432
  int32_t  sqlLen;
6433
  char*    sql;
6434
} SCreateMountReq;
6435

6436
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6437
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6438
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6439

6440
typedef struct {
6441
  char    mountName[TSDB_MOUNT_NAME_LEN];
6442
  int8_t  ignoreNotExists;
6443
  int32_t sqlLen;
6444
  char*   sql;
6445
} SDropMountReq;
6446

6447
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6448
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6449
void    tFreeSDropMountReq(SDropMountReq* pReq);
6450

6451
typedef struct {
6452
  char     mountName[TSDB_MOUNT_NAME_LEN];
6453
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6454
  int64_t  mountUid;
6455
  int32_t  dnodeId;
6456
  uint32_t valLen;
6457
  int8_t   ignoreExist;
6458
  void*    pVal;
6459
} SRetrieveMountPathReq;
6460

6461
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6462
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6463

6464
typedef struct {
6465
  // path
6466
  int32_t diskPrimary;
6467
  // vgInfo
6468
  int32_t  vgId;
6469
  int32_t  cacheLastSize;
6470
  int32_t  szPage;
6471
  int32_t  szCache;
6472
  uint64_t szBuf;
6473
  int8_t   cacheLast;
6474
  int8_t   standby;
6475
  int8_t   hashMethod;
6476
  uint32_t hashBegin;
6477
  uint32_t hashEnd;
6478
  int16_t  hashPrefix;
6479
  int16_t  hashSuffix;
6480
  int16_t  sttTrigger;
6481
  // syncInfo
6482
  int32_t replications;
6483
  // tsdbInfo
6484
  int8_t  precision;
6485
  int8_t  compression;
6486
  int8_t  slLevel;
6487
  int32_t daysPerFile;
6488
  int32_t keep0;
6489
  int32_t keep1;
6490
  int32_t keep2;
6491
  int32_t keepTimeOffset;
6492
  int32_t minRows;
6493
  int32_t maxRows;
6494
  int32_t tsdbPageSize;
6495
  int32_t ssChunkSize;
6496
  int32_t ssKeepLocal;
6497
  int8_t  ssCompact;
6498
  union {
6499
    uint8_t flags;
6500
    struct {
6501
      uint8_t isAudit : 1;
6502
      uint8_t allowDrop : 1;
6503
      uint8_t reserved : 6;
6504
    };
6505
  };
6506
  // walInfo
6507
  int32_t walFsyncPeriod;      // millisecond
6508
  int32_t walRetentionPeriod;  // secs
6509
  int32_t walRollPeriod;       // secs
6510
  int64_t walRetentionSize;
6511
  int64_t walSegSize;
6512
  int32_t walLevel;
6513
  // encryptInfo
6514
  int32_t encryptAlgorithm;
6515
  // SVState
6516
  int64_t committed;
6517
  int64_t commitID;
6518
  int64_t commitTerm;
6519
  // stats
6520
  int64_t numOfSTables;
6521
  int64_t numOfCTables;
6522
  int64_t numOfNTables;
6523
  // dbInfo
6524
  uint64_t dbId;
6525
} SMountVgInfo;
6526

6527
typedef struct {
6528
  SMCreateStbReq req;
6529
  SArray*        pColExts;  // element: column id
6530
  SArray*        pTagExts;  // element: tag id
6531
} SMountStbInfo;
6532

6533
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6534
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6535

6536
typedef struct {
6537
  char     dbName[TSDB_DB_FNAME_LEN];
6538
  uint64_t dbId;
6539
  SArray*  pVgs;   // SMountVgInfo
6540
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6541
} SMountDbInfo;
6542

6543
typedef struct {
6544
  // common fields
6545
  char     mountName[TSDB_MOUNT_NAME_LEN];
6546
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6547
  int8_t   ignoreExist;
6548
  int64_t  mountUid;
6549
  int64_t  clusterId;
6550
  int32_t  dnodeId;
6551
  uint32_t valLen;
6552
  void*    pVal;
6553

6554
  // response fields
6555
  SArray* pDbs;  // SMountDbInfo
6556

6557
  // memory fields, no serialized
6558
  SArray*   pDisks[TFS_MAX_TIERS];
6559
  TdFilePtr pFile;
6560
} SMountInfo;
6561

6562
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6563
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6564
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6565

6566
typedef struct {
6567
  SCreateVnodeReq createReq;
6568
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6569
  char            mountName[TSDB_MOUNT_NAME_LEN];
6570
  int64_t         mountId;
6571
  int32_t         diskPrimary;
6572
  int32_t         mountVgId;
6573
  int64_t         committed;
6574
  int64_t         commitID;
6575
  int64_t         commitTerm;
6576
  int64_t         numOfSTables;
6577
  int64_t         numOfCTables;
6578
  int64_t         numOfNTables;
6579
} SMountVnodeReq;
6580

6581
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6582
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6583
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6584

6585
#endif  // USE_MOUNT
6586

6587
#pragma pack(pop)
6588

6589
typedef struct {
6590
  char        db[TSDB_DB_FNAME_LEN];
6591
  STimeWindow timeRange;
6592
  int32_t     sqlLen;
6593
  char*       sql;
6594
  SArray*     vgroupIds;
6595
} SScanDbReq;
6596

6597
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6598
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6599
void    tFreeSScanDbReq(SScanDbReq* pReq);
6600

6601
typedef struct {
6602
  int32_t scanId;
6603
  int8_t  bAccepted;
6604
} SScanDbRsp;
6605

6606
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6607
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6608

6609
typedef struct {
6610
  int32_t scanId;
6611
  int32_t sqlLen;
6612
  char*   sql;
6613
} SKillScanReq;
6614

6615
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6616
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6617
void    tFreeSKillScanReq(SKillScanReq* pReq);
6618

6619
typedef struct {
6620
  int32_t scanId;
6621
  int32_t vgId;
6622
  int32_t dnodeId;
6623
} SVKillScanReq;
6624

6625
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6626
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6627

6628
typedef struct {
6629
  int32_t scanId;
6630
  int32_t vgId;
6631
  int32_t dnodeId;
6632
  int32_t numberFileset;
6633
  int32_t finished;
6634
  int32_t progress;
6635
  int64_t remainingTime;
6636
} SQueryScanProgressRsp;
6637

6638
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6639
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6640

6641
typedef struct {
6642
  int32_t scanId;
6643
  int32_t vgId;
6644
  int32_t dnodeId;
6645
} SQueryScanProgressReq;
6646

6647
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6648
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6649

6650
typedef struct {
6651
  int64_t     dbUid;
6652
  char        db[TSDB_DB_FNAME_LEN];
6653
  int64_t     scanStartTime;
6654
  STimeWindow tw;
6655
  int32_t     scanId;
6656
} SScanVnodeReq;
6657

6658
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6659
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6660

6661
#ifdef __cplusplus
6662
}
6663
#endif
6664

6665
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6666
 
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