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

taosdata / TDengine / #4995

18 Mar 2026 06:26AM UTC coverage: 71.996% (-0.2%) from 72.244%
#4995

push

travis-ci

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

2 of 4 new or added lines in 2 files covered. (50.0%)

5312 existing lines in 167 files now uncovered.

244665 of 339830 relevant lines covered (72.0%)

135013613.72 hits per line

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

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

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

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

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

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

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

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

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

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

67
typedef uint16_t tmsg_t;
68

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

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

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

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

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

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
970,282,013✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
922,081,485✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,892,363,498✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

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

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

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

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

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

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

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

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

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

263

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

269

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

275
#define TSDB_ALTER_RSMA_FUNCTION        0x1
276

277
#define TSDB_KILL_MSG_LEN 30
278

279
#define TSDB_TABLE_NUM_UNIT 100000
280

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

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

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

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

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

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

451

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

973
bool hasExtSchema(const SExtSchema* pExtSchema);
974

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

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

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

993
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
994
  if (pRef->pColRef) {
482,574✔
995
    return TSDB_CODE_INVALID_PARA;
×
996
  }
997
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
482,574✔
998
  if (pRef->pColRef == NULL) {
482,574✔
UNCOV
999
    return terrno;
×
1000
  }
1001
  pRef->nCols = nCols;
482,574✔
1002
  for (int32_t i = 0; i < nCols; i++) {
153,489,173✔
1003
    pRef->pColRef[i].hasRef = false;
153,006,599✔
1004
    pRef->pColRef[i].id = (col_id_t)(i + 1);
153,006,599✔
1005
  }
1006
  return 0;
482,574✔
1007
}
1008

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

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

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

1030
  return pDstWrapper;
1031
}
1032

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

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

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

1066
  taosMemoryFreeClear(pWrapper->pColCmpr);
1067
  taosMemoryFreeClear(pWrapper);
1068
}
1069
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1070
  if (pSchemaWrapper->pSchema == NULL) return NULL;
650,514,333✔
1071

1072
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
650,419,296✔
1073
  if (pSW == NULL) {
650,361,701✔
UNCOV
1074
    return NULL;
×
1075
  }
1076
  pSW->nCols = pSchemaWrapper->nCols;
650,361,701✔
1077
  pSW->version = pSchemaWrapper->version;
650,409,268✔
1078
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
650,428,298✔
1079
  if (pSW->pSchema == NULL) {
650,279,461✔
UNCOV
1080
    taosMemoryFree(pSW);
×
UNCOV
1081
    return NULL;
×
1082
  }
1083

1084
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
650,316,665✔
1085
  return pSW;
650,573,317✔
1086
}
1087

1088
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
170,258,320✔
1089
  if (pSchemaWrapper) {
1,471,965,037✔
1090
    taosMemoryFree(pSchemaWrapper->pSchema);
1,021,223,055✔
1091
    if (pSchemaWrapper->pRsma) {
1,021,171,498✔
1092
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
27,639✔
1093
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
27,639✔
1094
    }
1095
    taosMemoryFree(pSchemaWrapper);
1,021,174,601✔
1096
  }
1097
}
1,426,540,895✔
1098

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

1109
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
8,033,553✔
1110
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
8,033,553✔
1111
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
8,034,162✔
1112
  }
1113
}
8,033,034✔
1114

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

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

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

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

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

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

1166
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1167
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
929,284,472✔
1168
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
929,284,472✔
1169
  if (pColRef->hasRef) {
464,642,236✔
1170
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
616,637,636✔
1171
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
616,637,636✔
1172
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
616,637,636✔
1173
  }
1174
  return 0;
464,642,236✔
1175
}
1176

1177
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1178
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
465,016,646✔
1179
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
465,016,646✔
1180
  if (pColRef->hasRef) {
232,508,323✔
1181
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
154,319,952✔
1182
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
154,319,952✔
1183
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
154,319,952✔
1184
  }
1185

1186
  return 0;
232,508,323✔
1187
}
1188

1189
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1190
  int32_t tlen = 0;
430,368✔
1191
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
430,368✔
1192
  tlen += taosEncodeVariantI32(buf, pSW->version);
430,368✔
1193
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,038,414✔
1194
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,216,092✔
1195
  }
1196
  return tlen;
430,368✔
1197
}
1198

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

1208
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,377,836✔
1209
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,374,000✔
1210
    }
1211
  } else {
UNCOV
1212
    pSW->pSchema = NULL;
×
1213
  }
1214
  return (void*)buf;
190,836✔
1215
}
1216

1217
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1218
  if (pSW == NULL) {
306,027,540✔
UNCOV
1219
    return TSDB_CODE_INVALID_PARA;
×
1220
  }
1221
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
611,980,096✔
1222
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
611,876,281✔
1223
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1224
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1225
  }
1226
  return 0;
306,046,569✔
1227
}
1228

1229
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1230
  if (pSW == NULL) {
132,639,254✔
UNCOV
1231
    return TSDB_CODE_INVALID_PARA;
×
1232
  }
1233
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
265,259,326✔
1234
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
265,258,209✔
1235

1236
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
132,638,137✔
1237
  if (pSW->pSchema == NULL) {
132,607,325✔
UNCOV
1238
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1239
  }
1240
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,401,668,109✔
1241
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1242
  }
1243

1244
  return 0;
132,666,804✔
1245
}
1246

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

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

1259
  return 0;
2,034,993,294✔
1260
}
1261

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1594

