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

taosdata / TDengine / #5005

26 Mar 2026 12:51PM UTC coverage: 72.152% (-0.2%) from 72.338%
#5005

push

travis-ci

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

512 of 851 new or added lines in 47 files covered. (60.16%)

6189 existing lines in 147 files now uncovered.

253282 of 351039 relevant lines covered (72.15%)

132156710.33 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

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

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

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

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

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

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

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

67
typedef uint16_t tmsg_t;
68

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

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

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

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

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

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
937,691,027✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
887,727,854✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,825,418,881✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

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

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

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

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

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

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

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

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

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

264

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

270

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

276
#define TSDB_ALTER_RSMA_FUNCTION        0x1
277

278
#define TSDB_KILL_MSG_LEN 30
279

280
#define TSDB_TABLE_NUM_UNIT 100000
281

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

733
typedef struct {
734
  int32_t contLen;
735
  int32_t vgId;
736
} SMsgHead;
737

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

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

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

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

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

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

795
typedef struct {
796
  int32_t  nCols;
797
  int32_t  version;
798
  SColRef* pColRef;
799
  int32_t  nTagRefs;
800
  SColRef* pTagRef;
801
} SColRefWrapper;
802

803
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
804
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
805
typedef struct {
806
  int32_t vgId;
807
  SColRef colRef;
808
} SColRefEx;
809

810
typedef struct {
811
  int16_t colId;
812
  char    refDbName[TSDB_DB_NAME_LEN];
813
  char    refTableName[TSDB_TABLE_NAME_LEN];
814
  char    refColName[TSDB_COL_NAME_LEN];
815
} SRefColInfo;
816

817
typedef struct SVCTableRefCols {
818
  uint64_t     uid;
819
  int32_t      numOfSrcTbls;
820
  int32_t      numOfColRefs;
821
  SRefColInfo* refCols;
822
} SVCTableRefCols;
823

824
typedef struct SVCTableMergeInfo {
825
  uint64_t uid;
826
  int32_t  numOfSrcTbls;
827
} SVCTableMergeInfo;
828

829
typedef struct {
830
  int32_t    nCols;
831
  SColRefEx* pColRefEx;
832
} SColRefExWrapper;
833

834
struct SSchema {
835
  int8_t   type;
836
  int8_t   flags;
837
  col_id_t colId;
838
  int32_t  bytes;
839
  char     name[TSDB_COL_NAME_LEN];
840
};
841
struct SSchemaExt {
842
  col_id_t colId;
843
  uint32_t compress;
844
  STypeMod typeMod;
845
};
846

847
struct SSchemaRsma {
848
  int64_t    interval[2];
849
  int32_t    nFuncs;
850
  int8_t     tbType;
851
  tb_uid_t   tbUid;
852
  func_id_t* funcIds;
853
  char       tbName[TSDB_TABLE_NAME_LEN];
854
};
855

856
struct SSchema2 {
857
  int8_t   type;
858
  int8_t   flags;
859
  col_id_t colId;
860
  int32_t  bytes;
861
  char     name[TSDB_COL_NAME_LEN];
862
  uint32_t compress;
863
};
864

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

900
typedef struct {
901
  int32_t        code;
902
  int64_t        uid;
903
  char*          tblFName;
904
  int32_t        numOfRows;
905
  int32_t        affectedRows;
906
  int64_t        sver;
907
  STableMetaRsp* pMeta;
908
} SSubmitBlkRsp;
909

910
typedef struct {
911
  int32_t numOfRows;
912
  int32_t affectedRows;
913
  int32_t nBlocks;
914
  union {
915
    SArray*        pArray;
916
    SSubmitBlkRsp* pBlocks;
917
  };
918
} SSubmitRsp;
919

920
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
921
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
922
// void    tFreeSSubmitBlkRsp(void* param);
923
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
924

925
#define COL_SMA_ON       ((int8_t)0x1)
926
#define COL_IDX_ON       ((int8_t)0x2)
927
#define COL_IS_KEY       ((int8_t)0x4)
928
#define COL_SET_NULL     ((int8_t)0x10)
929
#define COL_SET_VAL      ((int8_t)0x20)
930
#define COL_IS_SYSINFO   ((int8_t)0x40)
931
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
932
#define COL_REF_BY_STM   ((int8_t)0x08)
933

934
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
935
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
936

937
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
938
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
939
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
940

941
#define SSCHMEA_SET_IDX_ON(s) \
942
  do {                        \
943
    (s)->flags |= COL_IDX_ON; \
944
  } while (0)
945

946
#define SSCHMEA_SET_IDX_OFF(s)   \
947
  do {                           \
948
    (s)->flags &= (~COL_IDX_ON); \
949
  } while (0)
950

951
#define SSCHEMA_SET_TYPE_MOD(s)     \
952
  do {                              \
953
    (s)->flags |= COL_HAS_TYPE_MOD; \
954
  } while (0)
955

956
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
957

958
#define SSCHMEA_TYPE(s)  ((s)->type)
959
#define SSCHMEA_FLAGS(s) ((s)->flags)
960
#define SSCHMEA_COLID(s) ((s)->colId)
961
#define SSCHMEA_BYTES(s) ((s)->bytes)
962
#define SSCHMEA_NAME(s)  ((s)->name)
963

964
typedef struct {
965
  bool    tsEnableMonitor;
966
  int32_t tsMonitorInterval;
967
  int32_t tsSlowLogThreshold;
968
  int32_t tsSlowLogMaxLen;
969
  int32_t tsSlowLogScope;
970
  int32_t tsSlowLogThresholdTest;  // Obsolete
971
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
972
} SMonitorParas;
973

974
typedef struct {
975
  STypeMod typeMod;
976
} SExtSchema;
977

978
bool hasExtSchema(const SExtSchema* pExtSchema);
979

980
typedef struct {
981
  int32_t      nCols;
982
  int32_t      version;
983
  SSchema*     pSchema;
984
  SSchemaRsma* pRsma;
985
} SSchemaWrapper;
986

987
typedef struct {
988
  col_id_t id;
989
  uint32_t alg;
990
} SColCmpr;
991

992
typedef struct {
993
  int32_t   nCols;
994
  int32_t   version;
995
  SColCmpr* pColCmpr;
996
} SColCmprWrapper;
997

998
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
999
  if (pRef->pColRef) {
527,716✔
1000
    return TSDB_CODE_INVALID_PARA;
×
1001
  }
1002
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
527,716✔
1003
  if (pRef->pColRef == NULL) {
527,716✔
1004
    return terrno;
×
1005
  }
1006
  pRef->nCols = nCols;
527,716✔
1007
  for (int32_t i = 0; i < nCols; i++) {
152,424,807✔
1008
    pRef->pColRef[i].hasRef = false;
151,897,091✔
1009
    pRef->pColRef[i].id = (col_id_t)(i + 1);
151,897,091✔
1010
  }
1011
  return 0;
527,716✔
1012
}
1013

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

1030
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
1031
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1032
    terrno = TSDB_CODE_INVALID_PARA;
1033
    return NULL;
1034
  }
1035

1036
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1037
  if (pDstWrapper == NULL) {
1038
    return NULL;
1039
  }
1040
  pDstWrapper->nCols = pSrcWrapper->nCols;
1041
  pDstWrapper->version = pSrcWrapper->version;
1042

1043
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1044
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1045
  if (pDstWrapper->pColCmpr == NULL) {
1046
    taosMemoryFree(pDstWrapper);
1047
    return NULL;
1048
  }
1049
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1050

1051
  return pDstWrapper;
1052
}
1053

1054
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1055
  if (!(!pCmpr->pColCmpr)) {
7,132,842✔
1056
    return TSDB_CODE_INVALID_PARA;
×
1057
  }
1058
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
7,132,842✔
1059
  if (pCmpr->pColCmpr == NULL) {
7,132,842✔
1060
    return terrno;
×
1061
  }
1062
  pCmpr->nCols = nCols;
7,132,842✔
1063
  return 0;
7,132,842✔
1064
}
1065

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

1084
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1085
  if (pWrapper == NULL) return;
1086

1087
  taosMemoryFreeClear(pWrapper->pColCmpr);
1088
  taosMemoryFreeClear(pWrapper);
1089
}
1090
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1091
  if (pSchemaWrapper->pSchema == NULL) return NULL;
650,709,151✔
1092

1093
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
650,468,809✔
1094
  if (pSW == NULL) {
650,502,833✔
1095
    return NULL;
×
1096
  }
1097
  pSW->nCols = pSchemaWrapper->nCols;
650,502,833✔
1098
  pSW->version = pSchemaWrapper->version;
650,580,868✔
1099
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
650,696,170✔
1100
  if (pSW->pSchema == NULL) {
650,266,303✔
1101
    taosMemoryFree(pSW);
×
1102
    return NULL;
×
1103
  }
1104

1105
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
650,349,463✔
1106
  return pSW;
650,737,428✔
1107
}
1108

1109
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
151,361,861✔
1110
  if (pSchemaWrapper) {
1,456,797,979✔
1111
    taosMemoryFree(pSchemaWrapper->pSchema);
1,014,235,638✔
1112
    if (pSchemaWrapper->pRsma) {
1,014,055,579✔
1113
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
27,935✔
1114
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
27,935✔
1115
    }
1116
    taosMemoryFree(pSchemaWrapper);
1,014,051,231✔
1117
  }
1118
}
1,417,424,839✔
1119

1120
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1121
  if (pSchemaWrapper) {
1122
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1123
    if (pSchemaWrapper->pRsma) {
1124
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1125
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1126
    }
1127
  }
1128
}
1129

1130
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
7,899,522✔
1131
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,899,522✔
1132
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,900,636✔
1133
  }
1134
}
7,898,908✔
1135

1136
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1137
  int32_t tlen = 0;
2,657,400✔
1138
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,659,692✔
1139
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,657,400✔
1140
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,657,400✔
1141
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,657,400✔
1142
  tlen += taosEncodeString(buf, pSchema->name);
2,657,400✔
1143
  return tlen;
2,657,400✔
1144
}
1145

1146
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1147
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,222,216✔
1148
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,221,724✔
1149
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,221,724✔
1150
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,221,724✔
1151
  buf = taosDecodeStringTo(buf, pSchema->name);
1,221,724✔
1152
  return (void*)buf;
1,221,724✔
1153
}
1154

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

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

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

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

1187
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1188
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
925,642,500✔
1189
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
925,642,500✔
1190
  if (pColRef->hasRef) {
462,821,250✔
1191
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
614,173,168✔
1192
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
614,173,168✔
1193
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
614,173,168✔
1194
  }
1195
  return 0;
462,821,250✔
1196
}
1197

1198
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1199
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
464,034,236✔
1200
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
464,034,236✔
1201
  if (pColRef->hasRef) {
232,017,118✔
1202
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
153,988,762✔
1203
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
153,988,762✔
1204
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
153,988,762✔
1205
  }
1206

1207
  return 0;
232,017,118✔
1208
}
1209

1210
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1211
  int32_t tlen = 0;
440,278✔
1212
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
440,278✔
1213
  tlen += taosEncodeVariantI32(buf, pSW->version);
440,278✔
1214
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,097,678✔
1215
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,314,800✔
1216
  }
1217
  return tlen;
440,278✔
1218
}
1219

1220
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1221
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
195,912✔
1222
  buf = taosDecodeVariantI32(buf, &pSW->version);
195,912✔
1223
  if (pSW->nCols > 0) {
195,912✔
1224
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
195,912✔
1225
    if (pSW->pSchema == NULL) {
195,912✔
1226
      return NULL;
×
1227
    }
1228

1229
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,417,636✔
1230
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,443,448✔
1231
    }
1232
  } else {
1233
    pSW->pSchema = NULL;
×
1234
  }
1235
  return (void*)buf;
195,912✔
1236
}
1237

1238
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1239
  if (pSW == NULL) {
288,875,610✔
1240
    return TSDB_CODE_INVALID_PARA;
×
1241
  }
1242
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
577,735,502✔
1243
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
577,700,161✔
1244
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1245
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1246
  }
1247
  return 0;
289,033,802✔
1248
}
1249

1250
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1251
  if (pSW == NULL) {
124,686,759✔
1252
    return TSDB_CODE_INVALID_PARA;
×
1253
  }
1254
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
249,345,718✔
1255
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
249,343,574✔
1256

1257
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
124,684,615✔
1258
  if (pSW->pSchema == NULL) {
124,630,269✔
1259
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1260
  }
1261
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,343,151,549✔
1262
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1263
  }
1264

1265
  return 0;
124,710,423✔
1266
}
1267

1268
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1269
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1270
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1271

1272
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1273
  if (pSW->pSchema == NULL) {
2,110,457,572✔
1274
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1275
  }
1276
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1277
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1278
  }
1279

1280
  return 0;
2,111,332,479✔
1281
}
1282

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

1317
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1318
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1319
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1320

1321
typedef struct {
1322
  STableMetaRsp* pMeta;
1323
} SMCreateStbRsp;
1324

1325
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1326
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1327
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1328

1329
typedef struct {
1330
  char     name[TSDB_TABLE_FNAME_LEN];
1331
  int8_t   igNotExists;
1332
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1333
  int8_t   reserved[6];
1334
  tb_uid_t suid;
1335
  int32_t  sqlLen;
1336
  char*    sql;
1337
} SMDropStbReq;
1338

1339
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1340
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1341
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1342

1343
typedef struct {
1344
  char    name[TSDB_TABLE_FNAME_LEN];
1345
  int8_t  alterType;
1346
  int32_t numOfFields;
1347
  SArray* pFields;
1348
  int32_t ttl;
1349
  int32_t commentLen;
1350
  char*   comment;
1351
  int32_t sqlLen;
1352
  char*   sql;
1353
  int64_t keep;
1354
  SArray* pTypeMods;
1355
  int8_t  secureDelete;
1356
} SMAlterStbReq;
1357

1358
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1359
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1360
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1361

1362
typedef struct SEpSet {
1363
  int8_t inUse;
1364
  int8_t numOfEps;
1365
  SEp    eps[TSDB_MAX_REPLICA];
1366
} SEpSet;
1367

1368
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1369
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1370
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1371
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1372

1373
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1374
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1375

1376
typedef struct {
1377
  int8_t  connType;
1378
  int32_t pid;
1379
  int32_t totpCode;
1380
  char    app[TSDB_APP_NAME_LEN];
1381
  char    db[TSDB_DB_NAME_LEN];
1382
  char    user[TSDB_USER_LEN];
1383
  char    passwd[TSDB_PASSWORD_LEN];
1384
  char    token[TSDB_TOKEN_LEN];
1385
  int64_t startTime;
1386
  int64_t connectTime;
1387
  char    sVer[TSDB_VERSION_LEN];
1388
  char    signature[20]; // SHA1 produces a 20-byte signature
1389
} SConnectReq;
1390

1391
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1392
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1393
void    tSignConnectReq(SConnectReq* pReq);
1394
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1395

1396
typedef struct {
1397
  int64_t       clusterId;
1398
  int32_t       acctId;
1399
  uint32_t      connId;
1400
  int32_t       dnodeNum;
1401
  int8_t        superUser;
1402
  int8_t        sysInfo;
1403
  int8_t        connType;
1404
  int8_t        enableAuditDelete;
1405
  SEpSet        epSet;
1406
  int32_t       svrTimestamp;
1407
  int32_t       passVer;
1408
  int32_t       authVer;
1409
  char          sVer[TSDB_VERSION_LEN];
1410
  char          sDetailVer[128];
1411
  int64_t       whiteListVer;
1412
  int64_t       timeWhiteListVer;
1413
  int64_t       userId;
1414
  SMonitorParas monitorParas;
1415
  char          user[TSDB_USER_LEN];
1416
  char          tokenName[TSDB_TOKEN_NAME_LEN];
1417
  int8_t        enableAuditSelect;
1418
  int8_t        enableAuditInsert;
1419
  int8_t        auditLevel;
1420
} SConnectRsp;
1421

1422
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1423
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1424

1425
typedef struct {
1426
  char    user[TSDB_USER_LEN];
1427
  char    pass[TSDB_PASSWORD_LEN];
1428
  int32_t maxUsers;
1429
  int32_t maxDbs;
1430
  int32_t maxTimeSeries;
1431
  int32_t maxStreams;
1432
  int32_t accessState;  // Configured only by command
1433
  int64_t maxStorage;
1434
} SCreateAcctReq, SAlterAcctReq;
1435

1436
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1437
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1438

1439
typedef struct {
1440
  char    user[TSDB_USER_LEN];
1441
  int8_t  ignoreNotExists;
1442
  int32_t sqlLen;
1443
  char*   sql;
1444
} SDropUserReq, SDropAcctReq;
1445

1446
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1447
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1448
void    tFreeSDropUserReq(SDropUserReq* pReq);
1449

1450
typedef struct {
1451
  char name[TSDB_ROLE_LEN];
1452
  union {
1453
    uint8_t flag;
1454
    struct {
1455
      uint8_t ignoreExists : 1;
1456
      uint8_t reserve : 7;
1457
    };
1458
  };
1459
  int32_t sqlLen;
1460
  char*   sql;
1461
} SCreateRoleReq;
1462

1463
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1464
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1465
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1466

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

1480
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1481
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1482
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1483

1484
typedef struct {
1485
  SPrivSet privSet;
1486
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1487
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1488
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1489
  // delete can only specify conditions by cond and cannot specify columns
1490
  char*    cond;     // for table privileges
1491
  int32_t  condLen;  // for table privileges
1492
} SPrivSetReqArgs;
1493

1494
typedef struct {
1495
  uint8_t alterType;  // TSDB_ALTER_ROLE_LOCK, TSDB_ALTER_ROLE_ROLE, TSDB_ALTER_ROLE_PRIVILEGES
1496
  uint8_t objType;    // none, db, table, view, rsma, topic, etc.
1497
  union {
1498
    uint32_t flag;
1499
    struct {
1500
      uint32_t lock : 1;     // lock or unlock role
1501
      uint32_t add : 1;      // add or remove
1502
      uint32_t sysPriv : 1;  // system or object privileges
1503
      uint32_t objLevel : 2;
1504
      uint32_t ignoreNotExists : 1;
1505
      uint32_t reserve : 26;
1506
    };
1507
  };
1508
  union {
1509
    SPrivSetReqArgs privileges;
1510
    char            roleName[TSDB_ROLE_LEN];
1511
  };
1512
  char    principal[TSDB_ROLE_LEN];      // role or user name
1513
  char    objFName[TSDB_OBJ_FNAME_LEN];  // db
1514
  char    tblName[TSDB_TABLE_NAME_LEN];  // none, table, view, rsma, topic, etc.
1515
  int32_t sqlLen;
1516
  char*   sql;
1517
} SAlterRoleReq;
1518

1519
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1520
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1521
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1522

1523
typedef struct {
1524
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1525
  int32_t sqlLen;
1526
  char*   sql;
1527
} SDropEncryptAlgrReq;
1528

1529
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1530
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1531
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1532

1533
typedef struct SIpV4Range {
1534
  uint32_t ip;
1535
  uint32_t mask;
1536
} SIpV4Range;
1537

1538
typedef struct SIpv6Range {
1539
  uint64_t addr[2];
1540
  uint32_t mask;
1541
} SIpV6Range;
1542

1543
typedef struct {
1544
  int8_t type;   // 0: IPv4, 1: IPv6
1545
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1546
  union {
1547
    SIpV4Range ipV4;
1548
    SIpV6Range ipV6;
1549
  };
1550
} SIpRange;
1551

1552
typedef struct {
1553
  int32_t    num;
1554
  SIpV4Range pIpRange[];
1555
} SIpWhiteList;
1556

1557
typedef struct {
1558
  int32_t  num;
1559
  SIpRange pIpRanges[];
1560
} SIpWhiteListDual;
1561

1562
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1563
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1564
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1565
int32_t           createDefaultIp6Range(SIpRange* pRange);
1566
int32_t           createDefaultIp4Range(SIpRange* pRange);
1567

1568
typedef struct {
1569
  int32_t sessPerUser;
1570
  int32_t sessConnTime;
1571
  int32_t sessConnIdleTime;
1572
  int32_t sessMaxConcurrency;
1573
  int32_t sessMaxCallVnodeNum;
1574
} SUserSessCfg;
1575

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

1580
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1581
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1582
typedef struct {
1583
  int16_t year;
1584
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1585
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1586
  int8_t hour;
1587
  int8_t minute;
1588
  int8_t neg;   // this is a negative entry
1589
  int32_t duration; // duration in minute
1590
} SDateTimeRange;
1591

1592
bool isValidDateTimeRange(SDateTimeRange* pRange);
1593
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1594
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1595

1596
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1597
typedef struct {
1598
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1599
  bool neg;         // this is a negative entry
1600
  int32_t duration; // duration in seconds
1601
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1602
} SDateTimeWhiteListItem;
1603

1604
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1605
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1606

1607
typedef struct {
1608
  int32_t num;
1609
  SDateTimeWhiteListItem ranges[];
1610
} SDateTimeWhiteList;
1611

1612
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1613
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1614

1615

