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

taosdata / TDengine / #4951

06 Feb 2026 07:29AM UTC coverage: 66.887% (+0.04%) from 66.849%
#4951

push

travis-ci

web-flow
merge: from main to 3.0 #34521

765 of 1081 new or added lines in 28 files covered. (70.77%)

6419 existing lines in 131 files now uncovered.

205810 of 307696 relevant lines covered (66.89%)

127232277.37 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;
836✔
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
1,026,280,509✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
981,968,107✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
2,008,248,616✔
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_XNODE_TASK_OPTIONS,              // XNode task options
660
  QUERY_NODE_XNODE_TASK_SOURCE_OPT,           // XNode task source
661
  QUERY_NODE_XNODE_TASK_SINK_OPT,             // XNode task sink
662
  QUERY_NODE_CREATE_XNODE_TASK_STMT,          // XNode task
663
  QUERY_NODE_START_XNODE_TASK_STMT,           // XNode task
664
  QUERY_NODE_STOP_XNODE_TASK_STMT,            // XNode task
665
  QUERY_NODE_UPDATE_XNODE_TASK_STMT,          // XNode task
666
  QUERY_NODE_DROP_XNODE_TASK_STMT,            // XNode task
667
  QUERY_NODE_CREATE_XNODE_JOB_STMT,           // XNode job
668
  QUERY_NODE_ALTER_XNODE_JOB_STMT,            // XNode job
669
  QUERY_NODE_REBALANCE_XNODE_JOB_STMT,        // XNode job
670
  QUERY_NODE_REBALANCE_XNODE_JOB_WHERE_STMT,  // XNode job
671
  QUERY_NODE_DROP_XNODE_JOB_STMT,             // XNode job
672
  QUERY_NODE_CREATE_XNODE_AGENT_STMT,         // XNode agent
673
  QUERY_NODE_DROP_XNODE_AGENT_STMT,           // XNode agent
674
  QUERY_NODE_ALTER_XNODE_AGENT_STMT,          // XNode agent
675
  QUERY_NODE_ALTER_XNODE_STMT,                // Alter xnode
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) {
366,808✔
987
    return TSDB_CODE_INVALID_PARA;
×
988
  }
989
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
366,808✔
990
  if (pRef->pColRef == NULL) {
366,808✔
991
    return terrno;
×
992
  }
993
  pRef->nCols = nCols;
366,808✔
994
  for (int32_t i = 0; i < nCols; i++) {
143,427,830✔
995
    pRef->pColRef[i].hasRef = false;
143,061,022✔
996
    pRef->pColRef[i].id = (col_id_t)(i + 1);
143,061,022✔
997
  }
998
  return 0;
366,808✔
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,607,334✔
1027
    return TSDB_CODE_INVALID_PARA;
×
1028
  }
1029
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
6,607,334✔
1030
  if (pCmpr->pColCmpr == NULL) {
6,607,334✔
1031
    return terrno;
×
1032
  }
1033
  pCmpr->nCols = nCols;
6,607,334✔
1034
  return 0;
6,607,334✔
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;
591,422,663✔
1063

1064
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
591,058,898✔
1065
  if (pSW == NULL) {
591,228,878✔
1066
    return NULL;
×
1067
  }
1068
  pSW->nCols = pSchemaWrapper->nCols;
591,228,878✔
1069
  pSW->version = pSchemaWrapper->version;
591,248,522✔
1070
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
591,355,208✔
1071
  if (pSW->pSchema == NULL) {
591,114,439✔
1072
    taosMemoryFree(pSW);
×
1073
    return NULL;
×
1074
  }
1075

1076
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
591,052,686✔
1077
  return pSW;
591,510,619✔
1078
}
1079

1080
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
308,764,668✔
1081
  if (pSchemaWrapper) {
1,678,380,391✔
1082
    taosMemoryFree(pSchemaWrapper->pSchema);
953,391,044✔
1083
    if (pSchemaWrapper->pRsma) {
953,259,967✔
1084
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
26,100✔
1085
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
26,100✔
1086
    }
1087
    taosMemoryFree(pSchemaWrapper);
953,230,463✔
1088
  }
1089
}
1,634,837,954✔
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,219,589✔
1102
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,219,589✔
1103
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,219,589✔
1104
  }
1105
}
7,218,689✔
1106

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

1117
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1118
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,182,996✔
1119
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,182,690✔
1120
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,182,690✔
1121
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,182,690✔
1122
  buf = taosDecodeStringTo(buf, pSchema->name);
1,182,690✔
1123
  return (void*)buf;
1,182,690✔
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));
873,459,116✔
1160
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
873,459,116✔
1161
  if (pColRef->hasRef) {
436,729,558✔
1162
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
579,822,528✔
1163
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
579,822,528✔
1164
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
579,822,528✔
1165
  }
1166
  return 0;
436,729,558✔
1167
}
1168

1169
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1170
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
437,259,316✔
1171
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
437,259,316✔
1172
  if (pColRef->hasRef) {
218,629,658✔
1173
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
145,150,432✔
1174
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
145,150,432✔
1175
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
145,150,432✔
1176
  }
1177

1178
  return 0;
218,629,658✔
1179
}
1180

1181
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1182
  int32_t tlen = 0;
435,536✔
1183
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
435,536✔
1184
  tlen += taosEncodeVariantI32(buf, pSW->version);
435,536✔
1185
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,076,934✔
1186
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,282,796✔
1187
  }
1188
  return tlen;
435,536✔
1189
}
1190

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

1200
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,371,621✔
1201
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,365,380✔
1202
    }
1203
  } else {
1204
    pSW->pSchema = NULL;
×
1205
  }
1206
  return (void*)buf;
188,931✔
1207
}
1208

1209
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1210
  if (pSW == NULL) {
459,348,934✔
1211
    return TSDB_CODE_INVALID_PARA;
×
1212
  }
1213
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
918,697,297✔
1214
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
918,651,925✔
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;
459,491,364✔
1219
}
1220

1221
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1222
  if (pSW == NULL) {
190,406,832✔
1223
    return TSDB_CODE_INVALID_PARA;
×
1224
  }
1225
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
380,785,997✔
1226
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
380,765,060✔
1227

1228
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
190,385,895✔
1229
  if (pSW->pSchema == NULL) {
190,338,452✔
1230
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1231
  }
1232
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,733,277,490✔
1233
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1234
  }
1235

1236
  return 0;
190,433,847✔
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,766,738,438✔
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,767,662,224✔
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[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
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
  bool        shouldFree;
3653
  int32_t     len;
3654
  const char* ptr;
3655
} CowStr;
3656
/**
3657
 * @brief Create a CowStr object.
3658
 *
3659
 * @param len: length of the string.
3660
 * @param ptr: pointer to the string input.
3661
 * @param shouldClone: whether to clone the string.
3662
 * @return CowStr object.
3663
 */
3664
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3665
/**
3666
 * @brief Set a CowStr object with given string.
3667
 *
3668
 * @param cow: pointer to the CowStr object.
3669
 * @param len: length of the string.
3670
 * @param ptr: pointer to the string input.
3671
 * @param shouldFree: whether to free the string.
3672
 */
3673
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3674
/**
3675
 * @brief Clone a CowStr object without copy the string.
3676
 *
3677
 * @param cow: pointer to the CowStr object.
3678
 * @return CowStr object.
3679
 */
3680
CowStr xCloneRefCowStr(CowStr* cow);
3681
/**
3682
 * @brief Convert a CowStr object to a string.
3683
 *
3684
 * @param cow: pointer to the CowStr object.
3685
 */
3686
char* xCowStrToStr(CowStr* cow);
3687
/**
3688
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3689
 *
3690
 * @param cow: pointer to the CowStr object.
3691
 */
3692
void xFreeCowStr(CowStr* cow);
3693
/**
3694
 * @brief Encode and push a CowStr object into the encoder.
3695
 *
3696
 * @param encoder
3697
 * @param cow
3698
 * @return int32_t
3699
 */
3700
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3701
/**
3702
 * @brief Decode a CowStr from the encoder.
3703
 *
3704
 * @param decoder
3705
 * @param cow
3706
 * @param shouldClone
3707
 * @return int32_t
3708
 */
3709
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3710

3711
typedef struct {
3712
  int32_t sqlLen;
3713
  int32_t urlLen;
3714
  int32_t userLen;
3715
  int32_t passLen;
3716
  int32_t passIsMd5;
3717
  char*   sql;
3718
  char*   url;
3719
  char*   user;
3720
  char*   pass;
3721
  CowStr  token;
3722
} SMCreateXnodeReq, SDCreateXnodeReq;
3723

3724
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3725
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3726
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3727

3728
typedef struct {
3729
  int32_t xnodeId;
3730
  int32_t force;
3731
  int32_t urlLen;
3732
  int32_t sqlLen;
3733
  char*   url;
3734
  char*   sql;
3735
} SMDropXnodeReq, SDDropXnodeReq;
3736

3737
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3738
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3739
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3740

3741
typedef struct {
3742
  int32_t id;
3743
  CowStr  token;
3744
  CowStr  user;
3745
  CowStr  pass;
3746
  int32_t urlLen;
3747
  int32_t sqlLen;
3748
  char*   url;
3749
  char*   sql;
3750
} SMUpdateXnodeReq;
3751
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3752
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3753
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3754

3755
typedef struct {
3756
  int32_t xnodeId;
3757
  int32_t sqlLen;
3758
  char*   sql;
3759
} SMDrainXnodeReq;
3760
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3761
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3762
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3763
typedef enum {
3764
  XNODE_TASK_SOURCE_DSN = 1,
3765
  XNODE_TASK_SOURCE_DATABASE,
3766
  XNODE_TASK_SOURCE_TOPIC,
3767
} ENodeXTaskSourceType;
3768

3769
typedef enum {
3770
  XNODE_TASK_SINK_DSN = 1,
3771
  XNODE_TASK_SINK_DATABASE,
3772
} ENodeXTaskSinkType;
3773

3774
typedef struct {
3775
  ENodeXTaskSourceType type;
3776
  CowStr               cstr;
3777
} xTaskSource;
3778
/**
3779
 * @brief Deallocate a xTaskSource object.
3780
 *
3781
 * @param source ptr
3782
 */
3783
void xFreeTaskSource(xTaskSource* source);
3784
/**
3785
 * @brief Create a xTaskSource object with cloned source string.
3786
 *
3787
 * @param sourceType: source type.
3788
 * @param len: length of source string.
3789
 * @param source: source string ptr.
3790
 * @return xTaskSource object
3791
 */
3792
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3793
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3794
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3795
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3796
const char* xGetTaskSourceStr(xTaskSource* source);
3797
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3798
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3799

3800
typedef struct {
3801
  ENodeXTaskSinkType type;
3802
  CowStr             cstr;
3803
} xTaskSink;
3804
/**
3805
 * @brief Deallocate a xTaskSink object.
3806
 *
3807
 * @param sink ptr
3808
 */
3809
void xFreeTaskSink(xTaskSink* sink);
3810
/**
3811
 * @brief Create a xTaskSink object with cloned name string.
3812
 *
3813
 * @param sinkType: sink type.
3814
 * @param len: length of sink string.
3815
 * @param ptr: sink string ptr.
3816
 * @return xTaskSink object
3817
 */
3818
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3819
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3820
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3821
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3822
const char* xGetTaskSinkStr(xTaskSink* sink);
3823
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3824
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3825