1595
typedef struct {
1596
  int8_t createType;
1597

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

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

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

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

1625
  int8_t negIpRanges;
1626
  int8_t negTimeRanges;
1627

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

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

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

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

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

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

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

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

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

1685
typedef struct {
1686
  int8_t alterType;
1687

1688
  int8_t isView;
1689

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1914

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

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

1924

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

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

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

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

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

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

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

1963

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2082
typedef STableCfg STableCfgRsp;
2083

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2465
typedef SDbCfgRsp SDbCfgInfo;
2466

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

2473
typedef struct {
2474
  int32_t rowNum;
2475
} SQnodeListReq;
2476

2477
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2478
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2479

2480
typedef struct {
2481
  int32_t rowNum;
2482
} SDnodeListReq;
2483

2484
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2485

2486
typedef struct {
2487
  int32_t useless;  // useless
2488
} SServerVerReq;
2489

2490
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2491
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2492

2493
typedef struct {
2494
  char ver[TSDB_VERSION_LEN];
2495
} SServerVerRsp;
2496

2497
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2498
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2499

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

2505
typedef struct {
2506
  SQueryNodeAddr addr;
2507
  uint64_t       load;
2508
} SQueryNodeLoad;
2509

2510
typedef struct {
2511
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2512
} SQnodeListRsp;
2513

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

2518

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

2531

2532

2533
typedef struct SDNodeAddr {
2534
  int32_t nodeId;  // dnodeId
2535
  SEpSet  epSet;
2536
} SDNodeAddr;
2537

2538
typedef struct {
2539
  SArray* dnodeList;  // SArray<SDNodeAddr>
2540
} SDnodeListRsp;
2541

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

2546
typedef struct {
2547
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2548
} STableTSMAInfoRsp;
2549

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

2559
typedef struct {
2560
  SArray* pArray;  // Array of SDbHbRsp
2561
} SDbHbBatchRsp;
2562

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

2567
typedef struct {
2568
  SArray* pArray;  // Array of SGetUserAuthRsp
2569
} SUserAuthBatchRsp;
2570

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

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

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

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

2598
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2599
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2600

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

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

2614
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2615
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2616

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

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

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

2641
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2642
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2643

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

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

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

2668
typedef struct {
2669
  int32_t funcVersion;
2670
  int64_t funcCreatedTime;
2671
} SFuncExtraInfo;
2672

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

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

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

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

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

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

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

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

2774
typedef struct {
2775
  int32_t vgId;
2776
  int64_t nTimeSeries;
2777
} SVnodeLoadLite;
2778

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

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

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

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

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

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

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

2850
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2851
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2852

2853
typedef enum {
2854
  MONITOR_TYPE_COUNTER = 0,
2855
  MONITOR_TYPE_SLOW_LOG = 1,
2856
} MONITOR_TYPE;
2857

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

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

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

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

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

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

2898
typedef struct {
2899
  int32_t dnodeId;
2900
  int64_t clusterId;
2901
} SDnodeCfg;
2902

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

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

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

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

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

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

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

2953
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2954
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2955

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

2973
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2974
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2975

2976
typedef struct {
2977
  int32_t reserved;
2978
} SMTimerReq;
2979

2980
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2981
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2982

2983
typedef struct SOrphanTask {
2984
  int64_t streamId;
2985
  int32_t taskId;
2986
  int32_t nodeId;
2987
} SOrphanTask;
2988

2989
typedef struct SMStreamDropOrphanMsg {
2990
  SArray* pList;  // SArray<SOrphanTask>
2991
} SMStreamDropOrphanMsg;
2992

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

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

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

3065
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3066
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3067
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3068

3069
typedef struct {
3070
  union {
3071
    int32_t compactId;
3072
    int32_t id;
3073
  };
3074
  int32_t vgId;
3075
  int32_t dnodeId;
3076
} SQueryCompactProgressReq;
3077

3078
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3079
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3080

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

3094
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3095
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3096

3097
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3098
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3099

3100
typedef struct {
3101
  int32_t vgId;
3102
  int32_t dnodeId;
3103
  int64_t dbUid;
3104
  char    db[TSDB_DB_FNAME_LEN];
3105
  int64_t reserved[8];
3106
} SDropVnodeReq;
3107

3108
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3109
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3110

3111
typedef struct {
3112
  char    colName[TSDB_COL_NAME_LEN];
3113
  char    stb[TSDB_TABLE_FNAME_LEN];
3114
  int64_t stbUid;
3115
  int64_t dbUid;
3116
  int64_t reserved[8];
3117
} SDropIndexReq;
3118

3119
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3120
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3121

3122
typedef struct {
3123
  int64_t dbUid;
3124
  char    db[TSDB_DB_FNAME_LEN];
3125
  union {
3126
    int64_t compactStartTime;
3127
    int64_t startTime;
3128
  };
3129

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

3147
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3148
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3149

3150
typedef struct {
3151
  union {
3152
    int32_t compactId;
3153
    int32_t taskId;
3154
  };
3155
  int32_t vgId;
3156
  int32_t dnodeId;
3157
} SVKillCompactReq;
3158

3159
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3160
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3161

3162
typedef SVKillCompactReq SVKillRetentionReq;
3163

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

3181
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3182
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3183
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3184

3185
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3186

3187
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3188
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3189

3190
typedef struct {
3191
  int32_t vgVersion;
3192
  int32_t buffer;
3193
  int32_t pageSize;
3194
  int32_t pages;
3195
  int32_t cacheLastSize;
3196
  int32_t daysPerFile;
3197
  int32_t daysToKeep0;
3198
  int32_t daysToKeep1;
3199
  int32_t daysToKeep2;
3200
  int32_t keepTimeOffset;
3201
  int32_t walFsyncPeriod;
3202
  int8_t  walLevel;
3203
  int8_t  strict;
3204
  int8_t  cacheLast;
3205
  int64_t reserved[7];
3206
  // 1st modification
3207
  int16_t sttTrigger;
3208
  int32_t minRows;
3209
  // 2nd modification
3210
  int32_t walRetentionPeriod;
3211
  int32_t walRetentionSize;
3212
  int32_t ssKeepLocal;
3213
  int8_t  ssCompact;
3214
  int8_t  allowDrop;
3215
  int8_t  secureDelete;
3216
} SAlterVnodeConfigReq;
3217

3218
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3219
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3220

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

3235
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3236
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3237

3238
typedef struct {
3239
  int32_t vgId;
3240
  int8_t  disable;
3241
} SDisableVnodeWriteReq;
3242

3243
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3244
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3245

3246
typedef struct {
3247
  int32_t  srcVgId;
3248
  int32_t  dstVgId;
3249
  uint32_t hashBegin;
3250
  uint32_t hashEnd;
3251
  int32_t  changeVersion;
3252
  int32_t  reserved;
3253
} SAlterVnodeHashRangeReq;
3254

3255
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3256
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3257

3258
#define REQ_OPT_TBNAME 0x0
3259
#define REQ_OPT_TBUID  0x01
3260
typedef struct {
3261
  SMsgHead header;
3262
  char     dbFName[TSDB_DB_FNAME_LEN];
3263
  char     tbName[TSDB_TABLE_NAME_LEN];
3264
  uint8_t  option;
3265
  uint8_t  autoCreateCtb;
3266
} STableInfoReq;
3267

3268
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3269
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3270

3271
typedef struct {
3272
  int8_t  metaClone;  // create local clone of the cached table meta
3273
  int32_t numOfVgroups;
3274
  int32_t numOfTables;
3275
  int32_t numOfUdfs;
3276
  char    tableNames[];
3277
} SMultiTableInfoReq;
3278

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

3291
typedef struct {
3292
  int32_t     numOfVgroups;
3293
  SVgroupInfo vgroups[];
3294
} SVgroupsInfo;
3295

3296
typedef struct {
3297
  STableMetaRsp* pMeta;
3298
} SMAlterStbRsp;
3299

3300
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3301
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3302
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3303

3304
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3305
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3306
void    tFreeSTableMetaRsp(void* pRsp);
3307
void    tFreeSTableIndexRsp(void* info);
3308

3309
typedef struct {
3310
  SArray* pMetaRsp;   // Array of STableMetaRsp
3311
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3312
} SSTbHbRsp;
3313

3314
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3315
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3316
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3317

3318
typedef struct {
3319
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3320
} SViewHbRsp;
3321

3322
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3323
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3324
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3325

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

3337
typedef struct {
3338
  int32_t dataLen;
3339
  char    name[TSDB_TABLE_FNAME_LEN];
3340
  char*   data;
3341
} STagData;
3342

3343
typedef struct {
3344
  int32_t  opType;
3345
  uint32_t valLen;
3346
  char*    val;
3347
} SShowVariablesReq;
3348

3349
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3350
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3351
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3352

3353
typedef struct {
3354
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3355
  char value[TSDB_CONFIG_PATH_LEN + 1];
3356
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3357
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3358
  char info[TSDB_CONFIG_INFO_LEN + 1];
3359
} SVariablesInfo;
3360

3361
typedef struct {
3362
  SArray* variables;  // SArray<SVariablesInfo>
3363
} SShowVariablesRsp;
3364

3365
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3366
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3367

3368
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3369

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

3382
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3383
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3384
void tFreeSShowReq(SShowReq* pReq);
3385

3386
typedef struct {
3387
  int64_t       showId;
3388
  STableMetaRsp tableMeta;
3389
} SShowRsp, SVShowTablesRsp;
3390

3391
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3392
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3393
// void    tFreeSShowRsp(SShowRsp* pRsp);
3394

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

3405
typedef struct SSysTableSchema {
3406
  int8_t   type;
3407
  col_id_t colId;
3408
  int32_t  bytes;
3409
} SSysTableSchema;
3410

3411
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3412
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3413

3414
#define RETRIEVE_TABLE_RSP_VERSION         0
3415
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3416
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3417

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

3437
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3438

3439
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3440
  do {                                          \
3441
    ((int32_t*)(_p))[0] = (_compLen);           \
3442
    ((int32_t*)(_p))[1] = (_fullLen);           \
3443
  } while (0);
3444

3445
typedef struct {
3446
  int64_t version;
3447
  int64_t numOfRows;
3448
  int8_t  compressed;
3449
  int8_t  precision;
3450
  char    data[];
3451
} SRetrieveTableRspForTmq;
3452

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

3465
typedef struct SExplainExecInfo {
3466
  double   startupCost;
3467
  double   totalCost;
3468
  uint64_t numOfRows;
3469
  uint32_t verboseLen;
3470
  void*    verboseInfo;
3471
} SExplainExecInfo;
3472

3473
typedef struct {
3474
  int32_t           numOfPlans;
3475
  SExplainExecInfo* subplanInfo;
3476
} SExplainRsp;
3477

3478
typedef struct {
3479
  SExplainRsp rsp;
3480
  uint64_t    qId;
3481
  uint64_t    cId;
3482
  uint64_t    tId;
3483
  int64_t     rId;
3484
  int32_t     eId;
3485
} SExplainLocalRsp;
3486

3487
typedef struct STableScanAnalyzeInfo {
3488
  uint64_t totalRows;
3489
  uint64_t totalCheckedRows;
3490
  uint32_t totalBlocks;
3491
  uint32_t loadBlocks;
3492
  uint32_t loadBlockStatis;
3493
  uint32_t skipBlocks;
3494
  uint32_t filterOutBlocks;
3495
  double   elapsedTime;
3496
  double   filterTime;
3497
} STableScanAnalyzeInfo;
3498

3499
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3500
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3501
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3502

3503
typedef struct {
3504
  char    config[TSDB_DNODE_CONFIG_LEN];
3505
  char    value[TSDB_CLUSTER_VALUE_LEN];
3506
  int32_t sqlLen;
3507
  char*   sql;
3508
} SMCfgClusterReq;
3509

3510
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3511
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3512
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3513

3514
typedef struct {
3515
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3516
  int32_t port;
3517
  int32_t sqlLen;
3518
  char*   sql;
3519
} SCreateDnodeReq;
3520

3521
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3522
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3523
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3524

3525
typedef struct {
3526
  int32_t dnodeId;
3527
  char    fqdn[TSDB_FQDN_LEN];
3528
  int32_t port;
3529
  int8_t  force;
3530
  int8_t  unsafe;
3531
  int32_t sqlLen;
3532
  char*   sql;
3533
} SDropDnodeReq;
3534

3535
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3536
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3537
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3538

3539
enum {
3540
  RESTORE_TYPE__ALL = 1,
3541
  RESTORE_TYPE__MNODE,
3542
  RESTORE_TYPE__VNODE,
3543
  RESTORE_TYPE__QNODE,
3544
};
3545

3546
typedef struct {
3547
  int32_t dnodeId;
3548
  int8_t  restoreType;
3549
  int32_t sqlLen;
3550
  char*   sql;
3551
} SRestoreDnodeReq;
3552

3553
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3554
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3555
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3556

3557
typedef struct {
3558
  int32_t dnodeId;
3559
  char    config[TSDB_DNODE_CONFIG_LEN];
3560
  char    value[TSDB_DNODE_VALUE_LEN];
3561
  int32_t sqlLen;
3562
  char*   sql;
3563
} SMCfgDnodeReq;
3564

3565
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3566
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3567
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3568

3569
typedef struct {
3570
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3571
  char    newKey[ENCRYPT_KEY_LEN + 1];
3572
  int32_t sqlLen;
3573
  char*   sql;
3574
} SMAlterEncryptKeyReq;
3575

3576
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3577
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3578
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3579

3580
typedef struct {
3581
  int32_t days;
3582
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3583
  int32_t sqlLen;
3584
  char*   sql;
3585
} SMAlterKeyExpirationReq;
3586

3587
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3588
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3589
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3590

3591
typedef struct {
3592
  char    config[TSDB_DNODE_CONFIG_LEN];
3593
  char    value[TSDB_DNODE_VALUE_LEN];
3594
  int32_t version;
3595
} SDCfgDnodeReq;
3596

3597
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3598
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3599

3600
typedef struct {
3601
  int32_t dnodeId;
3602
  int32_t sqlLen;
3603
  char*   sql;
3604
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3605
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3606

3607
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3608
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3609

3610
typedef struct {
3611
  int32_t nodeId;
3612
  SEpSet  epSet;
3613
} SNodeEpSet;
3614

3615
typedef struct {
3616
  int32_t    snodeId;
3617
  SNodeEpSet leaders[2];
3618
  SNodeEpSet replica;
3619
  int32_t    sqlLen;
3620
  char*      sql;
3621
} SDCreateSnodeReq;
3622

3623
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3624
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3625
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3626

3627
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3628
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3629
typedef struct {
3630
  int8_t   replica;
3631
  SReplica replicas[TSDB_MAX_REPLICA];
3632
  int8_t   learnerReplica;
3633
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3634
  int64_t  lastIndex;
3635
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3636
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3637

3638
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3639
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3640

3641
typedef struct {
3642
  int32_t urlLen;
3643
  int32_t sqlLen;
3644
  char*   url;
3645
  char*   sql;
3646
} SMCreateAnodeReq;
3647

3648
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3649
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3650
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3651

3652
typedef struct {
3653
  int32_t anodeId;
3654
  int32_t sqlLen;
3655
  char*   sql;
3656
} SMDropAnodeReq, SMUpdateAnodeReq;
3657

3658
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3659
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3660
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3661
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3662
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3663
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3664

3665
typedef struct {
3666
  int32_t dnodeId;
3667
  int32_t bnodeProto;
3668
  int32_t sqlLen;
3669
  char*   sql;
3670
} SMCreateBnodeReq, SDCreateBnodeReq;
3671

3672
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3673
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3674
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3675

3676
typedef struct {
3677
  int32_t dnodeId;
3678
  int32_t sqlLen;
3679
  char*   sql;
3680
} SMDropBnodeReq, SDDropBnodeReq;
3681

3682
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3683
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3684
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3685

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

3746
typedef struct {
3747
  int32_t sqlLen;
3748
  int32_t urlLen;
3749
  int32_t userLen;
3750
  int32_t passLen;
3751
  int32_t passIsMd5;
3752
  char*   sql;
3753
  char*   url;
3754
  char*   user;
3755
  char*   pass;
3756
  CowStr  token;
3757
} SMCreateXnodeReq, SDCreateXnodeReq;
3758

3759
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3760
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3761
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3762

3763
typedef struct {
3764
  int32_t xnodeId;
3765
  int32_t force;
3766
  int32_t urlLen;
3767
  int32_t sqlLen;
3768
  char*   url;
3769
  char*   sql;
3770
} SMDropXnodeReq, SDDropXnodeReq;
3771

3772
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3773
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3774
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3775

3776
typedef struct {
3777
  int32_t id;
3778
  CowStr  token;
3779
  CowStr  user;
3780
  CowStr  pass;
3781
  int32_t urlLen;
3782
  int32_t sqlLen;
3783
  char*   url;
3784
  char*   sql;
3785
} SMUpdateXnodeReq;
3786
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3787
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3788
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3789

3790
typedef struct {
3791
  int32_t xnodeId;
3792
  int32_t sqlLen;
3793
  char*   sql;
3794
} SMDrainXnodeReq;
3795
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3796
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3797
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3798
typedef enum {
3799
  XNODE_TASK_SOURCE_DSN = 1,
3800
  XNODE_TASK_SOURCE_DATABASE,
3801
  XNODE_TASK_SOURCE_TOPIC,
3802
} ENodeXTaskSourceType;
3803

3804
typedef enum {
3805
  XNODE_TASK_SINK_DSN = 1,
3806
  XNODE_TASK_SINK_DATABASE,
3807
} ENodeXTaskSinkType;
3808

3809
typedef struct {
3810
  ENodeXTaskSourceType type;
3811
  CowStr               cstr;
3812
} xTaskSource;
3813
/**
3814
 * @brief Deallocate a xTaskSource object.
3815
 *
3816
 * @param source ptr
3817
 */
3818
void xFreeTaskSource(xTaskSource* source);
3819
/**
3820
 * @brief Create a xTaskSource object with cloned source string.
3821
 *
3822
 * @param sourceType: source type.
3823
 * @param len: length of source string.
3824
 * @param source: source string ptr.
3825
 * @return xTaskSource object
3826
 */
3827
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3828
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3829
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3830
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3831
const char* xGetTaskSourceStr(xTaskSource* source);
3832
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3833
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3834

3835
typedef struct {
3836
  ENodeXTaskSinkType type;
3837
  CowStr             cstr;
3838
} xTaskSink;
3839
/**
3840
 * @brief Deallocate a xTaskSink object.
3841
 *
3842
 * @param sink ptr
3843
 */
3844
void xFreeTaskSink(xTaskSink* sink);
3845
/**
3846
 * @brief Create a xTaskSink object with cloned name string.
3847
 *
3848
 * @param sinkType: sink type.
3849
 * @param len: length of sink string.
3850
 * @param ptr: sink string ptr.
3851
 * @return xTaskSink object
3852
 */
3853
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3854
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3855
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3856
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3857
const char* xGetTaskSinkStr(xTaskSink* sink);
3858
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3859
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3860

3861
typedef struct {
3862
  int32_t via;
3863
  CowStr  parser;
3864
  // CowStr  reason;
3865
  CowStr  trigger;
3866
  CowStr  health;
3867
  int32_t optionsNum;
3868
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3869
} xTaskOptions;
3870
/**
3871
 * @brief Deallocate a xTaskOptions object.
3872
 *
3873
 * @param options ptr
3874
 */
3875
void    xFreeTaskOptions(xTaskOptions* options);
3876
void    printXnodeTaskOptions(xTaskOptions* options);
3877
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3878
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3879

3880
typedef struct {
3881
  int32_t sqlLen;
3882
  char*   sql;
3883
  int32_t      xnodeId;
3884
  CowStr       name;
3885
  xTaskSource  source;
3886
  xTaskSink    sink;
3887
  xTaskOptions options;
3888
} SMCreateXnodeTaskReq;
3889
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3890
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3891
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3892

3893
typedef struct {
3894
  int32_t     tid;
3895
  CowStr      name;
3896
  int32_t     via;
3897
  int32_t     xnodeId;
3898
  CowStr      status;
3899
  xTaskSource source;
3900
  xTaskSink   sink;
3901
  CowStr      parser;
3902
  CowStr      reason;
3903
  CowStr      updateName;
3904
  CowStr      labels;
3905
  int32_t     sqlLen;
3906
  char*       sql;
3907
} SMUpdateXnodeTaskReq;
3908
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3909
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3910
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3911

3912
typedef struct {
3913
  int32_t id;
3914
  bool    force;
3915
  CowStr  name;
3916
  int32_t sqlLen;
3917
  char*   sql;
3918
} SMDropXnodeTaskReq;
3919
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3920
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3921
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3922

3923
typedef struct {
3924
  int32_t tid;
3925
  CowStr  name;
3926
  int32_t sqlLen;
3927
  char*   sql;
3928
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3929
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3930
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3931
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3932

3933
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3934
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3935
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3936

3937
typedef struct {
3938
  int32_t tid;
3939
  int32_t via;
3940
  int32_t xnodeId;
3941
  CowStr  status;
3942
  CowStr  config;
3943
  CowStr  reason;
3944
  int32_t sqlLen;
3945
  char*   sql;
3946
} SMCreateXnodeJobReq;
3947
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3948
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3949
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3950

3951
typedef struct {
3952
  int32_t jid;
3953
  int32_t via;
3954
  int32_t xnodeId;
3955
  CowStr  status;
3956
  int32_t configLen;
3957
  int32_t reasonLen;
3958
  int32_t sqlLen;
3959
  char*   config;
3960
  char*   reason;
3961
  char*   sql;
3962
} SMUpdateXnodeJobReq;
3963
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3964
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3965
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3966

3967
typedef struct {
3968
  int32_t jid;
3969
  int32_t xnodeId;
3970
  int32_t sqlLen;
3971
  char*   sql;
3972
} SMRebalanceXnodeJobReq;
3973
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3974
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3975
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3976

3977
typedef struct {
3978
  CowStr  ast;
3979
  int32_t sqlLen;
3980
  char*   sql;
3981
} SMRebalanceXnodeJobsWhereReq;
3982
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3983
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3984
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3985

3986
typedef struct {
3987
  int32_t jid;
3988
  CowStr  ast;
3989
  int32_t sqlLen;
3990
  char*   sql;
3991
} SMDropXnodeJobReq;
3992
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3993
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3994
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3995

3996
typedef struct {
3997
  int32_t      sqlLen;
3998
  char*        sql;
3999
  CowStr       name;
4000
  CowStr       status;
4001
  xTaskOptions options;
4002
} SMCreateXnodeAgentReq;
4003
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4004
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
4005
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
4006

4007
typedef struct {
4008
  int32_t      sqlLen;
4009
  char*        sql;
4010
  int32_t      id;
4011
  CowStr       name;
4012
  xTaskOptions options;
4013
} SMUpdateXnodeAgentReq;
4014
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4015
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
4016
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
4017

4018
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4019
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4020
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4021
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4022

4023
typedef struct {
4024
  int32_t vgId;
4025
  int32_t hbSeq;
4026
} SVArbHbReqMember;
4027

4028
typedef struct {
4029
  int32_t dnodeId;
4030
  char*   arbToken;
4031
  int64_t arbTerm;
4032
  SArray* hbMembers;  // SVArbHbReqMember
4033
} SVArbHeartBeatReq;
4034

4035
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4036
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4037
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4038

4039
typedef struct {
4040
  int32_t vgId;
4041
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4042
  int32_t hbSeq;
4043
} SVArbHbRspMember;
4044

4045
typedef struct {
4046
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4047
  int32_t dnodeId;
4048
  SArray* hbMembers;  // SVArbHbRspMember
4049
} SVArbHeartBeatRsp;
4050

4051
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4052
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4053
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4054

4055
typedef struct {
4056
  char*   arbToken;
4057
  int64_t arbTerm;
4058
  char*   member0Token;
4059
  char*   member1Token;
4060
} SVArbCheckSyncReq;
4061

4062
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4063
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4064
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4065

4066
typedef struct {
4067
  char*   arbToken;
4068
  char*   member0Token;
4069
  char*   member1Token;
4070
  int32_t vgId;
4071
  int32_t errCode;
4072
} SVArbCheckSyncRsp;
4073

4074
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4075
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4076
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4077

4078
typedef struct {
4079
  char*   arbToken;
4080
  int64_t arbTerm;
4081
  char*   memberToken;
4082
  int8_t  force;
4083
} SVArbSetAssignedLeaderReq;
4084

4085
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4086
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4087
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4088

4089
typedef struct {
4090
  char* data;
4091
} SVAuditRecordReq;
4092
int32_t tSerializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4093
int32_t tDeserializeSVAuditRecordReq(void* buf, int32_t bufLen, SVAuditRecordReq* pReq);
4094
void    tFreeSVAuditRecordReq(SVAuditRecordReq* pReq);
4095

4096
typedef struct {
4097
  char*   arbToken;
4098
  char*   memberToken;
4099
  int32_t vgId;
4100
} SVArbSetAssignedLeaderRsp;
4101

4102
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4103
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4104
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4105

4106
typedef struct {
4107
  int32_t dnodeId;
4108
  char*   token;
4109
} SMArbUpdateGroupMember;
4110

4111
typedef struct {
4112
  int32_t dnodeId;
4113
  char*   token;
4114
  int8_t  acked;
4115
} SMArbUpdateGroupAssigned;
4116

4117
typedef struct {
4118
  int32_t                  vgId;
4119
  int64_t                  dbUid;
4120
  SMArbUpdateGroupMember   members[2];
4121
  int8_t                   isSync;
4122
  int8_t                   assignedAcked;
4123
  SMArbUpdateGroupAssigned assignedLeader;
4124
  int64_t                  version;
4125
  int32_t                  code;
4126
  int64_t                  updateTimeMs;
4127
} SMArbUpdateGroup;
4128

4129
typedef struct {
4130
  SArray* updateArray;  // SMArbUpdateGroup
4131
} SMArbUpdateGroupBatchReq;
4132

4133
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4134
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4135
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4136

4137
typedef struct {
4138
  char queryStrId[TSDB_QUERY_ID_LEN];
4139
} SKillQueryReq;
4140

4141
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4142
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4143

4144
typedef struct {
4145
  uint32_t connId;
4146
} SKillConnReq;
4147

4148
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4149
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4150

4151
typedef struct {
4152
  int32_t transId;
4153
} SKillTransReq;
4154

4155
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4156
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4157

4158
typedef struct {
4159
  int32_t useless;  // useless
4160
  int32_t sqlLen;
4161
  char*   sql;
4162
} SBalanceVgroupReq;
4163

4164
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4165
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4166
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4167

4168
typedef struct {
4169
  int32_t useless;  // useless
4170
  int32_t sqlLen;
4171
  char*   sql;
4172
} SAssignLeaderReq;
4173

4174
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4175
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4176
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4177
typedef struct {
4178
  int32_t vgId1;
4179
  int32_t vgId2;
4180
} SMergeVgroupReq;
4181

4182
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4183
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4184

4185
typedef struct {
4186
  int32_t vgId;
4187
  int32_t dnodeId1;
4188
  int32_t dnodeId2;
4189
  int32_t dnodeId3;
4190
  int32_t sqlLen;
4191
  char*   sql;
4192
} SRedistributeVgroupReq;
4193

4194
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4195
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4196
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4197

4198
typedef struct {
4199
  int32_t reserved;
4200
  int32_t vgId;
4201
  int32_t sqlLen;
4202
  char*   sql;
4203
  char    db[TSDB_DB_FNAME_LEN];
4204
} SBalanceVgroupLeaderReq;
4205

4206
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4207
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4208
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4209

4210
typedef struct {
4211
  int32_t vgId;
4212
} SForceBecomeFollowerReq;
4213

4214
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4215
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4216

4217
typedef struct {
4218
  int32_t vgId;
4219
  bool    force;
4220
} SSplitVgroupReq;
4221

4222
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4223
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4224

4225
typedef struct {
4226
  char user[TSDB_USER_LEN];
4227
  char spi;
4228
  char encrypt;
4229
  char secret[TSDB_PASSWORD_LEN];
4230
  char ckey[TSDB_PASSWORD_LEN];
4231
} SAuthReq, SAuthRsp;
4232

4233
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4234
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4235

4236
typedef struct {
4237
  int32_t statusCode;
4238
  char    details[1024];
4239
} SServerStatusRsp;
4240

4241
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4242
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4243

4244
/**
4245
 * The layout of the query message payload is as following:
4246
 * +--------------------+---------------------------------+
4247
 * |Sql statement       | Physical plan                   |
4248
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4249
 * +--------------------+---------------------------------+
4250
 */
4251
typedef struct SSubQueryMsg {
4252
  SMsgHead header;
4253
  uint64_t sId;
4254
  uint64_t queryId;
4255
  uint64_t clientId;
4256
  uint64_t taskId;
4257
  int64_t  refId;
4258
  int32_t  execId;
4259
  int32_t  msgMask;
4260
  int32_t  subQType;
4261
  int8_t   taskType;
4262
  int8_t   explain;
4263
  int8_t   needFetch;
4264
  int8_t   compress;
4265
  uint32_t sqlLen;
4266
  char*    sql;
4267
  uint32_t msgLen;
4268
  char*    msg;
4269
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4270
} SSubQueryMsg;
4271

4272
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4273
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4274
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4275

4276
typedef struct {
4277
  SMsgHead header;
4278
  uint64_t sId;
4279
  uint64_t queryId;
4280
  uint64_t taskId;
4281
} SSinkDataReq;
4282

4283
typedef struct {
4284
  SMsgHead header;
4285
  uint64_t sId;
4286
  uint64_t queryId;
4287
  uint64_t clientId;
4288
  uint64_t taskId;
4289
  int32_t  execId;
4290
} SQueryContinueReq;
4291

4292
typedef struct {
4293
  SMsgHead header;
4294
  uint64_t sId;
4295
  uint64_t queryId;
4296
  uint64_t taskId;
4297
} SResReadyReq;
4298

4299
typedef struct {
4300
  int32_t code;
4301
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4302
  int32_t sversion;
4303
  int32_t tversion;
4304
} SResReadyRsp;
4305

4306
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4307

4308
typedef struct SOperatorParam {
4309
  int32_t opType;
4310
  int32_t downstreamIdx;
4311
  void*   value;
4312
  SArray* pChildren;  // SArray<SOperatorParam*>
4313
  bool    reUse;
4314
} SOperatorParam;
4315

4316
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4317

4318
// virtual table's colId to origin table's colname
4319
typedef struct SColIdNameKV {
4320
  col_id_t colId;
4321
  char     colName[TSDB_COL_NAME_LEN];
4322
} SColIdNameKV;
4323

4324
#define COL_MASK_ON   ((int8_t)0x1)
4325
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4326
#define COL_SET_MASK_ON(c)     \
4327
  do {                         \
4328
    (c)->flags |= COL_MASK_ON; \
4329
  } while (0)
4330

4331
typedef struct SColNameFlag {
4332
  col_id_t colId;
4333
  char     colName[TSDB_COL_NAME_LEN];
4334
  int8_t   flags;  // 0x01: COL_MASK_ON
4335
} SColNameFlag;
4336

4337
typedef struct SColIdPair {
4338
  col_id_t  vtbColId;
4339
  col_id_t  orgColId;
4340
  SDataType type;
4341
} SColIdPair;
4342

4343
typedef struct SColIdSlotIdPair {
4344
  int32_t  vtbSlotId;
4345
  col_id_t orgColId;
4346
} SColIdSlotIdPair;
4347

4348
typedef struct SOrgTbInfo {
4349
  int32_t vgId;
4350
  char    tbName[TSDB_TABLE_FNAME_LEN];
4351
  SArray* colMap;  // SArray<SColIdNameKV>
4352
} SOrgTbInfo;
4353

4354
void destroySOrgTbInfo(void *info);
4355

4356
typedef enum {
4357
  DYN_TYPE_STB_JOIN = 1,
4358
  DYN_TYPE_VSTB_SINGLE_SCAN,
4359
  DYN_TYPE_VSTB_BATCH_SCAN,
4360
  DYN_TYPE_VSTB_WIN_SCAN,
4361
} ETableScanDynType;
4362

4363
typedef enum {
4364
  DYN_TYPE_SCAN_PARAM = 1,
4365
  NOTIFY_TYPE_SCAN_PARAM,
4366
} ETableScanGetParamType;
4367

4368
typedef struct STableScanOperatorParam {
4369
  ETableScanGetParamType paramType;
4370
  /* for building scan data source */
4371
  bool                   tableSeq;
4372
  bool                   isNewParam;
4373
  uint64_t               groupid;
4374
  SArray*                pUidList;
4375
  SOrgTbInfo*            pOrgTbInfo;
4376
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4377
  SArray*                pTagList;
4378
  STimeWindow            window;
4379
  ETableScanDynType      dynType;
4380
  /* for notifying source step done */
4381
  bool                   notifyToProcess;  // received notify STEP DONE message
4382
  TSKEY                  notifyTs;         // notify timestamp
4383
} STableScanOperatorParam;
4384

4385
typedef struct STagScanOperatorParam {
4386
  tb_uid_t vcUid;
4387
} STagScanOperatorParam;
4388

4389
typedef struct SRefColIdGroup {
4390
  SArray* pSlotIdList;  // SArray<int32_t>
4391
} SRefColIdGroup;
4392

4393
typedef struct SVTableScanOperatorParam {
4394
  uint64_t        uid;
4395
  STimeWindow     window;
4396
  SOperatorParam* pTagScanOp;
4397
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4398
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4399
} SVTableScanOperatorParam;
4400

4401
typedef struct SMergeOperatorParam {
4402
  int32_t         winNum;
4403
} SMergeOperatorParam;
4404

4405
typedef struct SAggOperatorParam {
4406
  bool            needCleanRes;
4407
} SAggOperatorParam;
4408

4409
typedef struct SExternalWindowOperatorParam {
4410
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4411
} SExternalWindowOperatorParam;
4412

4413
typedef struct SDynQueryCtrlOperatorParam {
4414
  STimeWindow    window;
4415
} SDynQueryCtrlOperatorParam;
4416

4417
struct SStreamRuntimeFuncInfo;
4418
typedef struct {
4419
  SMsgHead        header;
4420
  uint64_t        sId;
4421
  uint64_t        queryId;
4422
  uint64_t        clientId;
4423
  uint64_t        taskId;
4424
  uint64_t        srcTaskId;  // used for subQ
4425
  uint64_t        blockIdx;   // used for subQ
4426
  int32_t         execId;
4427
  SOperatorParam* pOpParam;
4428

4429
  // used for new-stream
4430
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4431
  bool                           reset;
4432
  bool                           dynTbname;
4433
  // used for new-stream
4434
} SResFetchReq;
4435

4436
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4437
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4438
void    tDestroySResFetchReq(SResFetchReq* pReq);
4439
typedef struct {
4440
  SMsgHead header;
4441
  uint64_t clientId;
4442
} SSchTasksStatusReq;
4443

4444
typedef struct {
4445
  uint64_t queryId;
4446
  uint64_t clientId;
4447
  uint64_t taskId;
4448
  int64_t  refId;
4449
  int32_t  subJobId;
4450
  int32_t  execId;
4451
  int8_t   status;
4452
} STaskStatus;
4453

4454
typedef struct {
4455
  int64_t refId;
4456
  SArray* taskStatus;  // SArray<STaskStatus>
4457
} SSchedulerStatusRsp;
4458

4459
typedef struct {
4460
  uint64_t queryId;
4461
  uint64_t taskId;
4462
  int8_t   action;
4463
} STaskAction;
4464

4465
typedef struct SQueryNodeEpId {
4466
  int32_t nodeId;  // vgId or qnodeId
4467
  SEp     ep;
4468
} SQueryNodeEpId;
4469

4470
typedef struct {
4471
  SMsgHead       header;
4472
  uint64_t       clientId;
4473
  SQueryNodeEpId epId;
4474
  SArray*        taskAction;  // SArray<STaskAction>
4475
} SSchedulerHbReq;
4476

4477
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4478
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4479
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4480

4481
typedef struct {
4482
  SQueryNodeEpId epId;
4483
  SArray*        taskStatus;  // SArray<STaskStatus>
4484
} SSchedulerHbRsp;
4485

4486
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4487
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4488
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4489

4490
typedef struct {
4491
  SMsgHead header;
4492
  uint64_t sId;
4493
  uint64_t queryId;
4494
  uint64_t clientId;
4495
  uint64_t taskId;
4496
  int64_t  refId;
4497
  int32_t  execId;
4498
} STaskCancelReq;
4499

4500
typedef struct {
4501
  int32_t code;
4502
} STaskCancelRsp;
4503

4504
typedef struct {
4505
  SMsgHead header;
4506
  uint64_t sId;
4507
  uint64_t queryId;
4508
  uint64_t clientId;
4509
  uint64_t taskId;
4510
  int64_t  refId;
4511
  int32_t  execId;
4512
} STaskDropReq;
4513

4514
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4515
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4516

4517
typedef enum {
4518
  TASK_NOTIFY_FINISHED = 1,
4519
} ETaskNotifyType;
4520

4521
typedef struct {
4522
  SMsgHead        header;
4523
  uint64_t        sId;
4524
  uint64_t        queryId;
4525
  uint64_t        clientId;
4526
  uint64_t        taskId;
4527
  int64_t         refId;
4528
  int32_t         execId;
4529
  ETaskNotifyType type;
4530
} STaskNotifyReq;
4531

4532
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4533
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4534

4535
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4536
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4537

4538
typedef struct {
4539
  int32_t code;
4540
} STaskDropRsp;
4541

4542
#define STREAM_TRIGGER_AT_ONCE                 1
4543
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4544
#define STREAM_TRIGGER_MAX_DELAY               3
4545
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4546
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4547

4548
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4549
#define STREAM_FILL_HISTORY_ON        1
4550
#define STREAM_FILL_HISTORY_OFF       0
4551
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4552
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4553
#define STREAM_CREATE_STABLE_TRUE     1
4554
#define STREAM_CREATE_STABLE_FALSE    0
4555

4556
typedef struct SVgroupVer {
4557
  int32_t vgId;
4558
  int64_t ver;
4559
} SVgroupVer;
4560

4561
enum {
4562
  TOPIC_SUB_TYPE__DB = 1,
4563
  TOPIC_SUB_TYPE__TABLE,
4564
  TOPIC_SUB_TYPE__COLUMN,
4565
};
4566

4567
#define DEFAULT_MAX_POLL_INTERVAL  300000
4568
#define DEFAULT_SESSION_TIMEOUT    12000
4569
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4570
#define DEFAULT_MIN_POLL_ROWS      4096
4571

4572
typedef struct {
4573
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4574
  int8_t igExists;
4575
  int8_t subType;
4576
  int8_t withMeta;
4577
  char*  sql;
4578
  char   subDbName[TSDB_DB_FNAME_LEN];
4579
  char*  ast;
4580
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4581
  int8_t reload;
4582
} SCMCreateTopicReq;
4583

4584
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4585
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4586
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4587

4588
typedef struct {
4589
  int64_t consumerId;
4590
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4591

4592
typedef struct {
4593
  int64_t consumerId;
4594
  char    cgroup[TSDB_CGROUP_LEN];
4595
  char    clientId[TSDB_CLIENT_ID_LEN];
4596
  char    user[TSDB_USER_LEN];
4597
  char    fqdn[TSDB_FQDN_LEN];
4598
  SArray* topicNames;  // SArray<char**>
4599

4600
  int8_t  withTbName;
4601
  int8_t  autoCommit;
4602
  int32_t autoCommitInterval;
4603
  int8_t  resetOffsetCfg;
4604
  int8_t  enableReplay;
4605
  int8_t  enableBatchMeta;
4606
  int32_t sessionTimeoutMs;
4607
  int32_t maxPollIntervalMs;
4608
  int64_t ownerId;
4609
} SCMSubscribeReq;
4610

4611
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4612
  int32_t tlen = 0;
666,008✔
4613
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
666,008✔
4614
  tlen += taosEncodeString(buf, pReq->cgroup);
666,008✔
4615
  tlen += taosEncodeString(buf, pReq->clientId);
666,008✔
4616

4617
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
666,008✔
4618
  tlen += taosEncodeFixedI32(buf, topicNum);
666,008✔
4619

4620
  for (int32_t i = 0; i < topicNum; i++) {
921,730✔
4621
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
511,444✔
4622
  }
4623

4624
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
666,008✔
4625
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
666,008✔
4626
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
666,008✔
4627
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
666,008✔
4628
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
666,008✔
4629
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
666,008✔
4630
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
666,008✔
4631
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
666,008✔
4632
  tlen += taosEncodeString(buf, pReq->user);
666,008✔
4633
  tlen += taosEncodeString(buf, pReq->fqdn);
666,008✔
4634

4635
  return tlen;
666,008✔
4636
}
4637

4638
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4639
  void* start = buf;
346,371✔
4640
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
346,371✔
4641
  buf = taosDecodeStringTo(buf, pReq->cgroup);
346,371✔
4642
  buf = taosDecodeStringTo(buf, pReq->clientId);
346,371✔
4643

4644
  int32_t topicNum = 0;
346,371✔
4645
  buf = taosDecodeFixedI32(buf, &topicNum);
346,371✔
4646

4647
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
346,371✔
4648
  if (pReq->topicNames == NULL) {
346,371✔
UNCOV
4649
    return terrno;
×
4650
  }
4651
  for (int32_t i = 0; i < topicNum; i++) {
501,108✔
4652
    char* name = NULL;
154,737✔
4653
    buf = taosDecodeString(buf, &name);
154,737✔
4654
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
309,474✔
UNCOV
4655
      return terrno;
×
4656
    }
4657
  }
4658

4659
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
346,371✔
4660
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
346,371✔
4661
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
346,371✔
4662
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
346,371✔
4663
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
346,371✔
4664
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
346,371✔
4665
  if ((char*)buf - (char*)start < len) {
346,371✔
4666
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
346,371✔
4667
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
346,371✔
4668
    buf = taosDecodeStringTo(buf, pReq->user);
346,371✔
4669
    buf = taosDecodeStringTo(buf, pReq->fqdn);
692,742✔
4670
  } else {
UNCOV
4671
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4672
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4673
  }
4674

4675
  return 0;
346,371✔
4676
}
4677

4678
typedef struct {
4679
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4680
  SArray* removedConsumers;  // SArray<int64_t>
4681
  SArray* newConsumers;      // SArray<int64_t>
4682
} SMqRebInfo;
4683

4684
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4685
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
316,928✔
4686
  if (pRebInfo == NULL) {
316,928✔
UNCOV
4687
    return NULL;
×
4688
  }
4689
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
316,928✔
4690
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
316,928✔
4691
  if (pRebInfo->removedConsumers == NULL) {
316,928✔
4692
    goto _err;
×
4693
  }
4694
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
316,928✔
4695
  if (pRebInfo->newConsumers == NULL) {
316,928✔
4696
    goto _err;
×
4697
  }
4698
  return pRebInfo;
316,928✔
4699
_err:
×
UNCOV
4700
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
4701
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
4702
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
4703
  return NULL;
×
4704
}
4705

4706
typedef struct {
4707
  int64_t streamId;
4708
  int64_t checkpointId;
4709
  char    streamName[TSDB_STREAM_FNAME_LEN];
4710
} SMStreamDoCheckpointMsg;
4711

4712
typedef struct {
4713
  int64_t status;
4714
} SMVSubscribeRsp;
4715

4716
typedef struct {
4717
  char    name[TSDB_TOPIC_FNAME_LEN];
4718
  int8_t  igNotExists;
4719
  int32_t sqlLen;
4720
  char*   sql;
4721
  int8_t  force;
4722
} SMDropTopicReq;
4723

4724
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4725
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4726
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4727

4728
typedef struct {
4729
  char    name[TSDB_TOPIC_FNAME_LEN];
4730
  int8_t  igNotExists;
4731
  int32_t sqlLen;
4732
  char*   sql;
4733
} SMReloadTopicReq;
4734

4735
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4736
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4737
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4738

4739
typedef struct {
4740
  char   topic[TSDB_TOPIC_FNAME_LEN];
4741
  char   cgroup[TSDB_CGROUP_LEN];
4742
  int8_t igNotExists;
4743
  int8_t force;
4744
} SMDropCgroupReq;
4745

4746
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4747
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4748

4749
typedef struct {
4750
  int8_t reserved;
4751
} SMDropCgroupRsp;
4752

4753
typedef struct {
4754
  char    name[TSDB_TABLE_FNAME_LEN];
4755
  int8_t  alterType;
4756
  SSchema schema;
4757
} SAlterTopicReq;
4758

4759
typedef struct {
4760
  SMsgHead head;
4761
  char     name[TSDB_TABLE_FNAME_LEN];
4762
  int64_t  tuid;
4763
  int32_t  sverson;
4764
  int32_t  execLen;
4765
  char*    executor;
4766
  int32_t  sqlLen;
4767
  char*    sql;
4768
} SDCreateTopicReq;
4769

4770
typedef struct {
4771
  SMsgHead head;
4772
  char     name[TSDB_TABLE_FNAME_LEN];
4773
  int64_t  tuid;
4774
} SDDropTopicReq;
4775

4776
typedef struct {
4777
  char*      name;
4778
  int64_t    uid;
4779
  int64_t    interval[2];
4780
  int8_t     intervalUnit;
4781
  int16_t    nFuncs;
4782
  col_id_t*  funcColIds;  // column ids specified by user
4783
  func_id_t* funcIds;     // function ids specified by user
4784
} SRSmaParam;
4785

4786
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4787
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4788

4789
// TDMT_VND_CREATE_STB ==============
4790
typedef struct SVCreateStbReq {
4791
  char*           name;
4792
  tb_uid_t        suid;
4793
  int8_t          rollup;
4794
  SSchemaWrapper  schemaRow;
4795
  SSchemaWrapper  schemaTag;
4796
  SRSmaParam      rsmaParam;
4797
  int32_t         alterOriDataLen;
4798
  void*           alterOriData;
4799
  int8_t          source;
4800
  int8_t          colCmpred;
4801
  SColCmprWrapper colCmpr;
4802
  int64_t         keep;
4803
  int64_t         ownerId;
4804
  SExtSchema*     pExtSchemas;
4805
  int8_t          virtualStb;
4806
  int8_t          secureDelete;
4807
} SVCreateStbReq;
4808

4809
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4810
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4811

4812
// TDMT_VND_DROP_STB ==============
4813
typedef struct SVDropStbReq {
4814
  char*    name;
4815
  tb_uid_t suid;
4816
} SVDropStbReq;
4817

4818
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4819
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4820

4821
// TDMT_VND_CREATE_TABLE ==============
4822
#define TD_CREATE_IF_NOT_EXISTS       0x1
4823
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4824
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4825
typedef struct SVCreateTbReq {
4826
  int32_t  flags;
4827
  char*    name;
4828
  tb_uid_t uid;
4829
  int64_t  btime;
4830
  int32_t  ttl;
4831
  int32_t  commentLen;
4832
  char*    comment;
4833
  int8_t   type;
4834
  union {
4835
    struct {
4836
      char*    stbName;  // super table name
4837
      uint8_t  tagNum;
4838
      tb_uid_t suid;
4839
      SArray*  tagName;
4840
      uint8_t* pTag;
4841
    } ctb;
4842
    struct {
4843
      SSchemaWrapper schemaRow;
4844
      int64_t        userId;
4845
    } ntb;
4846
  };
4847
  int32_t         sqlLen;
4848
  char*           sql;
4849
  SColCmprWrapper colCmpr;
4850
  SExtSchema*     pExtSchemas;
4851
  SColRefWrapper  colRef;  // col reference for virtual table
4852
} SVCreateTbReq;
4853

4854
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4855
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4856
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4857
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4858

4859
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4860
  if (NULL == req) {
2,147,483,647✔
4861
    return;
2,147,483,647✔
4862
  }
4863

4864
  taosMemoryFreeClear(req->sql);
81,363,205✔
4865
  taosMemoryFreeClear(req->name);
81,358,169✔
4866
  taosMemoryFreeClear(req->comment);
81,367,012✔
4867
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
81,362,450✔
4868
    taosMemoryFreeClear(req->ctb.pTag);
74,054,409✔
4869
    taosMemoryFreeClear(req->ctb.stbName);
74,044,561✔
4870
    taosArrayDestroy(req->ctb.tagName);
74,043,403✔
4871
    req->ctb.tagName = NULL;
74,015,640✔
4872
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
7,309,495✔
4873
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
7,309,495✔
4874
  }
4875
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
81,337,971✔
4876
  taosMemoryFreeClear(req->pExtSchemas);
81,359,497✔
4877
  taosMemoryFreeClear(req->colRef.pColRef);
81,360,811✔
4878
}
4879

4880
typedef struct {
4881
  int32_t nReqs;
4882
  union {
4883
    SVCreateTbReq* pReqs;
4884
    SArray*        pArray;
4885
  };
4886
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4887
} SVCreateTbBatchReq;
4888

4889
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4890
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4891
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4892

4893
typedef struct {
4894
  int32_t        code;
4895
  STableMetaRsp* pMeta;
4896
} SVCreateTbRsp, SVUpdateTbRsp;
4897

4898
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4899
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4900
void tFreeSVCreateTbRsp(void* param);
4901

4902
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4903
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4904

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

4913
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4914
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4915

4916
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4917
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4918

4919
// TDMT_VND_DROP_TABLE =================
4920
typedef struct {
4921
  char*    name;
4922
  uint64_t suid;  // for tmq in wal format
4923
  int64_t  uid;
4924
  int8_t   igNotExists;
4925
  int8_t   isVirtual;
4926
} SVDropTbReq;
4927

4928
typedef struct {
4929
  int32_t code;
4930
} SVDropTbRsp;
4931

4932
typedef struct {
4933
  int32_t nReqs;
4934
  union {
4935
    SVDropTbReq* pReqs;
4936
    SArray*      pArray;
4937
  };
4938
} SVDropTbBatchReq;
4939

4940
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4941
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4942

4943
typedef struct {
4944
  int32_t nRsps;
4945
  union {
4946
    SVDropTbRsp* pRsps;
4947
    SArray*      pArray;
4948
  };
4949
} SVDropTbBatchRsp;
4950

4951
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4952
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4953

4954
// TDMT_VND_ALTER_TABLE =====================
4955
typedef struct SUpdatedTagVal {
4956
  char*    tagName;
4957
  int32_t  colId;
4958
  int8_t   tagType;
4959
  int8_t   tagFree;
4960
  uint32_t nTagVal;
4961
  uint8_t* pTagVal;
4962
  int8_t   isNull;
4963
  SArray*  pTagArray;
4964
  // NOTE: regexp and replacement are only a temporary solution for tag value update,
4965
  // they should be replaced by a more generic solution in the future for full expression
4966
  // support
4967
  char*    regexp;
4968
  char*    replacement;
4969
} SUpdatedTagVal;
4970

4971
typedef struct SUpdateTableTagVal {
4972
  char *tbName;
4973
  SArray* tags; // Array of SUpdatedTagVal
4974
} SUpdateTableTagVal;
4975

4976
typedef struct SVAlterTbReq {
4977
  char*   tbName;
4978
  int8_t  action;
4979
  char*   colName;
4980
  int32_t colId;
4981
  // TSDB_ALTER_TABLE_ADD_COLUMN
4982
  int8_t  type;
4983
  int8_t  flags;
4984
  int32_t bytes;
4985
  // TSDB_ALTER_TABLE_DROP_COLUMN
4986
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4987
  int8_t   colModType;
4988
  int32_t  colModBytes;
4989
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4990
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4991
  int8_t   isNull;
4992
  int8_t   tagType;
4993
  int8_t   tagFree;
4994
  uint32_t nTagVal;
4995
  uint8_t* pTagVal;
4996
  SArray*  pTagArray;
4997
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4998
  int8_t   updateTTL;
4999
  int32_t  newTTL;
5000
  int32_t  newCommentLen;
5001
  char*    newComment;
5002
  int64_t  ctimeMs;    // fill by vnode
5003
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
5004
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
5005
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS and TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL
5006
  SArray*  tables;     // Array of SUpdateTableTagVal, for TSDB_ALTER_TABLE_UPDATE_MULTI_TABLE_TAG_VAL
5007
  int32_t  whereLen;   // [whereLen] & [where] are for TSDB_ALTER_TABLE_UPDATE_CHILD_TABLE_TAG_VAL,
5008
  uint8_t* where;      // [where] is the encode where condition.
5009
  // for Add column
5010
  STypeMod typeMod;
5011
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
5012
  char* refDbName;
5013
  char* refTbName;
5014
  char* refColName;
5015
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
5016
} SVAlterTbReq;
5017

5018
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
5019
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
5020
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
5021
void    tfreeMultiTagUpateVal(void* pMultiTag);
5022
void    tfreeUpdateTableTagVal(void* pMultiTable);
5023

5024
typedef struct {
5025
  int32_t        code;
5026
  STableMetaRsp* pMeta;
5027
} SVAlterTbRsp;
5028

5029
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
5030
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
5031
// ======================
5032

5033
typedef struct {
5034
  SMsgHead head;
5035
  int64_t  uid;
5036
  int32_t  tid;
5037
  int16_t  tversion;
5038
  int16_t  colId;
5039
  int8_t   type;
5040
  int16_t  bytes;
5041
  int32_t  tagValLen;
5042
  int16_t  numOfTags;
5043
  int32_t  schemaLen;
5044
  char     data[];
5045
} SUpdateTagValReq;
5046

5047
typedef struct {
5048
  SMsgHead head;
5049
} SUpdateTagValRsp;
5050

5051
typedef struct {
5052
  SMsgHead head;
5053
} SVShowTablesReq;
5054

5055
typedef struct {
5056
  SMsgHead head;
5057
  int32_t  id;
5058
} SVShowTablesFetchReq;
5059

5060
typedef struct {
5061
  int64_t useconds;
5062
  int8_t  completed;  // all results are returned to client
5063
  int8_t  precision;
5064
  int8_t  compressed;
5065
  int32_t compLen;
5066
  int32_t numOfRows;
5067
  char    data[];
5068
} SVShowTablesFetchRsp;
5069

5070
typedef struct {
5071
  int64_t consumerId;
5072
  int32_t epoch;
5073
  char    cgroup[TSDB_CGROUP_LEN];
5074
} SMqAskEpReq;
5075

5076
typedef struct {
5077
  int32_t key;
5078
  int32_t valueLen;
5079
  void*   value;
5080
} SKv;
5081

5082
typedef struct {
5083
  int64_t tscRid;
5084
  int8_t  connType;
5085
} SClientHbKey;
5086

5087
typedef struct {
5088
  int64_t tid;
5089
  char    status[TSDB_JOB_STATUS_LEN];
5090
} SQuerySubDesc;
5091

5092
typedef struct {
5093
  char     sql[TSDB_SHOW_SQL_LEN];
5094
  uint64_t queryId;
5095
  int64_t  useconds;
5096
  int64_t  stime;  // timestamp precision ms
5097
  int64_t  reqRid;
5098
  bool     stableQuery;
5099
  bool     isSubQuery;
5100
  char     fqdn[TSDB_FQDN_LEN];
5101
  int32_t  subPlanNum;
5102
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5103
} SQueryDesc;
5104

5105
typedef struct {
5106
  uint32_t connId;
5107
  SArray*  queryDesc;  // SArray<SQueryDesc>
5108
} SQueryHbReqBasic;
5109

5110
typedef struct {
5111
  uint32_t connId;
5112
  uint64_t killRid;
5113
  int32_t  totalDnodes;
5114
  int32_t  onlineDnodes;
5115
  int8_t   killConnection;
5116
  int8_t   align[3];
5117
  SEpSet   epSet;
5118
  SArray*  pQnodeList;
5119
} SQueryHbRspBasic;
5120

5121
typedef struct SAppClusterSummary {
5122
  uint64_t numOfInsertsReq;
5123
  uint64_t numOfInsertRows;
5124
  uint64_t insertElapsedTime;
5125
  uint64_t insertBytes;  // submit to tsdb since launched.
5126

5127
  uint64_t fetchBytes;
5128
  uint64_t numOfQueryReq;
5129
  uint64_t queryElapsedTime;
5130
  uint64_t numOfSlowQueries;
5131
  uint64_t totalRequests;
5132
  uint64_t currentRequests;  // the number of SRequestObj
5133
} SAppClusterSummary;
5134

5135
typedef struct {
5136
  int64_t            appId;
5137
  int32_t            pid;
5138
  char               name[TSDB_APP_NAME_LEN];
5139
  int64_t            startTime;
5140
  SAppClusterSummary summary;
5141
} SAppHbReq;
5142

5143
typedef struct {
5144
  SClientHbKey      connKey;
5145
  int64_t           clusterId;
5146
  SAppHbReq         app;
5147
  SQueryHbReqBasic* query;
5148
  SHashObj*         info;  // hash<Skv.key, Skv>
5149
  char              user[TSDB_USER_LEN];
5150
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5151
  char              userApp[TSDB_APP_NAME_LEN];
5152
  uint32_t          userIp;
5153
  SIpRange          userDualIp;
5154
  char              sVer[TSDB_VERSION_LEN];
5155
  char              cInfo[CONNECTOR_INFO_LEN];
5156
} SClientHbReq;
5157

5158
typedef struct {
5159
  int64_t reqId;
5160
  SArray* reqs;  // SArray<SClientHbReq>
5161
  int64_t ipWhiteListVer;
5162
} SClientHbBatchReq;
5163

5164
typedef struct {
5165
  SClientHbKey      connKey;
5166
  int32_t           status;
5167
  SQueryHbRspBasic* query;
5168
  SArray*           info;  // Array<Skv>
5169
} SClientHbRsp;
5170

5171
typedef struct {
5172
  int64_t       reqId;
5173
  int64_t       rspId;
5174
  int32_t       svrTimestamp;
5175
  SArray*       rsps;  // SArray<SClientHbRsp>
5176
  SMonitorParas monitorParas;
5177
  int8_t        enableAuditDelete;
5178
  int8_t        enableStrongPass;
5179
  int8_t        enableAuditSelect;
5180
  int8_t        enableAuditInsert;
5181
  int8_t        auditLevel;
5182
} SClientHbBatchRsp;
5183

5184
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
412,067,252✔
5185

5186
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5187
  void* pIter = taosHashIterate(info, NULL);
57,681,882✔
5188
  while (pIter != NULL) {
134,777,217✔
5189
    SKv* kv = (SKv*)pIter;
77,093,724✔
5190
    taosMemoryFreeClear(kv->value);
77,093,724✔
5191
    pIter = taosHashIterate(info, pIter);
77,092,373✔
5192
  }
5193
}
57,683,493✔
5194