1616
typedef struct {
1617
  int8_t createType;
1618

1619
  int8_t hasSessionPerUser;
1620
  int8_t hasConnectTime;
1621
  int8_t hasConnectIdleTime;
1622
  int8_t hasCallPerSession;
1623
  int8_t hasVnodePerCall;
1624
  int8_t hasFailedLoginAttempts;
1625
  int8_t hasPasswordLifeTime;
1626
  int8_t hasPasswordReuseTime;
1627
  int8_t hasPasswordReuseMax;
1628
  int8_t hasPasswordLockTime;
1629
  int8_t hasPasswordGraceTime;
1630
  int8_t hasInactiveAccountTime;
1631
  int8_t hasAllowTokenNum;
1632

1633
  int8_t superUser;  // denote if it is a super user or not
1634
  int8_t ignoreExists;
1635

1636
  char   user[TSDB_USER_LEN];
1637
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1638
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1639

1640
  int8_t sysInfo;
1641
  int8_t createDb;
1642
  int8_t isImport;
1643
  int8_t changepass;
1644
  int8_t enable;
1645

1646
  int8_t negIpRanges;
1647
  int8_t negTimeRanges;
1648

1649
  int32_t sessionPerUser;
1650
  int32_t connectTime;
1651
  int32_t connectIdleTime;
1652
  int32_t callPerSession;
1653
  int32_t vnodePerCall;
1654
  int32_t failedLoginAttempts;
1655
  int32_t passwordLifeTime;
1656
  int32_t passwordReuseTime;
1657
  int32_t passwordReuseMax;
1658
  int32_t passwordLockTime;
1659
  int32_t passwordGraceTime;
1660
  int32_t inactiveAccountTime;
1661
  int32_t allowTokenNum;
1662

1663
  int32_t         numIpRanges;
1664
  SIpRange*       pIpDualRanges;
1665
  int32_t         numTimeRanges;
1666
  SDateTimeRange* pTimeRanges;
1667

1668
  int32_t sqlLen;
1669
  char*   sql;
1670
} SCreateUserReq;
1671

1672
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1673
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1674
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1675

1676
typedef struct {
1677
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1678
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1679
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1680
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1681
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1682
  int32_t sqlLen;
1683
  char*   sql;
1684
} SCreateEncryptAlgrReq;
1685

1686
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1687
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1688
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1689

1690
typedef struct {
1691
  int32_t dnodeId;
1692
  int64_t analVer;
1693
} SRetrieveAnalyticsAlgoReq;
1694

1695
typedef struct {
1696
  int64_t   ver;
1697
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1698
} SRetrieveAnalyticAlgoRsp;
1699

1700
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1701
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1702
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1703
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1704
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1705

1706
typedef struct {
1707
  int8_t alterType;
1708

1709
  int8_t isView;
1710

1711
  int8_t hasPassword;
1712
  int8_t hasTotpseed;
1713
  int8_t hasEnable;
1714
  int8_t hasSysinfo;
1715
  int8_t hasCreatedb;
1716
  int8_t hasChangepass;
1717
  int8_t hasSessionPerUser;
1718
  int8_t hasConnectTime;
1719
  int8_t hasConnectIdleTime;
1720
  int8_t hasCallPerSession;
1721
  int8_t hasVnodePerCall;
1722
  int8_t hasFailedLoginAttempts;
1723
  int8_t hasPasswordLifeTime;
1724
  int8_t hasPasswordReuseTime;
1725
  int8_t hasPasswordReuseMax;
1726
  int8_t hasPasswordLockTime;
1727
  int8_t hasPasswordGraceTime;
1728
  int8_t hasInactiveAccountTime;
1729
  int8_t hasAllowTokenNum;
1730

1731
  int8_t enable;
1732
  int8_t sysinfo;
1733
  int8_t createdb;
1734
  int8_t changepass;
1735

1736
  char   user[TSDB_USER_LEN];
1737
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1738
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1739
  int32_t sessionPerUser;
1740
  int32_t connectTime;
1741
  int32_t connectIdleTime;
1742
  int32_t callPerSession;
1743
  int32_t vnodePerCall;
1744
  int32_t failedLoginAttempts;
1745
  int32_t passwordLifeTime;
1746
  int32_t passwordReuseTime;
1747
  int32_t passwordReuseMax;
1748
  int32_t passwordLockTime;
1749
  int32_t passwordGraceTime;
1750
  int32_t inactiveAccountTime;
1751
  int32_t allowTokenNum;
1752

1753
  int32_t         numIpRanges;
1754
  int32_t         numTimeRanges;
1755
  int32_t         numDropIpRanges;
1756
  int32_t         numDropTimeRanges;
1757
  SIpRange*       pIpRanges;
1758
  SDateTimeRange* pTimeRanges;
1759
  SIpRange*       pDropIpRanges;
1760
  SDateTimeRange* pDropTimeRanges;
1761
  SPrivSet        privileges;
1762

1763
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1764
  char        tabName[TSDB_TABLE_NAME_LEN];
1765
  char*       tagCond;
1766
  int32_t     tagCondLen;
1767
  int32_t     sqlLen;
1768
  char*       sql;
1769
} SAlterUserReq;
1770

1771
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1772
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1773
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1774

1775
typedef struct {
1776
  char    name[TSDB_TOKEN_NAME_LEN];
1777
  char    user[TSDB_USER_LEN];
1778
  int8_t  enable;
1779
  int8_t  ignoreExists;
1780
  int32_t ttl;
1781
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1782
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1783

1784
  int32_t sqlLen;
1785
  char*   sql;
1786
} SCreateTokenReq;
1787

1788
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1789
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1790
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1791

1792
typedef struct {
1793
  char name[TSDB_TOKEN_NAME_LEN];
1794
  char user[TSDB_USER_LEN];
1795
  char token[TSDB_TOKEN_LEN];
1796
} SCreateTokenRsp;
1797

1798
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1799
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1800
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1801

1802
typedef struct {
1803
  char    name[TSDB_TOKEN_NAME_LEN];
1804

1805
  int8_t hasEnable;
1806
  int8_t hasTtl;
1807
  int8_t hasProvider;
1808
  int8_t hasExtraInfo;
1809

1810
  int8_t  enable;
1811
  int32_t ttl;
1812
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1813
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1814

1815
  int32_t     sqlLen;
1816
  char*       sql;
1817
} SAlterTokenReq;
1818

1819
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1820
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1821
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1822

1823
typedef struct {
1824
  char    name[TSDB_TOKEN_NAME_LEN];
1825
  int8_t  ignoreNotExists;
1826
  int32_t sqlLen;
1827
  char*   sql;
1828
} SDropTokenReq;
1829

1830
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1831
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1832
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1833

1834
typedef struct {
1835
  char    user[TSDB_USER_LEN];
1836
  int32_t sqlLen;
1837
  char*   sql;
1838
} SCreateTotpSecretReq;
1839

1840
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1841
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1842
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1843

1844
typedef struct {
1845
  char user[TSDB_USER_LEN];
1846
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1847
} SCreateTotpSecretRsp;
1848

1849
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1850
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1851

1852
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1853
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1854
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1855
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1856

1857
typedef struct {
1858
  char user[TSDB_USER_LEN];
1859
} SGetUserAuthReq;
1860

1861
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1862
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1863

1864
typedef struct {
1865
  int8_t  enabled;
1866
  int32_t expireTime;
1867
} STokenStatus;
1868

1869
typedef struct {
1870
  char    user[TSDB_USER_LEN];
1871
  int64_t userId;
1872
  int32_t version;
1873
  int32_t passVer;
1874
  int8_t  superAuth;
1875
  int8_t  sysInfo;
1876
  int8_t  enable;
1877
  int8_t  dropped;
1878
  union {
1879
    uint8_t flags;
1880
    struct {
1881
      uint8_t privLevel : 3;
1882
      uint8_t withInsertCond : 1;
1883
      uint8_t reserve : 4;
1884
    };
1885
  };
1886
  SPrivSet  sysPrivs;
1887
  SHashObj* objPrivs;
1888
  SHashObj* selectTbs;
1889
  SHashObj* insertTbs;
1890
  SHashObj* deleteTbs;
1891
  SHashObj* ownedDbs;
1892
  int64_t   whiteListVer;
1893

1894
  SUserSessCfg sessCfg;
1895
  int64_t      timeWhiteListVer;
1896
  SHashObj*    tokens;
1897
} SGetUserAuthRsp;
1898

1899
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1900
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1901
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1902

1903
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1904
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1905
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1906
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1907

1908
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1909
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1910
typedef struct {
1911
  int64_t ver;
1912
  char    user[TSDB_USER_LEN];
1913
  int32_t numOfRange;
1914
  union {
1915
    SIpV4Range* pIpRanges;
1916
    SIpRange*   pIpDualRanges;
1917
  };
1918
} SUpdateUserIpWhite;
1919

1920
typedef struct {
1921
  int64_t             ver;
1922
  int                 numOfUser;
1923
  SUpdateUserIpWhite* pUserIpWhite;
1924
} SUpdateIpWhite;
1925

1926
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1927
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1928
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1929
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1930

1931
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1932
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1933
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1934

1935

1936
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1937
// corresponding response struct is different.
1938
typedef struct {
1939
  int64_t ver;
1940
} SRetrieveWhiteListReq;
1941

1942
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1943
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1944

1945

1946
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1947
// corresponding response struct is different.
1948
typedef struct {
1949
  char user[TSDB_USER_LEN];
1950
} SGetUserWhiteListReq;
1951

1952
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1953
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1954

1955
typedef struct {
1956
  char    user[TSDB_USER_LEN];
1957
  int32_t numWhiteLists;
1958
  union {
1959
    SIpV4Range* pWhiteLists;
1960
    SIpRange*   pWhiteListsDual;
1961
  };
1962
} SGetUserIpWhiteListRsp;
1963

1964
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1965
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1966
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1967
void    tIpRangeSetDefaultMask(SIpRange* range);
1968

1969
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1970
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1971
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1972

1973
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1974
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1975
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1976

1977
typedef struct {
1978
  int64_t ver;
1979
  char    user[TSDB_USER_LEN];
1980
  int32_t numWhiteLists;
1981
  SDateTimeWhiteListItem* pWhiteLists;
1982
} SUserDateTimeWhiteList;
1983

1984

1985
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1986
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1987
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1988
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1989

1990
typedef struct {
1991
  int64_t             ver;
1992
  int                 numOfUser;
1993
  SUserDateTimeWhiteList *pUsers;
1994
} SRetrieveDateTimeWhiteListRsp;
1995

1996
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1997
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1998
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1999
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
2000

2001
/*
2002
 * for client side struct, only column id, type, bytes are necessary
2003
 * But for data in vnode side, we need all the following information.
2004
 */
2005
typedef struct {
2006
  union {
2007
    col_id_t colId;
2008
    int16_t  slotId;
2009
  };
2010

2011
  uint8_t precision;
2012
  uint8_t scale;
2013
  int32_t bytes;
2014
  int8_t  type;
2015
  uint8_t pk;
2016
  bool    noData;
2017
} SColumnInfo;
2018

2019
typedef struct STimeWindow {
2020
  TSKEY skey;
2021
  TSKEY ekey;
2022
} STimeWindow;
2023

2024
typedef struct SQueryHint {
2025
  bool batchScan;
2026
} SQueryHint;
2027

2028
typedef struct {
2029
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
2030
  int32_t tsLen;          // total length of ts comp block
2031
  int32_t tsNumOfBlocks;  // ts comp block numbers
2032
  int32_t tsOrder;        // ts comp block order
2033
} STsBufInfo;
2034

2035
typedef struct {
2036
  void*       timezone;
2037
  char        intervalUnit;
2038
  char        slidingUnit;
2039
  char        offsetUnit;
2040
  int8_t      precision;
2041
  int64_t     interval;
2042
  int64_t     sliding;
2043
  int64_t     offset;
2044
  STimeWindow timeRange;
2045
} SInterval;
2046

2047
typedef struct STbVerInfo {
2048
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2049
  int32_t sversion;
2050
  int32_t tversion;
2051
  int32_t rversion;  // virtual table's column ref's version
2052
} STbVerInfo;
2053

2054
typedef struct {
2055
  int32_t code;
2056
  int64_t affectedRows;
2057
  SArray* tbVerInfo;  // STbVerInfo
2058
} SQueryTableRsp;
2059

2060
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2061

2062
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2063

2064
typedef struct {
2065
  SMsgHead header;
2066
  char     dbFName[TSDB_DB_FNAME_LEN];
2067
  char     tbName[TSDB_TABLE_NAME_LEN];
2068
} STableCfgReq;
2069

2070
typedef struct {
2071
  char        tbName[TSDB_TABLE_NAME_LEN];
2072
  char        stbName[TSDB_TABLE_NAME_LEN];
2073
  char        dbFName[TSDB_DB_FNAME_LEN];
2074
  int32_t     numOfTags;
2075
  int32_t     numOfColumns;
2076
  int8_t      tableType;
2077
  int64_t     delay1;
2078
  int64_t     delay2;
2079
  int64_t     watermark1;
2080
  int64_t     watermark2;
2081
  int32_t     ttl;
2082
  int32_t     keep;
2083
  int64_t     ownerId;
2084
  SArray*     pFuncs;
2085
  int32_t     commentLen;
2086
  char*       pComment;
2087
  SSchema*    pSchemas;
2088
  int32_t     tagsLen;
2089
  char*       pTags;
2090
  SSchemaExt* pSchemaExt;
2091
  union {
2092
    uint8_t flag;
2093
    struct {
2094
      uint8_t virtualStb : 1;  // no compatibility problem for little-endian arch
2095
      uint8_t isAudit : 1;
2096
      uint8_t reserve : 6;
2097
    };
2098
  };
2099
  SColRef* pColRefs;
2100
  int32_t  numOfTagRefs;
2101
  SColRef* pTagRefs;
2102
  int8_t   secureDelete;
2103
} STableCfg;
2104

2105
typedef STableCfg STableCfgRsp;
2106

2107
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2108
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2109

2110
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2111
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2112
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2113

2114
typedef struct {
2115
  SMsgHead header;
2116
  tb_uid_t suid;
2117
} SVSubTablesReq;
2118

2119
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2120
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2121

2122
typedef struct {
2123
  int32_t vgId;
2124
  SArray* pTables;  // SArray<SVCTableRefCols*>
2125
} SVSubTablesRsp;
2126

2127
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2128
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2129
void    tDestroySVSubTablesRsp(void* rsp);
2130

2131
typedef struct {
2132
  SMsgHead header;
2133
  tb_uid_t suid;
2134
} SVStbRefDbsReq;
2135

2136
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2137
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2138

2139
typedef struct {
2140
  int32_t vgId;
2141
  SArray* pDbs;  // SArray<char* (db name)>
2142
} SVStbRefDbsRsp;
2143

2144
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2145
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2146
void    tDestroySVStbRefDbsRsp(void* rsp);
2147

2148
typedef struct {
2149
  char    db[TSDB_DB_FNAME_LEN];
2150
  int32_t numOfVgroups;
2151
  int32_t numOfStables;  // single_stable
2152
  int32_t buffer;        // MB
2153
  int32_t pageSize;
2154
  int32_t pages;
2155
  int32_t cacheLastSize;
2156
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2157
  int32_t daysPerFile;
2158
  int32_t daysToKeep0;
2159
  int32_t daysToKeep1;
2160
  int32_t daysToKeep2;
2161
  int32_t keepTimeOffset;
2162
  int32_t minRows;
2163
  int32_t maxRows;
2164
  int32_t walFsyncPeriod;
2165
  int8_t  walLevel;
2166
  int8_t  precision;  // time resolution
2167
  int8_t  compression;
2168
  int8_t  replications;
2169
  int8_t  strict;
2170
  int8_t  cacheLast;
2171
  int8_t  schemaless;
2172
  int8_t  ignoreExist;
2173
  int32_t numOfRetensions;
2174
  SArray* pRetensions;  // SRetention
2175
  int32_t walRetentionPeriod;
2176
  int64_t walRetentionSize;
2177
  int32_t walRollPeriod;
2178
  int64_t walSegmentSize;
2179
  int32_t sstTrigger;
2180
  int16_t hashPrefix;
2181
  int16_t hashSuffix;
2182
  int32_t ssChunkSize;
2183
  int32_t ssKeepLocal;
2184
  int8_t  ssCompact;
2185
  int32_t tsdbPageSize;
2186
  int32_t sqlLen;
2187
  char*   sql;
2188
  int8_t  withArbitrator;
2189
  int8_t  encryptAlgorithm;
2190
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
2191
  // 1. add auto-compact parameters
2192
  int32_t compactInterval;    // minutes
2193
  int32_t compactStartTime;   // minutes
2194
  int32_t compactEndTime;     // minutes
2195
  int8_t  compactTimeOffset;  // hour
2196
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2197
  int8_t  isAudit;
2198
  int8_t  allowDrop;
2199
  int8_t  secureDelete;
2200
} SCreateDbReq;
2201

2202
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2203
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2204
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2205

2206
typedef struct {
2207
  char    db[TSDB_DB_FNAME_LEN];
2208
  int32_t buffer;
2209
  int32_t pageSize;
2210
  int32_t pages;
2211
  int32_t cacheLastSize;
2212
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
2213
  int32_t daysPerFile;
2214
  int32_t daysToKeep0;
2215
  int32_t daysToKeep1;
2216
  int32_t daysToKeep2;
2217
  int32_t keepTimeOffset;
2218
  int32_t walFsyncPeriod;
2219
  int8_t  walLevel;
2220
  int8_t  strict;
2221
  int8_t  cacheLast;
2222
  int8_t  replications;
2223
  int32_t sstTrigger;
2224
  int32_t minRows;
2225
  int32_t walRetentionPeriod;
2226
  int32_t walRetentionSize;
2227
  int32_t ssKeepLocal;
2228
  int8_t  ssCompact;
2229
  int32_t sqlLen;
2230
  char*   sql;
2231
  int8_t  withArbitrator;
2232
  // 1. add auto-compact parameters
2233
  int32_t compactInterval;
2234
  int32_t compactStartTime;
2235
  int32_t compactEndTime;
2236
  int8_t  compactTimeOffset;
2237
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2238
  int8_t  isAudit;
2239
  int8_t  allowDrop;
2240
  int8_t  secureDelete;
2241
} SAlterDbReq;
2242

2243
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2244
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2245
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2246

2247
typedef struct {
2248
  char    db[TSDB_DB_FNAME_LEN];
2249
  int8_t  ignoreNotExists;
2250
  int8_t  force;
2251
  int32_t sqlLen;
2252
  char*   sql;
2253
} SDropDbReq;
2254

2255
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2256
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2257
void    tFreeSDropDbReq(SDropDbReq* pReq);
2258

2259
typedef struct {
2260
  char    db[TSDB_DB_FNAME_LEN];
2261
  int64_t uid;
2262
} SDropDbRsp;
2263

2264
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2265
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2266

2267
typedef struct {
2268
  char    name[TSDB_MOUNT_NAME_LEN];
2269
  int64_t uid;
2270
} SDropMountRsp;
2271

2272
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2273
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2274

2275
typedef struct {
2276
  char    db[TSDB_DB_FNAME_LEN];
2277
  int64_t dbId;
2278
  int32_t vgVersion;
2279
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2280
  int64_t stateTs;     // ms
2281
} SUseDbReq;
2282

2283
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2284
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2285

2286
typedef struct {
2287
  char    db[TSDB_DB_FNAME_LEN];
2288
  int64_t uid;
2289
  int32_t vgVersion;
2290
  int32_t vgNum;
2291
  int16_t hashPrefix;
2292
  int16_t hashSuffix;
2293
  int8_t  hashMethod;
2294
  union {
2295
    uint8_t flags;
2296
    struct {
2297
      uint8_t isMount : 1;  // TS-5868
2298
      uint8_t padding : 7;
2299
    };
2300
  };
2301
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2302
  int32_t errCode;
2303
  int64_t stateTs;  // ms
2304
} SUseDbRsp;
2305

2306
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2307
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2308
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2309
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2310
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2311

2312
typedef struct {
2313
  char db[TSDB_DB_FNAME_LEN];
2314
} SDbCfgReq;
2315

2316
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2317
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2318

2319
typedef struct {
2320
  char db[TSDB_DB_FNAME_LEN];
2321
} SSsMigrateDbReq;
2322

2323
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2324
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2325

2326
typedef struct {
2327
  int32_t ssMigrateId;
2328
  bool    bAccepted;
2329
} SSsMigrateDbRsp;
2330

2331
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2332
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2333

2334
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2335
typedef struct {
2336
  int32_t ssMigrateId;
2337
} SListSsMigrateFileSetsReq;
2338

2339
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2340
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2341

2342
typedef struct {
2343
  int32_t ssMigrateId;
2344
  int32_t vgId;       // vgroup id
2345
  SArray* pFileSets;  // SArray<int32_t>
2346
} SListSsMigrateFileSetsRsp;
2347

2348
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2349
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2350
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2351

2352
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2353
typedef struct {
2354
  int32_t ssMigrateId;
2355
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2356
  int32_t fid;
2357
  int64_t startTimeSec;
2358
} SSsMigrateFileSetReq;
2359

2360
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2361
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2362

2363
typedef struct {
2364
  int32_t ssMigrateId;
2365
  int32_t nodeId;  // node id of the leader vnode
2366
  int32_t vgId;
2367
  int32_t fid;
2368
} SSsMigrateFileSetRsp;
2369

2370
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2371
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2372

2373
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2374
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2375
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2376
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2377
#define SSMIGRATE_FILESET_STATE_FAILED      4
2378

2379
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2380
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2381
// while as a request, the 'state' field is not used.
2382
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2383
typedef struct {
2384
  int32_t ssMigrateId;  // ss migrate id
2385
  int32_t nodeId;       // node id of the leader vnode
2386
  int32_t vgId;         // vgroup id
2387
  int32_t fid;          // file set id
2388
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2389
} SSsMigrateProgress;
2390

2391
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2392
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2393

2394
// Request for TDMT_MND_KILL_SSMIGRATE
2395
typedef struct {
2396
  int32_t ssMigrateId;
2397
  int32_t sqlLen;
2398
  char*   sql;
2399
} SKillSsMigrateReq;
2400