3826
typedef struct {
3827
  int32_t via;
3828
  CowStr  parser;
3829
  // CowStr  reason;
3830
  CowStr  trigger;
3831
  CowStr  health;
3832
  int32_t optionsNum;
3833
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3834
} xTaskOptions;
3835
/**
3836
 * @brief Deallocate a xTaskOptions object.
3837
 *
3838
 * @param options ptr
3839
 */
3840
void    xFreeTaskOptions(xTaskOptions* options);
3841
void    printXnodeTaskOptions(xTaskOptions* options);
3842
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3843
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3844

3845
typedef struct {
3846
  int32_t sqlLen;
3847
  char*   sql;
3848
  int32_t      xnodeId;
3849
  CowStr       name;
3850
  xTaskSource  source;
3851
  xTaskSink    sink;
3852
  xTaskOptions options;
3853
} SMCreateXnodeTaskReq;
3854
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3855
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3856
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3857

3858
typedef struct {
3859
  int32_t     tid;
3860
  CowStr      name;
3861
  int32_t     via;
3862
  int32_t     xnodeId;
3863
  CowStr      status;
3864
  xTaskSource source;
3865
  xTaskSink   sink;
3866
  CowStr      parser;
3867
  CowStr      reason;
3868
  CowStr      updateName;
3869
  CowStr      labels;
3870
  int32_t     sqlLen;
3871
  char*       sql;
3872
} SMUpdateXnodeTaskReq;
3873
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3874
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3875
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3876

3877
typedef struct {
3878
  int32_t id;
3879
  bool    force;
3880
  CowStr  name;
3881
  int32_t sqlLen;
3882
  char*   sql;
3883
} SMDropXnodeTaskReq;
3884
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3885
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3886
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3887