5195
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
38,384,906✔
5196
  SQueryDesc* desc = (SQueryDesc*)pDesc;
38,384,906✔
5197
  if (desc->subDesc) {
38,384,906✔
5198
    taosArrayDestroy(desc->subDesc);
26,832,973✔
5199
    desc->subDesc = NULL;
26,830,947✔
5200
  }
5201
}
38,383,885✔
5202

5203
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
66,216,143✔
5204
  SClientHbReq* req = (SClientHbReq*)pReq;
151,364,564✔
5205
  if (req->query) {
151,364,564✔
5206
    if (req->query->queryDesc) {
66,215,345✔
5207
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
30,622,679✔
5208
    }
5209
    taosMemoryFreeClear(req->query);
66,215,284✔
5210
  }
5211

5212
  if (req->info) {
151,361,488✔
5213
    tFreeReqKvHash(req->info);
57,679,064✔
5214
    taosHashCleanup(req->info);
57,683,493✔
5215
    req->info = NULL;
57,680,967✔
5216
  }
5217
}
117,162,602✔
5218

5219
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5220
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5221

5222
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5223
  if (pReq == NULL) return;
28,063,513✔
5224
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
28,063,513✔
5225
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
28,063,513✔
5226
  taosMemoryFree(pReq);
28,063,513✔
5227
}
5228