2401
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2402
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2403
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2404

2405
// Request for TDMT_VND_KILL_SSMIGRATE
2406
typedef struct {
2407
  int32_t ssMigrateId;
2408
} SVnodeKillSsMigrateReq;
2409

2410
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2411
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2412

2413
typedef struct {
2414
  int32_t vgId;
2415
  int64_t keepVersion;
2416
} SMndSetVgroupKeepVersionReq;
2417

2418
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2419
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2420

2421
typedef struct {
2422
  int32_t timestampSec;
2423
  int32_t ttlDropMaxCount;
2424
  int32_t nUids;
2425
  SArray* pTbUids;
2426
} SVDropTtlTableReq;
2427

2428
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2429
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2430

2431
typedef struct {
2432
  char    db[TSDB_DB_FNAME_LEN];
2433
  int64_t dbId;
2434
  int64_t ownerId;
2435
  int32_t cfgVersion;
2436
  int32_t numOfVgroups;
2437
  int32_t numOfStables;
2438
  int32_t buffer;
2439
  int32_t cacheSize;
2440
  int32_t cacheShardBits;
2441
  int32_t pageSize;
2442
  int32_t pages;
2443
  int32_t daysPerFile;
2444
  int32_t daysToKeep0;
2445
  int32_t daysToKeep1;
2446
  int32_t daysToKeep2;
2447
  int32_t keepTimeOffset;
2448
  int32_t minRows;
2449
  int32_t maxRows;
2450
  int32_t walFsyncPeriod;
2451
  int16_t hashPrefix;
2452
  int16_t hashSuffix;
2453
  int8_t  hashMethod;
2454
  int8_t  walLevel;
2455
  int8_t  precision;
2456
  int8_t  compression;
2457
  int8_t  replications;
2458
  int8_t  strict;
2459
  int8_t  cacheLast;
2460
  int8_t  encryptAlgr;
2461
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2462
  int32_t ssChunkSize;
2463
  int32_t ssKeepLocal;
2464
  int8_t  ssCompact;
2465
  union {
2466
    uint8_t flags;
2467
    struct {
2468
      uint8_t isMount : 1;    // TS-5868
2469
      uint8_t allowDrop : 1;  // TS-7232
2470
      uint8_t padding : 6;
2471
    };
2472
  };
2473
  int8_t  compactTimeOffset;
2474
  int32_t compactInterval;
2475
  int32_t compactStartTime;
2476
  int32_t compactEndTime;
2477
  int32_t tsdbPageSize;
2478
  int32_t walRetentionPeriod;
2479
  int32_t walRollPeriod;
2480
  int64_t walRetentionSize;
2481
  int64_t walSegmentSize;
2482
  int32_t numOfRetensions;
2483
  SArray* pRetensions;
2484
  int8_t  schemaless;
2485
  int16_t sstTrigger;
2486
  int8_t  withArbitrator;
2487
  int8_t  isAudit;
2488
  int8_t  secureDelete;
2489
} SDbCfgRsp;
2490

2491
typedef SDbCfgRsp SDbCfgInfo;
2492

2493
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2494
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2495
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2496
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2497
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2498

2499
typedef struct {
2500
  int32_t rowNum;
2501
} SQnodeListReq;
2502

2503
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2504
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2505

2506
typedef struct {
2507
  int32_t rowNum;
2508
} SDnodeListReq;
2509

2510
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2511

2512
typedef struct {
2513
  int32_t useless;  // useless
2514
} SServerVerReq;
2515

2516
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2517
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2518

2519
typedef struct {
2520
  char ver[TSDB_VERSION_LEN];
2521
} SServerVerRsp;
2522

2523
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2524
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2525

2526
typedef struct SQueryNodeAddr {
2527
  int32_t nodeId;  // vgId or qnodeId
2528
  SEpSet  epSet;
2529
} SQueryNodeAddr;
2530

2531
typedef struct {
2532
  SQueryNodeAddr addr;
2533
  uint64_t       load;
2534
} SQueryNodeLoad;
2535

2536
typedef struct {
2537
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2538
} SQnodeListRsp;
2539

2540
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2541
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2542
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2543

2544

2545
typedef struct SDownstreamSourceNode {
2546
  ENodeType      type;
2547
  SQueryNodeAddr addr;
2548
  uint64_t       clientId;
2549
  uint64_t       taskId;
2550
  uint64_t       sId;
2551
  uint64_t       srcTaskId;
2552
  int32_t        execId;
2553
  int32_t        fetchMsgType;
2554
  bool           localExec;
2555
} SDownstreamSourceNode;
2556

2557

2558

2559
typedef struct SDNodeAddr {
2560
  int32_t nodeId;  // dnodeId
2561
  SEpSet  epSet;
2562
} SDNodeAddr;
2563

2564
typedef struct {
2565
  SArray* dnodeList;  // SArray<SDNodeAddr>
2566
} SDnodeListRsp;
2567

2568
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2569
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2570
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2571

2572
typedef struct {
2573
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2574
} STableTSMAInfoRsp;
2575

2576
typedef struct {
2577
  SUseDbRsp*         useDbRsp;
2578
  SDbCfgRsp*         cfgRsp;
2579
  STableTSMAInfoRsp* pTsmaRsp;
2580
  int32_t            dbTsmaVersion;
2581
  char               db[TSDB_DB_FNAME_LEN];
2582
  int64_t            dbId;
2583
} SDbHbRsp;
2584

2585
typedef struct {
2586
  SArray* pArray;  // Array of SDbHbRsp
2587
} SDbHbBatchRsp;
2588

2589
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2590
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2591
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2592

2593
typedef struct {
2594
  SArray* pArray;  // Array of SGetUserAuthRsp
2595
} SUserAuthBatchRsp;
2596

2597
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2598
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2599
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2600

2601
typedef struct {
2602
  char        db[TSDB_DB_FNAME_LEN];
2603
  STimeWindow timeRange;
2604
  int32_t     sqlLen;
2605
  char*       sql;
2606
  SArray*     vgroupIds;
2607
  int32_t     compactId;
2608
  int8_t      metaOnly;
2609
  int8_t      force;
2610
} SCompactDbReq;
2611

2612
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2613
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2614
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2615

2616
typedef struct {
2617
  union {
2618
    int32_t compactId;
2619
    int32_t id;
2620
  };
2621
  int8_t bAccepted;
2622
} SCompactDbRsp;
2623

2624
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2625
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2626

2627
typedef struct {
2628
  union {
2629
    int32_t compactId;
2630
    int32_t id;
2631
  };
2632
  int32_t sqlLen;
2633
  char*   sql;
2634
} SKillCompactReq;
2635

2636
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2637
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2638
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2639

2640
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2641
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2642

2643
typedef struct {
2644
  char    name[TSDB_FUNC_NAME_LEN];
2645
  int8_t  igExists;
2646
  int8_t  funcType;
2647
  int8_t  scriptType;
2648
  int8_t  outputType;
2649
  int32_t outputLen;
2650
  int32_t bufSize;
2651
  int32_t codeLen;
2652
  int64_t signature;
2653
  char*   pComment;
2654
  char*   pCode;
2655
  int8_t  orReplace;
2656
} SCreateFuncReq;
2657

2658
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2659
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2660
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2661

2662
typedef struct {
2663
  char   name[TSDB_FUNC_NAME_LEN];
2664
  int8_t igNotExists;
2665
} SDropFuncReq;
2666

2667
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2668
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2669

2670
typedef struct {
2671
  int32_t numOfFuncs;
2672
  bool    ignoreCodeComment;
2673
  SArray* pFuncNames;
2674
} SRetrieveFuncReq;
2675

2676
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2677
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2678
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2679

2680
typedef struct {
2681
  char    name[TSDB_FUNC_NAME_LEN];
2682
  int8_t  funcType;
2683
  int8_t  scriptType;
2684
  int8_t  outputType;
2685
  int32_t outputLen;
2686
  int32_t bufSize;
2687
  int64_t signature;
2688
  int32_t commentSize;
2689
  int32_t codeSize;
2690
  char*   pComment;
2691
  char*   pCode;
2692
} SFuncInfo;
2693

2694
typedef struct {
2695
  int32_t funcVersion;
2696
  int64_t funcCreatedTime;
2697
} SFuncExtraInfo;
2698

2699
typedef struct {
2700
  int32_t numOfFuncs;
2701
  SArray* pFuncInfos;
2702
  SArray* pFuncExtraInfos;
2703
} SRetrieveFuncRsp;
2704

2705
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2706
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2707
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2708
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2709

2710
typedef struct {
2711
  int32_t       statusInterval;
2712
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2713
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2714
  char          locale[TD_LOCALE_LEN];      // tsLocale
2715
  char          charset[TD_LOCALE_LEN];     // tsCharset
2716
  int8_t        ttlChangeOnWrite;
2717
  int8_t        enableWhiteList;
2718
  int8_t        encryptionKeyStat;
2719
  uint32_t      encryptionKeyChksum;
2720
  SMonitorParas monitorParas;
2721
  int32_t       statusIntervalMs;
2722
} SClusterCfg;
2723

2724
typedef struct {
2725
  int32_t openVnodes;
2726
  int32_t dropVnodes;
2727
  int32_t totalVnodes;
2728
  int32_t masterNum;
2729
  int64_t numOfSelectReqs;
2730
  int64_t numOfInsertReqs;
2731
  int64_t numOfInsertSuccessReqs;
2732
  int64_t numOfBatchInsertReqs;
2733
  int64_t numOfBatchInsertSuccessReqs;
2734
  int64_t errors;
2735
} SVnodesStat;
2736

2737
typedef struct {
2738
  int32_t vgId;
2739
  int8_t  syncState;
2740
  int8_t  syncRestore;
2741
  int64_t syncTerm;
2742
  int64_t roleTimeMs;
2743
  int64_t startTimeMs;
2744
  int8_t  syncCanRead;
2745
  int64_t cacheUsage;
2746
  int64_t numOfTables;
2747
  int64_t numOfTimeSeries;
2748
  int64_t totalStorage;
2749
  int64_t compStorage;
2750
  int64_t pointsWritten;
2751
  int64_t numOfSelectReqs;
2752
  int64_t numOfInsertReqs;
2753
  int64_t numOfInsertSuccessReqs;
2754
  int64_t numOfBatchInsertReqs;
2755
  int64_t numOfBatchInsertSuccessReqs;
2756
  int32_t numOfCachedTables;
2757
  int32_t learnerProgress;  // use one reservered
2758
  int64_t syncAppliedIndex;
2759
  int64_t syncCommitIndex;
2760
  int64_t bufferSegmentUsed;
2761
  int64_t bufferSegmentSize;
2762
  int32_t snapSeq;
2763
  int64_t syncTotalIndex;
2764
} SVnodeLoad;
2765

2766
typedef struct {
2767
  int64_t total_requests;
2768
  int64_t total_rows;
2769
  int64_t total_bytes;
2770
  double  write_size;
2771
  double  cache_hit_ratio;
2772
  int64_t rpc_queue_wait;
2773
  int64_t preprocess_time;
2774

2775
  int64_t memory_table_size;
2776
  int64_t commit_count;
2777
  int64_t merge_count;
2778
  double  commit_time;
2779
  double  merge_time;
2780
  int64_t block_commit_time;
2781
  int64_t memtable_wait_time;
2782
} SVnodeMetrics;
2783

2784
typedef struct {
2785
  int32_t     vgId;
2786
  int64_t     numOfTables;
2787
  int64_t     memSize;
2788
  int64_t     l1Size;
2789
  int64_t     l2Size;
2790
  int64_t     l3Size;
2791
  int64_t     cacheSize;
2792
  int64_t     walSize;
2793
  int64_t     metaSize;
2794
  int64_t     rawDataSize;
2795
  int64_t     ssSize;
2796
  const char* dbname;
2797
  int8_t      estimateRawData;
2798
} SDbSizeStatisInfo;
2799

2800
typedef struct {
2801
  int32_t vgId;
2802
  int64_t nTimeSeries;
2803
} SVnodeLoadLite;
2804

2805
typedef struct {
2806
  int8_t  syncState;
2807
  int64_t syncTerm;
2808
  int8_t  syncRestore;
2809
  int64_t roleTimeMs;
2810
} SMnodeLoad;
2811

2812
typedef struct {
2813
  int32_t dnodeId;
2814
  int64_t numOfProcessedQuery;
2815
  int64_t numOfProcessedCQuery;
2816
  int64_t numOfProcessedFetch;
2817
  int64_t numOfProcessedDrop;
2818
  int64_t numOfProcessedNotify;
2819
  int64_t numOfProcessedHb;
2820
  int64_t numOfProcessedDelete;
2821
  int64_t cacheDataSize;
2822
  int64_t numOfQueryInQueue;
2823
  int64_t numOfFetchInQueue;
2824
  int64_t timeInQueryQueue;
2825
  int64_t timeInFetchQueue;
2826
} SQnodeLoad;
2827

2828
typedef struct {
2829
  int32_t     sver;      // software version
2830
  int64_t     dnodeVer;  // dnode table version in sdb
2831
  int32_t     dnodeId;
2832
  int64_t     clusterId;
2833
  int64_t     rebootTime;
2834
  int64_t     updateTime;
2835
  float       numOfCores;
2836
  int32_t     numOfSupportVnodes;
2837
  int32_t     numOfDiskCfg;
2838
  int64_t     memTotal;
2839
  int64_t     memAvail;
2840
  char        dnodeEp[TSDB_EP_LEN];
2841
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2842
  SMnodeLoad  mload;
2843
  SQnodeLoad  qload;
2844
  SClusterCfg clusterCfg;
2845
  SArray*     pVloads;  // array of SVnodeLoad
2846
  int32_t     statusSeq;
2847
  int64_t     ipWhiteVer;
2848
  int64_t     timeWhiteVer;
2849
  int64_t     analVer;
2850
  int64_t     timestamp;
2851
  char        auditDB[TSDB_DB_FNAME_LEN];
2852
  char        auditToken[TSDB_TOKEN_LEN];
2853
  SEpSet      auditEpSet;
2854
  int32_t     auditVgId;
2855
} SStatusReq;
2856

2857
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2858
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2859
void    tFreeSStatusReq(SStatusReq* pReq);
2860

2861
typedef struct {
2862
  int32_t forceReadConfig;
2863
  int32_t cver;
2864
  SArray* array;
2865
} SConfigReq;
2866

2867
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2868
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2869
void    tFreeSConfigReq(SConfigReq* pReq);
2870

2871
typedef struct {
2872
  int32_t dnodeId;
2873
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2874
} SDnodeInfoReq;
2875

2876
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2877
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2878

2879
typedef enum {
2880
  MONITOR_TYPE_COUNTER = 0,
2881
  MONITOR_TYPE_SLOW_LOG = 1,
2882
} MONITOR_TYPE;
2883

2884
typedef struct {
2885
  int32_t      contLen;
2886
  char*        pCont;
2887
  MONITOR_TYPE type;
2888
} SStatisReq;
2889

2890
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2891
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2892
void    tFreeSStatisReq(SStatisReq* pReq);
2893

2894
typedef struct {
2895
  char    db[TSDB_DB_FNAME_LEN];
2896
  char    table[TSDB_TABLE_NAME_LEN];
2897
  char    operation[AUDIT_OPERATION_LEN];
2898
  int32_t sqlLen;
2899
  char*   pSql;
2900
  double  duration;
2901
  int64_t affectedRows;
2902
} SAuditReq;
2903
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2904
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2905
void    tFreeSAuditReq(SAuditReq* pReq);
2906

2907
typedef struct {
2908
  SArray* auditArr;
2909
} SBatchAuditReq;
2910
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2911
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2912
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2913

2914
typedef struct {
2915
  int32_t dnodeId;
2916
  int64_t clusterId;
2917
  SArray* pVloads;
2918
} SNotifyReq;
2919

2920
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2921
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2922
void    tFreeSNotifyReq(SNotifyReq* pReq);
2923

2924
typedef struct {
2925
  int32_t dnodeId;
2926
  int64_t clusterId;
2927
} SDnodeCfg;
2928

2929
typedef struct {
2930
  int32_t id;
2931
  int8_t  isMnode;
2932
  SEp     ep;
2933
} SDnodeEp;
2934

2935
typedef struct {
2936
  int32_t id;
2937
  int8_t  isMnode;
2938
  int8_t  offlineReason;
2939
  SEp     ep;
2940
  char    active[TSDB_ACTIVE_KEY_LEN];
2941
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2942
} SDnodeInfo;
2943

2944
typedef struct {
2945
  int64_t   dnodeVer;
2946
  SDnodeCfg dnodeCfg;
2947
  SArray*   pDnodeEps;  // Array of SDnodeEp
2948
  int32_t   statusSeq;
2949
  int64_t   ipWhiteVer;
2950
  int64_t   analVer;
2951
  int64_t   timeWhiteVer;
2952
  char      auditDB[TSDB_DB_FNAME_LEN];
2953
  char      auditToken[TSDB_TOKEN_LEN];
2954
  SEpSet    auditEpSet;
2955
  int32_t   auditVgId;
2956
} SStatusRsp;
2957

2958
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2959
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2960
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2961

2962
typedef struct {
2963
  int32_t forceReadConfig;
2964
  int32_t isConifgVerified;
2965
  int32_t isVersionVerified;
2966
  int32_t cver;
2967
  SArray* array;
2968
} SConfigRsp;
2969

2970
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2971
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2972
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2973

2974
typedef struct {
2975
  int32_t dnodeId;
2976
  int32_t keyVersion;  // Local key version
2977
} SKeySyncReq;
2978

2979
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2980
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2981

2982
typedef struct {
2983
  int32_t keyVersion;        // mnode's key version
2984
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2985
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2986
  char    svrKey[129];       // Server key (if needUpdate)
2987
  char    dbKey[129];        // Database key (if needUpdate)
2988
  char    cfgKey[129];       // Config key (if needUpdate)
2989
  char    metaKey[129];      // Metadata key (if needUpdate)
2990
  char    dataKey[129];      // Data key (if needUpdate)
2991
  int32_t algorithm;         // Encryption algorithm for master keys
2992
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2993
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2994
  int64_t createTime;        // Key creation time
2995
  int64_t svrKeyUpdateTime;  // Server key update time
2996
  int64_t dbKeyUpdateTime;   // Database key update time
2997
} SKeySyncRsp;
2998

2999
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
3000
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
3001

3002
typedef struct {
3003
  int32_t reserved;
3004
} SMTimerReq;
3005

3006
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
3007
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
3008

3009
typedef struct SOrphanTask {
3010
  int64_t streamId;
3011
  int32_t taskId;
3012
  int32_t nodeId;
3013
} SOrphanTask;
3014

3015
typedef struct SMStreamDropOrphanMsg {
3016
  SArray* pList;  // SArray<SOrphanTask>
3017
} SMStreamDropOrphanMsg;
3018

3019
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
3020
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
3021
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
3022

3023
typedef struct {
3024
  int32_t  id;
3025
  uint16_t port;                 // node sync Port
3026
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
3027
} SReplica;
3028

3029
typedef struct {
3030
  int32_t  vgId;
3031
  char     db[TSDB_DB_FNAME_LEN];
3032
  int64_t  dbUid;
3033
  int32_t  vgVersion;
3034
  int32_t  numOfStables;
3035
  int32_t  buffer;
3036
  int32_t  pageSize;
3037
  int32_t  pages;
3038
  int32_t  cacheLastSize;
3039
  int32_t  cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3040
  int32_t  daysPerFile;
3041
  int32_t  daysToKeep0;
3042
  int32_t  daysToKeep1;
3043
  int32_t  daysToKeep2;
3044
  int32_t  keepTimeOffset;
3045
  int32_t  minRows;
3046
  int32_t  maxRows;
3047
  int32_t  walFsyncPeriod;
3048
  uint32_t hashBegin;
3049
  uint32_t hashEnd;
3050
  int8_t   hashMethod;
3051
  int8_t   walLevel;
3052
  int8_t   precision;
3053
  int8_t   compression;
3054
  int8_t   strict;
3055
  int8_t   cacheLast;
3056
  int8_t   isTsma;
3057
  int8_t   replica;
3058
  int8_t   selfIndex;
3059
  SReplica replicas[TSDB_MAX_REPLICA];
3060
  int32_t  numOfRetensions;
3061
  SArray*  pRetensions;  // SRetention
3062
  void*    pTsma;
3063
  int32_t  walRetentionPeriod;
3064
  int64_t  walRetentionSize;
3065
  int32_t  walRollPeriod;
3066
  int64_t  walSegmentSize;
3067
  int16_t  sstTrigger;
3068
  int16_t  hashPrefix;
3069
  int16_t  hashSuffix;
3070
  int32_t  tsdbPageSize;
3071
  int32_t  ssChunkSize;
3072
  int32_t  ssKeepLocal;
3073
  int8_t   ssCompact;
3074
  int64_t  reserved[6];
3075
  int8_t   learnerReplica;
3076
  int8_t   learnerSelfIndex;
3077
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3078
  int32_t  changeVersion;
3079
  int8_t   encryptAlgorithm;
3080
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
3081
  union {
3082
    uint8_t flags;
3083
    struct {
3084
      uint8_t isAudit : 1;
3085
      uint8_t allowDrop : 1;
3086
      uint8_t padding : 6;
3087
    };
3088
  };
3089
  int8_t secureDelete;
3090
} SCreateVnodeReq;
3091

3092
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3093
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3094
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3095

3096
typedef struct {
3097
  union {
3098
    int32_t compactId;
3099
    int32_t id;
3100
  };
3101
  int32_t vgId;
3102
  int32_t dnodeId;
3103
} SQueryCompactProgressReq;
3104