3888
typedef struct {
3889
  int32_t tid;
3890
  CowStr  name;
3891
  int32_t sqlLen;
3892
  char*   sql;
3893
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3894
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3895
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3896
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3897

3898
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3899
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3900
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3901

3902
typedef struct {
3903
  int32_t tid;
3904
  int32_t via;
3905
  int32_t xnodeId;
3906
  CowStr  status;
3907
  CowStr  config;
3908
  CowStr  reason;
3909
  int32_t sqlLen;
3910
  char*   sql;
3911
} SMCreateXnodeJobReq;
3912
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3913
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3914
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3915

3916
typedef struct {
3917
  int32_t jid;
3918
  int32_t via;
3919
  int32_t xnodeId;
3920
  CowStr  status;
3921
  int32_t configLen;
3922
  int32_t reasonLen;
3923
  int32_t sqlLen;
3924
  char*   config;
3925
  char*   reason;
3926
  char*   sql;
3927
} SMUpdateXnodeJobReq;
3928
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3929
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3930
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3931

3932
typedef struct {
3933
  int32_t jid;
3934
  int32_t xnodeId;
3935
  int32_t sqlLen;
3936
  char*   sql;
3937
} SMRebalanceXnodeJobReq;
3938
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3939
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3940
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3941

3942
typedef struct {
3943
  CowStr  ast;
3944
  int32_t sqlLen;
3945
  char*   sql;
3946
} SMRebalanceXnodeJobsWhereReq;
3947
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3948
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3949
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3950

3951
typedef struct {
3952
  int32_t jid;
3953
  CowStr  ast;
3954
  int32_t sqlLen;
3955
  char*   sql;
3956
} SMDropXnodeJobReq;
3957
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3958
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3959
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3960

3961
typedef struct {
3962
  int32_t      sqlLen;
3963
  char*        sql;
3964
  CowStr       name;
3965
  CowStr       status;
3966
  xTaskOptions options;
3967
} SMCreateXnodeAgentReq;
3968
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3969
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3970
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
3971

3972
typedef struct {
3973
  int32_t      sqlLen;
3974
  char*        sql;
3975
  int32_t      id;
3976
  CowStr       name;
3977
  xTaskOptions options;
3978
} SMUpdateXnodeAgentReq;
3979
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3980
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3981
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
3982

3983
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
3984
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
3985
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
3986
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
3987

3988
typedef struct {
3989
  int32_t vgId;
3990
  int32_t hbSeq;
3991
} SVArbHbReqMember;
3992

3993
typedef struct {
3994
  int32_t dnodeId;
3995
  char*   arbToken;
3996
  int64_t arbTerm;
3997
  SArray* hbMembers;  // SVArbHbReqMember
3998
} SVArbHeartBeatReq;
3999

4000
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4001
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4002
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4003

4004
typedef struct {
4005
  int32_t vgId;
4006
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4007
  int32_t hbSeq;
4008
} SVArbHbRspMember;
4009

4010
typedef struct {
4011
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4012
  int32_t dnodeId;
4013
  SArray* hbMembers;  // SVArbHbRspMember
4014
} SVArbHeartBeatRsp;
4015

4016
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4017
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4018
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4019

4020
typedef struct {
4021
  char*   arbToken;
4022
  int64_t arbTerm;
4023
  char*   member0Token;
4024
  char*   member1Token;
4025
} SVArbCheckSyncReq;
4026

4027
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4028
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4029
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4030

4031
typedef struct {
4032
  char*   arbToken;
4033
  char*   member0Token;
4034
  char*   member1Token;
4035
  int32_t vgId;
4036
  int32_t errCode;
4037
} SVArbCheckSyncRsp;
4038

4039
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4040
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4041
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4042

4043
typedef struct {
4044
  char*   arbToken;
4045
  int64_t arbTerm;
4046
  char*   memberToken;
4047
  int8_t  force;
4048
} SVArbSetAssignedLeaderReq;
4049

4050
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4051
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4052
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4053

4054
typedef struct {
4055
  char*   arbToken;
4056
  char*   memberToken;
4057
  int32_t vgId;
4058
} SVArbSetAssignedLeaderRsp;
4059

4060
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4061
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4062
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4063

4064
typedef struct {
4065
  int32_t dnodeId;
4066
  char*   token;
4067
} SMArbUpdateGroupMember;
4068

4069
typedef struct {
4070
  int32_t dnodeId;
4071
  char*   token;
4072
  int8_t  acked;
4073
} SMArbUpdateGroupAssigned;
4074

4075
typedef struct {
4076
  int32_t                  vgId;
4077
  int64_t                  dbUid;
4078
  SMArbUpdateGroupMember   members[2];
4079
  int8_t                   isSync;
4080
  int8_t                   assignedAcked;
4081
  SMArbUpdateGroupAssigned assignedLeader;
4082
  int64_t                  version;
4083
  int32_t                  code;
4084
  int64_t                  updateTimeMs;
4085
} SMArbUpdateGroup;
4086

4087
typedef struct {
4088
  SArray* updateArray;  // SMArbUpdateGroup
4089
} SMArbUpdateGroupBatchReq;
4090

4091
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4092
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4093
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4094

4095
typedef struct {
4096
  char queryStrId[TSDB_QUERY_ID_LEN];
4097
} SKillQueryReq;
4098

4099
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4100
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4101

4102
typedef struct {
4103
  uint32_t connId;
4104
} SKillConnReq;
4105

4106
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4107
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4108

4109
typedef struct {
4110
  int32_t transId;
4111
} SKillTransReq;
4112

4113
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4114
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4115

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

4122
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4123
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4124
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4125

4126
typedef struct {
4127
  int32_t useless;  // useless
4128
  int32_t sqlLen;
4129
  char*   sql;
4130
} SAssignLeaderReq;
4131

4132
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4133
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4134
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4135
typedef struct {
4136
  int32_t vgId1;
4137
  int32_t vgId2;
4138
} SMergeVgroupReq;
4139

4140
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4141
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4142

4143
typedef struct {
4144
  int32_t vgId;
4145
  int32_t dnodeId1;
4146
  int32_t dnodeId2;
4147
  int32_t dnodeId3;
4148
  int32_t sqlLen;
4149
  char*   sql;
4150
} SRedistributeVgroupReq;
4151

4152
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4153
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4154
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4155

4156
typedef struct {
4157
  int32_t reserved;
4158
  int32_t vgId;
4159
  int32_t sqlLen;
4160
  char*   sql;
4161
  char    db[TSDB_DB_FNAME_LEN];
4162
} SBalanceVgroupLeaderReq;
4163

4164
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4165
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4166
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4167

4168
typedef struct {
4169
  int32_t vgId;
4170
} SForceBecomeFollowerReq;
4171

4172
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4173
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4174

4175
typedef struct {
4176
  int32_t vgId;
4177
  bool    force;
4178
} SSplitVgroupReq;
4179

4180
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4181
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4182

4183
typedef struct {
4184
  char user[TSDB_USER_LEN];
4185
  char spi;
4186
  char encrypt;
4187
  char secret[TSDB_PASSWORD_LEN];
4188
  char ckey[TSDB_PASSWORD_LEN];
4189
} SAuthReq, SAuthRsp;
4190

4191
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4192
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4193

4194
typedef struct {
4195
  int32_t statusCode;
4196
  char    details[1024];
4197
} SServerStatusRsp;
4198

4199
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4200
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4201

4202
/**
4203
 * The layout of the query message payload is as following:
4204
 * +--------------------+---------------------------------+
4205
 * |Sql statement       | Physical plan                   |
4206
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4207
 * +--------------------+---------------------------------+
4208
 */
4209
typedef struct SSubQueryMsg {
4210
  SMsgHead header;
4211
  uint64_t sId;
4212
  uint64_t queryId;
4213
  uint64_t clientId;
4214
  uint64_t taskId;
4215
  int64_t  refId;
4216
  int32_t  execId;
4217
  int32_t  msgMask;
4218
  int32_t  subQType;
4219
  int8_t   taskType;
4220
  int8_t   explain;
4221
  int8_t   needFetch;
4222
  int8_t   compress;
4223
  uint32_t sqlLen;
4224
  char*    sql;
4225
  uint32_t msgLen;
4226
  char*    msg;
4227
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4228
} SSubQueryMsg;
4229

4230
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4231
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4232
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4233

4234
typedef struct {
4235
  SMsgHead header;
4236
  uint64_t sId;
4237
  uint64_t queryId;
4238
  uint64_t taskId;
4239
} SSinkDataReq;
4240

4241
typedef struct {
4242
  SMsgHead header;
4243
  uint64_t sId;
4244
  uint64_t queryId;
4245
  uint64_t clientId;
4246
  uint64_t taskId;
4247
  int32_t  execId;
4248
} SQueryContinueReq;
4249

4250
typedef struct {
4251
  SMsgHead header;
4252
  uint64_t sId;
4253
  uint64_t queryId;
4254
  uint64_t taskId;
4255
} SResReadyReq;
4256

4257
typedef struct {
4258
  int32_t code;
4259
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4260
  int32_t sversion;
4261
  int32_t tversion;
4262
} SResReadyRsp;
4263

4264
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4265

4266
typedef struct SOperatorParam {
4267
  int32_t opType;
4268
  int32_t downstreamIdx;
4269
  void*   value;
4270
  SArray* pChildren;  // SArray<SOperatorParam*>
4271
  bool    reUse;
4272
} SOperatorParam;
4273

4274
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4275

4276
// virtual table's colId to origin table's colname
4277
typedef struct SColIdNameKV {
4278
  col_id_t colId;
4279
  char     colName[TSDB_COL_NAME_LEN];
4280
} SColIdNameKV;
4281

4282
#define COL_MASK_ON   ((int8_t)0x1)
4283
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4284
#define COL_SET_MASK_ON(c)     \
4285
  do {                         \
4286
    (c)->flags |= COL_MASK_ON; \
4287
  } while (0)
4288

4289
typedef struct SColNameFlag {
4290
  col_id_t colId;
4291
  char     colName[TSDB_COL_NAME_LEN];
4292
  int8_t   flags;  // 0x01: COL_MASK_ON
4293
} SColNameFlag;
4294

4295
typedef struct SColIdPair {
4296
  col_id_t  vtbColId;
4297
  col_id_t  orgColId;
4298
  SDataType type;
4299
} SColIdPair;
4300

4301
typedef struct SColIdSlotIdPair {
4302
  int32_t  vtbSlotId;
4303
  col_id_t orgColId;
4304
} SColIdSlotIdPair;
4305

4306
typedef struct SOrgTbInfo {
4307
  int32_t vgId;
4308
  char    tbName[TSDB_TABLE_FNAME_LEN];
4309
  SArray* colMap;  // SArray<SColIdNameKV>
4310
} SOrgTbInfo;
4311

4312
void destroySOrgTbInfo(void *info);
4313

4314
typedef enum {
4315
  DYN_TYPE_STB_JOIN = 1,
4316
  DYN_TYPE_VSTB_SINGLE_SCAN,
4317
  DYN_TYPE_VSTB_BATCH_SCAN,
4318
  DYN_TYPE_VSTB_WIN_SCAN,
4319
} ETableScanDynType;
4320

4321
typedef enum {
4322
  DYN_TYPE_SCAN_PARAM = 1,
4323
  NOTIFY_TYPE_SCAN_PARAM,
4324
} ETableScanGetParamType;
4325

4326
typedef struct STableScanOperatorParam {
4327
  ETableScanGetParamType paramType;
4328
  /* for building scan data source */
4329
  bool                   tableSeq;
4330
  bool                   isNewParam;
4331
  uint64_t               groupid;
4332
  SArray*                pUidList;
4333
  SOrgTbInfo*            pOrgTbInfo;
4334
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4335
  SArray*                pTagList;
4336
  STimeWindow            window;
4337
  ETableScanDynType      dynType;
4338
  /* for notifying source step done */
4339
  bool                   notifyToProcess;  // received notify STEP DONE message
4340
  TSKEY                  notifyTs;         // notify timestamp
4341
} STableScanOperatorParam;
4342

4343
typedef struct STagScanOperatorParam {
4344
  tb_uid_t vcUid;
4345
} STagScanOperatorParam;
4346

4347
typedef struct SRefColIdGroup {
4348
  SArray* pSlotIdList;  // SArray<int32_t>
4349
} SRefColIdGroup;
4350

4351
typedef struct SVTableScanOperatorParam {
4352
  uint64_t        uid;
4353
  STimeWindow     window;
4354
  SOperatorParam* pTagScanOp;
4355
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4356
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4357
} SVTableScanOperatorParam;
4358

4359
typedef struct SMergeOperatorParam {
4360
  int32_t         winNum;
4361
} SMergeOperatorParam;
4362

4363
typedef struct SAggOperatorParam {
4364
  bool            needCleanRes;
4365
} SAggOperatorParam;
4366

4367
typedef struct SExternalWindowOperatorParam {
4368
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4369
} SExternalWindowOperatorParam;
4370

4371
typedef struct SDynQueryCtrlOperatorParam {
4372
  STimeWindow    window;
4373
} SDynQueryCtrlOperatorParam;
4374

4375
struct SStreamRuntimeFuncInfo;
4376
typedef struct {
4377
  SMsgHead        header;
4378
  uint64_t        sId;
4379
  uint64_t        queryId;
4380
  uint64_t        clientId;
4381
  uint64_t        taskId;
4382
  uint64_t        srcTaskId;  // used for subQ
4383
  uint64_t        blockIdx;   // used for subQ
4384
  int32_t         execId;
4385
  SOperatorParam* pOpParam;
4386

4387
  // used for new-stream
4388
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4389
  bool                           reset;
4390
  bool                           dynTbname;
4391
  // used for new-stream
4392
} SResFetchReq;
4393

4394
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4395
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4396
void    tDestroySResFetchReq(SResFetchReq* pReq);
4397
typedef struct {
4398
  SMsgHead header;
4399
  uint64_t clientId;
4400
} SSchTasksStatusReq;
4401

4402
typedef struct {
4403
  uint64_t queryId;
4404
  uint64_t clientId;
4405
  uint64_t taskId;
4406
  int64_t  refId;
4407
  int32_t  subJobId;
4408
  int32_t  execId;
4409
  int8_t   status;
4410
} STaskStatus;
4411

4412
typedef struct {
4413
  int64_t refId;
4414
  SArray* taskStatus;  // SArray<STaskStatus>
4415
} SSchedulerStatusRsp;
4416

4417
typedef struct {
4418
  uint64_t queryId;
4419
  uint64_t taskId;
4420
  int8_t   action;
4421
} STaskAction;
4422

4423
typedef struct SQueryNodeEpId {
4424
  int32_t nodeId;  // vgId or qnodeId
4425
  SEp     ep;
4426
} SQueryNodeEpId;
4427

4428
typedef struct {
4429
  SMsgHead       header;
4430
  uint64_t       clientId;
4431
  SQueryNodeEpId epId;
4432
  SArray*        taskAction;  // SArray<STaskAction>
4433
} SSchedulerHbReq;
4434

4435
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4436
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4437
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4438

4439
typedef struct {
4440
  SQueryNodeEpId epId;
4441
  SArray*        taskStatus;  // SArray<STaskStatus>
4442
} SSchedulerHbRsp;
4443

4444
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4445
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4446
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4447

4448
typedef struct {
4449
  SMsgHead header;
4450
  uint64_t sId;
4451
  uint64_t queryId;
4452
  uint64_t clientId;
4453
  uint64_t taskId;
4454
  int64_t  refId;
4455
  int32_t  execId;
4456
} STaskCancelReq;
4457

4458
typedef struct {
4459
  int32_t code;
4460
} STaskCancelRsp;
4461

4462
typedef struct {
4463
  SMsgHead header;
4464
  uint64_t sId;
4465
  uint64_t queryId;
4466
  uint64_t clientId;
4467
  uint64_t taskId;
4468
  int64_t  refId;
4469
  int32_t  execId;
4470
} STaskDropReq;
4471

4472
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4473
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4474

4475
typedef enum {
4476
  TASK_NOTIFY_FINISHED = 1,
4477
} ETaskNotifyType;
4478

4479
typedef struct {
4480
  SMsgHead        header;
4481
  uint64_t        sId;
4482
  uint64_t        queryId;
4483
  uint64_t        clientId;
4484
  uint64_t        taskId;
4485
  int64_t         refId;
4486
  int32_t         execId;
4487
  ETaskNotifyType type;
4488
} STaskNotifyReq;
4489

4490
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4491
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4492

4493
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4494
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4495

4496
typedef struct {
4497
  int32_t code;
4498
} STaskDropRsp;
4499

4500
#define STREAM_TRIGGER_AT_ONCE                 1
4501
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4502
#define STREAM_TRIGGER_MAX_DELAY               3
4503
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4504
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4505

4506
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4507
#define STREAM_FILL_HISTORY_ON        1
4508
#define STREAM_FILL_HISTORY_OFF       0
4509
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4510
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4511
#define STREAM_CREATE_STABLE_TRUE     1
4512
#define STREAM_CREATE_STABLE_FALSE    0
4513

4514
typedef struct SVgroupVer {
4515
  int32_t vgId;
4516
  int64_t ver;
4517
} SVgroupVer;
4518

4519
typedef struct STaskNotifyEventStat {
4520
  int64_t notifyEventAddTimes;     // call times of add function
4521
  int64_t notifyEventAddElems;     // elements added by add function
4522
  double  notifyEventAddCostSec;   // time cost of add function
4523
  int64_t notifyEventPushTimes;    // call times of push function
4524
  int64_t notifyEventPushElems;    // elements pushed by push function
4525
  double  notifyEventPushCostSec;  // time cost of push function
4526
  int64_t notifyEventPackTimes;    // call times of pack function
4527
  int64_t notifyEventPackElems;    // elements packed by pack function
4528
  double  notifyEventPackCostSec;  // time cost of pack function
4529
  int64_t notifyEventSendTimes;    // call times of send function
4530
  int64_t notifyEventSendElems;    // elements sent by send function
4531
  double  notifyEventSendCostSec;  // time cost of send function
4532
  int64_t notifyEventHoldElems;    // elements hold due to watermark
4533
} STaskNotifyEventStat;
4534

4535
enum {
4536
  TOPIC_SUB_TYPE__DB = 1,
4537
  TOPIC_SUB_TYPE__TABLE,
4538
  TOPIC_SUB_TYPE__COLUMN,
4539
};
4540

4541
#define DEFAULT_MAX_POLL_INTERVAL  300000
4542
#define DEFAULT_SESSION_TIMEOUT    12000
4543
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4544
#define DEFAULT_MIN_POLL_ROWS      4096
4545

4546
typedef struct {
4547
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4548
  int8_t igExists;
4549
  int8_t subType;
4550
  int8_t withMeta;
4551
  char*  sql;
4552
  char   subDbName[TSDB_DB_FNAME_LEN];
4553
  char*  ast;
4554
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4555
  int8_t reload;
4556
} SCMCreateTopicReq;
4557

4558
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4559
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4560
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4561

4562
typedef struct {
4563
  int64_t consumerId;
4564
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4565

4566
typedef struct {
4567
  int64_t consumerId;
4568
  char    cgroup[TSDB_CGROUP_LEN];
4569
  char    clientId[TSDB_CLIENT_ID_LEN];
4570
  char    user[TSDB_USER_LEN];
4571
  char    fqdn[TSDB_FQDN_LEN];
4572
  SArray* topicNames;  // SArray<char**>
4573

4574
  int8_t  withTbName;
4575
  int8_t  autoCommit;
4576
  int32_t autoCommitInterval;
4577
  int8_t  resetOffsetCfg;
4578
  int8_t  enableReplay;
4579
  int8_t  enableBatchMeta;
4580
  int32_t sessionTimeoutMs;
4581
  int32_t maxPollIntervalMs;
4582
  int64_t ownerId;
4583
} SCMSubscribeReq;
4584

4585
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4586
  int32_t tlen = 0;
678,000✔
4587
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
678,000✔
4588
  tlen += taosEncodeString(buf, pReq->cgroup);
678,000✔
4589
  tlen += taosEncodeString(buf, pReq->clientId);
678,000✔
4590

4591
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
678,000✔
4592
  tlen += taosEncodeFixedI32(buf, topicNum);
678,000✔
4593

4594
  for (int32_t i = 0; i < topicNum; i++) {
939,950✔
4595
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
523,900✔
4596
  }
4597

4598
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
678,000✔
4599
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
678,000✔
4600
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
678,000✔
4601
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
678,000✔
4602
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
678,000✔
4603
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
678,000✔
4604
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
678,000✔
4605
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
678,000✔
4606
  tlen += taosEncodeString(buf, pReq->user);
678,000✔
4607
  tlen += taosEncodeString(buf, pReq->fqdn);
678,000✔
4608

4609
  return tlen;
678,000✔
4610
}
4611

4612
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4613
  void* start = buf;
338,926✔
4614
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
338,926✔
4615
  buf = taosDecodeStringTo(buf, pReq->cgroup);
338,926✔
4616
  buf = taosDecodeStringTo(buf, pReq->clientId);
338,926✔
4617

4618
  int32_t topicNum = 0;
338,926✔
4619
  buf = taosDecodeFixedI32(buf, &topicNum);
338,926✔
4620

4621
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
338,926✔
4622
  if (pReq->topicNames == NULL) {
338,926✔
UNCOV
4623
    return terrno;
×
4624
  }
4625
  for (int32_t i = 0; i < topicNum; i++) {
480,488✔
4626
    char* name = NULL;
141,562✔
4627
    buf = taosDecodeString(buf, &name);
141,562✔
4628
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
283,124✔
UNCOV
4629
      return terrno;
×
4630
    }
4631
  }