5229
static FORCE_INLINE void tFreeClientKv(void* pKv) {
76,805,215✔
5230
  SKv* kv = (SKv*)pKv;
76,805,215✔
5231
  if (kv) {
76,805,215✔
5232
    taosMemoryFreeClear(kv->value);
76,805,600✔
5233
  }
5234
}
76,803,520✔
5235

5236
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
65,913,429✔
5237
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
65,913,429✔
5238
  if (rsp->query) {
65,913,429✔
5239
    taosArrayDestroy(rsp->query->pQnodeList);
65,905,232✔
5240
    taosMemoryFreeClear(rsp->query);
65,906,826✔
5241
  }
5242
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
65,915,290✔
5243
}
33,904,294✔
5244

5245
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5246
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
54,453,116✔
5247
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
54,453,116✔
5248
}
54,451,157✔
5249

5250
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5251
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5252
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5253

5254
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5255
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
479,916,814✔
5256
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
479,915,375✔
5257
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
479,918,434✔
5258
  return 0;
239,962,672✔
5259
}
5260

5261
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5262
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
157,859,078✔
5263
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
157,860,360✔
5264
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
78,930,180✔
5265
  if (pKv->value == NULL) {
78,928,959✔
UNCOV
5266
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5267
  }
5268
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
78,929,702✔
5269
  return 0;