3105
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3106
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3107

3108
typedef struct {
3109
  union {
3110
    int32_t compactId;
3111
    int32_t id;
3112
  };
3113
  int32_t vgId;
3114
  int32_t dnodeId;
3115
  int32_t numberFileset;
3116
  int32_t finished;
3117
  int32_t progress;
3118
  int64_t remainingTime;
3119
} SQueryCompactProgressRsp;
3120

3121
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3122
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3123

3124
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3125
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3126

3127
typedef struct {
3128
  int32_t vgId;
3129
  int32_t dnodeId;
3130
  int64_t dbUid;
3131
  char    db[TSDB_DB_FNAME_LEN];
3132
  int64_t reserved[8];
3133
} SDropVnodeReq;
3134

3135
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3136
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3137

3138
typedef struct {
3139
  char    colName[TSDB_COL_NAME_LEN];
3140
  char    stb[TSDB_TABLE_FNAME_LEN];
3141
  int64_t stbUid;
3142
  int64_t dbUid;
3143
  int64_t reserved[8];
3144
} SDropIndexReq;
3145

3146
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3147
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3148

3149
typedef struct {
3150
  int64_t dbUid;
3151
  char    db[TSDB_DB_FNAME_LEN];
3152
  union {
3153
    int64_t compactStartTime;
3154
    int64_t startTime;
3155
  };
3156

3157
  STimeWindow tw;
3158
  union {
3159
    int32_t compactId;
3160
    int32_t id;
3161
  };
3162
  int8_t metaOnly;
3163
  union {
3164
    uint16_t flags;
3165
    struct {
3166
      uint16_t optrType : 3;     // ETsdbOpType
3167
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3168
      uint16_t reserved : 12;
3169
    };
3170
  };
3171
  int8_t force;  // force compact
3172
} SCompactVnodeReq;
3173

3174
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3175
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3176

3177
typedef struct {
3178
  union {
3179
    int32_t compactId;
3180
    int32_t taskId;
3181
  };
3182
  int32_t vgId;
3183
  int32_t dnodeId;
3184
} SVKillCompactReq;
3185

3186
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3187
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3188

3189
typedef SVKillCompactReq SVKillRetentionReq;
3190

3191
typedef struct {
3192
  char        db[TSDB_DB_FNAME_LEN];
3193
  int32_t     maxSpeed;
3194
  int32_t     sqlLen;
3195
  char*       sql;
3196
  SArray*     vgroupIds;
3197
  STimeWindow tw;  // unit is second
3198
  union {
3199
    uint32_t flags;
3200
    struct {
3201
      uint32_t optrType : 3;     // ETsdbOpType
3202
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3203
      uint32_t reserved : 28;
3204
    };
3205
  };
3206
} STrimDbReq;
3207

3208
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3209
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3210
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3211

3212
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3213

3214
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3215
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3216

3217
typedef struct {
3218
  int32_t vgVersion;
3219
  int32_t buffer;
3220
  int32_t pageSize;
3221
  int32_t pages;
3222
  int32_t cacheLastSize;
3223
  int32_t cacheLastShardBits;  // Number of shards for last cache LRU, -1 for auto
3224
  int32_t daysPerFile;
3225
  int32_t daysToKeep0;
3226
  int32_t daysToKeep1;
3227
  int32_t daysToKeep2;
3228
  int32_t keepTimeOffset;
3229
  int32_t walFsyncPeriod;
3230
  int8_t  walLevel;
3231
  int8_t  strict;
3232
  int8_t  cacheLast;
3233
  int64_t reserved[7];
3234
  // 1st modification
3235
  int16_t sttTrigger;
3236
  int32_t minRows;
3237
  // 2nd modification
3238
  int32_t walRetentionPeriod;
3239
  int32_t walRetentionSize;
3240
  int32_t ssKeepLocal;
3241
  int8_t  ssCompact;
3242
  int8_t  allowDrop;
3243
  int8_t  secureDelete;
3244
} SAlterVnodeConfigReq;
3245

3246
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3247
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3248