4632

4633
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
338,926✔
4634
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
338,926✔
4635
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
338,926✔
4636
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
338,926✔
4637
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
338,926✔
4638
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
338,926✔
4639
  if ((char*)buf - (char*)start < len) {
338,926✔
4640
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
338,926✔
4641
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
338,926✔
4642
    buf = taosDecodeStringTo(buf, pReq->user);
338,926✔
4643
    buf = taosDecodeStringTo(buf, pReq->fqdn);
677,852✔
4644
  } else {
UNCOV
4645
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4646
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4647
  }
4648

4649
  return 0;
338,926✔
4650
}
4651

4652
typedef struct {
4653
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4654
  SArray* removedConsumers;  // SArray<int64_t>
4655
  SArray* newConsumers;      // SArray<int64_t>
4656
} SMqRebInfo;
4657

4658
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4659
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
310,875✔
4660
  if (pRebInfo == NULL) {
310,875✔
UNCOV
4661
    return NULL;
×
4662
  }
4663
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
310,875✔
4664
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
310,875✔
4665
  if (pRebInfo->removedConsumers == NULL) {
310,875✔
UNCOV
4666
    goto _err;
×
4667
  }
4668
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
310,875✔
4669
  if (pRebInfo->newConsumers == NULL) {
310,875✔
UNCOV
4670
    goto _err;
×
4671
  }
4672
  return pRebInfo;
310,875✔
UNCOV
4673
_err:
×
UNCOV
4674
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
4675
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
4676
  taosMemoryFreeClear(pRebInfo);
×
4677
  return NULL;
×
4678
}
4679

4680
typedef struct {
4681
  int64_t streamId;
4682
  int64_t checkpointId;
4683
  char    streamName[TSDB_STREAM_FNAME_LEN];
4684
} SMStreamDoCheckpointMsg;
4685

4686
typedef struct {
4687
  int64_t status;
4688
} SMVSubscribeRsp;
4689

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

4698
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4699
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4700
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4701

4702
typedef struct {
4703
  char    name[TSDB_TOPIC_FNAME_LEN];
4704
  int8_t  igNotExists;
4705
  int32_t sqlLen;
4706
  char*   sql;
4707
} SMReloadTopicReq;
4708

4709
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4710
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4711
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4712

4713
typedef struct {
4714
  char   topic[TSDB_TOPIC_FNAME_LEN];
4715
  char   cgroup[TSDB_CGROUP_LEN];
4716
  int8_t igNotExists;
4717
  int8_t force;
4718
} SMDropCgroupReq;
4719

4720
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4721
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4722

4723
typedef struct {
4724
  int8_t reserved;
4725
} SMDropCgroupRsp;
4726

4727
typedef struct {
4728
  char    name[TSDB_TABLE_FNAME_LEN];
4729
  int8_t  alterType;
4730
  SSchema schema;
4731
} SAlterTopicReq;
4732

4733
typedef struct {
4734
  SMsgHead head;
4735
  char     name[TSDB_TABLE_FNAME_LEN];
4736
  int64_t  tuid;
4737
  int32_t  sverson;
4738
  int32_t  execLen;
4739
  char*    executor;
4740
  int32_t  sqlLen;
4741
  char*    sql;
4742
} SDCreateTopicReq;
4743

4744
typedef struct {
4745
  SMsgHead head;
4746
  char     name[TSDB_TABLE_FNAME_LEN];
4747
  int64_t  tuid;
4748
} SDDropTopicReq;
4749

4750
typedef struct {
4751
  char*      name;
4752
  int64_t    uid;
4753
  int64_t    interval[2];
4754
  int8_t     intervalUnit;
4755
  int16_t    nFuncs;
4756
  col_id_t*  funcColIds;  // column ids specified by user
4757
  func_id_t* funcIds;     // function ids specified by user
4758
} SRSmaParam;
4759

4760
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4761
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4762

4763
// TDMT_VND_CREATE_STB ==============
4764
typedef struct SVCreateStbReq {
4765
  char*           name;
4766
  tb_uid_t        suid;
4767
  int8_t          rollup;
4768
  SSchemaWrapper  schemaRow;
4769
  SSchemaWrapper  schemaTag;
4770
  SRSmaParam      rsmaParam;
4771
  int32_t         alterOriDataLen;
4772
  void*           alterOriData;
4773
  int8_t          source;
4774
  int8_t          colCmpred;
4775
  SColCmprWrapper colCmpr;
4776
  int64_t         keep;
4777
  int64_t         ownerId;
4778
  SExtSchema*     pExtSchemas;
4779
  int8_t          virtualStb;
4780
} SVCreateStbReq;
4781

4782
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4783
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4784

4785
// TDMT_VND_DROP_STB ==============
4786
typedef struct SVDropStbReq {
4787
  char*    name;
4788
  tb_uid_t suid;
4789
} SVDropStbReq;
4790

4791
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4792
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4793

4794
// TDMT_VND_CREATE_TABLE ==============
4795
#define TD_CREATE_IF_NOT_EXISTS       0x1
4796
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4797
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4798
typedef struct SVCreateTbReq {
4799
  int32_t  flags;
4800
  char*    name;
4801
  tb_uid_t uid;
4802
  int64_t  btime;
4803
  int32_t  ttl;
4804
  int32_t  commentLen;
4805
  char*    comment;
4806
  int8_t   type;
4807
  union {
4808
    struct {
4809
      char*    stbName;  // super table name
4810
      uint8_t  tagNum;
4811
      tb_uid_t suid;
4812
      SArray*  tagName;
4813
      uint8_t* pTag;
4814
    } ctb;
4815
    struct {
4816
      SSchemaWrapper schemaRow;
4817
      int64_t        userId;
4818
    } ntb;
4819
  };
4820
  int32_t         sqlLen;
4821
  char*           sql;
4822
  SColCmprWrapper colCmpr;
4823
  SExtSchema*     pExtSchemas;
4824
  SColRefWrapper  colRef;  // col reference for virtual table
4825
} SVCreateTbReq;
4826

4827
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4828
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4829
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4830
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4831

4832
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4833
  if (NULL == req) {
2,147,483,647✔
4834
    return;
2,147,483,647✔
4835
  }
4836

4837
  taosMemoryFreeClear(req->sql);
74,760,732✔
4838
  taosMemoryFreeClear(req->name);
74,757,377✔
4839
  taosMemoryFreeClear(req->comment);
74,776,341✔
4840
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
74,754,051✔
4841
    taosMemoryFreeClear(req->ctb.pTag);
67,885,119✔
4842
    taosMemoryFreeClear(req->ctb.stbName);
67,853,579✔
4843
    taosArrayDestroy(req->ctb.tagName);
67,891,225✔
4844
    req->ctb.tagName = NULL;
67,827,561✔
4845
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
6,882,161✔
4846
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
6,882,161✔
4847
  }
4848
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
74,726,631✔
4849
  taosMemoryFreeClear(req->pExtSchemas);
74,756,101✔
4850
  taosMemoryFreeClear(req->colRef.pColRef);
74,760,538✔
4851
}
4852

4853
typedef struct {
4854
  int32_t nReqs;
4855
  union {
4856
    SVCreateTbReq* pReqs;
4857
    SArray*        pArray;
4858
  };
4859
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4860
} SVCreateTbBatchReq;
4861

4862
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4863
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4864
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4865

4866
typedef struct {
4867
  int32_t        code;
4868
  STableMetaRsp* pMeta;
4869
} SVCreateTbRsp, SVUpdateTbRsp;
4870

4871
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4872
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4873
void tFreeSVCreateTbRsp(void* param);
4874

4875
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4876
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4877

4878
typedef struct {
4879
  int32_t nRsps;
4880
  union {
4881
    SVCreateTbRsp* pRsps;
4882
    SArray*        pArray;
4883
  };
4884
} SVCreateTbBatchRsp;
4885

4886
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4887
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4888

4889
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4890
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4891

4892
// TDMT_VND_DROP_TABLE =================
4893
typedef struct {
4894
  char*    name;
4895
  uint64_t suid;  // for tmq in wal format
4896
  int64_t  uid;
4897
  int8_t   igNotExists;
4898
  int8_t   isVirtual;
4899
} SVDropTbReq;
4900

4901
typedef struct {
4902
  int32_t code;
4903
} SVDropTbRsp;
4904

4905
typedef struct {
4906
  int32_t nReqs;
4907
  union {
4908
    SVDropTbReq* pReqs;
4909
    SArray*      pArray;
4910
  };
4911
} SVDropTbBatchReq;
4912

4913
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4914
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4915

4916
typedef struct {
4917
  int32_t nRsps;
4918
  union {
4919
    SVDropTbRsp* pRsps;
4920
    SArray*      pArray;
4921
  };
4922
} SVDropTbBatchRsp;
4923

4924
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4925
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4926

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

4977
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4978
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4979
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4980
void    tfreeMultiTagUpateVal(void* pMultiTag);
4981

4982
typedef struct {
4983
  int32_t        code;
4984
  STableMetaRsp* pMeta;
4985
} SVAlterTbRsp;
4986

4987
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4988
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4989
// ======================
4990

4991
typedef struct {
4992
  SMsgHead head;
4993
  int64_t  uid;
4994
  int32_t  tid;
4995
  int16_t  tversion;
4996
  int16_t  colId;
4997
  int8_t   type;
4998
  int16_t  bytes;
4999
  int32_t  tagValLen;
5000
  int16_t  numOfTags;
5001
  int32_t  schemaLen;
5002
  char     data[];
5003
} SUpdateTagValReq;
5004

5005
typedef struct {
5006
  SMsgHead head;
5007
} SUpdateTagValRsp;
5008

5009
typedef struct {
5010
  SMsgHead head;
5011
} SVShowTablesReq;
5012

5013
typedef struct {
5014
  SMsgHead head;
5015
  int32_t  id;
5016
} SVShowTablesFetchReq;
5017

5018
typedef struct {
5019
  int64_t useconds;
5020
  int8_t  completed;  // all results are returned to client
5021
  int8_t  precision;
5022
  int8_t  compressed;
5023
  int32_t compLen;
5024
  int32_t numOfRows;
5025
  char    data[];
5026
} SVShowTablesFetchRsp;
5027

5028
typedef struct {
5029
  int64_t consumerId;
5030
  int32_t epoch;
5031
  char    cgroup[TSDB_CGROUP_LEN];
5032
} SMqAskEpReq;
5033

5034
typedef struct {
5035
  int32_t key;
5036
  int32_t valueLen;
5037
  void*   value;
5038
} SKv;
5039

5040
typedef struct {
5041
  int64_t tscRid;
5042
  int8_t  connType;
5043
} SClientHbKey;
5044

5045
typedef struct {
5046
  int64_t tid;
5047
  char    status[TSDB_JOB_STATUS_LEN];
5048
} SQuerySubDesc;
5049