78,929,610✔
5270
}
5271

5272
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5273
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
413,632,816✔
5274
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
413,627,970✔
5275
  return 0;
206,816,324✔
5276
}
5277

5278
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5279
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
135,872,931✔
5280
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
135,877,884✔
5281
  return 0;
67,943,570✔
5282
}
5283

5284
typedef struct {
5285
  int32_t vgId;
5286
  // TODO stas
5287
} SMqReportVgInfo;
5288

5289
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5290
  int32_t tlen = 0;
5291
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5292
  return tlen;
5293
}
5294

5295
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5296
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5297
  return buf;
5298
}
5299

5300
typedef struct {
5301
  int32_t epoch;
5302
  int64_t topicUid;
5303
  char    name[TSDB_TOPIC_FNAME_LEN];
5304
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5305
} SMqTopicInfo;
5306

5307
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5308
  int32_t tlen = 0;
5309
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5310
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5311
  tlen += taosEncodeString(buf, pTopicInfo->name);
5312
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5313
  tlen += taosEncodeFixedI32(buf, sz);
5314
  for (int32_t i = 0; i < sz; i++) {
5315
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5316
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5317
  }
5318
  return tlen;
5319
}
5320

5321
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5322
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5323
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5324
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5325
  int32_t sz;
5326
  buf = taosDecodeFixedI32(buf, &sz);