3249
typedef struct {
3250
  int32_t  vgId;
3251
  int8_t   strict;
3252
  int8_t   selfIndex;
3253
  int8_t   replica;
3254
  SReplica replicas[TSDB_MAX_REPLICA];
3255
  int64_t  reserved[8];
3256
  int8_t   learnerSelfIndex;
3257
  int8_t   learnerReplica;
3258
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3259
  int32_t  changeVersion;
3260
  int32_t  electBaseLine;
3261
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3262

3263
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3264
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3265

3266
typedef struct {
3267
  int32_t vgId;
3268
  int8_t  disable;
3269
} SDisableVnodeWriteReq;
3270

3271
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3272
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3273

3274
typedef struct {
3275
  int32_t  srcVgId;
3276
  int32_t  dstVgId;
3277
  uint32_t hashBegin;
3278
  uint32_t hashEnd;
3279
  int32_t  changeVersion;
3280
  int32_t  reserved;
3281
} SAlterVnodeHashRangeReq;
3282

3283
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3284
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3285

3286
#define REQ_OPT_TBNAME 0x0
3287
#define REQ_OPT_TBUID  0x01
3288
typedef struct {
3289
  SMsgHead header;
3290
  char     dbFName[TSDB_DB_FNAME_LEN];
3291
  char     tbName[TSDB_TABLE_NAME_LEN];
3292
  uint8_t  option;
3293
  uint8_t  autoCreateCtb;
3294
} STableInfoReq;
3295

3296
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3297
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3298

3299
typedef struct {
3300
  int8_t  metaClone;  // create local clone of the cached table meta
3301
  int32_t numOfVgroups;
3302
  int32_t numOfTables;
3303
  int32_t numOfUdfs;
3304
  char    tableNames[];
3305
} SMultiTableInfoReq;
3306

3307
// todo refactor
3308
typedef struct SVgroupInfo {
3309
  int32_t  vgId;
3310
  uint32_t hashBegin;
3311
  uint32_t hashEnd;
3312
  SEpSet   epSet;
3313
  union {
3314
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3315
    int32_t taskId;      // used in stream
3316
  };
3317
} SVgroupInfo;
3318

3319
typedef struct {
3320
  int32_t     numOfVgroups;
3321
  SVgroupInfo vgroups[];
3322
} SVgroupsInfo;
3323

3324
typedef struct {
3325
  STableMetaRsp* pMeta;
3326
} SMAlterStbRsp;
3327

3328
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3329
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3330
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3331

3332
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3333
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3334
void    tFreeSTableMetaRsp(void* pRsp);
3335
void    tFreeSTableIndexRsp(void* info);
3336

3337
typedef struct {
3338
  SArray* pMetaRsp;   // Array of STableMetaRsp
3339
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3340
} SSTbHbRsp;
3341

3342
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3343
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3344
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3345

3346
typedef struct {
3347
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3348
} SViewHbRsp;
3349

3350
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3351
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3352
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3353

3354
typedef struct {
3355
  int32_t numOfTables;
3356
  int32_t numOfVgroup;
3357
  int32_t numOfUdf;
3358
  int32_t contLen;
3359
  int8_t  compressed;  // denote if compressed or not
3360
  int32_t rawLen;      // size before compress
3361
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3362
  char    meta[];
3363
} SMultiTableMeta;
3364

3365
typedef struct {
3366
  int32_t dataLen;
3367
  char    name[TSDB_TABLE_FNAME_LEN];
3368
  char*   data;
3369
} STagData;
3370

3371
typedef struct {
3372
  int32_t  opType;
3373
  uint32_t valLen;
3374
  char*    val;
3375
} SShowVariablesReq;
3376

3377
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3378
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3379
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3380

3381
typedef struct {
3382
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3383
  char value[TSDB_CONFIG_PATH_LEN + 1];
3384
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3385
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3386
  char info[TSDB_CONFIG_INFO_LEN + 1];
3387
} SVariablesInfo;
3388

3389
typedef struct {
3390
  SArray* variables;  // SArray<SVariablesInfo>
3391
} SShowVariablesRsp;
3392

3393
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3394
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3395

3396
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3397

3398
/*
3399
 * sql: show tables like '%a_%'
3400
 * payload is the query condition, e.g., '%a_%'
3401
 * payloadLen is the length of payload
3402
 */
3403
typedef struct {
3404
  int32_t type;
3405
  char    db[TSDB_DB_FNAME_LEN];
3406
  int32_t payloadLen;
3407
  char*   payload;
3408
} SShowReq;
3409

3410
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3411
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3412
void tFreeSShowReq(SShowReq* pReq);
3413

3414
typedef struct {
3415
  int64_t       showId;
3416
  STableMetaRsp tableMeta;
3417
} SShowRsp, SVShowTablesRsp;
3418

3419
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3420
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3421
// void    tFreeSShowRsp(SShowRsp* pRsp);
3422

3423
typedef struct {
3424
  char    db[TSDB_DB_FNAME_LEN];
3425
  char    tb[TSDB_TABLE_NAME_LEN];
3426
  char    user[TSDB_USER_LEN];
3427
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3428
  int64_t showId;
3429
  int64_t compactId;  // for compact
3430
  bool    withFull;   // for show users full
3431
} SRetrieveTableReq;
3432

3433
typedef struct SSysTableSchema {
3434
  int8_t   type;
3435
  col_id_t colId;
3436
  int32_t  bytes;
3437
} SSysTableSchema;
3438

3439
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3440
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3441

3442
#define RETRIEVE_TABLE_RSP_VERSION         0
3443
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3444
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3445

3446
typedef struct {
3447
  int64_t useconds;
3448
  int8_t  completed;  // all results are returned to client
3449
  int8_t  precision;
3450
  int8_t  compressed;
3451
  int8_t  streamBlockType;
3452
  int32_t payloadLen;
3453
  int32_t compLen;
3454
  int32_t numOfBlocks;
3455
  int64_t numOfRows;  // from int32_t change to int64_t
3456
  int64_t numOfCols;
3457
  int64_t skey;
3458
  int64_t ekey;
3459
  int64_t version;                         // for stream
3460
  TSKEY   watermark;                       // for stream
3461
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3462
  char    data[];
3463
} SRetrieveTableRsp;
3464

3465
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3466

3467
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3468
  do {                                          \
3469
    ((int32_t*)(_p))[0] = (_compLen);           \
3470
    ((int32_t*)(_p))[1] = (_fullLen);           \
3471
  } while (0);
3472

3473
typedef struct {
3474
  int64_t version;
3475
  int64_t numOfRows;
3476
  int8_t  compressed;
3477
  int8_t  precision;
3478
  char    data[];
3479
} SRetrieveTableRspForTmq;
3480

3481
typedef struct {
3482
  int64_t handle;
3483
  int64_t useconds;
3484
  int8_t  completed;  // all results are returned to client
3485
  int8_t  precision;
3486
  int8_t  compressed;
3487
  int32_t compLen;
3488
  int32_t numOfRows;
3489
  int32_t fullLen;
3490
  char    data[];
3491
} SRetrieveMetaTableRsp;
3492

3493
typedef struct SExplainExecInfo {
3494
  /* the number of rows returned */
3495
  uint64_t numOfRows;
3496
  uint32_t verboseLen;
3497
  void*    verboseInfo;
3498

3499
  /* the timestamp when the operator is created */
3500
  TSKEY    execCreate;
3501
  /* the first timestamp when the operator's next interface is called */
3502
  TSKEY    execStart;
3503
  /* the timestamp when the first row is returned */
3504
  TSKEY    execFirstRow;
3505
  /* the timestamp when the last row is returned */
3506
  TSKEY    execLastRow;
3507
  /* the number of times the operator's next interface is called */
3508
  uint32_t execTimes;
3509
  /**
3510
    the time elapsed for executing the operator's next interface,
3511
    not including waiting time for data from downstream
3512
  */
3513
  TSKEY    execElapsed;
3514
  /* the time elapsed for waiting for data from downstream */
3515
  TSKEY    inputWaitElapsed;
3516
  /* the time elapsed for waiting call from upstream */
3517
  TSKEY    outputWaitElapsed;
3518
  /* the number of rows input */
3519
  uint64_t inputRows;
3520

3521
  int32_t  vgId;
3522
} SExplainExecInfo;
3523

3524
typedef struct {
3525
  int32_t           numOfPlans;
3526
  SExplainExecInfo* subplanInfo;
3527
} SExplainRsp;
3528

3529
typedef struct {
3530
  SExplainRsp rsp;
3531
  uint64_t    qId;
3532
  uint64_t    cId;
3533
  uint64_t    tId;
3534
  int64_t     rId;
3535
  int32_t     eId;
3536
} SExplainLocalRsp;
3537

3538
typedef struct STableScanAnalyzeInfo {
3539
  int64_t totalBlocks;
3540
  int64_t fileLoadBlocks;
3541
  double  fileLoadElapsed;
3542
  int64_t sttLoadBlocks;
3543
  double  sttLoadElapsed;
3544
  int64_t memLoadBlocks;
3545
  double  memLoadElapsed;
3546
  int64_t smaLoadBlocks;
3547
  double  smaLoadElapsed;
3548
  int64_t composedBlocks;
3549
  double  composedElapsed;
3550
  
3551
  uint64_t checkRows;
3552

3553
  uint64_t skipBlocks;
3554
  uint64_t filterOutBlocks;
3555
  double   filterTime;
3556
} STableScanAnalyzeInfo;
3557

3558
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3559
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3560
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3561

3562
typedef struct {
3563
  char    config[TSDB_DNODE_CONFIG_LEN];
3564
  char    value[TSDB_CLUSTER_VALUE_LEN];
3565
  int32_t sqlLen;
3566
  char*   sql;
3567
} SMCfgClusterReq;
3568

3569
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3570
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3571
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3572

3573
typedef struct {
3574
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3575
  int32_t port;
3576
  int32_t sqlLen;
3577
  char*   sql;
3578
} SCreateDnodeReq;
3579

3580
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3581
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3582
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3583

3584
typedef struct {
3585
  int32_t dnodeId;
3586
  char    fqdn[TSDB_FQDN_LEN];
3587
  int32_t port;
3588
  int8_t  force;
3589
  int8_t  unsafe;
3590
  int32_t sqlLen;
3591
  char*   sql;
3592
} SDropDnodeReq;
3593

3594
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3595
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3596
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3597

3598
enum {
3599
  RESTORE_TYPE__ALL = 1,
3600
  RESTORE_TYPE__MNODE,
3601
  RESTORE_TYPE__VNODE,
3602
  RESTORE_TYPE__QNODE,
3603
};
3604

3605
typedef struct {
3606
  int32_t dnodeId;
3607
  int8_t  restoreType;
3608
  int32_t sqlLen;
3609
  char*   sql;
3610
} SRestoreDnodeReq;
3611

3612
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3613
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3614
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3615

3616
typedef struct {
3617
  int32_t dnodeId;
3618
  char    config[TSDB_DNODE_CONFIG_LEN];
3619
  char    value[TSDB_DNODE_VALUE_LEN];
3620
  int32_t sqlLen;
3621
  char*   sql;
3622
} SMCfgDnodeReq;
3623

3624
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3625
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3626
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3627

3628
typedef struct {
3629
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3630
  char    newKey[ENCRYPT_KEY_LEN + 1];
3631
  int32_t sqlLen;
3632
  char*   sql;
3633
} SMAlterEncryptKeyReq;
3634

3635
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3636
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3637
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3638

3639
typedef struct {
3640
  int32_t days;
3641
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3642
  int32_t sqlLen;
3643
  char*   sql;
3644
} SMAlterKeyExpirationReq;
3645

3646
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3647
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3648
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3649

3650
typedef struct {
3651
  char    config[TSDB_DNODE_CONFIG_LEN];
3652
  char    value[TSDB_DNODE_VALUE_LEN];
3653
  int32_t version;
3654
} SDCfgDnodeReq;
3655

3656
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3657
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3658

3659
typedef struct {
3660
  int32_t dnodeId;
3661
  int32_t sqlLen;
3662
  char*   sql;
3663
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3664
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3665

3666
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3667
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3668

3669
typedef struct {
3670
  int32_t nodeId;
3671
  SEpSet  epSet;
3672
} SNodeEpSet;
3673

3674
typedef struct {
3675
  int32_t    snodeId;
3676
  SNodeEpSet leaders[2];
3677
  SNodeEpSet replica;
3678
  int32_t    sqlLen;
3679
  char*      sql;
3680
} SDCreateSnodeReq;
3681

3682
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3683
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3684
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3685

3686
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3687
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3688
typedef struct {
3689
  int8_t   replica;
3690
  SReplica replicas[TSDB_MAX_REPLICA];
3691
  int8_t   learnerReplica;
3692
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3693
  int64_t  lastIndex;
3694
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3695
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3696

3697
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3698
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3699

3700
typedef struct {
3701
  int32_t urlLen;
3702
  int32_t sqlLen;
3703
  char*   url;
3704
  char*   sql;
3705
} SMCreateAnodeReq;
3706

3707
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3708
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3709
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3710

3711
typedef struct {
3712
  int32_t anodeId;
3713
  int32_t sqlLen;
3714
  char*   sql;
3715
} SMDropAnodeReq, SMUpdateAnodeReq;
3716

3717
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3718
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3719
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3720
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3721
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3722
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3723

3724
typedef struct {
3725
  int32_t dnodeId;
3726
  int32_t bnodeProto;
3727
  int32_t sqlLen;
3728
  char*   sql;
3729
} SMCreateBnodeReq, SDCreateBnodeReq;
3730

3731
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3732
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3733
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3734

3735
typedef struct {
3736
  int32_t dnodeId;
3737
  int32_t sqlLen;
3738
  char*   sql;
3739
} SMDropBnodeReq, SDDropBnodeReq;
3740

3741
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3742
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3743
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3744

3745
typedef struct {
3746
  bool        shouldFree;
3747
  int32_t     len;
3748
  const char* ptr;
3749
} CowStr;
3750
/**
3751
 * @brief Create a CowStr object.
3752
 *
3753
 * @param len: length of the string.
3754
 * @param ptr: pointer to the string input.
3755
 * @param shouldClone: whether to clone the string.
3756
 * @return CowStr object.
3757
 */
3758
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3759
/**
3760
 * @brief Set a CowStr object with given string.
3761
 *
3762
 * @param cow: pointer to the CowStr object.
3763
 * @param len: length of the string.
3764
 * @param ptr: pointer to the string input.
3765
 * @param shouldFree: whether to free the string.
3766
 */
3767
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3768
/**
3769
 * @brief Clone a CowStr object without copy the string.
3770
 *
3771
 * @param cow: pointer to the CowStr object.
3772
 * @return CowStr object.
3773
 */
3774
CowStr xCloneRefCowStr(CowStr* cow);
3775
/**
3776
 * @brief Convert a CowStr object to a string.
3777
 *
3778
 * @param cow: pointer to the CowStr object.
3779
 */
3780
char* xCowStrToStr(CowStr* cow);
3781
/**
3782
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3783
 *
3784
 * @param cow: pointer to the CowStr object.
3785
 */
3786
void xFreeCowStr(CowStr* cow);
3787
/**
3788
 * @brief Encode and push a CowStr object into the encoder.
3789
 *
3790
 * @param encoder
3791
 * @param cow
3792
 * @return int32_t
3793
 */
3794
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3795
/**
3796
 * @brief Decode a CowStr from the encoder.
3797
 *
3798
 * @param decoder
3799
 * @param cow
3800
 * @param shouldClone
3801
 * @return int32_t
3802
 */
3803
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3804

3805
typedef struct {
3806
  int32_t sqlLen;
3807
  int32_t urlLen;
3808
  int32_t userLen;
3809
  int32_t passLen;
3810
  int32_t passIsMd5;
3811
  char*   sql;
3812
  char*   url;
3813
  char*   user;
3814
  char*   pass;
3815
  CowStr  token;
3816
} SMCreateXnodeReq, SDCreateXnodeReq;
3817

3818
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3819
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3820
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3821

3822
typedef struct {
3823
  int32_t xnodeId;
3824
  int32_t force;
3825
  int32_t urlLen;
3826
  int32_t sqlLen;
3827
  char*   url;
3828
  char*   sql;
3829
} SMDropXnodeReq, SDDropXnodeReq;
3830

3831
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3832
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3833
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3834

3835
typedef struct {
3836
  int32_t id;
3837
  CowStr  token;
3838
  CowStr  user;
3839
  CowStr  pass;
3840
  int32_t urlLen;
3841
  int32_t sqlLen;
3842
  char*   url;
3843
  char*   sql;
3844
} SMUpdateXnodeReq;
3845
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3846
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3847
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3848

3849
typedef struct {
3850
  int32_t xnodeId;
3851
  int32_t sqlLen;
3852
  char*   sql;
3853
} SMDrainXnodeReq;
3854
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3855
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3856
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3857
typedef enum {
3858
  XNODE_TASK_SOURCE_DSN = 1,
3859
  XNODE_TASK_SOURCE_DATABASE,
3860
  XNODE_TASK_SOURCE_TOPIC,
3861
} ENodeXTaskSourceType;
3862

3863
typedef enum {
3864
  XNODE_TASK_SINK_DSN = 1,
3865
  XNODE_TASK_SINK_DATABASE,
3866
} ENodeXTaskSinkType;
3867

3868
typedef struct {
3869
  ENodeXTaskSourceType type;
3870
  CowStr               cstr;
3871
} xTaskSource;
3872
/**
3873
 * @brief Deallocate a xTaskSource object.
3874
 *
3875
 * @param source ptr
3876
 */
3877
void xFreeTaskSource(xTaskSource* source);
3878
/**
3879
 * @brief Create a xTaskSource object with cloned source string.
3880
 *
3881
 * @param sourceType: source type.
3882
 * @param len: length of source string.
3883
 * @param source: source string ptr.
3884
 * @return xTaskSource object
3885
 */
3886
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3887
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3888
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3889
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3890
const char* xGetTaskSourceStr(xTaskSource* source);
3891
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3892
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3893

3894
typedef struct {
3895
  ENodeXTaskSinkType type;
3896
  CowStr             cstr;
3897
} xTaskSink;
3898
/**
3899
 * @brief Deallocate a xTaskSink object.
3900
 *
3901
 * @param sink ptr
3902
 */
3903
void xFreeTaskSink(xTaskSink* sink);
3904
/**
3905
 * @brief Create a xTaskSink object with cloned name string.
3906
 *
3907
 * @param sinkType: sink type.
3908
 * @param len: length of sink string.
3909
 * @param ptr: sink string ptr.
3910
 * @return xTaskSink object
3911
 */
3912
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3913
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3914
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3915
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3916
const char* xGetTaskSinkStr(xTaskSink* sink);
3917
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3918
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3919

3920
typedef struct {
3921
  int32_t via;
3922
  CowStr  parser;
3923
  // CowStr  reason;
3924
  CowStr  trigger;
3925
  CowStr  health;
3926
  int32_t optionsNum;
3927
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3928
} xTaskOptions;
3929
/**
3930
 * @brief Deallocate a xTaskOptions object.
3931
 *
3932
 * @param options ptr
3933
 */
3934
void    xFreeTaskOptions(xTaskOptions* options);
3935
void    printXnodeTaskOptions(xTaskOptions* options);
3936
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3937
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3938

3939
typedef struct {
3940
  int32_t sqlLen;
3941
  char*   sql;
3942
  int32_t      xnodeId;
3943
  CowStr       name;
3944
  xTaskSource  source;
3945
  xTaskSink    sink;
3946
  xTaskOptions options;
3947
} SMCreateXnodeTaskReq;
3948
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3949
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3950
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3951

3952
typedef struct {
3953
  int32_t     tid;
3954
  CowStr      name;
3955
  int32_t     via;
3956
  int32_t     xnodeId;
3957
  CowStr      status;
3958
  xTaskSource source;
3959
  xTaskSink   sink;
3960
  CowStr      parser;
3961
  CowStr      reason;
3962
  CowStr      updateName;
3963
  CowStr      labels;
3964
  int32_t     sqlLen;
3965
  char*       sql;
3966
} SMUpdateXnodeTaskReq;
3967
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3968
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3969
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3970

3971
typedef struct {
3972
  int32_t id;
3973
  bool    force;
3974
  CowStr  name;
3975
  int32_t sqlLen;
3976
  char*   sql;
3977
} SMDropXnodeTaskReq;
3978
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3979
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3980
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3981

3982
typedef struct {
3983
  int32_t tid;
3984
  CowStr  name;
3985
  int32_t sqlLen;
3986
  char*   sql;
3987
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3988
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3989
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3990
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3991

3992
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3993
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3994
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3995

3996
typedef struct {
3997
  int32_t tid;
3998
  int32_t via;
3999
  int32_t xnodeId;
4000
  CowStr  status;
4001
  CowStr  config;
4002
  CowStr  reason;
4003
  int32_t sqlLen;
4004
  char*   sql;
4005
} SMCreateXnodeJobReq;
4006
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
4007
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
4008
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
4009

4010
typedef struct {
4011
  int32_t jid;
4012
  int32_t via;
4013
  int32_t xnodeId;
4014
  CowStr  status;
4015
  int32_t configLen;
4016
  int32_t reasonLen;
4017
  int32_t sqlLen;
4018
  char*   config;
4019
  char*   reason;
4020
  char*   sql;
4021
} SMUpdateXnodeJobReq;
4022
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4023
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
4024
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
4025

4026
typedef struct {
4027
  int32_t jid;
4028
  int32_t xnodeId;
4029
  int32_t sqlLen;
4030
  char*   sql;
4031
} SMRebalanceXnodeJobReq;
4032
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4033
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
4034
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
4035

4036
typedef struct {
4037
  CowStr  ast;
4038
  int32_t sqlLen;
4039
  char*   sql;
4040
} SMRebalanceXnodeJobsWhereReq;
4041
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4042
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
4043
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
4044

4045
typedef struct {
4046
  int32_t jid;
4047
  CowStr  ast;
4048
  int32_t sqlLen;
4049
  char*   sql;
4050
} SMDropXnodeJobReq;
4051
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4052
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
4053
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
4054

4055
typedef struct {
4056
  int32_t      sqlLen;
4057
  char*        sql;
4058
  CowStr       name;
4059
  CowStr       status;
4060
  xTaskOptions options;
4061
} SMCreateXnodeAgentReq;
4062
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4063
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4064
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
4065

4066
typedef struct {
4067
  int32_t      sqlLen;
4068
  char*        sql;
4069
  int32_t      id;
4070
  CowStr       name;
4071
  xTaskOptions options;
4072
} SMUpdateXnodeAgentReq;
4073
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4074
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4075
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
4076

4077
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4078
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4079
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4080
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4081

4082
typedef struct {
4083
  int32_t vgId;
4084
  int32_t hbSeq;
4085
} SVArbHbReqMember;
4086

4087
typedef struct {
4088
  int32_t dnodeId;
4089
  char*   arbToken;
4090
  int64_t arbTerm;
4091
  SArray* hbMembers;  // SVArbHbReqMember
4092
} SVArbHeartBeatReq;
4093

4094
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4095
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4096
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4097

4098
typedef struct {
4099
  int32_t vgId;
4100
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4101
  int32_t hbSeq;
4102
} SVArbHbRspMember;
4103

4104
typedef struct {
4105
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4106
  int32_t dnodeId;
4107
  SArray* hbMembers;  // SVArbHbRspMember
4108
} SVArbHeartBeatRsp;
4109

4110
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4111
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4112
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4113

4114
typedef struct {
4115
  char*   arbToken;
4116
  int64_t arbTerm;
4117
  char*   member0Token;
4118
  char*   member1Token;
4119
} SVArbCheckSyncReq;
4120

4121
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4122
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4123
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4124

4125
typedef struct {
4126
  char*   arbToken;
4127
  char*   member0Token;
4128
  char*   member1Token;
4129
  int32_t vgId;
4130
  int32_t errCode;
4131
} SVArbCheckSyncRsp;
4132

4133
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4134
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4135
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4136

4137
typedef struct {
4138
  char*   arbToken;
4139
  int64_t arbTerm;
4140
  char*   memberToken;
4141
  int8_t  force;
4142
} SVArbSetAssignedLeaderReq;
4143

4144
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4145
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4146
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4147

4148
typedef struct {
4149
  char* data;
4150
} SVAuditRecordReq;
4151
int32_t tSerializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4152
int32_t tDeserializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4153
void    tFreeSVAuditRecordReq(SVAuditRecordReq* pReq);
4154

4155
typedef struct {
4156
  char*   arbToken;
4157
  char*   memberToken;
4158
  int32_t vgId;
4159
} SVArbSetAssignedLeaderRsp;
4160

4161
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4162
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4163
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4164

4165
typedef struct {
4166
  int32_t dnodeId;
4167
  char*   token;
4168
} SMArbUpdateGroupMember;
4169

4170
typedef struct {
4171
  int32_t dnodeId;
4172
  char*   token;
4173
  int8_t  acked;
4174
} SMArbUpdateGroupAssigned;
4175

4176
typedef struct {
4177
  int32_t                  vgId;
4178
  int64_t                  dbUid;
4179
  SMArbUpdateGroupMember   members[2];
4180
  int8_t                   isSync;
4181
  int8_t                   assignedAcked;
4182
  SMArbUpdateGroupAssigned assignedLeader;
4183
  int64_t                  version;
4184
  int32_t                  code;
4185
  int64_t                  updateTimeMs;
4186
} SMArbUpdateGroup;
4187

4188
typedef struct {
4189
  SArray* updateArray;  // SMArbUpdateGroup
4190
} SMArbUpdateGroupBatchReq;
4191

4192
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4193
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4194
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4195

4196
typedef struct {
4197
  char queryStrId[TSDB_QUERY_ID_LEN];
4198
} SKillQueryReq;
4199

4200
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4201
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4202

4203
typedef struct {
4204
  uint32_t connId;
4205
} SKillConnReq;
4206

4207
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4208
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4209

4210
typedef struct {
4211
  int32_t transId;
4212
} SKillTransReq;
4213

4214
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4215
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4216

4217
typedef struct {
4218
  int32_t useless;  // useless
4219
  int32_t sqlLen;
4220
  char*   sql;
4221
} SBalanceVgroupReq;
4222

4223
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4224
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4225
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4226

4227
typedef struct {
4228
  int32_t useless;  // useless
4229
  int32_t sqlLen;
4230
  char*   sql;
4231
} SAssignLeaderReq;
4232

4233
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4234
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4235
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4236
typedef struct {
4237
  int32_t vgId1;
4238
  int32_t vgId2;
4239
} SMergeVgroupReq;
4240

4241
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4242
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4243

4244
typedef struct {
4245
  int32_t vgId;
4246
  int32_t dnodeId1;
4247
  int32_t dnodeId2;
4248
  int32_t dnodeId3;
4249
  int32_t sqlLen;
4250
  char*   sql;
4251
} SRedistributeVgroupReq;
4252

4253
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4254
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4255
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4256

4257
typedef struct {
4258
  int32_t reserved;
4259
  int32_t vgId;
4260
  int32_t sqlLen;
4261
  char*   sql;
4262
  char    db[TSDB_DB_FNAME_LEN];
4263
} SBalanceVgroupLeaderReq;
4264

4265
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4266
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4267
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4268

4269
typedef struct {
4270
  int32_t vgId;
4271
} SForceBecomeFollowerReq;
4272

4273
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4274
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4275

4276
typedef struct {
4277
  int32_t vgId;
4278
  bool    force;
4279
} SSplitVgroupReq;
4280

4281
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4282
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4283

4284
typedef struct {
4285
  char user[TSDB_USER_LEN];
4286
  char spi;
4287
  char encrypt;
4288
  char secret[TSDB_PASSWORD_LEN];
4289
  char ckey[TSDB_PASSWORD_LEN];
4290
} SAuthReq, SAuthRsp;
4291

4292
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4293
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4294

4295
typedef struct {
4296
  int32_t statusCode;
4297
  char    details[1024];
4298
} SServerStatusRsp;
4299

4300
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4301
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4302

4303
/**
4304
 * The layout of the query message payload is as following:
4305
 * +--------------------+---------------------------------+
4306
 * |Sql statement       | Physical plan                   |
4307
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4308
 * +--------------------+---------------------------------+
4309
 */
4310
typedef struct SSubQueryMsg {
4311
  SMsgHead header;
4312
  uint64_t sId;
4313
  uint64_t queryId;
4314
  uint64_t clientId;
4315
  uint64_t taskId;
4316
  int64_t  refId;
4317
  int32_t  execId;
4318
  int32_t  msgMask;
4319
  int32_t  subQType;
4320
  int8_t   taskType;
4321
  int8_t   explain;
4322
  int8_t   needFetch;
4323
  int8_t   compress;
4324
  uint32_t sqlLen;
4325
  char*    sql;
4326
  uint32_t msgLen;
4327
  char*    msg;
4328
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4329
} SSubQueryMsg;
4330

4331
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4332
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4333
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4334

4335
typedef struct {
4336
  SMsgHead header;
4337
  uint64_t sId;
4338
  uint64_t queryId;
4339
  uint64_t taskId;
4340
} SSinkDataReq;
4341

4342
typedef struct {
4343
  SMsgHead header;
4344
  uint64_t sId;
4345
  uint64_t queryId;
4346
  uint64_t clientId;
4347
  uint64_t taskId;
4348
  int32_t  execId;
4349
} SQueryContinueReq;
4350

4351
typedef struct {
4352
  SMsgHead header;
4353
  uint64_t sId;
4354
  uint64_t queryId;
4355
  uint64_t taskId;
4356
} SResReadyReq;
4357

4358
typedef struct {
4359
  int32_t code;
4360
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4361
  int32_t sversion;
4362
  int32_t tversion;
4363
} SResReadyRsp;
4364

4365
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4366

4367
typedef struct SOperatorParam {
4368
  int32_t opType;
4369
  int32_t downstreamIdx;
4370
  void*   value;
4371
  SArray* pChildren;  // SArray<SOperatorParam*>
4372
  bool    reUse;
4373
} SOperatorParam;
4374

4375
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4376

4377
// virtual table's colId to origin table's colname
4378
typedef struct SColIdNameKV {
4379
  col_id_t colId;
4380
  char     colName[TSDB_COL_NAME_LEN];
4381
} SColIdNameKV;
4382

4383
#define COL_MASK_ON   ((int8_t)0x1)
4384
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4385
#define COL_SET_MASK_ON(c)     \
4386
  do {                         \
4387
    (c)->flags |= COL_MASK_ON; \
4388
  } while (0)
4389

4390
typedef struct SColNameFlag {
4391
  col_id_t colId;
4392
  char     colName[TSDB_COL_NAME_LEN];
4393
  int8_t   flags;  // 0x01: COL_MASK_ON
4394
} SColNameFlag;
4395

4396
typedef struct SColIdPair {
4397
  col_id_t  vtbColId;
4398
  col_id_t  orgColId;
4399
  SDataType type;
4400
} SColIdPair;
4401

4402
typedef struct SColIdSlotIdPair {
4403
  int32_t  vtbSlotId;
4404
  col_id_t orgColId;
4405
} SColIdSlotIdPair;
4406

4407
typedef struct SOrgTbInfo {
4408
  int32_t vgId;
4409
  char    tbName[TSDB_TABLE_FNAME_LEN];
4410
  SArray* colMap;  // SArray<SColIdNameKV>
4411
} SOrgTbInfo;
4412

4413
void destroySOrgTbInfo(void *info);
4414

4415
typedef enum {
4416
  DYN_TYPE_STB_JOIN = 1,
4417
  DYN_TYPE_VSTB_SINGLE_SCAN,
4418
  DYN_TYPE_VSTB_BATCH_SCAN,
4419
  DYN_TYPE_VSTB_WIN_SCAN,
4420
} ETableScanDynType;
4421

4422
typedef enum {
4423
  DYN_TYPE_SCAN_PARAM = 1,
4424
  NOTIFY_TYPE_SCAN_PARAM,
4425
} ETableScanGetParamType;
4426

4427
typedef struct STableScanOperatorParam {
4428
  ETableScanGetParamType paramType;
4429
  /* for building scan data source */
4430
  bool                   tableSeq;
4431
  bool                   isNewParam;
4432
  uint64_t               groupid;
4433
  SArray*                pUidList;
4434
  SOrgTbInfo*            pOrgTbInfo;
4435
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4436
  SArray*                pTagList;
4437
  STimeWindow            window;
4438
  ETableScanDynType      dynType;
4439
  /* for notifying source step done */
4440
  bool                   notifyToProcess;  // received notify STEP DONE message
4441
  TSKEY                  notifyTs;         // notify timestamp
4442
} STableScanOperatorParam;
4443

4444
typedef struct STagScanOperatorParam {
4445
  tb_uid_t vcUid;
4446
} STagScanOperatorParam;
4447

4448
typedef struct SRefColIdGroup {
4449
  SArray* pSlotIdList;  // SArray<int32_t>
4450
} SRefColIdGroup;
4451

4452
typedef struct SVTableScanOperatorParam {
4453
  uint64_t        uid;
4454
  STimeWindow     window;
4455
  SOperatorParam* pTagScanOp;
4456
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4457
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4458
} SVTableScanOperatorParam;
4459

4460
typedef struct SMergeOperatorParam {
4461
  int32_t         winNum;
4462
} SMergeOperatorParam;
4463

4464
typedef struct SAggOperatorParam {
4465
  bool            needCleanRes;
4466
} SAggOperatorParam;
4467

4468
typedef struct SExternalWindowOperatorParam {
4469
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4470
} SExternalWindowOperatorParam;
4471

4472
typedef struct SDynQueryCtrlOperatorParam {
4473
  STimeWindow    window;
4474
} SDynQueryCtrlOperatorParam;
4475

4476
struct SStreamRuntimeFuncInfo;
4477
typedef struct {
4478
  SMsgHead        header;
4479
  uint64_t        sId;
4480
  uint64_t        queryId;
4481
  uint64_t        clientId;
4482
  uint64_t        taskId;
4483
  uint64_t        srcTaskId;  // used for subQ
4484
  uint64_t        blockIdx;   // used for subQ
4485
  int32_t         execId;
4486
  SOperatorParam* pOpParam;
4487

4488
  // used for new-stream
4489
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4490
  bool                           reset;
4491
  bool                           dynTbname;
4492
  // used for new-stream
4493
} SResFetchReq;
4494

4495
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4496
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4497
void    tDestroySResFetchReq(SResFetchReq* pReq);
4498
typedef struct {
4499
  SMsgHead header;
4500
  uint64_t clientId;
4501
} SSchTasksStatusReq;
4502

4503
typedef struct {
4504
  uint64_t queryId;
4505
  uint64_t clientId;
4506
  uint64_t taskId;
4507
  int64_t  refId;
4508
  int32_t  subJobId;
4509
  int32_t  execId;
4510
  int8_t   status;
4511
} STaskStatus;
4512

4513
typedef struct {
4514
  int64_t refId;
4515
  SArray* taskStatus;  // SArray<STaskStatus>
4516
} SSchedulerStatusRsp;
4517

4518
typedef struct {
4519
  uint64_t queryId;
4520
  uint64_t taskId;
4521
  int8_t   action;
4522
} STaskAction;
4523

4524
typedef struct SQueryNodeEpId {
4525
  int32_t nodeId;  // vgId or qnodeId
4526
  SEp     ep;
4527
} SQueryNodeEpId;
4528

4529
typedef struct {
4530
  SMsgHead       header;
4531
  uint64_t       clientId;
4532
  SQueryNodeEpId epId;
4533
  SArray*        taskAction;  // SArray<STaskAction>
4534
} SSchedulerHbReq;
4535

4536
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4537
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4538
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4539

4540
typedef struct {
4541
  SQueryNodeEpId epId;
4542
  SArray*        taskStatus;  // SArray<STaskStatus>
4543
} SSchedulerHbRsp;
4544

4545
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4546
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4547
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4548

4549
typedef struct {
4550
  SMsgHead header;
4551
  uint64_t sId;
4552
  uint64_t queryId;
4553
  uint64_t clientId;
4554
  uint64_t taskId;
4555
  int64_t  refId;
4556
  int32_t  execId;
4557
} STaskCancelReq;
4558

4559
typedef struct {
4560
  int32_t code;
4561
} STaskCancelRsp;
4562

4563
typedef struct {
4564
  SMsgHead header;
4565
  uint64_t sId;
4566
  uint64_t queryId;
4567
  uint64_t clientId;
4568
  uint64_t taskId;
4569
  int64_t  refId;
4570
  int32_t  execId;
4571
} STaskDropReq;
4572

4573
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4574
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4575

4576
typedef enum {
4577
  TASK_NOTIFY_FINISHED = 1,
4578
} ETaskNotifyType;
4579

4580
typedef struct {
4581
  SMsgHead        header;
4582
  uint64_t        sId;
4583
  uint64_t        queryId;
4584
  uint64_t        clientId;
4585
  uint64_t        taskId;
4586
  int64_t         refId;
4587
  int32_t         execId;
4588
  ETaskNotifyType type;
4589
} STaskNotifyReq;
4590

4591
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4592
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4593

4594
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4595
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4596

4597
typedef struct {
4598
  int32_t code;
4599
} STaskDropRsp;
4600

4601
#define STREAM_TRIGGER_AT_ONCE                 1
4602
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4603
#define STREAM_TRIGGER_MAX_DELAY               3
4604
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4605
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4606

4607
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4608
#define STREAM_FILL_HISTORY_ON        1
4609
#define STREAM_FILL_HISTORY_OFF       0
4610
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4611
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4612
#define STREAM_CREATE_STABLE_TRUE     1
4613
#define STREAM_CREATE_STABLE_FALSE    0
4614

4615
typedef struct SVgroupVer {
4616
  int32_t vgId;
4617
  int64_t ver;
4618
} SVgroupVer;
4619

4620
enum {
4621
  TOPIC_SUB_TYPE__DB = 1,
4622
  TOPIC_SUB_TYPE__TABLE,
4623
  TOPIC_SUB_TYPE__COLUMN,
4624
};
4625

4626
#define DEFAULT_MAX_POLL_INTERVAL  300000
4627
#define DEFAULT_SESSION_TIMEOUT    12000
4628
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4629
#define DEFAULT_MIN_POLL_ROWS      4096
4630

4631
typedef struct {
4632
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4633
  int8_t igExists;
4634
  int8_t subType;
4635
  int8_t withMeta;
4636
  char*  sql;
4637
  char   subDbName[TSDB_DB_FNAME_LEN];
4638
  char*  ast;
4639
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4640
  int8_t reload;
4641
} SCMCreateTopicReq;
4642

4643
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4644
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4645
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4646

4647
typedef struct {
4648
  int64_t consumerId;
4649
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4650

4651
typedef struct {
4652
  int64_t consumerId;
4653
  char    cgroup[TSDB_CGROUP_LEN];
4654
  char    clientId[TSDB_CLIENT_ID_LEN];
4655
  char    user[TSDB_USER_LEN];
4656
  char    fqdn[TSDB_FQDN_LEN];
4657
  SArray* topicNames;  // SArray<char**>
4658

4659
  int8_t  withTbName;
4660
  int8_t  autoCommit;
4661
  int32_t autoCommitInterval;
4662
  int8_t  resetOffsetCfg;
4663
  int8_t  enableReplay;
4664
  int8_t  enableBatchMeta;
4665
  int32_t sessionTimeoutMs;
4666
  int32_t maxPollIntervalMs;
4667
  int64_t ownerId;
4668
} SCMSubscribeReq;
4669

4670
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4671
  int32_t tlen = 0;
673,068✔
4672
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
673,068✔
4673
  tlen += taosEncodeString(buf, pReq->cgroup);
672,729✔
4674
  tlen += taosEncodeString(buf, pReq->clientId);
672,729✔
4675

4676
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
672,729✔
4677
  tlen += taosEncodeFixedI32(buf, topicNum);
672,729✔
4678

4679
  for (int32_t i = 0; i < topicNum; i++) {
935,515✔
4680
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
525,572✔
4681
  }
4682

4683
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
672,729✔
4684
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
672,729✔
4685
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
673,068✔
4686
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
672,729✔
4687
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
672,377✔
4688
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
672,729✔
4689
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
672,729✔
4690
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
673,068✔
4691
  tlen += taosEncodeString(buf, pReq->user);
672,390✔
4692
  tlen += taosEncodeString(buf, pReq->fqdn);
672,729✔
4693

4694
  return tlen;
673,068✔
4695
}
4696

4697
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4698
  void* start = buf;
355,055✔
4699
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
355,055✔
4700
  buf = taosDecodeStringTo(buf, pReq->cgroup);
355,055✔
4701
  buf = taosDecodeStringTo(buf, pReq->clientId);
355,055✔
4702

4703
  int32_t topicNum = 0;
355,055✔
4704
  buf = taosDecodeFixedI32(buf, &topicNum);
355,055✔
4705

4706
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
355,055✔
4707
  if (pReq->topicNames == NULL) {
355,055✔
4708
    return terrno;
×
4709
  }
4710
  for (int32_t i = 0; i < topicNum; i++) {
515,911✔
4711
    char* name = NULL;
160,856✔
4712
    buf = taosDecodeString(buf, &name);
160,856✔
4713
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
321,712✔
4714
      return terrno;
×
4715
    }
4716
  }
4717

4718
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
355,055✔
4719
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
355,055✔
4720
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
355,055✔
4721
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
355,055✔
4722
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
355,055✔
4723
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
355,055✔
4724
  if ((char*)buf - (char*)start < len) {
355,055✔
4725
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
355,055✔
4726
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
355,055✔
4727
    buf = taosDecodeStringTo(buf, pReq->user);
355,055✔
4728
    buf = taosDecodeStringTo(buf, pReq->fqdn);
710,110✔
4729
  } else {
4730
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
4731
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4732
  }
4733

4734
  return 0;
355,055✔
4735
}
4736

4737
typedef struct {
4738
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4739
  SArray* removedConsumers;  // SArray<int64_t>
4740
  SArray* newConsumers;      // SArray<int64_t>
4741
} SMqRebInfo;
4742

4743
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4744
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
319,144✔
4745
  if (pRebInfo == NULL) {
319,144✔
4746
    return NULL;
×
4747
  }
4748
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
319,144✔
4749
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
319,144✔
4750
  if (pRebInfo->removedConsumers == NULL) {
319,144✔
4751
    goto _err;
×
4752
  }
4753
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
319,144✔
4754
  if (pRebInfo->newConsumers == NULL) {
319,144✔
4755
    goto _err;
×
4756
  }
4757
  return pRebInfo;
319,144✔
4758
_err:
×
4759
  taosArrayDestroy(pRebInfo->removedConsumers);
×
4760
  taosArrayDestroy(pRebInfo->newConsumers);
×
4761
  taosMemoryFreeClear(pRebInfo);
×
4762
  return NULL;
×
4763
}
4764

4765
typedef struct {
4766
  int64_t streamId;
4767
  int64_t checkpointId;
4768
  char    streamName[TSDB_STREAM_FNAME_LEN];
4769
} SMStreamDoCheckpointMsg;
4770

4771
typedef struct {
4772
  int64_t status;
4773
} SMVSubscribeRsp;
4774

4775
typedef struct {
4776
  char    name[TSDB_TOPIC_FNAME_LEN];
4777
  int8_t  igNotExists;
4778
  int32_t sqlLen;
4779
  char*   sql;
4780
  int8_t  force;
4781
} SMDropTopicReq;
4782

4783
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4784
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4785
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4786

4787
typedef struct {
4788
  char    name[TSDB_TOPIC_FNAME_LEN];
4789
  int8_t  igNotExists;
4790
  int32_t sqlLen;
4791
  char*   sql;
4792
} SMReloadTopicReq;
4793

4794
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4795
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4796
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4797

4798
typedef struct {
4799
  char   topic[TSDB_TOPIC_FNAME_LEN];
4800
  char   cgroup[TSDB_CGROUP_LEN];
4801
  int8_t igNotExists;
4802
  int8_t force;
4803
} SMDropCgroupReq;
4804

4805
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4806
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4807

4808
typedef struct {
4809
  int8_t reserved;
4810
} SMDropCgroupRsp;
4811

4812
typedef struct {
4813
  char    name[TSDB_TABLE_FNAME_LEN];
4814
  int8_t  alterType;
4815
  SSchema schema;
4816
} SAlterTopicReq;
4817

4818
typedef struct {
4819
  SMsgHead head;
4820
  char     name[TSDB_TABLE_FNAME_LEN];
4821
  int64_t  tuid;
4822
  int32_t  sverson;
4823
  int32_t  execLen;
4824
  char*    executor;
4825
  int32_t  sqlLen;
4826
  char*    sql;
4827
} SDCreateTopicReq;
4828

4829
typedef struct {
4830
  SMsgHead head;
4831
  char     name[TSDB_TABLE_FNAME_LEN];
4832
  int64_t  tuid;
4833
} SDDropTopicReq;
4834

4835
typedef struct {
4836
  char*      name;
4837
  int64_t    uid;
4838
  int64_t    interval[2];
4839
  int8_t     intervalUnit;
4840
  int16_t    nFuncs;
4841
  col_id_t*  funcColIds;  // column ids specified by user
4842
  func_id_t* funcIds;     // function ids specified by user
4843
} SRSmaParam;
4844

4845
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4846
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4847

4848
// TDMT_VND_CREATE_STB ==============
4849
typedef struct SVCreateStbReq {
4850
  char*           name;
4851
  tb_uid_t        suid;
4852
  int8_t          rollup;
4853
  SSchemaWrapper  schemaRow;
4854
  SSchemaWrapper  schemaTag;
4855
  SRSmaParam      rsmaParam;
4856
  int32_t         alterOriDataLen;
4857
  void*           alterOriData;
4858
  int8_t          source;
4859
  int8_t          colCmpred;
4860
  SColCmprWrapper colCmpr;
4861
  int64_t         keep;
4862
  int64_t         ownerId;
4863
  SExtSchema*     pExtSchemas;
4864
  int8_t          virtualStb;
4865
  int8_t          secureDelete;
4866
} SVCreateStbReq;
4867

4868
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4869
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4870

4871
// TDMT_VND_DROP_STB ==============
4872
typedef struct SVDropStbReq {
4873
  char*    name;
4874
  tb_uid_t suid;
4875
} SVDropStbReq;
4876

4877
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4878
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4879

4880
// TDMT_VND_CREATE_TABLE ==============
4881
#define TD_CREATE_IF_NOT_EXISTS       0x1
4882
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4883
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4884
typedef struct SVCreateTbReq {
4885
  int32_t  flags;
4886
  char*    name;
4887
  tb_uid_t uid;
4888
  int64_t  btime;
4889
  int32_t  ttl;
4890
  int32_t  commentLen;
4891
  char*    comment;
4892
  int8_t   type;
4893
  union {
4894
    struct {
4895
      char*    stbName;  // super table name
4896
      uint8_t  tagNum;
4897
      tb_uid_t suid;
4898
      SArray*  tagName;
4899
      uint8_t* pTag;
4900
    } ctb;
4901
    struct {
4902
      SSchemaWrapper schemaRow;
4903
      int64_t        userId;
4904
    } ntb;
4905
  };
4906
  int32_t         sqlLen;
4907
  char*           sql;
4908
  SColCmprWrapper colCmpr;
4909
  SExtSchema*     pExtSchemas;
4910
  SColRefWrapper  colRef;  // col reference for virtual table
4911
} SVCreateTbReq;
4912

4913
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4914
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4915
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4916
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4917

4918
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4919
  if (NULL == req) {
2,147,483,647✔
4920
    return;
2,147,483,647✔
4921
  }
4922

4923
  taosMemoryFreeClear(req->sql);
81,948,727✔
4924
  taosMemoryFreeClear(req->name);
81,943,510✔
4925
  taosMemoryFreeClear(req->comment);
81,957,926✔
4926
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
81,943,053✔
4927
    taosMemoryFreeClear(req->ctb.pTag);
74,477,041✔
4928
    taosMemoryFreeClear(req->ctb.stbName);
74,426,824✔
4929
    taosArrayDestroy(req->ctb.tagName);
74,506,108✔
4930
    req->ctb.tagName = NULL;
74,427,965✔
4931
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
7,471,857✔
4932
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
7,472,083✔
4933
  }