5050
typedef struct {
5051
  char     sql[TSDB_SHOW_SQL_LEN];
5052
  uint64_t queryId;
5053
  int64_t  useconds;
5054
  int64_t  stime;  // timestamp precision ms
5055
  int64_t  reqRid;
5056
  bool     stableQuery;
5057
  bool     isSubQuery;
5058
  char     fqdn[TSDB_FQDN_LEN];
5059
  int32_t  subPlanNum;
5060
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5061
} SQueryDesc;
5062

5063
typedef struct {
5064
  uint32_t connId;
5065
  SArray*  queryDesc;  // SArray<SQueryDesc>
5066
} SQueryHbReqBasic;
5067

5068
typedef struct {
5069
  uint32_t connId;
5070
  uint64_t killRid;
5071
  int32_t  totalDnodes;
5072
  int32_t  onlineDnodes;
5073
  int8_t   killConnection;
5074
  int8_t   align[3];
5075
  SEpSet   epSet;
5076
  SArray*  pQnodeList;
5077
} SQueryHbRspBasic;
5078

5079
typedef struct SAppClusterSummary {
5080
  uint64_t numOfInsertsReq;
5081
  uint64_t numOfInsertRows;
5082
  uint64_t insertElapsedTime;
5083
  uint64_t insertBytes;  // submit to tsdb since launched.
5084

5085
  uint64_t fetchBytes;
5086
  uint64_t numOfQueryReq;
5087
  uint64_t queryElapsedTime;
5088
  uint64_t numOfSlowQueries;
5089
  uint64_t totalRequests;
5090
  uint64_t currentRequests;  // the number of SRequestObj
5091
} SAppClusterSummary;
5092

5093
typedef struct {
5094
  int64_t            appId;
5095
  int32_t            pid;
5096
  char               name[TSDB_APP_NAME_LEN];
5097
  int64_t            startTime;
5098
  SAppClusterSummary summary;
5099
} SAppHbReq;
5100

5101
typedef struct {
5102
  SClientHbKey      connKey;
5103
  int64_t           clusterId;
5104
  SAppHbReq         app;
5105
  SQueryHbReqBasic* query;
5106
  SHashObj*         info;  // hash<Skv.key, Skv>
5107
  char              user[TSDB_USER_LEN];
5108
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5109
  char              userApp[TSDB_APP_NAME_LEN];
5110
  uint32_t          userIp;
5111
  SIpRange          userDualIp;
5112
  char              sVer[TSDB_VERSION_LEN];
5113
  char              cInfo[CONNECTOR_INFO_LEN];
5114
} SClientHbReq;
5115

5116
typedef struct {
5117
  int64_t reqId;
5118
  SArray* reqs;  // SArray<SClientHbReq>
5119
  int64_t ipWhiteListVer;
5120
} SClientHbBatchReq;
5121

5122
typedef struct {
5123
  SClientHbKey      connKey;
5124
  int32_t           status;
5125
  SQueryHbRspBasic* query;
5126
  SArray*           info;  // Array<Skv>
5127
} SClientHbRsp;
5128

5129
typedef struct {
5130
  int64_t       reqId;
5131
  int64_t       rspId;
5132
  int32_t       svrTimestamp;
5133
  SArray*       rsps;  // SArray<SClientHbRsp>
5134
  SMonitorParas monitorParas;
5135
  int8_t        enableAuditDelete;
5136
  int8_t        enableStrongPass;
5137
  int8_t        enableAuditSelect;
5138
  int8_t        enableAuditInsert;
5139
  int8_t        auditLevel;
5140
} SClientHbBatchRsp;
5141

5142
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
75,489,826✔
5143

5144
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5145
  void* pIter = taosHashIterate(info, NULL);
51,352,230✔
5146
  while (pIter != NULL) {
121,183,627✔
5147
    SKv* kv = (SKv*)pIter;
69,829,802✔
5148
    taosMemoryFreeClear(kv->value);
69,829,802✔
5149
    pIter = taosHashIterate(info, pIter);
69,830,372✔
5150
  }
5151
}
51,353,825✔
5152

5153
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
33,305,708✔
5154
  SQueryDesc* desc = (SQueryDesc*)pDesc;
33,305,708✔
5155
  if (desc->subDesc) {
33,305,708✔
5156
    taosArrayDestroy(desc->subDesc);
23,485,641✔
5157
    desc->subDesc = NULL;
23,483,106✔
5158
  }
5159
}
33,302,888✔
5160

5161
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
58,347,388✔
5162
  SClientHbReq* req = (SClientHbReq*)pReq;
61,129,880✔
5163
  if (req->query) {
61,129,880✔
5164
    if (req->query->queryDesc) {
58,346,001✔
5165
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
26,975,330✔
5166
    }
5167
    taosMemoryFreeClear(req->query);
58,345,762✔
5168
  }
5169

5170
  if (req->info) {
61,130,282✔
5171
    tFreeReqKvHash(req->info);
51,348,581✔
5172
    taosHashCleanup(req->info);
51,353,825✔
5173
    req->info = NULL;
51,351,774✔
5174
  }
5175
}
31,014,106✔
5176

5177
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5178
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5179

5180
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5181
  if (pReq == NULL) return;
25,364,205✔
5182
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
25,364,205✔
5183
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
25,364,205✔
5184
  taosMemoryFree(pReq);
25,364,205✔
5185
}
5186

5187
static FORCE_INLINE void tFreeClientKv(void* pKv) {
69,592,022✔
5188
  SKv* kv = (SKv*)pKv;
69,592,022✔
5189
  if (kv) {
69,592,022✔
5190
    taosMemoryFreeClear(kv->value);
69,592,530✔
5191
  }
5192
}
69,592,194✔
5193

5194
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
58,164,036✔
5195
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
58,164,036✔
5196
  if (rsp->query) {
58,164,036✔
5197
    taosArrayDestroy(rsp->query->pQnodeList);
58,152,818✔
5198
    taosMemoryFreeClear(rsp->query);
58,160,582✔
5199
  }
5200
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
58,167,383✔
5201
}
29,938,439✔
5202

5203
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5204
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
49,069,821✔
5205
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
49,069,821✔
5206
}
49,070,982✔
5207

5208
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5209
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5210
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5211

5212
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5213
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
439,257,794✔
5214
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
439,257,740✔
5215
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
439,257,289✔
5216
  return 0;
219,626,849✔
5217
}
5218

5219
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5220
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
143,866,416✔
5221
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
143,865,476✔
5222
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
71,932,393✔
5223
  if (pKv->value == NULL) {
71,932,977✔
UNCOV
5224
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5225
  }
5226
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
71,933,333✔
5227
  return 0;
71,933,333✔
5228
}
5229

5230
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5231
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
368,054,713✔
5232
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
368,039,555✔
5233
  return 0;
184,018,331✔
5234
}
5235

5236
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5237
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
120,861,157✔
5238
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
120,861,193✔
5239
  return 0;
60,431,150✔
5240
}
5241

5242
typedef struct {
5243
  int32_t vgId;
5244
  // TODO stas
5245
} SMqReportVgInfo;
5246

5247
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5248
  int32_t tlen = 0;
5249
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5250
  return tlen;
5251
}
5252

5253
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5254
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5255
  return buf;
5256
}
5257

5258
typedef struct {
5259
  int32_t epoch;
5260
  int64_t topicUid;
5261
  char    name[TSDB_TOPIC_FNAME_LEN];
5262
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5263
} SMqTopicInfo;
5264

5265
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5266
  int32_t tlen = 0;
5267
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5268
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5269
  tlen += taosEncodeString(buf, pTopicInfo->name);
5270
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5271
  tlen += taosEncodeFixedI32(buf, sz);
5272
  for (int32_t i = 0; i < sz; i++) {
5273
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5274
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5275
  }
5276
  return tlen;
5277
}
5278

5279
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5280
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5281
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5282
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5283
  int32_t sz;
5284
  buf = taosDecodeFixedI32(buf, &sz);
5285
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5286
    return NULL;
5287
  }
5288
  for (int32_t i = 0; i < sz; i++) {
5289
    SMqReportVgInfo vgInfo;
5290
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5291
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5292
      return NULL;
5293
    }
5294
  }
5295
  return buf;
5296
}
5297

5298
typedef struct {
5299
  int32_t status;  // ask hb endpoint
5300
  int32_t epoch;
5301
  int64_t consumerId;
5302
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5303
} SMqReportReq;
5304

5305
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5306
  int32_t tlen = 0;
5307
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5308
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5309
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5310
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5311
  tlen += taosEncodeFixedI32(buf, sz);
5312
  for (int32_t i = 0; i < sz; i++) {
5313
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5314
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5315
  }
5316
  return tlen;
5317
}
5318

5319
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5320
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5321
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5322
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5323
  int32_t sz;
5324
  buf = taosDecodeFixedI32(buf, &sz);
5325
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5326
    return NULL;
5327
  }
5328
  for (int32_t i = 0; i < sz; i++) {
5329
    SMqTopicInfo topicInfo;
5330
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5331
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5332
      return NULL;
5333
    }
5334
  }
5335
  return buf;
5336
}
5337

5338
typedef struct {
5339
  SMsgHead head;
5340
  int64_t  leftForVer;
5341
  int32_t  vgId;
5342
  int64_t  consumerId;
5343
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5344
} SMqVDeleteReq;
5345

5346
typedef struct {
5347
  int8_t reserved;
5348
} SMqVDeleteRsp;
5349

5350
typedef struct {
5351
  char**  name;
5352
  int32_t count;
5353
  int8_t igNotExists;
5354
} SMDropStreamReq;
5355

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

5360
typedef struct {
5361
  SMsgHead head;
5362
  int64_t  resetRelHalt;  // reset related stream task halt status
5363
  int64_t  streamId;
5364
  int32_t  taskId;
5365
} SVDropStreamTaskReq;
5366

5367
typedef struct {
5368
  int8_t reserved;
5369
} SVDropStreamTaskRsp;
5370

5371
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5372
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5373
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5374

5375
typedef struct {
5376
  char*  name;
5377
  int8_t igNotExists;
5378
} SMPauseStreamReq;
5379

5380
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5381
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5382
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5383

5384
typedef struct {
5385
  char*  name;
5386
  int8_t igNotExists;
5387
  int8_t igUntreated;
5388
} SMResumeStreamReq;
5389

5390
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5391
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5392
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5393

5394
typedef struct {
5395
  char*       name;
5396
  int8_t      calcAll;
5397
  STimeWindow timeRange;
5398
} SMRecalcStreamReq;
5399

5400
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5401
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5402
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5403

5404

5405
typedef struct SVndSetKeepVersionReq {
5406
  int64_t keepVersion;
5407
} SVndSetKeepVersionReq;
5408

5409
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5410
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5411

5412
typedef struct SVUpdateCheckpointInfoReq {
5413
  SMsgHead head;
5414
  int64_t  streamId;
5415
  int32_t  taskId;
5416
  int64_t  checkpointId;
5417
  int64_t  checkpointVer;
5418
  int64_t  checkpointTs;
5419
  int32_t  transId;
5420
  int64_t  hStreamId;  // add encode/decode
5421
  int64_t  hTaskId;
5422
  int8_t   dropRelHTask;
5423
} SVUpdateCheckpointInfoReq;
5424

5425
typedef struct {
5426
  int64_t leftForVer;
5427
  int32_t vgId;
5428
  int64_t oldConsumerId;
5429
  int64_t newConsumerId;
5430
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5431
  int8_t  subType;
5432
  int8_t  withMeta;
5433
  char*   qmsg;  // SubPlanToString
5434
  SSchemaWrapper schema;
5435
  int64_t suid;
5436
} SMqRebVgReq;
5437

