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

taosdata / TDengine / #4934

21 Jan 2026 06:06AM UTC coverage: 66.691% (+0.02%) from 66.671%
#4934

push

travis-ci

web-flow
 enh:stmt support interval opt (#34335)

0 of 26 new or added lines in 3 files covered. (0.0%)

562 existing lines in 98 files now uncovered.

203203 of 304692 relevant lines covered (66.69%)

129902664.38 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

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

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

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

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

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

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

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

67
typedef uint16_t tmsg_t;
68

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

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

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

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

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

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
1,023,242,344✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
979,628,757✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
2,002,871,101✔
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

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

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

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

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

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

673
typedef struct {
674
  int32_t     vgId;
675
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
676
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
677
  const char* dbFName;
678
  const char* tbName;
679
} SBuildTableInput;
680

681
typedef struct {
682
  char    db[TSDB_DB_FNAME_LEN];
683
  int64_t dbId;
684
  int32_t vgVersion;
685
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
686
  int64_t stateTs;
687
} SBuildUseDBInput;
688

689
typedef struct SField {
690
  char    name[TSDB_COL_NAME_LEN];
691
  uint8_t type;
692
  int8_t  flags;
693
  int32_t bytes;
694
} SField;
695

696
typedef struct SFieldWithOptions {
697
  char     name[TSDB_COL_NAME_LEN];
698
  uint8_t  type;
699
  int8_t   flags;
700
  int32_t  bytes;
701
  uint32_t compress;
702
  STypeMod typeMod;
703
} SFieldWithOptions;
704

705
typedef struct SRetention {
706
  int64_t freq;
707
  int64_t keep;
708
  int8_t  freqUnit;
709
  int8_t  keepUnit;
710
} SRetention;
711

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

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

721
typedef struct {
722
  int32_t contLen;
723
  int32_t vgId;
724
} SMsgHead;
725

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

737
// Submit message for this TSDB
738
typedef struct {
739
  SMsgHead header;
740
  int64_t  version;
741
  int32_t  length;
742
  int32_t  numOfBlocks;
743
  char     blocks[];
744
} SSubmitReq;
745

746
typedef struct {
747
  int32_t totalLen;
748
  int32_t len;
749
  STSRow* row;
750
} SSubmitBlkIter;
751

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

767
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
768
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
769
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
770
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
771
// for debug
772
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
773

774
typedef struct {
775
  bool     hasRef;
776
  col_id_t id;
777
  char     refDbName[TSDB_DB_NAME_LEN];
778
  char     refTableName[TSDB_TABLE_NAME_LEN];
779
  char     refColName[TSDB_COL_NAME_LEN];
780
} SColRef;
781

782
typedef struct {
783
  int32_t  nCols;
784
  int32_t  version;
785
  SColRef* pColRef;
786
} SColRefWrapper;
787

788
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
789
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
790
typedef struct {
791
  int32_t vgId;
792
  SColRef colRef;
793
} SColRefEx;
794

795
typedef struct {
796
  int16_t colId;
797
  char    refDbName[TSDB_DB_NAME_LEN];
798
  char    refTableName[TSDB_TABLE_NAME_LEN];
799
  char    refColName[TSDB_COL_NAME_LEN];
800
} SRefColInfo;
801

802
typedef struct SVCTableRefCols {
803
  uint64_t     uid;
804
  int32_t      numOfSrcTbls;
805
  int32_t      numOfColRefs;
806
  SRefColInfo* refCols;
807
} SVCTableRefCols;
808

809
typedef struct SVCTableMergeInfo {
810
  uint64_t uid;
811
  int32_t  numOfSrcTbls;
812
} SVCTableMergeInfo;
813

814
typedef struct {
815
  int32_t    nCols;
816
  SColRefEx* pColRefEx;
817
} SColRefExWrapper;
818

819
struct SSchema {
820
  int8_t   type;
821
  int8_t   flags;
822
  col_id_t colId;
823
  int32_t  bytes;
824
  char     name[TSDB_COL_NAME_LEN];
825
};
826
struct SSchemaExt {
827
  col_id_t colId;
828
  uint32_t compress;
829
  STypeMod typeMod;
830
};
831

832
struct SSchemaRsma {
833
  int64_t    interval[2];
834
  int32_t    nFuncs;
835
  int8_t     tbType;
836
  tb_uid_t   tbUid;
837
  func_id_t* funcIds;
838
  char       tbName[TSDB_TABLE_NAME_LEN];
839
};
840

841
struct SSchema2 {
842
  int8_t   type;
843
  int8_t   flags;
844
  col_id_t colId;
845
  int32_t  bytes;
846
  char     name[TSDB_COL_NAME_LEN];
847
  uint32_t compress;
848
};
849

850
typedef struct {
851
  char        tbName[TSDB_TABLE_NAME_LEN];
852
  char        stbName[TSDB_TABLE_NAME_LEN];
853
  char        dbFName[TSDB_DB_FNAME_LEN];
854
  int64_t     dbId;
855
  int32_t     numOfTags;
856
  int32_t     numOfColumns;
857
  int8_t      precision;
858
  int8_t      tableType;
859
  int32_t     sversion;
860
  int32_t     tversion;
861
  int32_t     rversion;
862
  uint64_t    suid;
863
  uint64_t    tuid;
864
  int32_t     vgId;
865
  int8_t      sysInfo;
866
  int64_t     ownerId;
867
  SSchema*    pSchemas;
868
  SSchemaExt* pSchemaExt;
869
  int8_t      virtualStb;
870
  int32_t     numOfColRefs;
871
  SColRef*    pColRefs;
872
} STableMetaRsp;
873

874
typedef struct {
875
  int32_t        code;
876
  int64_t        uid;
877
  char*          tblFName;
878
  int32_t        numOfRows;
879
  int32_t        affectedRows;
880
  int64_t        sver;
881
  STableMetaRsp* pMeta;
882
} SSubmitBlkRsp;
883

884
typedef struct {
885
  int32_t numOfRows;
886
  int32_t affectedRows;
887
  int32_t nBlocks;
888
  union {
889
    SArray*        pArray;
890
    SSubmitBlkRsp* pBlocks;
891
  };
892
} SSubmitRsp;
893

894
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
895
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
896
// void    tFreeSSubmitBlkRsp(void* param);
897
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
898

899
#define COL_SMA_ON       ((int8_t)0x1)
900
#define COL_IDX_ON       ((int8_t)0x2)
901
#define COL_IS_KEY       ((int8_t)0x4)
902
#define COL_SET_NULL     ((int8_t)0x10)
903
#define COL_SET_VAL      ((int8_t)0x20)
904
#define COL_IS_SYSINFO   ((int8_t)0x40)
905
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
906
#define COL_REF_BY_STM   ((int8_t)0x08)
907

908
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
909
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
910

911
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
912
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
913
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
914

915
#define SSCHMEA_SET_IDX_ON(s) \
916
  do {                        \
917
    (s)->flags |= COL_IDX_ON; \
918
  } while (0)
919

920
#define SSCHMEA_SET_IDX_OFF(s)   \
921
  do {                           \
922
    (s)->flags &= (~COL_IDX_ON); \
923
  } while (0)
924

925
#define SSCHEMA_SET_TYPE_MOD(s)     \
926
  do {                              \
927
    (s)->flags |= COL_HAS_TYPE_MOD; \
928
  } while (0)
929

930
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
931

932
#define SSCHMEA_TYPE(s)  ((s)->type)
933
#define SSCHMEA_FLAGS(s) ((s)->flags)
934
#define SSCHMEA_COLID(s) ((s)->colId)
935
#define SSCHMEA_BYTES(s) ((s)->bytes)
936
#define SSCHMEA_NAME(s)  ((s)->name)
937

938
typedef struct {
939
  bool    tsEnableMonitor;
940
  int32_t tsMonitorInterval;
941
  int32_t tsSlowLogThreshold;
942
  int32_t tsSlowLogMaxLen;
943
  int32_t tsSlowLogScope;
944
  int32_t tsSlowLogThresholdTest;  // Obsolete
945
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
946
} SMonitorParas;
947

948
typedef struct {
949
  STypeMod typeMod;
950
} SExtSchema;
951

952
bool hasExtSchema(const SExtSchema* pExtSchema);
953

954
typedef struct {
955
  int32_t      nCols;
956
  int32_t      version;
957
  SSchema*     pSchema;
958
  SSchemaRsma* pRsma;
959
} SSchemaWrapper;
960

961
typedef struct {
962
  col_id_t id;
963
  uint32_t alg;
964
} SColCmpr;
965

966
typedef struct {
967
  int32_t   nCols;
968
  int32_t   version;
969
  SColCmpr* pColCmpr;
970
} SColCmprWrapper;
971

972
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
973
  if (pRef->pColRef) {
337,504✔
974
    return TSDB_CODE_INVALID_PARA;
×
975
  }
976
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
337,504✔
977
  if (pRef->pColRef == NULL) {
337,504✔
978
    return terrno;
×
979
  }
980
  pRef->nCols = nCols;
337,504✔
981
  for (int32_t i = 0; i < nCols; i++) {
140,092,410✔
982
    pRef->pColRef[i].hasRef = false;
139,754,906✔
983
    pRef->pColRef[i].id = (col_id_t)(i + 1);
139,754,906✔
984
  }
985
  return 0;
337,504✔
986
}
987

988
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
989
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
990
    terrno = TSDB_CODE_INVALID_PARA;
991
    return NULL;
992
  }
993

994
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
995
  if (pDstWrapper == NULL) {
996
    return NULL;
997
  }
998
  pDstWrapper->nCols = pSrcWrapper->nCols;
999
  pDstWrapper->version = pSrcWrapper->version;
1000

1001
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1002
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1003
  if (pDstWrapper->pColCmpr == NULL) {
1004
    taosMemoryFree(pDstWrapper);
1005
    return NULL;
1006
  }
1007
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1008

1009
  return pDstWrapper;
1010
}
1011

1012
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1013
  if (!(!pCmpr->pColCmpr)) {
5,266,901✔
1014
    return TSDB_CODE_INVALID_PARA;
×
1015
  }
1016
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
5,266,901✔
1017
  if (pCmpr->pColCmpr == NULL) {
5,266,901✔
1018
    return terrno;
×
1019
  }
1020
  pCmpr->nCols = nCols;
5,266,901✔
1021
  return 0;
5,266,901✔
1022
}
1023

1024
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
1025
  pCmpr->nCols = pSchema->nCols;
1026
  if (!(!pCmpr->pColCmpr)) {
1027
    return TSDB_CODE_INVALID_PARA;
1028
  }
1029
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
1030
  if (pCmpr->pColCmpr == NULL) {
1031
    return terrno;
1032
  }
1033
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1034
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
1035
    SSchema*  pColSchema = &pSchema->pSchema[i];
1036
    pColCmpr->id = pColSchema->colId;
1037
    pColCmpr->alg = 0;
1038
  }
1039
  return 0;
1040
}
1041

1042
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1043
  if (pWrapper == NULL) return;
1044

1045
  taosMemoryFreeClear(pWrapper->pColCmpr);
1046
  taosMemoryFreeClear(pWrapper);
1047
}
1048
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1049
  if (pSchemaWrapper->pSchema == NULL) return NULL;
829,322,142✔
1050

1051
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
828,952,179✔
1052
  if (pSW == NULL) {
828,968,928✔
1053
    return NULL;
×
1054
  }
1055
  pSW->nCols = pSchemaWrapper->nCols;
828,968,928✔
1056
  pSW->version = pSchemaWrapper->version;
829,021,673✔
1057
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
828,887,208✔
1058
  if (pSW->pSchema == NULL) {
828,216,058✔
1059
    taosMemoryFree(pSW);
×
1060
    return NULL;
×
1061
  }
1062

1063
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
828,325,245✔
1064
  return pSW;
829,284,735✔
1065
}
1066

1067
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
297,205,666✔
1068
  if (pSchemaWrapper) {
2,147,483,647✔
1069
    taosMemoryFree(pSchemaWrapper->pSchema);
1,288,465,999✔
1070
    if (pSchemaWrapper->pRsma) {
1,288,451,196✔
1071
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
26,676✔
1072
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
26,676✔
1073
    }
1074
    taosMemoryFree(pSchemaWrapper);
1,288,062,770✔
1075
  }
1076
}
2,147,483,647✔
1077

1078
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1079
  if (pSchemaWrapper) {
1080
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1081
    if (pSchemaWrapper->pRsma) {
1082
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1083
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1084
    }
1085
  }
1086
}
1087

1088
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
7,049,938✔
1089
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,049,938✔
1090
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,049,938✔
1091
  }
1092
}
7,048,802✔
1093

1094
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1095
  int32_t tlen = 0;
2,658,152✔
1096
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,659,400✔
1097
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,658,152✔
1098
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,658,152✔
1099
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,658,152✔
1100
  tlen += taosEncodeString(buf, pSchema->name);
2,658,152✔
1101
  return tlen;
2,658,152✔
1102
}
1103

1104
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1105
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,197,975✔
1106
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,197,663✔
1107
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,197,663✔
1108
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,197,663✔
1109
  buf = taosDecodeStringTo(buf, pSchema->name);
1,197,663✔
1110
  return (void*)buf;
1,197,663✔
1111
}
1112

1113
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1114
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1115
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1116
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1117
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1118
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1119
  return 0;
2,147,483,647✔
1120
}
1121

1122
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1123
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1124
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1125
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1126
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1127
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1128
  return 0;
2,147,483,647✔
1129
}
1130

1131
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1132
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1133
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1134
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1135
  return 0;
2,147,483,647✔
1136
}
1137

1138
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1139
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1140
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1141
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1142
  return 0;
2,147,483,647✔
1143
}
1144

1145
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1146
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
704,440,456✔
1147
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
704,440,456✔
1148
  if (pColRef->hasRef) {
352,220,228✔
1149
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
422,492,632✔
1150
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
422,492,632✔
1151
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
422,492,632✔
1152
  }
1153
  return 0;
352,220,228✔
1154
}
1155

1156
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1157
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
353,357,906✔
1158
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
353,357,906✔
1159
  if (pColRef->hasRef) {
176,678,953✔
1160
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
105,993,757✔
1161
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
105,993,757✔
1162
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
105,993,757✔
1163
  }
1164

1165
  return 0;
176,678,953✔
1166
}
1167

1168
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1169
  int32_t tlen = 0;
432,702✔
1170
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
432,702✔
1171
  tlen += taosEncodeVariantI32(buf, pSW->version);
432,702✔
1172
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,090,854✔
1173
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,316,304✔
1174
  }
1175
  return tlen;
432,702✔
1176
}
1177

1178
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1179
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
188,579✔
1180
  buf = taosDecodeVariantI32(buf, &pSW->version);
188,579✔
1181
  if (pSW->nCols > 0) {
188,579✔
1182
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
188,579✔
1183
    if (pSW->pSchema == NULL) {
188,579✔
1184
      return NULL;
×
1185
    }
1186

1187
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,386,242✔
1188
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,395,326✔
1189
    }
1190
  } else {
1191
    pSW->pSchema = NULL;
×
1192
  }
1193
  return (void*)buf;
188,579✔
1194
}
1195

1196
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1197
  if (pSW == NULL) {
448,870,826✔
1198
    return TSDB_CODE_INVALID_PARA;
×
1199
  }
1200
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
897,768,781✔
1201
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
897,664,489✔
1202
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1203
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1204
  }
1205
  return 0;
449,094,007✔
1206
}
1207

1208
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1209
  if (pSW == NULL) {
175,004,497✔
1210
    return TSDB_CODE_INVALID_PARA;
×
1211
  }
1212
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
349,991,456✔
1213
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
349,975,431✔
1214

1215
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
174,988,472✔
1216
  if (pSW->pSchema == NULL) {
174,959,228✔
1217
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1218
  }
1219
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,651,735,117✔
1220
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1221
  }
1222

1223
  return 0;
175,037,151✔
1224
}
1225

1226
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1227
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1228
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1229

1230
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1231
  if (pSW->pSchema == NULL) {
2,130,011,588✔
1232
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1233
  }
1234
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1235
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1236
  }
1237

1238
  return 0;
2,131,936,018✔
1239
}
1240

1241
typedef struct {
1242
  char     name[TSDB_TABLE_FNAME_LEN];
1243
  int8_t   igExists;
1244
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1245
  int8_t   reserved[6];
1246
  tb_uid_t suid;
1247
  int64_t  delay1;
1248
  int64_t  delay2;
1249
  int64_t  watermark1;
1250
  int64_t  watermark2;
1251
  int32_t  ttl;
1252
  int32_t  colVer;
1253
  int32_t  tagVer;
1254
  int32_t  numOfColumns;
1255
  int32_t  numOfTags;
1256
  int32_t  numOfFuncs;
1257
  int32_t  commentLen;
1258
  int32_t  ast1Len;
1259
  int32_t  ast2Len;
1260
  SArray*  pColumns;  // array of SFieldWithOptions
1261
  SArray*  pTags;     // array of SField
1262
  SArray*  pFuncs;
1263
  char*    pComment;
1264
  char*    pAst1;
1265
  char*    pAst2;
1266
  int64_t  deleteMark1;
1267
  int64_t  deleteMark2;
1268
  int32_t  sqlLen;
1269
  char*    sql;
1270
  int64_t  keep;
1271
  int8_t   virtualStb;
1272
} SMCreateStbReq;
1273

1274
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1275
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1276
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1277

1278
typedef struct {
1279
  STableMetaRsp* pMeta;
1280
} SMCreateStbRsp;
1281

1282
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1283
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1284
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1285

1286
typedef struct {
1287
  char     name[TSDB_TABLE_FNAME_LEN];
1288
  int8_t   igNotExists;
1289
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1290
  int8_t   reserved[6];
1291
  tb_uid_t suid;
1292
  int32_t  sqlLen;
1293
  char*    sql;
1294
} SMDropStbReq;
1295

1296
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1297
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1298
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1299

1300
typedef struct {
1301
  char    name[TSDB_TABLE_FNAME_LEN];
1302
  int8_t  alterType;
1303
  int32_t numOfFields;
1304
  SArray* pFields;
1305
  int32_t ttl;
1306
  int32_t commentLen;
1307
  char*   comment;
1308
  int32_t sqlLen;
1309
  char*   sql;
1310
  int64_t keep;
1311
  SArray* pTypeMods;
1312
} SMAlterStbReq;
1313

1314
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1315
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1316
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1317

1318
typedef struct SEpSet {
1319
  int8_t inUse;
1320
  int8_t numOfEps;
1321
  SEp    eps[TSDB_MAX_REPLICA];
1322
} SEpSet;
1323

1324
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1325
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1326
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1327
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1328

1329
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1330
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1331

1332
typedef struct {
1333
  int8_t  connType;
1334
  int32_t pid;
1335
  int32_t totpCode;
1336
  char    app[TSDB_APP_NAME_LEN];
1337
  char    db[TSDB_DB_NAME_LEN];
1338
  char    user[TSDB_USER_LEN];
1339
  char    passwd[TSDB_PASSWORD_LEN];
1340
  char    token[TSDB_TOKEN_LEN];
1341
  int64_t startTime;
1342
  int64_t connectTime;
1343
  char    sVer[TSDB_VERSION_LEN];
1344
  char    signature[20]; // SHA1 produces a 20-byte signature
1345
} SConnectReq;
1346

1347
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1348
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1349
void    tSignConnectReq(SConnectReq* pReq);
1350
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1351

1352
typedef struct {
1353
  int64_t       clusterId;
1354
  int32_t       acctId;
1355
  uint32_t      connId;
1356
  int32_t       dnodeNum;
1357
  int8_t        superUser;
1358
  int8_t        sysInfo;
1359
  int8_t        connType;
1360
  int8_t        enableAuditDelete;
1361
  SEpSet        epSet;
1362
  int32_t       svrTimestamp;
1363
  int32_t       passVer;
1364
  int32_t       authVer;
1365
  char          sVer[TSDB_VERSION_LEN];
1366
  char          sDetailVer[128];
1367
  int64_t       whiteListVer;
1368
  int64_t       timeWhiteListVer;
1369
  int64_t       userId;
1370
  SMonitorParas monitorParas;
1371
  char          user[TSDB_USER_LEN];
1372
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1373
  int8_t        enableAuditSelect;
1374
  int8_t        enableAuditInsert;
1375
  int8_t        auditLevel;
1376
} SConnectRsp;
1377

1378
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1379
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1380

1381
typedef struct {
1382
  char    user[TSDB_USER_LEN];
1383
  char    pass[TSDB_PASSWORD_LEN];
1384
  int32_t maxUsers;
1385
  int32_t maxDbs;
1386
  int32_t maxTimeSeries;
1387
  int32_t maxStreams;
1388
  int32_t accessState;  // Configured only by command
1389
  int64_t maxStorage;
1390
} SCreateAcctReq, SAlterAcctReq;
1391

1392
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1393
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1394

1395
typedef struct {
1396
  char    user[TSDB_USER_LEN];
1397
  int8_t  ignoreNotExists;
1398
  int32_t sqlLen;
1399
  char*   sql;
1400
} SDropUserReq, SDropAcctReq;
1401

1402
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1403
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1404
void    tFreeSDropUserReq(SDropUserReq* pReq);
1405