4934
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
81,913,127✔
4935
  taosMemoryFreeClear(req->pExtSchemas);
81,940,589✔
4936
  taosMemoryFreeClear(req->colRef.pColRef);
81,952,014✔
4937
  taosMemoryFreeClear(req->colRef.pTagRef);
81,950,867✔
4938
}
4939

4940
typedef struct {
4941
  int32_t nReqs;
4942
  union {
4943
    SVCreateTbReq* pReqs;
4944
    SArray*        pArray;
4945
  };
4946
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4947
} SVCreateTbBatchReq;
4948

4949
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4950
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4951
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4952

4953
typedef struct {
4954
  int32_t        code;
4955
  STableMetaRsp* pMeta;
4956
} SVCreateTbRsp, SVUpdateTbRsp;
4957

4958
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4959
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4960
void tFreeSVCreateTbRsp(void* param);
4961

4962
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4963
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4964

4965
typedef struct {
4966
  int32_t nRsps;
4967
  union {
4968
    SVCreateTbRsp* pRsps;
4969
    SArray*        pArray;
4970
  };
4971
} SVCreateTbBatchRsp;
4972

4973
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4974
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4975

4976
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4977
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4978

4979
// TDMT_VND_DROP_TABLE =================
4980
typedef struct {
4981
  char*    name;
4982
  uint64_t suid;  // for tmq in wal format
4983
  int64_t  uid;
4984
  int8_t   igNotExists;
4985
  int8_t   isVirtual;
4986
} SVDropTbReq;
4987

4988
typedef struct {
4989
  int32_t code;
4990
} SVDropTbRsp;
4991

4992
typedef struct {
4993
  int32_t nReqs;
4994
  union {
4995
    SVDropTbReq* pReqs;
4996
    SArray*      pArray;
4997
  };
4998
} SVDropTbBatchReq;
4999

5000
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
5001
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
5002

5003
typedef struct {
5004
  int32_t nRsps;
5005
  union {
5006
    SVDropTbRsp* pRsps;
5007
    SArray*      pArray;
5008
  };
5009
} SVDropTbBatchRsp;
5010

5011
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
5012
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
5013

5014
// TDMT_VND_ALTER_TABLE =====================
5015
typedef struct SUpdatedTagVal {
5016
  char*    tagName;
5017
  int32_t  colId;
5018
  int8_t   tagType;
5019
  int8_t   tagFree;
5020
  uint32_t nTagVal;
5021
  uint8_t* pTagVal;
5022
  int8_t   isNull;
5023
  SArray*  pTagArray;
5024
  // NOTE: regexp and replacement are only a temporary solution for tag value update,
5025
  // they should be replaced by a more generic solution in the future for full expression
5026
  // support
5027
  char*    regexp;
5028
  char*    replacement;
5029
} SUpdatedTagVal;
5030

5031
typedef struct SUpdateTableTagVal {
5032
  char *tbName;
5033
  SArray* tags; // Array of SUpdatedTagVal
5034
} SUpdateTableTagVal;
5035

5036
typedef struct SVAlterTbReq {
5037
  char*   tbName;
5038
  int8_t  action;
5039
  char*   colName;
5040
  int32_t colId;
5041
  // TSDB_ALTER_TABLE_ADD_COLUMN
5042
  int8_t  type;
5043
  int8_t  flags;
5044
  int32_t bytes;
5045
  // TSDB_ALTER_TABLE_DROP_COLUMN
5046
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
5047
  int8_t   colModType;
5048
  int32_t  colModBytes;
5049
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
5050
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
5051
  int8_t   isNull;
5052
  int8_t   tagType;
5053
  int8_t   tagFree;
5054
  uint32_t nTagVal;
5055
  uint8_t* pTagVal;
5056
  SArray*  pTagArray;
5057
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
5058
  int8_t   updateTTL;
5059
  int32_t  newTTL;
5060
  int32_t  newCommentLen;
5061
  char*    newComment;
5062
  int64_t  ctimeMs;    // fill by vnode
5063
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
5064
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
5065
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS and TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL
5066
  SArray*  tables;     // Array of SUpdateTableTagVal, for TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL
5067
  int32_t  whereLen;   // [whereLen] & [where] are for TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL,
5068
  uint8_t* where;      // [where] is the encode where condition.
5069
  // for Add column
5070
  STypeMod typeMod;
5071
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
5072
  char* refDbName;
5073
  char* refTbName;
5074
  char* refColName;
5075
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
5076
} SVAlterTbReq;
5077

5078
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
5079
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
5080
void    destroyAlterTbReq(SVAlterTbReq* pReq);
5081
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
5082
void    tfreeMultiTagUpateVal(void* pMultiTag);
5083
void    tfreeUpdateTableTagVal(void* pMultiTable);
5084

5085
typedef struct {
5086
  int32_t        code;
5087
  STableMetaRsp* pMeta;
5088
} SVAlterTbRsp;
5089

5090
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
5091
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
5092
// ======================
5093

5094
typedef struct {
5095
  SMsgHead head;
5096
  int64_t  uid;
5097
  int32_t  tid;
5098
  int16_t  tversion;
5099
  int16_t  colId;
5100
  int8_t   type;
5101
  int16_t  bytes;
5102
  int32_t  tagValLen;
5103
  int16_t  numOfTags;
5104
  int32_t  schemaLen;
5105
  char     data[];
5106
} SUpdateTagValReq;
5107

5108
typedef struct {
5109
  SMsgHead head;
5110
} SUpdateTagValRsp;
5111

5112
typedef struct {
5113
  SMsgHead head;
5114
} SVShowTablesReq;
5115

5116
typedef struct {
5117
  SMsgHead head;
5118
  int32_t  id;
5119
} SVShowTablesFetchReq;
5120

5121
typedef struct {
5122
  int64_t useconds;
5123
  int8_t  completed;  // all results are returned to client
5124
  int8_t  precision;
5125
  int8_t  compressed;
5126
  int32_t compLen;
5127
  int32_t numOfRows;
5128
  char    data[];
5129
} SVShowTablesFetchRsp;
5130

5131
typedef struct {
5132
  int64_t consumerId;
5133
  int32_t epoch;
5134
  char    cgroup[TSDB_CGROUP_LEN];
5135
} SMqAskEpReq;
5136

5137
typedef struct {
5138
  int32_t key;
5139
  int32_t valueLen;
5140
  void*   value;
5141
} SKv;
5142

5143
typedef struct {
5144
  int64_t tscRid;
5145
  int8_t  connType;
5146
} SClientHbKey;
5147

5148
typedef struct {
5149
  int64_t tid;
5150
  char    status[TSDB_JOB_STATUS_LEN];
5151
  int64_t startTs;  // sub-task first execution start time, us
5152
} SQuerySubDesc;
5153

5154
typedef enum EQueryExecPhase {
5155
  /* Main phases: 0-9 */
5156
  QUERY_PHASE_NONE     = 0,
5157
  QUERY_PHASE_PARSE    = 1,
5158
  QUERY_PHASE_CATALOG  = 2,
5159
  QUERY_PHASE_PLAN     = 3,
5160
  QUERY_PHASE_SCHEDULE = 4,
5161
  QUERY_PHASE_EXECUTE  = 5,
5162
  QUERY_PHASE_FETCH    = 6,
5163
  QUERY_PHASE_DONE     = 7,
5164

5165
  /* SCHEDULE sub-phases: 4x */
5166
  QUERY_PHASE_SCHEDULE_ANALYSIS       = 41,
5167
  QUERY_PHASE_SCHEDULE_PLANNING       = 42,
5168
  QUERY_PHASE_SCHEDULE_NODE_SELECTION = 43,
5169

5170
  /* EXECUTE sub-phases: 5x */
5171
  QUERY_PHASE_EXEC_DATA_QUERY       = 51,
5172
  QUERY_PHASE_EXEC_MERGE_QUERY      = 52,
5173
  QUERY_PHASE_EXEC_WAITING_CHILDREN = 53,
5174

5175
  /* FETCH sub-phases: 6x */
5176
  QUERY_PHASE_FETCH_IN_PROGRESS = 60,  // A single fetch operation is in progress
5177
  QUERY_PHASE_FETCH_RETURNED    = 61,  // Data returned to client, business logic processing
5178
} EQueryExecPhase;
5179

5180
const char* queryPhaseStr(int32_t phase);
5181

5182
typedef struct {
5183
  char     sql[TSDB_SHOW_SQL_LEN];
5184
  uint64_t queryId;
5185
  int64_t  useconds;
5186
  int64_t  stime;  // timestamp precision ms
5187
  int64_t  reqRid;
5188
  bool     stableQuery;
5189
  bool     isSubQuery;
5190
  char     fqdn[TSDB_FQDN_LEN];
5191
  int32_t  subPlanNum;
5192
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5193
  int32_t  execPhase;       // EQueryExecPhase
5194
  int64_t  phaseStartTime;  // when current phase started, ms
5195
} SQueryDesc;
5196

5197
typedef struct {
5198
  uint32_t connId;
5199
  SArray*  queryDesc;  // SArray<SQueryDesc>
5200
} SQueryHbReqBasic;
5201

5202
typedef struct {
5203
  uint32_t connId;
5204
  uint64_t killRid;
5205
  int32_t  totalDnodes;
5206
  int32_t  onlineDnodes;
5207
  int8_t   killConnection;
5208
  int8_t   align[3];
5209
  SEpSet   epSet;
5210
  SArray*  pQnodeList;
5211
} SQueryHbRspBasic;
5212

5213
typedef struct SAppClusterSummary {
5214
  uint64_t numOfInsertsReq;
5215
  uint64_t numOfInsertRows;
5216
  uint64_t insertElapsedTime;
5217
  uint64_t insertBytes;  // submit to tsdb since launched.
5218

5219
  uint64_t fetchBytes;
5220
  uint64_t numOfQueryReq;
5221
  uint64_t queryElapsedTime;
5222
  uint64_t numOfSlowQueries;
5223
  uint64_t totalRequests;
5224
  uint64_t currentRequests;  // the number of SRequestObj
5225
} SAppClusterSummary;
5226

5227
typedef struct {
5228
  int64_t            appId;
5229
  int32_t            pid;
5230
  char               name[TSDB_APP_NAME_LEN];
5231
  int64_t            startTime;
5232
  SAppClusterSummary summary;
5233
} SAppHbReq;
5234

5235
typedef struct {
5236
  SClientHbKey      connKey;
5237
  int64_t           clusterId;
5238
  SAppHbReq         app;
5239
  SQueryHbReqBasic* query;
5240
  SHashObj*         info;  // hash<Skv.key, Skv>
5241
  char              user[TSDB_USER_LEN];
5242
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5243
  char              userApp[TSDB_APP_NAME_LEN];
5244
  uint32_t          userIp;
5245
  SIpRange          userDualIp;
5246
  char              sVer[TSDB_VERSION_LEN];
5247
  char              cInfo[CONNECTOR_INFO_LEN];
5248
} SClientHbReq;
5249

5250
typedef struct {
5251
  int64_t reqId;
5252
  SArray* reqs;  // SArray<SClientHbReq>
5253
  int64_t ipWhiteListVer;
5254
} SClientHbBatchReq;
5255

5256
typedef struct {
5257
  SClientHbKey      connKey;
5258
  int32_t           status;
5259
  SQueryHbRspBasic* query;
5260
  SArray*           info;  // Array<Skv>
5261
} SClientHbRsp;
5262

5263
typedef struct {
5264
  int64_t       reqId;
5265
  int64_t       rspId;
5266
  int32_t       svrTimestamp;
5267
  SArray*       rsps;  // SArray<SClientHbRsp>
5268
  SMonitorParas monitorParas;
5269
  int8_t        enableAuditDelete;
5270
  int8_t        enableStrongPass;
5271
  int8_t        enableAuditSelect;
5272
  int8_t        enableAuditInsert;
5273
  int8_t        auditLevel;
5274
} SClientHbBatchRsp;
5275

5276
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
411,715,625✔
5277

5278
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5279
  void* pIter = taosHashIterate(info, NULL);
55,597,041✔
5280
  while (pIter != NULL) {
130,617,536✔
5281
    SKv* kv = (SKv*)pIter;
75,019,631✔
5282
    taosMemoryFreeClear(kv->value);
75,019,631✔
5283
    pIter = taosHashIterate(info, pIter);
75,019,067✔
5284
  }
5285
}
55,597,905✔
5286

5287
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
37,493,679✔
5288
  SQueryDesc* desc = (SQueryDesc*)pDesc;
