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

taosdata / TDengine / #4997

20 Mar 2026 06:10AM UTC coverage: 71.739% (-0.3%) from 72.069%
#4997

push

travis-ci

web-flow
feat: add query phase tracking for SHOW QUERIES (#34706)

148 of 183 new or added lines in 10 files covered. (80.87%)

9273 existing lines in 172 files now uncovered.

244572 of 340921 relevant lines covered (71.74%)

133392941.95 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

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

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

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

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

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

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

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

67
typedef uint16_t tmsg_t;
68

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

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

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

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

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

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
949,078,140✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
900,463,952✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,849,542,092✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
2,076,206,395✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
2,076,206,395✔
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 // deprecated, kept for wire compatibility
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 // deprecated, kept for wire compatibility
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
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL      19 // alter multiple tag values of multi tables
251
#define TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL      20 // alter multiple tag values of the child tables of a stable
252

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

263

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

269

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

275
#define TSDB_ALTER_RSMA_FUNCTION        0x1
276

277
#define TSDB_KILL_MSG_LEN 30
278

279
#define TSDB_TABLE_NUM_UNIT 100000
280

281
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
282
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
283
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
284

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

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

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

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

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

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

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

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

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

683
typedef struct {
684
  int32_t     vgId;
685
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
686
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
687
  const char* dbFName;
688
  const char* tbName;
689
} SBuildTableInput;
690

691
typedef struct {
692
  char    db[TSDB_DB_FNAME_LEN];
693
  int64_t dbId;
694
  int32_t vgVersion;
695
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
696
  int64_t stateTs;
697
} SBuildUseDBInput;
698

699
typedef struct SField {
700
  char    name[TSDB_COL_NAME_LEN];
701
  uint8_t type;
702
  int8_t  flags;
703
  int32_t bytes;
704
} SField;
705

706
typedef struct SFieldWithOptions {
707
  char     name[TSDB_COL_NAME_LEN];
708
  uint8_t  type;
709
  int8_t   flags;
710
  int32_t  bytes;
711
  uint32_t compress;
712
  STypeMod typeMod;
713
} SFieldWithOptions;
714

715
typedef struct SRetention {
716
  int64_t freq;
717
  int64_t keep;
718
  int8_t  freqUnit;
719
  int8_t  keepUnit;
720
} SRetention;
721

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

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

731
typedef struct {
732
  int32_t contLen;
733
  int32_t vgId;
734
} SMsgHead;
735

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

747
// Submit message for this TSDB
748
typedef struct {
749
  SMsgHead header;
750
  int64_t  version;
751
  int32_t  length;
752
  int32_t  numOfBlocks;
753
  char     blocks[];
754
} SSubmitReq;
755

756
typedef struct {
757
  int32_t totalLen;
758
  int32_t len;
759
  STSRow* row;
760
} SSubmitBlkIter;
761

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

777
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
778
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
779
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
780
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
781
// for debug
782
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
783

784
typedef struct {
785
  bool     hasRef;
786
  col_id_t id;
787
  char     refDbName[TSDB_DB_NAME_LEN];
788
  char     refTableName[TSDB_TABLE_NAME_LEN];
789
  char     refColName[TSDB_COL_NAME_LEN];
790
  char     colName[TSDB_COL_NAME_LEN];     // for tmq get json
791
} SColRef;
792

793
typedef struct {
794
  int32_t  nCols;
795
  int32_t  version;
796
  SColRef* pColRef;
797
} SColRefWrapper;
798

799
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
800
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
801
typedef struct {
802
  int32_t vgId;
803
  SColRef colRef;
804
} SColRefEx;
805

806
typedef struct {
807
  int16_t colId;
808
  char    refDbName[TSDB_DB_NAME_LEN];
809
  char    refTableName[TSDB_TABLE_NAME_LEN];
810
  char    refColName[TSDB_COL_NAME_LEN];
811
} SRefColInfo;
812

813
typedef struct SVCTableRefCols {
814
  uint64_t     uid;
815
  int32_t      numOfSrcTbls;
816
  int32_t      numOfColRefs;
817
  SRefColInfo* refCols;
818
} SVCTableRefCols;
819

820
typedef struct SVCTableMergeInfo {
821
  uint64_t uid;
822
  int32_t  numOfSrcTbls;
823
} SVCTableMergeInfo;
824

825
typedef struct {
826
  int32_t    nCols;
827
  SColRefEx* pColRefEx;
828
} SColRefExWrapper;
829

830
struct SSchema {
831
  int8_t   type;
832
  int8_t   flags;
833
  col_id_t colId;
834
  int32_t  bytes;
835
  char     name[TSDB_COL_NAME_LEN];
836
};
837
struct SSchemaExt {
838
  col_id_t colId;
839
  uint32_t compress;
840
  STypeMod typeMod;
841
};
842

843
struct SSchemaRsma {
844
  int64_t    interval[2];
845
  int32_t    nFuncs;
846
  int8_t     tbType;
847
  tb_uid_t   tbUid;
848
  func_id_t* funcIds;
849
  char       tbName[TSDB_TABLE_NAME_LEN];
850
};
851

852
struct SSchema2 {
853
  int8_t   type;
854
  int8_t   flags;
855
  col_id_t colId;
856
  int32_t  bytes;
857
  char     name[TSDB_COL_NAME_LEN];
858
  uint32_t compress;
859
};
860

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

894
typedef struct {
895
  int32_t        code;
896
  int64_t        uid;
897
  char*          tblFName;
898
  int32_t        numOfRows;
899
  int32_t        affectedRows;
900
  int64_t        sver;
901
  STableMetaRsp* pMeta;
902
} SSubmitBlkRsp;
903

904
typedef struct {
905
  int32_t numOfRows;
906
  int32_t affectedRows;
907
  int32_t nBlocks;
908
  union {
909
    SArray*        pArray;
910
    SSubmitBlkRsp* pBlocks;
911
  };
912
} SSubmitRsp;
913

914
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
915
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
916
// void    tFreeSSubmitBlkRsp(void* param);
917
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
918

919
#define COL_SMA_ON       ((int8_t)0x1)
920
#define COL_IDX_ON       ((int8_t)0x2)
921
#define COL_IS_KEY       ((int8_t)0x4)
922
#define COL_SET_NULL     ((int8_t)0x10)
923
#define COL_SET_VAL      ((int8_t)0x20)
924
#define COL_IS_SYSINFO   ((int8_t)0x40)
925
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
926
#define COL_REF_BY_STM   ((int8_t)0x08)
927

928
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
929
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
930

931
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
932
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
933
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
934

935
#define SSCHMEA_SET_IDX_ON(s) \
936
  do {                        \
937
    (s)->flags |= COL_IDX_ON; \
938
  } while (0)
939

940
#define SSCHMEA_SET_IDX_OFF(s)   \
941
  do {                           \
942
    (s)->flags &= (~COL_IDX_ON); \
943
  } while (0)
944

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

950
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
951

952
#define SSCHMEA_TYPE(s)  ((s)->type)
953
#define SSCHMEA_FLAGS(s) ((s)->flags)
954
#define SSCHMEA_COLID(s) ((s)->colId)
955
#define SSCHMEA_BYTES(s) ((s)->bytes)
956
#define SSCHMEA_NAME(s)  ((s)->name)
957

958
typedef struct {
959
  bool    tsEnableMonitor;
960
  int32_t tsMonitorInterval;
961
  int32_t tsSlowLogThreshold;
962
  int32_t tsSlowLogMaxLen;
963
  int32_t tsSlowLogScope;
964
  int32_t tsSlowLogThresholdTest;  // Obsolete
965
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
966
} SMonitorParas;
967

968
typedef struct {
969
  STypeMod typeMod;
970
} SExtSchema;
971

972
bool hasExtSchema(const SExtSchema* pExtSchema);
973

974
typedef struct {
975
  int32_t      nCols;
976
  int32_t      version;
977
  SSchema*     pSchema;
978
  SSchemaRsma* pRsma;
979
} SSchemaWrapper;
980

981
typedef struct {
982
  col_id_t id;
983
  uint32_t alg;
984
} SColCmpr;
985

986
typedef struct {
987
  int32_t   nCols;
988
  int32_t   version;
989
  SColCmpr* pColCmpr;
990
} SColCmprWrapper;
991

992
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
993
  if (pRef->pColRef) {
497,632✔
994
    return TSDB_CODE_INVALID_PARA;
×
995
  }
996
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
497,632✔
997
  if (pRef->pColRef == NULL) {
497,632✔
998
    return terrno;
×
999
  }
1000
  pRef->nCols = nCols;
497,632✔
1001
  for (int32_t i = 0; i < nCols; i++) {
149,658,282✔
1002
    pRef->pColRef[i].hasRef = false;
149,160,650✔
1003
    pRef->pColRef[i].id = (col_id_t)(i + 1);
149,160,650✔
1004
  }
1005
  return 0;
497,632✔
1006
}
1007

1008
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
1009
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1010
    terrno = TSDB_CODE_INVALID_PARA;
1011
    return NULL;
1012
  }
1013

1014
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1015
  if (pDstWrapper == NULL) {
1016
    return NULL;
1017
  }
1018
  pDstWrapper->nCols = pSrcWrapper->nCols;
1019
  pDstWrapper->version = pSrcWrapper->version;
1020

1021
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1022
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1023
  if (pDstWrapper->pColCmpr == NULL) {
1024
    taosMemoryFree(pDstWrapper);
1025
    return NULL;
1026
  }
1027
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1028

1029
  return pDstWrapper;
1030
}
1031

1032
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1033
  if (!(!pCmpr->pColCmpr)) {
6,948,732✔
1034
    return TSDB_CODE_INVALID_PARA;
×
1035
  }
1036
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
6,948,732✔
1037
  if (pCmpr->pColCmpr == NULL) {
6,948,732✔
1038
    return terrno;
×
1039
  }
1040
  pCmpr->nCols = nCols;
6,948,732✔
1041
  return 0;
6,948,732✔
1042
}
1043

1044
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
1045
  pCmpr->nCols = pSchema->nCols;
1046
  if (!(!pCmpr->pColCmpr)) {
1047
    return TSDB_CODE_INVALID_PARA;
1048
  }
1049
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
1050
  if (pCmpr->pColCmpr == NULL) {
1051
    return terrno;
1052
  }
1053
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
1054
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
1055
    SSchema*  pColSchema = &pSchema->pSchema[i];
1056
    pColCmpr->id = pColSchema->colId;
1057
    pColCmpr->alg = 0;
1058
  }
1059
  return 0;
1060
}
1061

1062
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1063
  if (pWrapper == NULL) return;
1064

1065
  taosMemoryFreeClear(pWrapper->pColCmpr);
1066
  taosMemoryFreeClear(pWrapper);
1067
}
1068
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1069
  if (pSchemaWrapper->pSchema == NULL) return NULL;
628,852,146✔
1070

1071
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
628,820,023✔
1072
  if (pSW == NULL) {
628,746,038✔
1073
    return NULL;
×
1074
  }
1075
  pSW->nCols = pSchemaWrapper->nCols;
628,746,038✔
1076
  pSW->version = pSchemaWrapper->version;
628,766,646✔
1077
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
628,709,101✔
1078
  if (pSW->pSchema == NULL) {
628,612,871✔
1079
    taosMemoryFree(pSW);
×
1080
    return NULL;
×
1081
  }
1082

1083
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
628,632,065✔
1084
  return pSW;
628,932,215✔
1085
}
1086

1087
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
138,386,000✔
1088
  if (pSchemaWrapper) {
1,408,557,279✔
1089
    taosMemoryFree(pSchemaWrapper->pSchema);
979,177,194✔
1090
    if (pSchemaWrapper->pRsma) {
979,086,951✔
1091
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
27,676✔
1092
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
27,676✔
1093
    }
1094
    taosMemoryFree(pSchemaWrapper);
979,111,819✔
1095
  }
1096
}
1,365,548,488✔
1097

1098
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1099
  if (pSchemaWrapper) {
1100
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1101
    if (pSchemaWrapper->pRsma) {
1102
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1103
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1104
    }
1105
  }
1106
}
1107

1108
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
7,052,212✔
1109
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,052,212✔
1110
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,055,201✔
1111
  }
1112
}
7,050,516✔
1113

1114
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1115
  int32_t tlen = 0;
2,610,346✔
1116
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,612,692✔
1117
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,610,346✔
1118
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,610,346✔
1119
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,610,346✔
1120
  tlen += taosEncodeString(buf, pSchema->name);
2,610,346✔
1121
  return tlen;
2,610,346✔
1122
}
1123

1124
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1125
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,201,128✔
1126
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,200,627✔
1127
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,200,627✔
1128
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,200,627✔
1129
  buf = taosDecodeStringTo(buf, pSchema->name);
1,200,627✔
1130
  return (void*)buf;
1,200,627✔
1131
}
1132

1133
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1134
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1135
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1136
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1137
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1138
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1139
  return 0;
2,147,483,647✔
1140
}
1141

1142
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1143
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1144
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1145
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1146
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1147
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1148
  return 0;
2,147,483,647✔
1149
}
1150

1151
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1152
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1153
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1154
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1155
  return 0;
2,147,483,647✔
1156
}
1157

1158
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1159
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1160
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1161
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1162
  return 0;
2,147,483,647✔
1163
}
1164

1165
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1166
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
906,439,492✔
1167
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
906,439,492✔
1168
  if (pColRef->hasRef) {
453,219,746✔
1169
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
601,546,068✔
1170
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
601,546,068✔
1171
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
601,546,068✔
1172
  }
1173
  return 0;
453,219,746✔
1174
}
1175

1176
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1177
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
454,196,048✔
1178
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
454,196,048✔
1179
  if (pColRef->hasRef) {
227,098,024✔
1180
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
150,715,205✔
1181
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
150,715,205✔
1182
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
150,715,205✔
1183
  }
1184

1185
  return 0;
227,098,024✔
1186
}
1187

1188
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1189
  int32_t tlen = 0;
431,504✔
1190
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
431,504✔
1191
  tlen += taosEncodeVariantI32(buf, pSW->version);
431,504✔
1192
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,041,850✔
1193
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,220,692✔
1194
  }
1195
  return tlen;
431,504✔
1196
}
1197

1198
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1199
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
192,356✔
1200
  buf = taosDecodeVariantI32(buf, &pSW->version);
192,356✔
1201
  if (pSW->nCols > 0) {
192,356✔
1202
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
192,356✔
1203
    if (pSW->pSchema == NULL) {
192,356✔
1204
      return NULL;
×
1205
    }
1206

1207
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,392,983✔
1208
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,401,254✔
1209
    }
1210
  } else {
1211
    pSW->pSchema = NULL;
×
1212
  }
1213
  return (void*)buf;
192,356✔
1214
}
1215

1216
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1217
  if (pSW == NULL) {
279,163,063✔
1218
    return TSDB_CODE_INVALID_PARA;
×
1219
  }
1220
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
558,303,569✔
1221
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
558,193,225✔
1222
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1223
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1224
  }
1225
  return 0;
279,242,538✔
1226
}
1227

1228
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1229
  if (pSW == NULL) {
118,986,952✔
1230
    return TSDB_CODE_INVALID_PARA;
×
1231
  }
1232
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
237,934,108✔
1233
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
237,926,064✔
1234

1235
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
118,978,908✔
1236
  if (pSW->pSchema == NULL) {
118,933,028✔
1237
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1238
  }
1239
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,298,009,856✔
1240
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1241
  }
1242

1243
  return 0;
119,009,367✔
1244
}
1245

1246
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1247
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1248
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1249

1250
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1251
  if (pSW->pSchema == NULL) {
2,045,070,760✔
1252
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1253
  }
1254
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1255
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1256
  }
1257

1258
  return 0;
2,045,806,023✔
1259
}
1260

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

1295
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1296
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1297
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1298

1299
typedef struct {
1300
  STableMetaRsp* pMeta;
1301
} SMCreateStbRsp;
1302

1303
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1304
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1305
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1306

1307
typedef struct {
1308
  char     name[TSDB_TABLE_FNAME_LEN];
1309
  int8_t   igNotExists;
1310
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1311
  int8_t   reserved[6];
1312
  tb_uid_t suid;
1313
  int32_t  sqlLen;
1314
  char*    sql;
1315
} SMDropStbReq;
1316

1317
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1318
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1319
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1320

1321
typedef struct {
1322
  char    name[TSDB_TABLE_FNAME_LEN];
1323
  int8_t  alterType;
1324
  int32_t numOfFields;
1325
  SArray* pFields;
1326
  int32_t ttl;
1327
  int32_t commentLen;
1328
  char*   comment;
1329
  int32_t sqlLen;
1330
  char*   sql;
1331
  int64_t keep;
1332
  SArray* pTypeMods;
1333
  int8_t  secureDelete;
1334
} SMAlterStbReq;
1335

1336
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1337
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1338
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1339

1340
typedef struct SEpSet {
1341
  int8_t inUse;
1342
  int8_t numOfEps;
1343
  SEp    eps[TSDB_MAX_REPLICA];
1344
} SEpSet;
1345

1346
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1347
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1348
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1349
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1350

1351
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1352
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1353

1354
typedef struct {
1355
  int8_t  connType;
1356
  int32_t pid;
1357
  int32_t totpCode;
1358
  char    app[TSDB_APP_NAME_LEN];
1359
  char    db[TSDB_DB_NAME_LEN];
1360
  char    user[TSDB_USER_LEN];
1361
  char    passwd[TSDB_PASSWORD_LEN];
1362
  char    token[TSDB_TOKEN_LEN];
1363
  int64_t startTime;
1364
  int64_t connectTime;
1365
  char    sVer[TSDB_VERSION_LEN];
1366
  char    signature[20]; // SHA1 produces a 20-byte signature
1367
} SConnectReq;
1368

1369
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1370
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1371
void    tSignConnectReq(SConnectReq* pReq);
1372
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1373

1374
typedef struct {
1375
  int64_t       clusterId;
1376
  int32_t       acctId;
1377
  uint32_t      connId;
1378
  int32_t       dnodeNum;
1379
  int8_t        superUser;
1380
  int8_t        sysInfo;
1381
  int8_t        connType;
1382
  int8_t        enableAuditDelete;
1383
  SEpSet        epSet;
1384
  int32_t       svrTimestamp;
1385
  int32_t       passVer;
1386
  int32_t       authVer;
1387
  char          sVer[TSDB_VERSION_LEN];
1388
  char          sDetailVer[128];
1389
  int64_t       whiteListVer;
1390
  int64_t       timeWhiteListVer;
1391
  int64_t       userId;
1392
  SMonitorParas monitorParas;
1393
  char          user[TSDB_USER_LEN];
1394
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1395
  int8_t        enableAuditSelect;
1396
  int8_t        enableAuditInsert;
1397
  int8_t        auditLevel;
1398
} SConnectRsp;
1399

1400
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1401
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1402

1403
typedef struct {
1404
  char    user[TSDB_USER_LEN];
1405
  char    pass[TSDB_PASSWORD_LEN];
1406
  int32_t maxUsers;
1407
  int32_t maxDbs;
1408
  int32_t maxTimeSeries;
1409
  int32_t maxStreams;
1410
  int32_t accessState;  // Configured only by command
1411
  int64_t maxStorage;
1412
} SCreateAcctReq, SAlterAcctReq;
1413

1414
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1415
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1416

1417
typedef struct {
1418
  char    user[TSDB_USER_LEN];
1419
  int8_t  ignoreNotExists;
1420
  int32_t sqlLen;
1421
  char*   sql;
1422
} SDropUserReq, SDropAcctReq;
1423

1424
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1425
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1426
void    tFreeSDropUserReq(SDropUserReq* pReq);
1427

1428
typedef struct {
1429
  char name[TSDB_ROLE_LEN];
1430
  union {
1431
    uint8_t flag;
1432
    struct {
1433
      uint8_t ignoreExists : 1;
1434
      uint8_t reserve : 7;
1435
    };
1436
  };
1437
  int32_t sqlLen;
1438
  char*   sql;
1439
} SCreateRoleReq;
1440

1441
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1442
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1443
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1444

1445
typedef struct {
1446
  char name[TSDB_ROLE_LEN];
1447
  union {
1448
    uint8_t flag;
1449
    struct {
1450
      uint8_t ignoreNotExists : 1;
1451
      uint8_t reserve : 7;
1452
    };
1453
  };
1454
  int32_t sqlLen;
1455
  char*   sql;
1456
} SDropRoleReq;
1457

1458
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1459
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1460
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1461

1462
typedef struct {
1463
  SPrivSet privSet;
1464
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1465
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1466
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1467
  // delete can only specify conditions by cond and cannot specify columns
1468
  char*    cond;     // for table privileges
1469
  int32_t  condLen;  // for table privileges
1470
} SPrivSetReqArgs;
1471

1472
typedef struct {
1473
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1474
  uint8_t objType;    // none, db, table, view, rsma, topic, etc.
1475
  union {
1476
    uint32_t flag;
1477
    struct {
1478
      uint32_t lock : 1;     // lock or unlock role
1479
      uint32_t add : 1;      // add or remove
1480
      uint32_t sysPriv : 1;  // system or object privileges
1481
      uint32_t objLevel : 2;
1482
      uint32_t ignoreNotExists : 1;
1483
      uint32_t reserve : 26;
1484
    };
1485
  };
1486
  union {
1487
    SPrivSetReqArgs privileges;
1488
    char            roleName[TSDB_ROLE_LEN];
1489
  };
1490
  char    principal[TSDB_ROLE_LEN];      // role or user name
1491
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db
1492
  char    tblName[TSDB_TABLE_NAME_LEN];  // none, table, view, rsma, topic, etc.
1493
  int32_t sqlLen;
1494
  char*   sql;
1495
} SAlterRoleReq;
1496

1497
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1498
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1499
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1500

1501
typedef struct {
1502
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1503
  int32_t sqlLen;
1504
  char*   sql;
1505
} SDropEncryptAlgrReq;
1506

1507
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1508
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1509
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1510