5327
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5328
    return NULL;
5329
  }
5330
  for (int32_t i = 0; i < sz; i++) {
5331
    SMqReportVgInfo vgInfo;
5332
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5333
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5334
      return NULL;
5335
    }
5336
  }
5337
  return buf;
5338
}
5339

5340
typedef struct {
5341
  int32_t status;  // ask hb endpoint
5342
  int32_t epoch;
5343
  int64_t consumerId;
5344
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5345
} SMqReportReq;
5346

5347
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5348
  int32_t tlen = 0;
5349
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5350
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5351
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5352
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5353
  tlen += taosEncodeFixedI32(buf, sz);
5354
  for (int32_t i = 0; i < sz; i++) {
5355
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5356
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5357
  }
5358
  return tlen;
5359
}
5360

5361
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5362
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5363
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5364
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5365
  int32_t sz;
5366
  buf = taosDecodeFixedI32(buf, &sz);
5367
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5368
    return NULL;
5369
  }
5370
  for (int32_t i = 0; i < sz; i++) {
5371
    SMqTopicInfo topicInfo;
5372
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5373
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5374
      return NULL;
5375
    }
5376
  }
5377
  return buf;
5378
}
5379

5380
typedef struct {
5381
  SMsgHead head;
5382
  int64_t  leftForVer;
5383
  int32_t  vgId;
5384
  int64_t  consumerId;
5385
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5386
} SMqVDeleteReq;
5387

5388
typedef struct {
5389
  int8_t reserved;
5390
} SMqVDeleteRsp;
5391

5392
typedef struct {
5393
  char**  name;
5394
  int32_t count;
5395
  int8_t igNotExists;
5396
} SMDropStreamReq;
5397

5398
typedef struct {
5399
  int8_t reserved;
5400
} SMDropStreamRsp;
5401

5402
typedef struct {
5403
  SMsgHead head;
5404
  int64_t  resetRelHalt;  // reset related stream task halt status
5405
  int64_t  streamId;
5406
  int32_t  taskId;
5407
} SVDropStreamTaskReq;
5408

5409
typedef struct {
5410
  int8_t reserved;
5411
} SVDropStreamTaskRsp;
5412

5413
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5414
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5415
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5416

5417
typedef struct {
5418
  char*  name;
5419
  int8_t igNotExists;
5420
} SMPauseStreamReq;
5421

5422
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5423
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5424
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5425

5426
typedef struct {
5427
  char*  name;
5428
  int8_t igNotExists;
5429
  int8_t igUntreated;
5430
} SMResumeStreamReq;
5431

5432
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5433
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5434
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5435

5436
typedef struct {
5437
  char*       name;
5438
  int8_t      calcAll;
5439
  STimeWindow timeRange;
5440
} SMRecalcStreamReq;
5441

5442
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5443
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5444
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5445

5446

5447
typedef struct SVndSetKeepVersionReq {
5448
  int64_t keepVersion;
5449
} SVndSetKeepVersionReq;
5450

5451
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5452
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5453

5454
typedef struct SVUpdateCheckpointInfoReq {
5455
  SMsgHead head;
5456
  int64_t  streamId;
5457
  int32_t  taskId;
5458
  int64_t  checkpointId;
5459
  int64_t  checkpointVer;
5460
  int64_t  checkpointTs;
5461
  int32_t  transId;
5462
  int64_t  hStreamId;  // add encode/decode
5463
  int64_t  hTaskId;
5464
  int8_t   dropRelHTask;
5465
} SVUpdateCheckpointInfoReq;
5466

5467
typedef struct {
5468
  int64_t leftForVer;
5469
  int32_t vgId;
5470
  int64_t oldConsumerId;
5471
  int64_t newConsumerId;
5472
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5473
  int8_t  subType;
5474
  int8_t  withMeta;
5475
  char*   qmsg;  // SubPlanToString
5476
  SSchemaWrapper schema;
5477
  int64_t suid;
5478
} SMqRebVgReq;
5479

5480
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5481
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5482

5483
// tqOffset
5484
enum {
5485
  TMQ_OFFSET__RESET_NONE = -3,
5486
  TMQ_OFFSET__RESET_EARLIEST = -2,
5487
  TMQ_OFFSET__RESET_LATEST = -1,
5488
  TMQ_OFFSET__LOG = 1,
5489
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5490
  TMQ_OFFSET__SNAPSHOT_META = 3,
5491
};
5492

5493
enum {
5494
  WITH_DATA = 0,
5495
  WITH_META = 1,
5496
  ONLY_META = 2,
5497
};
5498

5499
#define TQ_OFFSET_VERSION 1
5500

5501
typedef struct {
5502
  int8_t type;
5503
  union {
5504
    // snapshot
5505
    struct {
5506
      int64_t uid;
5507
      int64_t ts;
5508
      SValue  primaryKey;
5509
    };
5510
    // log
5511
    struct {
5512
      int64_t version;
5513
    };
5514
  };
5515
} STqOffsetVal;
5516

5517
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5518
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
8,030,318✔
5519
  pOffsetVal->uid = uid;
8,029,053✔
5520
  pOffsetVal->ts = ts;
8,029,028✔
5521
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
8,029,672✔
5522
    taosMemoryFree(pOffsetVal->primaryKey.pData);
318✔
5523
  }
5524
  pOffsetVal->primaryKey = primaryKey;
8,027,119✔
5525
}
8,029,033✔
5526

5527
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5528
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
11,941✔
5529
  pOffsetVal->uid = uid;
11,941✔
5530
}
11,941✔
5531

5532
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5533
  pOffsetVal->type = TMQ_OFFSET__LOG;
31,247,611✔
5534
  pOffsetVal->version = ver;
31,246,949✔
5535
}
31,247,285✔
5536

5537
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5538
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5539
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5540
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5541
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5542
void    tOffsetDestroy(void* pVal);
5543

5544
typedef struct {
5545
  STqOffsetVal val;
5546
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5547
} STqOffset;
5548

5549
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5550
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5551
void    tDeleteSTqOffset(void* val);
5552

5553
typedef struct SMqVgOffset {
5554
  int64_t   consumerId;
5555
  STqOffset offset;
5556
} SMqVgOffset;
5557

5558
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5559
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5560

5561
typedef struct {
5562
  char    name[TSDB_TABLE_FNAME_LEN];
5563
  char    stb[TSDB_TABLE_FNAME_LEN];
5564
  int8_t  igExists;
5565
  int8_t  intervalUnit;
5566
  int8_t  slidingUnit;
5567
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5568
  int32_t dstVgId;   // for stream
5569
  int64_t interval;
5570
  int64_t offset;
5571
  int64_t sliding;
5572
  int64_t maxDelay;
5573
  int64_t watermark;
5574
  int32_t exprLen;        // strlen + 1
5575
  int32_t tagsFilterLen;  // strlen + 1
5576
  int32_t sqlLen;         // strlen + 1
5577
  int32_t astLen;         // strlen + 1
5578
  char*   expr;
5579
  char*   tagsFilter;
5580
  char*   sql;
5581
  char*   ast;
5582
  int64_t deleteMark;
5583
  int64_t lastTs;
5584
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5585
  SArray* pVgroupVerList;
5586
  int8_t  recursiveTsma;
5587
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5588
  char*   createStreamReq;
5589
  int32_t streamReqLen;
5590
  char*   dropStreamReq;
5591
  int32_t dropStreamReqLen;
5592
  int64_t uid;
5593
} SMCreateSmaReq;
5594

5595
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5596
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5597
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5598

5599
typedef struct {
5600
  char    name[TSDB_TABLE_FNAME_LEN];
5601
  int8_t  igNotExists;
5602
  char*   dropStreamReq;
5603
  int32_t dropStreamReqLen;
5604
} SMDropSmaReq;
5605

5606
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5607
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5608
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5609

5610
typedef struct {
5611
  char name[TSDB_TABLE_NAME_LEN];
5612
  union {
5613
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5614
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5615
  };
5616
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5617
  union {
5618
    int8_t igExists;   // used by mnode
5619
    int8_t alterType;  // used by vnode
5620
  };
5621
  int8_t     intervalUnit;
5622
  int16_t    nFuncs;       // number of functions specified by user
5623
  col_id_t*  funcColIds;   // column ids specified by user
5624
  func_id_t* funcIds;      // function ids specified by user
5625
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5626
  int64_t    tbUid;
5627
  int64_t    uid;     // rsma uid
5628
  int32_t    sqlLen;  // strlen + 1
5629
  char*      sql;
5630
} SMCreateRsmaReq;
5631

5632
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5633
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5634
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5635

5636
typedef SMCreateRsmaReq SVCreateRsmaReq;
5637

5638
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5639
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5640
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5641

5642
typedef SMCreateRsmaReq SVAlterRsmaReq;
5643

5644
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5645
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5646
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5647

5648
typedef struct {
5649
  char       name[TSDB_TABLE_NAME_LEN];
5650
  int8_t     alterType;
5651
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5652
  int8_t     igNotExists;
5653
  int16_t    nFuncs;      // number of functions specified by user
5654
  col_id_t*  funcColIds;  // column ids specified by user
5655
  func_id_t* funcIds;     // function ids specified by user
5656
  int32_t    sqlLen;      // strlen + 1
5657
  char*      sql;
5658
} SMAlterRsmaReq;
5659

5660
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5661
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5662
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5663

5664
typedef struct {
5665
  int64_t    id;
5666
  char       name[TSDB_TABLE_NAME_LEN];
5667
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5668
  int64_t    ownerId;
5669
  int32_t    code;
5670
  int32_t    version;
5671
  int8_t     tbType;
5672
  int8_t     intervalUnit;
5673
  col_id_t   nFuncs;
5674
  col_id_t   nColNames;
5675
  int64_t    interval[2];
5676
  col_id_t*  funcColIds;
5677
  func_id_t* funcIds;
5678
  SArray*    colNames;
5679
} SRsmaInfoRsp;
5680

5681
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5682
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5683
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5684

5685
typedef struct {
5686
  char   name[TSDB_TABLE_FNAME_LEN];
5687
  int8_t igNotExists;
5688
} SMDropRsmaReq;
5689

5690
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5691
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5692

5693
typedef struct {
5694
  char    name[TSDB_TABLE_NAME_LEN];
5695
  char    tbName[TSDB_TABLE_NAME_LEN];
5696
  int64_t uid;
5697
  int64_t tbUid;
5698
  int8_t  tbType;
5699
} SVDropRsmaReq;
5700

5701
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5702
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5703

5704
typedef struct {
5705
  char   dbFName[TSDB_DB_FNAME_LEN];
5706
  char   stbName[TSDB_TABLE_NAME_LEN];
5707
  char   colName[TSDB_COL_NAME_LEN];
5708
  char   idxName[TSDB_INDEX_FNAME_LEN];
5709
  int8_t idxType;
5710
} SCreateTagIndexReq;
5711

5712
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5713
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5714

5715
typedef SMDropSmaReq SDropTagIndexReq;
5716

5717
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5718
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5719

5720
typedef struct {
5721
  int8_t         version;       // for compatibility(default 0)
5722
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5723
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5724
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5725
  int32_t        dstVgId;
5726
  char           indexName[TSDB_INDEX_NAME_LEN];
5727
  int32_t        exprLen;
5728
  int32_t        tagsFilterLen;
5729
  int64_t        indexUid;
5730
  tb_uid_t       tableUid;  // super/child/common table uid
5731
  tb_uid_t       dstTbUid;  // for dstVgroup
5732
  int64_t        interval;
5733
  int64_t        offset;  // use unit by precision of DB
5734
  int64_t        sliding;
5735
  char*          dstTbName;  // for dstVgroup
5736
  char*          expr;       // sma expression
5737
  char*          tagsFilter;
5738
  SSchemaWrapper schemaRow;  // for dstVgroup
5739
  SSchemaWrapper schemaTag;  // for dstVgroup
5740
} STSma;                     // Time-range-wise SMA
5741

5742
typedef STSma SVCreateTSmaReq;
5743

5744
typedef struct {
5745
  int8_t  type;  // 0 status report, 1 update data
5746
  int64_t indexUid;
5747
  int64_t skey;  // start TS key of interval/sliding window
5748
} STSmaMsg;
5749

5750
typedef struct {
5751
  int64_t indexUid;
5752
  char    indexName[TSDB_INDEX_NAME_LEN];
5753
} SVDropTSmaReq;
5754

5755
typedef struct {
5756
  int tmp;  // TODO: to avoid compile error
5757
} SVCreateTSmaRsp, SVDropTSmaRsp;
5758

5759
#if 0
5760
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5761
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5762
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5763
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5764
#endif
5765

5766
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5767
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5768
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5769
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5770

5771
typedef struct {
5772
  int32_t number;
5773
  STSma*  tSma;
5774
} STSmaWrapper;
5775