37,493,679✔
5289
  if (desc->subDesc) {
37,493,679✔
5290
    taosArrayDestroy(desc->subDesc);
26,167,118✔
5291
    desc->subDesc = NULL;
26,166,202✔
5292
  }
5293
}
37,494,243✔
5294

5295
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
63,711,466✔
5296
  SClientHbReq* req = (SClientHbReq*)pReq;
149,274,613✔
5297
  if (req->query) {
149,274,613✔
5298
    if (req->query->queryDesc) {
63,710,204✔
5299
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
29,576,549✔
5300
    }
5301
    taosMemoryFreeClear(req->query);
63,711,136✔
5302
  }
5303

5304
  if (req->info) {
149,276,537✔
5305
    tFreeReqKvHash(req->info);
55,596,581✔
5306
    taosHashCleanup(req->info);
55,597,905✔
5307
    req->info = NULL;
55,597,577✔
5308
  }
5309
}
116,363,369✔
5310

5311
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5312
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5313

5314
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5315
  if (pReq == NULL) return;
27,026,448✔
5316
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
27,026,448✔
5317
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
27,026,448✔
5318
  taosMemoryFree(pReq);
27,026,448✔
5319
}
5320

5321
static FORCE_INLINE void tFreeClientKv(void* pKv) {
74,734,900✔
5322
  SKv* kv = (SKv*)pKv;
74,734,900✔
5323
  if (kv) {
74,734,900✔
5324
    taosMemoryFreeClear(kv->value);
74,734,900✔
5325
  }
5326
}
74,735,608✔
5327

5328
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
63,434,296✔
5329
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
63,434,296✔
5330
  if (rsp->query) {
63,434,296✔
5331
    taosArrayDestroy(rsp->query->pQnodeList);
63,425,930✔
5332
    taosMemoryFreeClear(rsp->query);
63,422,364✔
5333
  }
5334
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
63,438,562✔
5335
}
32,638,398✔
5336

5337
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5338
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
52,462,506✔
5339
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
52,462,506✔
5340
}
52,464,214✔
5341

5342
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5343
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5344
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5345

5346
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5347
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
309,694,080✔
5348
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
309,694,438✔
5349
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
309,694,645✔
5350
  return 0;
154,848,402✔
5351
}
5352

5353
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5354
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
154,281,263✔
5355
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
154,281,392✔
5356

5357
  if (pKv->valueLen < 0) {
77,140,727✔
5358
    return TSDB_CODE_INVALID_MSG;
×
5359
  }
5360

5361
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
77,139,599✔
5362
  if (pKv->value == NULL) {
77,140,128✔
5363
    return TSDB_CODE_OUT_OF_MEMORY;
×
5364
  }
5365
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
77,140,013✔
5366
  return 0;
77,140,799✔
5367
}
5368

5369
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5370
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
264,460,837✔
5371
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
264,454,105✔
5372
  return 0;
132,225,516✔
5373
}
5374

5375
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5376
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
131,671,172✔
5377
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
131,671,091✔
5378
  return 0;
65,836,251✔
5379
}
5380

5381
typedef struct {
5382
  int32_t vgId;
5383
  // TODO stas
5384
} SMqReportVgInfo;
5385

5386
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5387
  int32_t tlen = 0;
5388
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5389
  return tlen;
5390
}
5391

5392
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5393
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5394
  return buf;
5395
}
5396

5397
typedef struct {
5398
  int32_t epoch;
5399
  int64_t topicUid;
5400
  char    name[TSDB_TOPIC_FNAME_LEN];
5401
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5402
} SMqTopicInfo;
5403

5404
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5405
  int32_t tlen = 0;
5406
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5407
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5408
  tlen += taosEncodeString(buf, pTopicInfo->name);
5409
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5410
  tlen += taosEncodeFixedI32(buf, sz);
5411
  for (int32_t i = 0; i < sz; i++) {
5412
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5413
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5414
  }
5415
  return tlen;
5416
}
5417

5418
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5419
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5420
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5421
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5422
  int32_t sz;
5423
  buf = taosDecodeFixedI32(buf, &sz);
5424
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5425
    return NULL;
5426
  }
5427
  for (int32_t i = 0; i < sz; i++) {
5428
    SMqReportVgInfo vgInfo;
5429
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5430
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5431
      return NULL;
5432
    }
5433
  }
5434
  return buf;
5435
}
5436

5437
typedef struct {
5438
  int32_t status;  // ask hb endpoint
5439
  int32_t epoch;
5440
  int64_t consumerId;
5441
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5442
} SMqReportReq;
5443

5444
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5445
  int32_t tlen = 0;
5446
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5447
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5448
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5449
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5450
  tlen += taosEncodeFixedI32(buf, sz);
5451
  for (int32_t i = 0; i < sz; i++) {
5452
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5453
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5454
  }
5455
  return tlen;
5456
}
5457

5458
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5459
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5460
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5461
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5462
  int32_t sz;
5463
  buf = taosDecodeFixedI32(buf, &sz);
5464
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5465
    return NULL;
5466
  }
5467
  for (int32_t i = 0; i < sz; i++) {
5468
    SMqTopicInfo topicInfo;
5469
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5470
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5471
      return NULL;
5472
    }
5473
  }
5474
  return buf;
5475
}
5476

5477
typedef struct {
5478
  SMsgHead head;
5479
  int64_t  leftForVer;
5480
  int32_t  vgId;
5481
  int64_t  consumerId;
5482
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5483
} SMqVDeleteReq;
5484

5485
typedef struct {
5486
  int8_t reserved;
5487
} SMqVDeleteRsp;
5488

5489
typedef struct {
5490
  char**  name;
5491
  int32_t count;
5492
  int8_t  igNotExists;
5493
} SMDropStreamReq;
5494

5495
typedef struct {
5496
  int8_t reserved;
5497
} SMDropStreamRsp;
5498

5499
typedef struct {
5500
  SMsgHead head;
5501
  int64_t  resetRelHalt;  // reset related stream task halt status
5502
  int64_t  streamId;
5503
  int32_t  taskId;
5504
} SVDropStreamTaskReq;
5505

5506
typedef struct {
5507
  int8_t reserved;
5508
} SVDropStreamTaskRsp;
5509

5510
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5511
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5512
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5513

5514
typedef struct {
5515
  char*  name;
5516
  int8_t igNotExists;
5517
} SMPauseStreamReq;
5518

5519
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5520
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5521
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5522

5523
typedef struct {
5524
  char*  name;
5525
  int8_t igNotExists;
5526
  int8_t igUntreated;
5527
} SMResumeStreamReq;
5528

5529
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5530
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5531
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5532

5533
typedef struct {
5534
  char*       name;
5535
  int8_t      calcAll;
5536
  STimeWindow timeRange;
5537
} SMRecalcStreamReq;
5538

5539
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5540
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5541
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5542

5543
typedef struct SVndSetKeepVersionReq {
5544
  int64_t keepVersion;
5545
} SVndSetKeepVersionReq;
5546

5547
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5548
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5549

5550
typedef struct SVUpdateCheckpointInfoReq {
5551
  SMsgHead head;
5552
  int64_t  streamId;
5553
  int32_t  taskId;
5554
  int64_t  checkpointId;
5555
  int64_t  checkpointVer;
5556
  int64_t  checkpointTs;
5557
  int32_t  transId;
5558
  int64_t  hStreamId;  // add encode/decode
5559
  int64_t  hTaskId;
5560
  int8_t   dropRelHTask;
5561
} SVUpdateCheckpointInfoReq;
5562

5563
typedef struct {
5564
  int64_t        leftForVer;
5565
  int32_t        vgId;
5566
  int64_t        oldConsumerId;
5567
  int64_t        newConsumerId;
5568
  char           subKey[TSDB_SUBSCRIBE_KEY_LEN];
5569
  int8_t         subType;
5570
  int8_t         withMeta;
5571
  char*          qmsg;  // SubPlanToString
5572
  SSchemaWrapper schema;
5573
  int64_t        suid;
5574
} SMqRebVgReq;
5575

5576
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5577
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5578

5579
// tqOffset
5580
enum {
5581
  TMQ_OFFSET__RESET_NONE = -3,
5582
  TMQ_OFFSET__RESET_EARLIEST = -2,
5583
  TMQ_OFFSET__RESET_LATEST = -1,
5584
  TMQ_OFFSET__LOG = 1,
5585
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5586
  TMQ_OFFSET__SNAPSHOT_META = 3,
5587
};
5588

5589
enum {
5590
  WITH_DATA = 0,
5591
  WITH_META = 1,
5592
  ONLY_META = 2,
5593
};
5594

5595
#define TQ_OFFSET_VERSION 1
5596

5597
typedef struct {
5598
  int8_t type;
5599
  union {
5600
    // snapshot
5601
    struct {
5602
      int64_t uid;
5603
      int64_t ts;
5604
      SValue  primaryKey;
5605
    };
5606
    // log
5607
    struct {
5608
      int64_t version;
5609
    };
5610
  };
5611
} STqOffsetVal;
5612

5613
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5614
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
8,141,583✔
5615
  pOffsetVal->uid = uid;
8,140,585✔
5616
  pOffsetVal->ts = ts;
8,140,231✔
5617
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
8,140,585✔
5618
    taosMemoryFree(pOffsetVal->primaryKey.pData);
311✔
5619
  }
5620
  pOffsetVal->primaryKey = primaryKey;
8,140,228✔
5621
}
8,140,944✔
5622

5623
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5624
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
12,284✔
5625
  pOffsetVal->uid = uid;
12,284✔
5626
}
12,284✔
5627

5628
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5629
  pOffsetVal->type = TMQ_OFFSET__LOG;
15,425,281✔
5630
  pOffsetVal->version = ver;
15,427,392✔
5631
}
15,425,162✔
5632

5633
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5634
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5635
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5636
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5637
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5638
void    tOffsetDestroy(void* pVal);
5639

5640
typedef struct {
5641
  STqOffsetVal val;
5642
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5643
} STqOffset;
5644

5645
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5646
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5647
void    tDeleteSTqOffset(void* val);
5648

5649
typedef struct SMqVgOffset {
5650
  int64_t   consumerId;
5651
  STqOffset offset;
5652
} SMqVgOffset;
5653

5654
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5655
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5656

5657
typedef struct {
5658
  char    name[TSDB_TABLE_FNAME_LEN];
5659
  char    stb[TSDB_TABLE_FNAME_LEN];
5660
  int8_t  igExists;
5661
  int8_t  intervalUnit;
5662
  int8_t  slidingUnit;
5663
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5664
  int32_t dstVgId;   // for stream
5665
  int64_t interval;
5666
  int64_t offset;
5667
  int64_t sliding;
5668
  int64_t maxDelay;
5669
  int64_t watermark;
5670
  int32_t exprLen;        // strlen + 1
5671
  int32_t tagsFilterLen;  // strlen + 1
5672
  int32_t sqlLen;         // strlen + 1
5673
  int32_t astLen;         // strlen + 1
5674
  char*   expr;
5675
  char*   tagsFilter;
5676
  char*   sql;
5677
  char*   ast;
5678
  int64_t deleteMark;
5679
  int64_t lastTs;
5680
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5681
  SArray* pVgroupVerList;
5682
  int8_t  recursiveTsma;
5683
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5684
  char*   createStreamReq;
5685
  int32_t streamReqLen;
5686
  char*   dropStreamReq;
5687
  int32_t dropStreamReqLen;
5688
  int64_t uid;
5689
} SMCreateSmaReq;
5690

5691
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5692
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5693
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5694

5695
typedef struct {
5696
  char    name[TSDB_TABLE_FNAME_LEN];
5697
  int8_t  igNotExists;
5698
  char*   dropStreamReq;
5699
  int32_t dropStreamReqLen;
5700
} SMDropSmaReq;
5701

5702
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5703
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5704
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5705

5706
typedef struct {
5707
  char name[TSDB_TABLE_NAME_LEN];
5708
  union {
5709
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5710
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5711
  };
5712
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5713
  union {
5714
    int8_t igExists;   // used by mnode
5715
    int8_t alterType;  // used by vnode
5716
  };
5717
  int8_t     intervalUnit;
5718
  int16_t    nFuncs;       // number of functions specified by user
5719
  col_id_t*  funcColIds;   // column ids specified by user
5720
  func_id_t* funcIds;      // function ids specified by user
5721
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5722
  int64_t    tbUid;
5723
  int64_t    uid;     // rsma uid
5724
  int32_t    sqlLen;  // strlen + 1
5725
  char*      sql;
5726
} SMCreateRsmaReq;
5727

5728
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5729
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5730
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5731

5732
typedef SMCreateRsmaReq SVCreateRsmaReq;
5733

5734
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5735
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5736
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5737

5738
typedef SMCreateRsmaReq SVAlterRsmaReq;
5739

5740
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5741
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5742
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5743

5744
typedef struct {
5745
  char       name[TSDB_TABLE_NAME_LEN];
5746
  int8_t     alterType;
5747
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5748
  int8_t     igNotExists;
5749
  int16_t    nFuncs;      // number of functions specified by user
5750
  col_id_t*  funcColIds;  // column ids specified by user
5751
  func_id_t* funcIds;     // function ids specified by user
5752
  int32_t    sqlLen;      // strlen + 1
5753
  char*      sql;
5754
} SMAlterRsmaReq;
5755

5756
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5757
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5758
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5759

5760
typedef struct {
5761
  int64_t    id;
5762
  char       name[TSDB_TABLE_NAME_LEN];
5763
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5764
  int64_t    ownerId;
5765
  int32_t    code;
5766
  int32_t    version;
5767
  int8_t     tbType;
5768
  int8_t     intervalUnit;
5769
  col_id_t   nFuncs;
5770
  col_id_t   nColNames;
5771
  int64_t    interval[2];
5772
  col_id_t*  funcColIds;
5773
  func_id_t* funcIds;
5774
  SArray*    colNames;
5775
} SRsmaInfoRsp;
5776

5777
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5778
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5779
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5780

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

5786
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5787
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5788

5789
typedef struct {
5790
  char    name[TSDB_TABLE_NAME_LEN];
5791
  char    tbName[TSDB_TABLE_NAME_LEN];
5792
  int64_t uid;
5793
  int64_t tbUid;
5794
  int8_t  tbType;
5795
} SVDropRsmaReq;
5796

5797
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5798
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5799

5800
typedef struct {
5801
  char   dbFName[TSDB_DB_FNAME_LEN];
5802
  char   stbName[TSDB_TABLE_NAME_LEN];
5803
  char   colName[TSDB_COL_NAME_LEN];
5804
  char   idxName[TSDB_INDEX_FNAME_LEN];
5805
  int8_t idxType;
5806
} SCreateTagIndexReq;
5807

5808
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5809
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5810

5811
typedef SMDropSmaReq SDropTagIndexReq;
5812

5813
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5814
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5815

5816
typedef struct {
5817
  int8_t         version;       // for compatibility(default 0)
5818
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5819
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5820
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5821
  int32_t        dstVgId;
5822
  char           indexName[TSDB_INDEX_NAME_LEN];
5823
  int32_t        exprLen;
5824
  int32_t        tagsFilterLen;
5825
  int64_t        indexUid;
5826
  tb_uid_t       tableUid;  // super/child/common table uid
5827
  tb_uid_t       dstTbUid;  // for dstVgroup
5828
  int64_t        interval;
5829
  int64_t        offset;  // use unit by precision of DB
5830
  int64_t        sliding;
5831
  char*          dstTbName;  // for dstVgroup
5832
  char*          expr;       // sma expression
5833
  char*          tagsFilter;
5834
  SSchemaWrapper schemaRow;  // for dstVgroup
5835
  SSchemaWrapper schemaTag;  // for dstVgroup
5836
} STSma;                     // Time-range-wise SMA
5837

5838
typedef STSma SVCreateTSmaReq;
5839

5840
typedef struct {
5841
  int8_t  type;  // 0 status report, 1 update data
5842
  int64_t indexUid;
5843
  int64_t skey;  // start TS key of interval/sliding window
5844
} STSmaMsg;
5845

5846
typedef struct {
5847
  int64_t indexUid;
5848
  char    indexName[TSDB_INDEX_NAME_LEN];
5849
} SVDropTSmaReq;
5850

5851
typedef struct {
5852
  int tmp;  // TODO: to avoid compile error
5853
} SVCreateTSmaRsp, SVDropTSmaRsp;
5854

5855
#if 0
5856
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5857
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5858
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5859
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5860
#endif
5861

5862
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5863
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5864
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5865
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5866

5867
typedef struct {
5868
  int32_t number;
5869
  STSma*  tSma;
5870
} STSmaWrapper;
5871

5872
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5873
  if (pSma) {
×
5874
    taosMemoryFreeClear(pSma->dstTbName);
×
5875
    taosMemoryFreeClear(pSma->expr);
×
5876
    taosMemoryFreeClear(pSma->tagsFilter);
×
5877
  }
5878
}
×
5879

5880
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5881
  if (pSW) {
×
5882
    if (pSW->tSma) {
×
5883
      if (deepCopy) {
×
5884
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
5885
          tDestroyTSma(pSW->tSma + i);
×
5886
        }
5887
      }
5888
      taosMemoryFreeClear(pSW->tSma);
×
5889
    }
5890
  }
5891
}
×
5892

5893
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5894
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5895
  taosMemoryFreeClear(pSW);
×
5896
  return NULL;
×
5897
}
5898

5899
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5900
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5901

5902
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5903
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5904

5905
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5906
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5907
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5908
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5909
  }
5910
  return 0;
×
5911
}
5912

5913
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5914
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5915
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5916
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5917
  }
5918
  return 0;
×
5919
}
5920

5921
typedef struct {
5922
  int idx;
5923
} SMCreateFullTextReq;
5924

5925
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5926
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5927
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5928

5929
typedef struct {
5930
  char   name[TSDB_TABLE_FNAME_LEN];
5931
  int8_t igNotExists;
5932
} SMDropFullTextReq;
5933

5934
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5935
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5936

5937
typedef struct {
5938
  char indexFName[TSDB_INDEX_FNAME_LEN];
5939
} SUserIndexReq;
5940

5941
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5942
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5943

5944
typedef struct {
5945
  char dbFName[TSDB_DB_FNAME_LEN];
5946
  char tblFName[TSDB_TABLE_FNAME_LEN];
5947
  char colName[TSDB_COL_NAME_LEN];
5948
  char owner[TSDB_USER_LEN];
5949
  char indexType[TSDB_INDEX_TYPE_LEN];
5950
  char indexExts[TSDB_INDEX_EXTS_LEN];
5951
} SUserIndexRsp;
5952

5953
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5954
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5955

5956
typedef struct {
5957
  char tbFName[TSDB_TABLE_FNAME_LEN];
5958
} STableIndexReq;
5959

5960
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5961
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5962

5963
typedef struct {
5964
  int8_t  intervalUnit;
5965
  int8_t  slidingUnit;
5966
  int64_t interval;
5967
  int64_t offset;
5968
  int64_t sliding;
5969
  int64_t dstTbUid;
5970
  int32_t dstVgId;
5971
  SEpSet  epSet;
5972
  char*   expr;
5973
} STableIndexInfo;
5974

5975
typedef struct {
5976
  char     tbName[TSDB_TABLE_NAME_LEN];
5977
  char     dbFName[TSDB_DB_FNAME_LEN];
5978
  uint64_t suid;
5979
  int32_t  version;
5980
  int32_t  indexSize;
5981
  SArray*  pIndex;  // STableIndexInfo
5982
} STableIndexRsp;
5983

5984
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5985
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5986
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5987

5988
void tFreeSTableIndexInfo(void* pInfo);
5989

5990
typedef struct {
5991
  int8_t  mqMsgType;
5992
  int32_t code;
5993
  int32_t epoch;
5994
  int64_t consumerId;
5995
  int64_t walsver;
5996
  int64_t walever;
5997
} SMqRspHead;
5998

5999
typedef struct {
6000
  SMsgHead     head;
6001
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
6002
  int8_t       withTbName;
6003
  int8_t       useSnapshot;
6004
  int32_t      epoch;
6005
  uint64_t     reqId;
6006
  int64_t      consumerId;
6007
  int64_t      timeout;
6008
  STqOffsetVal reqOffset;
6009
  int8_t       enableReplay;
6010
  int8_t       sourceExcluded;
6011
  int8_t       rawData;
6012
  int32_t      minPollRows;
6013
  int8_t       enableBatchMeta;
6014
  SHashObj*    uidHash;  // to find if uid is duplicated
6015
} SMqPollReq;
6016

6017
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
6018
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
6019
void    tDestroySMqPollReq(SMqPollReq* pReq);
6020

6021
typedef struct {
6022
  int32_t vgId;
6023
  int64_t offset;
6024
  SEpSet  epSet;
6025
} SMqSubVgEp;
6026

6027
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
6028
  int32_t tlen = 0;
2,388,164✔
6029
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,388,164✔
6030
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,388,164✔
6031
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,388,164✔
6032
  return tlen;
2,388,164✔
6033
}
6034

6035
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
6036
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,180,100✔
6037
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,180,100✔
6038
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,180,100✔
6039
  return buf;
1,180,100✔
6040
}
6041

6042
typedef struct {
6043
  char    topic[TSDB_TOPIC_FNAME_LEN];
6044
  char    db[TSDB_DB_FNAME_LEN];
6045
  SArray* vgs;  // SArray<SMqSubVgEp>
6046
} SMqSubTopicEp;
6047

6048
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
6049
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
6050
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
6051

6052
typedef struct {
6053
  SMqRspHead   head;
6054
  STqOffsetVal rspOffset;
6055
  int16_t      resMsgType;
6056
  int32_t      metaRspLen;
6057
  void*        metaRsp;
6058
} SMqMetaRsp;
6059