1406
typedef struct {
1407
  char name[TSDB_ROLE_LEN];
1408
  union {
1409
    uint8_t flag;
1410
    struct {
1411
      uint8_t ignoreExists : 1;
1412
      uint8_t reserve : 7;
1413
    };
1414
  };
1415
  int32_t sqlLen;
1416
  char*   sql;
1417
} SCreateRoleReq;
1418

1419
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1420
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1421
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1422

1423
typedef struct {
1424
  char name[TSDB_ROLE_LEN];
1425
  union {
1426
    uint8_t flag;
1427
    struct {
1428
      uint8_t ignoreNotExists : 1;
1429
      uint8_t reserve : 7;
1430
    };
1431
  };
1432
  int32_t sqlLen;
1433
  char*   sql;
1434
} SDropRoleReq;
1435

1436
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1437
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1438
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1439

1440
typedef struct {
1441
  SPrivSet privSet;
1442
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1443
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1444
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1445
  // delete can only specify conditions by cond and cannot specify columns
1446
  char*    cond;     // for table privileges
1447
  int32_t  condLen;  // for table privileges
1448
} SPrivSetReqArgs;
1449

1450
typedef struct {
1451
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1452
  uint8_t objType;    // db, table, view, rsma, etc.
1453
  union {
1454
    uint32_t flag;
1455
    struct {
1456
      uint32_t lock : 1;     // lock or unlock role
1457
      uint32_t add : 1;      // add or remove
1458
      uint32_t sysPriv : 1;  // system or object privileges
1459
      uint32_t objLevel : 2;
1460
      uint32_t reserve : 27;
1461
    };
1462
  };
1463
  union {
1464
    SPrivSetReqArgs privileges;
1465
    char            roleName[TSDB_ROLE_LEN];
1466
  };
1467
  char    principal[TSDB_ROLE_LEN];      // role or user name
1468
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db or topic
1469
  char    tblName[TSDB_TABLE_NAME_LEN];
1470
  int32_t sqlLen;
1471
  char*   sql;
1472
} SAlterRoleReq;
1473

1474
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1475
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1476
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1477

1478
typedef struct {
1479
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1480
  int32_t sqlLen;
1481
  char*   sql;
1482
} SDropEncryptAlgrReq;
1483

1484
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1485
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1486
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1487

1488
typedef struct SIpV4Range {
1489
  uint32_t ip;
1490
  uint32_t mask;
1491
} SIpV4Range;
1492

1493
typedef struct SIpv6Range {
1494
  uint64_t addr[2];
1495
  uint32_t mask;
1496
} SIpV6Range;
1497

1498
typedef struct {
1499
  int8_t type;   // 0: IPv4, 1: IPv6
1500
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1501
  union {
1502
    SIpV4Range ipV4;
1503
    SIpV6Range ipV6;
1504
  };
1505
} SIpRange;
1506

1507
typedef struct {
1508
  int32_t    num;
1509
  SIpV4Range pIpRange[];
1510
} SIpWhiteList;
1511

1512
typedef struct {
1513
  int32_t  num;
1514
  SIpRange pIpRanges[];
1515
} SIpWhiteListDual;
1516

1517
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1518
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1519
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1520
int32_t           createDefaultIp6Range(SIpRange* pRange);
1521
int32_t           createDefaultIp4Range(SIpRange* pRange);
1522

1523
typedef struct {
1524
  int32_t sessPerUser;
1525
  int32_t sessConnTime;
1526
  int32_t sessConnIdleTime;
1527
  int32_t sessMaxConcurrency;
1528
  int32_t sessMaxCallVnodeNum;
1529
} SUserSessCfg;
1530

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

1535
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1536
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1537
typedef struct {
1538
  int16_t year;
1539
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1540
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1541
  int8_t hour;
1542
  int8_t minute;
1543
  int8_t neg;   // this is a negative entry
1544
  int32_t duration; // duration in minute
1545
} SDateTimeRange;
1546

1547
bool isValidDateTimeRange(SDateTimeRange* pRange);
1548
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1549
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1550

1551
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1552
typedef struct {
1553
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1554
  bool neg;         // this is a negative entry
1555
  int32_t duration; // duration in seconds
1556
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1557
} SDateTimeWhiteListItem;
1558

1559
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1560
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1561

1562
typedef struct {
1563
  int32_t num;
1564
  SDateTimeWhiteListItem ranges[];
1565
} SDateTimeWhiteList;
1566

1567
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1568
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1569

1570

1571
typedef struct {
1572
  int8_t createType;
1573
  int8_t superUser;  // denote if it is a super user or not
1574
  int8_t ignoreExists;
1575

1576
  char   user[TSDB_USER_LEN];
1577
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1578
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1579

1580
  int8_t sysInfo;
1581
  int8_t createDb;
1582
  int8_t isImport;
1583
  int8_t changepass;
1584
  int8_t enable;
1585

1586
  int8_t negIpRanges;
1587
  int8_t negTimeRanges;
1588

1589
  int32_t sessionPerUser;
1590
  int32_t connectTime;
1591
  int32_t connectIdleTime;
1592
  int32_t callPerSession;
1593
  int32_t vnodePerCall;
1594
  int32_t failedLoginAttempts;
1595
  int32_t passwordLifeTime;
1596
  int32_t passwordReuseTime;
1597
  int32_t passwordReuseMax;
1598
  int32_t passwordLockTime;
1599
  int32_t passwordGraceTime;
1600
  int32_t inactiveAccountTime;
1601
  int32_t allowTokenNum;
1602

1603
  int32_t         numIpRanges;
1604
  SIpRange*       pIpDualRanges;
1605
  int32_t         numTimeRanges;
1606
  SDateTimeRange* pTimeRanges;
1607

1608
  int32_t sqlLen;
1609
  char*   sql;
1610
} SCreateUserReq;
1611

1612
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1613
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1614
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1615

1616
typedef struct {
1617
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1618
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1619
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1620
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1621
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1622
  int32_t sqlLen;
1623
  char*   sql;
1624
} SCreateEncryptAlgrReq;
1625

1626
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1627
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1628
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1629

1630
typedef struct {
1631
  int32_t dnodeId;
1632
  int64_t analVer;
1633
} SRetrieveAnalyticsAlgoReq;
1634

1635
typedef struct {
1636
  int64_t   ver;
1637
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1638
} SRetrieveAnalyticAlgoRsp;
1639

1640
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1641
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1642
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1643
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1644
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1645

1646
typedef struct {
1647
  int8_t alterType;
1648

1649
  int8_t isView;
1650

1651
  int8_t hasPassword;
1652
  int8_t hasTotpseed;
1653
  int8_t hasEnable;
1654
  int8_t hasSysinfo;
1655
  int8_t hasCreatedb;
1656
  int8_t hasChangepass;
1657
  int8_t hasSessionPerUser;
1658
  int8_t hasConnectTime;
1659
  int8_t hasConnectIdleTime;
1660
  int8_t hasCallPerSession;
1661
  int8_t hasVnodePerCall;
1662
  int8_t hasFailedLoginAttempts;
1663
  int8_t hasPasswordLifeTime;
1664
  int8_t hasPasswordReuseTime;
1665
  int8_t hasPasswordReuseMax;
1666
  int8_t hasPasswordLockTime;
1667
  int8_t hasPasswordGraceTime;
1668
  int8_t hasInactiveAccountTime;
1669
  int8_t hasAllowTokenNum;
1670

1671
  int8_t enable;
1672
  int8_t sysinfo;
1673
  int8_t createdb;
1674
  int8_t changepass;
1675

1676
  char   user[TSDB_USER_LEN];
1677
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1678
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1679
  int32_t sessionPerUser;
1680
  int32_t connectTime;
1681
  int32_t connectIdleTime;
1682
  int32_t callPerSession;
1683
  int32_t vnodePerCall;
1684
  int32_t failedLoginAttempts;
1685
  int32_t passwordLifeTime;
1686
  int32_t passwordReuseTime;
1687
  int32_t passwordReuseMax;
1688
  int32_t passwordLockTime;
1689
  int32_t passwordGraceTime;
1690
  int32_t inactiveAccountTime;
1691
  int32_t allowTokenNum;
1692

1693
  int32_t         numIpRanges;
1694
  int32_t         numTimeRanges;
1695
  int32_t         numDropIpRanges;
1696
  int32_t         numDropTimeRanges;
1697
  SIpRange*       pIpRanges;
1698
  SDateTimeRange* pTimeRanges;
1699
  SIpRange*       pDropIpRanges;
1700
  SDateTimeRange* pDropTimeRanges;
1701
  SPrivSet        privileges;
1702

1703
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1704
  char        tabName[TSDB_TABLE_NAME_LEN];
1705
  char*       tagCond;
1706
  int32_t     tagCondLen;
1707
  int32_t     sqlLen;
1708
  char*       sql;
1709
} SAlterUserReq;
1710

1711
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1712
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1713
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1714

1715
typedef struct {
1716
  char    name[TSDB_TOKEN_NAME_LEN];
1717
  char    user[TSDB_USER_LEN];
1718
  int8_t  enable;
1719
  int8_t  ignoreExists;
1720
  int32_t ttl;
1721
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1722
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1723

1724
  int32_t sqlLen;
1725
  char*   sql;
1726
} SCreateTokenReq;
1727

1728
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1729
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1730
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1731

1732
typedef struct {
1733
  char name[TSDB_TOKEN_NAME_LEN];
1734
  char user[TSDB_USER_LEN];
1735
  char token[TSDB_TOKEN_LEN];
1736
} SCreateTokenRsp;
1737

1738
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1739
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1740
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1741

1742
typedef struct {
1743
  char    name[TSDB_TOKEN_NAME_LEN];
1744

1745
  int8_t hasEnable;
1746
  int8_t hasTtl;
1747
  int8_t hasProvider;
1748
  int8_t hasExtraInfo;
1749

1750
  int8_t  enable;
1751
  int32_t ttl;
1752
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1753
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1754

1755
  int32_t     sqlLen;
1756
  char*       sql;
1757
} SAlterTokenReq;
1758

1759
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1760
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1761
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1762

1763
typedef struct {
1764
  char    name[TSDB_TOKEN_NAME_LEN];
1765
  int8_t  ignoreNotExists;
1766
  int32_t sqlLen;
1767
  char*   sql;
1768
} SDropTokenReq;
1769

1770
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1771
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1772
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1773

1774
typedef struct {
1775
  char    user[TSDB_USER_LEN];
1776
  int32_t sqlLen;
1777
  char*   sql;
1778
} SCreateTotpSecretReq;
1779

1780
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1781
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1782
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1783

1784
typedef struct {
1785
  char user[TSDB_USER_LEN];
1786
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1787
} SCreateTotpSecretRsp;
1788

1789
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1790
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1791

1792
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1793
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1794
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1795
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1796

1797
typedef struct {
1798
  char user[TSDB_USER_LEN];
1799
} SGetUserAuthReq;
1800

1801
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1802
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1803

1804
typedef struct {
1805
  int8_t  enabled;
1806
  int32_t expireTime;
1807
} STokenStatus;
1808

1809
typedef struct {
1810
  char      user[TSDB_USER_LEN];
1811
  int64_t   userId;
1812
  int32_t   version;
1813
  int32_t   passVer;
1814
  int8_t    superAuth;
1815
  int8_t    sysInfo;
1816
  int8_t    enable;
1817
  int8_t    dropped;
1818
  SPrivSet  sysPrivs;
1819
  SHashObj* objPrivs;
1820
  // SHashObj* createdDbs;
1821
  SHashObj* selectTbs;
1822
  SHashObj* insertTbs;
1823
  SHashObj* deleteTbs;
1824
  // SHashObj* readViews;
1825
  // SHashObj* writeViews;
1826
  // SHashObj* alterViews;
1827
  // SHashObj* useDbs;
1828
  int64_t   whiteListVer;
1829

1830
  SUserSessCfg sessCfg;
1831
  int64_t      timeWhiteListVer;
1832
  SHashObj*    tokens;
1833
} SGetUserAuthRsp;
1834

1835
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1836
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1837
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1838

1839
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1840
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1841
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1842
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1843

1844
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1845
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1846
typedef struct {
1847
  int64_t ver;
1848
  char    user[TSDB_USER_LEN];
1849
  int32_t numOfRange;
1850
  union {
1851
    SIpV4Range* pIpRanges;
1852
    SIpRange*   pIpDualRanges;
1853
  };
1854
} SUpdateUserIpWhite;
1855

1856
typedef struct {
1857
  int64_t             ver;
1858
  int                 numOfUser;
1859
  SUpdateUserIpWhite* pUserIpWhite;
1860
} SUpdateIpWhite;
1861

1862
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1863
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1864
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1865
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1866

1867
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1868
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1869
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1870

1871

1872
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1873
// corresponding response struct is different.
1874
typedef struct {
1875
  int64_t ver;
1876
} SRetrieveWhiteListReq;
1877

1878
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1879
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1880

1881

1882
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1883
// corresponding response struct is different.
1884
typedef struct {
1885
  char user[TSDB_USER_LEN];
1886
} SGetUserWhiteListReq;
1887

1888
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1889
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1890

1891
typedef struct {
1892
  char    user[TSDB_USER_LEN];
1893
  int32_t numWhiteLists;
1894
  union {
1895
    SIpV4Range* pWhiteLists;
1896
    SIpRange*   pWhiteListsDual;
1897
  };
1898
} SGetUserIpWhiteListRsp;
1899

1900
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1901
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1902
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1903
void    tIpRangeSetDefaultMask(SIpRange* range);
1904

1905
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1906
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1907
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1908

1909
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1910
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1911
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1912

1913
typedef struct {
1914
  int64_t ver;
1915
  char    user[TSDB_USER_LEN];
1916
  int32_t numWhiteLists;
1917
  SDateTimeWhiteListItem* pWhiteLists;
1918
} SUserDateTimeWhiteList;
1919

1920

1921
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1922
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1923
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1924
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1925

1926
typedef struct {
1927
  int64_t             ver;
1928
  int                 numOfUser;
1929
  SUserDateTimeWhiteList *pUsers;
1930
} SRetrieveDateTimeWhiteListRsp;
1931

1932
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1933
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1934
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1935
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1936

1937
/*
1938
 * for client side struct, only column id, type, bytes are necessary
1939
 * But for data in vnode side, we need all the following information.
1940
 */
1941
typedef struct {
1942
  union {
1943
    col_id_t colId;
1944
    int16_t  slotId;
1945
  };
1946

1947
  uint8_t precision;
1948
  uint8_t scale;
1949
  int32_t bytes;
1950
  int8_t  type;
1951
  uint8_t pk;
1952
  bool    noData;
1953
} SColumnInfo;
1954

1955
typedef struct STimeWindow {
1956
  TSKEY skey;
1957
  TSKEY ekey;
1958
} STimeWindow;
1959

1960
typedef struct SQueryHint {
1961
  bool batchScan;
1962
} SQueryHint;
1963

1964
typedef struct {
1965
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1966
  int32_t tsLen;          // total length of ts comp block
1967
  int32_t tsNumOfBlocks;  // ts comp block numbers
1968
  int32_t tsOrder;        // ts comp block order
1969
} STsBufInfo;
1970

1971
typedef struct {
1972
  void*       timezone;
1973
  char        intervalUnit;
1974
  char        slidingUnit;
1975
  char        offsetUnit;
1976
  int8_t      precision;
1977
  int64_t     interval;
1978
  int64_t     sliding;
1979
  int64_t     offset;
1980
  STimeWindow timeRange;
1981
} SInterval;
1982

1983
typedef struct STbVerInfo {
1984
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1985
  int32_t sversion;
1986
  int32_t tversion;
1987
  int32_t rversion;  // virtual table's column ref's version
1988
} STbVerInfo;
1989

1990
typedef struct {
1991
  int32_t code;
1992
  int64_t affectedRows;
1993
  SArray* tbVerInfo;  // STbVerInfo
1994
} SQueryTableRsp;
1995

1996
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1997

1998
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1999

2000
typedef struct {
2001
  SMsgHead header;
2002
  char     dbFName[TSDB_DB_FNAME_LEN];
2003
  char     tbName[TSDB_TABLE_NAME_LEN];
2004
} STableCfgReq;
2005

2006
typedef struct {
2007
  char        tbName[TSDB_TABLE_NAME_LEN];
2008
  char        stbName[TSDB_TABLE_NAME_LEN];
2009
  char        dbFName[TSDB_DB_FNAME_LEN];
2010
  int32_t     numOfTags;
2011
  int32_t     numOfColumns;
2012
  int8_t      tableType;
2013
  int64_t     delay1;
2014
  int64_t     delay2;
2015
  int64_t     watermark1;
2016
  int64_t     watermark2;
2017
  int32_t     ttl;
2018
  int32_t     keep;
2019
  int64_t     ownerId;
2020
  SArray*     pFuncs;
2021
  int32_t     commentLen;
2022
  char*       pComment;
2023
  SSchema*    pSchemas;
2024
  int32_t     tagsLen;
2025
  char*       pTags;
2026
  SSchemaExt* pSchemaExt;
2027
  int8_t      virtualStb;
2028
  SColRef*    pColRefs;
2029
} STableCfg;
2030

2031
typedef STableCfg STableCfgRsp;
2032

2033
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2034
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2035

2036
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2037
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2038
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2039

2040
typedef struct {
2041
  SMsgHead header;
2042
  tb_uid_t suid;
2043
} SVSubTablesReq;
2044

2045
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2046
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2047

2048
typedef struct {
2049
  int32_t vgId;
2050
  SArray* pTables;  // SArray<SVCTableRefCols*>
2051
} SVSubTablesRsp;
2052

2053
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2054
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2055
void    tDestroySVSubTablesRsp(void* rsp);
2056

2057
typedef struct {
2058
  SMsgHead header;
2059
  tb_uid_t suid;
2060
} SVStbRefDbsReq;
2061

2062
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2063
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2064

2065
typedef struct {
2066
  int32_t vgId;
2067
  SArray* pDbs;  // SArray<char* (db name)>
2068
} SVStbRefDbsRsp;
2069

2070
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2071
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2072
void    tDestroySVStbRefDbsRsp(void* rsp);
2073

2074
typedef struct {
2075
  char    db[TSDB_DB_FNAME_LEN];
2076
  int32_t numOfVgroups;
2077
  int32_t numOfStables;  // single_stable
2078
  int32_t buffer;        // MB
2079
  int32_t pageSize;
2080
  int32_t pages;
2081
  int32_t cacheLastSize;
2082
  int32_t daysPerFile;
2083
  int32_t daysToKeep0;
2084
  int32_t daysToKeep1;
2085
  int32_t daysToKeep2;
2086
  int32_t keepTimeOffset;
2087
  int32_t minRows;
2088
  int32_t maxRows;
2089
  int32_t walFsyncPeriod;
2090
  int8_t  walLevel;
2091
  int8_t  precision;  // time resolution
2092
  int8_t  compression;
2093
  int8_t  replications;
2094
  int8_t  strict;
2095
  int8_t  cacheLast;
2096
  int8_t  schemaless;
2097
  int8_t  ignoreExist;
2098
  int32_t numOfRetensions;
2099
  SArray* pRetensions;  // SRetention
2100
  int32_t walRetentionPeriod;
2101
  int64_t walRetentionSize;
2102
  int32_t walRollPeriod;
2103
  int64_t walSegmentSize;
2104
  int32_t sstTrigger;
2105
  int16_t hashPrefix;
2106
  int16_t hashSuffix;
2107
  int32_t ssChunkSize;
2108
  int32_t ssKeepLocal;
2109
  int8_t  ssCompact;
2110
  int32_t tsdbPageSize;
2111
  int32_t sqlLen;
2112
  char*   sql;
2113
  int8_t  withArbitrator;
2114
  int8_t  encryptAlgorithm;
2115
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2116
  // 1. add auto-compact parameters
2117
  int32_t compactInterval;    // minutes
2118
  int32_t compactStartTime;   // minutes
2119
  int32_t compactEndTime;     // minutes
2120
  int8_t  compactTimeOffset;  // hour
2121
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2122
  int8_t  isAudit;
2123
} SCreateDbReq;
2124

2125
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2126
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2127
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2128

2129
typedef struct {
2130
  char    db[TSDB_DB_FNAME_LEN];
2131
  int32_t buffer;
2132
  int32_t pageSize;
2133
  int32_t pages;
2134
  int32_t cacheLastSize;
2135
  int32_t daysPerFile;
2136
  int32_t daysToKeep0;
2137
  int32_t daysToKeep1;
2138
  int32_t daysToKeep2;
2139
  int32_t keepTimeOffset;
2140
  int32_t walFsyncPeriod;
2141
  int8_t  walLevel;
2142
  int8_t  strict;
2143
  int8_t  cacheLast;
2144
  int8_t  replications;
2145
  int32_t sstTrigger;
2146
  int32_t minRows;
2147
  int32_t walRetentionPeriod;
2148
  int32_t walRetentionSize;
2149
  int32_t ssKeepLocal;
2150
  int8_t  ssCompact;
2151
  int32_t sqlLen;
2152
  char*   sql;
2153
  int8_t  withArbitrator;
2154
  // 1. add auto-compact parameters
2155
  int32_t compactInterval;
2156
  int32_t compactStartTime;
2157
  int32_t compactEndTime;
2158
  int8_t  compactTimeOffset;
2159
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2160
  int8_t  isAudit;
2161
} SAlterDbReq;
2162

2163
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2164
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2165
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2166