1511
typedef struct SIpV4Range {
1512
  uint32_t ip;
1513
  uint32_t mask;
1514
} SIpV4Range;
1515

1516
typedef struct SIpv6Range {
1517
  uint64_t addr[2];
1518
  uint32_t mask;
1519
} SIpV6Range;
1520

1521
typedef struct {
1522
  int8_t type;   // 0: IPv4, 1: IPv6
1523
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1524
  union {
1525
    SIpV4Range ipV4;
1526
    SIpV6Range ipV6;
1527
  };
1528
} SIpRange;
1529

1530
typedef struct {
1531
  int32_t    num;
1532
  SIpV4Range pIpRange[];
1533
} SIpWhiteList;
1534

1535
typedef struct {
1536
  int32_t  num;
1537
  SIpRange pIpRanges[];
1538
} SIpWhiteListDual;
1539

1540
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1541
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1542
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1543
int32_t           createDefaultIp6Range(SIpRange* pRange);
1544
int32_t           createDefaultIp4Range(SIpRange* pRange);
1545

1546
typedef struct {
1547
  int32_t sessPerUser;
1548
  int32_t sessConnTime;
1549
  int32_t sessConnIdleTime;
1550
  int32_t sessMaxConcurrency;
1551
  int32_t sessMaxCallVnodeNum;
1552
} SUserSessCfg;
1553

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

1558
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1559
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1560
typedef struct {
1561
  int16_t year;
1562
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1563
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1564
  int8_t hour;
1565
  int8_t minute;
1566
  int8_t neg;   // this is a negative entry
1567
  int32_t duration; // duration in minute
1568
} SDateTimeRange;
1569

1570
bool isValidDateTimeRange(SDateTimeRange* pRange);
1571
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1572
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1573

1574
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1575
typedef struct {
1576
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1577
  bool neg;         // this is a negative entry
1578
  int32_t duration; // duration in seconds
1579
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1580
} SDateTimeWhiteListItem;
1581

1582
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1583
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1584

1585
typedef struct {
1586
  int32_t num;
1587
  SDateTimeWhiteListItem ranges[];
1588
} SDateTimeWhiteList;
1589

1590
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1591
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1592

1593

1594
typedef struct {
1595
  int8_t createType;
1596

1597
  int8_t hasSessionPerUser;
1598
  int8_t hasConnectTime;
1599
  int8_t hasConnectIdleTime;
1600
  int8_t hasCallPerSession;
1601
  int8_t hasVnodePerCall;
1602
  int8_t hasFailedLoginAttempts;
1603
  int8_t hasPasswordLifeTime;
1604
  int8_t hasPasswordReuseTime;
1605
  int8_t hasPasswordReuseMax;
1606
  int8_t hasPasswordLockTime;
1607
  int8_t hasPasswordGraceTime;
1608
  int8_t hasInactiveAccountTime;
1609
  int8_t hasAllowTokenNum;
1610

1611
  int8_t superUser;  // denote if it is a super user or not
1612
  int8_t ignoreExists;
1613

1614
  char   user[TSDB_USER_LEN];
1615
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1616
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1617

1618
  int8_t sysInfo;
1619
  int8_t createDb;
1620
  int8_t isImport;
1621
  int8_t changepass;
1622
  int8_t enable;
1623

1624
  int8_t negIpRanges;
1625
  int8_t negTimeRanges;
1626

1627
  int32_t sessionPerUser;
1628
  int32_t connectTime;
1629
  int32_t connectIdleTime;
1630
  int32_t callPerSession;
1631
  int32_t vnodePerCall;
1632
  int32_t failedLoginAttempts;
1633
  int32_t passwordLifeTime;
1634
  int32_t passwordReuseTime;
1635
  int32_t passwordReuseMax;
1636
  int32_t passwordLockTime;
1637
  int32_t passwordGraceTime;
1638
  int32_t inactiveAccountTime;
1639
  int32_t allowTokenNum;
1640

1641
  int32_t         numIpRanges;
1642
  SIpRange*       pIpDualRanges;
1643
  int32_t         numTimeRanges;
1644
  SDateTimeRange* pTimeRanges;
1645

1646
  int32_t sqlLen;
1647
  char*   sql;
1648
} SCreateUserReq;
1649

1650
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1651
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1652
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1653

1654
typedef struct {
1655
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1656
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1657
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1658
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1659
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1660
  int32_t sqlLen;
1661
  char*   sql;
1662
} SCreateEncryptAlgrReq;
1663

1664
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1665
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1666
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1667

1668
typedef struct {
1669
  int32_t dnodeId;
1670
  int64_t analVer;
1671
} SRetrieveAnalyticsAlgoReq;
1672

1673
typedef struct {
1674
  int64_t   ver;
1675
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1676
} SRetrieveAnalyticAlgoRsp;
1677

1678
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1679
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1680
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1681
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1682
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1683

1684
typedef struct {
1685
  int8_t alterType;
1686

1687
  int8_t isView;
1688

1689
  int8_t hasPassword;
1690
  int8_t hasTotpseed;
1691
  int8_t hasEnable;
1692
  int8_t hasSysinfo;
1693
  int8_t hasCreatedb;
1694
  int8_t hasChangepass;
1695
  int8_t hasSessionPerUser;
1696
  int8_t hasConnectTime;
1697
  int8_t hasConnectIdleTime;
1698
  int8_t hasCallPerSession;
1699
  int8_t hasVnodePerCall;
1700
  int8_t hasFailedLoginAttempts;
1701
  int8_t hasPasswordLifeTime;
1702
  int8_t hasPasswordReuseTime;
1703
  int8_t hasPasswordReuseMax;
1704
  int8_t hasPasswordLockTime;
1705
  int8_t hasPasswordGraceTime;
1706
  int8_t hasInactiveAccountTime;
1707
  int8_t hasAllowTokenNum;
1708

1709
  int8_t enable;
1710
  int8_t sysinfo;
1711
  int8_t createdb;
1712
  int8_t changepass;
1713

1714
  char   user[TSDB_USER_LEN];
1715
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1716
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1717
  int32_t sessionPerUser;
1718
  int32_t connectTime;
1719
  int32_t connectIdleTime;
1720
  int32_t callPerSession;
1721
  int32_t vnodePerCall;
1722
  int32_t failedLoginAttempts;
1723
  int32_t passwordLifeTime;
1724
  int32_t passwordReuseTime;
1725
  int32_t passwordReuseMax;
1726
  int32_t passwordLockTime;
1727
  int32_t passwordGraceTime;
1728
  int32_t inactiveAccountTime;
1729
  int32_t allowTokenNum;
1730

1731
  int32_t         numIpRanges;
1732
  int32_t         numTimeRanges;
1733
  int32_t         numDropIpRanges;
1734
  int32_t         numDropTimeRanges;
1735
  SIpRange*       pIpRanges;
1736
  SDateTimeRange* pTimeRanges;
1737
  SIpRange*       pDropIpRanges;
1738
  SDateTimeRange* pDropTimeRanges;
1739
  SPrivSet        privileges;
1740

1741
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1742
  char        tabName[TSDB_TABLE_NAME_LEN];
1743
  char*       tagCond;
1744
  int32_t     tagCondLen;
1745
  int32_t     sqlLen;
1746
  char*       sql;
1747
} SAlterUserReq;
1748

1749
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1750
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1751
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1752

1753
typedef struct {
1754
  char    name[TSDB_TOKEN_NAME_LEN];
1755
  char    user[TSDB_USER_LEN];
1756
  int8_t  enable;
1757
  int8_t  ignoreExists;
1758
  int32_t ttl;
1759
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1760
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1761

1762
  int32_t sqlLen;
1763
  char*   sql;
1764
} SCreateTokenReq;
1765

1766
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1767
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1768
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1769

1770
typedef struct {
1771
  char name[TSDB_TOKEN_NAME_LEN];
1772
  char user[TSDB_USER_LEN];
1773
  char token[TSDB_TOKEN_LEN];
1774
} SCreateTokenRsp;
1775

1776
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1777
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1778
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1779

1780
typedef struct {
1781
  char    name[TSDB_TOKEN_NAME_LEN];
1782

1783
  int8_t hasEnable;
1784
  int8_t hasTtl;
1785
  int8_t hasProvider;
1786
  int8_t hasExtraInfo;
1787

1788
  int8_t  enable;
1789
  int32_t ttl;
1790
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1791
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1792

1793
  int32_t     sqlLen;
1794
  char*       sql;
1795
} SAlterTokenReq;
1796

1797
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1798
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1799
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1800

1801
typedef struct {
1802
  char    name[TSDB_TOKEN_NAME_LEN];
1803
  int8_t  ignoreNotExists;
1804
  int32_t sqlLen;
1805
  char*   sql;
1806
} SDropTokenReq;
1807

1808
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1809
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1810
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1811

1812
typedef struct {
1813
  char    user[TSDB_USER_LEN];
1814
  int32_t sqlLen;
1815
  char*   sql;
1816
} SCreateTotpSecretReq;
1817

1818
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1819
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1820
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1821

1822
typedef struct {
1823
  char user[TSDB_USER_LEN];
1824
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1825
} SCreateTotpSecretRsp;
1826

1827
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1828
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1829

1830
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1831
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1832
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1833
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1834

1835
typedef struct {
1836
  char user[TSDB_USER_LEN];
1837
} SGetUserAuthReq;
1838

1839
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1840
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1841

1842
typedef struct {
1843
  int8_t  enabled;
1844
  int32_t expireTime;
1845
} STokenStatus;
1846

1847
typedef struct {
1848
  char    user[TSDB_USER_LEN];
1849
  int64_t userId;
1850
  int32_t version;
1851
  int32_t passVer;
1852
  int8_t  superAuth;
1853
  int8_t  sysInfo;
1854
  int8_t  enable;
1855
  int8_t  dropped;
1856
  union {
1857
    uint8_t flags;
1858
    struct {
1859
      uint8_t privLevel : 3;
1860
      uint8_t withInsertCond : 1;
1861
      uint8_t reserve : 4;
1862
    };
1863
  };
1864
  SPrivSet  sysPrivs;
1865
  SHashObj* objPrivs;
1866
  SHashObj* selectTbs;
1867
  SHashObj* insertTbs;
1868
  SHashObj* deleteTbs;
1869
  SHashObj* ownedDbs;
1870
  int64_t   whiteListVer;
1871

1872
  SUserSessCfg sessCfg;
1873
  int64_t      timeWhiteListVer;
1874
  SHashObj*    tokens;
1875
} SGetUserAuthRsp;
1876

1877
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1878
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1879
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1880

1881
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1882
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1883
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1884
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1885

1886
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1887
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1888
typedef struct {
1889
  int64_t ver;
1890
  char    user[TSDB_USER_LEN];
1891
  int32_t numOfRange;
1892
  union {
1893
    SIpV4Range* pIpRanges;
1894
    SIpRange*   pIpDualRanges;
1895
  };
1896
} SUpdateUserIpWhite;
1897

1898
typedef struct {
1899
  int64_t             ver;
1900
  int                 numOfUser;
1901
  SUpdateUserIpWhite* pUserIpWhite;
1902
} SUpdateIpWhite;
1903

1904
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1905
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1906
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1907
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1908

1909
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1910
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1911
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1912

1913

1914
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1915
// corresponding response struct is different.
1916
typedef struct {
1917
  int64_t ver;
1918
} SRetrieveWhiteListReq;
1919

1920
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1921
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1922

1923

1924
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1925
// corresponding response struct is different.
1926
typedef struct {
1927
  char user[TSDB_USER_LEN];
1928
} SGetUserWhiteListReq;
1929

1930
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1931
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1932

1933
typedef struct {
1934
  char    user[TSDB_USER_LEN];
1935
  int32_t numWhiteLists;
1936
  union {
1937
    SIpV4Range* pWhiteLists;
1938
    SIpRange*   pWhiteListsDual;
1939
  };
1940
} SGetUserIpWhiteListRsp;
1941

1942
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1943
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1944
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1945
void    tIpRangeSetDefaultMask(SIpRange* range);
1946

1947
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1948
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1949
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1950

1951
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1952
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1953
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1954

1955
typedef struct {
1956
  int64_t ver;
1957
  char    user[TSDB_USER_LEN];
1958
  int32_t numWhiteLists;
1959
  SDateTimeWhiteListItem* pWhiteLists;
1960
} SUserDateTimeWhiteList;
1961

1962

1963
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1964
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1965
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1966
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1967

1968
typedef struct {
1969
  int64_t             ver;
1970
  int                 numOfUser;
1971
  SUserDateTimeWhiteList *pUsers;
1972
} SRetrieveDateTimeWhiteListRsp;
1973

1974
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1975
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1976
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1977
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1978

1979
/*
1980
 * for client side struct, only column id, type, bytes are necessary
1981
 * But for data in vnode side, we need all the following information.
1982
 */
1983
typedef struct {
1984
  union {
1985
    col_id_t colId;
1986
    int16_t  slotId;
1987
  };
1988

1989
  uint8_t precision;
1990
  uint8_t scale;
1991
  int32_t bytes;
1992
  int8_t  type;
1993
  uint8_t pk;
1994
  bool    noData;
1995
} SColumnInfo;
1996

1997
typedef struct STimeWindow {
1998
  TSKEY skey;
1999
  TSKEY ekey;
2000
} STimeWindow;
2001

2002
typedef struct SQueryHint {
2003
  bool batchScan;
2004
} SQueryHint;
2005

2006
typedef struct {
2007
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
2008
  int32_t tsLen;          // total length of ts comp block
2009
  int32_t tsNumOfBlocks;  // ts comp block numbers
2010
  int32_t tsOrder;        // ts comp block order
2011
} STsBufInfo;
2012

2013
typedef struct {
2014
  void*       timezone;
2015
  char        intervalUnit;
2016
  char        slidingUnit;
2017
  char        offsetUnit;
2018
  int8_t      precision;
2019
  int64_t     interval;
2020
  int64_t     sliding;
2021
  int64_t     offset;
2022
  STimeWindow timeRange;
2023
} SInterval;
2024

2025
typedef struct STbVerInfo {
2026
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2027
  int32_t sversion;
2028
  int32_t tversion;
2029
  int32_t rversion;  // virtual table's column ref's version
2030
} STbVerInfo;
2031

2032
typedef struct {
2033
  int32_t code;
2034
  int64_t affectedRows;
2035
  SArray* tbVerInfo;  // STbVerInfo
2036
} SQueryTableRsp;
2037

2038
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2039

2040
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2041

2042
typedef struct {
2043
  SMsgHead header;
2044
  char     dbFName[TSDB_DB_FNAME_LEN];
2045
  char     tbName[TSDB_TABLE_NAME_LEN];
2046
} STableCfgReq;
2047

2048
typedef struct {
2049
  char        tbName[TSDB_TABLE_NAME_LEN];
2050
  char        stbName[TSDB_TABLE_NAME_LEN];
2051
  char        dbFName[TSDB_DB_FNAME_LEN];
2052
  int32_t     numOfTags;
2053
  int32_t     numOfColumns;
2054
  int8_t      tableType;
2055
  int64_t     delay1;
2056
  int64_t     delay2;
2057
  int64_t     watermark1;
2058
  int64_t     watermark2;
2059
  int32_t     ttl;
2060
  int32_t     keep;
2061
  int64_t     ownerId;
2062
  SArray*     pFuncs;
2063
  int32_t     commentLen;
2064
  char*       pComment;
2065
  SSchema*    pSchemas;
2066
  int32_t     tagsLen;
2067
  char*       pTags;
2068
  SSchemaExt* pSchemaExt;
2069
  union {
2070
    uint8_t flag;
2071
    struct {
2072
      uint8_t virtualStb : 1;  // no compatibility problem for little-endian arch
2073
      uint8_t isAudit : 1;
2074
      uint8_t reserve : 6;
2075
    };
2076
  };
2077
  SColRef* pColRefs;
2078
  int8_t   secureDelete;
2079
} STableCfg;
2080

2081
typedef STableCfg STableCfgRsp;
2082

2083
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2084
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2085

2086
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2087
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2088
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2089

2090
typedef struct {
2091
  SMsgHead header;
2092
  tb_uid_t suid;
2093
} SVSubTablesReq;
2094

2095
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2096
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2097

2098
typedef struct {
2099
  int32_t vgId;
2100
  SArray* pTables;  // SArray<SVCTableRefCols*>
2101
} SVSubTablesRsp;
2102

2103
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2104
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2105
void    tDestroySVSubTablesRsp(void* rsp);
2106

2107
typedef struct {
2108
  SMsgHead header;
2109
  tb_uid_t suid;
2110
} SVStbRefDbsReq;
2111

2112
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2113
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2114

2115
typedef struct {
2116
  int32_t vgId;
2117
  SArray* pDbs;  // SArray<char* (db name)>
2118
} SVStbRefDbsRsp;
2119

2120
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2121
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2122
void    tDestroySVStbRefDbsRsp(void* rsp);
2123

2124
typedef struct {
2125
  char    db[TSDB_DB_FNAME_LEN];
2126
  int32_t numOfVgroups;
2127
  int32_t numOfStables;  // single_stable
2128
  int32_t buffer;        // MB
2129
  int32_t pageSize;
2130
  int32_t pages;
2131
  int32_t cacheLastSize;
2132
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2133
  int32_t daysPerFile;
2134
  int32_t daysToKeep0;
2135
  int32_t daysToKeep1;
2136
  int32_t daysToKeep2;
2137
  int32_t keepTimeOffset;
2138
  int32_t minRows;
2139
  int32_t maxRows;
2140
  int32_t walFsyncPeriod;
2141
  int8_t  walLevel;
2142
  int8_t  precision;  // time resolution
2143
  int8_t  compression;
2144
  int8_t  replications;
2145
  int8_t  strict;
2146
  int8_t  cacheLast;
2147
  int8_t  schemaless;
2148
  int8_t  ignoreExist;
2149
  int32_t numOfRetensions;
2150
  SArray* pRetensions;  // SRetention
2151
  int32_t walRetentionPeriod;
2152
  int64_t walRetentionSize;
2153
  int32_t walRollPeriod;
2154
  int64_t walSegmentSize;
2155
  int32_t sstTrigger;
2156
  int16_t hashPrefix;
2157
  int16_t hashSuffix;
2158
  int32_t ssChunkSize;
2159
  int32_t ssKeepLocal;
2160
  int8_t  ssCompact;
2161
  int32_t tsdbPageSize;
2162
  int32_t sqlLen;
2163
  char*   sql;
2164
  int8_t  withArbitrator;
2165
  int8_t  encryptAlgorithm;
2166
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2167
  // 1. add auto-compact parameters
2168
  int32_t compactInterval;    // minutes
2169
  int32_t compactStartTime;   // minutes
2170
  int32_t compactEndTime;     // minutes
2171
  int8_t  compactTimeOffset;  // hour
2172
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2173
  int8_t  isAudit;
2174
  int8_t  allowDrop;
2175
  int8_t  secureDelete;
2176
} SCreateDbReq;
2177

2178
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2179
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2180
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2181

2182
typedef struct {
2183
  char    db[TSDB_DB_FNAME_LEN];
2184
  int32_t buffer;
2185
  int32_t pageSize;
2186
  int32_t pages;
2187
  int32_t cacheLastSize;
2188
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2189
  int32_t daysPerFile;
2190
  int32_t daysToKeep0;
2191
  int32_t daysToKeep1;
2192
  int32_t daysToKeep2;
2193
  int32_t keepTimeOffset;
2194
  int32_t walFsyncPeriod;
2195
  int8_t  walLevel;
2196
  int8_t  strict;
2197
  int8_t  cacheLast;
2198
  int8_t  replications;
2199
  int32_t sstTrigger;
2200
  int32_t minRows;
2201
  int32_t walRetentionPeriod;
2202
  int32_t walRetentionSize;
2203
  int32_t ssKeepLocal;
2204
  int8_t  ssCompact;
2205
  int32_t sqlLen;
2206
  char*   sql;
2207
  int8_t  withArbitrator;
2208
  // 1. add auto-compact parameters
2209
  int32_t compactInterval;
2210
  int32_t compactStartTime;
2211
  int32_t compactEndTime;
2212
  int8_t  compactTimeOffset;
2213
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2214
  int8_t  isAudit;
2215
  int8_t  allowDrop;
2216
  int8_t  secureDelete;
2217
} SAlterDbReq;
2218

2219
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2220
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2221
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2222

2223
typedef struct {
2224
  char    db[TSDB_DB_FNAME_LEN];
2225
  int8_t  ignoreNotExists;
2226
  int8_t  force;
2227
  int32_t sqlLen;
2228
  char*   sql;
2229
} SDropDbReq;
2230

2231
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2232
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2233
void    tFreeSDropDbReq(SDropDbReq* pReq);
2234

2235
typedef struct {
2236
  char    db[TSDB_DB_FNAME_LEN];
2237
  int64_t uid;
2238
} SDropDbRsp;
2239

2240
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2241
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2242

2243
typedef struct {
2244
  char    name[TSDB_MOUNT_NAME_LEN];
2245
  int64_t uid;
2246
} SDropMountRsp;
2247

2248
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2249
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2250

2251
typedef struct {
2252
  char    db[TSDB_DB_FNAME_LEN];
2253
  int64_t dbId;
2254
  int32_t vgVersion;
2255
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2256
  int64_t stateTs;     // ms
2257
} SUseDbReq;
2258

2259
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2260
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2261

2262
typedef struct {
2263
  char    db[TSDB_DB_FNAME_LEN];
2264
  int64_t uid;
2265
  int32_t vgVersion;
2266
  int32_t vgNum;
2267
  int16_t hashPrefix;
2268
  int16_t hashSuffix;
2269
  int8_t  hashMethod;
2270
  union {
2271
    uint8_t flags;
2272
    struct {
2273
      uint8_t isMount : 1;  // TS-5868
2274
      uint8_t padding : 7;
2275
    };
2276
  };
2277
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2278
  int32_t errCode;
2279
  int64_t stateTs;  // ms
2280
} SUseDbRsp;
2281