5438
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5439
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5440

5441
// tqOffset
5442
enum {
5443
  TMQ_OFFSET__RESET_NONE = -3,
5444
  TMQ_OFFSET__RESET_EARLIEST = -2,
5445
  TMQ_OFFSET__RESET_LATEST = -1,
5446
  TMQ_OFFSET__LOG = 1,
5447
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5448
  TMQ_OFFSET__SNAPSHOT_META = 3,
5449
};
5450

5451
enum {
5452
  WITH_DATA = 0,
5453
  WITH_META = 1,
5454
  ONLY_META = 2,
5455
};
5456

5457
#define TQ_OFFSET_VERSION 1
5458

5459
typedef struct {
5460
  int8_t type;
5461
  union {
5462
    // snapshot
5463
    struct {
5464
      int64_t uid;
5465
      int64_t ts;
5466
      SValue  primaryKey;
5467
    };
5468
    // log
5469
    struct {
5470
      int64_t version;
5471
    };
5472
  };
5473
} STqOffsetVal;
5474

5475
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5476
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,659,381✔
5477
  pOffsetVal->uid = uid;
7,657,547✔
5478
  pOffsetVal->ts = ts;
7,657,154✔
5479
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,658,413✔
5480
    taosMemoryFree(pOffsetVal->primaryKey.pData);
289✔
5481
  }
5482
  pOffsetVal->primaryKey = primaryKey;
7,657,516✔
5483
}
7,658,126✔
5484

5485
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5486
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
41,016✔
5487
  pOffsetVal->uid = uid;
41,016✔
5488
}
41,016✔
5489

5490
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5491
  pOffsetVal->type = TMQ_OFFSET__LOG;
118,436,923✔
5492
  pOffsetVal->version = ver;
118,437,073✔
5493
}
118,434,253✔
5494

5495
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5496
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5497
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5498
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5499
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5500
void    tOffsetDestroy(void* pVal);
5501

5502
typedef struct {
5503
  STqOffsetVal val;
5504
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5505
} STqOffset;
5506

5507
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5508
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5509
void    tDeleteSTqOffset(void* val);
5510

5511
typedef struct SMqVgOffset {
5512
  int64_t   consumerId;
5513
  STqOffset offset;
5514
} SMqVgOffset;
5515

5516
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5517
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5518

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

5553
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5554
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5555
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5556

5557
typedef struct {
5558
  char    name[TSDB_TABLE_FNAME_LEN];
5559
  int8_t  igNotExists;
5560
  char*   dropStreamReq;
5561
  int32_t dropStreamReqLen;
5562
} SMDropSmaReq;
5563

5564
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5565
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5566
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5567

5568
typedef struct {
5569
  char name[TSDB_TABLE_NAME_LEN];
5570
  union {
5571
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5572
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5573
  };
5574
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5575
  union {
5576
    int8_t igExists;   // used by mnode
5577
    int8_t alterType;  // used by vnode
5578
  };
5579
  int8_t     intervalUnit;
5580
  int16_t    nFuncs;       // number of functions specified by user
5581
  col_id_t*  funcColIds;   // column ids specified by user
5582
  func_id_t* funcIds;      // function ids specified by user
5583
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5584
  int64_t    tbUid;
5585
  int64_t    uid;     // rsma uid
5586
  int32_t    sqlLen;  // strlen + 1
5587
  char*      sql;
5588
} SMCreateRsmaReq;
5589

5590
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5591
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5592
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5593

5594
typedef SMCreateRsmaReq SVCreateRsmaReq;
5595

5596
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5597
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5598
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5599

5600
typedef SMCreateRsmaReq SVAlterRsmaReq;
5601

5602
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5603
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5604
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5605

5606
typedef struct {
5607
  char       name[TSDB_TABLE_NAME_LEN];
5608
  int8_t     alterType;
5609
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5610
  int8_t     igNotExists;
5611
  int16_t    nFuncs;      // number of functions specified by user
5612
  col_id_t*  funcColIds;  // column ids specified by user
5613
  func_id_t* funcIds;     // function ids specified by user
5614
  int32_t    sqlLen;      // strlen + 1
5615
  char*      sql;
5616
} SMAlterRsmaReq;
5617

5618
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5619
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5620
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5621

5622
typedef struct {
5623
  int64_t    id;
5624
  char       name[TSDB_TABLE_NAME_LEN];
5625
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5626
  int64_t    ownerId;
5627
  int32_t    code;
5628
  int32_t    version;
5629
  int8_t     tbType;
5630
  int8_t     intervalUnit;
5631
  col_id_t   nFuncs;
5632
  col_id_t   nColNames;
5633
  int64_t    interval[2];
5634
  col_id_t*  funcColIds;
5635
  func_id_t* funcIds;
5636
  SArray*    colNames;
5637
} SRsmaInfoRsp;
5638

5639
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5640
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5641
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5642

5643
typedef struct {
5644
  char   name[TSDB_TABLE_FNAME_LEN];
5645
  int8_t igNotExists;
5646
} SMDropRsmaReq;
5647

5648
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5649
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5650

5651
typedef struct {
5652
  char    name[TSDB_TABLE_NAME_LEN];
5653
  char    tbName[TSDB_TABLE_NAME_LEN];
5654
  int64_t uid;
5655
  int64_t tbUid;
5656
  int8_t  tbType;
5657
} SVDropRsmaReq;
5658

5659
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5660
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5661

5662
typedef struct {
5663
  char   dbFName[TSDB_DB_FNAME_LEN];
5664
  char   stbName[TSDB_TABLE_NAME_LEN];
5665
  char   colName[TSDB_COL_NAME_LEN];
5666
  char   idxName[TSDB_INDEX_FNAME_LEN];
5667
  int8_t idxType;
5668
} SCreateTagIndexReq;
5669

5670
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5671
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5672

5673
typedef SMDropSmaReq SDropTagIndexReq;
5674

5675
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5676
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5677

5678
typedef struct {
5679
  int8_t         version;       // for compatibility(default 0)
5680
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5681
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5682
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5683
  int32_t        dstVgId;
5684
  char           indexName[TSDB_INDEX_NAME_LEN];
5685
  int32_t        exprLen;
5686
  int32_t        tagsFilterLen;
5687
  int64_t        indexUid;
5688
  tb_uid_t       tableUid;  // super/child/common table uid
5689
  tb_uid_t       dstTbUid;  // for dstVgroup
5690
  int64_t        interval;
5691
  int64_t        offset;  // use unit by precision of DB
5692
  int64_t        sliding;
5693
  char*          dstTbName;  // for dstVgroup
5694
  char*          expr;       // sma expression
5695
  char*          tagsFilter;
5696
  SSchemaWrapper schemaRow;  // for dstVgroup
5697
  SSchemaWrapper schemaTag;  // for dstVgroup
5698
} STSma;                     // Time-range-wise SMA
5699

5700
typedef STSma SVCreateTSmaReq;
5701

5702
typedef struct {
5703
  int8_t  type;  // 0 status report, 1 update data
5704
  int64_t indexUid;
5705
  int64_t skey;  // start TS key of interval/sliding window
5706
} STSmaMsg;
5707

5708
typedef struct {
5709
  int64_t indexUid;
5710
  char    indexName[TSDB_INDEX_NAME_LEN];
5711
} SVDropTSmaReq;
5712

5713
typedef struct {
5714
  int tmp;  // TODO: to avoid compile error
5715
} SVCreateTSmaRsp, SVDropTSmaRsp;
5716

5717
#if 0
5718
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5719
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5720
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5721
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5722
#endif
5723

5724
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5725
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5726
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5727
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5728

5729
typedef struct {
5730
  int32_t number;
5731
  STSma*  tSma;
5732
} STSmaWrapper;
5733

5734
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5735
  if (pSma) {
×
UNCOV
5736
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5737
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
5738
    taosMemoryFreeClear(pSma->tagsFilter);
×
5739
  }
UNCOV
5740
}
×
5741

5742
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5743
  if (pSW) {
×
UNCOV
5744
    if (pSW->tSma) {
×
UNCOV
5745
      if (deepCopy) {
×
5746
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
5747
          tDestroyTSma(pSW->tSma + i);
×
5748
        }
5749
      }
UNCOV
5750
      taosMemoryFreeClear(pSW->tSma);
×
5751
    }
5752
  }
UNCOV
5753
}
×
5754

5755
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5756
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5757
  taosMemoryFreeClear(pSW);
×
5758
  return NULL;
×
5759
}
5760

5761
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5762
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5763

5764
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5765
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5766

5767
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5768
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5769
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5770
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5771
  }
UNCOV
5772
  return 0;
×
5773
}
5774

UNCOV
5775
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5776
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5777
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5778
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5779
  }
5780
  return 0;
×
5781
}
5782

5783
typedef struct {
5784
  int idx;
5785
} SMCreateFullTextReq;
5786

5787
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5788
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5789
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5790

5791
typedef struct {
5792
  char   name[TSDB_TABLE_FNAME_LEN];
5793
  int8_t igNotExists;
5794
} SMDropFullTextReq;
5795

5796
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5797
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5798

5799
typedef struct {
5800
  char indexFName[TSDB_INDEX_FNAME_LEN];
5801
} SUserIndexReq;
5802

5803
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5804
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5805

5806
typedef struct {
5807
  char dbFName[TSDB_DB_FNAME_LEN];
5808
  char tblFName[TSDB_TABLE_FNAME_LEN];
5809
  char colName[TSDB_COL_NAME_LEN];
5810
  char owner[TSDB_USER_LEN];
5811
  char indexType[TSDB_INDEX_TYPE_LEN];
5812
  char indexExts[TSDB_INDEX_EXTS_LEN];
5813
} SUserIndexRsp;
5814

5815
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5816
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5817

5818
typedef struct {
5819
  char tbFName[TSDB_TABLE_FNAME_LEN];
5820
} STableIndexReq;
5821

5822
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5823
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5824

5825
typedef struct {
5826
  int8_t  intervalUnit;
5827
  int8_t  slidingUnit;
5828
  int64_t interval;
5829
  int64_t offset;
5830
  int64_t sliding;
5831
  int64_t dstTbUid;
5832
  int32_t dstVgId;
5833
  SEpSet  epSet;
5834
  char*   expr;
5835
} STableIndexInfo;
5836

5837
typedef struct {
5838
  char     tbName[TSDB_TABLE_NAME_LEN];
5839
  char     dbFName[TSDB_DB_FNAME_LEN];
5840
  uint64_t suid;
5841
  int32_t  version;
5842
  int32_t  indexSize;
5843
  SArray*  pIndex;  // STableIndexInfo
5844
} STableIndexRsp;
5845

5846
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5847
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5848
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5849

5850
void tFreeSTableIndexInfo(void* pInfo);
5851

5852
typedef struct {
5853
  int8_t  mqMsgType;
5854
  int32_t code;
5855
  int32_t epoch;
5856
  int64_t consumerId;
5857
  int64_t walsver;
5858
  int64_t walever;
5859
} SMqRspHead;
5860

5861
typedef struct {
5862
  SMsgHead     head;
5863
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5864
  int8_t       withTbName;
5865
  int8_t       useSnapshot;
5866
  int32_t      epoch;
5867
  uint64_t     reqId;
5868
  int64_t      consumerId;
5869
  int64_t      timeout;
5870
  STqOffsetVal reqOffset;
5871
  int8_t       enableReplay;
5872
  int8_t       sourceExcluded;
5873
  int8_t       rawData;
5874
  int32_t      minPollRows;
5875
  int8_t       enableBatchMeta;
5876
  SHashObj*    uidHash;  // to find if uid is duplicated
5877
} SMqPollReq;
5878