2167
typedef struct {
2168
  char    db[TSDB_DB_FNAME_LEN];
2169
  int8_t  ignoreNotExists;
2170
  int8_t  force;
2171
  int32_t sqlLen;
2172
  char*   sql;
2173
} SDropDbReq;
2174

2175
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2176
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2177
void    tFreeSDropDbReq(SDropDbReq* pReq);
2178

2179
typedef struct {
2180
  char    db[TSDB_DB_FNAME_LEN];
2181
  int64_t uid;
2182
} SDropDbRsp;
2183

2184
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2185
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2186

2187
typedef struct {
2188
  char    name[TSDB_MOUNT_NAME_LEN];
2189
  int64_t uid;
2190
} SDropMountRsp;
2191

2192
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2193
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2194

2195
typedef struct {
2196
  char    db[TSDB_DB_FNAME_LEN];
2197
  int64_t dbId;
2198
  int32_t vgVersion;
2199
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2200
  int64_t stateTs;     // ms
2201
} SUseDbReq;
2202

2203
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2204
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2205

2206
typedef struct {
2207
  char    db[TSDB_DB_FNAME_LEN];
2208
  int64_t uid;
2209
  int32_t vgVersion;
2210
  int32_t vgNum;
2211
  int16_t hashPrefix;
2212
  int16_t hashSuffix;
2213
  int8_t  hashMethod;
2214
  union {
2215
    uint8_t flags;
2216
    struct {
2217
      uint8_t isMount : 1;  // TS-5868
2218
      uint8_t padding : 7;
2219
    };
2220
  };
2221
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2222
  int32_t errCode;
2223
  int64_t stateTs;  // ms
2224
} SUseDbRsp;
2225

2226
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2227
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2228
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2229
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2230
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2231

2232
typedef struct {
2233
  char db[TSDB_DB_FNAME_LEN];
2234
} SDbCfgReq;
2235

2236
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2237
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2238

2239
typedef struct {
2240
  char db[TSDB_DB_FNAME_LEN];
2241
} SSsMigrateDbReq;
2242

2243
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2244
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2245

2246
typedef struct {
2247
  int32_t ssMigrateId;
2248
  bool    bAccepted;
2249
} SSsMigrateDbRsp;
2250

2251
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2252
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2253

2254
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2255
typedef struct {
2256
  int32_t ssMigrateId;
2257
} SListSsMigrateFileSetsReq;
2258

2259
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2260
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2261

2262
typedef struct {
2263
  int32_t ssMigrateId;
2264
  int32_t vgId;       // vgroup id
2265
  SArray* pFileSets;  // SArray<int32_t>
2266
} SListSsMigrateFileSetsRsp;
2267

2268
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2269
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2270
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2271

2272
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2273
typedef struct {
2274
  int32_t ssMigrateId;
2275
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2276
  int32_t fid;
2277
  int64_t startTimeSec;
2278
} SSsMigrateFileSetReq;
2279

2280
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2281
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2282

2283
typedef struct {
2284
  int32_t ssMigrateId;
2285
  int32_t nodeId;  // node id of the leader vnode
2286
  int32_t vgId;
2287
  int32_t fid;
2288
} SSsMigrateFileSetRsp;
2289

2290
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2291
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2292

2293
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2294
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2295
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2296
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2297
#define SSMIGRATE_FILESET_STATE_FAILED      4
2298

2299
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2300
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2301
// while as a request, the 'state' field is not used.
2302
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2303
typedef struct {
2304
  int32_t ssMigrateId;  // ss migrate id
2305
  int32_t nodeId;       // node id of the leader vnode
2306
  int32_t vgId;         // vgroup id
2307
  int32_t fid;          // file set id
2308
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2309
} SSsMigrateProgress;
2310

2311
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2312
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2313

2314
// Request for TDMT_MND_KILL_SSMIGRATE
2315
typedef struct {
2316
  int32_t ssMigrateId;
2317
  int32_t sqlLen;
2318
  char*   sql;
2319
} SKillSsMigrateReq;
2320

2321
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2322
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2323
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2324

2325
// Request for TDMT_VND_KILL_SSMIGRATE
2326
typedef struct {
2327
  int32_t ssMigrateId;
2328
} SVnodeKillSsMigrateReq;
2329

2330
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2331
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2332

2333
typedef struct {
2334
  int32_t vgId;
2335
  int64_t keepVersion;
2336
} SMndSetVgroupKeepVersionReq;
2337

2338
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2339
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2340

2341
typedef struct {
2342
  int32_t timestampSec;
2343
  int32_t ttlDropMaxCount;
2344
  int32_t nUids;
2345
  SArray* pTbUids;
2346
} SVDropTtlTableReq;
2347

2348
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2349
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2350

2351
typedef struct {
2352
  char    db[TSDB_DB_FNAME_LEN];
2353
  int64_t dbId;
2354
  int64_t ownerId;
2355
  int32_t cfgVersion;
2356
  int32_t numOfVgroups;
2357
  int32_t numOfStables;
2358
  int32_t buffer;
2359
  int32_t cacheSize;
2360
  int32_t pageSize;
2361
  int32_t pages;
2362
  int32_t daysPerFile;
2363
  int32_t daysToKeep0;
2364
  int32_t daysToKeep1;
2365
  int32_t daysToKeep2;
2366
  int32_t keepTimeOffset;
2367
  int32_t minRows;
2368
  int32_t maxRows;
2369
  int32_t walFsyncPeriod;
2370
  int16_t hashPrefix;
2371
  int16_t hashSuffix;
2372
  int8_t  hashMethod;
2373
  int8_t  walLevel;
2374
  int8_t  precision;
2375
  int8_t  compression;
2376
  int8_t  replications;
2377
  int8_t  strict;
2378
  int8_t  cacheLast;
2379
  int8_t  encryptAlgr;
2380
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2381
  int32_t ssChunkSize;
2382
  int32_t ssKeepLocal;
2383
  int8_t  ssCompact;
2384
  union {
2385
    uint8_t flags;
2386
    struct {
2387
      uint8_t isMount : 1;  // TS-5868
2388
      uint8_t padding : 7;
2389
    };
2390
  };
2391
  int8_t  compactTimeOffset;
2392
  int32_t compactInterval;
2393
  int32_t compactStartTime;
2394
  int32_t compactEndTime;
2395
  int32_t tsdbPageSize;
2396
  int32_t walRetentionPeriod;
2397
  int32_t walRollPeriod;
2398
  int64_t walRetentionSize;
2399
  int64_t walSegmentSize;
2400
  int32_t numOfRetensions;
2401
  SArray* pRetensions;
2402
  int8_t  schemaless;
2403
  int16_t sstTrigger;
2404
  int8_t  withArbitrator;
2405
  int8_t  isAudit;
2406
} SDbCfgRsp;
2407

2408
typedef SDbCfgRsp SDbCfgInfo;
2409

2410
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2411
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2412
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2413
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2414
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2415

2416
typedef struct {
2417
  int32_t rowNum;
2418
} SQnodeListReq;
2419

2420
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2421
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2422

2423
typedef struct {
2424
  int32_t rowNum;
2425
} SDnodeListReq;
2426

2427
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2428

2429
typedef struct {
2430
  int32_t useless;  // useless
2431
} SServerVerReq;
2432

2433
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2434
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2435

2436
typedef struct {
2437
  char ver[TSDB_VERSION_LEN];
2438
} SServerVerRsp;
2439

2440
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2441
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2442

2443
typedef struct SQueryNodeAddr {
2444
  int32_t nodeId;  // vgId or qnodeId
2445
  SEpSet  epSet;
2446
} SQueryNodeAddr;
2447

2448
typedef struct {
2449
  SQueryNodeAddr addr;
2450
  uint64_t       load;
2451
} SQueryNodeLoad;
2452

2453
typedef struct {
2454
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2455
} SQnodeListRsp;
2456

2457
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2458
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2459
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2460

2461

2462
typedef struct SDownstreamSourceNode {
2463
  ENodeType      type;
2464
  SQueryNodeAddr addr;
2465
  uint64_t       clientId;
2466
  uint64_t       taskId;
2467
  uint64_t       sId;
2468
  int32_t        execId;
2469
  int32_t        fetchMsgType;
2470
  bool           localExec;
2471
} SDownstreamSourceNode;
2472

2473

2474

2475
typedef struct SDNodeAddr {
2476
  int32_t nodeId;  // dnodeId
2477
  SEpSet  epSet;
2478
} SDNodeAddr;
2479

2480
typedef struct {
2481
  SArray* dnodeList;  // SArray<SDNodeAddr>
2482
} SDnodeListRsp;
2483

2484
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2485
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2486
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2487

2488
typedef struct {
2489
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2490
} STableTSMAInfoRsp;
2491

2492
typedef struct {
2493
  SUseDbRsp*         useDbRsp;
2494
  SDbCfgRsp*         cfgRsp;
2495
  STableTSMAInfoRsp* pTsmaRsp;
2496
  int32_t            dbTsmaVersion;
2497
  char               db[TSDB_DB_FNAME_LEN];
2498
  int64_t            dbId;
2499
} SDbHbRsp;
2500

2501
typedef struct {
2502
  SArray* pArray;  // Array of SDbHbRsp
2503
} SDbHbBatchRsp;
2504

2505
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2506
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2507
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2508

2509
typedef struct {
2510
  SArray* pArray;  // Array of SGetUserAuthRsp
2511
} SUserAuthBatchRsp;
2512

2513
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2514
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2515
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2516

2517
typedef struct {
2518
  char        db[TSDB_DB_FNAME_LEN];
2519
  STimeWindow timeRange;
2520
  int32_t     sqlLen;
2521
  char*       sql;
2522
  SArray*     vgroupIds;
2523
  int32_t     compactId;
2524
  int8_t      metaOnly;
2525
  int8_t      force;
2526
} SCompactDbReq;
2527

2528
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2529
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2530
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2531

2532
typedef struct {
2533
  union {
2534
    int32_t compactId;
2535
    int32_t id;
2536
  };
2537
  int8_t bAccepted;
2538
} SCompactDbRsp;
2539

2540
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2541
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2542

2543
typedef struct {
2544
  union {
2545
    int32_t compactId;
2546
    int32_t id;
2547
  };
2548
  int32_t sqlLen;
2549
  char*   sql;
2550
} SKillCompactReq;
2551

2552
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2553
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2554
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2555

2556
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2557
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2558

2559
typedef struct {
2560
  char    name[TSDB_FUNC_NAME_LEN];
2561
  int8_t  igExists;
2562
  int8_t  funcType;
2563
  int8_t  scriptType;
2564
  int8_t  outputType;
2565
  int32_t outputLen;
2566
  int32_t bufSize;
2567
  int32_t codeLen;
2568
  int64_t signature;
2569
  char*   pComment;
2570
  char*   pCode;
2571
  int8_t  orReplace;
2572
} SCreateFuncReq;
2573

2574
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2575
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2576
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2577

2578
typedef struct {
2579
  char   name[TSDB_FUNC_NAME_LEN];
2580
  int8_t igNotExists;
2581
} SDropFuncReq;
2582

2583
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2584
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2585

2586
typedef struct {
2587
  int32_t numOfFuncs;
2588
  bool    ignoreCodeComment;
2589
  SArray* pFuncNames;
2590
} SRetrieveFuncReq;
2591

2592
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2593
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2594
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2595

2596
typedef struct {
2597
  char    name[TSDB_FUNC_NAME_LEN];
2598
  int8_t  funcType;
2599
  int8_t  scriptType;
2600
  int8_t  outputType;
2601
  int32_t outputLen;
2602
  int32_t bufSize;
2603
  int64_t signature;
2604
  int32_t commentSize;
2605
  int32_t codeSize;
2606
  char*   pComment;
2607
  char*   pCode;
2608
} SFuncInfo;
2609

2610
typedef struct {
2611
  int32_t funcVersion;
2612
  int64_t funcCreatedTime;
2613
} SFuncExtraInfo;
2614

2615
typedef struct {
2616
  int32_t numOfFuncs;
2617
  SArray* pFuncInfos;
2618
  SArray* pFuncExtraInfos;
2619
} SRetrieveFuncRsp;
2620

2621
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2622
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2623
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2624
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2625

2626
typedef struct {
2627
  int32_t       statusInterval;
2628
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2629
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2630
  char          locale[TD_LOCALE_LEN];      // tsLocale
2631
  char          charset[TD_LOCALE_LEN];     // tsCharset
2632
  int8_t        ttlChangeOnWrite;
2633
  int8_t        enableWhiteList;
2634
  int8_t        encryptionKeyStat;
2635
  uint32_t      encryptionKeyChksum;
2636
  SMonitorParas monitorParas;
2637
  int32_t       statusIntervalMs;
2638
} SClusterCfg;
2639

2640
typedef struct {
2641
  int32_t openVnodes;
2642
  int32_t dropVnodes;
2643
  int32_t totalVnodes;
2644
  int32_t masterNum;
2645
  int64_t numOfSelectReqs;
2646
  int64_t numOfInsertReqs;
2647
  int64_t numOfInsertSuccessReqs;
2648
  int64_t numOfBatchInsertReqs;
2649
  int64_t numOfBatchInsertSuccessReqs;
2650
  int64_t errors;
2651
} SVnodesStat;
2652

2653
typedef struct {
2654
  int32_t vgId;
2655
  int8_t  syncState;
2656
  int8_t  syncRestore;
2657
  int64_t syncTerm;
2658
  int64_t roleTimeMs;
2659
  int64_t startTimeMs;
2660
  int8_t  syncCanRead;
2661
  int64_t cacheUsage;
2662
  int64_t numOfTables;
2663
  int64_t numOfTimeSeries;
2664
  int64_t totalStorage;
2665
  int64_t compStorage;
2666
  int64_t pointsWritten;
2667
  int64_t numOfSelectReqs;
2668
  int64_t numOfInsertReqs;
2669
  int64_t numOfInsertSuccessReqs;
2670
  int64_t numOfBatchInsertReqs;
2671
  int64_t numOfBatchInsertSuccessReqs;
2672
  int32_t numOfCachedTables;
2673
  int32_t learnerProgress;  // use one reservered
2674
  int64_t syncAppliedIndex;
2675
  int64_t syncCommitIndex;
2676
  int64_t bufferSegmentUsed;
2677
  int64_t bufferSegmentSize;
2678
  int32_t snapSeq;
2679
  int64_t syncTotalIndex;
2680
} SVnodeLoad;
2681

2682
typedef struct {
2683
  int64_t total_requests;
2684
  int64_t total_rows;
2685
  int64_t total_bytes;
2686
  double  write_size;
2687
  double  cache_hit_ratio;
2688
  int64_t rpc_queue_wait;
2689
  int64_t preprocess_time;
2690

2691
  int64_t memory_table_size;
2692
  int64_t commit_count;
2693
  int64_t merge_count;
2694
  double  commit_time;
2695
  double  merge_time;
2696
  int64_t block_commit_time;
2697
  int64_t memtable_wait_time;
2698
} SVnodeMetrics;
2699

2700
typedef struct {
2701
  int32_t     vgId;
2702
  int64_t     numOfTables;
2703
  int64_t     memSize;
2704
  int64_t     l1Size;
2705
  int64_t     l2Size;
2706
  int64_t     l3Size;
2707
  int64_t     cacheSize;
2708
  int64_t     walSize;
2709
  int64_t     metaSize;
2710
  int64_t     rawDataSize;
2711
  int64_t     ssSize;
2712
  const char* dbname;
2713
  int8_t      estimateRawData;
2714
} SDbSizeStatisInfo;
2715

2716
typedef struct {
2717
  int32_t vgId;
2718
  int64_t nTimeSeries;
2719
} SVnodeLoadLite;
2720

2721
typedef struct {
2722
  int8_t  syncState;
2723
  int64_t syncTerm;
2724
  int8_t  syncRestore;
2725
  int64_t roleTimeMs;
2726
} SMnodeLoad;
2727

2728
typedef struct {
2729
  int32_t dnodeId;
2730
  int64_t numOfProcessedQuery;
2731
  int64_t numOfProcessedCQuery;
2732
  int64_t numOfProcessedFetch;
2733
  int64_t numOfProcessedDrop;
2734
  int64_t numOfProcessedNotify;
2735
  int64_t numOfProcessedHb;
2736
  int64_t numOfProcessedDelete;
2737
  int64_t cacheDataSize;
2738
  int64_t numOfQueryInQueue;
2739
  int64_t numOfFetchInQueue;
2740
  int64_t timeInQueryQueue;
2741
  int64_t timeInFetchQueue;
2742
} SQnodeLoad;
2743

2744
typedef struct {
2745
  int32_t     sver;      // software version
2746
  int64_t     dnodeVer;  // dnode table version in sdb
2747
  int32_t     dnodeId;
2748
  int64_t     clusterId;
2749
  int64_t     rebootTime;
2750
  int64_t     updateTime;
2751
  float       numOfCores;
2752
  int32_t     numOfSupportVnodes;
2753
  int32_t     numOfDiskCfg;
2754
  int64_t     memTotal;
2755
  int64_t     memAvail;
2756
  char        dnodeEp[TSDB_EP_LEN];
2757
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2758
  SMnodeLoad  mload;
2759
  SQnodeLoad  qload;
2760
  SClusterCfg clusterCfg;
2761
  SArray*     pVloads;  // array of SVnodeLoad
2762
  int32_t     statusSeq;
2763
  int64_t     ipWhiteVer;
2764
  int64_t     timeWhiteVer;
2765
  int64_t     analVer;
2766
  int64_t     timestamp;
2767
  char        auditDB[TSDB_DB_FNAME_LEN];
2768
  char        auditToken[TSDB_TOKEN_LEN];
2769
} SStatusReq;
2770

2771
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2772
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2773
void    tFreeSStatusReq(SStatusReq* pReq);
2774

2775
typedef struct {
2776
  int32_t forceReadConfig;
2777
  int32_t cver;
2778
  SArray* array;
2779
} SConfigReq;
2780

2781
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2782
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2783
void    tFreeSConfigReq(SConfigReq* pReq);
2784

2785
typedef struct {
2786
  int32_t dnodeId;
2787
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2788
} SDnodeInfoReq;
2789

2790
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2791
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2792

2793
typedef enum {
2794
  MONITOR_TYPE_COUNTER = 0,
2795
  MONITOR_TYPE_SLOW_LOG = 1,
2796
} MONITOR_TYPE;
2797

2798
typedef struct {
2799
  int32_t      contLen;
2800
  char*        pCont;
2801
  MONITOR_TYPE type;
2802
} SStatisReq;
2803

2804
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2805
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2806
void    tFreeSStatisReq(SStatisReq* pReq);
2807

2808
typedef struct {
2809
  char    db[TSDB_DB_FNAME_LEN];
2810
  char    table[TSDB_TABLE_NAME_LEN];
2811
  char    operation[AUDIT_OPERATION_LEN];
2812
  int32_t sqlLen;
2813
  char*   pSql;
2814
  double  duration;
2815
  int64_t affectedRows;
2816
} SAuditReq;
2817
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2818
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2819
void    tFreeSAuditReq(SAuditReq* pReq);
2820

2821
typedef struct {
2822
  SArray* auditArr;
2823
} SBatchAuditReq;
2824
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2825
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2826
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2827

2828
typedef struct {
2829
  int32_t dnodeId;
2830
  int64_t clusterId;
2831
  SArray* pVloads;
2832
} SNotifyReq;
2833

2834
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2835
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2836
void    tFreeSNotifyReq(SNotifyReq* pReq);
2837

2838
typedef struct {
2839
  int32_t dnodeId;
2840
  int64_t clusterId;
2841
} SDnodeCfg;
2842

2843
typedef struct {
2844
  int32_t id;
2845
  int8_t  isMnode;
2846
  SEp     ep;
2847
} SDnodeEp;
2848

2849
typedef struct {
2850
  int32_t id;
2851
  int8_t  isMnode;
2852
  int8_t  offlineReason;
2853
  SEp     ep;
2854
  char    active[TSDB_ACTIVE_KEY_LEN];
2855
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2856
} SDnodeInfo;
2857

2858
typedef struct {
2859
  int64_t   dnodeVer;
2860
  SDnodeCfg dnodeCfg;
2861
  SArray*   pDnodeEps;  // Array of SDnodeEp
2862
  int32_t   statusSeq;
2863
  int64_t   ipWhiteVer;
2864
  int64_t   analVer;
2865
  int64_t   timeWhiteVer;
2866
  char      auditDB[TSDB_DB_FNAME_LEN];
2867
  char      auditToken[TSDB_TOKEN_LEN];
2868
} SStatusRsp;
2869

2870
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2871
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2872
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2873

2874
typedef struct {
2875
  int32_t forceReadConfig;
2876
  int32_t isConifgVerified;
2877
  int32_t isVersionVerified;
2878
  int32_t cver;
2879
  SArray* array;
2880
} SConfigRsp;
2881

2882
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2883
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2884
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2885

2886
typedef struct {
2887
  int32_t dnodeId;
2888
  int32_t keyVersion;  // Local key version
2889
} SKeySyncReq;
2890

2891
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2892
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2893