2282
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2283
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2284
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2285
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2286
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2287

2288
typedef struct {
2289
  char db[TSDB_DB_FNAME_LEN];
2290
} SDbCfgReq;
2291

2292
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2293
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2294

2295
typedef struct {
2296
  char db[TSDB_DB_FNAME_LEN];
2297
} SSsMigrateDbReq;
2298

2299
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2300
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2301

2302
typedef struct {
2303
  int32_t ssMigrateId;
2304
  bool    bAccepted;
2305
} SSsMigrateDbRsp;
2306

2307
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2308
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2309

2310
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2311
typedef struct {
2312
  int32_t ssMigrateId;
2313
} SListSsMigrateFileSetsReq;
2314

2315
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2316
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2317

2318
typedef struct {
2319
  int32_t ssMigrateId;
2320
  int32_t vgId;       // vgroup id
2321
  SArray* pFileSets;  // SArray<int32_t>
2322
} SListSsMigrateFileSetsRsp;
2323

2324
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2325
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2326
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2327

2328
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2329
typedef struct {
2330
  int32_t ssMigrateId;
2331
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2332
  int32_t fid;
2333
  int64_t startTimeSec;
2334
} SSsMigrateFileSetReq;
2335

2336
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2337
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2338

2339
typedef struct {
2340
  int32_t ssMigrateId;
2341
  int32_t nodeId;  // node id of the leader vnode
2342
  int32_t vgId;
2343
  int32_t fid;
2344
} SSsMigrateFileSetRsp;
2345

2346
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2347
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2348

2349
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2350
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2351
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2352
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2353
#define SSMIGRATE_FILESET_STATE_FAILED      4
2354

2355
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2356
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2357
// while as a request, the 'state' field is not used.
2358
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2359
typedef struct {
2360
  int32_t ssMigrateId;  // ss migrate id
2361
  int32_t nodeId;       // node id of the leader vnode
2362
  int32_t vgId;         // vgroup id
2363
  int32_t fid;          // file set id
2364
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2365
} SSsMigrateProgress;
2366

2367
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2368
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2369

2370
// Request for TDMT_MND_KILL_SSMIGRATE
2371
typedef struct {
2372
  int32_t ssMigrateId;
2373
  int32_t sqlLen;
2374
  char*   sql;
2375
} SKillSsMigrateReq;
2376

2377
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2378
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2379
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2380

2381
// Request for TDMT_VND_KILL_SSMIGRATE
2382
typedef struct {
2383
  int32_t ssMigrateId;
2384
} SVnodeKillSsMigrateReq;
2385

2386
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2387
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2388

2389
typedef struct {
2390
  int32_t vgId;
2391
  int64_t keepVersion;
2392
} SMndSetVgroupKeepVersionReq;
2393

2394
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2395
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2396

2397
typedef struct {
2398
  int32_t timestampSec;
2399
  int32_t ttlDropMaxCount;
2400
  int32_t nUids;
2401
  SArray* pTbUids;
2402
} SVDropTtlTableReq;
2403

2404
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2405
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2406

2407
typedef struct {
2408
  char    db[TSDB_DB_FNAME_LEN];
2409
  int64_t dbId;
2410
  int64_t ownerId;
2411
  int32_t cfgVersion;
2412
  int32_t numOfVgroups;
2413
  int32_t numOfStables;
2414
  int32_t buffer;
2415
  int32_t cacheSize;
2416
  int32_t cacheShardBits;
2417
  int32_t pageSize;
2418
  int32_t pages;
2419
  int32_t daysPerFile;
2420
  int32_t daysToKeep0;
2421
  int32_t daysToKeep1;
2422
  int32_t daysToKeep2;
2423
  int32_t keepTimeOffset;
2424
  int32_t minRows;
2425
  int32_t maxRows;
2426
  int32_t walFsyncPeriod;
2427
  int16_t hashPrefix;
2428
  int16_t hashSuffix;
2429
  int8_t  hashMethod;
2430
  int8_t  walLevel;
2431
  int8_t  precision;
2432
  int8_t  compression;
2433
  int8_t  replications;
2434
  int8_t  strict;
2435
  int8_t  cacheLast;
2436
  int8_t  encryptAlgr;
2437
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2438
  int32_t ssChunkSize;
2439
  int32_t ssKeepLocal;
2440
  int8_t  ssCompact;
2441
  union {
2442
    uint8_t flags;
2443
    struct {
2444
      uint8_t isMount : 1;    // TS-5868
2445
      uint8_t allowDrop : 1;  // TS-7232
2446
      uint8_t padding : 6;
2447
    };
2448
  };
2449
  int8_t  compactTimeOffset;
2450
  int32_t compactInterval;
2451
  int32_t compactStartTime;
2452
  int32_t compactEndTime;
2453
  int32_t tsdbPageSize;
2454
  int32_t walRetentionPeriod;
2455
  int32_t walRollPeriod;
2456
  int64_t walRetentionSize;
2457
  int64_t walSegmentSize;
2458
  int32_t numOfRetensions;
2459
  SArray* pRetensions;
2460
  int8_t  schemaless;
2461
  int16_t sstTrigger;
2462
  int8_t  withArbitrator;
2463
  int8_t  isAudit;
2464
  int8_t  secureDelete;
2465
} SDbCfgRsp;
2466

2467
typedef SDbCfgRsp SDbCfgInfo;
2468

2469
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2470
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2471
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2472
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2473
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2474

2475
typedef struct {
2476
  int32_t rowNum;
2477
} SQnodeListReq;
2478

2479
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2480
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2481

2482
typedef struct {
2483
  int32_t rowNum;
2484
} SDnodeListReq;
2485

2486
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2487

2488
typedef struct {
2489
  int32_t useless;  // useless
2490
} SServerVerReq;
2491

2492
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2493
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2494

2495
typedef struct {
2496
  char ver[TSDB_VERSION_LEN];
2497
} SServerVerRsp;
2498

2499
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2500
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2501

2502
typedef struct SQueryNodeAddr {
2503
  int32_t nodeId;  // vgId or qnodeId
2504
  SEpSet  epSet;
2505
} SQueryNodeAddr;
2506

2507
typedef struct {
2508
  SQueryNodeAddr addr;
2509
  uint64_t       load;
2510
} SQueryNodeLoad;
2511

2512
typedef struct {
2513
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2514
} SQnodeListRsp;
2515

2516
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2517
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2518
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2519

2520

2521
typedef struct SDownstreamSourceNode {
2522
  ENodeType      type;
2523
  SQueryNodeAddr addr;
2524
  uint64_t       clientId;
2525
  uint64_t       taskId;
2526
  uint64_t       sId;
2527
  uint64_t       srcTaskId;
2528
  int32_t        execId;
2529
  int32_t        fetchMsgType;
2530
  bool           localExec;
2531
} SDownstreamSourceNode;
2532

2533

2534

2535
typedef struct SDNodeAddr {
2536
  int32_t nodeId;  // dnodeId
2537
  SEpSet  epSet;
2538
} SDNodeAddr;
2539

2540
typedef struct {
2541
  SArray* dnodeList;  // SArray<SDNodeAddr>
2542
} SDnodeListRsp;
2543

2544
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2545
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2546
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2547

2548
typedef struct {
2549
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2550
} STableTSMAInfoRsp;
2551

2552
typedef struct {
2553
  SUseDbRsp*         useDbRsp;
2554
  SDbCfgRsp*         cfgRsp;
2555
  STableTSMAInfoRsp* pTsmaRsp;
2556
  int32_t            dbTsmaVersion;
2557
  char               db[TSDB_DB_FNAME_LEN];
2558
  int64_t            dbId;
2559
} SDbHbRsp;
2560

2561
typedef struct {
2562
  SArray* pArray;  // Array of SDbHbRsp
2563
} SDbHbBatchRsp;
2564

2565
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2566
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2567
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2568

2569
typedef struct {
2570
  SArray* pArray;  // Array of SGetUserAuthRsp
2571
} SUserAuthBatchRsp;
2572

2573
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2574
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2575
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2576

2577
typedef struct {
2578
  char        db[TSDB_DB_FNAME_LEN];
2579
  STimeWindow timeRange;
2580
  int32_t     sqlLen;
2581
  char*       sql;
2582
  SArray*     vgroupIds;
2583
  int32_t     compactId;
2584
  int8_t      metaOnly;
2585
  int8_t      force;
2586
} SCompactDbReq;
2587

2588
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2589
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2590
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2591

2592
typedef struct {
2593
  union {
2594
    int32_t compactId;
2595
    int32_t id;
2596
  };
2597
  int8_t bAccepted;
2598
} SCompactDbRsp;
2599

2600
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2601
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2602

2603
typedef struct {
2604
  union {
2605
    int32_t compactId;
2606
    int32_t id;
2607
  };
2608
  int32_t sqlLen;
2609
  char*   sql;
2610
} SKillCompactReq;
2611

2612
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2613
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2614
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2615

2616
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2617
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2618

2619
typedef struct {
2620
  char    name[TSDB_FUNC_NAME_LEN];
2621
  int8_t  igExists;
2622
  int8_t  funcType;
2623
  int8_t  scriptType;
2624
  int8_t  outputType;
2625
  int32_t outputLen;
2626
  int32_t bufSize;
2627
  int32_t codeLen;
2628
  int64_t signature;
2629
  char*   pComment;
2630
  char*   pCode;
2631
  int8_t  orReplace;
2632
} SCreateFuncReq;
2633

2634
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2635
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2636
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2637

2638
typedef struct {
2639
  char   name[TSDB_FUNC_NAME_LEN];
2640
  int8_t igNotExists;
2641
} SDropFuncReq;
2642

2643
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2644
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2645

2646
typedef struct {
2647
  int32_t numOfFuncs;
2648
  bool    ignoreCodeComment;
2649
  SArray* pFuncNames;
2650
} SRetrieveFuncReq;
2651

2652
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2653
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2654
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2655

2656
typedef struct {
2657
  char    name[TSDB_FUNC_NAME_LEN];
2658
  int8_t  funcType;
2659
  int8_t  scriptType;
2660
  int8_t  outputType;
2661
  int32_t outputLen;
2662
  int32_t bufSize;
2663
  int64_t signature;
2664
  int32_t commentSize;
2665
  int32_t codeSize;
2666
  char*   pComment;
2667
  char*   pCode;
2668
} SFuncInfo;
2669

2670
typedef struct {
2671
  int32_t funcVersion;
2672
  int64_t funcCreatedTime;
2673
} SFuncExtraInfo;
2674

2675
typedef struct {
2676
  int32_t numOfFuncs;
2677
  SArray* pFuncInfos;
2678
  SArray* pFuncExtraInfos;
2679
} SRetrieveFuncRsp;
2680

2681
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2682
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2683
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2684
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2685

2686
typedef struct {
2687
  int32_t       statusInterval;
2688
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2689
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2690
  char          locale[TD_LOCALE_LEN];      // tsLocale
2691
  char          charset[TD_LOCALE_LEN];     // tsCharset
2692
  int8_t        ttlChangeOnWrite;
2693
  int8_t        enableWhiteList;
2694
  int8_t        encryptionKeyStat;
2695
  uint32_t      encryptionKeyChksum;
2696
  SMonitorParas monitorParas;
2697
  int32_t       statusIntervalMs;
2698
} SClusterCfg;
2699

2700
typedef struct {
2701
  int32_t openVnodes;
2702
  int32_t dropVnodes;
2703
  int32_t totalVnodes;
2704
  int32_t masterNum;
2705
  int64_t numOfSelectReqs;
2706
  int64_t numOfInsertReqs;
2707
  int64_t numOfInsertSuccessReqs;
2708
  int64_t numOfBatchInsertReqs;
2709
  int64_t numOfBatchInsertSuccessReqs;
2710
  int64_t errors;
2711
} SVnodesStat;
2712

2713
typedef struct {
2714
  int32_t vgId;
2715
  int8_t  syncState;
2716
  int8_t  syncRestore;
2717
  int64_t syncTerm;
2718
  int64_t roleTimeMs;
2719
  int64_t startTimeMs;
2720
  int8_t  syncCanRead;
2721
  int64_t cacheUsage;
2722
  int64_t numOfTables;
2723
  int64_t numOfTimeSeries;
2724
  int64_t totalStorage;
2725
  int64_t compStorage;
2726
  int64_t pointsWritten;
2727
  int64_t numOfSelectReqs;
2728
  int64_t numOfInsertReqs;
2729
  int64_t numOfInsertSuccessReqs;
2730
  int64_t numOfBatchInsertReqs;
2731
  int64_t numOfBatchInsertSuccessReqs;
2732
  int32_t numOfCachedTables;
2733
  int32_t learnerProgress;  // use one reservered
2734
  int64_t syncAppliedIndex;
2735
  int64_t syncCommitIndex;
2736
  int64_t bufferSegmentUsed;
2737
  int64_t bufferSegmentSize;
2738
  int32_t snapSeq;
2739
  int64_t syncTotalIndex;
2740
} SVnodeLoad;
2741

2742
typedef struct {
2743
  int64_t total_requests;
2744
  int64_t total_rows;
2745
  int64_t total_bytes;
2746
  double  write_size;
2747
  double  cache_hit_ratio;
2748
  int64_t rpc_queue_wait;
2749
  int64_t preprocess_time;
2750

2751
  int64_t memory_table_size;
2752
  int64_t commit_count;
2753
  int64_t merge_count;
2754
  double  commit_time;
2755
  double  merge_time;
2756
  int64_t block_commit_time;
2757
  int64_t memtable_wait_time;
2758
} SVnodeMetrics;
2759

2760
typedef struct {
2761
  int32_t     vgId;
2762
  int64_t     numOfTables;
2763
  int64_t     memSize;
2764
  int64_t     l1Size;
2765
  int64_t     l2Size;
2766
  int64_t     l3Size;
2767
  int64_t     cacheSize;
2768
  int64_t     walSize;
2769
  int64_t     metaSize;
2770
  int64_t     rawDataSize;
2771
  int64_t     ssSize;
2772
  const char* dbname;
2773
  int8_t      estimateRawData;
2774
} SDbSizeStatisInfo;
2775

2776
typedef struct {
2777
  int32_t vgId;
2778
  int64_t nTimeSeries;
2779
} SVnodeLoadLite;
2780

2781
typedef struct {
2782
  int8_t  syncState;
2783
  int64_t syncTerm;
2784
  int8_t  syncRestore;
2785
  int64_t roleTimeMs;
2786
} SMnodeLoad;
2787

2788
typedef struct {
2789
  int32_t dnodeId;
2790
  int64_t numOfProcessedQuery;
2791
  int64_t numOfProcessedCQuery;
2792
  int64_t numOfProcessedFetch;
2793
  int64_t numOfProcessedDrop;
2794
  int64_t numOfProcessedNotify;
2795
  int64_t numOfProcessedHb;
2796
  int64_t numOfProcessedDelete;
2797
  int64_t cacheDataSize;
2798
  int64_t numOfQueryInQueue;
2799
  int64_t numOfFetchInQueue;
2800
  int64_t timeInQueryQueue;
2801
  int64_t timeInFetchQueue;
2802
} SQnodeLoad;
2803

2804
typedef struct {
2805
  int32_t     sver;      // software version
2806
  int64_t     dnodeVer;  // dnode table version in sdb
2807
  int32_t     dnodeId;
2808
  int64_t     clusterId;
2809
  int64_t     rebootTime;
2810
  int64_t     updateTime;
2811
  float       numOfCores;
2812
  int32_t     numOfSupportVnodes;
2813
  int32_t     numOfDiskCfg;
2814
  int64_t     memTotal;
2815
  int64_t     memAvail;
2816
  char        dnodeEp[TSDB_EP_LEN];
2817
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2818
  SMnodeLoad  mload;
2819
  SQnodeLoad  qload;
2820
  SClusterCfg clusterCfg;
2821
  SArray*     pVloads;  // array of SVnodeLoad
2822
  int32_t     statusSeq;
2823
  int64_t     ipWhiteVer;
2824
  int64_t     timeWhiteVer;
2825
  int64_t     analVer;
2826
  int64_t     timestamp;
2827
  char        auditDB[TSDB_DB_FNAME_LEN];
2828
  char        auditToken[TSDB_TOKEN_LEN];
2829
  SEpSet      auditEpSet;
2830
  int32_t     auditVgId;
2831
} SStatusReq;
2832

2833
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2834
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2835
void    tFreeSStatusReq(SStatusReq* pReq);
2836

2837
typedef struct {
2838
  int32_t forceReadConfig;
2839
  int32_t cver;
2840
  SArray* array;
2841
} SConfigReq;
2842

2843
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2844
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2845
void    tFreeSConfigReq(SConfigReq* pReq);
2846

2847
typedef struct {
2848
  int32_t dnodeId;
2849
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2850
} SDnodeInfoReq;
2851

2852
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2853
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2854

2855
typedef enum {
2856
  MONITOR_TYPE_COUNTER = 0,
2857
  MONITOR_TYPE_SLOW_LOG = 1,
2858
} MONITOR_TYPE;
2859

2860
typedef struct {
2861
  int32_t      contLen;
2862
  char*        pCont;
2863
  MONITOR_TYPE type;
2864
} SStatisReq;
2865

2866
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2867
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2868
void    tFreeSStatisReq(SStatisReq* pReq);
2869

2870
typedef struct {
2871
  char    db[TSDB_DB_FNAME_LEN];
2872
  char    table[TSDB_TABLE_NAME_LEN];
2873
  char    operation[AUDIT_OPERATION_LEN];
2874
  int32_t sqlLen;
2875
  char*   pSql;
2876
  double  duration;
2877
  int64_t affectedRows;
2878
} SAuditReq;
2879
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2880
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2881
void    tFreeSAuditReq(SAuditReq* pReq);
2882

2883
typedef struct {
2884
  SArray* auditArr;
2885
} SBatchAuditReq;
2886
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2887
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2888
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2889

2890
typedef struct {
2891
  int32_t dnodeId;
2892
  int64_t clusterId;
2893
  SArray* pVloads;
2894
} SNotifyReq;
2895

2896
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2897
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2898
void    tFreeSNotifyReq(SNotifyReq* pReq);
2899

2900
typedef struct {
2901
  int32_t dnodeId;
2902
  int64_t clusterId;
2903
} SDnodeCfg;
2904

2905
typedef struct {
2906
  int32_t id;
2907
  int8_t  isMnode;
2908
  SEp     ep;
2909
} SDnodeEp;
2910

2911
typedef struct {
2912
  int32_t id;
2913
  int8_t  isMnode;
2914
  int8_t  offlineReason;
2915
  SEp     ep;
2916
  char    active[TSDB_ACTIVE_KEY_LEN];
2917
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2918
} SDnodeInfo;
2919

2920
typedef struct {
2921
  int64_t   dnodeVer;
2922
  SDnodeCfg dnodeCfg;
2923
  SArray*   pDnodeEps;  // Array of SDnodeEp
2924
  int32_t   statusSeq;
2925
  int64_t   ipWhiteVer;
2926
  int64_t   analVer;
2927
  int64_t   timeWhiteVer;
2928
  char      auditDB[TSDB_DB_FNAME_LEN];
2929
  char      auditToken[TSDB_TOKEN_LEN];
2930
  SEpSet    auditEpSet;
2931
  int32_t   auditVgId;
2932
} SStatusRsp;
2933

2934
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2935
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2936
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2937

2938
typedef struct {
2939
  int32_t forceReadConfig;
2940
  int32_t isConifgVerified;
2941
  int32_t isVersionVerified;
2942
  int32_t cver;
2943
  SArray* array;
2944
} SConfigRsp;
2945

2946
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2947
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2948
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2949

2950
typedef struct {
2951
  int32_t dnodeId;
2952
  int32_t keyVersion;  // Local key version
2953
} SKeySyncReq;
2954

2955
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2956
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2957

2958
typedef struct {
2959
  int32_t keyVersion;        // mnode's key version
2960
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2961
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2962
  char    svrKey[129];       // Server key (if needUpdate)
2963
  char    dbKey[129];        // Database key (if needUpdate)
2964
  char    cfgKey[129];       // Config key (if needUpdate)
2965
  char    metaKey[129];      // Metadata key (if needUpdate)
2966
  char    dataKey[129];      // Data key (if needUpdate)
2967
  int32_t algorithm;         // Encryption algorithm for master keys
2968
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2969
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2970
  int64_t createTime;        // Key creation time
2971
  int64_t svrKeyUpdateTime;  // Server key update time
2972
  int64_t dbKeyUpdateTime;   // Database key update time
2973
} SKeySyncRsp;
2974

2975
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2976
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2977

2978
typedef struct {
2979
  int32_t reserved;
2980
} SMTimerReq;
2981

2982
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2983
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2984

2985
typedef struct SOrphanTask {
2986
  int64_t streamId;
2987
  int32_t taskId;
2988
  int32_t nodeId;
2989
} SOrphanTask;
2990

2991
typedef struct SMStreamDropOrphanMsg {
2992
  SArray* pList;  // SArray<SOrphanTask>
2993
} SMStreamDropOrphanMsg;
2994

2995
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2996
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2997
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2998

2999
typedef struct {
3000
  int32_t  id;
3001
  uint16_t port;                 // node sync Port
3002
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
3003
} SReplica;
3004