6060
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
6061
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
6062
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
6063

6064
#define MQ_DATA_RSP_VERSION 100
6065

6066
typedef struct {
6067
  SMqRspHead   head;
6068
  STqOffsetVal rspOffset;
6069
  STqOffsetVal reqOffset;
6070
  int32_t      blockNum;
6071
  int8_t       withTbName;
6072
  int8_t       withSchema;
6073
  SArray*      blockDataLen;
6074
  SArray*      blockData;
6075
  SArray*      blockTbName;
6076
  SArray*      blockSchema;
6077

6078
  union {
6079
    struct {
6080
      int64_t sleepTime;
6081
    };
6082
    struct {
6083
      int32_t createTableNum;
6084
      SArray* createTableLen;
6085
      SArray* createTableReq;
6086
    };
6087
    struct {
6088
      int32_t len;
6089
      void*   rawData;
6090
    };
6091
  };
6092
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
6093
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
6094
  bool  timeout;
6095
} SMqDataRsp;
6096

6097
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
6098
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6099
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6100
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
6101
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
6102

6103
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
6104
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6105
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
6106

6107
typedef struct SMqBatchMetaRsp {
6108
  SMqRspHead   head;  // not serialize
6109
  STqOffsetVal rspOffset;
6110
  SArray*      batchMetaLen;
6111
  SArray*      batchMetaReq;
6112
  void*        pMetaBuff;    // not serialize
6113
  uint32_t     metaBuffLen;  // not serialize
6114
} SMqBatchMetaRsp;
6115

6116
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
6117
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6118
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6119
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
6120

6121
typedef struct {
6122
  int32_t code;
6123
  SArray* topics;  // SArray<SMqSubTopicEp>
6124
} SMqAskEpRsp;
6125

6126
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6127
  int32_t tlen = 0;
8,061,684✔
6128
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6129
  int32_t sz = taosArrayGetSize(pRsp->topics);
8,061,684✔
6130
  tlen += taosEncodeFixedI32(buf, sz);
8,060,980✔
6131
  for (int32_t i = 0; i < sz; i++) {
9,820,430✔
6132
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,759,802✔
6133
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,759,802✔
6134
  }
6135
  tlen += taosEncodeFixedI32(buf, pRsp->code);
8,060,628✔
6136

6137
  return tlen;
8,061,332✔
6138
}
6139

6140
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6141
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6142
  int32_t sz;
3,389,743✔
6143
  buf = taosDecodeFixedI32(buf, &sz);
3,463,088✔
6144
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,463,088✔
6145
  if (pRsp->topics == NULL) {
3,463,088✔
6146
    return NULL;
×
6147
  }
6148
  for (int32_t i = 0; i < sz; i++) {
4,315,992✔
6149
    SMqSubTopicEp topicEp;
840,635✔
6150
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
852,904✔
6151
    if (buf == NULL) {
852,904✔
6152
      return NULL;
×
6153
    }
6154
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,705,808✔
6155
      return NULL;
×
6156
    }
6157
  }
6158
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,463,088✔
6159

6160
  return buf;
3,463,088✔
6161
}
6162

6163
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6164
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,989,605✔
6165
}
9,988,901✔
6166

6167
typedef struct {
6168
  int32_t      vgId;
6169
  STqOffsetVal offset;
6170
  int64_t      rows;
6171
  int64_t      ever;
6172
} OffsetRows;
6173

6174
typedef struct {
6175
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6176
  SArray* offsetRows;
6177
} TopicOffsetRows;
6178

6179
typedef struct {
6180
  int64_t consumerId;
6181
  int32_t epoch;
6182
  SArray* topics;
6183
  int8_t  pollFlag;
6184
} SMqHbReq;
6185

6186
typedef struct {
6187
  char   topic[TSDB_TOPIC_FNAME_LEN];
6188
  int8_t noPrivilege;
6189
} STopicPrivilege;
6190

6191
typedef struct {
6192
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6193
  int32_t debugFlag;
6194
} SMqHbRsp;
6195

6196
typedef struct {
6197
  SMsgHead head;
6198
  int64_t  consumerId;
6199
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6200
} SMqSeekReq;
6201

6202
#define TD_AUTO_CREATE_TABLE 0x1
6203
typedef struct {
6204
  int64_t       suid;
6205
  int64_t       uid;
6206
  int32_t       sver;
6207
  uint32_t      nData;
6208
  uint8_t*      pData;
6209
  SVCreateTbReq cTbReq;
6210
} SVSubmitBlk;
6211

6212
typedef struct {
6213
  SMsgHead header;
6214
  uint64_t sId;
6215
  uint64_t queryId;
6216
  uint64_t clientId;
6217
  uint64_t taskId;
6218
  uint32_t sqlLen;
6219
  uint32_t phyLen;
6220
  char*    sql;
6221
  char*    msg;
6222
  int8_t   source;
6223
  int8_t   secureDelete;
6224
} SVDeleteReq;
6225

6226
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6227
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6228

6229
typedef struct {
6230
  int64_t affectedRows;
6231
} SVDeleteRsp;
6232

6233
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6234
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6235

6236
typedef struct SDeleteRes {
6237
  uint64_t suid;
6238
  SArray*  uidList;
6239
  int64_t  skey;
6240
  int64_t  ekey;
6241
  int64_t  affectedRows;
6242
  char     tableFName[TSDB_TABLE_NAME_LEN];
6243
  char     tsColName[TSDB_COL_NAME_LEN];
6244
  int64_t  ctimeMs;  // fill by vnode
6245
  int8_t   source;
6246
  int8_t   secureDelete;  // force physical overwrite
6247
} SDeleteRes;
6248

6249
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6250
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6251

6252
typedef struct {
6253
  // int64_t uid;
6254
  char    tbname[TSDB_TABLE_NAME_LEN];
6255
  int64_t startTs;
6256
  int64_t endTs;
6257
} SSingleDeleteReq;
6258

6259
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6260
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6261

6262
typedef struct {
6263
  int64_t suid;
6264
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6265
  int64_t ctimeMs;     // fill by vnode
6266
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6267
} SBatchDeleteReq;
6268

6269
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6270
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6271
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6272

6273
typedef struct {
6274
  int32_t msgIdx;
6275
  int32_t msgType;
6276
  int32_t msgLen;
6277
  void*   msg;
6278
} SBatchMsg;
6279

6280
typedef struct {
6281
  SMsgHead header;
6282
  SArray*  pMsgs;  // SArray<SBatchMsg>
6283
} SBatchReq;
6284

6285
typedef struct {
6286
  int32_t reqType;
6287
  int32_t msgIdx;
6288
  int32_t msgLen;
6289
  int32_t rspCode;
6290
  void*   msg;
6291
} SBatchRspMsg;
6292

6293
typedef struct {
6294
  SArray* pRsps;  // SArray<SBatchRspMsg>
6295
} SBatchRsp;
6296

6297
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6298
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6299
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
99,238,594✔
6300
  if (NULL == msg) {
99,238,594✔
6301
    return;
×
6302
  }
6303
  SBatchMsg* pMsg = (SBatchMsg*)msg;
99,238,594✔
6304
  taosMemoryFree(pMsg->msg);
99,238,594✔
6305
}
6306

6307
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6308
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6309

6310
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
138,737,435✔
6311
  if (NULL == p) {
138,737,435✔
6312
    return;
×
6313
  }
6314

6315
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
138,737,435✔
6316
  taosMemoryFree(pRsp->msg);
138,737,435✔
6317
}
6318

6319
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6320
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6321
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6322
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6323
void    tDestroySMqHbReq(SMqHbReq* pReq);
6324

6325
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6326
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6327
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6328

6329
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6330
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6331

6332
#define TD_REQ_FROM_APP               0x0
6333
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6334
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6335
#define SUBMIT_REQ_FROM_FILE          0x4
6336
#define TD_REQ_FROM_TAOX              0x8
6337
#define TD_REQ_FROM_SML               0x10
6338
#define SUBMIT_REQUEST_VERSION        (2)
6339
#define SUBMIT_REQ_WITH_BLOB          0x10
6340
#define SUBMIT_REQ_SCHEMA_RES         0x20
6341
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6342

6343
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6344

6345
typedef struct {
6346
  int32_t        flags;
6347
  SVCreateTbReq* pCreateTbReq;
6348
  int64_t        suid;
6349
  int64_t        uid;
6350
  int32_t        sver;
6351
  union {
6352
    SArray* aRowP;
6353
    SArray* aCol;
6354
  };
6355
  int64_t   ctimeMs;
6356
  SBlobSet* pBlobSet;
6357
} SSubmitTbData;
6358

6359
typedef struct {
6360
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6361
  SArray* aSubmitBlobData;
6362
  bool    raw;
6363
} SSubmitReq2;
6364

6365
typedef struct {
6366
  SMsgHead header;
6367
  int64_t  version;
6368
  char     data[];  // SSubmitReq2
6369
} SSubmitReq2Msg;
6370

6371
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6372
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6373
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6374
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6375
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6376

6377
typedef struct {
6378
  int32_t affectedRows;
6379
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6380
} SSubmitRsp2;
6381

6382
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6383
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6384
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6385

6386
#define TSDB_MSG_FLG_ENCODE 0x1
6387
#define TSDB_MSG_FLG_DECODE 0x2
6388
#define TSDB_MSG_FLG_CMPT   0x3
6389

6390
typedef struct {
6391
  union {
6392
    struct {
6393
      void*   msgStr;
6394
      int32_t msgLen;
6395
      int64_t ver;
6396
    };
6397
    void* pDataBlock;
6398
  };
6399
} SPackedData;
6400

6401
typedef struct {
6402
  char     fullname[TSDB_VIEW_FNAME_LEN];
6403
  char     name[TSDB_VIEW_NAME_LEN];
6404
  char     dbFName[TSDB_DB_FNAME_LEN];
6405
  char*    querySql;
6406
  char*    sql;
6407
  int8_t   orReplace;
6408
  int8_t   precision;
6409
  int32_t  numOfCols;
6410
  SSchema* pSchema;
6411
} SCMCreateViewReq;
6412

6413
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6414
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6415
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6416

6417
typedef struct {
6418
  char   fullname[TSDB_VIEW_FNAME_LEN];
6419
  char   name[TSDB_VIEW_NAME_LEN];
6420
  char   dbFName[TSDB_DB_FNAME_LEN];
6421
  char*  sql;
6422
  int8_t igNotExists;
6423
} SCMDropViewReq;
6424

6425
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6426
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6427
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6428

6429
typedef struct {
6430
  char fullname[TSDB_VIEW_FNAME_LEN];
6431
} SViewMetaReq;
6432
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6433
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6434

6435
typedef struct {
6436
  char     name[TSDB_VIEW_NAME_LEN];
6437
  char     dbFName[TSDB_DB_FNAME_LEN];
6438
  char*    createUser;
6439
  int64_t  ownerId;
6440
  uint64_t dbId;
6441
  uint64_t viewId;
6442
  char*    querySql;
6443
  int8_t   precision;
6444
  int8_t   type;
6445
  int32_t  version;
6446
  int32_t  numOfCols;
6447
  SSchema* pSchema;
6448
} SViewMetaRsp;
6449
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6450
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6451
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6452
typedef struct {
6453
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6454
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6455
} STableTSMAInfoReq;
6456

6457
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6458
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6459

6460
typedef struct {
6461
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6462
  union {
6463
    uint8_t flags;
6464
    struct {
6465
      uint8_t withColName : 1;
6466
      uint8_t reserved : 7;
6467
    };
6468
  };
6469

6470
} SRsmaInfoReq;
6471

6472
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6473
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6474

6475
typedef struct {
6476
  int32_t  funcId;
6477
  col_id_t colId;
6478
} STableTSMAFuncInfo;
6479

6480
typedef struct {
6481
  char     name[TSDB_TABLE_NAME_LEN];
6482
  uint64_t tsmaId;
6483
  char     targetTb[TSDB_TABLE_NAME_LEN];
6484
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6485
  char     tb[TSDB_TABLE_NAME_LEN];
6486
  char     dbFName[TSDB_DB_FNAME_LEN];
6487
  uint64_t suid;
6488
  uint64_t destTbUid;
6489
  uint64_t dbId;
6490
  int32_t  version;
6491
  int64_t  interval;
6492
  int8_t   unit;
6493
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6494
  SArray*  pTags;      // SArray<SSchema>
6495
  SArray*  pUsedCols;  // SArray<SSchema>
6496
  char*    ast;
6497

6498
  int64_t streamUid;
6499
  int64_t reqTs;
6500
  int64_t rspTs;
6501
  int64_t delayDuration;  // ms
6502
  bool    fillHistoryFinished;
6503

6504
  void* streamAddr;  // for stream task, the address of the stream task
6505
} STableTSMAInfo;
6506

6507
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6508
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6509
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6510
void    tFreeTableTSMAInfo(void* p);
6511
void    tFreeAndClearTableTSMAInfo(void* p);
6512
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6513

6514
#define STSMAHbRsp            STableTSMAInfoRsp
6515
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6516
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6517
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6518

6519
typedef struct SDropCtbWithTsmaSingleVgReq {
6520
  SVgroupInfo vgInfo;
6521
  SArray*     pTbs;  // SVDropTbReq
6522
} SMDropTbReqsOnSingleVg;
6523

6524
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6525
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6526
void    tFreeSMDropTbReqOnSingleVg(void* p);
6527

6528
typedef struct SDropTbsReq {
6529
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6530
} SMDropTbsReq;
6531

6532
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6533
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6534
void    tFreeSMDropTbsReq(void*);
6535

6536
typedef struct SVFetchTtlExpiredTbsRsp {
6537
  SArray* pExpiredTbs;  // SVDropTbReq
6538
  int32_t vgId;
6539
} SVFetchTtlExpiredTbsRsp;
6540

6541
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6542
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6543

6544
void tFreeFetchTtlExpiredTbsRsp(void* p);
6545

6546
void setDefaultOptionsForField(SFieldWithOptions* field);
6547
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6548

6549
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6550
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6551

6552
typedef struct {
6553
  char    id[TSDB_INSTANCE_ID_LEN];
6554
  char    type[TSDB_INSTANCE_TYPE_LEN];
6555
  char    desc[TSDB_INSTANCE_DESC_LEN];
6556
  int32_t expire;
6557
} SInstanceRegisterReq;
6558

6559
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6560
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6561

6562
typedef struct {
6563
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6564
} SInstanceListReq;
6565

6566
typedef struct {
6567
  int32_t count;
6568
  char**  ids;  // Array of instance IDs
6569
} SInstanceListRsp;
6570

6571
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6572
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6573
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6574
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6575

6576
#ifdef USE_MOUNT
6577
typedef struct {
6578
  char     mountName[TSDB_MOUNT_NAME_LEN];
6579
  int8_t   ignoreExist;
6580
  int16_t  nMounts;
6581
  int32_t* dnodeIds;
6582
  char**   mountPaths;
6583
  int32_t  sqlLen;
6584
  char*    sql;
6585
} SCreateMountReq;
6586

6587
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6588
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6589
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6590

6591
typedef struct {
6592
  char    mountName[TSDB_MOUNT_NAME_LEN];
6593
  int8_t  ignoreNotExists;
6594
  int32_t sqlLen;
6595
  char*   sql;
6596
} SDropMountReq;
6597

6598
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6599
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6600
void    tFreeSDropMountReq(SDropMountReq* pReq);
6601

6602
typedef struct {
6603
  char     mountName[TSDB_MOUNT_NAME_LEN];
6604
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6605
  int64_t  mountUid;
6606
  int32_t  dnodeId;
6607
  uint32_t valLen;
6608
  int8_t   ignoreExist;
6609
  void*    pVal;
6610
} SRetrieveMountPathReq;
6611

6612
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6613
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6614

6615
typedef struct {
6616
  // path
6617
  int32_t diskPrimary;
6618
  // vgInfo
6619
  int32_t  vgId;
6620
  int32_t  cacheLastSize;
6621
  int32_t  szPage;
6622
  int32_t  szCache;
6623
  uint64_t szBuf;
6624
  int8_t   cacheLast;
6625
  int8_t   standby;
6626
  int8_t   hashMethod;
6627
  uint32_t hashBegin;
6628
  uint32_t hashEnd;
6629
  int16_t  hashPrefix;
6630
  int16_t  hashSuffix;
6631
  int16_t  sttTrigger;
6632
  // syncInfo
6633
  int32_t replications;
6634
  // tsdbInfo
6635
  int8_t  precision;
6636
  int8_t  compression;
6637
  int8_t  slLevel;
6638
  int32_t daysPerFile;
6639
  int32_t keep0;
6640
  int32_t keep1;
6641
  int32_t keep2;
6642
  int32_t keepTimeOffset;
6643
  int32_t minRows;
6644
  int32_t maxRows;
6645
  int32_t tsdbPageSize;
6646
  int32_t ssChunkSize;
6647
  int32_t ssKeepLocal;
6648
  int8_t  ssCompact;
6649
  union {
6650
    uint8_t flags;
6651
    struct {
6652
      uint8_t isAudit : 1;
6653
      uint8_t allowDrop : 1;
6654
      uint8_t reserved : 6;
6655
    };
6656
  };
6657
  int8_t secureDelete;
6658
  // walInfo
6659
  int32_t walFsyncPeriod;      // millisecond
6660
  int32_t walRetentionPeriod;  // secs
6661
  int32_t walRollPeriod;       // secs
6662
  int64_t walRetentionSize;
6663
  int64_t walSegSize;
6664
  int32_t walLevel;
6665
  // encryptInfo
6666
  int32_t encryptAlgorithm;
6667
  // SVState
6668
  int64_t committed;
6669
  int64_t commitID;
6670
  int64_t commitTerm;
6671
  // stats
6672
  int64_t numOfSTables;
6673
  int64_t numOfCTables;
6674
  int64_t numOfNTables;
6675
  // dbInfo
6676
  uint64_t dbId;
6677
} SMountVgInfo;
6678

6679
typedef struct {
6680
  SMCreateStbReq req;
6681
  SArray*        pColExts;  // element: column id
6682
  SArray*        pTagExts;  // element: tag id
6683
} SMountStbInfo;
6684

6685
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6686
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6687

6688
typedef struct {
6689
  char     dbName[TSDB_DB_FNAME_LEN];
6690
  uint64_t dbId;
6691
  SArray*  pVgs;   // SMountVgInfo
6692
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6693
} SMountDbInfo;
6694

6695
typedef struct {
6696
  // common fields
6697
  char     mountName[TSDB_MOUNT_NAME_LEN];
6698
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6699
  int8_t   ignoreExist;
6700
  int64_t  mountUid;
6701
  int64_t  clusterId;
6702
  int32_t  dnodeId;
6703
  uint32_t valLen;
6704
  void*    pVal;
6705

6706
  // response fields
6707
  SArray* pDbs;  // SMountDbInfo
6708

6709
  // memory fields, no serialized
6710
  SArray*   pDisks[TFS_MAX_TIERS];
6711
  TdFilePtr pFile;
6712
} SMountInfo;
6713

6714
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6715
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6716
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6717

6718
typedef struct {
6719
  SCreateVnodeReq createReq;
6720
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6721
  char            mountName[TSDB_MOUNT_NAME_LEN];
6722
  int64_t         mountId;
6723
  int32_t         diskPrimary;
6724
  int32_t         mountVgId;
6725
  int64_t         committed;
6726
  int64_t         commitID;
6727
  int64_t         commitTerm;
6728
  int64_t         numOfSTables;
6729
  int64_t         numOfCTables;
6730
  int64_t         numOfNTables;
6731
} SMountVnodeReq;
6732

6733
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6734
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6735
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6736

6737
#endif  // USE_MOUNT
6738

6739
#pragma pack(pop)
6740

6741
typedef struct {
6742
  char        db[TSDB_DB_FNAME_LEN];
6743
  STimeWindow timeRange;
6744
  int32_t     sqlLen;
6745
  char*       sql;
6746
  SArray*     vgroupIds;
6747
} SScanDbReq;
6748

6749
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6750
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6751
void    tFreeSScanDbReq(SScanDbReq* pReq);
6752

6753
typedef struct {
6754
  int32_t scanId;
6755
  int8_t  bAccepted;
6756
} SScanDbRsp;
6757

6758
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6759
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6760

6761
typedef struct {
6762
  int32_t scanId;
6763
  int32_t sqlLen;
6764
  char*   sql;
6765
} SKillScanReq;
6766

6767
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6768
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6769
void    tFreeSKillScanReq(SKillScanReq* pReq);
6770

6771
typedef struct {
6772
  int32_t scanId;
6773
  int32_t vgId;
6774
  int32_t dnodeId;
6775
} SVKillScanReq;
6776

6777
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6778
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6779

6780
typedef struct {
6781
  int32_t scanId;
6782
  int32_t vgId;
6783
  int32_t dnodeId;
6784
  int32_t numberFileset;
6785
  int32_t finished;
6786
  int32_t progress;
6787
  int64_t remainingTime;
6788
} SQueryScanProgressRsp;
6789

6790
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6791
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6792

6793
typedef struct {
6794
  int32_t scanId;
6795
  int32_t vgId;
6796
  int32_t dnodeId;
6797
} SQueryScanProgressReq;
6798

6799
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6800
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6801

6802
typedef struct {
6803
  int64_t     dbUid;
6804
  char        db[TSDB_DB_FNAME_LEN];
6805
  int64_t     scanStartTime;
6806
  STimeWindow tw;
6807
  int32_t     scanId;
6808
} SScanVnodeReq;
6809

6810
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6811
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6812

6813
#ifdef __cplusplus
6814
}
6815
#endif
6816

6817
#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