5879
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5880
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5881
void    tDestroySMqPollReq(SMqPollReq* pReq);
5882

5883
typedef struct {
5884
  int32_t vgId;
5885
  int64_t offset;
5886
  SEpSet  epSet;
5887
} SMqSubVgEp;
5888

5889
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5890
  int32_t tlen = 0;
2,393,862✔
5891
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,393,862✔
5892
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,393,862✔
5893
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,393,862✔
5894
  return tlen;
2,393,862✔
5895
}
5896

5897
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5898
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,200,773✔
5899
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,200,773✔
5900
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,200,773✔
5901
  return buf;
1,200,773✔
5902
}
5903

5904
typedef struct {
5905
  char           topic[TSDB_TOPIC_FNAME_LEN];
5906
  char           db[TSDB_DB_FNAME_LEN];
5907
  SArray*        vgs;  // SArray<SMqSubVgEp>
5908
} SMqSubTopicEp;
5909

5910
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5911
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5912
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5913

5914
typedef struct {
5915
  SMqRspHead   head;
5916
  STqOffsetVal rspOffset;
5917
  int16_t      resMsgType;
5918
  int32_t      metaRspLen;
5919
  void*        metaRsp;
5920
} SMqMetaRsp;
5921

5922
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5923
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5924
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5925

5926
#define MQ_DATA_RSP_VERSION 100
5927

5928
typedef struct {
5929
  SMqRspHead   head;
5930
  STqOffsetVal rspOffset;
5931
  STqOffsetVal reqOffset;
5932
  int32_t      blockNum;
5933
  int8_t       withTbName;
5934
  int8_t       withSchema;
5935
  SArray*      blockDataLen;
5936
  SArray*      blockData;
5937
  SArray*      blockTbName;
5938
  SArray*      blockSchema;
5939

5940
  union {
5941
    struct {
5942
      int64_t sleepTime;
5943
    };
5944
    struct {
5945
      int32_t createTableNum;
5946
      SArray* createTableLen;
5947
      SArray* createTableReq;
5948
    };
5949
    struct {
5950
      int32_t len;
5951
      void*   rawData;
5952
    };
5953
  };
5954
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5955
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5956
} SMqDataRsp;
5957

5958
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5959
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5960
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5961
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5962
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5963

5964
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5965
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5966
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5967

5968
typedef struct SMqBatchMetaRsp {
5969
  SMqRspHead   head;  // not serialize
5970
  STqOffsetVal rspOffset;
5971
  SArray*      batchMetaLen;
5972
  SArray*      batchMetaReq;
5973
  void*        pMetaBuff;    // not serialize
5974
  uint32_t     metaBuffLen;  // not serialize
5975
} SMqBatchMetaRsp;
5976

5977
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5978
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5979
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5980
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5981

5982
typedef struct {
5983
  int32_t    code;
5984
  SArray*    topics;  // SArray<SMqSubTopicEp>
5985
} SMqAskEpRsp;
5986

5987
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5988
  int32_t tlen = 0;
7,105,430✔
5989
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5990
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,105,430✔
5991
  tlen += taosEncodeFixedI32(buf, sz);
7,105,159✔
5992
  for (int32_t i = 0; i < sz; i++) {
8,843,345✔
5993
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,738,186✔
5994
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,738,186✔
5995
  }
5996
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,105,159✔
5997

5998
  return tlen;
7,105,430✔
5999
}
6000

6001
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6002
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6003
  int32_t sz;
3,344,200✔
6004
  buf = taosDecodeFixedI32(buf, &sz);
3,412,755✔
6005
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,412,755✔
6006
  if (pRsp->topics == NULL) {
3,412,755✔
UNCOV
6007
    return NULL;
×
6008
  }
6009
  for (int32_t i = 0; i < sz; i++) {
4,273,597✔
6010
    SMqSubTopicEp topicEp;
848,963✔
6011
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
860,842✔
6012
    if (buf == NULL) {
860,842✔
UNCOV
6013
      return NULL;
×
6014
    }
6015
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,721,684✔
UNCOV
6016
      return NULL;
×
6017
    }
6018
  }
6019
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,412,755✔
6020

6021
  return buf;
3,412,755✔
6022
}
6023

6024
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6025
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,406,443✔
6026
}
9,406,443✔
6027

6028
typedef struct {
6029
  int32_t      vgId;
6030
  STqOffsetVal offset;
6031
  int64_t      rows;
6032
  int64_t      ever;
6033
} OffsetRows;
6034

6035
typedef struct {
6036
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6037
  SArray* offsetRows;
6038
} TopicOffsetRows;
6039

6040
typedef struct {
6041
  int64_t consumerId;
6042
  int32_t epoch;
6043
  SArray* topics;
6044
  int8_t  pollFlag;
6045
} SMqHbReq;
6046

6047
typedef struct {
6048
  char   topic[TSDB_TOPIC_FNAME_LEN];
6049
  int8_t noPrivilege;
6050
} STopicPrivilege;
6051

6052
typedef struct {
6053
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6054
  int32_t debugFlag;
6055
} SMqHbRsp;
6056

6057
typedef struct {
6058
  SMsgHead head;
6059
  int64_t  consumerId;
6060
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6061
} SMqSeekReq;
6062

6063
#define TD_AUTO_CREATE_TABLE 0x1
6064
typedef struct {
6065
  int64_t       suid;
6066
  int64_t       uid;
6067
  int32_t       sver;
6068
  uint32_t      nData;
6069
  uint8_t*      pData;
6070
  SVCreateTbReq cTbReq;
6071
} SVSubmitBlk;
6072

6073
typedef struct {
6074
  SMsgHead header;
6075
  uint64_t sId;
6076
  uint64_t queryId;
6077
  uint64_t clientId;
6078
  uint64_t taskId;
6079
  uint32_t sqlLen;
6080
  uint32_t phyLen;
6081
  char*    sql;
6082
  char*    msg;
6083
  int8_t   source;
6084
} SVDeleteReq;
6085

6086
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6087
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6088

6089
typedef struct {
6090
  int64_t affectedRows;
6091
} SVDeleteRsp;
6092

6093
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6094
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6095

6096
typedef struct SDeleteRes {
6097
  uint64_t suid;
6098
  SArray*  uidList;
6099
  int64_t  skey;
6100
  int64_t  ekey;
6101
  int64_t  affectedRows;
6102
  char     tableFName[TSDB_TABLE_NAME_LEN];
6103
  char     tsColName[TSDB_COL_NAME_LEN];
6104
  int64_t  ctimeMs;  // fill by vnode
6105
  int8_t   source;
6106
} SDeleteRes;
6107

6108
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6109
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6110

6111
typedef struct {
6112
  // int64_t uid;
6113
  char    tbname[TSDB_TABLE_NAME_LEN];
6114
  int64_t startTs;
6115
  int64_t endTs;
6116
} SSingleDeleteReq;
6117

6118
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6119
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6120

6121
typedef struct {
6122
  int64_t suid;
6123
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6124
  int64_t ctimeMs;     // fill by vnode
6125
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6126
} SBatchDeleteReq;
6127

6128
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6129
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6130
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6131

6132
typedef struct {
6133
  int32_t msgIdx;
6134
  int32_t msgType;
6135
  int32_t msgLen;
6136
  void*   msg;
6137
} SBatchMsg;
6138

6139
typedef struct {
6140
  SMsgHead header;
6141
  SArray*  pMsgs;  // SArray<SBatchMsg>
6142
} SBatchReq;
6143

6144
typedef struct {
6145
  int32_t reqType;
6146
  int32_t msgIdx;
6147
  int32_t msgLen;
6148
  int32_t rspCode;
6149
  void*   msg;
6150
} SBatchRspMsg;
6151

6152
typedef struct {
6153
  SArray* pRsps;  // SArray<SBatchRspMsg>
6154
} SBatchRsp;
6155

6156
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6157
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6158
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
93,510,703✔
6159
  if (NULL == msg) {
93,510,703✔
UNCOV
6160
    return;
×
6161
  }
6162
  SBatchMsg* pMsg = (SBatchMsg*)msg;
93,510,703✔
6163
  taosMemoryFree(pMsg->msg);
93,510,703✔
6164
}
6165

6166
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6167
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6168

6169
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
131,022,033✔
6170
  if (NULL == p) {
131,022,033✔
6171
    return;
×
6172
  }
6173

6174
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
131,022,033✔
6175
  taosMemoryFree(pRsp->msg);
131,022,033✔
6176
}
6177

6178
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6179
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6180
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6181
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6182
void    tDestroySMqHbReq(SMqHbReq* pReq);
6183

6184
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6185
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6186
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6187

6188
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6189
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6190

6191
#define TD_REQ_FROM_APP               0x0
6192
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6193
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6194
#define SUBMIT_REQ_FROM_FILE          0x4
6195
#define TD_REQ_FROM_TAOX              0x8
6196
#define TD_REQ_FROM_SML               0x10
6197
#define SUBMIT_REQUEST_VERSION        (2)
6198
#define SUBMIT_REQ_WITH_BLOB          0x10
6199
#define SUBMIT_REQ_SCHEMA_RES         0x20
6200
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6201

6202
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6203

6204
typedef struct {
6205
  int32_t        flags;
6206
  SVCreateTbReq* pCreateTbReq;
6207
  int64_t        suid;
6208
  int64_t        uid;
6209
  int32_t        sver;
6210
  union {
6211
    SArray* aRowP;
6212
    SArray* aCol;
6213
  };
6214
  int64_t   ctimeMs;
6215
  SBlobSet* pBlobSet;
6216
} SSubmitTbData;
6217

6218
typedef struct {
6219
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6220
  SArray* aSubmitBlobData;
6221
  bool    raw;
6222
} SSubmitReq2;
6223

6224
typedef struct {
6225
  SMsgHead header;
6226
  int64_t  version;
6227
  char     data[];  // SSubmitReq2
6228
} SSubmitReq2Msg;
6229

6230
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6231
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6232
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6233
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6234
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6235

6236
typedef struct {
6237
  int32_t affectedRows;
6238
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6239
} SSubmitRsp2;
6240

6241
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6242
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6243
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6244

6245
#define TSDB_MSG_FLG_ENCODE 0x1
6246
#define TSDB_MSG_FLG_DECODE 0x2
6247
#define TSDB_MSG_FLG_CMPT   0x3
6248

6249
typedef struct {
6250
  union {
6251
    struct {
6252
      void*   msgStr;
6253
      int32_t msgLen;
6254
      int64_t ver;
6255
    };
6256
    void* pDataBlock;
6257
  };
6258
} SPackedData;
6259

6260
typedef struct {
6261
  char     fullname[TSDB_VIEW_FNAME_LEN];
6262
  char     name[TSDB_VIEW_NAME_LEN];
6263
  char     dbFName[TSDB_DB_FNAME_LEN];
6264
  char*    querySql;
6265
  char*    sql;
6266
  int8_t   orReplace;
6267
  int8_t   precision;
6268
  int32_t  numOfCols;
6269
  SSchema* pSchema;
6270
} SCMCreateViewReq;
6271

6272
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6273
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6274
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6275

6276
typedef struct {
6277
  char   fullname[TSDB_VIEW_FNAME_LEN];
6278
  char   name[TSDB_VIEW_NAME_LEN];
6279
  char   dbFName[TSDB_DB_FNAME_LEN];
6280
  char*  sql;
6281
  int8_t igNotExists;
6282
} SCMDropViewReq;
6283