3005
typedef struct {
3006
  int32_t  vgId;
3007
  char     db[TSDB_DB_FNAME_LEN];
3008
  int64_t  dbUid;
3009
  int32_t  vgVersion;
3010
  int32_t  numOfStables;
3011
  int32_t  buffer;
3012
  int32_t  pageSize;
3013
  int32_t  pages;
3014
  int32_t  cacheLastSize;
3015
  int32_t  cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3016
  int32_t  daysPerFile;
3017
  int32_t  daysToKeep0;
3018
  int32_t  daysToKeep1;
3019
  int32_t  daysToKeep2;
3020
  int32_t  keepTimeOffset;
3021
  int32_t  minRows;
3022
  int32_t  maxRows;
3023
  int32_t  walFsyncPeriod;
3024
  uint32_t hashBegin;
3025
  uint32_t hashEnd;
3026
  int8_t   hashMethod;
3027
  int8_t   walLevel;
3028
  int8_t   precision;
3029
  int8_t   compression;
3030
  int8_t   strict;
3031
  int8_t   cacheLast;
3032
  int8_t   isTsma;
3033
  int8_t   replica;
3034
  int8_t   selfIndex;
3035
  SReplica replicas[TSDB_MAX_REPLICA];
3036
  int32_t  numOfRetensions;
3037
  SArray*  pRetensions;  // SRetention
3038
  void*    pTsma;
3039
  int32_t  walRetentionPeriod;
3040
  int64_t  walRetentionSize;
3041
  int32_t  walRollPeriod;
3042
  int64_t  walSegmentSize;
3043
  int16_t  sstTrigger;
3044
  int16_t  hashPrefix;
3045
  int16_t  hashSuffix;
3046
  int32_t  tsdbPageSize;
3047
  int32_t  ssChunkSize;
3048
  int32_t  ssKeepLocal;
3049
  int8_t   ssCompact;
3050
  int64_t  reserved[6];
3051
  int8_t   learnerReplica;
3052
  int8_t   learnerSelfIndex;
3053
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3054
  int32_t  changeVersion;
3055
  int8_t   encryptAlgorithm;
3056
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
3057
  union {
3058
    uint8_t flags;
3059
    struct {
3060
      uint8_t isAudit : 1;
3061
      uint8_t allowDrop : 1;
3062
      uint8_t padding : 6;
3063
    };
3064
  };
3065
  int8_t secureDelete;
3066
} SCreateVnodeReq;
3067

3068
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3069
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3070
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3071

3072
typedef struct {
3073
  union {
3074
    int32_t compactId;
3075
    int32_t id;
3076
  };
3077
  int32_t vgId;
3078
  int32_t dnodeId;
3079
} SQueryCompactProgressReq;
3080

3081
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3082
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3083

3084
typedef struct {
3085
  union {
3086
    int32_t compactId;
3087
    int32_t id;
3088
  };
3089
  int32_t vgId;
3090
  int32_t dnodeId;
3091
  int32_t numberFileset;
3092
  int32_t finished;
3093
  int32_t progress;
3094
  int64_t remainingTime;
3095
} SQueryCompactProgressRsp;
3096

3097
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3098
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3099

3100
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3101
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3102

3103
typedef struct {
3104
  int32_t vgId;
3105
  int32_t dnodeId;
3106
  int64_t dbUid;
3107
  char    db[TSDB_DB_FNAME_LEN];
3108
  int64_t reserved[8];
3109
} SDropVnodeReq;
3110

3111
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3112
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3113

3114
typedef struct {
3115
  char    colName[TSDB_COL_NAME_LEN];
3116
  char    stb[TSDB_TABLE_FNAME_LEN];
3117
  int64_t stbUid;
3118
  int64_t dbUid;
3119
  int64_t reserved[8];
3120
} SDropIndexReq;
3121

3122
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3123
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3124

3125
typedef struct {
3126
  int64_t dbUid;
3127
  char    db[TSDB_DB_FNAME_LEN];
3128
  union {
3129
    int64_t compactStartTime;
3130
    int64_t startTime;
3131
  };
3132

3133
  STimeWindow tw;
3134
  union {
3135
    int32_t compactId;
3136
    int32_t id;
3137
  };
3138
  int8_t metaOnly;
3139
  union {
3140
    uint16_t flags;
3141
    struct {
3142
      uint16_t optrType : 3;     // ETsdbOpType
3143
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3144
      uint16_t reserved : 12;
3145
    };
3146
  };
3147
  int8_t force;  // force compact
3148
} SCompactVnodeReq;
3149

3150
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3151
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3152

3153
typedef struct {
3154
  union {
3155
    int32_t compactId;
3156
    int32_t taskId;
3157
  };
3158
  int32_t vgId;
3159
  int32_t dnodeId;
3160
} SVKillCompactReq;
3161

3162
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3163
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3164

3165
typedef SVKillCompactReq SVKillRetentionReq;
3166

3167
typedef struct {
3168
  char        db[TSDB_DB_FNAME_LEN];
3169
  int32_t     maxSpeed;
3170
  int32_t     sqlLen;
3171
  char*       sql;
3172
  SArray*     vgroupIds;
3173
  STimeWindow tw;  // unit is second
3174
  union {
3175
    uint32_t flags;
3176
    struct {
3177
      uint32_t optrType : 3;     // ETsdbOpType
3178
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3179
      uint32_t reserved : 28;
3180
    };
3181
  };
3182
} STrimDbReq;
3183

3184
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3185
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3186
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3187

3188
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3189

3190
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3191
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3192

3193
typedef struct {
3194
  int32_t vgVersion;
3195
  int32_t buffer;
3196
  int32_t pageSize;
3197
  int32_t pages;
3198
  int32_t cacheLastSize;
3199
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3200
  int32_t daysPerFile;
3201
  int32_t daysToKeep0;
3202
  int32_t daysToKeep1;
3203
  int32_t daysToKeep2;
3204
  int32_t keepTimeOffset;
3205
  int32_t walFsyncPeriod;
3206
  int8_t  walLevel;
3207
  int8_t  strict;
3208
  int8_t  cacheLast;
3209
  int64_t reserved[7];
3210
  // 1st modification
3211
  int16_t sttTrigger;
3212
  int32_t minRows;
3213
  // 2nd modification
3214
  int32_t walRetentionPeriod;
3215
  int32_t walRetentionSize;
3216
  int32_t ssKeepLocal;
3217
  int8_t  ssCompact;
3218
  int8_t  allowDrop;
3219
  int8_t  secureDelete;
3220
} SAlterVnodeConfigReq;
3221

3222
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3223
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3224