2894
typedef struct {
2895
  int32_t keyVersion;        // mnode's key version
2896
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2897
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2898
  char    svrKey[129];       // Server key (if needUpdate)
2899
  char    dbKey[129];        // Database key (if needUpdate)
2900
  char    cfgKey[129];       // Config key (if needUpdate)
2901
  char    metaKey[129];      // Metadata key (if needUpdate)
2902
  char    dataKey[129];      // Data key (if needUpdate)
2903
  int32_t algorithm;         // Encryption algorithm for master keys
2904
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2905
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2906
  int64_t createTime;        // Key creation time
2907
  int64_t svrKeyUpdateTime;  // Server key update time
2908
  int64_t dbKeyUpdateTime;   // Database key update time
2909
} SKeySyncRsp;
2910

2911
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2912
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2913

2914
typedef struct {
2915
  int32_t reserved;
2916
} SMTimerReq;
2917

2918
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2919
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2920

2921
typedef struct SOrphanTask {
2922
  int64_t streamId;
2923
  int32_t taskId;
2924
  int32_t nodeId;
2925
} SOrphanTask;
2926

2927
typedef struct SMStreamDropOrphanMsg {
2928
  SArray* pList;  // SArray<SOrphanTask>
2929
} SMStreamDropOrphanMsg;
2930

2931
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2932
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2933
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2934

2935
typedef struct {
2936
  int32_t  id;
2937
  uint16_t port;                 // node sync Port
2938
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2939
} SReplica;
2940

2941
typedef struct {
2942
  int32_t  vgId;
2943
  char     db[TSDB_DB_FNAME_LEN];
2944
  int64_t  dbUid;
2945
  int32_t  vgVersion;
2946
  int32_t  numOfStables;
2947
  int32_t  buffer;
2948
  int32_t  pageSize;
2949
  int32_t  pages;
2950
  int32_t  cacheLastSize;
2951
  int32_t  daysPerFile;
2952
  int32_t  daysToKeep0;
2953
  int32_t  daysToKeep1;
2954
  int32_t  daysToKeep2;
2955
  int32_t  keepTimeOffset;
2956
  int32_t  minRows;
2957
  int32_t  maxRows;
2958
  int32_t  walFsyncPeriod;
2959
  uint32_t hashBegin;
2960
  uint32_t hashEnd;
2961
  int8_t   hashMethod;
2962
  int8_t   walLevel;
2963
  int8_t   precision;
2964
  int8_t   compression;
2965
  int8_t   strict;
2966
  int8_t   cacheLast;
2967
  int8_t   isTsma;
2968
  int8_t   replica;
2969
  int8_t   selfIndex;
2970
  SReplica replicas[TSDB_MAX_REPLICA];
2971
  int32_t  numOfRetensions;
2972
  SArray*  pRetensions;  // SRetention
2973
  void*    pTsma;
2974
  int32_t  walRetentionPeriod;
2975
  int64_t  walRetentionSize;
2976
  int32_t  walRollPeriod;
2977
  int64_t  walSegmentSize;
2978
  int16_t  sstTrigger;
2979
  int16_t  hashPrefix;
2980
  int16_t  hashSuffix;
2981
  int32_t  tsdbPageSize;
2982
  int32_t  ssChunkSize;
2983
  int32_t  ssKeepLocal;
2984
  int8_t   ssCompact;
2985
  int64_t  reserved[6];
2986
  int8_t   learnerReplica;
2987
  int8_t   learnerSelfIndex;
2988
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2989
  int32_t  changeVersion;
2990
  int8_t   encryptAlgorithm;
2991
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2992
} SCreateVnodeReq;
2993

2994
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2995
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2996
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2997

2998
typedef struct {
2999
  union {
3000
    int32_t compactId;
3001
    int32_t id;
3002
  };
3003
  int32_t vgId;
3004
  int32_t dnodeId;
3005
} SQueryCompactProgressReq;
3006

3007
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3008
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3009

3010
typedef struct {
3011
  union {
3012
    int32_t compactId;
3013
    int32_t id;
3014
  };
3015
  int32_t vgId;
3016
  int32_t dnodeId;
3017
  int32_t numberFileset;
3018
  int32_t finished;
3019
  int32_t progress;
3020
  int64_t remainingTime;
3021
} SQueryCompactProgressRsp;
3022

3023
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3024
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3025

3026
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3027
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3028

3029
typedef struct {
3030
  int32_t vgId;
3031
  int32_t dnodeId;
3032
  int64_t dbUid;
3033
  char    db[TSDB_DB_FNAME_LEN];
3034
  int64_t reserved[8];
3035
} SDropVnodeReq;
3036

3037
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3038
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3039

3040
typedef struct {
3041
  char    colName[TSDB_COL_NAME_LEN];
3042
  char    stb[TSDB_TABLE_FNAME_LEN];
3043
  int64_t stbUid;
3044
  int64_t dbUid;
3045
  int64_t reserved[8];
3046
} SDropIndexReq;
3047

3048
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3049
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3050

3051
typedef struct {
3052
  int64_t dbUid;
3053
  char    db[TSDB_DB_FNAME_LEN];
3054
  union {
3055
    int64_t compactStartTime;
3056
    int64_t startTime;
3057
  };
3058

3059
  STimeWindow tw;
3060
  union {
3061
    int32_t compactId;
3062
    int32_t id;
3063
  };
3064
  int8_t metaOnly;
3065
  union {
3066
    uint16_t flags;
3067
    struct {
3068
      uint16_t optrType : 3;     // ETsdbOpType
3069
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3070
      uint16_t reserved : 12;
3071
    };
3072
  };
3073
  int8_t force;  // force compact
3074
} SCompactVnodeReq;
3075

3076
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3077
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3078

3079
typedef struct {
3080
  union {
3081
    int32_t compactId;
3082
    int32_t taskId;
3083
  };
3084
  int32_t vgId;
3085
  int32_t dnodeId;
3086
} SVKillCompactReq;
3087

3088
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3089
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3090

3091
typedef SVKillCompactReq SVKillRetentionReq;
3092

3093
typedef struct {
3094
  char        db[TSDB_DB_FNAME_LEN];
3095
  int32_t     maxSpeed;
3096
  int32_t     sqlLen;
3097
  char*       sql;
3098
  SArray*     vgroupIds;
3099
  STimeWindow tw;  // unit is second
3100
  union {
3101
    uint32_t flags;
3102
    struct {
3103
      uint32_t optrType : 3;     // ETsdbOpType
3104
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3105
      uint32_t reserved : 28;
3106
    };
3107
  };
3108
} STrimDbReq;
3109

3110
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3111
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3112
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3113

3114
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3115

3116
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3117
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3118

3119
typedef struct {
3120
  int32_t vgVersion;
3121
  int32_t buffer;
3122
  int32_t pageSize;
3123
  int32_t pages;
3124
  int32_t cacheLastSize;
3125
  int32_t daysPerFile;
3126
  int32_t daysToKeep0;
3127
  int32_t daysToKeep1;
3128
  int32_t daysToKeep2;
3129
  int32_t keepTimeOffset;
3130
  int32_t walFsyncPeriod;
3131
  int8_t  walLevel;
3132
  int8_t  strict;
3133
  int8_t  cacheLast;
3134
  int64_t reserved[7];
3135
  // 1st modification
3136
  int16_t sttTrigger;
3137
  int32_t minRows;
3138
  // 2nd modification
3139
  int32_t walRetentionPeriod;
3140
  int32_t walRetentionSize;
3141
  int32_t ssKeepLocal;
3142
  int8_t  ssCompact;
3143
} SAlterVnodeConfigReq;
3144

3145
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3146
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3147