6284
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6285
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6286
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6287

6288
typedef struct {
6289
  char fullname[TSDB_VIEW_FNAME_LEN];
6290
} SViewMetaReq;
6291
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6292
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6293

6294
typedef struct {
6295
  char     name[TSDB_VIEW_NAME_LEN];
6296
  char     dbFName[TSDB_DB_FNAME_LEN];
6297
  char*    createUser;
6298
  int64_t  ownerId;
6299
  uint64_t dbId;
6300
  uint64_t viewId;
6301
  char*    querySql;
6302
  int8_t   precision;
6303
  int8_t   type;
6304
  int32_t  version;
6305
  int32_t  numOfCols;
6306
  SSchema* pSchema;
6307
} SViewMetaRsp;
6308
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6309
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6310
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6311
typedef struct {
6312
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6313
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6314
} STableTSMAInfoReq;
6315

6316
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6317
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6318

6319
typedef struct {
6320
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6321
  union {
6322
    uint8_t flags;
6323
    struct {
6324
      uint8_t withColName : 1;
6325
      uint8_t reserved : 7;
6326
    };
6327
  };
6328

6329
} SRsmaInfoReq;
6330

6331
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6332
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6333

6334
typedef struct {
6335
  int32_t  funcId;
6336
  col_id_t colId;
6337
} STableTSMAFuncInfo;
6338

6339
typedef struct {
6340
  char     name[TSDB_TABLE_NAME_LEN];
6341
  uint64_t tsmaId;
6342
  char     targetTb[TSDB_TABLE_NAME_LEN];
6343
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6344
  char     tb[TSDB_TABLE_NAME_LEN];
6345
  char     dbFName[TSDB_DB_FNAME_LEN];
6346
  uint64_t suid;
6347
  uint64_t destTbUid;
6348
  uint64_t dbId;
6349
  int32_t  version;
6350
  int64_t  interval;
6351
  int8_t   unit;
6352
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6353
  SArray*  pTags;      // SArray<SSchema>
6354
  SArray*  pUsedCols;  // SArray<SSchema>
6355
  char*    ast;
6356

6357
  int64_t streamUid;
6358
  int64_t reqTs;
6359
  int64_t rspTs;
6360
  int64_t delayDuration;  // ms
6361
  bool    fillHistoryFinished;
6362

6363
  void* streamAddr;  // for stream task, the address of the stream task
6364
} STableTSMAInfo;
6365

6366
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6367
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6368
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6369
void    tFreeTableTSMAInfo(void* p);
6370
void    tFreeAndClearTableTSMAInfo(void* p);
6371
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6372

6373
#define STSMAHbRsp            STableTSMAInfoRsp
6374
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6375
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6376
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6377

6378
typedef struct SDropCtbWithTsmaSingleVgReq {
6379
  SVgroupInfo vgInfo;
6380
  SArray*     pTbs;  // SVDropTbReq
6381
} SMDropTbReqsOnSingleVg;
6382

6383
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6384
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6385
void    tFreeSMDropTbReqOnSingleVg(void* p);
6386

6387
typedef struct SDropTbsReq {
6388
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6389
} SMDropTbsReq;
6390

6391
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6392
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6393
void    tFreeSMDropTbsReq(void*);
6394

6395
typedef struct SVFetchTtlExpiredTbsRsp {
6396
  SArray* pExpiredTbs;  // SVDropTbReq
6397
  int32_t vgId;
6398
} SVFetchTtlExpiredTbsRsp;
6399

6400
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6401
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6402

6403
void tFreeFetchTtlExpiredTbsRsp(void* p);
6404

6405
void setDefaultOptionsForField(SFieldWithOptions* field);
6406
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6407

6408
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6409
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6410

6411

6412
typedef struct {
6413
  char    id[TSDB_INSTANCE_ID_LEN];
6414
  char    type[TSDB_INSTANCE_TYPE_LEN];
6415
  char    desc[TSDB_INSTANCE_DESC_LEN];
6416
  int32_t expire;
6417
} SInstanceRegisterReq;
6418

6419
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6420
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6421

6422
typedef struct {
6423
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6424
} SInstanceListReq;
6425

6426
typedef struct {
6427
  int32_t count;
6428
  char**  ids;  // Array of instance IDs
6429
} SInstanceListRsp;
6430

6431
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6432
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6433
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6434
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6435

6436
#ifdef USE_MOUNT
6437
typedef struct {
6438
  char     mountName[TSDB_MOUNT_NAME_LEN];
6439
  int8_t   ignoreExist;
6440
  int16_t  nMounts;
6441
  int32_t* dnodeIds;
6442
  char**   mountPaths;
6443
  int32_t  sqlLen;
6444
  char*    sql;
6445
} SCreateMountReq;
6446

6447
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6448
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6449
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6450

6451
typedef struct {
6452
  char    mountName[TSDB_MOUNT_NAME_LEN];
6453
  int8_t  ignoreNotExists;
6454
  int32_t sqlLen;
6455
  char*   sql;
6456
} SDropMountReq;
6457

6458
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6459
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6460
void    tFreeSDropMountReq(SDropMountReq* pReq);
6461

6462
typedef struct {
6463
  char     mountName[TSDB_MOUNT_NAME_LEN];
6464
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6465
  int64_t  mountUid;
6466
  int32_t  dnodeId;
6467
  uint32_t valLen;
6468
  int8_t   ignoreExist;
6469
  void*    pVal;
6470
} SRetrieveMountPathReq;
6471

6472
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6473
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6474

6475
typedef struct {
6476
  // path
6477
  int32_t diskPrimary;
6478
  // vgInfo
6479
  int32_t  vgId;
6480
  int32_t  cacheLastSize;
6481
  int32_t  szPage;
6482
  int32_t  szCache;
6483
  uint64_t szBuf;
6484
  int8_t   cacheLast;
6485
  int8_t   standby;
6486
  int8_t   hashMethod;
6487
  uint32_t hashBegin;
6488
  uint32_t hashEnd;
6489
  int16_t  hashPrefix;
6490
  int16_t  hashSuffix;
6491
  int16_t  sttTrigger;
6492
  // syncInfo
6493
  int32_t replications;
6494
  // tsdbInfo
6495
  int8_t  precision;
6496
  int8_t  compression;
6497
  int8_t  slLevel;
6498
  int32_t daysPerFile;
6499
  int32_t keep0;
6500
  int32_t keep1;
6501
  int32_t keep2;
6502
  int32_t keepTimeOffset;
6503
  int32_t minRows;
6504
  int32_t maxRows;
6505
  int32_t tsdbPageSize;
6506
  int32_t ssChunkSize;
6507
  int32_t ssKeepLocal;
6508
  int8_t  ssCompact;
6509
  union {
6510
    uint8_t flags;
6511
    struct {
6512
      uint8_t isAudit : 1;
6513
      uint8_t allowDrop : 1;
6514
      uint8_t reserved : 6;
6515
    };
6516
  };
6517
  // walInfo
6518
  int32_t walFsyncPeriod;      // millisecond
6519
  int32_t walRetentionPeriod;  // secs
6520
  int32_t walRollPeriod;       // secs
6521
  int64_t walRetentionSize;
6522
  int64_t walSegSize;
6523
  int32_t walLevel;
6524
  // encryptInfo
6525
  int32_t encryptAlgorithm;
6526
  // SVState
6527
  int64_t committed;
6528
  int64_t commitID;
6529
  int64_t commitTerm;
6530
  // stats
6531
  int64_t numOfSTables;
6532
  int64_t numOfCTables;
6533
  int64_t numOfNTables;
6534
  // dbInfo
6535
  uint64_t dbId;
6536
} SMountVgInfo;
6537

6538
typedef struct {
6539
  SMCreateStbReq req;
6540
  SArray*        pColExts;  // element: column id
6541
  SArray*        pTagExts;  // element: tag id
6542
} SMountStbInfo;
6543

6544
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6545
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6546

6547
typedef struct {
6548
  char     dbName[TSDB_DB_FNAME_LEN];
6549
  uint64_t dbId;
6550
  SArray*  pVgs;   // SMountVgInfo
6551
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6552
} SMountDbInfo;
6553

6554
typedef struct {
6555
  // common fields
6556
  char     mountName[TSDB_MOUNT_NAME_LEN];
6557
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6558
  int8_t   ignoreExist;
6559
  int64_t  mountUid;
6560
  int64_t  clusterId;
6561
  int32_t  dnodeId;
6562
  uint32_t valLen;
6563
  void*    pVal;
6564

6565
  // response fields
6566
  SArray* pDbs;  // SMountDbInfo
6567

6568
  // memory fields, no serialized
6569
  SArray*   pDisks[TFS_MAX_TIERS];
6570
  TdFilePtr pFile;
6571
} SMountInfo;
6572

6573
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6574
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6575
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6576

6577
typedef struct {
6578
  SCreateVnodeReq createReq;
6579
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6580
  char            mountName[TSDB_MOUNT_NAME_LEN];
6581
  int64_t         mountId;
6582
  int32_t         diskPrimary;
6583
  int32_t         mountVgId;
6584
  int64_t         committed;
6585
  int64_t         commitID;
6586
  int64_t         commitTerm;
6587
  int64_t         numOfSTables;
6588
  int64_t         numOfCTables;
6589
  int64_t         numOfNTables;
6590
} SMountVnodeReq;
6591

6592
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6593
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6594
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6595

6596
#endif  // USE_MOUNT
6597

6598
#pragma pack(pop)
6599

6600
typedef struct {
6601
  char        db[TSDB_DB_FNAME_LEN];
6602
  STimeWindow timeRange;
6603
  int32_t     sqlLen;
6604
  char*       sql;
6605
  SArray*     vgroupIds;
6606
} SScanDbReq;
6607

6608
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6609
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6610
void    tFreeSScanDbReq(SScanDbReq* pReq);
6611

6612
typedef struct {
6613
  int32_t scanId;
6614
  int8_t  bAccepted;
6615
} SScanDbRsp;
6616

6617
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6618
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6619

6620
typedef struct {
6621
  int32_t scanId;
6622
  int32_t sqlLen;
6623
  char*   sql;
6624
} SKillScanReq;
6625

6626
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6627
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6628
void    tFreeSKillScanReq(SKillScanReq* pReq);
6629

6630
typedef struct {
6631
  int32_t scanId;
6632
  int32_t vgId;
6633
  int32_t dnodeId;
6634
} SVKillScanReq;
6635

6636
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6637
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6638

6639
typedef struct {
6640
  int32_t scanId;
6641
  int32_t vgId;
6642
  int32_t dnodeId;
6643
  int32_t numberFileset;
6644
  int32_t finished;
6645
  int32_t progress;
6646
  int64_t remainingTime;
6647
} SQueryScanProgressRsp;
6648

6649
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6650
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6651

6652
typedef struct {
6653
  int32_t scanId;
6654
  int32_t vgId;
6655
  int32_t dnodeId;
6656
} SQueryScanProgressReq;
6657

6658
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6659
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6660

6661
typedef struct {
6662
  int64_t     dbUid;
6663
  char        db[TSDB_DB_FNAME_LEN];
6664
  int64_t     scanStartTime;
6665
  STimeWindow tw;
6666
  int32_t     scanId;
6667
} SScanVnodeReq;
6668

6669
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6670
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6671

6672
#ifdef __cplusplus
6673
}
6674
#endif
6675

6676
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6677
 
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