3225
typedef struct {
3226
  int32_t  vgId;
3227
  int8_t   strict;
3228
  int8_t   selfIndex;
3229
  int8_t   replica;
3230
  SReplica replicas[TSDB_MAX_REPLICA];
3231
  int64_t  reserved[8];
3232
  int8_t   learnerSelfIndex;
3233
  int8_t   learnerReplica;
3234
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3235
  int32_t  changeVersion;
3236
  int32_t  electBaseLine;
3237
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3238

3239
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3240
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3241

3242
typedef struct {
3243
  int32_t vgId;
3244
  int8_t  disable;
3245
} SDisableVnodeWriteReq;
3246

3247
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3248
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3249

3250
typedef struct {
3251
  int32_t  srcVgId;
3252
  int32_t  dstVgId;
3253
  uint32_t hashBegin;
3254
  uint32_t hashEnd;
3255
  int32_t  changeVersion;
3256
  int32_t  reserved;
3257
} SAlterVnodeHashRangeReq;
3258

3259
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3260
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3261

3262
#define REQ_OPT_TBNAME 0x0
3263
#define REQ_OPT_TBUID  0x01
3264
typedef struct {
3265
  SMsgHead header;
3266
  char     dbFName[TSDB_DB_FNAME_LEN];
3267
  char     tbName[TSDB_TABLE_NAME_LEN];
3268
  uint8_t  option;
3269
  uint8_t  autoCreateCtb;
3270
} STableInfoReq;
3271

3272
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3273
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3274

3275
typedef struct {
3276
  int8_t  metaClone;  // create local clone of the cached table meta
3277
  int32_t numOfVgroups;
3278
  int32_t numOfTables;
3279
  int32_t numOfUdfs;
3280
  char    tableNames[];
3281
} SMultiTableInfoReq;
3282

3283
// todo refactor
3284
typedef struct SVgroupInfo {
3285
  int32_t  vgId;
3286
  uint32_t hashBegin;
3287
  uint32_t hashEnd;
3288
  SEpSet   epSet;
3289
  union {
3290
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3291
    int32_t taskId;      // used in stream
3292
  };
3293
} SVgroupInfo;
3294

3295
typedef struct {
3296
  int32_t     numOfVgroups;
3297
  SVgroupInfo vgroups[];
3298
} SVgroupsInfo;
3299

3300
typedef struct {
3301
  STableMetaRsp* pMeta;
3302
} SMAlterStbRsp;
3303

3304
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3305
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3306
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3307

3308
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3309
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3310
void    tFreeSTableMetaRsp(void* pRsp);
3311
void    tFreeSTableIndexRsp(void* info);
3312

3313
typedef struct {
3314
  SArray* pMetaRsp;   // Array of STableMetaRsp
3315
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3316
} SSTbHbRsp;
3317

3318
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3319
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3320
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3321

3322
typedef struct {
3323
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3324
} SViewHbRsp;
3325

3326
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3327
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3328
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3329

3330
typedef struct {
3331
  int32_t numOfTables;
3332
  int32_t numOfVgroup;
3333
  int32_t numOfUdf;
3334
  int32_t contLen;
3335
  int8_t  compressed;  // denote if compressed or not
3336
  int32_t rawLen;      // size before compress
3337
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3338
  char    meta[];
3339
} SMultiTableMeta;
3340

3341
typedef struct {
3342
  int32_t dataLen;
3343
  char    name[TSDB_TABLE_FNAME_LEN];
3344
  char*   data;
3345
} STagData;
3346

3347
typedef struct {
3348
  int32_t  opType;
3349
  uint32_t valLen;
3350
  char*    val;
3351
} SShowVariablesReq;
3352

3353
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3354
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3355
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3356

3357
typedef struct {
3358
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3359
  char value[TSDB_CONFIG_PATH_LEN + 1];
3360
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3361
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3362
  char info[TSDB_CONFIG_INFO_LEN + 1];
3363
} SVariablesInfo;
3364

3365
typedef struct {
3366
  SArray* variables;  // SArray<SVariablesInfo>
3367
} SShowVariablesRsp;
3368

3369
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3370
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3371

3372
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3373

3374
/*
3375
 * sql: show tables like '%a_%'
3376
 * payload is the query condition, e.g., '%a_%'
3377
 * payloadLen is the length of payload
3378
 */
3379
typedef struct {
3380
  int32_t type;
3381
  char    db[TSDB_DB_FNAME_LEN];
3382
  int32_t payloadLen;
3383
  char*   payload;
3384
} SShowReq;
3385

3386
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3387
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3388
void tFreeSShowReq(SShowReq* pReq);
3389

3390
typedef struct {
3391
  int64_t       showId;
3392
  STableMetaRsp tableMeta;
3393
} SShowRsp, SVShowTablesRsp;
3394

3395
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3396
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3397
// void    tFreeSShowRsp(SShowRsp* pRsp);
3398

3399
typedef struct {
3400
  char    db[TSDB_DB_FNAME_LEN];
3401
  char    tb[TSDB_TABLE_NAME_LEN];
3402
  char    user[TSDB_USER_LEN];
3403
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3404
  int64_t showId;
3405
  int64_t compactId;  // for compact
3406
  bool    withFull;   // for show users full
3407
} SRetrieveTableReq;
3408

3409
typedef struct SSysTableSchema {
3410
  int8_t   type;
3411
  col_id_t colId;
3412
  int32_t  bytes;
3413
} SSysTableSchema;
3414

3415
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3416
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3417

3418
#define RETRIEVE_TABLE_RSP_VERSION         0
3419
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3420
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3421

3422
typedef struct {
3423
  int64_t useconds;
3424
  int8_t  completed;  // all results are returned to client
3425
  int8_t  precision;
3426
  int8_t  compressed;
3427
  int8_t  streamBlockType;
3428
  int32_t payloadLen;
3429
  int32_t compLen;
3430
  int32_t numOfBlocks;
3431
  int64_t numOfRows;  // from int32_t change to int64_t
3432
  int64_t numOfCols;
3433
  int64_t skey;
3434
  int64_t ekey;
3435
  int64_t version;                         // for stream
3436
  TSKEY   watermark;                       // for stream
3437
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3438
  char    data[];
3439
} SRetrieveTableRsp;
3440

3441
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3442

3443
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3444
  do {                                          \
3445
    ((int32_t*)(_p))[0] = (_compLen);           \
3446
    ((int32_t*)(_p))[1] = (_fullLen);           \
3447
  } while (0);
3448

3449
typedef struct {
3450
  int64_t version;
3451
  int64_t numOfRows;
3452
  int8_t  compressed;
3453
  int8_t  precision;
3454
  char    data[];
3455
} SRetrieveTableRspForTmq;
3456

3457
typedef struct {
3458
  int64_t handle;
3459
  int64_t useconds;
3460
  int8_t  completed;  // all results are returned to client
3461
  int8_t  precision;
3462
  int8_t  compressed;
3463
  int32_t compLen;
3464
  int32_t numOfRows;
3465
  int32_t fullLen;
3466
  char    data[];
3467
} SRetrieveMetaTableRsp;
3468

3469
typedef struct SExplainExecInfo {
3470
  /* the number of rows returned */
3471
  uint64_t numOfRows;
3472
  uint32_t verboseLen;
3473
  void*    verboseInfo;
3474

3475
  /* the timestamp when the operator is created */
3476
  TSKEY    execCreate;
3477
  /* the first timestamp when the operator's next interface is called */
3478
  TSKEY    execStart;
3479
  /* the timestamp when the first row is returned */
3480
  TSKEY    execFirstRow;
3481
  /* the timestamp when the last row is returned */
3482
  TSKEY    execLastRow;
3483
  /* the number of times the operator's next interface is called */
3484
  uint32_t execTimes;
3485
  /**
3486
    the time elapsed for executing the operator's next interface,
3487
    not including waiting time for data from downstream
3488
  */
3489
  TSKEY    execElapsed;
3490
  /* the time elapsed for waiting for data from downstream */
3491
  TSKEY    inputWaitElapsed;
3492
  /* the time elapsed for waiting call from upstream */
3493
  TSKEY    outputWaitElapsed;
3494
  /* the number of rows input */
3495
  uint64_t inputRows;
3496

3497
  int32_t  vgId;
3498
} SExplainExecInfo;
3499

3500
typedef struct {
3501
  int32_t           numOfPlans;
3502
  SExplainExecInfo* subplanInfo;
3503
} SExplainRsp;
3504

3505
typedef struct {
3506
  SExplainRsp rsp;
3507
  uint64_t    qId;
3508
  uint64_t    cId;
3509
  uint64_t    tId;
3510
  int64_t     rId;
3511
  int32_t     eId;
3512
} SExplainLocalRsp;
3513

3514
typedef struct STableScanAnalyzeInfo {
3515
  int64_t totalBlocks;
3516
  int64_t fileLoadBlocks;
3517
  double  fileLoadElapsed;
3518
  int64_t sttLoadBlocks;
3519
  double  sttLoadElapsed;
3520
  int64_t memLoadBlocks;
3521
  double  memLoadElapsed;
3522
  int64_t smaLoadBlocks;
3523
  double  smaLoadElapsed;
3524
  int64_t composedBlocks;
3525
  double  composedElapsed;
3526
  
3527
  uint64_t checkRows;
3528

3529
  uint64_t skipBlocks;
3530
  uint64_t filterOutBlocks;
3531
  double   filterTime;
3532
} STableScanAnalyzeInfo;
3533

3534
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3535
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3536
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3537

3538
typedef struct {
3539
  char    config[TSDB_DNODE_CONFIG_LEN];
3540
  char    value[TSDB_CLUSTER_VALUE_LEN];
3541
  int32_t sqlLen;
3542
  char*   sql;
3543
} SMCfgClusterReq;
3544

3545
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3546
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3547
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3548

3549
typedef struct {
3550
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3551
  int32_t port;
3552
  int32_t sqlLen;
3553
  char*   sql;
3554
} SCreateDnodeReq;
3555

3556
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3557
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3558
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3559

3560
typedef struct {
3561
  int32_t dnodeId;
3562
  char    fqdn[TSDB_FQDN_LEN];
3563
  int32_t port;
3564
  int8_t  force;
3565
  int8_t  unsafe;
3566
  int32_t sqlLen;
3567
  char*   sql;
3568
} SDropDnodeReq;
3569

3570
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3571
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3572
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3573

3574
enum {
3575
  RESTORE_TYPE__ALL = 1,
3576
  RESTORE_TYPE__MNODE,
3577
  RESTORE_TYPE__VNODE,
3578
  RESTORE_TYPE__QNODE,
3579
};
3580

3581
typedef struct {
3582
  int32_t dnodeId;
3583
  int8_t  restoreType;
3584
  int32_t sqlLen;
3585
  char*   sql;
3586
} SRestoreDnodeReq;
3587

3588
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3589
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3590
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3591

3592
typedef struct {
3593
  int32_t dnodeId;
3594
  char    config[TSDB_DNODE_CONFIG_LEN];
3595
  char    value[TSDB_DNODE_VALUE_LEN];
3596
  int32_t sqlLen;
3597
  char*   sql;
3598
} SMCfgDnodeReq;
3599

3600
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3601
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3602
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3603

3604
typedef struct {
3605
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3606
  char    newKey[ENCRYPT_KEY_LEN + 1];
3607
  int32_t sqlLen;
3608
  char*   sql;
3609
} SMAlterEncryptKeyReq;
3610

3611
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3612
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3613
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3614

3615
typedef struct {
3616
  int32_t days;
3617
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3618
  int32_t sqlLen;
3619
  char*   sql;
3620
} SMAlterKeyExpirationReq;
3621

3622
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3623
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3624
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3625

3626
typedef struct {
3627
  char    config[TSDB_DNODE_CONFIG_LEN];
3628
  char    value[TSDB_DNODE_VALUE_LEN];
3629
  int32_t version;
3630
} SDCfgDnodeReq;
3631

3632
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3633
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3634

3635
typedef struct {
3636
  int32_t dnodeId;
3637
  int32_t sqlLen;
3638
  char*   sql;
3639
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3640
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3641

3642
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3643
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3644

3645
typedef struct {
3646
  int32_t nodeId;
3647
  SEpSet  epSet;
3648
} SNodeEpSet;
3649

3650
typedef struct {
3651
  int32_t    snodeId;
3652
  SNodeEpSet leaders[2];
3653
  SNodeEpSet replica;
3654
  int32_t    sqlLen;
3655
  char*      sql;
3656
} SDCreateSnodeReq;
3657

3658
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3659
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3660
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3661

3662
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3663
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3664
typedef struct {
3665
  int8_t   replica;
3666
  SReplica replicas[TSDB_MAX_REPLICA];
3667
  int8_t   learnerReplica;
3668
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3669
  int64_t  lastIndex;
3670
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3671
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3672

3673
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3674
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3675

3676
typedef struct {
3677
  int32_t urlLen;
3678
  int32_t sqlLen;
3679
  char*   url;
3680
  char*   sql;
3681
} SMCreateAnodeReq;
3682

3683
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3684
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3685
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3686

3687
typedef struct {
3688
  int32_t anodeId;
3689
  int32_t sqlLen;
3690
  char*   sql;
3691
} SMDropAnodeReq, SMUpdateAnodeReq;
3692

3693
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3694
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3695
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3696
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3697
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3698
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3699

3700
typedef struct {
3701
  int32_t dnodeId;
3702
  int32_t bnodeProto;
3703
  int32_t sqlLen;
3704
  char*   sql;
3705
} SMCreateBnodeReq, SDCreateBnodeReq;
3706

3707
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3708
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3709
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3710

3711
typedef struct {
3712
  int32_t dnodeId;
3713
  int32_t sqlLen;
3714
  char*   sql;
3715
} SMDropBnodeReq, SDDropBnodeReq;
3716

3717
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3718
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3719
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3720

3721
typedef struct {
3722
  bool        shouldFree;
3723
  int32_t     len;
3724
  const char* ptr;
3725
} CowStr;
3726
/**
3727
 * @brief Create a CowStr object.
3728
 *
3729
 * @param len: length of the string.
3730
 * @param ptr: pointer to the string input.
3731
 * @param shouldClone: whether to clone the string.
3732
 * @return CowStr object.
3733
 */
3734
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3735
/**
3736
 * @brief Set a CowStr object with given string.
3737
 *
3738
 * @param cow: pointer to the CowStr object.
3739
 * @param len: length of the string.
3740
 * @param ptr: pointer to the string input.
3741
 * @param shouldFree: whether to free the string.
3742
 */
3743
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3744
/**
3745
 * @brief Clone a CowStr object without copy the string.
3746
 *
3747
 * @param cow: pointer to the CowStr object.
3748
 * @return CowStr object.
3749
 */
3750
CowStr xCloneRefCowStr(CowStr* cow);
3751
/**
3752
 * @brief Convert a CowStr object to a string.
3753
 *
3754
 * @param cow: pointer to the CowStr object.
3755
 */
3756
char* xCowStrToStr(CowStr* cow);
3757
/**
3758
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3759
 *
3760
 * @param cow: pointer to the CowStr object.
3761
 */
3762
void xFreeCowStr(CowStr* cow);
3763
/**
3764
 * @brief Encode and push a CowStr object into the encoder.
3765
 *
3766
 * @param encoder
3767
 * @param cow
3768
 * @return int32_t
3769
 */
3770
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3771
/**
3772
 * @brief Decode a CowStr from the encoder.
3773
 *
3774
 * @param decoder
3775
 * @param cow
3776
 * @param shouldClone
3777
 * @return int32_t
3778
 */
3779
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3780

3781
typedef struct {
3782
  int32_t sqlLen;
3783
  int32_t urlLen;
3784
  int32_t userLen;
3785
  int32_t passLen;
3786
  int32_t passIsMd5;
3787
  char*   sql;
3788
  char*   url;
3789
  char*   user;
3790
  char*   pass;
3791
  CowStr  token;
3792
} SMCreateXnodeReq, SDCreateXnodeReq;
3793

3794
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3795
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3796
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3797

3798
typedef struct {
3799
  int32_t xnodeId;
3800
  int32_t force;
3801
  int32_t urlLen;
3802
  int32_t sqlLen;
3803
  char*   url;
3804
  char*   sql;
3805
} SMDropXnodeReq, SDDropXnodeReq;
3806

3807
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3808
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3809
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3810

3811
typedef struct {
3812
  int32_t id;
3813
  CowStr  token;
3814
  CowStr  user;
3815
  CowStr  pass;
3816
  int32_t urlLen;
3817
  int32_t sqlLen;
3818
  char*   url;
3819
  char*   sql;
3820
} SMUpdateXnodeReq;
3821
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3822
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3823
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3824

3825
typedef struct {
3826
  int32_t xnodeId;
3827
  int32_t sqlLen;
3828
  char*   sql;
3829
} SMDrainXnodeReq;
3830
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3831
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3832
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3833
typedef enum {
3834
  XNODE_TASK_SOURCE_DSN = 1,
3835
  XNODE_TASK_SOURCE_DATABASE,
3836
  XNODE_TASK_SOURCE_TOPIC,
3837
} ENodeXTaskSourceType;
3838

3839
typedef enum {
3840
  XNODE_TASK_SINK_DSN = 1,
3841
  XNODE_TASK_SINK_DATABASE,
3842
} ENodeXTaskSinkType;
3843

3844
typedef struct {
3845
  ENodeXTaskSourceType type;
3846
  CowStr               cstr;
3847
} xTaskSource;
3848
/**
3849
 * @brief Deallocate a xTaskSource object.
3850
 *
3851
 * @param source ptr
3852
 */
3853
void xFreeTaskSource(xTaskSource* source);
3854
/**
3855
 * @brief Create a xTaskSource object with cloned source string.
3856
 *
3857
 * @param sourceType: source type.
3858
 * @param len: length of source string.
3859
 * @param source: source string ptr.
3860
 * @return xTaskSource object
3861
 */
3862
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3863
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3864
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3865
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3866
const char* xGetTaskSourceStr(xTaskSource* source);
3867
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3868
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3869

3870
typedef struct {
3871
  ENodeXTaskSinkType type;
3872
  CowStr             cstr;
3873
} xTaskSink;
3874
/**
3875
 * @brief Deallocate a xTaskSink object.
3876
 *
3877
 * @param sink ptr
3878
 */
3879
void xFreeTaskSink(xTaskSink* sink);
3880
/**
3881
 * @brief Create a xTaskSink object with cloned name string.
3882
 *
3883
 * @param sinkType: sink type.
3884
 * @param len: length of sink string.
3885
 * @param ptr: sink string ptr.
3886
 * @return xTaskSink object
3887
 */
3888
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3889
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3890
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3891
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3892
const char* xGetTaskSinkStr(xTaskSink* sink);
3893
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3894
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3895

3896
typedef struct {
3897
  int32_t via;
3898
  CowStr  parser;
3899
  // CowStr  reason;
3900
  CowStr  trigger;
3901
  CowStr  health;
3902
  int32_t optionsNum;
3903
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3904
} xTaskOptions;
3905
/**
3906
 * @brief Deallocate a xTaskOptions object.
3907
 *
3908
 * @param options ptr
3909
 */
3910
void    xFreeTaskOptions(xTaskOptions* options);
3911
void    printXnodeTaskOptions(xTaskOptions* options);
3912
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3913
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3914

3915
typedef struct {
3916
  int32_t sqlLen;
3917
  char*   sql;
3918
  int32_t      xnodeId;
3919
  CowStr       name;
3920
  xTaskSource  source;
3921
  xTaskSink    sink;
3922
  xTaskOptions options;
3923
} SMCreateXnodeTaskReq;
3924
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3925
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3926
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3927

3928
typedef struct {
3929
  int32_t     tid;
3930
  CowStr      name;
3931
  int32_t     via;
3932
  int32_t     xnodeId;
3933
  CowStr      status;
3934
  xTaskSource source;
3935
  xTaskSink   sink;
3936
  CowStr      parser;
3937
  CowStr      reason;
3938
  CowStr      updateName;
3939
  CowStr      labels;
3940
  int32_t     sqlLen;
3941
  char*       sql;
3942
} SMUpdateXnodeTaskReq;
3943
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3944
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3945
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3946

3947
typedef struct {
3948
  int32_t id;
3949
  bool    force;
3950
  CowStr  name;
3951
  int32_t sqlLen;
3952
  char*   sql;
3953
} SMDropXnodeTaskReq;
3954
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3955
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3956
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3957

3958
typedef struct {
3959
  int32_t tid;
3960
  CowStr  name;
3961
  int32_t sqlLen;
3962
  char*   sql;
3963
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3964
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3965
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3966
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3967

3968
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3969
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3970
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3971

3972
typedef struct {
3973
  int32_t tid;
3974
  int32_t via;
3975
  int32_t xnodeId;
3976
  CowStr  status;
3977
  CowStr  config;
3978
  CowStr  reason;
3979
  int32_t sqlLen;
3980
  char*   sql;
3981
} SMCreateXnodeJobReq;
3982
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3983
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3984
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3985

3986
typedef struct {
3987
  int32_t jid;
3988
  int32_t via;
3989
  int32_t xnodeId;
3990
  CowStr  status;
3991
  int32_t configLen;
3992
  int32_t reasonLen;
3993
  int32_t sqlLen;
3994
  char*   config;
3995
  char*   reason;
3996
  char*   sql;
3997
} SMUpdateXnodeJobReq;
3998
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3999
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4000
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
4001

4002
typedef struct {
4003
  int32_t jid;
4004
  int32_t xnodeId;
4005
  int32_t sqlLen;
4006
  char*   sql;
4007
} SMRebalanceXnodeJobReq;
4008
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4009
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4010
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
4011

4012
typedef struct {
4013
  CowStr  ast;
4014
  int32_t sqlLen;
4015
  char*   sql;
4016
} SMRebalanceXnodeJobsWhereReq;
4017
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4018
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4019
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
4020

4021
typedef struct {
4022
  int32_t jid;
4023
  CowStr  ast;
4024
  int32_t sqlLen;
4025
  char*   sql;
4026
} SMDropXnodeJobReq;
4027
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4028
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4029
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
4030

4031
typedef struct {
4032
  int32_t      sqlLen;
4033
  char*        sql;
4034
  CowStr       name;
4035
  CowStr       status;
4036
  xTaskOptions options;
4037
} SMCreateXnodeAgentReq;
4038
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4039
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4040
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
4041

4042
typedef struct {
4043
  int32_t      sqlLen;
4044
  char*        sql;
4045
  int32_t      id;
4046
  CowStr       name;
4047
  xTaskOptions options;
4048
} SMUpdateXnodeAgentReq;
4049
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4050
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4051
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
4052

4053
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4054
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4055
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4056
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4057

4058
typedef struct {
4059
  int32_t vgId;
4060
  int32_t hbSeq;
4061
} SVArbHbReqMember;
4062

4063
typedef struct {
4064
  int32_t dnodeId;
4065
  char*   arbToken;
4066
  int64_t arbTerm;
4067
  SArray* hbMembers;  // SVArbHbReqMember
4068
} SVArbHeartBeatReq;
4069

4070
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4071
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4072
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4073

4074
typedef struct {
4075
  int32_t vgId;
4076
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4077
  int32_t hbSeq;
4078
} SVArbHbRspMember;
4079

4080
typedef struct {
4081
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4082
  int32_t dnodeId;
4083
  SArray* hbMembers;  // SVArbHbRspMember
4084
} SVArbHeartBeatRsp;
4085

4086
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4087
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4088
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4089

4090
typedef struct {
4091
  char*   arbToken;
4092
  int64_t arbTerm;
4093
  char*   member0Token;
4094
  char*   member1Token;
4095
} SVArbCheckSyncReq;
4096

4097
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4098
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4099
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4100

4101
typedef struct {
4102
  char*   arbToken;
4103
  char*   member0Token;
4104
  char*   member1Token;
4105
  int32_t vgId;
4106
  int32_t errCode;
4107
} SVArbCheckSyncRsp;
4108

4109
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4110
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4111
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4112

4113
typedef struct {
4114
  char*   arbToken;
4115
  int64_t arbTerm;
4116
  char*   memberToken;
4117
  int8_t  force;
4118
} SVArbSetAssignedLeaderReq;
4119

4120
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4121
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4122
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4123

4124
typedef struct {
4125
  char* data;
4126
} SVAuditRecordReq;
4127
int32_t tSerializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4128
int32_t tDeserializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4129
void    tFreeSVAuditRecordReq(SVAuditRecordReq* pReq);
4130

4131
typedef struct {
4132
  char*   arbToken;
4133
  char*   memberToken;
4134
  int32_t vgId;
4135
} SVArbSetAssignedLeaderRsp;
4136

4137
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4138
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4139
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4140

4141
typedef struct {
4142
  int32_t dnodeId;
4143
  char*   token;
4144
} SMArbUpdateGroupMember;
4145

4146
typedef struct {
4147
  int32_t dnodeId;
4148
  char*   token;
4149
  int8_t  acked;
4150
} SMArbUpdateGroupAssigned;
4151

4152
typedef struct {
4153
  int32_t                  vgId;
4154
  int64_t                  dbUid;
4155
  SMArbUpdateGroupMember   members[2];
4156
  int8_t                   isSync;
4157
  int8_t                   assignedAcked;
4158
  SMArbUpdateGroupAssigned assignedLeader;
4159
  int64_t                  version;
4160
  int32_t                  code;
4161
  int64_t                  updateTimeMs;
4162
} SMArbUpdateGroup;
4163

4164
typedef struct {
4165
  SArray* updateArray;  // SMArbUpdateGroup
4166
} SMArbUpdateGroupBatchReq;
4167

4168
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4169
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4170
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4171

4172
typedef struct {
4173
  char queryStrId[TSDB_QUERY_ID_LEN];
4174
} SKillQueryReq;
4175

4176
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4177
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4178

4179
typedef struct {
4180
  uint32_t connId;
4181
} SKillConnReq;
4182

4183
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4184
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4185

4186
typedef struct {
4187
  int32_t transId;
4188
} SKillTransReq;
4189

4190
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4191
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4192

4193
typedef struct {
4194
  int32_t useless;  // useless
4195
  int32_t sqlLen;
4196
  char*   sql;
4197
} SBalanceVgroupReq;
4198

4199
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4200
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4201
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4202

4203
typedef struct {
4204
  int32_t useless;  // useless
4205
  int32_t sqlLen;
4206
  char*   sql;
4207
} SAssignLeaderReq;
4208

4209
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4210
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4211
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4212
typedef struct {
4213
  int32_t vgId1;
4214
  int32_t vgId2;
4215
} SMergeVgroupReq;
4216

4217
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4218
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4219

4220
typedef struct {
4221
  int32_t vgId;
4222
  int32_t dnodeId1;
4223
  int32_t dnodeId2;
4224
  int32_t dnodeId3;
4225
  int32_t sqlLen;
4226
  char*   sql;
4227
} SRedistributeVgroupReq;
4228

4229
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4230
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4231
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4232

4233
typedef struct {
4234
  int32_t reserved;
4235
  int32_t vgId;
4236
  int32_t sqlLen;
4237
  char*   sql;
4238
  char    db[TSDB_DB_FNAME_LEN];
4239
} SBalanceVgroupLeaderReq;
4240

4241
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4242
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4243
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4244

4245
typedef struct {
4246
  int32_t vgId;
4247
} SForceBecomeFollowerReq;
4248

4249
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4250
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4251

4252
typedef struct {
4253
  int32_t vgId;
4254
  bool    force;
4255
} SSplitVgroupReq;
4256

4257
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4258
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4259

4260
typedef struct {
4261
  char user[TSDB_USER_LEN];
4262
  char spi;
4263
  char encrypt;
4264
  char secret[TSDB_PASSWORD_LEN];
4265
  char ckey[TSDB_PASSWORD_LEN];
4266
} SAuthReq, SAuthRsp;
4267

4268
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4269
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4270

4271
typedef struct {
4272
  int32_t statusCode;
4273
  char    details[1024];
4274
} SServerStatusRsp;
4275

4276
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4277
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4278

4279
/**
4280
 * The layout of the query message payload is as following:
4281
 * +--------------------+---------------------------------+
4282
 * |Sql statement       | Physical plan                   |
4283
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4284
 * +--------------------+---------------------------------+
4285
 */
4286
typedef struct SSubQueryMsg {
4287
  SMsgHead header;
4288
  uint64_t sId;
4289
  uint64_t queryId;
4290
  uint64_t clientId;
4291
  uint64_t taskId;
4292
  int64_t  refId;
4293
  int32_t  execId;
4294
  int32_t  msgMask;
4295
  int32_t  subQType;
4296
  int8_t   taskType;
4297
  int8_t   explain;
4298
  int8_t   needFetch;
4299
  int8_t   compress;
4300
  uint32_t sqlLen;
4301
  char*    sql;
4302
  uint32_t msgLen;
4303
  char*    msg;
4304
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4305
} SSubQueryMsg;
4306

4307
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4308
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4309
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4310

4311
typedef struct {
4312
  SMsgHead header;
4313
  uint64_t sId;
4314
  uint64_t queryId;
4315
  uint64_t taskId;
4316
} SSinkDataReq;
4317

4318
typedef struct {
4319
  SMsgHead header;
4320
  uint64_t sId;
4321
  uint64_t queryId;
4322
  uint64_t clientId;
4323
  uint64_t taskId;
4324
  int32_t  execId;
4325
} SQueryContinueReq;
4326

4327
typedef struct {
4328
  SMsgHead header;
4329
  uint64_t sId;
4330
  uint64_t queryId;
4331
  uint64_t taskId;
4332
} SResReadyReq;
4333

4334
typedef struct {
4335
  int32_t code;
4336
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4337
  int32_t sversion;
4338
  int32_t tversion;
4339
} SResReadyRsp;
4340

4341
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4342

4343
typedef struct SOperatorParam {
4344
  int32_t opType;
4345
  int32_t downstreamIdx;
4346
  void*   value;
4347
  SArray* pChildren;  // SArray<SOperatorParam*>
4348
  bool    reUse;
4349
} SOperatorParam;
4350

4351
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4352

4353
// virtual table's colId to origin table's colname
4354
typedef struct SColIdNameKV {
4355
  col_id_t colId;
4356
  char     colName[TSDB_COL_NAME_LEN];
4357
} SColIdNameKV;
4358

4359
#define COL_MASK_ON   ((int8_t)0x1)
4360
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4361
#define COL_SET_MASK_ON(c)     \
4362
  do {                         \
4363
    (c)->flags |= COL_MASK_ON; \
4364
  } while (0)
4365

4366
typedef struct SColNameFlag {
4367
  col_id_t colId;
4368
  char     colName[TSDB_COL_NAME_LEN];
4369
  int8_t   flags;  // 0x01: COL_MASK_ON
4370
} SColNameFlag;
4371

4372
typedef struct SColIdPair {
4373
  col_id_t  vtbColId;
4374
  col_id_t  orgColId;
4375
  SDataType type;
4376
} SColIdPair;
4377

4378
typedef struct SColIdSlotIdPair {
4379
  int32_t  vtbSlotId;
4380
  col_id_t orgColId;
4381
} SColIdSlotIdPair;
4382

4383
typedef struct SOrgTbInfo {
4384
  int32_t vgId;
4385
  char    tbName[TSDB_TABLE_FNAME_LEN];
4386
  SArray* colMap;  // SArray<SColIdNameKV>
4387
} SOrgTbInfo;
4388

4389
void destroySOrgTbInfo(void *info);
4390

4391
typedef enum {
4392
  DYN_TYPE_STB_JOIN = 1,
4393
  DYN_TYPE_VSTB_SINGLE_SCAN,
4394
  DYN_TYPE_VSTB_BATCH_SCAN,
4395
  DYN_TYPE_VSTB_WIN_SCAN,
4396
} ETableScanDynType;
4397

4398
typedef enum {
4399
  DYN_TYPE_SCAN_PARAM = 1,
4400
  NOTIFY_TYPE_SCAN_PARAM,
4401
} ETableScanGetParamType;
4402

4403
typedef struct STableScanOperatorParam {
4404
  ETableScanGetParamType paramType;
4405
  /* for building scan data source */
4406
  bool                   tableSeq;
4407
  bool                   isNewParam;
4408
  uint64_t               groupid;
4409
  SArray*                pUidList;
4410
  SOrgTbInfo*            pOrgTbInfo;
4411
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4412
  SArray*                pTagList;
4413
  STimeWindow            window;
4414
  ETableScanDynType      dynType;
4415
  /* for notifying source step done */
4416
  bool                   notifyToProcess;  // received notify STEP DONE message
4417
  TSKEY                  notifyTs;         // notify timestamp
4418
} STableScanOperatorParam;
4419

4420
typedef struct STagScanOperatorParam {
4421
  tb_uid_t vcUid;
4422
} STagScanOperatorParam;
4423

4424
typedef struct SRefColIdGroup {
4425
  SArray* pSlotIdList;  // SArray<int32_t>
4426
} SRefColIdGroup;
4427

4428
typedef struct SVTableScanOperatorParam {
4429
  uint64_t        uid;
4430
  STimeWindow     window;
4431
  SOperatorParam* pTagScanOp;
4432
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4433
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4434
} SVTableScanOperatorParam;
4435

4436
typedef struct SMergeOperatorParam {
4437
  int32_t         winNum;
4438
} SMergeOperatorParam;
4439

4440
typedef struct SAggOperatorParam {
4441
  bool            needCleanRes;
4442
} SAggOperatorParam;
4443

4444
typedef struct SExternalWindowOperatorParam {
4445
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4446
} SExternalWindowOperatorParam;
4447

4448
typedef struct SDynQueryCtrlOperatorParam {
4449
  STimeWindow    window;
4450
} SDynQueryCtrlOperatorParam;
4451

4452
struct SStreamRuntimeFuncInfo;
4453
typedef struct {
4454
  SMsgHead        header;
4455
  uint64_t        sId;
4456
  uint64_t        queryId;
4457
  uint64_t        clientId;
4458
  uint64_t        taskId;
4459
  uint64_t        srcTaskId;  // used for subQ
4460
  uint64_t        blockIdx;   // used for subQ
4461
  int32_t         execId;
4462
  SOperatorParam* pOpParam;
4463

4464
  // used for new-stream
4465
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4466
  bool                           reset;
4467
  bool                           dynTbname;
4468
  // used for new-stream
4469
} SResFetchReq;
4470

4471
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4472
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4473
void    tDestroySResFetchReq(SResFetchReq* pReq);
4474
typedef struct {
4475
  SMsgHead header;
4476
  uint64_t clientId;
4477
} SSchTasksStatusReq;
4478

4479
typedef struct {
4480
  uint64_t queryId;
4481
  uint64_t clientId;
4482
  uint64_t taskId;
4483
  int64_t  refId;
4484
  int32_t  subJobId;
4485
  int32_t  execId;
4486
  int8_t   status;
4487
} STaskStatus;
4488

4489
typedef struct {
4490
  int64_t refId;
4491
  SArray* taskStatus;  // SArray<STaskStatus>
4492
} SSchedulerStatusRsp;
4493

4494
typedef struct {
4495
  uint64_t queryId;
4496
  uint64_t taskId;
4497
  int8_t   action;
4498
} STaskAction;
4499

4500
typedef struct SQueryNodeEpId {
4501
  int32_t nodeId;  // vgId or qnodeId
4502
  SEp     ep;
4503
} SQueryNodeEpId;
4504

4505
typedef struct {
4506
  SMsgHead       header;
4507
  uint64_t       clientId;
4508
  SQueryNodeEpId epId;
4509
  SArray*        taskAction;  // SArray<STaskAction>
4510
} SSchedulerHbReq;
4511

4512
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4513
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4514
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4515

4516
typedef struct {
4517
  SQueryNodeEpId epId;
4518
  SArray*        taskStatus;  // SArray<STaskStatus>
4519
} SSchedulerHbRsp;
4520

4521
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4522
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4523
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4524

4525
typedef struct {
4526
  SMsgHead header;
4527
  uint64_t sId;
4528
  uint64_t queryId;
4529
  uint64_t clientId;
4530
  uint64_t taskId;
4531
  int64_t  refId;
4532
  int32_t  execId;
4533
} STaskCancelReq;
4534

4535
typedef struct {
4536
  int32_t code;
4537
} STaskCancelRsp;
4538

4539
typedef struct {
4540
  SMsgHead header;
4541
  uint64_t sId;
4542
  uint64_t queryId;
4543
  uint64_t clientId;
4544
  uint64_t taskId;
4545
  int64_t  refId;
4546
  int32_t  execId;
4547
} STaskDropReq;
4548

4549
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4550
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4551

4552
typedef enum {
4553
  TASK_NOTIFY_FINISHED = 1,
4554
} ETaskNotifyType;
4555

4556
typedef struct {
4557
  SMsgHead        header;
4558
  uint64_t        sId;
4559
  uint64_t        queryId;
4560
  uint64_t        clientId;
4561
  uint64_t        taskId;
4562
  int64_t         refId;
4563
  int32_t         execId;
4564
  ETaskNotifyType type;
4565
} STaskNotifyReq;
4566

4567
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4568
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4569

4570
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4571
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4572

4573
typedef struct {
4574
  int32_t code;
4575
} STaskDropRsp;
4576

4577
#define STREAM_TRIGGER_AT_ONCE                 1
4578
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4579
#define STREAM_TRIGGER_MAX_DELAY               3
4580
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4581
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4582

4583
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4584
#define STREAM_FILL_HISTORY_ON        1
4585
#define STREAM_FILL_HISTORY_OFF       0
4586
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4587
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4588
#define STREAM_CREATE_STABLE_TRUE     1
4589
#define STREAM_CREATE_STABLE_FALSE    0
4590

4591
typedef struct SVgroupVer {
4592
  int32_t vgId;
4593
  int64_t ver;
4594
} SVgroupVer;
4595

4596
enum {
4597
  TOPIC_SUB_TYPE__DB = 1,
4598
  TOPIC_SUB_TYPE__TABLE,
4599
  TOPIC_SUB_TYPE__COLUMN,
4600
};
4601

4602
#define DEFAULT_MAX_POLL_INTERVAL  300000
4603
#define DEFAULT_SESSION_TIMEOUT    12000
4604
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4605
#define DEFAULT_MIN_POLL_ROWS      4096
4606

4607
typedef struct {
4608
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4609
  int8_t igExists;
4610
  int8_t subType;
4611
  int8_t withMeta;
4612
  char*  sql;
4613
  char   subDbName[TSDB_DB_FNAME_LEN];
4614
  char*  ast;
4615
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4616
  int8_t reload;
4617
} SCMCreateTopicReq;
4618

4619
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4620
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4621
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4622

4623
typedef struct {
4624
  int64_t consumerId;
4625
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4626

4627
typedef struct {
4628
  int64_t consumerId;
4629
  char    cgroup[TSDB_CGROUP_LEN];
4630
  char    clientId[TSDB_CLIENT_ID_LEN];
4631
  char    user[TSDB_USER_LEN];
4632
  char    fqdn[TSDB_FQDN_LEN];
4633
  SArray* topicNames;  // SArray<char**>
4634

4635
  int8_t  withTbName;
4636
  int8_t  autoCommit;
4637
  int32_t autoCommitInterval;
4638
  int8_t  resetOffsetCfg;
4639
  int8_t  enableReplay;
4640
  int8_t  enableBatchMeta;
4641
  int32_t sessionTimeoutMs;
4642
  int32_t maxPollIntervalMs;
4643
  int64_t ownerId;
4644
} SCMSubscribeReq;
4645

4646
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4647
  int32_t tlen = 0;
657,902✔
4648
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
657,902✔
4649
  tlen += taosEncodeString(buf, pReq->cgroup);
657,902✔
4650
  tlen += taosEncodeString(buf, pReq->clientId);
657,902✔
4651

4652
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
657,902✔
4653
  tlen += taosEncodeFixedI32(buf, topicNum);
657,902✔
4654

4655
  for (int32_t i = 0; i < topicNum; i++) {
910,308✔
4656
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
504,812✔
4657
  }
4658

4659
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
657,902✔
4660
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
657,902✔
4661
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
657,902✔
4662
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
657,902✔
4663
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
657,902✔
4664
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
657,902✔
4665
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
657,902✔
4666
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
657,902✔
4667
  tlen += taosEncodeString(buf, pReq->user);
657,902✔
4668
  tlen += taosEncodeString(buf, pReq->fqdn);
657,902✔
4669

4670
  return tlen;
657,902✔
4671
}
4672

4673
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4674
  void* start = buf;
346,756✔
4675
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
346,756✔
4676
  buf = taosDecodeStringTo(buf, pReq->cgroup);
346,756✔
4677
  buf = taosDecodeStringTo(buf, pReq->clientId);
346,756✔
4678

4679
  int32_t topicNum = 0;
346,756✔
4680
  buf = taosDecodeFixedI32(buf, &topicNum);
346,756✔
4681

4682
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
346,756✔
4683
  if (pReq->topicNames == NULL) {
346,756✔
UNCOV
4684
    return terrno;
×
4685
  }
4686
  for (int32_t i = 0; i < topicNum; i++) {
501,739✔
4687
    char* name = NULL;
154,983✔
4688
    buf = taosDecodeString(buf, &name);
154,983✔
4689
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
309,966✔
UNCOV
4690
      return terrno;
×
4691
    }
4692
  }
4693

4694
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
346,756✔
4695
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
346,756✔
4696
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
346,756✔
4697
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
346,756✔
4698
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
346,756✔
4699
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
346,756✔
4700
  if ((char*)buf - (char*)start < len) {
346,756✔
4701
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
346,756✔
4702
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
346,756✔
4703
    buf = taosDecodeStringTo(buf, pReq->user);
346,756✔
4704
    buf = taosDecodeStringTo(buf, pReq->fqdn);
693,512✔
4705
  } else {
UNCOV
4706
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4707
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4708
  }
4709

4710
  return 0;
346,756✔
4711
}
4712

4713
typedef struct {
4714
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4715
  SArray* removedConsumers;  // SArray<int64_t>
4716
  SArray* newConsumers;      // SArray<int64_t>
4717
} SMqRebInfo;
4718

4719
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4720
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
323,892✔
4721
  if (pRebInfo == NULL) {
323,892✔
UNCOV
4722
    return NULL;
×
4723
  }
4724
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
323,892✔
4725
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
323,892✔
4726
  if (pRebInfo->removedConsumers == NULL) {
323,892✔
UNCOV
4727
    goto _err;
×
4728
  }
4729
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
323,892✔
4730
  if (pRebInfo->newConsumers == NULL) {
323,892✔
UNCOV
4731
    goto _err;
×
4732
  }
4733
  return pRebInfo;
323,892✔
UNCOV
4734
_err:
×
UNCOV
4735
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
4736
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
4737
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
4738
  return NULL;
×
4739
}
4740

4741
typedef struct {
4742
  int64_t streamId;
4743
  int64_t checkpointId;
4744
  char    streamName[TSDB_STREAM_FNAME_LEN];
4745
} SMStreamDoCheckpointMsg;
4746

4747
typedef struct {
4748
  int64_t status;
4749
} SMVSubscribeRsp;
4750

4751
typedef struct {
4752
  char    name[TSDB_TOPIC_FNAME_LEN];
4753
  int8_t  igNotExists;
4754
  int32_t sqlLen;
4755
  char*   sql;
4756
  int8_t  force;
4757
} SMDropTopicReq;
4758

4759
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4760
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4761
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4762

4763
typedef struct {
4764
  char    name[TSDB_TOPIC_FNAME_LEN];
4765
  int8_t  igNotExists;
4766
  int32_t sqlLen;
4767
  char*   sql;
4768
} SMReloadTopicReq;
4769

4770
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4771
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4772
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4773

4774
typedef struct {
4775
  char   topic[TSDB_TOPIC_FNAME_LEN];
4776
  char   cgroup[TSDB_CGROUP_LEN];
4777
  int8_t igNotExists;
4778
  int8_t force;
4779
} SMDropCgroupReq;
4780

4781
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4782
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4783

4784
typedef struct {
4785
  int8_t reserved;
4786
} SMDropCgroupRsp;
4787

4788
typedef struct {
4789
  char    name[TSDB_TABLE_FNAME_LEN];
4790
  int8_t  alterType;
4791
  SSchema schema;
4792
} SAlterTopicReq;
4793

4794
typedef struct {
4795
  SMsgHead head;
4796
  char     name[TSDB_TABLE_FNAME_LEN];
4797
  int64_t  tuid;
4798
  int32_t  sverson;
4799
  int32_t  execLen;
4800
  char*    executor;
4801
  int32_t  sqlLen;
4802
  char*    sql;
4803
} SDCreateTopicReq;
4804

4805
typedef struct {
4806
  SMsgHead head;
4807
  char     name[TSDB_TABLE_FNAME_LEN];
4808
  int64_t  tuid;
4809
} SDDropTopicReq;
4810

4811
typedef struct {
4812
  char*      name;
4813
  int64_t    uid;
4814
  int64_t    interval[2];
4815
  int8_t     intervalUnit;
4816
  int16_t    nFuncs;
4817
  col_id_t*  funcColIds;  // column ids specified by user
4818
  func_id_t* funcIds;     // function ids specified by user
4819
} SRSmaParam;
4820

4821
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4822
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4823

4824
// TDMT_VND_CREATE_STB ==============
4825
typedef struct SVCreateStbReq {
4826
  char*           name;
4827
  tb_uid_t        suid;
4828
  int8_t          rollup;
4829
  SSchemaWrapper  schemaRow;
4830
  SSchemaWrapper  schemaTag;
4831
  SRSmaParam      rsmaParam;
4832
  int32_t         alterOriDataLen;
4833
  void*           alterOriData;
4834
  int8_t          source;
4835
  int8_t          colCmpred;
4836
  SColCmprWrapper colCmpr;
4837
  int64_t         keep;
4838
  int64_t         ownerId;
4839
  SExtSchema*     pExtSchemas;
4840
  int8_t          virtualStb;
4841
  int8_t          secureDelete;
4842
} SVCreateStbReq;
4843

4844
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4845
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4846

4847
// TDMT_VND_DROP_STB ==============
4848
typedef struct SVDropStbReq {
4849
  char*    name;
4850
  tb_uid_t suid;
4851
} SVDropStbReq;
4852

4853
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4854
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4855

4856
// TDMT_VND_CREATE_TABLE ==============
4857
#define TD_CREATE_IF_NOT_EXISTS       0x1
4858
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4859
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4860
typedef struct SVCreateTbReq {
4861
  int32_t  flags;
4862
  char*    name;
4863
  tb_uid_t uid;
4864
  int64_t  btime;
4865
  int32_t  ttl;
4866
  int32_t  commentLen;
4867
  char*    comment;
4868
  int8_t   type;
4869
  union {
4870
    struct {
4871
      char*    stbName;  // super table name
4872
      uint8_t  tagNum;
4873
      tb_uid_t suid;
4874
      SArray*  tagName;
4875
      uint8_t* pTag;
4876
    } ctb;
4877
    struct {
4878
      SSchemaWrapper schemaRow;
4879
      int64_t        userId;
4880
    } ntb;
4881
  };
4882
  int32_t         sqlLen;
4883
  char*           sql;
4884
  SColCmprWrapper colCmpr;
4885
  SExtSchema*     pExtSchemas;
4886
  SColRefWrapper  colRef;  // col reference for virtual table
4887
} SVCreateTbReq;
4888

4889
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4890
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4891
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4892
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4893

4894
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4895
  if (NULL == req) {
2,147,483,647✔
4896
    return;
2,146,676,128✔
4897
  }
4898

4899
  taosMemoryFreeClear(req->sql);
80,537,108✔
4900
  taosMemoryFreeClear(req->name);
80,543,644✔
4901
  taosMemoryFreeClear(req->comment);
80,563,377✔
4902
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
80,540,719✔
4903
    taosMemoryFreeClear(req->ctb.pTag);
73,325,510✔
4904
    taosMemoryFreeClear(req->ctb.stbName);
73,314,522✔
4905
    taosArrayDestroy(req->ctb.tagName);
73,347,176✔
4906
    req->ctb.tagName = NULL;
73,259,967✔
4907
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
7,229,271✔
4908
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
7,229,271✔
4909
  }