3148
typedef struct {
3149
  int32_t  vgId;
3150
  int8_t   strict;
3151
  int8_t   selfIndex;
3152
  int8_t   replica;
3153
  SReplica replicas[TSDB_MAX_REPLICA];
3154
  int64_t  reserved[8];
3155
  int8_t   learnerSelfIndex;
3156
  int8_t   learnerReplica;
3157
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3158
  int32_t  changeVersion;
3159
  int32_t  electBaseLine;
3160
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3161

3162
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3163
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3164

3165
typedef struct {
3166
  int32_t vgId;
3167
  int8_t  disable;
3168
} SDisableVnodeWriteReq;
3169

3170
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3171
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3172

3173
typedef struct {
3174
  int32_t  srcVgId;
3175
  int32_t  dstVgId;
3176
  uint32_t hashBegin;
3177
  uint32_t hashEnd;
3178
  int32_t  changeVersion;
3179
  int32_t  reserved;
3180
} SAlterVnodeHashRangeReq;
3181

3182
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3183
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3184

3185
#define REQ_OPT_TBNAME 0x0
3186
#define REQ_OPT_TBUID  0x01
3187
typedef struct {
3188
  SMsgHead header;
3189
  char     dbFName[TSDB_DB_FNAME_LEN];
3190
  char     tbName[TSDB_TABLE_NAME_LEN];
3191
  uint8_t  option;
3192
  uint8_t  autoCreateCtb;
3193
} STableInfoReq;
3194

3195
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3196
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3197

3198
typedef struct {
3199
  int8_t  metaClone;  // create local clone of the cached table meta
3200
  int32_t numOfVgroups;
3201
  int32_t numOfTables;
3202
  int32_t numOfUdfs;
3203
  char    tableNames[];
3204
} SMultiTableInfoReq;
3205

3206
// todo refactor
3207
typedef struct SVgroupInfo {
3208
  int32_t  vgId;
3209
  uint32_t hashBegin;
3210
  uint32_t hashEnd;
3211
  SEpSet   epSet;
3212
  union {
3213
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3214
    int32_t taskId;      // used in stream
3215
  };
3216
} SVgroupInfo;
3217

3218
typedef struct {
3219
  int32_t     numOfVgroups;
3220
  SVgroupInfo vgroups[];
3221
} SVgroupsInfo;
3222

3223
typedef struct {
3224
  STableMetaRsp* pMeta;
3225
} SMAlterStbRsp;
3226

3227
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3228
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3229
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3230

3231
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3232
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3233
void    tFreeSTableMetaRsp(void* pRsp);
3234
void    tFreeSTableIndexRsp(void* info);
3235

3236
typedef struct {
3237
  SArray* pMetaRsp;   // Array of STableMetaRsp
3238
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3239
} SSTbHbRsp;
3240

3241
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3242
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3243
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3244

3245
typedef struct {
3246
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3247
} SViewHbRsp;
3248

3249
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3250
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3251
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3252

3253
typedef struct {
3254
  int32_t numOfTables;
3255
  int32_t numOfVgroup;
3256
  int32_t numOfUdf;
3257
  int32_t contLen;
3258
  int8_t  compressed;  // denote if compressed or not
3259
  int32_t rawLen;      // size before compress
3260
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3261
  char    meta[];
3262
} SMultiTableMeta;
3263

3264
typedef struct {
3265
  int32_t dataLen;
3266
  char    name[TSDB_TABLE_FNAME_LEN];
3267
  char*   data;
3268
} STagData;
3269

3270
typedef struct {
3271
  int32_t  opType;
3272
  uint32_t valLen;
3273
  char*    val;
3274
} SShowVariablesReq;
3275

3276
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3277
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3278
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3279

3280
typedef struct {
3281
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3282
  char value[TSDB_CONFIG_PATH_LEN + 1];
3283
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3284
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3285
  char info[TSDB_CONFIG_INFO_LEN + 1];
3286
} SVariablesInfo;
3287

3288
typedef struct {
3289
  SArray* variables;  // SArray<SVariablesInfo>
3290
} SShowVariablesRsp;
3291

3292
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3293
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3294

3295
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3296

3297
/*
3298
 * sql: show tables like '%a_%'
3299
 * payload is the query condition, e.g., '%a_%'
3300
 * payloadLen is the length of payload
3301
 */
3302
typedef struct {
3303
  int32_t type;
3304
  char    db[TSDB_DB_FNAME_LEN];
3305
  int32_t payloadLen;
3306
  char*   payload;
3307
} SShowReq;
3308

3309
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3310
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3311
void tFreeSShowReq(SShowReq* pReq);
3312

3313
typedef struct {
3314
  int64_t       showId;
3315
  STableMetaRsp tableMeta;
3316
} SShowRsp, SVShowTablesRsp;
3317

3318
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3319
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3320
// void    tFreeSShowRsp(SShowRsp* pRsp);
3321

3322
typedef struct {
3323
  char    db[TSDB_DB_FNAME_LEN];
3324
  char    tb[TSDB_TABLE_NAME_LEN];
3325
  char    user[TSDB_USER_LEN];
3326
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3327
  int64_t showId;
3328
  int64_t compactId;  // for compact
3329
  bool    withFull;   // for show users full
3330
} SRetrieveTableReq;
3331

3332
typedef struct SSysTableSchema {
3333
  int8_t   type;
3334
  col_id_t colId;
3335
  int32_t  bytes;
3336
} SSysTableSchema;
3337

3338
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3339
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3340

3341
#define RETRIEVE_TABLE_RSP_VERSION         0
3342
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3343
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3344

3345
typedef struct {
3346
  int64_t useconds;
3347
  int8_t  completed;  // all results are returned to client
3348
  int8_t  precision;
3349
  int8_t  compressed;
3350
  int8_t  streamBlockType;
3351
  int32_t payloadLen;
3352
  int32_t compLen;
3353
  int32_t numOfBlocks;
3354
  int64_t numOfRows;  // from int32_t change to int64_t
3355
  int64_t numOfCols;
3356
  int64_t skey;
3357
  int64_t ekey;
3358
  int64_t version;                         // for stream
3359
  TSKEY   watermark;                       // for stream
3360
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3361
  char    data[];
3362
} SRetrieveTableRsp;
3363

3364
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3365

3366
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3367
  do {                                          \
3368
    ((int32_t*)(_p))[0] = (_compLen);           \
3369
    ((int32_t*)(_p))[1] = (_fullLen);           \
3370
  } while (0);
3371

3372
typedef struct {
3373
  int64_t version;
3374
  int64_t numOfRows;
3375
  int8_t  compressed;
3376
  int8_t  precision;
3377
  char    data[];
3378
} SRetrieveTableRspForTmq;
3379

3380
typedef struct {
3381
  int64_t handle;
3382
  int64_t useconds;
3383
  int8_t  completed;  // all results are returned to client
3384
  int8_t  precision;
3385
  int8_t  compressed;
3386
  int32_t compLen;
3387
  int32_t numOfRows;
3388
  int32_t fullLen;
3389
  char    data[];
3390
} SRetrieveMetaTableRsp;
3391

3392
typedef struct SExplainExecInfo {
3393
  double   startupCost;
3394
  double   totalCost;
3395
  uint64_t numOfRows;
3396
  uint32_t verboseLen;
3397
  void*    verboseInfo;
3398
} SExplainExecInfo;
3399

3400
typedef struct {
3401
  int32_t           numOfPlans;
3402
  SExplainExecInfo* subplanInfo;
3403
} SExplainRsp;
3404

3405
typedef struct {
3406
  SExplainRsp rsp;
3407
  uint64_t    qId;
3408
  uint64_t    cId;
3409
  uint64_t    tId;
3410
  int64_t     rId;
3411
  int32_t     eId;
3412
} SExplainLocalRsp;
3413

3414
typedef struct STableScanAnalyzeInfo {
3415
  uint64_t totalRows;
3416
  uint64_t totalCheckedRows;
3417
  uint32_t totalBlocks;
3418
  uint32_t loadBlocks;
3419
  uint32_t loadBlockStatis;
3420
  uint32_t skipBlocks;
3421
  uint32_t filterOutBlocks;
3422
  double   elapsedTime;
3423
  double   filterTime;
3424
} STableScanAnalyzeInfo;
3425

3426
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3427
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3428
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3429

3430
typedef struct {
3431
  char    config[TSDB_DNODE_CONFIG_LEN];
3432
  char    value[TSDB_CLUSTER_VALUE_LEN];
3433
  int32_t sqlLen;
3434
  char*   sql;
3435
} SMCfgClusterReq;
3436

3437
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3438
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3439
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3440

3441
typedef struct {
3442
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3443
  int32_t port;
3444
  int32_t sqlLen;
3445
  char*   sql;
3446
} SCreateDnodeReq;
3447

3448
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3449
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3450
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3451

3452
typedef struct {
3453
  int32_t dnodeId;
3454
  char    fqdn[TSDB_FQDN_LEN];
3455
  int32_t port;
3456
  int8_t  force;
3457
  int8_t  unsafe;
3458
  int32_t sqlLen;
3459
  char*   sql;
3460
} SDropDnodeReq;
3461

3462
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3463
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3464
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3465

3466
enum {
3467
  RESTORE_TYPE__ALL = 1,
3468
  RESTORE_TYPE__MNODE,
3469
  RESTORE_TYPE__VNODE,
3470
  RESTORE_TYPE__QNODE,
3471
};
3472

3473
typedef struct {
3474
  int32_t dnodeId;
3475
  int8_t  restoreType;
3476
  int32_t sqlLen;
3477
  char*   sql;
3478
} SRestoreDnodeReq;
3479

3480
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3481
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3482
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3483

3484
typedef struct {
3485
  int32_t dnodeId;
3486
  char    config[TSDB_DNODE_CONFIG_LEN];
3487
  char    value[TSDB_DNODE_VALUE_LEN];
3488
  int32_t sqlLen;
3489
  char*   sql;
3490
} SMCfgDnodeReq;
3491

3492
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3493
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3494
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3495

3496
typedef struct {
3497
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3498
  char    newKey[ENCRYPT_KEY_LEN + 1];
3499
  int32_t sqlLen;
3500
  char*   sql;
3501
} SMAlterEncryptKeyReq;
3502

3503
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3504
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3505
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3506

3507
typedef struct {
3508
  char    config[TSDB_DNODE_CONFIG_LEN];
3509
  char    value[TSDB_DNODE_VALUE_LEN];
3510
  int32_t version;
3511
} SDCfgDnodeReq;
3512

3513
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3514
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3515

3516
typedef struct {
3517
  int32_t dnodeId;
3518
  int32_t sqlLen;
3519
  char*   sql;
3520
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3521
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3522

3523
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3524
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3525

3526
typedef struct {
3527
  int32_t nodeId;
3528
  SEpSet  epSet;
3529
} SNodeEpSet;
3530

3531
typedef struct {
3532
  int32_t    snodeId;
3533
  SNodeEpSet leaders[2];
3534
  SNodeEpSet replica;
3535
  int32_t    sqlLen;
3536
  char*      sql;
3537
} SDCreateSnodeReq;
3538

3539
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3540
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3541
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3542

3543
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3544
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3545
typedef struct {
3546
  int8_t   replica;
3547
  SReplica replicas[TSDB_MAX_REPLICA];
3548
  int8_t   learnerReplica;
3549
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3550
  int64_t  lastIndex;
3551
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3552

3553
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3554
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3555

3556
typedef struct {
3557
  int32_t urlLen;
3558
  int32_t sqlLen;
3559
  char*   url;
3560
  char*   sql;
3561
} SMCreateAnodeReq;
3562

3563
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3564
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3565
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3566

3567
typedef struct {
3568
  int32_t anodeId;
3569
  int32_t sqlLen;
3570
  char*   sql;
3571
} SMDropAnodeReq, SMUpdateAnodeReq;
3572

3573
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3574
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3575
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3576
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3577
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3578
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3579

3580
typedef struct {
3581
  int32_t dnodeId;
3582
  int32_t bnodeProto;
3583
  int32_t sqlLen;
3584
  char*   sql;
3585
} SMCreateBnodeReq, SDCreateBnodeReq;
3586

3587
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3588
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3589
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3590

3591
typedef struct {
3592
  int32_t dnodeId;
3593
  int32_t sqlLen;
3594
  char*   sql;
3595
} SMDropBnodeReq, SDDropBnodeReq;
3596

3597
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3598
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3599
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3600

3601
typedef struct {
3602
  int32_t sqlLen;
3603
  int32_t urlLen;
3604
  int32_t userLen;
3605
  int32_t passLen;
3606
  int32_t passIsMd5;
3607
  char*   sql;
3608
  char*   url;
3609
  char*   user;
3610
  char*   pass;
3611
} SMCreateXnodeReq, SDCreateXnodeReq;
3612

3613
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3614
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3615
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3616

3617
typedef struct {
3618
  int32_t xnodeId;
3619
  int32_t force;
3620
  int32_t urlLen;
3621
  int32_t sqlLen;
3622
  char*   url;
3623
  char*   sql;
3624
} SMDropXnodeReq, SMUpdateXnodeReq, SDDropXnodeReq;
3625

3626
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3627
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3628
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3629
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3630
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3631
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3632

3633
typedef struct {
3634
  int32_t xnodeId;
3635
  int32_t sqlLen;
3636
  char*   sql;
3637
} SMDrainXnodeReq;
3638
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3639
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3640
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3641

3642
typedef struct {
3643
  bool        shouldFree;
3644
  int32_t     len;
3645
  const char* ptr;
3646
} CowStr;
3647
/**
3648
 * @brief Create a CowStr object.
3649
 *
3650
 * @param len: length of the string.
3651
 * @param ptr: pointer to the string input.
3652
 * @param shouldClone: whether to clone the string.
3653
 * @return CowStr object.
3654
 */
3655
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3656
/**
3657
 * @brief Set a CowStr object with given string.
3658
 *
3659
 * @param cow: pointer to the CowStr object.
3660
 * @param len: length of the string.
3661
 * @param ptr: pointer to the string input.
3662
 * @param shouldFree: whether to free the string.
3663
 */
3664
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3665
/**
3666
 * @brief Clone a CowStr object without copy the string.
3667
 *
3668
 * @param cow: pointer to the CowStr object.
3669
 * @return CowStr object.
3670
 */
3671
CowStr xCloneRefCowStr(CowStr* cow);
3672
/**
3673
 * @brief Convert a CowStr object to a string.
3674
 *
3675
 * @param cow: pointer to the CowStr object.
3676
 */
3677
char* xCowStrToStr(CowStr* cow);
3678
/**
3679
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3680
 *
3681
 * @param cow: pointer to the CowStr object.
3682
 */
3683
void xFreeCowStr(CowStr* cow);
3684
/**
3685
 * @brief Encode and push a CowStr object into the encoder.
3686
 *
3687
 * @param encoder
3688
 * @param cow
3689
 * @return int32_t
3690
 */
3691
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3692
/**
3693
 * @brief Decode a CowStr from the encoder.
3694
 *
3695
 * @param decoder
3696
 * @param cow
3697
 * @param shouldClone
3698
 * @return int32_t
3699
 */
3700
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3701

3702
typedef enum {
3703
  XNODE_TASK_SOURCE_DSN = 1,
3704
  XNODE_TASK_SOURCE_DATABASE,
3705
  XNODE_TASK_SOURCE_TOPIC,
3706
} ENodeXTaskSourceType;
3707

3708
typedef enum {
3709
  XNODE_TASK_SINK_DSN = 1,
3710
  XNODE_TASK_SINK_DATABASE,
3711
} ENodeXTaskSinkType;
3712

3713
typedef struct {
3714
  ENodeXTaskSourceType type;
3715
  CowStr               cstr;
3716
} xTaskSource;
3717
/**
3718
 * @brief Deallocate a xTaskSource object.
3719
 *
3720
 * @param source ptr
3721
 */
3722
void xFreeTaskSource(xTaskSource* source);
3723
/**
3724
 * @brief Create a xTaskSource object with cloned source string.
3725
 *
3726
 * @param sourceType: source type.
3727
 * @param len: length of source string.
3728
 * @param source: source string ptr.
3729
 * @return xTaskSource object
3730
 */
3731
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3732
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3733
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3734
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3735
const char* xGetTaskSourceStr(xTaskSource* source);
3736
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3737
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3738

3739
typedef struct {
3740
  ENodeXTaskSinkType type;
3741
  CowStr             cstr;
3742
} xTaskSink;
3743
/**
3744
 * @brief Deallocate a xTaskSink object.
3745
 *
3746
 * @param sink ptr
3747
 */
3748
void xFreeTaskSink(xTaskSink* sink);
3749
/**
3750
 * @brief Create a xTaskSink object with cloned name string.
3751
 *
3752
 * @param sinkType: sink type.
3753
 * @param len: length of sink string.
3754
 * @param ptr: sink string ptr.
3755
 * @return xTaskSink object
3756
 */
3757
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3758
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3759
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3760
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3761
const char* xGetTaskSinkStr(xTaskSink* sink);
3762
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3763
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3764

3765
typedef struct {
3766
  int32_t via;
3767
  CowStr  parser;
3768
  // CowStr  reason;
3769
  CowStr  trigger;
3770
  CowStr  health;
3771
  int32_t optionsNum;
3772
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3773
} xTaskOptions;
3774
/**
3775
 * @brief Deallocate a xTaskOptions object.
3776
 *
3777
 * @param options ptr
3778
 */
3779
void    xFreeTaskOptions(xTaskOptions* options);
3780
void    printXnodeTaskOptions(xTaskOptions* options);
3781
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3782
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3783

3784
typedef struct {
3785
  int32_t sqlLen;
3786
  char*   sql;
3787
  int32_t      xnodeId;
3788
  CowStr       name;
3789
  xTaskSource  source;
3790
  xTaskSink    sink;
3791
  xTaskOptions options;
3792
} SMCreateXnodeTaskReq;
3793
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3794
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3795
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3796

3797
typedef struct {
3798
  int32_t     tid;
3799
  CowStr      name;
3800
  int32_t     via;
3801
  int32_t     xnodeId;
3802
  CowStr      status;
3803
  xTaskSource source;
3804
  xTaskSink   sink;
3805
  CowStr      parser;
3806
  CowStr      reason;
3807
  CowStr      updateName;
3808
  CowStr      labels;
3809
  int32_t     sqlLen;
3810
  char*       sql;
3811
} SMUpdateXnodeTaskReq;
3812
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3813
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3814
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3815

3816
typedef struct {
3817
  int32_t id;
3818
  bool    force;
3819
  CowStr  name;
3820
  int32_t sqlLen;
3821
  char*   sql;
3822
} SMDropXnodeTaskReq;
3823
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3824
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3825
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3826

3827
typedef struct {
3828
  int32_t tid;
3829
  CowStr  name;
3830
  int32_t sqlLen;
3831
  char*   sql;
3832
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3833
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3834
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3835
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3836

3837
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3838
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3839
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3840

3841
typedef struct {
3842
  int32_t tid;
3843
  int32_t via;
3844
  int32_t xnodeId;
3845
  CowStr  status;
3846
  CowStr  config;
3847
  CowStr  reason;
3848
  int32_t sqlLen;
3849
  char*   sql;
3850
} SMCreateXnodeJobReq;
3851
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3852
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3853
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3854

3855
typedef struct {
3856
  int32_t jid;
3857
  int32_t via;
3858
  int32_t xnodeId;
3859
  CowStr  status;
3860
  int32_t configLen;
3861
  int32_t reasonLen;
3862
  int32_t sqlLen;
3863
  char*   config;
3864
  char*   reason;
3865
  char*   sql;
3866
} SMUpdateXnodeJobReq;
3867
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3868
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3869
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3870

3871
typedef struct {
3872
  int32_t jid;
3873
  int32_t xnodeId;
3874
  int32_t sqlLen;
3875
  char*   sql;
3876
} SMRebalanceXnodeJobReq;
3877
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3878
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3879
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3880

3881
typedef struct {
3882
  CowStr  ast;
3883
  int32_t sqlLen;
3884
  char*   sql;
3885
} SMRebalanceXnodeJobsWhereReq;
3886
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3887
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3888
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3889

3890
typedef struct {
3891
  int32_t jid;
3892
  int32_t tid;
3893
  int32_t sqlLen;
3894
  char*   sql;
3895
} SMDropXnodeJobReq;
3896
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3897
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3898
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3899

3900
typedef struct {
3901
  int32_t      sqlLen;
3902
  char*        sql;
3903
  CowStr       name;
3904
  CowStr       status;
3905
  xTaskOptions options;
3906
} SMCreateXnodeAgentReq;
3907
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3908
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3909
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
3910

3911
typedef struct {
3912
  int32_t      sqlLen;
3913
  char*        sql;
3914
  int32_t      id;
3915
  CowStr       name;
3916
  xTaskOptions options;
3917
} SMUpdateXnodeAgentReq;
3918
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3919
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3920
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
3921

3922
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
3923
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
3924
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
3925
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
3926

3927
typedef struct {
3928
  int32_t vgId;
3929
  int32_t hbSeq;
3930
} SVArbHbReqMember;
3931

3932
typedef struct {
3933
  int32_t dnodeId;
3934
  char*   arbToken;
3935
  int64_t arbTerm;
3936
  SArray* hbMembers;  // SVArbHbReqMember
3937
} SVArbHeartBeatReq;
3938

3939
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3940
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3941
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3942

3943
typedef struct {
3944
  int32_t vgId;
3945
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3946
  int32_t hbSeq;
3947
} SVArbHbRspMember;
3948

3949
typedef struct {
3950
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3951
  int32_t dnodeId;
3952
  SArray* hbMembers;  // SVArbHbRspMember
3953
} SVArbHeartBeatRsp;
3954

3955
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3956
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3957
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3958

3959
typedef struct {
3960
  char*   arbToken;
3961
  int64_t arbTerm;
3962
  char*   member0Token;
3963
  char*   member1Token;
3964
} SVArbCheckSyncReq;
3965

3966
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3967
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3968
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3969

3970
typedef struct {
3971
  char*   arbToken;
3972
  char*   member0Token;
3973
  char*   member1Token;
3974
  int32_t vgId;
3975
  int32_t errCode;
3976
} SVArbCheckSyncRsp;
3977

3978
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3979
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3980
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3981

3982
typedef struct {
3983
  char*   arbToken;
3984
  int64_t arbTerm;
3985
  char*   memberToken;
3986
  int8_t  force;
3987
} SVArbSetAssignedLeaderReq;
3988

3989
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3990
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3991
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3992

3993
typedef struct {
3994
  char*   arbToken;
3995
  char*   memberToken;
3996
  int32_t vgId;
3997
} SVArbSetAssignedLeaderRsp;
3998

3999
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4000
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4001
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4002

4003
typedef struct {
4004
  int32_t dnodeId;
4005
  char*   token;
4006
} SMArbUpdateGroupMember;
4007

4008
typedef struct {
4009
  int32_t dnodeId;
4010
  char*   token;
4011
  int8_t  acked;
4012
} SMArbUpdateGroupAssigned;
4013

4014
typedef struct {
4015
  int32_t                  vgId;
4016
  int64_t                  dbUid;
4017
  SMArbUpdateGroupMember   members[2];
4018
  int8_t                   isSync;
4019
  int8_t                   assignedAcked;
4020
  SMArbUpdateGroupAssigned assignedLeader;
4021
  int64_t                  version;
4022
  int32_t                  code;
4023
  int64_t                  updateTimeMs;
4024
} SMArbUpdateGroup;
4025

4026
typedef struct {
4027
  SArray* updateArray;  // SMArbUpdateGroup
4028
} SMArbUpdateGroupBatchReq;
4029

4030
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4031
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4032
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4033

4034
typedef struct {
4035
  char queryStrId[TSDB_QUERY_ID_LEN];
4036
} SKillQueryReq;
4037

4038
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4039
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4040

4041
typedef struct {
4042
  uint32_t connId;
4043
} SKillConnReq;
4044

4045
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4046
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4047

4048
typedef struct {
4049
  int32_t transId;
4050
} SKillTransReq;
4051

4052
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4053
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4054

4055
typedef struct {
4056
  int32_t useless;  // useless
4057
  int32_t sqlLen;
4058
  char*   sql;
4059
} SBalanceVgroupReq;
4060

4061
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4062
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4063
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4064

4065
typedef struct {
4066
  int32_t useless;  // useless
4067
  int32_t sqlLen;
4068
  char*   sql;
4069
} SAssignLeaderReq;
4070

4071
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4072
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4073
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4074
typedef struct {
4075
  int32_t vgId1;
4076
  int32_t vgId2;
4077
} SMergeVgroupReq;
4078

4079
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4080
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4081

4082
typedef struct {
4083
  int32_t vgId;
4084
  int32_t dnodeId1;
4085
  int32_t dnodeId2;
4086
  int32_t dnodeId3;
4087
  int32_t sqlLen;
4088
  char*   sql;
4089
} SRedistributeVgroupReq;
4090

4091
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4092
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4093
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4094

4095
typedef struct {
4096
  int32_t reserved;
4097
  int32_t vgId;
4098
  int32_t sqlLen;
4099
  char*   sql;
4100
  char    db[TSDB_DB_FNAME_LEN];
4101
} SBalanceVgroupLeaderReq;
4102

4103
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4104
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4105
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4106

4107
typedef struct {
4108
  int32_t vgId;
4109
} SForceBecomeFollowerReq;
4110

4111
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4112
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4113

4114
typedef struct {
4115
  int32_t vgId;
4116
  bool    force;
4117
} SSplitVgroupReq;
4118

4119
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4120
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4121

4122
typedef struct {
4123
  char user[TSDB_USER_LEN];
4124
  char spi;
4125
  char encrypt;
4126
  char secret[TSDB_PASSWORD_LEN];
4127
  char ckey[TSDB_PASSWORD_LEN];
4128
} SAuthReq, SAuthRsp;
4129

4130
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4131
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4132

4133
typedef struct {
4134
  int32_t statusCode;
4135
  char    details[1024];
4136
} SServerStatusRsp;
4137

4138
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4139
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4140

4141
/**
4142
 * The layout of the query message payload is as following:
4143
 * +--------------------+---------------------------------+
4144
 * |Sql statement       | Physical plan                   |
4145
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4146
 * +--------------------+---------------------------------+
4147
 */
4148
typedef struct SSubQueryMsg {
4149
  SMsgHead header;
4150
  uint64_t sId;
4151
  uint64_t queryId;
4152
  uint64_t clientId;
4153
  uint64_t taskId;
4154
  int64_t  refId;
4155
  int32_t  execId;
4156
  int32_t  msgMask;
4157
  int8_t   taskType;
4158
  int8_t   explain;
4159
  int8_t   needFetch;
4160
  int8_t   compress;
4161
  uint32_t sqlLen;
4162
  char*    sql;
4163
  uint32_t msgLen;
4164
  char*    msg;
4165
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4166
} SSubQueryMsg;
4167

4168
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4169
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4170
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4171

4172
typedef struct {
4173
  SMsgHead header;
4174
  uint64_t sId;
4175
  uint64_t queryId;
4176
  uint64_t taskId;
4177
} SSinkDataReq;
4178

4179
typedef struct {
4180
  SMsgHead header;
4181
  uint64_t sId;
4182
  uint64_t queryId;
4183
  uint64_t clientId;
4184
  uint64_t taskId;
4185
  int32_t  execId;
4186
} SQueryContinueReq;
4187

4188
typedef struct {
4189
  SMsgHead header;
4190
  uint64_t sId;
4191
  uint64_t queryId;
4192
  uint64_t taskId;
4193
} SResReadyReq;
4194

4195
typedef struct {
4196
  int32_t code;
4197
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4198
  int32_t sversion;
4199
  int32_t tversion;
4200
} SResReadyRsp;
4201

4202
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4203

4204
typedef struct SOperatorParam {
4205
  int32_t opType;
4206
  int32_t downstreamIdx;
4207
  void*   value;
4208
  SArray* pChildren;  // SArray<SOperatorParam*>
4209
  bool    reUse;
4210
} SOperatorParam;
4211

4212
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4213

4214
typedef struct SColIdNameKV {
4215
  col_id_t colId;
4216
  char     colName[TSDB_COL_NAME_LEN];
4217
} SColIdNameKV;
4218

4219
#define COL_MASK_ON   ((int8_t)0x1)
4220
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4221
#define COL_SET_MASK_ON(c)     \
4222
  do {                         \
4223
    (c)->flags |= COL_MASK_ON; \
4224
  } while (0)
4225

4226
typedef struct SColNameFlag {
4227
  col_id_t colId;
4228
  char     colName[TSDB_COL_NAME_LEN];
4229
  int8_t   flags;  // 0x01: COL_MASK_ON
4230
} SColNameFlag;
4231

4232
typedef struct SColIdPair {
4233
  col_id_t  vtbColId;
4234
  col_id_t  orgColId;
4235
  SDataType type;
4236
} SColIdPair;
4237

4238
typedef struct SColIdSlotIdPair {
4239
  int32_t  vtbSlotId;
4240
  col_id_t orgColId;
4241
} SColIdSlotIdPair;
4242

4243
typedef struct SOrgTbInfo {
4244
  int32_t vgId;
4245
  char    tbName[TSDB_TABLE_FNAME_LEN];
4246
  SArray* colMap;  // SArray<SColIdNameKV>
4247
} SOrgTbInfo;
4248

4249
void destroySOrgTbInfo(void *info);
4250

4251
typedef enum {
4252
  DYN_TYPE_STB_JOIN = 1,
4253
  DYN_TYPE_VSTB_SINGLE_SCAN,
4254
  DYN_TYPE_VSTB_BATCH_SCAN,
4255
  DYN_TYPE_VSTB_WIN_SCAN,
4256
} ETableScanDynType;
4257

4258
typedef enum {
4259
  DYN_TYPE_SCAN_PARAM = 1,
4260
  NOTIFY_TYPE_SCAN_PARAM,
4261
} ETableScanGetParamType;
4262

4263
typedef struct STableScanOperatorParam {
4264
  ETableScanGetParamType paramType;
4265
  /* for building scan data source */
4266
  bool                   tableSeq;
4267
  bool                   isNewParam;
4268
  uint64_t               groupid;
4269
  SArray*                pUidList;
4270
  SOrgTbInfo*            pOrgTbInfo;
4271
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4272
  SArray*                pTagList;
4273
  STimeWindow            window;
4274
  ETableScanDynType      dynType;
4275
  /* for notifying source step done */
4276
  bool                   notifyToProcess;  // received notify STEP DONE message
4277
  TSKEY                  notifyTs;         // notify timestamp
4278
} STableScanOperatorParam;
4279

4280
typedef struct STagScanOperatorParam {
4281
  tb_uid_t vcUid;
4282
} STagScanOperatorParam;
4283

4284
typedef struct SVTableScanOperatorParam {
4285
  uint64_t        uid;
4286
  STimeWindow     window;
4287
  SOperatorParam* pTagScanOp;
4288
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4289
} SVTableScanOperatorParam;
4290

4291
typedef struct SMergeOperatorParam {
4292
  int32_t         winNum;
4293
} SMergeOperatorParam;
4294

4295
typedef struct SAggOperatorParam {
4296
  bool            needCleanRes;
4297
} SAggOperatorParam;
4298

4299
typedef struct SExternalWindowOperatorParam {
4300
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4301
} SExternalWindowOperatorParam;
4302

4303
typedef struct SDynQueryCtrlOperatorParam {
4304
  STimeWindow    window;
4305
} SDynQueryCtrlOperatorParam;
4306

4307
struct SStreamRuntimeFuncInfo;
4308
typedef struct {
4309
  SMsgHead        header;
4310
  uint64_t        sId;
4311
  uint64_t        queryId;
4312
  uint64_t        clientId;
4313
  uint64_t        taskId;
4314
  int32_t         execId;
4315
  SOperatorParam* pOpParam;
4316

4317
  // used for new-stream
4318
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4319
  bool                           reset;
4320
  bool                           dynTbname;
4321
  // used for new-stream
4322
} SResFetchReq;
4323

4324
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4325
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4326
void    tDestroySResFetchReq(SResFetchReq* pReq);
4327
typedef struct {
4328
  SMsgHead header;
4329
  uint64_t clientId;
4330
} SSchTasksStatusReq;
4331

4332
typedef struct {
4333
  uint64_t queryId;
4334
  uint64_t clientId;
4335
  uint64_t taskId;
4336
  int64_t  refId;
4337
  int32_t  subJobId;
4338
  int32_t  execId;
4339
  int8_t   status;
4340
} STaskStatus;
4341

4342
typedef struct {
4343
  int64_t refId;
4344
  SArray* taskStatus;  // SArray<STaskStatus>
4345
} SSchedulerStatusRsp;
4346

4347
typedef struct {
4348
  uint64_t queryId;
4349
  uint64_t taskId;
4350
  int8_t   action;
4351
} STaskAction;
4352

4353
typedef struct SQueryNodeEpId {
4354
  int32_t nodeId;  // vgId or qnodeId
4355
  SEp     ep;
4356
} SQueryNodeEpId;
4357

4358
typedef struct {
4359
  SMsgHead       header;
4360
  uint64_t       clientId;
4361
  SQueryNodeEpId epId;
4362
  SArray*        taskAction;  // SArray<STaskAction>
4363
} SSchedulerHbReq;
4364

4365
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4366
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4367
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4368

4369
typedef struct {
4370
  SQueryNodeEpId epId;
4371
  SArray*        taskStatus;  // SArray<STaskStatus>
4372
} SSchedulerHbRsp;
4373

4374
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4375
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4376
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4377

4378
typedef struct {
4379
  SMsgHead header;
4380
  uint64_t sId;
4381
  uint64_t queryId;
4382
  uint64_t clientId;
4383
  uint64_t taskId;
4384
  int64_t  refId;
4385
  int32_t  execId;
4386
} STaskCancelReq;
4387

4388
typedef struct {
4389
  int32_t code;
4390
} STaskCancelRsp;
4391

4392
typedef struct {
4393
  SMsgHead header;
4394
  uint64_t sId;
4395
  uint64_t queryId;
4396
  uint64_t clientId;
4397
  uint64_t taskId;
4398
  int64_t  refId;
4399
  int32_t  execId;
4400
} STaskDropReq;
4401

4402
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4403
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4404

4405
typedef enum {
4406
  TASK_NOTIFY_FINISHED = 1,
4407
} ETaskNotifyType;
4408

4409
typedef struct {
4410
  SMsgHead        header;
4411
  uint64_t        sId;
4412
  uint64_t        queryId;
4413
  uint64_t        clientId;
4414
  uint64_t        taskId;
4415
  int64_t         refId;
4416
  int32_t         execId;
4417
  ETaskNotifyType type;
4418
} STaskNotifyReq;
4419

4420
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4421
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4422

4423
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4424
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4425

4426
typedef struct {
4427
  int32_t code;
4428
} STaskDropRsp;
4429

4430
#define STREAM_TRIGGER_AT_ONCE                 1
4431
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4432
#define STREAM_TRIGGER_MAX_DELAY               3
4433
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4434
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4435

4436
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4437
#define STREAM_FILL_HISTORY_ON        1
4438
#define STREAM_FILL_HISTORY_OFF       0
4439
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4440
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4441
#define STREAM_CREATE_STABLE_TRUE     1
4442
#define STREAM_CREATE_STABLE_FALSE    0
4443

4444
typedef struct SVgroupVer {
4445
  int32_t vgId;
4446
  int64_t ver;
4447
} SVgroupVer;
4448

4449
typedef struct STaskNotifyEventStat {
4450
  int64_t notifyEventAddTimes;     // call times of add function
4451
  int64_t notifyEventAddElems;     // elements added by add function
4452
  double  notifyEventAddCostSec;   // time cost of add function
4453
  int64_t notifyEventPushTimes;    // call times of push function
4454
  int64_t notifyEventPushElems;    // elements pushed by push function
4455
  double  notifyEventPushCostSec;  // time cost of push function
4456
  int64_t notifyEventPackTimes;    // call times of pack function
4457
  int64_t notifyEventPackElems;    // elements packed by pack function
4458
  double  notifyEventPackCostSec;  // time cost of pack function
4459
  int64_t notifyEventSendTimes;    // call times of send function
4460
  int64_t notifyEventSendElems;    // elements sent by send function
4461
  double  notifyEventSendCostSec;  // time cost of send function
4462
  int64_t notifyEventHoldElems;    // elements hold due to watermark
4463
} STaskNotifyEventStat;
4464

4465
enum {
4466
  TOPIC_SUB_TYPE__DB = 1,
4467
  TOPIC_SUB_TYPE__TABLE,
4468
  TOPIC_SUB_TYPE__COLUMN,
4469
};
4470

4471
#define DEFAULT_MAX_POLL_INTERVAL  300000
4472
#define DEFAULT_SESSION_TIMEOUT    12000
4473
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4474
#define DEFAULT_MIN_POLL_ROWS      4096
4475

4476
typedef struct {
4477
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4478
  int8_t igExists;
4479
  int8_t subType;
4480
  int8_t withMeta;
4481
  char*  sql;
4482
  char   subDbName[TSDB_DB_FNAME_LEN];
4483
  char*  ast;
4484
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4485
  int8_t reload;
4486
} SCMCreateTopicReq;
4487

4488
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4489
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4490
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4491

4492
typedef struct {
4493
  int64_t consumerId;
4494
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4495

4496
typedef struct {
4497
  int64_t consumerId;
4498
  char    cgroup[TSDB_CGROUP_LEN];
4499
  char    clientId[TSDB_CLIENT_ID_LEN];
4500
  char    user[TSDB_USER_LEN];
4501
  char    fqdn[TSDB_FQDN_LEN];
4502
  SArray* topicNames;  // SArray<char**>
4503

4504
  int8_t  withTbName;
4505
  int8_t  autoCommit;
4506
  int32_t autoCommitInterval;
4507
  int8_t  resetOffsetCfg;
4508
  int8_t  enableReplay;
4509
  int8_t  enableBatchMeta;
4510
  int32_t sessionTimeoutMs;
4511
  int32_t maxPollIntervalMs;
4512
} SCMSubscribeReq;
4513

4514
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4515
  int32_t tlen = 0;
673,326✔
4516
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
673,326✔
4517
  tlen += taosEncodeString(buf, pReq->cgroup);
673,326✔
4518
  tlen += taosEncodeString(buf, pReq->clientId);
673,326✔
4519

4520
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
673,326✔
4521
  tlen += taosEncodeFixedI32(buf, topicNum);
673,326✔
4522

4523
  for (int32_t i = 0; i < topicNum; i++) {
938,278✔
4524
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
529,904✔
4525
  }
4526

4527
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
673,326✔
4528
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
673,326✔
4529
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
673,326✔
4530
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
673,326✔
4531
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
673,326✔
4532
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
673,326✔
4533
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
673,326✔
4534
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
673,326✔
4535
  tlen += taosEncodeString(buf, pReq->user);
673,326✔
4536
  tlen += taosEncodeString(buf, pReq->fqdn);
673,326✔
4537

4538
  return tlen;
673,326✔
4539
}
4540

4541
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4542
  void* start = buf;
356,563✔
4543
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
356,563✔
4544
  buf = taosDecodeStringTo(buf, pReq->cgroup);
356,563✔
4545
  buf = taosDecodeStringTo(buf, pReq->clientId);
356,563✔
4546

4547
  int32_t topicNum = 0;
356,563✔
4548
  buf = taosDecodeFixedI32(buf, &topicNum);
356,563✔
4549

4550
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
356,563✔
4551
  if (pReq->topicNames == NULL) {
356,563✔
4552
    return terrno;
×
4553
  }
4554
  for (int32_t i = 0; i < topicNum; i++) {
517,836✔
4555
    char* name = NULL;
161,273✔
4556
    buf = taosDecodeString(buf, &name);
161,273✔
4557
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
322,546✔
4558
      return terrno;
×
4559
    }
4560
  }
4561

4562
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
356,563✔
4563
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
356,563✔
4564
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
356,563✔
4565
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
356,563✔
4566
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
356,563✔
4567
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
356,563✔
4568
  if ((char*)buf - (char*)start < len) {
356,563✔
4569
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
356,563✔
4570
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
356,563✔
4571
    buf = taosDecodeStringTo(buf, pReq->user);
356,563✔
4572
    buf = taosDecodeStringTo(buf, pReq->fqdn);
713,126✔
4573
  } else {
4574
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
4575
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4576
  }
4577

4578
  return 0;
356,563✔
4579
}
4580

4581
typedef struct {
4582
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4583
  SArray* removedConsumers;  // SArray<int64_t>
4584
  SArray* newConsumers;      // SArray<int64_t>
4585
} SMqRebInfo;
4586

4587
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4588
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
342,138✔
4589
  if (pRebInfo == NULL) {
342,138✔
4590
    return NULL;
×
4591
  }
4592
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
342,138✔
4593
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
342,138✔
4594
  if (pRebInfo->removedConsumers == NULL) {
342,138✔
4595
    goto _err;
×
4596
  }
4597
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
342,138✔
4598
  if (pRebInfo->newConsumers == NULL) {
342,138✔
4599
    goto _err;
×
4600
  }
4601
  return pRebInfo;
342,138✔
4602
_err:
×
4603
  taosArrayDestroy(pRebInfo->removedConsumers);
×
4604
  taosArrayDestroy(pRebInfo->newConsumers);
×
4605
  taosMemoryFreeClear(pRebInfo);
×
4606
  return NULL;
×
4607
}
4608

4609
typedef struct {
4610
  int64_t streamId;
4611
  int64_t checkpointId;
4612
  char    streamName[TSDB_STREAM_FNAME_LEN];
4613
} SMStreamDoCheckpointMsg;
4614

4615
typedef struct {
4616
  int64_t status;
4617
} SMVSubscribeRsp;
4618

4619
typedef struct {
4620
  char    name[TSDB_TOPIC_FNAME_LEN];
4621
  int8_t  igNotExists;
4622
  int32_t sqlLen;
4623
  char*   sql;
4624
  int8_t  force;
4625
} SMDropTopicReq;
4626

4627
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4628
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4629
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4630

4631
typedef struct {
4632
  char    name[TSDB_TOPIC_FNAME_LEN];
4633
  int8_t  igNotExists;
4634
  int32_t sqlLen;
4635
  char*   sql;
4636
} SMReloadTopicReq;
4637

4638
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4639
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4640
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4641

4642
typedef struct {
4643
  char   topic[TSDB_TOPIC_FNAME_LEN];
4644
  char   cgroup[TSDB_CGROUP_LEN];
4645
  int8_t igNotExists;
4646
  int8_t force;
4647
} SMDropCgroupReq;
4648

4649
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4650
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4651

4652
typedef struct {
4653
  int8_t reserved;
4654
} SMDropCgroupRsp;
4655

4656
typedef struct {
4657
  char    name[TSDB_TABLE_FNAME_LEN];
4658
  int8_t  alterType;
4659
  SSchema schema;
4660
} SAlterTopicReq;
4661

4662
typedef struct {
4663
  SMsgHead head;
4664
  char     name[TSDB_TABLE_FNAME_LEN];
4665
  int64_t  tuid;
4666
  int32_t  sverson;
4667
  int32_t  execLen;
4668
  char*    executor;
4669
  int32_t  sqlLen;
4670
  char*    sql;
4671
} SDCreateTopicReq;
4672

4673
typedef struct {
4674
  SMsgHead head;
4675
  char     name[TSDB_TABLE_FNAME_LEN];
4676
  int64_t  tuid;
4677
} SDDropTopicReq;
4678

4679
typedef struct {
4680
  char*      name;
4681
  int64_t    uid;
4682
  int64_t    interval[2];
4683
  int8_t     intervalUnit;
4684
  int16_t    nFuncs;
4685
  col_id_t*  funcColIds;  // column ids specified by user
4686
  func_id_t* funcIds;     // function ids specified by user
4687
} SRSmaParam;
4688

4689
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4690
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4691

4692
// TDMT_VND_CREATE_STB ==============
4693
typedef struct SVCreateStbReq {
4694
  char*           name;
4695
  tb_uid_t        suid;
4696
  int8_t          rollup;
4697
  SSchemaWrapper  schemaRow;
4698
  SSchemaWrapper  schemaTag;
4699
  SRSmaParam      rsmaParam;
4700
  int32_t         alterOriDataLen;
4701
  void*           alterOriData;
4702
  int8_t          source;
4703
  int8_t          colCmpred;
4704
  SColCmprWrapper colCmpr;
4705
  int64_t         keep;
4706
  int64_t         ownerId;
4707
  SExtSchema*     pExtSchemas;
4708
  int8_t          virtualStb;
4709
} SVCreateStbReq;
4710

4711
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4712
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4713

4714
// TDMT_VND_DROP_STB ==============
4715
typedef struct SVDropStbReq {
4716
  char*    name;
4717
  tb_uid_t suid;
4718
} SVDropStbReq;
4719

4720
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4721
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4722

4723
// TDMT_VND_CREATE_TABLE ==============
4724
#define TD_CREATE_IF_NOT_EXISTS       0x1
4725
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4726
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4727
typedef struct SVCreateTbReq {
4728
  int32_t  flags;
4729
  char*    name;
4730
  tb_uid_t uid;
4731
  int64_t  btime;
4732
  int32_t  ttl;
4733
  int32_t  commentLen;
4734
  char*    comment;
4735
  int8_t   type;
4736
  union {
4737
    struct {
4738
      char*    stbName;  // super table name
4739
      uint8_t  tagNum;
4740
      tb_uid_t suid;
4741
      SArray*  tagName;
4742
      uint8_t* pTag;
4743
    } ctb;
4744
    struct {
4745
      SSchemaWrapper schemaRow;
4746
    } ntb;
4747
  };
4748
  int32_t         sqlLen;
4749
  char*           sql;
4750
  SColCmprWrapper colCmpr;
4751
  SExtSchema*     pExtSchemas;
4752
  SColRefWrapper  colRef;  // col reference for virtual table
4753
} SVCreateTbReq;
4754

4755
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4756
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4757
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4758
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4759

4760
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4761
  if (NULL == req) {
2,147,483,647✔
4762
    return;
2,147,483,647✔
4763
  }
4764

4765
  taosMemoryFreeClear(req->sql);
60,693,837✔
4766
  taosMemoryFreeClear(req->name);
60,694,304✔
4767
  taosMemoryFreeClear(req->comment);
60,705,279✔
4768
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
60,673,384✔
4769
    taosMemoryFreeClear(req->ctb.pTag);
55,195,840✔
4770
    taosMemoryFreeClear(req->ctb.stbName);
55,172,977✔
4771
    taosArrayDestroy(req->ctb.tagName);
55,177,382✔
4772
    req->ctb.tagName = NULL;
55,167,071✔
4773
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
5,510,615✔
4774
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
5,510,615✔
4775
  }