5776
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5777
  if (pSma) {
×
UNCOV
5778
    taosMemoryFreeClear(pSma->dstTbName);
×
5779
    taosMemoryFreeClear(pSma->expr);
×
5780
    taosMemoryFreeClear(pSma->tagsFilter);
×
5781
  }
UNCOV
5782
}
×
5783

5784
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5785
  if (pSW) {
×
UNCOV
5786
    if (pSW->tSma) {
×
UNCOV
5787
      if (deepCopy) {
×
UNCOV
5788
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5789
          tDestroyTSma(pSW->tSma + i);
×
5790
        }
5791
      }
5792
      taosMemoryFreeClear(pSW->tSma);
×
5793
    }
5794
  }
5795
}
×
5796

5797
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5798
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5799
  taosMemoryFreeClear(pSW);
×
5800
  return NULL;
×
5801
}
5802

5803
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5804
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5805

5806
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5807
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5808

UNCOV
5809
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
5810
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
5811
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5812
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5813
  }
UNCOV
5814
  return 0;
×
5815
}
5816

UNCOV
5817
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5818
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5819
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5820
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5821
  }
UNCOV
5822
  return 0;
×
5823
}
5824

5825
typedef struct {
5826
  int idx;
5827
} SMCreateFullTextReq;
5828

5829
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5830
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5831
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5832

5833
typedef struct {
5834
  char   name[TSDB_TABLE_FNAME_LEN];
5835
  int8_t igNotExists;
5836
} SMDropFullTextReq;
5837

5838
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5839
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5840

5841
typedef struct {
5842
  char indexFName[TSDB_INDEX_FNAME_LEN];
5843
} SUserIndexReq;
5844

5845
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5846
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5847

5848
typedef struct {
5849
  char dbFName[TSDB_DB_FNAME_LEN];
5850
  char tblFName[TSDB_TABLE_FNAME_LEN];
5851
  char colName[TSDB_COL_NAME_LEN];
5852
  char owner[TSDB_USER_LEN];
5853
  char indexType[TSDB_INDEX_TYPE_LEN];
5854
  char indexExts[TSDB_INDEX_EXTS_LEN];
5855
} SUserIndexRsp;
5856

5857
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5858
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5859

5860
typedef struct {
5861
  char tbFName[TSDB_TABLE_FNAME_LEN];
5862
} STableIndexReq;
5863

5864
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5865
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5866

5867
typedef struct {
5868
  int8_t  intervalUnit;
5869
  int8_t  slidingUnit;
5870
  int64_t interval;
5871
  int64_t offset;
5872
  int64_t sliding;
5873
  int64_t dstTbUid;
5874
  int32_t dstVgId;
5875
  SEpSet  epSet;
5876
  char*   expr;
5877
} STableIndexInfo;
5878

5879
typedef struct {
5880
  char     tbName[TSDB_TABLE_NAME_LEN];
5881
  char     dbFName[TSDB_DB_FNAME_LEN];
5882
  uint64_t suid;
5883
  int32_t  version;
5884
  int32_t  indexSize;
5885
  SArray*  pIndex;  // STableIndexInfo
5886
} STableIndexRsp;
5887

5888
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5889
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5890
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5891

5892
void tFreeSTableIndexInfo(void* pInfo);
5893

5894
typedef struct {
5895
  int8_t  mqMsgType;
5896
  int32_t code;
5897
  int32_t epoch;
5898
  int64_t consumerId;
5899
  int64_t walsver;
5900
  int64_t walever;
5901
} SMqRspHead;
5902

5903
typedef struct {
5904
  SMsgHead     head;
5905
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5906
  int8_t       withTbName;
5907
  int8_t       useSnapshot;
5908
  int32_t      epoch;
5909
  uint64_t     reqId;
5910
  int64_t      consumerId;
5911
  int64_t      timeout;
5912
  STqOffsetVal reqOffset;
5913
  int8_t       enableReplay;
5914
  int8_t       sourceExcluded;
5915
  int8_t       rawData;
5916
  int32_t      minPollRows;
5917
  int8_t       enableBatchMeta;
5918
  SHashObj*    uidHash;  // to find if uid is duplicated
5919
} SMqPollReq;
5920

5921
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5922
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5923
void    tDestroySMqPollReq(SMqPollReq* pReq);
5924

5925
typedef struct {
5926
  int32_t vgId;
5927
  int64_t offset;
5928
  SEpSet  epSet;
5929
} SMqSubVgEp;
5930

5931
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5932
  int32_t tlen = 0;
2,656,932✔
5933
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,656,932✔
5934
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,656,932✔
5935
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,656,932✔
5936
  return tlen;
2,656,932✔
5937
}
5938

5939
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5940
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,315,796✔
5941
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,315,796✔
5942
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,315,796✔
5943
  return buf;
1,315,796✔
5944
}
5945

5946
typedef struct {
5947
  char           topic[TSDB_TOPIC_FNAME_LEN];
5948
  char           db[TSDB_DB_FNAME_LEN];
5949
  SArray*        vgs;  // SArray<SMqSubVgEp>
5950
} SMqSubTopicEp;
5951

5952
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5953
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5954
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5955

5956
typedef struct {
5957
  SMqRspHead   head;
5958
  STqOffsetVal rspOffset;
5959
  int16_t      resMsgType;
5960
  int32_t      metaRspLen;
5961
  void*        metaRsp;
5962
} SMqMetaRsp;
5963

5964
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5965
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5966
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5967

5968
#define MQ_DATA_RSP_VERSION 100
5969

5970
typedef struct {
5971
  SMqRspHead   head;
5972
  STqOffsetVal rspOffset;
5973
  STqOffsetVal reqOffset;
5974
  int32_t      blockNum;
5975
  int8_t       withTbName;
5976
  int8_t       withSchema;
5977
  SArray*      blockDataLen;
5978
  SArray*      blockData;
5979
  SArray*      blockTbName;
5980
  SArray*      blockSchema;
5981

5982
  union {
5983
    struct {
5984
      int64_t sleepTime;
5985
    };
5986
    struct {
5987
      int32_t createTableNum;
5988
      SArray* createTableLen;
5989
      SArray* createTableReq;
5990
    };
5991
    struct {
5992
      int32_t len;
5993
      void*   rawData;
5994
    };
5995
  };
5996
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5997
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5998
  bool  timeout;
5999
} SMqDataRsp;
6000

6001
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
6002
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6003
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6004
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
6005
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
6006

6007
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
6008
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
6009
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
6010

6011
typedef struct SMqBatchMetaRsp {
6012
  SMqRspHead   head;  // not serialize
6013
  STqOffsetVal rspOffset;
6014
  SArray*      batchMetaLen;
6015
  SArray*      batchMetaReq;
6016
  void*        pMetaBuff;    // not serialize
6017
  uint32_t     metaBuffLen;  // not serialize
6018
} SMqBatchMetaRsp;
6019

6020
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
6021
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6022
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
6023
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
6024

6025
typedef struct {
6026
  int32_t    code;
6027
  SArray*    topics;  // SArray<SMqSubTopicEp>
6028
} SMqAskEpRsp;
6029

6030
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6031
  int32_t tlen = 0;
8,428,506✔
6032
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6033
  int32_t sz = taosArrayGetSize(pRsp->topics);
8,428,506✔
6034
  tlen += taosEncodeFixedI32(buf, sz);
8,428,844✔
6035
  for (int32_t i = 0; i < sz; i++) {
10,435,370✔
6036
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
2,006,864✔
6037
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
2,006,864✔
6038
  }
6039
  tlen += taosEncodeFixedI32(buf, pRsp->code);
8,428,506✔
6040

6041
  return tlen;
8,428,844✔
6042
}
6043

6044
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6045
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6046
  int32_t sz;
3,402,808✔
6047
  buf = taosDecodeFixedI32(buf, &sz);
3,482,243✔
6048
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,482,243✔
6049
  if (pRsp->topics == NULL) {
3,482,243✔
UNCOV
6050
    return NULL;
×
6051
  }
6052
  for (int32_t i = 0; i < sz; i++) {
4,469,524✔
6053
    SMqSubTopicEp topicEp;
972,969✔
6054
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
987,281✔
6055
    if (buf == NULL) {
987,281✔
UNCOV
6056
      return NULL;
×
6057
    }
6058
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,974,562✔
UNCOV
6059
      return NULL;
×
6060
    }
6061
  }
6062
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,482,243✔
6063

6064
  return buf;
3,482,243✔
6065
}
6066

6067
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6068
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
10,244,576✔
6069
}
10,244,558✔
6070

6071
typedef struct {
6072
  int32_t      vgId;
6073
  STqOffsetVal offset;
6074
  int64_t      rows;
6075
  int64_t      ever;
6076
} OffsetRows;
6077

6078
typedef struct {
6079
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6080
  SArray* offsetRows;
6081
} TopicOffsetRows;
6082

6083
typedef struct {
6084
  int64_t consumerId;
6085
  int32_t epoch;
6086
  SArray* topics;
6087
  int8_t  pollFlag;
6088
} SMqHbReq;
6089

6090
typedef struct {
6091
  char   topic[TSDB_TOPIC_FNAME_LEN];
6092
  int8_t noPrivilege;
6093
} STopicPrivilege;
6094

6095
typedef struct {
6096
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6097
  int32_t debugFlag;
6098
} SMqHbRsp;
6099

6100
typedef struct {
6101
  SMsgHead head;
6102
  int64_t  consumerId;
6103
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6104
} SMqSeekReq;
6105

6106
#define TD_AUTO_CREATE_TABLE 0x1
6107
typedef struct {
6108
  int64_t       suid;
6109
  int64_t       uid;
6110
  int32_t       sver;
6111
  uint32_t      nData;
6112
  uint8_t*      pData;
6113
  SVCreateTbReq cTbReq;
6114
} SVSubmitBlk;
6115

6116
typedef struct {
6117
  SMsgHead header;
6118
  uint64_t sId;
6119
  uint64_t queryId;
6120
  uint64_t clientId;
6121
  uint64_t taskId;
6122
  uint32_t sqlLen;
6123
  uint32_t phyLen;
6124
  char*    sql;
6125
  char*    msg;
6126
  int8_t   source;
6127
  int8_t   secureDelete;
6128
} SVDeleteReq;
6129

6130
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6131
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6132

6133
typedef struct {
6134
  int64_t affectedRows;
6135
} SVDeleteRsp;
6136

6137
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6138
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6139

6140
typedef struct SDeleteRes {
6141
  uint64_t suid;
6142
  SArray*  uidList;
6143
  int64_t  skey;
6144
  int64_t  ekey;
6145
  int64_t  affectedRows;
6146
  char     tableFName[TSDB_TABLE_NAME_LEN];
6147
  char     tsColName[TSDB_COL_NAME_LEN];
6148
  int64_t  ctimeMs;  // fill by vnode
6149
  int8_t   source;
6150
  int8_t   secureDelete;  // force physical overwrite
6151
} SDeleteRes;
6152

6153
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6154
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6155

6156
typedef struct {
6157
  // int64_t uid;
6158
  char    tbname[TSDB_TABLE_NAME_LEN];
6159
  int64_t startTs;
6160
  int64_t endTs;
6161
} SSingleDeleteReq;
6162

6163
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6164
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6165

6166
typedef struct {
6167
  int64_t suid;
6168
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6169
  int64_t ctimeMs;     // fill by vnode
6170
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6171
} SBatchDeleteReq;
6172

6173
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6174
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6175
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6176

6177
typedef struct {
6178
  int32_t msgIdx;
6179
  int32_t msgType;
6180
  int32_t msgLen;
6181
  void*   msg;
6182
} SBatchMsg;
6183

6184
typedef struct {
6185
  SMsgHead header;
6186
  SArray*  pMsgs;  // SArray<SBatchMsg>
6187
} SBatchReq;
6188

6189
typedef struct {
6190
  int32_t reqType;
6191
  int32_t msgIdx;
6192
  int32_t msgLen;
6193
  int32_t rspCode;
6194
  void*   msg;
6195
} SBatchRspMsg;
6196

6197
typedef struct {
6198
  SArray* pRsps;  // SArray<SBatchRspMsg>
6199
} SBatchRsp;
6200

6201
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6202
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6203
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
101,312,412✔
6204
  if (NULL == msg) {
101,312,412✔
UNCOV
6205
    return;
×
6206
  }
6207
  SBatchMsg* pMsg = (SBatchMsg*)msg;
101,312,412✔
6208
  taosMemoryFree(pMsg->msg);
101,312,412✔
6209
}
6210

6211
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6212
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6213

6214
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
141,806,220✔
6215
  if (NULL == p) {
141,806,220✔
UNCOV
6216
    return;
×
6217
  }
6218

6219
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
141,806,220✔
6220
  taosMemoryFree(pRsp->msg);
141,806,220✔
6221
}
6222

6223
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6224
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6225
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6226
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6227
void    tDestroySMqHbReq(SMqHbReq* pReq);
6228

6229
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6230
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6231
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6232

6233
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6234
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6235

6236
#define TD_REQ_FROM_APP               0x0
6237
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6238
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6239
#define SUBMIT_REQ_FROM_FILE          0x4
6240
#define TD_REQ_FROM_TAOX              0x8
6241
#define TD_REQ_FROM_SML               0x10
6242
#define SUBMIT_REQUEST_VERSION        (2)
6243
#define SUBMIT_REQ_WITH_BLOB          0x10
6244
#define SUBMIT_REQ_SCHEMA_RES         0x20
6245
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6246

6247
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6248