4910
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
80,494,188✔
4911
  taosMemoryFreeClear(req->pExtSchemas);
80,547,390✔
4912
  taosMemoryFreeClear(req->colRef.pColRef);
80,550,480✔
4913
}
4914

4915
typedef struct {
4916
  int32_t nReqs;
4917
  union {
4918
    SVCreateTbReq* pReqs;
4919
    SArray*        pArray;
4920
  };
4921
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4922
} SVCreateTbBatchReq;
4923

4924
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4925
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4926
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4927

4928
typedef struct {
4929
  int32_t        code;
4930
  STableMetaRsp* pMeta;
4931
} SVCreateTbRsp, SVUpdateTbRsp;
4932

4933
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4934
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4935
void tFreeSVCreateTbRsp(void* param);
4936

4937
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4938
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4939

4940
typedef struct {
4941
  int32_t nRsps;
4942
  union {
4943
    SVCreateTbRsp* pRsps;
4944
    SArray*        pArray;
4945
  };
4946
} SVCreateTbBatchRsp;
4947

4948
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4949
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4950

4951
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4952
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4953

4954
// TDMT_VND_DROP_TABLE =================
4955
typedef struct {
4956
  char*    name;
4957
  uint64_t suid;  // for tmq in wal format
4958
  int64_t  uid;
4959
  int8_t   igNotExists;
4960
  int8_t   isVirtual;
4961
} SVDropTbReq;
4962

4963
typedef struct {
4964
  int32_t code;
4965
} SVDropTbRsp;
4966

4967
typedef struct {
4968
  int32_t nReqs;
4969
  union {
4970
    SVDropTbReq* pReqs;
4971
    SArray*      pArray;
4972
  };
4973
} SVDropTbBatchReq;
4974

4975
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4976
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4977

4978
typedef struct {
4979
  int32_t nRsps;
4980
  union {
4981
    SVDropTbRsp* pRsps;
4982
    SArray*      pArray;
4983
  };
4984
} SVDropTbBatchRsp;
4985

4986
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4987
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4988

4989
// TDMT_VND_ALTER_TABLE =====================
4990
typedef struct SUpdatedTagVal {
4991
  char*    tagName;
4992
  int32_t  colId;
4993
  int8_t   tagType;
4994
  int8_t   tagFree;
4995
  uint32_t nTagVal;
4996
  uint8_t* pTagVal;
4997
  int8_t   isNull;
4998
  SArray*  pTagArray;
4999
  // NOTE: regexp and replacement are only a temporary solution for tag value update,
5000
  // they should be replaced by a more generic solution in the future for full expression
5001
  // support
5002
  char*    regexp;
5003
  char*    replacement;
5004
} SUpdatedTagVal;
5005

5006
typedef struct SUpdateTableTagVal {
5007
  char *tbName;
5008
  SArray* tags; // Array of SUpdatedTagVal
5009
} SUpdateTableTagVal;
5010

5011
typedef struct SVAlterTbReq {
5012
  char*   tbName;
5013
  int8_t  action;
5014
  char*   colName;
5015
  int32_t colId;
5016
  // TSDB_ALTER_TABLE_ADD_COLUMN
5017
  int8_t  type;
5018
  int8_t  flags;
5019
  int32_t bytes;
5020
  // TSDB_ALTER_TABLE_DROP_COLUMN
5021
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
5022
  int8_t   colModType;
5023
  int32_t  colModBytes;
5024
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
5025
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
5026
  int8_t   isNull;
5027
  int8_t   tagType;
5028
  int8_t   tagFree;
5029
  uint32_t nTagVal;
5030
  uint8_t* pTagVal;
5031
  SArray*  pTagArray;
5032
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
5033
  int8_t   updateTTL;
5034
  int32_t  newTTL;
5035
  int32_t  newCommentLen;
5036
  char*    newComment;
5037
  int64_t  ctimeMs;    // fill by vnode
5038
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
5039
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
5040
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS and TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL
5041
  SArray*  tables;     // Array of SUpdateTableTagVal, for TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL
5042
  int32_t  whereLen;   // [whereLen] & [where] are for TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL,
5043
  uint8_t* where;      // [where] is the encode where condition.
5044
  // for Add column
5045
  STypeMod typeMod;
5046
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
5047
  char* refDbName;
5048
  char* refTbName;
5049
  char* refColName;
5050
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
5051
} SVAlterTbReq;
5052

5053
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
5054
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
5055
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
5056
void    tfreeMultiTagUpateVal(void* pMultiTag);
5057
void    tfreeUpdateTableTagVal(void* pMultiTable);
5058

5059
typedef struct {
5060
  int32_t        code;
5061
  STableMetaRsp* pMeta;
5062
} SVAlterTbRsp;
5063

5064
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
5065
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
5066
// ======================
5067

5068
typedef struct {
5069
  SMsgHead head;
5070
  int64_t  uid;
5071
  int32_t  tid;
5072
  int16_t  tversion;
5073
  int16_t  colId;
5074
  int8_t   type;
5075
  int16_t  bytes;
5076
  int32_t  tagValLen;
5077
  int16_t  numOfTags;
5078
  int32_t  schemaLen;
5079
  char     data[];
5080
} SUpdateTagValReq;
5081

5082
typedef struct {
5083
  SMsgHead head;
5084
} SUpdateTagValRsp;
5085

5086
typedef struct {
5087
  SMsgHead head;
5088
} SVShowTablesReq;
5089

5090
typedef struct {
5091
  SMsgHead head;
5092
  int32_t  id;
5093
} SVShowTablesFetchReq;
5094

5095
typedef struct {
5096
  int64_t useconds;
5097
  int8_t  completed;  // all results are returned to client
5098
  int8_t  precision;
5099
  int8_t  compressed;
5100
  int32_t compLen;
5101
  int32_t numOfRows;
5102
  char    data[];
5103
} SVShowTablesFetchRsp;
5104

5105
typedef struct {
5106
  int64_t consumerId;
5107
  int32_t epoch;
5108
  char    cgroup[TSDB_CGROUP_LEN];
5109
} SMqAskEpReq;
5110

5111
typedef struct {
5112
  int32_t key;
5113
  int32_t valueLen;
5114
  void*   value;
5115
} SKv;
5116

5117
typedef struct {
5118
  int64_t tscRid;
5119
  int8_t  connType;
5120
} SClientHbKey;
5121

5122
typedef struct {
5123
  int64_t tid;
5124
  char    status[TSDB_JOB_STATUS_LEN];
5125
  int64_t startTs;  // sub-task first execution start time, us
5126
} SQuerySubDesc;
5127

5128
typedef enum EQueryExecPhase {
5129
  /* Main phases: 0-9 */
5130
  QUERY_PHASE_NONE     = 0,
5131
  QUERY_PHASE_PARSE    = 1,
5132
  QUERY_PHASE_CATALOG  = 2,
5133
  QUERY_PHASE_PLAN     = 3,
5134
  QUERY_PHASE_SCHEDULE = 4,
5135
  QUERY_PHASE_EXECUTE  = 5,
5136
  QUERY_PHASE_FETCH    = 6,
5137
  QUERY_PHASE_DONE     = 7,
5138

5139
  /* SCHEDULE sub-phases: 4x */
5140
  QUERY_PHASE_SCHEDULE_ANALYSIS       = 41,
5141
  QUERY_PHASE_SCHEDULE_PLANNING       = 42,
5142
  QUERY_PHASE_SCHEDULE_NODE_SELECTION = 43,
5143

5144
  /* EXECUTE sub-phases: 5x */
5145
  QUERY_PHASE_EXEC_DATA_QUERY       = 51,
5146
  QUERY_PHASE_EXEC_MERGE_QUERY      = 52,
5147
  QUERY_PHASE_EXEC_WAITING_CHILDREN = 53,
5148

5149
  /* FETCH sub-phases: 6x */
5150
  QUERY_PHASE_FETCH_IN_PROGRESS = 60,  // A single fetch operation is in progress
5151
  QUERY_PHASE_FETCH_RETURNED    = 61,  // Data returned to client, business logic processing
5152
} EQueryExecPhase;
5153

5154
const char* queryPhaseStr(int32_t phase);
5155

5156
typedef struct {
5157
  char     sql[TSDB_SHOW_SQL_LEN];
5158
  uint64_t queryId;
5159
  int64_t  useconds;
5160
  int64_t  stime;  // timestamp precision ms
5161
  int64_t  reqRid;
5162
  bool     stableQuery;
5163
  bool     isSubQuery;
5164
  char     fqdn[TSDB_FQDN_LEN];
5165
  int32_t  subPlanNum;
5166
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5167
  int32_t  execPhase;       // EQueryExecPhase
5168
  int64_t  phaseStartTime;  // when current phase started, ms
5169
} SQueryDesc;
5170

5171
typedef struct {
5172
  uint32_t connId;
5173
  SArray*  queryDesc;  // SArray<SQueryDesc>
5174
} SQueryHbReqBasic;
5175

5176
typedef struct {
5177
  uint32_t connId;
5178
  uint64_t killRid;
5179
  int32_t  totalDnodes;
5180
  int32_t  onlineDnodes;
5181
  int8_t   killConnection;
5182
  int8_t   align[3];
5183
  SEpSet   epSet;
5184
  SArray*  pQnodeList;
5185
} SQueryHbRspBasic;
5186

5187
typedef struct SAppClusterSummary {
5188
  uint64_t numOfInsertsReq;
5189
  uint64_t numOfInsertRows;
5190
  uint64_t insertElapsedTime;
5191
  uint64_t insertBytes;  // submit to tsdb since launched.
5192

5193
  uint64_t fetchBytes;
5194
  uint64_t numOfQueryReq;
5195
  uint64_t queryElapsedTime;
5196
  uint64_t numOfSlowQueries;
5197
  uint64_t totalRequests;
5198
  uint64_t currentRequests;  // the number of SRequestObj
5199
} SAppClusterSummary;
5200

5201
typedef struct {
5202
  int64_t            appId;
5203
  int32_t            pid;
5204
  char               name[TSDB_APP_NAME_LEN];
5205
  int64_t            startTime;
5206
  SAppClusterSummary summary;
5207
} SAppHbReq;
5208

5209
typedef struct {
5210
  SClientHbKey      connKey;
5211
  int64_t           clusterId;
5212
  SAppHbReq         app;
5213
  SQueryHbReqBasic* query;
5214
  SHashObj*         info;  // hash<Skv.key, Skv>
5215
  char              user[TSDB_USER_LEN];
5216
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5217
  char              userApp[TSDB_APP_NAME_LEN];
5218
  uint32_t          userIp;
5219
  SIpRange          userDualIp;
5220
  char              sVer[TSDB_VERSION_LEN];
5221
  char              cInfo[CONNECTOR_INFO_LEN];
5222
} SClientHbReq;
5223

5224
typedef struct {
5225
  int64_t reqId;
5226
  SArray* reqs;  // SArray<SClientHbReq>
5227
  int64_t ipWhiteListVer;
5228
} SClientHbBatchReq;
5229

5230
typedef struct {
5231
  SClientHbKey      connKey;
5232
  int32_t           status;
5233
  SQueryHbRspBasic* query;
5234
  SArray*           info;  // Array<Skv>
5235
} SClientHbRsp;
5236

5237
typedef struct {
5238
  int64_t       reqId;
5239
  int64_t       rspId;
5240
  int32_t       svrTimestamp;
5241
  SArray*       rsps;  // SArray<SClientHbRsp>
5242
  SMonitorParas monitorParas;
5243
  int8_t        enableAuditDelete;
5244
  int8_t        enableStrongPass;
5245
  int8_t        enableAuditSelect;
5246
  int8_t        enableAuditInsert;
5247
  int8_t        auditLevel;
5248
} SClientHbBatchRsp;
5249

5250
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
410,021,326✔
5251

5252
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5253
  void* pIter = taosHashIterate(info, NULL);