4776
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
60,689,753✔
4777
  taosMemoryFreeClear(req->pExtSchemas);
60,706,736✔
4778
  taosMemoryFreeClear(req->colRef.pColRef);
60,688,288✔
4779
}
4780

4781
typedef struct {
4782
  int32_t nReqs;
4783
  union {
4784
    SVCreateTbReq* pReqs;
4785
    SArray*        pArray;
4786
  };
4787
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4788
} SVCreateTbBatchReq;
4789

4790
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4791
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4792
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4793

4794
typedef struct {
4795
  int32_t        code;
4796
  STableMetaRsp* pMeta;
4797
} SVCreateTbRsp, SVUpdateTbRsp;
4798

4799
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4800
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4801
void tFreeSVCreateTbRsp(void* param);
4802

4803
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4804
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4805

4806
typedef struct {
4807
  int32_t nRsps;
4808
  union {
4809
    SVCreateTbRsp* pRsps;
4810
    SArray*        pArray;
4811
  };
4812
} SVCreateTbBatchRsp;
4813

4814
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4815
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4816

4817
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4818
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4819

4820
// TDMT_VND_DROP_TABLE =================
4821
typedef struct {
4822
  char*    name;
4823
  uint64_t suid;  // for tmq in wal format
4824
  int64_t  uid;
4825
  int8_t   igNotExists;
4826
  int8_t   isVirtual;
4827
} SVDropTbReq;
4828

4829
typedef struct {
4830
  int32_t code;
4831
} SVDropTbRsp;
4832

4833
typedef struct {
4834
  int32_t nReqs;
4835
  union {
4836
    SVDropTbReq* pReqs;
4837
    SArray*      pArray;
4838
  };
4839
} SVDropTbBatchReq;
4840

4841
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4842
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4843

4844
typedef struct {
4845
  int32_t nRsps;
4846
  union {
4847
    SVDropTbRsp* pRsps;
4848
    SArray*      pArray;
4849
  };
4850
} SVDropTbBatchRsp;
4851

4852
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4853
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4854

4855
// TDMT_VND_ALTER_TABLE =====================
4856
typedef struct SMultiTagUpateVal {
4857
  char*    tagName;
4858
  int32_t  colId;
4859
  int8_t   tagType;
4860
  int8_t   tagFree;
4861
  uint32_t nTagVal;
4862
  uint8_t* pTagVal;
4863
  int8_t   isNull;
4864
  SArray*  pTagArray;
4865
} SMultiTagUpateVal;
4866
typedef struct SVAlterTbReq {
4867
  char*   tbName;
4868
  int8_t  action;
4869
  char*   colName;
4870
  int32_t colId;
4871
  // TSDB_ALTER_TABLE_ADD_COLUMN
4872
  int8_t  type;
4873
  int8_t  flags;
4874
  int32_t bytes;
4875
  // TSDB_ALTER_TABLE_DROP_COLUMN
4876
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4877
  int8_t   colModType;
4878
  int32_t  colModBytes;
4879
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4880
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4881
  int8_t   isNull;
4882
  int8_t   tagType;
4883
  int8_t   tagFree;
4884
  uint32_t nTagVal;
4885
  uint8_t* pTagVal;
4886
  SArray*  pTagArray;
4887
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4888
  int8_t   updateTTL;
4889
  int32_t  newTTL;
4890
  int32_t  newCommentLen;
4891
  char*    newComment;
4892
  int64_t  ctimeMs;    // fill by vnode
4893
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4894
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4895
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4896
  // for Add column
4897
  STypeMod typeMod;
4898
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4899
  char* refDbName;
4900
  char* refTbName;
4901
  char* refColName;
4902
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4903
} SVAlterTbReq;
4904

4905
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4906
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4907
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4908
void    tfreeMultiTagUpateVal(void* pMultiTag);
4909

4910
typedef struct {
4911
  int32_t        code;
4912
  STableMetaRsp* pMeta;
4913
} SVAlterTbRsp;
4914

4915
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4916
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4917
// ======================
4918

4919
typedef struct {
4920
  SMsgHead head;
4921
  int64_t  uid;
4922
  int32_t  tid;
4923
  int16_t  tversion;
4924
  int16_t  colId;
4925
  int8_t   type;
4926
  int16_t  bytes;
4927
  int32_t  tagValLen;
4928
  int16_t  numOfTags;
4929
  int32_t  schemaLen;
4930
  char     data[];
4931
} SUpdateTagValReq;
4932

4933
typedef struct {
4934
  SMsgHead head;
4935
} SUpdateTagValRsp;
4936

4937
typedef struct {
4938
  SMsgHead head;
4939
} SVShowTablesReq;
4940

4941
typedef struct {
4942
  SMsgHead head;
4943
  int32_t  id;
4944
} SVShowTablesFetchReq;
4945

4946
typedef struct {
4947
  int64_t useconds;
4948
  int8_t  completed;  // all results are returned to client
4949
  int8_t  precision;
4950
  int8_t  compressed;
4951
  int32_t compLen;
4952
  int32_t numOfRows;
4953
  char    data[];
4954
} SVShowTablesFetchRsp;
4955

4956
typedef struct {
4957
  int64_t consumerId;
4958
  int32_t epoch;
4959
  char    cgroup[TSDB_CGROUP_LEN];
4960
} SMqAskEpReq;
4961

4962
typedef struct {
4963
  int32_t key;
4964
  int32_t valueLen;
4965
  void*   value;
4966
} SKv;
4967

4968
typedef struct {
4969
  int64_t tscRid;
4970
  int8_t  connType;
4971
} SClientHbKey;
4972

4973
typedef struct {
4974
  int64_t tid;
4975
  char    status[TSDB_JOB_STATUS_LEN];
4976
} SQuerySubDesc;
4977

4978
typedef struct {
4979
  char     sql[TSDB_SHOW_SQL_LEN];
4980
  uint64_t queryId;
4981
  int64_t  useconds;
4982
  int64_t  stime;  // timestamp precision ms
4983
  int64_t  reqRid;
4984
  bool     stableQuery;
4985
  bool     isSubQuery;
4986
  char     fqdn[TSDB_FQDN_LEN];
4987
  int32_t  subPlanNum;
4988
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4989
} SQueryDesc;
4990

4991
typedef struct {
4992
  uint32_t connId;
4993
  SArray*  queryDesc;  // SArray<SQueryDesc>
4994
} SQueryHbReqBasic;
4995

4996
typedef struct {
4997
  uint32_t connId;
4998
  uint64_t killRid;
4999
  int32_t  totalDnodes;
5000
  int32_t  onlineDnodes;
5001
  int8_t   killConnection;
5002
  int8_t   align[3];
5003
  SEpSet   epSet;
5004
  SArray*  pQnodeList;
5005
} SQueryHbRspBasic;
5006

5007
typedef struct SAppClusterSummary {
5008
  uint64_t numOfInsertsReq;
5009
  uint64_t numOfInsertRows;
5010
  uint64_t insertElapsedTime;
5011
  uint64_t insertBytes;  // submit to tsdb since launched.
5012

5013
  uint64_t fetchBytes;
5014
  uint64_t numOfQueryReq;
5015
  uint64_t queryElapsedTime;
5016
  uint64_t numOfSlowQueries;
5017
  uint64_t totalRequests;
5018
  uint64_t currentRequests;  // the number of SRequestObj
5019
} SAppClusterSummary;
5020

5021
typedef struct {
5022
  int64_t            appId;
5023
  int32_t            pid;
5024
  char               name[TSDB_APP_NAME_LEN];
5025
  int64_t            startTime;
5026
  SAppClusterSummary summary;
5027
} SAppHbReq;
5028

5029
typedef struct {
5030
  SClientHbKey      connKey;
5031
  int64_t           clusterId;
5032
  SAppHbReq         app;
5033
  SQueryHbReqBasic* query;
5034
  SHashObj*         info;  // hash<Skv.key, Skv>
5035
  char              user[TSDB_USER_LEN];
5036
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5037
  char              userApp[TSDB_APP_NAME_LEN];
5038
  uint32_t          userIp;
5039
  SIpRange          userDualIp;
5040
  char              sVer[TSDB_VERSION_LEN];
5041
  char              cInfo[CONNECTOR_INFO_LEN];
5042
} SClientHbReq;
5043

5044
typedef struct {
5045
  int64_t reqId;
5046
  SArray* reqs;  // SArray<SClientHbReq>
5047
  int64_t ipWhiteListVer;
5048
} SClientHbBatchReq;
5049

5050
typedef struct {
5051
  SClientHbKey      connKey;
5052
  int32_t           status;
5053
  SQueryHbRspBasic* query;
5054
  SArray*           info;  // Array<Skv>
5055
} SClientHbRsp;
5056

5057
typedef struct {
5058
  int64_t       reqId;
5059
  int64_t       rspId;
5060
  int32_t       svrTimestamp;
5061
  SArray*       rsps;  // SArray<SClientHbRsp>
5062
  SMonitorParas monitorParas;
5063
  int8_t        enableAuditDelete;
5064
  int8_t        enableStrongPass;
5065
  int8_t        enableAuditSelect;
5066
  int8_t        enableAuditInsert;
5067
  int8_t        auditLevel;
5068
} SClientHbBatchRsp;
5069

5070
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
73,315,946✔
5071

5072
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5073
  void* pIter = taosHashIterate(info, NULL);
51,559,440✔
5074
  while (pIter != NULL) {
120,387,801✔
5075
    SKv* kv = (SKv*)pIter;
68,825,090✔
5076
    taosMemoryFreeClear(kv->value);
68,825,090✔
5077
    pIter = taosHashIterate(info, pIter);
68,824,788✔
5078
  }
5079
}
51,562,711✔
5080

5081
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
33,652,135✔
5082
  SQueryDesc* desc = (SQueryDesc*)pDesc;
33,652,135✔
5083
  if (desc->subDesc) {
33,652,135✔
5084
    taosArrayDestroy(desc->subDesc);
22,427,574✔
5085
    desc->subDesc = NULL;
22,426,458✔
5086
  }
5087
}
33,651,514✔
5088

5089
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
58,197,076✔
5090
  SClientHbReq* req = (SClientHbReq*)pReq;
60,897,036✔
5091
  if (req->query) {
60,897,036✔
5092
    if (req->query->queryDesc) {
58,195,840✔
5093
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
26,221,321✔
5094
    }
5095
    taosMemoryFreeClear(req->query);
58,196,615✔
5096
  }
5097

5098
  if (req->info) {
60,898,042✔
5099
    tFreeReqKvHash(req->info);
51,561,094✔
5100
    taosHashCleanup(req->info);
51,562,711✔
5101
    req->info = NULL;
51,560,603✔
5102
  }
5103
}
31,589,932✔
5104

5105
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5106
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5107

5108
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5109
  if (pReq == NULL) return;
24,756,249✔
5110
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
24,756,249✔
5111
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
24,756,249✔
5112
  taosMemoryFree(pReq);
24,756,249✔
5113
}
5114

5115
static FORCE_INLINE void tFreeClientKv(void* pKv) {
68,623,816✔
5116
  SKv* kv = (SKv*)pKv;
68,623,816✔
5117
  if (kv) {
68,623,816✔
5118
    taosMemoryFreeClear(kv->value);
68,624,108✔
5119
  }
5120
}
68,625,472✔
5121

5122
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
58,026,360✔
5123
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
58,026,360✔
5124
  if (rsp->query) {
58,026,360✔
5125
    taosArrayDestroy(rsp->query->pQnodeList);
58,015,583✔
5126
    taosMemoryFreeClear(rsp->query);
58,012,665✔
5127
  }
5128
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
58,032,072✔
5129
}
29,141,658✔
5130

5131
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5132
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
48,671,156✔
5133
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
48,671,156✔
5134
}
48,677,146✔
5135

5136
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5137
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5138
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5139

5140
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5141
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
410,283,179✔
5142
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
410,283,162✔
5143
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
410,279,480✔
5144
  return 0;
205,138,813✔
5145
}
5146

5147
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5148
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
134,627,325✔
5149
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
134,629,112✔
5150
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
67,314,696✔
5151
  if (pKv->value == NULL) {
67,312,875✔
5152
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5153
  }
5154
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
67,312,305✔
5155
  return 0;
67,314,279✔
5156
}
5157

5158
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5159
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
344,283,058✔
5160
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
344,272,990✔
5161
  return 0;
172,131,889✔
5162
}
5163

5164
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5165
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
113,533,870✔
5166
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
113,540,414✔
5167
  return 0;
56,771,690✔
5168
}
5169

5170
typedef struct {
5171
  int32_t vgId;
5172
  // TODO stas
5173
} SMqReportVgInfo;
5174

5175
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5176
  int32_t tlen = 0;
5177
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5178
  return tlen;
5179
}
5180

5181
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5182
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5183
  return buf;
5184
}
5185

5186
typedef struct {
5187
  int32_t epoch;
5188
  int64_t topicUid;
5189
  char    name[TSDB_TOPIC_FNAME_LEN];
5190
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5191
} SMqTopicInfo;
5192

5193
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5194
  int32_t tlen = 0;
5195
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5196
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5197
  tlen += taosEncodeString(buf, pTopicInfo->name);
5198
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5199
  tlen += taosEncodeFixedI32(buf, sz);
5200
  for (int32_t i = 0; i < sz; i++) {
5201
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5202
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5203
  }
5204
  return tlen;
5205
}
5206

5207
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5208
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5209
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5210
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5211
  int32_t sz;
5212
  buf = taosDecodeFixedI32(buf, &sz);
5213
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5214
    return NULL;
5215
  }
5216
  for (int32_t i = 0; i < sz; i++) {
5217
    SMqReportVgInfo vgInfo;
5218
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5219
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5220
      return NULL;
5221
    }
5222
  }
5223
  return buf;
5224
}
5225

5226
typedef struct {
5227
  int32_t status;  // ask hb endpoint
5228
  int32_t epoch;
5229
  int64_t consumerId;
5230
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5231
} SMqReportReq;
5232

5233
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5234
  int32_t tlen = 0;
5235
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5236
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5237
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5238
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5239
  tlen += taosEncodeFixedI32(buf, sz);
5240
  for (int32_t i = 0; i < sz; i++) {
5241
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5242
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5243
  }
5244
  return tlen;
5245
}
5246

5247
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5248
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5249
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5250
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5251
  int32_t sz;
5252
  buf = taosDecodeFixedI32(buf, &sz);
5253
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5254
    return NULL;
5255
  }
5256
  for (int32_t i = 0; i < sz; i++) {
5257
    SMqTopicInfo topicInfo;
5258
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5259
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5260
      return NULL;
5261
    }
5262
  }
5263
  return buf;
5264
}
5265

5266
typedef struct {
5267
  SMsgHead head;
5268
  int64_t  leftForVer;
5269
  int32_t  vgId;
5270
  int64_t  consumerId;
5271
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5272
} SMqVDeleteReq;
5273

5274
typedef struct {
5275
  int8_t reserved;
5276
} SMqVDeleteRsp;
5277

5278
typedef struct {
5279
  char**  name;
5280
  int32_t count;
5281
  int8_t igNotExists;
5282
} SMDropStreamReq;
5283

5284
typedef struct {
5285
  int8_t reserved;
5286
} SMDropStreamRsp;
5287

5288
typedef struct {
5289
  SMsgHead head;
5290
  int64_t  resetRelHalt;  // reset related stream task halt status
5291
  int64_t  streamId;
5292
  int32_t  taskId;
5293
} SVDropStreamTaskReq;
5294

5295
typedef struct {
5296
  int8_t reserved;
5297
} SVDropStreamTaskRsp;
5298

5299
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5300
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5301
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5302

5303
typedef struct {
5304
  char*  name;
5305
  int8_t igNotExists;
5306
} SMPauseStreamReq;
5307

5308
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5309
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5310
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5311

5312
typedef struct {
5313
  char*  name;
5314
  int8_t igNotExists;
5315
  int8_t igUntreated;
5316
} SMResumeStreamReq;
5317

5318
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5319
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5320
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5321

5322
typedef struct {
5323
  char*       name;
5324
  int8_t      calcAll;
5325
  STimeWindow timeRange;
5326
} SMRecalcStreamReq;
5327

5328
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5329
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5330
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5331

5332

5333
typedef struct SVndSetKeepVersionReq {
5334
  int64_t keepVersion;
5335
} SVndSetKeepVersionReq;
5336

5337
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5338
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5339

5340
typedef struct SVUpdateCheckpointInfoReq {
5341
  SMsgHead head;
5342
  int64_t  streamId;
5343
  int32_t  taskId;
5344
  int64_t  checkpointId;
5345
  int64_t  checkpointVer;
5346
  int64_t  checkpointTs;
5347
  int32_t  transId;
5348
  int64_t  hStreamId;  // add encode/decode
5349
  int64_t  hTaskId;
5350
  int8_t   dropRelHTask;
5351
} SVUpdateCheckpointInfoReq;
5352

5353
typedef struct {
5354
  int64_t leftForVer;
5355
  int32_t vgId;
5356
  int64_t oldConsumerId;
5357
  int64_t newConsumerId;
5358
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5359
  int8_t  subType;
5360
  int8_t  withMeta;
5361
  char*   qmsg;  // SubPlanToString
5362
  SSchemaWrapper schema;
5363
  int64_t suid;
5364
} SMqRebVgReq;
5365

5366
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5367
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5368

5369
// tqOffset
5370
enum {
5371
  TMQ_OFFSET__RESET_NONE = -3,
5372
  TMQ_OFFSET__RESET_EARLIEST = -2,
5373
  TMQ_OFFSET__RESET_LATEST = -1,
5374
  TMQ_OFFSET__LOG = 1,
5375
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5376
  TMQ_OFFSET__SNAPSHOT_META = 3,
5377
};
5378

5379
enum {
5380
  WITH_DATA = 0,
5381
  WITH_META = 1,
5382
  ONLY_META = 2,
5383
};
5384

5385
#define TQ_OFFSET_VERSION 1
5386

5387
typedef struct {
5388
  int8_t type;
5389
  union {
5390
    // snapshot
5391
    struct {
5392
      int64_t uid;
5393
      int64_t ts;
5394
      SValue  primaryKey;
5395
    };
5396
    // log
5397
    struct {
5398
      int64_t version;
5399
    };
5400
  };
5401
} STqOffsetVal;
5402

5403
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5404
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,659,348✔
5405
  pOffsetVal->uid = uid;
7,658,457✔
5406
  pOffsetVal->ts = ts;
7,658,457✔
5407
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,658,158✔
5408
    taosMemoryFree(pOffsetVal->primaryKey.pData);
287✔
5409
  }
5410
  pOffsetVal->primaryKey = primaryKey;
7,656,082✔
5411
}
7,656,700✔
5412

5413
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5414
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
38,846✔
5415
  pOffsetVal->uid = uid;
38,846✔
5416
}
38,846✔
5417

5418
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5419
  pOffsetVal->type = TMQ_OFFSET__LOG;
121,953,212✔
5420
  pOffsetVal->version = ver;
121,952,425✔
5421
}
121,939,230✔
5422

5423
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5424
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5425
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5426
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5427
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5428
void    tOffsetDestroy(void* pVal);
5429

5430
typedef struct {
5431
  STqOffsetVal val;
5432
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5433
} STqOffset;
5434

5435
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5436
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5437
void    tDeleteSTqOffset(void* val);
5438

5439
typedef struct SMqVgOffset {
5440
  int64_t   consumerId;
5441
  STqOffset offset;
5442
} SMqVgOffset;
5443

5444
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5445
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5446

5447
typedef struct {
5448
  char    name[TSDB_TABLE_FNAME_LEN];
5449
  char    stb[TSDB_TABLE_FNAME_LEN];
5450
  int8_t  igExists;
5451
  int8_t  intervalUnit;
5452
  int8_t  slidingUnit;
5453
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5454
  int32_t dstVgId;   // for stream
5455
  int64_t interval;
5456
  int64_t offset;
5457
  int64_t sliding;
5458
  int64_t maxDelay;
5459
  int64_t watermark;
5460
  int32_t exprLen;        // strlen + 1
5461
  int32_t tagsFilterLen;  // strlen + 1
5462
  int32_t sqlLen;         // strlen + 1
5463
  int32_t astLen;         // strlen + 1
5464
  char*   expr;
5465
  char*   tagsFilter;
5466
  char*   sql;
5467
  char*   ast;
5468
  int64_t deleteMark;
5469
  int64_t lastTs;
5470
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5471
  SArray* pVgroupVerList;
5472
  int8_t  recursiveTsma;
5473
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5474
  char*   createStreamReq;
5475
  int32_t streamReqLen;
5476
  char*   dropStreamReq;
5477
  int32_t dropStreamReqLen;
5478
  int64_t uid;
5479
} SMCreateSmaReq;
5480

5481
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5482
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5483
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5484

5485
typedef struct {
5486
  char    name[TSDB_TABLE_FNAME_LEN];
5487
  int8_t  igNotExists;
5488
  char*   dropStreamReq;
5489
  int32_t dropStreamReqLen;
5490
} SMDropSmaReq;
5491

5492
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5493
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5494
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5495

5496
typedef struct {
5497
  char name[TSDB_TABLE_NAME_LEN];
5498
  union {
5499
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5500
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5501
  };
5502
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5503
  union {
5504
    int8_t igExists;   // used by mnode
5505
    int8_t alterType;  // used by vnode
5506
  };
5507
  int8_t     intervalUnit;
5508
  int16_t    nFuncs;       // number of functions specified by user
5509
  col_id_t*  funcColIds;   // column ids specified by user
5510
  func_id_t* funcIds;      // function ids specified by user
5511
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5512
  int64_t    tbUid;
5513
  int64_t    uid;     // rsma uid
5514
  int32_t    sqlLen;  // strlen + 1
5515
  char*      sql;
5516
} SMCreateRsmaReq;
5517

5518
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5519
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5520
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5521

5522
typedef SMCreateRsmaReq SVCreateRsmaReq;
5523

5524
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5525
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5526
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5527

5528
typedef SMCreateRsmaReq SVAlterRsmaReq;
5529

5530
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5531
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5532
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5533

5534
typedef struct {
5535
  char       name[TSDB_TABLE_NAME_LEN];
5536
  int8_t     alterType;
5537
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5538
  int8_t     igNotExists;
5539
  int16_t    nFuncs;      // number of functions specified by user
5540
  col_id_t*  funcColIds;  // column ids specified by user
5541
  func_id_t* funcIds;     // function ids specified by user
5542
  int32_t    sqlLen;      // strlen + 1
5543
  char*      sql;
5544
} SMAlterRsmaReq;
5545

5546
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5547
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5548
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5549

5550
typedef struct {
5551
  int64_t    id;
5552
  char       name[TSDB_TABLE_NAME_LEN];
5553
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5554
  int64_t    ownerId;
5555
  int32_t    code;
5556
  int32_t    version;
5557
  int8_t     tbType;
5558
  int8_t     intervalUnit;
5559
  col_id_t   nFuncs;
5560
  col_id_t   nColNames;
5561
  int64_t    interval[2];
5562
  col_id_t*  funcColIds;
5563
  func_id_t* funcIds;
5564
  SArray*    colNames;
5565
} SRsmaInfoRsp;
5566

5567
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5568
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5569
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5570

5571
typedef struct {
5572
  char   name[TSDB_TABLE_FNAME_LEN];
5573
  int8_t igNotExists;
5574
} SMDropRsmaReq;
5575

5576
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5577
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5578

5579
typedef struct {
5580
  char    name[TSDB_TABLE_NAME_LEN];
5581
  char    tbName[TSDB_TABLE_NAME_LEN];
5582
  int64_t uid;
5583
  int64_t tbUid;
5584
  int8_t  tbType;
5585
} SVDropRsmaReq;
5586

5587
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5588
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5589

5590
typedef struct {
5591
  char   dbFName[TSDB_DB_FNAME_LEN];
5592
  char   stbName[TSDB_TABLE_NAME_LEN];
5593
  char   colName[TSDB_COL_NAME_LEN];
5594
  char   idxName[TSDB_INDEX_FNAME_LEN];
5595
  int8_t idxType;
5596
} SCreateTagIndexReq;
5597

5598
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5599
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5600

5601
typedef SMDropSmaReq SDropTagIndexReq;
5602

5603
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5604
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5605

5606
typedef struct {
5607
  int8_t         version;       // for compatibility(default 0)
5608
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5609
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5610
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5611
  int32_t        dstVgId;
5612
  char           indexName[TSDB_INDEX_NAME_LEN];
5613
  int32_t        exprLen;
5614
  int32_t        tagsFilterLen;
5615
  int64_t        indexUid;
5616
  tb_uid_t       tableUid;  // super/child/common table uid
5617
  tb_uid_t       dstTbUid;  // for dstVgroup
5618
  int64_t        interval;
5619
  int64_t        offset;  // use unit by precision of DB
5620
  int64_t        sliding;
5621
  char*          dstTbName;  // for dstVgroup
5622
  char*          expr;       // sma expression
5623
  char*          tagsFilter;
5624
  SSchemaWrapper schemaRow;  // for dstVgroup
5625
  SSchemaWrapper schemaTag;  // for dstVgroup
5626
} STSma;                     // Time-range-wise SMA
5627

5628
typedef STSma SVCreateTSmaReq;
5629

5630
typedef struct {
5631
  int8_t  type;  // 0 status report, 1 update data
5632
  int64_t indexUid;
5633
  int64_t skey;  // start TS key of interval/sliding window
5634
} STSmaMsg;
5635

5636
typedef struct {
5637
  int64_t indexUid;
5638
  char    indexName[TSDB_INDEX_NAME_LEN];
5639
} SVDropTSmaReq;
5640

5641
typedef struct {
5642
  int tmp;  // TODO: to avoid compile error
5643
} SVCreateTSmaRsp, SVDropTSmaRsp;
5644

5645
#if 0
5646
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5647
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5648
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5649
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5650
#endif
5651

5652
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5653
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5654
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5655
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5656

5657
typedef struct {
5658
  int32_t number;
5659
  STSma*  tSma;
5660
} STSmaWrapper;
5661

5662
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5663
  if (pSma) {
×
5664
    taosMemoryFreeClear(pSma->dstTbName);
×
5665
    taosMemoryFreeClear(pSma->expr);
×
5666
    taosMemoryFreeClear(pSma->tagsFilter);
×
5667
  }
5668
}
×
5669

5670
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5671
  if (pSW) {
×
5672
    if (pSW->tSma) {
×
5673
      if (deepCopy) {
×
5674
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
5675
          tDestroyTSma(pSW->tSma + i);
×
5676
        }
5677
      }
5678
      taosMemoryFreeClear(pSW->tSma);
×
5679
    }
5680
  }
5681
}
×
5682

5683
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5684
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5685
  taosMemoryFreeClear(pSW);
×
5686
  return NULL;
×
5687
}
5688

5689
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5690
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5691

5692
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5693
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5694

5695
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5696
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5697
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5698
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5699
  }
5700
  return 0;
×
5701
}
5702

5703
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5704
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5705
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5706
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5707
  }
5708
  return 0;
×
5709
}
5710

5711
typedef struct {
5712
  int idx;
5713
} SMCreateFullTextReq;
5714

5715
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5716
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5717
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5718

5719
typedef struct {
5720
  char   name[TSDB_TABLE_FNAME_LEN];
5721
  int8_t igNotExists;
5722
} SMDropFullTextReq;
5723

5724
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5725
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5726

5727
typedef struct {
5728
  char indexFName[TSDB_INDEX_FNAME_LEN];
5729
} SUserIndexReq;
5730

5731
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5732
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5733

5734
typedef struct {
5735
  char dbFName[TSDB_DB_FNAME_LEN];
5736
  char tblFName[TSDB_TABLE_FNAME_LEN];
5737
  char colName[TSDB_COL_NAME_LEN];
5738
  char owner[TSDB_USER_LEN];
5739
  char indexType[TSDB_INDEX_TYPE_LEN];
5740
  char indexExts[TSDB_INDEX_EXTS_LEN];
5741
} SUserIndexRsp;
5742

5743
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5744
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5745

5746
typedef struct {
5747
  char tbFName[TSDB_TABLE_FNAME_LEN];
5748
} STableIndexReq;
5749

5750
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5751
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5752

5753
typedef struct {
5754
  int8_t  intervalUnit;
5755
  int8_t  slidingUnit;
5756
  int64_t interval;
5757
  int64_t offset;
5758
  int64_t sliding;
5759
  int64_t dstTbUid;
5760
  int32_t dstVgId;
5761
  SEpSet  epSet;
5762
  char*   expr;
5763
} STableIndexInfo;
5764

5765
typedef struct {
5766
  char     tbName[TSDB_TABLE_NAME_LEN];
5767
  char     dbFName[TSDB_DB_FNAME_LEN];
5768
  uint64_t suid;
5769
  int32_t  version;
5770
  int32_t  indexSize;
5771
  SArray*  pIndex;  // STableIndexInfo
5772
} STableIndexRsp;
5773

5774
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5775
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5776
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5777

5778
void tFreeSTableIndexInfo(void* pInfo);
5779

5780
typedef struct {
5781
  int8_t  mqMsgType;
5782
  int32_t code;
5783
  int32_t epoch;
5784
  int64_t consumerId;
5785
  int64_t walsver;
5786
  int64_t walever;
5787
} SMqRspHead;
5788

5789
typedef struct {
5790
  SMsgHead     head;
5791
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5792
  int8_t       withTbName;
5793
  int8_t       useSnapshot;
5794
  int32_t      epoch;
5795
  uint64_t     reqId;
5796
  int64_t      consumerId;
5797
  int64_t      timeout;
5798
  STqOffsetVal reqOffset;
5799
  int8_t       enableReplay;
5800
  int8_t       sourceExcluded;
5801
  int8_t       rawData;
5802
  int32_t      minPollRows;
5803
  int8_t       enableBatchMeta;
5804
  SHashObj*    uidHash;  // to find if uid is duplicated
5805
} SMqPollReq;
5806

5807
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5808
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5809
void    tDestroySMqPollReq(SMqPollReq* pReq);
5810

5811
typedef struct {
5812
  int32_t vgId;
5813
  int64_t offset;
5814
  SEpSet  epSet;
5815
} SMqSubVgEp;
5816

5817
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5818
  int32_t tlen = 0;
2,580,362✔
5819
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,580,362✔
5820
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,580,362✔
5821
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,580,362✔
5822
  return tlen;
2,580,362✔
5823
}
5824

5825
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5826
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,286,231✔
5827
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,286,231✔
5828
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,286,231✔
5829
  return buf;
1,286,231✔
5830
}
5831

5832
typedef struct {
5833
  char           topic[TSDB_TOPIC_FNAME_LEN];
5834
  char           db[TSDB_DB_FNAME_LEN];
5835
  SArray*        vgs;  // SArray<SMqSubVgEp>
5836
} SMqSubTopicEp;
5837

5838
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5839
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5840
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5841

5842
typedef struct {
5843
  SMqRspHead   head;
5844
  STqOffsetVal rspOffset;
5845
  int16_t      resMsgType;
5846
  int32_t      metaRspLen;
5847
  void*        metaRsp;
5848
} SMqMetaRsp;
5849