6249
typedef struct {
6250
  int32_t        flags;
6251
  SVCreateTbReq* pCreateTbReq;
6252
  int64_t        suid;
6253
  int64_t        uid;
6254
  int32_t        sver;
6255
  union {
6256
    SArray* aRowP;
6257
    SArray* aCol;
6258
  };
6259
  int64_t   ctimeMs;
6260
  SBlobSet* pBlobSet;
6261
} SSubmitTbData;
6262

6263
typedef struct {
6264
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6265
  SArray* aSubmitBlobData;
6266
  bool    raw;
6267
} SSubmitReq2;
6268

6269
typedef struct {
6270
  SMsgHead header;
6271
  int64_t  version;
6272
  char     data[];  // SSubmitReq2
6273
} SSubmitReq2Msg;
6274

6275
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6276
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6277
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6278
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6279
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6280

6281
typedef struct {
6282
  int32_t affectedRows;
6283
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6284
} SSubmitRsp2;
6285

6286
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6287
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6288
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6289

6290
#define TSDB_MSG_FLG_ENCODE 0x1
6291
#define TSDB_MSG_FLG_DECODE 0x2
6292
#define TSDB_MSG_FLG_CMPT   0x3
6293

6294
typedef struct {
6295
  union {
6296
    struct {
6297
      void*   msgStr;
6298
      int32_t msgLen;
6299
      int64_t ver;
6300
    };
6301
    void* pDataBlock;
6302
  };
6303
} SPackedData;
6304

6305
typedef struct {
6306
  char     fullname[TSDB_VIEW_FNAME_LEN];
6307
  char     name[TSDB_VIEW_NAME_LEN];
6308
  char     dbFName[TSDB_DB_FNAME_LEN];
6309
  char*    querySql;
6310
  char*    sql;
6311
  int8_t   orReplace;
6312
  int8_t   precision;
6313
  int32_t  numOfCols;
6314
  SSchema* pSchema;
6315
} SCMCreateViewReq;
6316

6317
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6318
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6319
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6320

6321
typedef struct {
6322
  char   fullname[TSDB_VIEW_FNAME_LEN];
6323
  char   name[TSDB_VIEW_NAME_LEN];
6324
  char   dbFName[TSDB_DB_FNAME_LEN];
6325
  char*  sql;
6326
  int8_t igNotExists;
6327
} SCMDropViewReq;
6328

6329
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6330
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6331
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6332

6333
typedef struct {
6334
  char fullname[TSDB_VIEW_FNAME_LEN];
6335
} SViewMetaReq;
6336
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6337
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6338

6339
typedef struct {
6340
  char     name[TSDB_VIEW_NAME_LEN];
6341
  char     dbFName[TSDB_DB_FNAME_LEN];
6342
  char*    createUser;
6343
  int64_t  ownerId;
6344
  uint64_t dbId;
6345
  uint64_t viewId;
6346
  char*    querySql;
6347
  int8_t   precision;
6348
  int8_t   type;
6349
  int32_t  version;
6350
  int32_t  numOfCols;
6351
  SSchema* pSchema;
6352
} SViewMetaRsp;
6353
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6354
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6355
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6356
typedef struct {
6357
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6358
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6359
} STableTSMAInfoReq;
6360

6361
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6362
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6363

6364
typedef struct {
6365
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6366
  union {
6367
    uint8_t flags;
6368
    struct {
6369
      uint8_t withColName : 1;
6370
      uint8_t reserved : 7;
6371
    };
6372
  };
6373

6374
} SRsmaInfoReq;
6375

6376
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6377
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6378

6379
typedef struct {
6380
  int32_t  funcId;
6381
  col_id_t colId;
6382
} STableTSMAFuncInfo;
6383

6384
typedef struct {
6385
  char     name[TSDB_TABLE_NAME_LEN];
6386
  uint64_t tsmaId;
6387
  char     targetTb[TSDB_TABLE_NAME_LEN];
6388
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6389
  char     tb[TSDB_TABLE_NAME_LEN];
6390
  char     dbFName[TSDB_DB_FNAME_LEN];
6391
  uint64_t suid;
6392
  uint64_t destTbUid;
6393
  uint64_t dbId;
6394
  int32_t  version;
6395
  int64_t  interval;
6396
  int8_t   unit;
6397
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6398
  SArray*  pTags;      // SArray<SSchema>
6399
  SArray*  pUsedCols;  // SArray<SSchema>
6400
  char*    ast;
6401

6402
  int64_t streamUid;
6403
  int64_t reqTs;
6404
  int64_t rspTs;
6405
  int64_t delayDuration;  // ms
6406
  bool    fillHistoryFinished;
6407

6408
  void* streamAddr;  // for stream task, the address of the stream task
6409
} STableTSMAInfo;
6410

6411
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6412
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6413
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6414
void    tFreeTableTSMAInfo(void* p);
6415
void    tFreeAndClearTableTSMAInfo(void* p);
6416
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6417

6418
#define STSMAHbRsp            STableTSMAInfoRsp
6419
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6420
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6421
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6422

6423
typedef struct SDropCtbWithTsmaSingleVgReq {
6424
  SVgroupInfo vgInfo;
6425
  SArray*     pTbs;  // SVDropTbReq
6426
} SMDropTbReqsOnSingleVg;
6427

6428
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6429
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6430
void    tFreeSMDropTbReqOnSingleVg(void* p);
6431

6432
typedef struct SDropTbsReq {
6433
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6434
} SMDropTbsReq;
6435

6436
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6437
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6438
void    tFreeSMDropTbsReq(void*);
6439

6440
typedef struct SVFetchTtlExpiredTbsRsp {
6441
  SArray* pExpiredTbs;  // SVDropTbReq
6442
  int32_t vgId;
6443
} SVFetchTtlExpiredTbsRsp;
6444

6445
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6446
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6447

6448
void tFreeFetchTtlExpiredTbsRsp(void* p);
6449

6450
void setDefaultOptionsForField(SFieldWithOptions* field);
6451
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6452

6453
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6454
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6455

6456

6457
typedef struct {
6458
  char    id[TSDB_INSTANCE_ID_LEN];
6459
  char    type[TSDB_INSTANCE_TYPE_LEN];
6460
  char    desc[TSDB_INSTANCE_DESC_LEN];
6461
  int32_t expire;
6462
} SInstanceRegisterReq;
6463

6464
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6465
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6466

6467
typedef struct {
6468
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6469
} SInstanceListReq;
6470

6471
typedef struct {
6472
  int32_t count;
6473
  char**  ids;  // Array of instance IDs
6474
} SInstanceListRsp;
6475

6476
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6477
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6478
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6479
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6480

6481
#ifdef USE_MOUNT
6482
typedef struct {
6483
  char     mountName[TSDB_MOUNT_NAME_LEN];
6484
  int8_t   ignoreExist;
6485
  int16_t  nMounts;
6486
  int32_t* dnodeIds;
6487
  char**   mountPaths;
6488
  int32_t  sqlLen;
6489
  char*    sql;
6490
} SCreateMountReq;
6491

6492
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6493
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6494
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6495

6496
typedef struct {
6497
  char    mountName[TSDB_MOUNT_NAME_LEN];
6498
  int8_t  ignoreNotExists;
6499
  int32_t sqlLen;
6500
  char*   sql;
6501
} SDropMountReq;
6502

6503
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6504
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6505
void    tFreeSDropMountReq(SDropMountReq* pReq);
6506

6507
typedef struct {
6508
  char     mountName[TSDB_MOUNT_NAME_LEN];
6509
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6510
  int64_t  mountUid;
6511
  int32_t  dnodeId;
6512
  uint32_t valLen;
6513
  int8_t   ignoreExist;
6514
  void*    pVal;
6515
} SRetrieveMountPathReq;
6516

6517
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6518
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6519

6520
typedef struct {
6521
  // path
6522
  int32_t diskPrimary;
6523
  // vgInfo
6524
  int32_t  vgId;
6525
  int32_t  cacheLastSize;
6526
  int32_t  szPage;
6527
  int32_t  szCache;
6528
  uint64_t szBuf;
6529
  int8_t   cacheLast;
6530
  int8_t   standby;
6531
  int8_t   hashMethod;
6532
  uint32_t hashBegin;
6533
  uint32_t hashEnd;
6534
  int16_t  hashPrefix;
6535
  int16_t  hashSuffix;
6536
  int16_t  sttTrigger;
6537
  // syncInfo
6538
  int32_t replications;
6539
  // tsdbInfo
6540
  int8_t  precision;
6541
  int8_t  compression;
6542
  int8_t  slLevel;
6543
  int32_t daysPerFile;
6544
  int32_t keep0;
6545
  int32_t keep1;
6546
  int32_t keep2;
6547
  int32_t keepTimeOffset;
6548
  int32_t minRows;
6549
  int32_t maxRows;
6550
  int32_t tsdbPageSize;
6551
  int32_t ssChunkSize;
6552
  int32_t ssKeepLocal;
6553
  int8_t  ssCompact;
6554
  union {
6555
    uint8_t flags;
6556
    struct {
6557
      uint8_t isAudit : 1;
6558
      uint8_t allowDrop : 1;
6559
      uint8_t reserved : 6;
6560
    };
6561
  };
6562
  int8_t secureDelete;
6563
  // walInfo
6564
  int32_t walFsyncPeriod;      // millisecond
6565
  int32_t walRetentionPeriod;  // secs
6566
  int32_t walRollPeriod;       // secs
6567
  int64_t walRetentionSize;
6568
  int64_t walSegSize;
6569
  int32_t walLevel;
6570
  // encryptInfo
6571
  int32_t encryptAlgorithm;
6572
  // SVState
6573
  int64_t committed;
6574
  int64_t commitID;
6575
  int64_t commitTerm;
6576
  // stats
6577
  int64_t numOfSTables;
6578
  int64_t numOfCTables;
6579
  int64_t numOfNTables;
6580
  // dbInfo
6581
  uint64_t dbId;
6582
} SMountVgInfo;
6583

6584
typedef struct {
6585
  SMCreateStbReq req;
6586
  SArray*        pColExts;  // element: column id
6587
  SArray*        pTagExts;  // element: tag id
6588
} SMountStbInfo;
6589

6590
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6591
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6592

6593
typedef struct {
6594
  char     dbName[TSDB_DB_FNAME_LEN];
6595
  uint64_t dbId;
6596
  SArray*  pVgs;   // SMountVgInfo
6597
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6598
} SMountDbInfo;
6599

6600
typedef struct {
6601
  // common fields
6602
  char     mountName[TSDB_MOUNT_NAME_LEN];
6603
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6604
  int8_t   ignoreExist;
6605
  int64_t  mountUid;
6606
  int64_t  clusterId;
6607
  int32_t  dnodeId;
6608
  uint32_t valLen;
6609
  void*    pVal;
6610

6611
  // response fields
6612
  SArray* pDbs;  // SMountDbInfo
6613

6614
  // memory fields, no serialized
6615
  SArray*   pDisks[TFS_MAX_TIERS];
6616
  TdFilePtr pFile;
6617
} SMountInfo;
6618

6619
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6620
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6621
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6622

6623
typedef struct {
6624
  SCreateVnodeReq createReq;
6625
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6626
  char            mountName[TSDB_MOUNT_NAME_LEN];
6627
  int64_t         mountId;
6628
  int32_t         diskPrimary;
6629
  int32_t         mountVgId;
6630
  int64_t         committed;
6631
  int64_t         commitID;
6632
  int64_t         commitTerm;
6633
  int64_t         numOfSTables;
6634
  int64_t         numOfCTables;
6635
  int64_t         numOfNTables;
6636
} SMountVnodeReq;
6637

6638
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6639
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6640
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6641

6642
#endif  // USE_MOUNT
6643

6644
#pragma pack(pop)
6645

6646
typedef struct {
6647
  char        db[TSDB_DB_FNAME_LEN];
6648
  STimeWindow timeRange;
6649
  int32_t     sqlLen;
6650
  char*       sql;
6651
  SArray*     vgroupIds;
6652
} SScanDbReq;
6653

6654
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6655
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6656
void    tFreeSScanDbReq(SScanDbReq* pReq);
6657

6658
typedef struct {
6659
  int32_t scanId;
6660
  int8_t  bAccepted;
6661
} SScanDbRsp;
6662

6663
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6664
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6665

6666
typedef struct {
6667
  int32_t scanId;
6668
  int32_t sqlLen;
6669
  char*   sql;
6670
} SKillScanReq;
6671

6672
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6673
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6674
void    tFreeSKillScanReq(SKillScanReq* pReq);
6675

6676
typedef struct {
6677
  int32_t scanId;
6678
  int32_t vgId;
6679
  int32_t dnodeId;
6680
} SVKillScanReq;
6681

6682
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6683
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6684

6685
typedef struct {
6686
  int32_t scanId;
6687
  int32_t vgId;
6688
  int32_t dnodeId;
6689
  int32_t numberFileset;
6690
  int32_t finished;
6691
  int32_t progress;
6692
  int64_t remainingTime;
6693
} SQueryScanProgressRsp;
6694

6695
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6696
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6697

6698
typedef struct {
6699
  int32_t scanId;
6700
  int32_t vgId;
6701
  int32_t dnodeId;
6702
} SQueryScanProgressReq;
6703

6704
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6705
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6706

6707
typedef struct {
6708
  int64_t     dbUid;
6709
  char        db[TSDB_DB_FNAME_LEN];
6710
  int64_t     scanStartTime;
6711
  STimeWindow tw;
6712
  int32_t     scanId;
6713
} SScanVnodeReq;
6714

6715
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6716
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6717

6718
#ifdef __cplusplus
6719
}
6720
#endif
6721

6722
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6723
 
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