54,671,865✔
5254
  while (pIter != NULL) {
128,398,438✔
5255
    SKv* kv = (SKv*)pIter;
73,724,318✔
5256
    taosMemoryFreeClear(kv->value);
73,724,318✔
5257
    pIter = taosHashIterate(info, pIter);
73,722,552✔
5258
  }
5259
}
54,674,120✔
5260

5261
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
36,489,038✔
5262
  SQueryDesc* desc = (SQueryDesc*)pDesc;
36,489,038✔
5263
  if (desc->subDesc) {
36,489,038✔
5264
    taosArrayDestroy(desc->subDesc);
26,019,175✔
5265
    desc->subDesc = NULL;
26,018,889✔
5266
  }
5267
}
36,489,750✔
5268

5269
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
63,281,201✔
5270
  SClientHbReq* req = (SClientHbReq*)pReq;
148,243,570✔
5271
  if (req->query) {
148,243,570✔
5272
    if (req->query->queryDesc) {
63,278,788✔
5273
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
30,079,319✔
5274
    }
5275
    taosMemoryFreeClear(req->query);
63,279,993✔
5276
  }
5277

5278
  if (req->info) {
148,244,835✔
5279
    tFreeReqKvHash(req->info);
54,670,387✔
5280
    taosHashCleanup(req->info);
54,674,120✔
5281
    req->info = NULL;
54,672,890✔
5282
  }
5283
}
114,823,144✔
5284

5285
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5286
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5287

5288
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5289
  if (pReq == NULL) return;
27,113,473✔
5290
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
27,113,473✔
5291
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
27,113,473✔
5292
  taosMemoryFree(pReq);
27,113,473✔
5293
}
5294

5295
static FORCE_INLINE void tFreeClientKv(void* pKv) {
73,466,007✔
5296
  SKv* kv = (SKv*)pKv;
73,466,007✔
5297
  if (kv) {
73,466,007✔
5298
    taosMemoryFreeClear(kv->value);
73,466,159✔
5299
  }
5300
}
73,466,474✔
5301

5302
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
63,014,112✔
5303
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
63,014,112✔
5304
  if (rsp->query) {
63,014,112✔
5305
    taosArrayDestroy(rsp->query->pQnodeList);
63,002,219✔
5306
    taosMemoryFreeClear(rsp->query);
62,996,689✔
5307
  }
5308
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
63,016,399✔
5309
}
33,156,858✔
5310

5311
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5312
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
51,737,490✔
5313
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
51,737,490✔
5314
}
51,737,830✔
5315

5316
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5317
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5318
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5319

5320
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5321
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
465,029,855✔
5322
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
465,030,208✔
5323
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
465,033,014✔
5324
  return 0;
232,519,074✔
5325
}
5326

5327
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5328
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
151,668,245✔
5329
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
151,668,308✔
5330

5331
  if (pKv->valueLen < 0) {
75,834,428✔
NEW
5332
    return TSDB_CODE_INVALID_MSG;
×
5333
  }
5334

5335
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
75,834,699✔
5336
  if (pKv->value == NULL) {
75,833,546✔
NEW
5337
    return TSDB_CODE_OUT_OF_MEMORY;
×
5338
  }
5339
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
75,833,092✔
5340
  return 0;
75,834,553✔
5341
}
5342

5343
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5344
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
402,196,805✔
5345
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
402,192,221✔
5346
  return 0;
201,097,351✔
5347
}
5348

5349
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5350
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
130,819,374✔
5351
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
130,823,089✔
5352
  return 0;
65,414,744✔
5353
}
5354

5355
typedef struct {
5356
  int32_t vgId;
5357
  // TODO stas
5358
} SMqReportVgInfo;
5359

5360
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5361
  int32_t tlen = 0;
5362
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5363
  return tlen;
5364
}
5365

5366
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5367
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5368
  return buf;
5369
}
5370

5371
typedef struct {
5372
  int32_t epoch;
5373
  int64_t topicUid;
5374
  char    name[TSDB_TOPIC_FNAME_LEN];
5375
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5376
} SMqTopicInfo;
5377

5378
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5379
  int32_t tlen = 0;
5380
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5381
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5382
  tlen += taosEncodeString(buf, pTopicInfo->name);
5383
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5384
  tlen += taosEncodeFixedI32(buf, sz);
5385
  for (int32_t i = 0; i < sz; i++) {
5386
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5387
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5388
  }
5389
  return tlen;
5390
}
5391

5392
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5393
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5394
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5395
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5396
  int32_t sz;
5397
  buf = taosDecodeFixedI32(buf, &sz);
5398
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5399
    return NULL;
5400
  }
5401
  for (int32_t i = 0; i < sz; i++) {
5402
    SMqReportVgInfo vgInfo;
5403
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5404
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5405
      return NULL;
5406
    }
5407
  }
5408
  return buf;
5409
}
5410

5411
typedef struct {
5412
  int32_t status;  // ask hb endpoint
5413
  int32_t epoch;
5414
  int64_t consumerId;
5415
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5416
} SMqReportReq;
5417

5418
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5419
  int32_t tlen = 0;
5420
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5421
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5422
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5423
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5424
  tlen += taosEncodeFixedI32(buf, sz);
5425
  for (int32_t i = 0; i < sz; i++) {
5426
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5427
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5428
  }
5429
  return tlen;
5430
}
5431

5432
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5433
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5434
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5435
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5436
  int32_t sz;
5437
  buf = taosDecodeFixedI32(buf, &sz);
5438
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5439
    return NULL;
5440
  }
5441
  for (int32_t i = 0; i < sz; i++) {
5442
    SMqTopicInfo topicInfo;
5443
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5444
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5445
      return NULL;
5446
    }
5447
  }
5448
  return buf;
5449
}
5450

5451
typedef struct {
5452
  SMsgHead head;
5453
  int64_t  leftForVer;
5454
  int32_t  vgId;
5455
  int64_t  consumerId;
5456
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5457
} SMqVDeleteReq;
5458

5459
typedef struct {
5460
  int8_t reserved;
5461
} SMqVDeleteRsp;
5462

5463
typedef struct {
5464
  char**  name;
5465
  int32_t count;
5466
  int8_t  igNotExists;
5467
} SMDropStreamReq;
5468

5469
typedef struct {
5470
  int8_t reserved;
5471
} SMDropStreamRsp;
5472

5473
typedef struct {
5474
  SMsgHead head;
5475
  int64_t  resetRelHalt;  // reset related stream task halt status
5476
  int64_t  streamId;
5477
  int32_t  taskId;
5478
} SVDropStreamTaskReq;
5479

5480
typedef struct {
5481
  int8_t reserved;
5482
} SVDropStreamTaskRsp;
5483

5484
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5485
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5486
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5487

5488
typedef struct {
5489
  char*  name;
5490
  int8_t igNotExists;
5491
} SMPauseStreamReq;
5492

5493
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5494
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5495
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5496

5497
typedef struct {
5498
  char*  name;
5499
  int8_t igNotExists;
5500
  int8_t igUntreated;
5501
} SMResumeStreamReq;
5502

5503
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5504
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5505
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5506

5507
typedef struct {
5508
  char*       name;
5509
  int8_t      calcAll;
5510
  STimeWindow timeRange;
5511
} SMRecalcStreamReq;
5512

5513
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5514
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5515
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5516

5517
typedef struct SVndSetKeepVersionReq {
5518
  int64_t keepVersion;
5519
} SVndSetKeepVersionReq;
5520

5521
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5522
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5523

5524
typedef struct SVUpdateCheckpointInfoReq {
5525
  SMsgHead head;
5526
  int64_t  streamId;
5527
  int32_t  taskId;
5528
  int64_t  checkpointId;
5529
  int64_t  checkpointVer;
5530
  int64_t  checkpointTs;
5531
  int32_t  transId;
5532
  int64_t  hStreamId;  // add encode/decode
5533
  int64_t  hTaskId;
5534
  int8_t   dropRelHTask;
5535
} SVUpdateCheckpointInfoReq;
5536

5537
typedef struct {
5538
  int64_t        leftForVer;
5539
  int32_t        vgId;
5540
  int64_t        oldConsumerId;
5541
  int64_t        newConsumerId;
5542
  char           subKey[TSDB_SUBSCRIBE_KEY_LEN];
5543
  int8_t         subType;
5544
  int8_t         withMeta;
5545
  char*          qmsg;  // SubPlanToString
5546
  SSchemaWrapper schema;
5547
  int64_t        suid;
5548
} SMqRebVgReq;
5549

5550
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5551
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5552

5553
// tqOffset
5554
enum {
5555
  TMQ_OFFSET__RESET_NONE = -3,
5556
  TMQ_OFFSET__RESET_EARLIEST = -2,
5557
  TMQ_OFFSET__RESET_LATEST = -1,
5558
  TMQ_OFFSET__LOG = 1,
5559
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5560
  TMQ_OFFSET__SNAPSHOT_META = 3,
5561
};
5562

5563
enum {
5564
  WITH_DATA = 0,
5565
  WITH_META = 1,
5566
  ONLY_META = 2,
5567
};
5568

5569
#define TQ_OFFSET_VERSION 1
5570

5571
typedef struct {
5572
  int8_t type;
5573
  union {
5574
    // snapshot
5575
    struct {
5576
      int64_t uid;
5577
      int64_t ts;
5578
      SValue  primaryKey;
5579
    };
5580
    // log
5581
    struct {
5582
      int64_t version;
5583
    };
5584
  };
5585
} STqOffsetVal;
5586

5587
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5588
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
8,060,816✔
5589
  pOffsetVal->uid = uid;
8,060,178✔
5590
  pOffsetVal->ts = ts;
8,060,819✔
5591
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
8,059,540✔
5592
    taosMemoryFree(pOffsetVal->primaryKey.pData);
306✔
5593
  }
5594
  pOffsetVal->primaryKey = primaryKey;
8,061,776✔
5595
}
8,059,859✔
5596

5597
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5598
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
12,121✔
5599
  pOffsetVal->uid = uid;
12,121✔
5600
}
12,121✔
5601

5602
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5603
  pOffsetVal->type = TMQ_OFFSET__LOG;
11,448,225✔
5604
  pOffsetVal->version = ver;
11,447,831✔
5605
}
11,447,500✔
5606

5607
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5608
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5609
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5610
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5611
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5612
void    tOffsetDestroy(void* pVal);
5613

5614
typedef struct {
5615
  STqOffsetVal val;
5616
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5617
} STqOffset;
5618

5619
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5620
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5621
void    tDeleteSTqOffset(void* val);
5622

5623
typedef struct SMqVgOffset {
5624
  int64_t   consumerId;
5625
  STqOffset offset;
5626
} SMqVgOffset;
5627

5628
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5629
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5630

5631
typedef struct {
5632
  char    name[TSDB_TABLE_FNAME_LEN];
5633
  char    stb[TSDB_TABLE_FNAME_LEN];
5634
  int8_t  igExists;
5635
  int8_t  intervalUnit;
5636
  int8_t  slidingUnit;
5637
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5638
  int32_t dstVgId;   // for stream
5639
  int64_t interval;
5640
  int64_t offset;
5641
  int64_t sliding;
5642
  int64_t maxDelay;
5643
  int64_t watermark;
5644
  int32_t exprLen;        // strlen + 1
5645
  int32_t tagsFilterLen;  // strlen + 1
5646
  int32_t sqlLen;         // strlen + 1
5647
  int32_t astLen;         // strlen + 1
5648
  char*   expr;
5649
  char*   tagsFilter;
5650
  char*   sql;
5651
  char*   ast;
5652
  int64_t deleteMark;
5653
  int64_t lastTs;
5654
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5655
  SArray* pVgroupVerList;
5656
  int8_t  recursiveTsma;
5657
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5658
  char*   createStreamReq;
5659
  int32_t streamReqLen;
5660
  char*   dropStreamReq;
5661
  int32_t dropStreamReqLen;
5662
  int64_t uid;
5663
} SMCreateSmaReq;
5664

5665
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5666
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5667
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5668

5669
typedef struct {
5670
  char    name[TSDB_TABLE_FNAME_LEN];
5671
  int8_t  igNotExists;
5672
  char*   dropStreamReq;
5673
  int32_t dropStreamReqLen;
5674
} SMDropSmaReq;
5675

5676
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5677
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5678
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5679

5680
typedef struct {
5681
  char name[TSDB_TABLE_NAME_LEN];
5682
  union {
5683
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5684
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5685
  };
5686
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5687
  union {
5688
    int8_t igExists;   // used by mnode
5689
    int8_t alterType;  // used by vnode
5690
  };
5691
  int8_t     intervalUnit;
5692
  int16_t    nFuncs;       // number of functions specified by user
5693
  col_id_t*  funcColIds;   // column ids specified by user
5694
  func_id_t* funcIds;      // function ids specified by user
5695
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5696
  int64_t    tbUid;
5697
  int64_t    uid;     // rsma uid
5698
  int32_t    sqlLen;  // strlen + 1
5699
  char*      sql;
5700
} SMCreateRsmaReq;
5701

5702
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5703
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5704
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5705

5706
typedef SMCreateRsmaReq SVCreateRsmaReq;
5707

5708
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5709
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5710
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5711

5712
typedef SMCreateRsmaReq SVAlterRsmaReq;
5713

5714
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5715
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5716
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5717

5718
typedef struct {
5719
  char       name[TSDB_TABLE_NAME_LEN];
5720
  int8_t     alterType;
5721
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5722
  int8_t     igNotExists;
5723
  int16_t    nFuncs;      // number of functions specified by user
5724
  col_id_t*  funcColIds;  // column ids specified by user
5725
  func_id_t* funcIds;     // function ids specified by user
5726
  int32_t    sqlLen;      // strlen + 1
5727
  char*      sql;
5728
} SMAlterRsmaReq;
5729

5730
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5731
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5732
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5733

5734
typedef struct {
5735
  int64_t    id;
5736
  char       name[TSDB_TABLE_NAME_LEN];
5737
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5738
  int64_t    ownerId;
5739
  int32_t    code;
5740
  int32_t    version;
5741
  int8_t     tbType;
5742
  int8_t     intervalUnit;
5743
  col_id_t   nFuncs;
5744
  col_id_t   nColNames;
5745
  int64_t    interval[2];
5746
  col_id_t*  funcColIds;
5747
  func_id_t* funcIds;
5748
  SArray*    colNames;
5749
} SRsmaInfoRsp;
5750

5751
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5752
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5753
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5754

5755
typedef struct {
5756
  char   name[TSDB_TABLE_FNAME_LEN];
5757
  int8_t igNotExists;
5758
} SMDropRsmaReq;
5759

5760
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5761
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5762

5763
typedef struct {
5764
  char    name[TSDB_TABLE_NAME_LEN];
5765
  char    tbName[TSDB_TABLE_NAME_LEN];
5766
  int64_t uid;
5767
  int64_t tbUid;
5768
  int8_t  tbType;
5769
} SVDropRsmaReq;
5770

5771
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5772
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5773

5774
typedef struct {
5775
  char   dbFName[TSDB_DB_FNAME_LEN];
5776
  char   stbName[TSDB_TABLE_NAME_LEN];
5777
  char   colName[TSDB_COL_NAME_LEN];
5778
  char   idxName[TSDB_INDEX_FNAME_LEN];
5779
  int8_t idxType;
5780
} SCreateTagIndexReq;
5781

5782
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5783
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5784

5785
typedef SMDropSmaReq SDropTagIndexReq;
5786

5787
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5788
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5789

5790
typedef struct {
5791
  int8_t         version;       // for compatibility(default 0)
5792
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5793
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5794
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5795
  int32_t        dstVgId;
5796
  char           indexName[TSDB_INDEX_NAME_LEN];
5797
  int32_t        exprLen;
5798
  int32_t        tagsFilterLen;
5799
  int64_t        indexUid;
5800
  tb_uid_t       tableUid;  // super/child/common table uid
5801
  tb_uid_t       dstTbUid;  // for dstVgroup
5802
  int64_t        interval;
5803
  int64_t        offset;  // use unit by precision of DB
5804
  int64_t        sliding;
5805
  char*          dstTbName;  // for dstVgroup
5806
  char*          expr;       // sma expression
5807
  char*          tagsFilter;
5808
  SSchemaWrapper schemaRow;  // for dstVgroup
5809
  SSchemaWrapper schemaTag;  // for dstVgroup
5810
} STSma;                     // Time-range-wise SMA
5811

5812
typedef STSma SVCreateTSmaReq;
5813

5814
typedef struct {
5815
  int8_t  type;  // 0 status report, 1 update data
5816
  int64_t indexUid;
5817
  int64_t skey;  // start TS key of interval/sliding window
5818
} STSmaMsg;
5819

5820
typedef struct {
5821
  int64_t indexUid;
5822
  char    indexName[TSDB_INDEX_NAME_LEN];
5823
} SVDropTSmaReq;
5824

5825
typedef struct {
5826
  int tmp;  // TODO: to avoid compile error
5827
} SVCreateTSmaRsp, SVDropTSmaRsp;
5828

5829
#if 0
5830
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5831
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5832
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5833
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5834
#endif
5835

5836
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5837
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5838
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5839
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5840

5841
typedef struct {
5842
  int32_t number;
5843
  STSma*  tSma;
5844
} STSmaWrapper;
5845

5846
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5847
  if (pSma) {
×
5848
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5849
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
5850
    taosMemoryFreeClear(pSma->tagsFilter);
×
5851
  }
5852
}
×
5853

5854
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5855
  if (pSW) {
×
5856
    if (pSW->tSma) {
×
UNCOV
5857
      if (deepCopy) {
×
UNCOV
5858
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5859
          tDestroyTSma(pSW->tSma + i);
×
5860
        }
5861
      }
UNCOV
5862
      taosMemoryFreeClear(pSW->tSma);
×
5863
    }
5864
  }
UNCOV
5865
}
×
5866

5867
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5868
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5869
  taosMemoryFreeClear(pSW);
×
UNCOV
5870
  return NULL;
×
5871
}
5872

5873
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5874
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5875

5876
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5877
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5878

UNCOV
5879
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
5880
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
5881
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5882
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5883
  }
UNCOV
5884
  return 0;
×
5885
}
5886

UNCOV
5887
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5888
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5889
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5890
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5891
  }
UNCOV
5892
  return 0;
×
5893
}
5894

5895
typedef struct {
5896
  int idx;
5897
} SMCreateFullTextReq;
5898

5899
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5900
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5901
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5902

5903
typedef struct {
5904
  char   name[TSDB_TABLE_FNAME_LEN];
5905
  int8_t igNotExists;
5906
} SMDropFullTextReq;
5907

5908
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5909
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5910

5911
typedef struct {
5912
  char indexFName[TSDB_INDEX_FNAME_LEN];
5913
} SUserIndexReq;
5914

5915
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5916
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5917

5918
typedef struct {
5919
  char dbFName[TSDB_DB_FNAME_LEN];
5920
  char tblFName[TSDB_TABLE_FNAME_LEN];
5921
  char colName[TSDB_COL_NAME_LEN];
5922
  char owner[TSDB_USER_LEN];
5923
  char indexType[TSDB_INDEX_TYPE_LEN];
5924
  char indexExts[TSDB_INDEX_EXTS_LEN];
5925
} SUserIndexRsp;
5926

5927
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5928
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5929

5930
typedef struct {
5931
  char tbFName[TSDB_TABLE_FNAME_LEN];
5932
} STableIndexReq;
5933

5934
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5935
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5936

5937
typedef struct {
5938
  int8_t  intervalUnit;
5939
  int8_t  slidingUnit;
5940
  int64_t interval;
5941
  int64_t offset;
5942
  int64_t sliding;
5943
  int64_t dstTbUid;
5944
  int32_t dstVgId;
5945
  SEpSet  epSet;
5946
  char*   expr;
5947
} STableIndexInfo;
5948

5949
typedef struct {
5950
  char     tbName[TSDB_TABLE_NAME_LEN];
5951
  char     dbFName[TSDB_DB_FNAME_LEN];
5952
  uint64_t suid;
5953
  int32_t  version;
5954
  int32_t  indexSize;
5955
  SArray*  pIndex;  // STableIndexInfo
5956
} STableIndexRsp;
5957

5958
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5959
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5960
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5961

5962
void tFreeSTableIndexInfo(void* pInfo);
5963

5964
typedef struct {
5965
  int8_t  mqMsgType;
5966
  int32_t code;
5967
  int32_t epoch;
5968
  int64_t consumerId;
5969
  int64_t walsver;
5970
  int64_t walever;
5971
} SMqRspHead;
5972

5973
typedef struct {
5974
  SMsgHead     head;
5975
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5976
  int8_t       withTbName;
5977
  int8_t       useSnapshot;
5978
  int32_t      epoch;
5979
  uint64_t     reqId;
5980
  int64_t      consumerId;
5981
  int64_t      timeout;
5982
  STqOffsetVal reqOffset;
5983
  int8_t       enableReplay;
5984
  int8_t       sourceExcluded;
5985
  int8_t       rawData;
5986
  int32_t      minPollRows;
5987
  int8_t       enableBatchMeta;
5988
  SHashObj*    uidHash;  // to find if uid is duplicated
5989
} SMqPollReq;
5990

5991
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5992
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5993
void    tDestroySMqPollReq(SMqPollReq* pReq);
5994

5995
typedef struct {
5996
  int32_t vgId;
5997
  int64_t offset;
5998
  SEpSet  epSet;
5999
} SMqSubVgEp;
6000

6001
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
6002
  int32_t tlen = 0;
2,701,708✔
6003
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,701,708✔
6004
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,701,708✔
6005
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,701,708✔
6006
  return tlen;
2,701,708✔
6007
}
6008

6009
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
6010
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,334,930✔
6011
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,334,930✔
6012
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,334,930✔
6013
  return buf;
1,334,930✔
6014
}
6015

6016
typedef struct {
6017
  char    topic[TSDB_TOPIC_FNAME_LEN];
6018
  char    db[TSDB_DB_FNAME_LEN];
6019
  SArray* vgs;  // SArray<SMqSubVgEp>
6020
} SMqSubTopicEp;
6021