5850
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5851
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5852
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5853

5854
#define MQ_DATA_RSP_VERSION 100
5855

5856
typedef struct {
5857
  SMqRspHead   head;
5858
  STqOffsetVal rspOffset;
5859
  STqOffsetVal reqOffset;
5860
  int32_t      blockNum;
5861
  int8_t       withTbName;
5862
  int8_t       withSchema;
5863
  SArray*      blockDataLen;
5864
  SArray*      blockData;
5865
  SArray*      blockTbName;
5866
  SArray*      blockSchema;
5867

5868
  union {
5869
    struct {
5870
      int64_t sleepTime;
5871
    };
5872
    struct {
5873
      int32_t createTableNum;
5874
      SArray* createTableLen;
5875
      SArray* createTableReq;
5876
    };
5877
    struct {
5878
      int32_t len;
5879
      void*   rawData;
5880
    };
5881
  };
5882
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5883
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5884
} SMqDataRsp;
5885

5886
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5887
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5888
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5889
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5890
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5891

5892
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5893
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5894
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5895

5896
typedef struct SMqBatchMetaRsp {
5897
  SMqRspHead   head;  // not serialize
5898
  STqOffsetVal rspOffset;
5899
  SArray*      batchMetaLen;
5900
  SArray*      batchMetaReq;
5901
  void*        pMetaBuff;    // not serialize
5902
  uint32_t     metaBuffLen;  // not serialize
5903
} SMqBatchMetaRsp;
5904

5905
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5906
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5907
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5908
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5909

5910
typedef struct {
5911
  int32_t    code;
5912
  SArray*    topics;  // SArray<SMqSubTopicEp>
5913
} SMqAskEpRsp;
5914

5915
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5916
  int32_t tlen = 0;
8,146,898✔
5917
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5918
  int32_t sz = taosArrayGetSize(pRsp->topics);
8,146,898✔
5919
  tlen += taosEncodeFixedI32(buf, sz);
8,146,898✔
5920
  for (int32_t i = 0; i < sz; i++) {
10,267,106✔
5921
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
2,120,554✔
5922
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
2,120,554✔
5923
  }
5924
  tlen += taosEncodeFixedI32(buf, pRsp->code);
8,146,552✔
5925

5926
  return tlen;
8,146,898✔
5927
}
5928

5929
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5930
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5931
  int32_t sz;
3,393,521✔
5932
  buf = taosDecodeFixedI32(buf, &sz);
3,466,567✔
5933
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,466,567✔
5934
  if (pRsp->topics == NULL) {
3,466,567✔
5935
    return NULL;
×
5936
  }
5937
  for (int32_t i = 0; i < sz; i++) {
4,470,607✔
5938
    SMqSubTopicEp topicEp;
991,745✔
5939
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
1,004,040✔
5940
    if (buf == NULL) {
1,004,040✔
5941
      return NULL;
×
5942
    }
5943
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
2,008,080✔
5944
      return NULL;
×
5945
    }
5946
  }
5947
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,466,567✔
5948

5949
  return buf;
3,466,567✔
5950
}
5951

5952
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5953
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
10,040,367✔
5954
}
10,040,020✔
5955

5956
typedef struct {
5957
  int32_t      vgId;
5958
  STqOffsetVal offset;
5959
  int64_t      rows;
5960
  int64_t      ever;
5961
} OffsetRows;
5962

5963
typedef struct {
5964
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5965
  SArray* offsetRows;
5966
} TopicOffsetRows;
5967

5968
typedef struct {
5969
  int64_t consumerId;
5970
  int32_t epoch;
5971
  SArray* topics;
5972
  int8_t  pollFlag;
5973
} SMqHbReq;
5974

5975
typedef struct {
5976
  char   topic[TSDB_TOPIC_FNAME_LEN];
5977
  int8_t noPrivilege;
5978
} STopicPrivilege;
5979

5980
typedef struct {
5981
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5982
  int32_t debugFlag;
5983
} SMqHbRsp;
5984

5985
typedef struct {
5986
  SMsgHead head;
5987
  int64_t  consumerId;
5988
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5989
} SMqSeekReq;
5990

5991
#define TD_AUTO_CREATE_TABLE 0x1
5992
typedef struct {
5993
  int64_t       suid;
5994
  int64_t       uid;
5995
  int32_t       sver;
5996
  uint32_t      nData;
5997
  uint8_t*      pData;
5998
  SVCreateTbReq cTbReq;
5999
} SVSubmitBlk;
6000

6001
typedef struct {
6002
  SMsgHead header;
6003
  uint64_t sId;
6004
  uint64_t queryId;
6005
  uint64_t clientId;
6006
  uint64_t taskId;
6007
  uint32_t sqlLen;
6008
  uint32_t phyLen;
6009
  char*    sql;
6010
  char*    msg;
6011
  int8_t   source;
6012
} SVDeleteReq;
6013

6014
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6015
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6016

6017
typedef struct {
6018
  int64_t affectedRows;
6019
} SVDeleteRsp;
6020

6021
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6022
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6023

6024
typedef struct SDeleteRes {
6025
  uint64_t suid;
6026
  SArray*  uidList;
6027
  int64_t  skey;
6028
  int64_t  ekey;
6029
  int64_t  affectedRows;
6030
  char     tableFName[TSDB_TABLE_NAME_LEN];
6031
  char     tsColName[TSDB_COL_NAME_LEN];
6032
  int64_t  ctimeMs;  // fill by vnode
6033
  int8_t   source;
6034
} SDeleteRes;
6035

6036
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6037
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6038

6039
typedef struct {
6040
  // int64_t uid;
6041
  char    tbname[TSDB_TABLE_NAME_LEN];
6042
  int64_t startTs;
6043
  int64_t endTs;
6044
} SSingleDeleteReq;
6045

6046
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6047
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6048

6049
typedef struct {
6050
  int64_t suid;
6051
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6052
  int64_t ctimeMs;     // fill by vnode
6053
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6054
} SBatchDeleteReq;
6055

6056
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6057
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6058
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6059

6060
typedef struct {
6061
  int32_t msgIdx;
6062
  int32_t msgType;
6063
  int32_t msgLen;
6064
  void*   msg;
6065
} SBatchMsg;
6066

6067
typedef struct {
6068
  SMsgHead header;
6069
  SArray*  pMsgs;  // SArray<SBatchMsg>
6070
} SBatchReq;
6071

6072
typedef struct {
6073
  int32_t reqType;
6074
  int32_t msgIdx;
6075
  int32_t msgLen;
6076
  int32_t rspCode;
6077
  void*   msg;
6078
} SBatchRspMsg;
6079

6080
typedef struct {
6081
  SArray* pRsps;  // SArray<SBatchRspMsg>
6082
} SBatchRsp;
6083

6084
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6085
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6086
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
94,951,517✔
6087
  if (NULL == msg) {
94,951,517✔
6088
    return;
×
6089
  }
6090
  SBatchMsg* pMsg = (SBatchMsg*)msg;
94,951,517✔
6091
  taosMemoryFree(pMsg->msg);
94,951,517✔
6092
}
6093

6094
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6095
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6096

6097
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
127,059,976✔
6098
  if (NULL == p) {
127,059,976✔
6099
    return;
×
6100
  }
6101

6102
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
127,059,976✔
6103
  taosMemoryFree(pRsp->msg);
127,059,976✔
6104
}
6105

6106
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6107
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6108
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6109
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6110
void    tDestroySMqHbReq(SMqHbReq* pReq);
6111

6112
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6113
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6114
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6115

6116
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6117
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6118

6119
#define TD_REQ_FROM_APP               0x0
6120
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6121
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6122
#define SUBMIT_REQ_FROM_FILE          0x4
6123
#define TD_REQ_FROM_TAOX              0x8
6124
#define TD_REQ_FROM_SML               0x10
6125
#define SUBMIT_REQUEST_VERSION        (2)
6126
#define SUBMIT_REQ_WITH_BLOB          0x10
6127
#define SUBMIT_REQ_SCHEMA_RES         0x20
6128
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6129

6130
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6131

6132
typedef struct {
6133
  int32_t        flags;
6134
  SVCreateTbReq* pCreateTbReq;
6135
  int64_t        suid;
6136
  int64_t        uid;
6137
  int32_t        sver;
6138
  union {
6139
    SArray* aRowP;
6140
    SArray* aCol;
6141
  };
6142
  int64_t   ctimeMs;
6143
  SBlobSet* pBlobSet;
6144
} SSubmitTbData;
6145

6146
typedef struct {
6147
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6148
  SArray* aSubmitBlobData;
6149
  bool    raw;
6150
} SSubmitReq2;
6151

6152
typedef struct {
6153
  SMsgHead header;
6154
  int64_t  version;
6155
  char     data[];  // SSubmitReq2
6156
} SSubmitReq2Msg;
6157

6158
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6159
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6160
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6161
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6162
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6163

6164
typedef struct {
6165
  int32_t affectedRows;
6166
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6167
} SSubmitRsp2;
6168

6169
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6170
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6171
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6172

6173
#define TSDB_MSG_FLG_ENCODE 0x1
6174
#define TSDB_MSG_FLG_DECODE 0x2
6175
#define TSDB_MSG_FLG_CMPT   0x3
6176

6177
typedef struct {
6178
  union {
6179
    struct {
6180
      void*   msgStr;
6181
      int32_t msgLen;
6182
      int64_t ver;
6183
    };
6184
    void* pDataBlock;
6185
  };
6186
} SPackedData;
6187

6188
typedef struct {
6189
  char     fullname[TSDB_VIEW_FNAME_LEN];
6190
  char     name[TSDB_VIEW_NAME_LEN];
6191
  char     dbFName[TSDB_DB_FNAME_LEN];
6192
  char*    querySql;
6193
  char*    sql;
6194
  int8_t   orReplace;
6195
  int8_t   precision;
6196
  int32_t  numOfCols;
6197
  SSchema* pSchema;
6198
} SCMCreateViewReq;
6199

6200
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6201
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6202
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6203

6204
typedef struct {
6205
  char   fullname[TSDB_VIEW_FNAME_LEN];
6206
  char   name[TSDB_VIEW_NAME_LEN];
6207
  char   dbFName[TSDB_DB_FNAME_LEN];
6208
  char*  sql;
6209
  int8_t igNotExists;
6210
} SCMDropViewReq;
6211

6212
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6213
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6214
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6215

6216
typedef struct {
6217
  char fullname[TSDB_VIEW_FNAME_LEN];
6218
} SViewMetaReq;
6219
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6220
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6221

6222
typedef struct {
6223
  char     name[TSDB_VIEW_NAME_LEN];
6224
  char     dbFName[TSDB_DB_FNAME_LEN];
6225
  char*    createUser;
6226
  int64_t  ownerId;
6227
  uint64_t dbId;
6228
  uint64_t viewId;
6229
  char*    querySql;
6230
  int8_t   precision;
6231
  int8_t   type;
6232
  int32_t  version;
6233
  int32_t  numOfCols;
6234
  SSchema* pSchema;
6235
} SViewMetaRsp;
6236
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6237
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6238
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6239
typedef struct {
6240
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6241
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6242
} STableTSMAInfoReq;
6243

6244
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6245
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6246

6247
typedef struct {
6248
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6249
  union {
6250
    uint8_t flags;
6251
    struct {
6252
      uint8_t withColName : 1;
6253
      uint8_t reserved : 7;
6254
    };
6255
  };
6256

6257
} SRsmaInfoReq;
6258

6259
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6260
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6261

6262
typedef struct {
6263
  int32_t  funcId;
6264
  col_id_t colId;
6265
} STableTSMAFuncInfo;
6266

6267
typedef struct {
6268
  char     name[TSDB_TABLE_NAME_LEN];
6269
  uint64_t tsmaId;
6270
  char     targetTb[TSDB_TABLE_NAME_LEN];
6271
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6272
  char     tb[TSDB_TABLE_NAME_LEN];
6273
  char     dbFName[TSDB_DB_FNAME_LEN];
6274
  uint64_t suid;
6275
  uint64_t destTbUid;
6276
  uint64_t dbId;
6277
  int32_t  version;
6278
  int64_t  interval;
6279
  int8_t   unit;
6280
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6281
  SArray*  pTags;      // SArray<SSchema>
6282
  SArray*  pUsedCols;  // SArray<SSchema>
6283
  char*    ast;
6284

6285
  int64_t streamUid;
6286
  int64_t reqTs;
6287
  int64_t rspTs;
6288
  int64_t delayDuration;  // ms
6289
  bool    fillHistoryFinished;
6290

6291
  void* streamAddr;  // for stream task, the address of the stream task
6292
} STableTSMAInfo;
6293

6294
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6295
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6296
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6297
void    tFreeTableTSMAInfo(void* p);
6298
void    tFreeAndClearTableTSMAInfo(void* p);
6299
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6300

6301
#define STSMAHbRsp            STableTSMAInfoRsp
6302
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6303
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6304
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6305

6306
typedef struct SDropCtbWithTsmaSingleVgReq {
6307
  SVgroupInfo vgInfo;
6308
  SArray*     pTbs;  // SVDropTbReq
6309
} SMDropTbReqsOnSingleVg;
6310

6311
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6312
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6313
void    tFreeSMDropTbReqOnSingleVg(void* p);
6314

6315
typedef struct SDropTbsReq {
6316
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6317
} SMDropTbsReq;
6318

6319
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6320
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6321
void    tFreeSMDropTbsReq(void*);
6322

6323
typedef struct SVFetchTtlExpiredTbsRsp {
6324
  SArray* pExpiredTbs;  // SVDropTbReq
6325
  int32_t vgId;
6326
} SVFetchTtlExpiredTbsRsp;
6327

6328
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6329
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6330

6331
void tFreeFetchTtlExpiredTbsRsp(void* p);
6332

6333
void setDefaultOptionsForField(SFieldWithOptions* field);
6334
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6335

6336
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6337
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6338

6339

6340
typedef struct {
6341
  char    id[TSDB_INSTANCE_ID_LEN];
6342
  char    type[TSDB_INSTANCE_TYPE_LEN];
6343
  char    desc[TSDB_INSTANCE_DESC_LEN];
6344
  int32_t expire;
6345
} SInstanceRegisterReq;
6346

6347
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6348
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6349

6350
typedef struct {
6351
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6352
} SInstanceListReq;
6353

6354
typedef struct {
6355
  int32_t count;
6356
  char**  ids;  // Array of instance IDs
6357
} SInstanceListRsp;
6358

6359
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6360
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6361
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6362
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6363

6364
#ifdef USE_MOUNT
6365
typedef struct {
6366
  char     mountName[TSDB_MOUNT_NAME_LEN];
6367
  int8_t   ignoreExist;
6368
  int16_t  nMounts;
6369
  int32_t* dnodeIds;
6370
  char**   mountPaths;
6371
  int32_t  sqlLen;
6372
  char*    sql;
6373
} SCreateMountReq;
6374

6375
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6376
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6377
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6378

6379
typedef struct {
6380
  char    mountName[TSDB_MOUNT_NAME_LEN];
6381
  int8_t  ignoreNotExists;
6382
  int32_t sqlLen;
6383
  char*   sql;
6384
} SDropMountReq;
6385

6386
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6387
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6388
void    tFreeSDropMountReq(SDropMountReq* pReq);
6389

6390
typedef struct {
6391
  char     mountName[TSDB_MOUNT_NAME_LEN];
6392
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6393
  int64_t  mountUid;
6394
  int32_t  dnodeId;
6395
  uint32_t valLen;
6396
  int8_t   ignoreExist;
6397
  void*    pVal;
6398
} SRetrieveMountPathReq;
6399

6400
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6401
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6402

6403
typedef struct {
6404
  // path
6405
  int32_t diskPrimary;
6406
  // vgInfo
6407
  int32_t  vgId;
6408
  int32_t  cacheLastSize;
6409
  int32_t  szPage;
6410
  int32_t  szCache;
6411
  uint64_t szBuf;
6412
  int8_t   cacheLast;
6413
  int8_t   standby;
6414
  int8_t   hashMethod;
6415
  uint32_t hashBegin;
6416
  uint32_t hashEnd;
6417
  int16_t  hashPrefix;
6418
  int16_t  hashSuffix;
6419
  int16_t  sttTrigger;
6420
  // syncInfo
6421
  int32_t replications;
6422
  // tsdbInfo
6423
  int8_t  precision;
6424
  int8_t  compression;
6425
  int8_t  slLevel;
6426
  int32_t daysPerFile;
6427
  int32_t keep0;
6428
  int32_t keep1;
6429
  int32_t keep2;
6430
  int32_t keepTimeOffset;
6431
  int32_t minRows;
6432
  int32_t maxRows;
6433
  int32_t tsdbPageSize;
6434
  int32_t ssChunkSize;
6435
  int32_t ssKeepLocal;
6436
  int8_t  ssCompact;
6437
  // walInfo
6438
  int32_t walFsyncPeriod;      // millisecond
6439
  int32_t walRetentionPeriod;  // secs
6440
  int32_t walRollPeriod;       // secs
6441
  int64_t walRetentionSize;
6442
  int64_t walSegSize;
6443
  int32_t walLevel;
6444
  // encryptInfo
6445
  int32_t encryptAlgorithm;
6446
  // SVState
6447
  int64_t committed;
6448
  int64_t commitID;
6449
  int64_t commitTerm;
6450
  // stats
6451
  int64_t numOfSTables;
6452
  int64_t numOfCTables;
6453
  int64_t numOfNTables;
6454
  // dbInfo
6455
  uint64_t dbId;
6456
} SMountVgInfo;
6457

6458
typedef struct {
6459
  SMCreateStbReq req;
6460
  SArray*        pColExts;  // element: column id
6461
  SArray*        pTagExts;  // element: tag id
6462
} SMountStbInfo;
6463

6464
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6465
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6466

6467
typedef struct {
6468
  char     dbName[TSDB_DB_FNAME_LEN];
6469
  uint64_t dbId;
6470
  SArray*  pVgs;   // SMountVgInfo
6471
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6472
} SMountDbInfo;
6473

6474
typedef struct {
6475
  // common fields
6476
  char     mountName[TSDB_MOUNT_NAME_LEN];
6477
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6478
  int8_t   ignoreExist;
6479
  int64_t  mountUid;
6480
  int64_t  clusterId;
6481
  int32_t  dnodeId;
6482
  uint32_t valLen;
6483
  void*    pVal;
6484

6485
  // response fields
6486
  SArray* pDbs;  // SMountDbInfo
6487

6488
  // memory fields, no serialized
6489
  SArray*   pDisks[TFS_MAX_TIERS];
6490
  TdFilePtr pFile;
6491
} SMountInfo;
6492

6493
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6494
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6495
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6496

6497
typedef struct {
6498
  SCreateVnodeReq createReq;
6499
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6500
  char            mountName[TSDB_MOUNT_NAME_LEN];
6501
  int64_t         mountId;
6502
  int32_t         diskPrimary;
6503
  int32_t         mountVgId;
6504
  int64_t         committed;
6505
  int64_t         commitID;
6506
  int64_t         commitTerm;
6507
  int64_t         numOfSTables;
6508
  int64_t         numOfCTables;
6509
  int64_t         numOfNTables;
6510
} SMountVnodeReq;
6511

6512
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6513
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6514
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6515

6516
#endif  // USE_MOUNT
6517

6518
#pragma pack(pop)
6519

6520
typedef struct {
6521
  char        db[TSDB_DB_FNAME_LEN];
6522
  STimeWindow timeRange;
6523
  int32_t     sqlLen;
6524
  char*       sql;
6525
  SArray*     vgroupIds;
6526
} SScanDbReq;
6527

6528
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6529
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6530
void    tFreeSScanDbReq(SScanDbReq* pReq);
6531

6532
typedef struct {
6533
  int32_t scanId;
6534
  int8_t  bAccepted;
6535
} SScanDbRsp;
6536

6537
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6538
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6539

6540
typedef struct {
6541
  int32_t scanId;
6542
  int32_t sqlLen;
6543
  char*   sql;
6544
} SKillScanReq;
6545

6546
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6547
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6548
void    tFreeSKillScanReq(SKillScanReq* pReq);
6549

6550
typedef struct {
6551
  int32_t scanId;
6552
  int32_t vgId;
6553
  int32_t dnodeId;
6554
} SVKillScanReq;
6555

6556
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6557
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6558

6559
typedef struct {
6560
  int32_t scanId;
6561
  int32_t vgId;
6562
  int32_t dnodeId;
6563
  int32_t numberFileset;
6564
  int32_t finished;
6565
  int32_t progress;
6566
  int64_t remainingTime;
6567
} SQueryScanProgressRsp;
6568

6569
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6570
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6571

6572
typedef struct {
6573
  int32_t scanId;
6574
  int32_t vgId;
6575
  int32_t dnodeId;
6576
} SQueryScanProgressReq;
6577

6578
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6579
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6580

6581
typedef struct {
6582
  int64_t     dbUid;
6583
  char        db[TSDB_DB_FNAME_LEN];
6584
  int64_t     scanStartTime;
6585
  STimeWindow tw;
6586
  int32_t     scanId;
6587
} SScanVnodeReq;
6588

6589
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6590
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6591

6592
#ifdef __cplusplus
6593
}
6594
#endif
6595

6596
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6597
 
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