6022
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
6023
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
6024
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
6025

6026
typedef struct {
6027
  SMqRspHead   head;
6028
  STqOffsetVal rspOffset;
6029
  int16_t      resMsgType;
6030
  int32_t      metaRspLen;
6031
  void*        metaRsp;
6032
} SMqMetaRsp;
6033

6034
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
6035
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
6036
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
6037

6038
#define MQ_DATA_RSP_VERSION 100
6039

6040
typedef struct {
6041
  SMqRspHead   head;
6042
  STqOffsetVal rspOffset;
6043
  STqOffsetVal reqOffset;
6044
  int32_t      blockNum;
6045
  int8_t       withTbName;
6046
  int8_t       withSchema;
6047
  SArray*      blockDataLen;
6048
  SArray*      blockData;
6049
  SArray*      blockTbName;
6050
  SArray*      blockSchema;
6051

6052
  union {
6053
    struct {
6054
      int64_t sleepTime;
6055
    };
6056
    struct {
6057
      int32_t createTableNum;
6058
      SArray* createTableLen;
6059
      SArray* createTableReq;
6060
    };
6061
    struct {
6062
      int32_t len;
6063
      void*   rawData;
6064
    };
6065
  };
6066
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
6067
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
6068
  bool  timeout;
6069
} SMqDataRsp;
6070

6071
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
6072
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6073
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6074
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
6075
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
6076

6077
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
6078
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6079
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
6080

6081
typedef struct SMqBatchMetaRsp {
6082
  SMqRspHead   head;  // not serialize
6083
  STqOffsetVal rspOffset;
6084
  SArray*      batchMetaLen;
6085
  SArray*      batchMetaReq;
6086
  void*        pMetaBuff;    // not serialize
6087
  uint32_t     metaBuffLen;  // not serialize
6088
} SMqBatchMetaRsp;
6089

6090
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
6091
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6092
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6093
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
6094

6095
typedef struct {
6096
  int32_t code;
6097
  SArray* topics;  // SArray<SMqSubTopicEp>
6098
} SMqAskEpRsp;
6099

6100
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6101
  int32_t tlen = 0;
7,717,038✔
6102
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6103
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,717,038✔
6104
  tlen += taosEncodeFixedI32(buf, sz);
7,717,059✔
6105
  for (int32_t i = 0; i < sz; i++) {
9,787,643✔
6106
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
2,070,584✔
6107
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
2,070,584✔
6108
  }
6109
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,717,059✔
6110

6111
  return tlen;
7,716,703✔
6112
}
6113

6114
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6115
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6116
  int32_t sz;
3,413,736✔
6117
  buf = taosDecodeFixedI32(buf, &sz);
3,486,390✔
6118
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,486,390✔
6119
  if (pRsp->topics == NULL) {
3,486,401✔
UNCOV
6120
    return NULL;
×
6121
  }
6122
  for (int32_t i = 0; i < sz; i++) {
4,494,542✔
6123
    SMqSubTopicEp topicEp;
996,068✔
6124
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
1,008,141✔
6125
    if (buf == NULL) {
1,008,141✔
UNCOV
6126
      return NULL;
×
6127
    }
6128
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
2,016,282✔
UNCOV
6129
      return NULL;
×
6130
    }
6131
  }
6132
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,486,401✔
6133

6134
  return buf;
3,486,401✔
6135
}
6136

6137
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6138
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,910,052✔
6139
}
9,909,329✔
6140

6141
typedef struct {
6142
  int32_t      vgId;
6143
  STqOffsetVal offset;
6144
  int64_t      rows;
6145
  int64_t      ever;
6146
} OffsetRows;
6147

6148
typedef struct {
6149
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6150
  SArray* offsetRows;
6151
} TopicOffsetRows;
6152

6153
typedef struct {
6154
  int64_t consumerId;
6155
  int32_t epoch;
6156
  SArray* topics;
6157
  int8_t  pollFlag;
6158
} SMqHbReq;
6159

6160
typedef struct {
6161
  char   topic[TSDB_TOPIC_FNAME_LEN];
6162
  int8_t noPrivilege;
6163
} STopicPrivilege;
6164

6165
typedef struct {
6166
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6167
  int32_t debugFlag;
6168
} SMqHbRsp;
6169

6170
typedef struct {
6171
  SMsgHead head;
6172
  int64_t  consumerId;
6173
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6174
} SMqSeekReq;
6175

6176
#define TD_AUTO_CREATE_TABLE 0x1
6177
typedef struct {
6178
  int64_t       suid;
6179
  int64_t       uid;
6180
  int32_t       sver;
6181
  uint32_t      nData;
6182
  uint8_t*      pData;
6183
  SVCreateTbReq cTbReq;
6184
} SVSubmitBlk;
6185

6186
typedef struct {
6187
  SMsgHead header;
6188
  uint64_t sId;
6189
  uint64_t queryId;
6190
  uint64_t clientId;
6191
  uint64_t taskId;
6192
  uint32_t sqlLen;
6193
  uint32_t phyLen;
6194
  char*    sql;
6195
  char*    msg;
6196
  int8_t   source;
6197
  int8_t   secureDelete;
6198
} SVDeleteReq;
6199

6200
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6201
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6202

6203
typedef struct {
6204
  int64_t affectedRows;
6205
} SVDeleteRsp;
6206

6207
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6208
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6209

6210
typedef struct SDeleteRes {
6211
  uint64_t suid;
6212
  SArray*  uidList;
6213
  int64_t  skey;
6214
  int64_t  ekey;
6215
  int64_t  affectedRows;
6216
  char     tableFName[TSDB_TABLE_NAME_LEN];
6217
  char     tsColName[TSDB_COL_NAME_LEN];
6218
  int64_t  ctimeMs;  // fill by vnode
6219
  int8_t   source;
6220
  int8_t   secureDelete;  // force physical overwrite
6221
} SDeleteRes;
6222

6223
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6224
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6225

6226
typedef struct {
6227
  // int64_t uid;
6228
  char    tbname[TSDB_TABLE_NAME_LEN];
6229
  int64_t startTs;
6230
  int64_t endTs;
6231
} SSingleDeleteReq;
6232

6233
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6234
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6235

6236
typedef struct {
6237
  int64_t suid;
6238
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6239
  int64_t ctimeMs;     // fill by vnode
6240
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6241
} SBatchDeleteReq;
6242

6243
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6244
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6245
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6246

6247
typedef struct {
6248
  int32_t msgIdx;
6249
  int32_t msgType;
6250
  int32_t msgLen;
6251
  void*   msg;
6252
} SBatchMsg;
6253

6254
typedef struct {
6255
  SMsgHead header;
6256
  SArray*  pMsgs;  // SArray<SBatchMsg>
6257
} SBatchReq;
6258

6259
typedef struct {
6260
  int32_t reqType;
6261
  int32_t msgIdx;
6262
  int32_t msgLen;
6263
  int32_t rspCode;
6264
  void*   msg;
6265
} SBatchRspMsg;
6266

6267
typedef struct {
6268
  SArray* pRsps;  // SArray<SBatchRspMsg>
6269
} SBatchRsp;
6270

6271
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6272
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6273
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
96,294,409✔
6274
  if (NULL == msg) {
96,294,409✔
UNCOV
6275
    return;
×
6276
  }
6277
  SBatchMsg* pMsg = (SBatchMsg*)msg;
96,294,409✔
6278
  taosMemoryFree(pMsg->msg);
96,294,409✔
6279
}
6280

6281
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6282
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6283

6284
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
136,760,418✔
6285
  if (NULL == p) {
136,760,418✔
UNCOV
6286
    return;
×
6287
  }
6288

6289
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
136,760,418✔
6290
  taosMemoryFree(pRsp->msg);
136,760,418✔
6291
}
6292

6293
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6294
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6295
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6296
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6297
void    tDestroySMqHbReq(SMqHbReq* pReq);
6298

6299
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6300
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6301
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6302

6303
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6304
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6305

6306
#define TD_REQ_FROM_APP               0x0
6307
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6308
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6309
#define SUBMIT_REQ_FROM_FILE          0x4
6310
#define TD_REQ_FROM_TAOX              0x8
6311
#define TD_REQ_FROM_SML               0x10
6312
#define SUBMIT_REQUEST_VERSION        (2)
6313
#define SUBMIT_REQ_WITH_BLOB          0x10
6314
#define SUBMIT_REQ_SCHEMA_RES         0x20
6315
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6316

6317
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6318

6319
typedef struct {
6320
  int32_t        flags;
6321
  SVCreateTbReq* pCreateTbReq;
6322
  int64_t        suid;
6323
  int64_t        uid;
6324
  int32_t        sver;
6325
  union {
6326
    SArray* aRowP;
6327
    SArray* aCol;
6328
  };
6329
  int64_t   ctimeMs;
6330
  SBlobSet* pBlobSet;
6331
} SSubmitTbData;
6332

6333
typedef struct {
6334
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6335
  SArray* aSubmitBlobData;
6336
  bool    raw;
6337
} SSubmitReq2;
6338

6339
typedef struct {
6340
  SMsgHead header;
6341
  int64_t  version;
6342
  char     data[];  // SSubmitReq2
6343
} SSubmitReq2Msg;
6344

6345
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6346
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6347
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6348
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6349
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6350

6351
typedef struct {
6352
  int32_t affectedRows;
6353
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6354
} SSubmitRsp2;
6355

6356
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6357
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6358
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6359

6360
#define TSDB_MSG_FLG_ENCODE 0x1
6361
#define TSDB_MSG_FLG_DECODE 0x2
6362
#define TSDB_MSG_FLG_CMPT   0x3
6363

6364
typedef struct {
6365
  union {
6366
    struct {
6367
      void*   msgStr;
6368
      int32_t msgLen;
6369
      int64_t ver;
6370
    };
6371
    void* pDataBlock;
6372
  };
6373
} SPackedData;
6374

6375
typedef struct {
6376
  char     fullname[TSDB_VIEW_FNAME_LEN];
6377
  char     name[TSDB_VIEW_NAME_LEN];
6378
  char     dbFName[TSDB_DB_FNAME_LEN];
6379
  char*    querySql;
6380
  char*    sql;
6381
  int8_t   orReplace;
6382
  int8_t   precision;
6383
  int32_t  numOfCols;
6384
  SSchema* pSchema;
6385
} SCMCreateViewReq;
6386

6387
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6388
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6389
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6390

6391
typedef struct {
6392
  char   fullname[TSDB_VIEW_FNAME_LEN];
6393
  char   name[TSDB_VIEW_NAME_LEN];
6394
  char   dbFName[TSDB_DB_FNAME_LEN];
6395
  char*  sql;
6396
  int8_t igNotExists;
6397
} SCMDropViewReq;
6398

6399
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6400
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6401
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6402

6403
typedef struct {
6404
  char fullname[TSDB_VIEW_FNAME_LEN];
6405
} SViewMetaReq;
6406
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6407
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6408

6409
typedef struct {
6410
  char     name[TSDB_VIEW_NAME_LEN];
6411
  char     dbFName[TSDB_DB_FNAME_LEN];
6412
  char*    createUser;
6413
  int64_t  ownerId;
6414
  uint64_t dbId;
6415
  uint64_t viewId;
6416
  char*    querySql;
6417
  int8_t   precision;
6418
  int8_t   type;
6419
  int32_t  version;
6420
  int32_t  numOfCols;
6421
  SSchema* pSchema;
6422
} SViewMetaRsp;
6423
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6424
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6425
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6426
typedef struct {
6427
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6428
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6429
} STableTSMAInfoReq;
6430

6431
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6432
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6433

6434
typedef struct {
6435
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6436
  union {
6437
    uint8_t flags;
6438
    struct {
6439
      uint8_t withColName : 1;
6440
      uint8_t reserved : 7;
6441
    };
6442
  };
6443

6444
} SRsmaInfoReq;
6445

6446
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6447
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6448

6449
typedef struct {
6450
  int32_t  funcId;
6451
  col_id_t colId;
6452
} STableTSMAFuncInfo;
6453

6454
typedef struct {
6455
  char     name[TSDB_TABLE_NAME_LEN];
6456
  uint64_t tsmaId;
6457
  char     targetTb[TSDB_TABLE_NAME_LEN];
6458
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6459
  char     tb[TSDB_TABLE_NAME_LEN];
6460
  char     dbFName[TSDB_DB_FNAME_LEN];
6461
  uint64_t suid;
6462
  uint64_t destTbUid;
6463
  uint64_t dbId;
6464
  int32_t  version;
6465
  int64_t  interval;
6466
  int8_t   unit;
6467
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6468
  SArray*  pTags;      // SArray<SSchema>
6469
  SArray*  pUsedCols;  // SArray<SSchema>
6470
  char*    ast;
6471

6472
  int64_t streamUid;
6473
  int64_t reqTs;
6474
  int64_t rspTs;
6475
  int64_t delayDuration;  // ms
6476
  bool    fillHistoryFinished;
6477

6478
  void* streamAddr;  // for stream task, the address of the stream task
6479
} STableTSMAInfo;
6480

6481
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6482
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6483
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6484
void    tFreeTableTSMAInfo(void* p);
6485
void    tFreeAndClearTableTSMAInfo(void* p);
6486
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6487

6488
#define STSMAHbRsp            STableTSMAInfoRsp
6489
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6490
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6491
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6492

6493
typedef struct SDropCtbWithTsmaSingleVgReq {
6494
  SVgroupInfo vgInfo;
6495
  SArray*     pTbs;  // SVDropTbReq
6496
} SMDropTbReqsOnSingleVg;
6497

6498
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6499
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6500
void    tFreeSMDropTbReqOnSingleVg(void* p);
6501

6502
typedef struct SDropTbsReq {
6503
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6504
} SMDropTbsReq;
6505

6506
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6507
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6508
void    tFreeSMDropTbsReq(void*);
6509

6510
typedef struct SVFetchTtlExpiredTbsRsp {
6511
  SArray* pExpiredTbs;  // SVDropTbReq
6512
  int32_t vgId;
6513
} SVFetchTtlExpiredTbsRsp;
6514

6515
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6516
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6517

6518
void tFreeFetchTtlExpiredTbsRsp(void* p);
6519

6520
void setDefaultOptionsForField(SFieldWithOptions* field);
6521
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6522

6523
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6524
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6525

6526
typedef struct {
6527
  char    id[TSDB_INSTANCE_ID_LEN];
6528
  char    type[TSDB_INSTANCE_TYPE_LEN];
6529
  char    desc[TSDB_INSTANCE_DESC_LEN];
6530
  int32_t expire;
6531
} SInstanceRegisterReq;
6532

6533
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6534
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6535

6536
typedef struct {
6537
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6538
} SInstanceListReq;
6539

6540
typedef struct {
6541
  int32_t count;
6542
  char**  ids;  // Array of instance IDs
6543
} SInstanceListRsp;
6544

6545
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6546
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6547
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6548
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6549

6550
#ifdef USE_MOUNT
6551
typedef struct {
6552
  char     mountName[TSDB_MOUNT_NAME_LEN];
6553
  int8_t   ignoreExist;
6554
  int16_t  nMounts;
6555
  int32_t* dnodeIds;
6556
  char**   mountPaths;
6557
  int32_t  sqlLen;
6558
  char*    sql;
6559
} SCreateMountReq;
6560

6561
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6562
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6563
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6564

6565
typedef struct {
6566
  char    mountName[TSDB_MOUNT_NAME_LEN];
6567
  int8_t  ignoreNotExists;
6568
  int32_t sqlLen;
6569
  char*   sql;
6570
} SDropMountReq;
6571

6572
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6573
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6574
void    tFreeSDropMountReq(SDropMountReq* pReq);
6575

6576
typedef struct {
6577
  char     mountName[TSDB_MOUNT_NAME_LEN];
6578
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6579
  int64_t  mountUid;
6580
  int32_t  dnodeId;
6581
  uint32_t valLen;
6582
  int8_t   ignoreExist;
6583
  void*    pVal;
6584
} SRetrieveMountPathReq;
6585

6586
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6587
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6588

6589
typedef struct {
6590
  // path
6591
  int32_t diskPrimary;
6592
  // vgInfo
6593
  int32_t  vgId;
6594
  int32_t  cacheLastSize;
6595
  int32_t  szPage;
6596
  int32_t  szCache;
6597
  uint64_t szBuf;
6598
  int8_t   cacheLast;
6599
  int8_t   standby;
6600
  int8_t   hashMethod;
6601
  uint32_t hashBegin;
6602
  uint32_t hashEnd;
6603
  int16_t  hashPrefix;
6604
  int16_t  hashSuffix;
6605
  int16_t  sttTrigger;
6606
  // syncInfo
6607
  int32_t replications;
6608
  // tsdbInfo
6609
  int8_t  precision;
6610
  int8_t  compression;
6611
  int8_t  slLevel;
6612
  int32_t daysPerFile;
6613
  int32_t keep0;
6614
  int32_t keep1;
6615
  int32_t keep2;
6616
  int32_t keepTimeOffset;
6617
  int32_t minRows;
6618
  int32_t maxRows;
6619
  int32_t tsdbPageSize;
6620
  int32_t ssChunkSize;
6621
  int32_t ssKeepLocal;
6622
  int8_t  ssCompact;
6623
  union {
6624
    uint8_t flags;
6625
    struct {
6626
      uint8_t isAudit : 1;
6627
      uint8_t allowDrop : 1;
6628
      uint8_t reserved : 6;
6629
    };
6630
  };
6631
  int8_t secureDelete;
6632
  // walInfo
6633
  int32_t walFsyncPeriod;      // millisecond
6634
  int32_t walRetentionPeriod;  // secs
6635
  int32_t walRollPeriod;       // secs
6636
  int64_t walRetentionSize;
6637
  int64_t walSegSize;
6638
  int32_t walLevel;
6639
  // encryptInfo
6640
  int32_t encryptAlgorithm;
6641
  // SVState
6642
  int64_t committed;
6643
  int64_t commitID;
6644
  int64_t commitTerm;
6645
  // stats
6646
  int64_t numOfSTables;
6647
  int64_t numOfCTables;
6648
  int64_t numOfNTables;
6649
  // dbInfo
6650
  uint64_t dbId;
6651
} SMountVgInfo;
6652

6653
typedef struct {
6654
  SMCreateStbReq req;
6655
  SArray*        pColExts;  // element: column id
6656
  SArray*        pTagExts;  // element: tag id
6657
} SMountStbInfo;
6658

6659
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6660
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6661

6662
typedef struct {
6663
  char     dbName[TSDB_DB_FNAME_LEN];
6664
  uint64_t dbId;
6665
  SArray*  pVgs;   // SMountVgInfo
6666
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6667
} SMountDbInfo;
6668

6669
typedef struct {
6670
  // common fields
6671
  char     mountName[TSDB_MOUNT_NAME_LEN];
6672
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6673
  int8_t   ignoreExist;
6674
  int64_t  mountUid;
6675
  int64_t  clusterId;
6676
  int32_t  dnodeId;
6677
  uint32_t valLen;
6678
  void*    pVal;
6679

6680
  // response fields
6681
  SArray* pDbs;  // SMountDbInfo
6682

6683
  // memory fields, no serialized
6684
  SArray*   pDisks[TFS_MAX_TIERS];
6685
  TdFilePtr pFile;
6686
} SMountInfo;
6687

6688
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6689
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6690
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6691

6692
typedef struct {
6693
  SCreateVnodeReq createReq;
6694
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6695
  char            mountName[TSDB_MOUNT_NAME_LEN];
6696
  int64_t         mountId;
6697
  int32_t         diskPrimary;
6698
  int32_t         mountVgId;
6699
  int64_t         committed;
6700
  int64_t         commitID;
6701
  int64_t         commitTerm;
6702
  int64_t         numOfSTables;
6703
  int64_t         numOfCTables;
6704
  int64_t         numOfNTables;
6705
} SMountVnodeReq;
6706

6707
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6708
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6709
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6710

6711
#endif  // USE_MOUNT
6712

6713
#pragma pack(pop)
6714

6715
typedef struct {
6716
  char        db[TSDB_DB_FNAME_LEN];
6717
  STimeWindow timeRange;
6718
  int32_t     sqlLen;
6719
  char*       sql;
6720
  SArray*     vgroupIds;
6721
} SScanDbReq;
6722

6723
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6724
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6725
void    tFreeSScanDbReq(SScanDbReq* pReq);
6726

6727
typedef struct {
6728
  int32_t scanId;
6729
  int8_t  bAccepted;
6730
} SScanDbRsp;
6731

6732
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6733
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6734

6735
typedef struct {
6736
  int32_t scanId;
6737
  int32_t sqlLen;
6738
  char*   sql;
6739
} SKillScanReq;
6740

6741
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6742
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6743
void    tFreeSKillScanReq(SKillScanReq* pReq);
6744

6745
typedef struct {
6746
  int32_t scanId;
6747
  int32_t vgId;
6748
  int32_t dnodeId;
6749
} SVKillScanReq;
6750

6751
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6752
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6753

6754
typedef struct {
6755
  int32_t scanId;
6756
  int32_t vgId;
6757
  int32_t dnodeId;
6758
  int32_t numberFileset;
6759
  int32_t finished;
6760
  int32_t progress;
6761
  int64_t remainingTime;
6762
} SQueryScanProgressRsp;
6763

6764
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6765
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6766

6767
typedef struct {
6768
  int32_t scanId;
6769
  int32_t vgId;
6770
  int32_t dnodeId;
6771
} SQueryScanProgressReq;
6772

6773
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6774
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6775

6776
typedef struct {
6777
  int64_t     dbUid;
6778
  char        db[TSDB_DB_FNAME_LEN];
6779
  int64_t     scanStartTime;
6780
  STimeWindow tw;
6781
  int32_t     scanId;
6782
} SScanVnodeReq;
6783

6784
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6785
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6786

6787
#ifdef __cplusplus
6788
}
6789
#endif
6790

6791
#endif /*_TD_COMMON_TAOS_MSG_H_*/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc