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

taosdata / TDengine / #4976

06 Mar 2026 09:48AM UTC coverage: 68.446% (+0.08%) from 68.37%
#4976

push

travis-ci

web-flow
feat(TDgpt): support multiple input data columns for anomaly detection. (#34606)

0 of 93 new or added lines in 9 files covered. (0.0%)

5718 existing lines in 144 files now uncovered.

211146 of 308486 relevant lines covered (68.45%)

136170362.0 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;
9✔
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
1,036,317,436✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
982,513,617✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
2,018,831,053✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

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

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

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

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

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

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

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

232
#define TSDB_ALTER_TABLE_ADD_TAG                         1
233
#define TSDB_ALTER_TABLE_DROP_TAG                        2
234
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
235
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4
236
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
237
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
238
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
239
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
240
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
241
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
242
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
243
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
244
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
245
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
246
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15
247
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
248
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
249
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
250

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

261

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

267

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

273
#define TSDB_ALTER_RSMA_FUNCTION        0x1
274

275
#define TSDB_KILL_MSG_LEN 30
276

277
#define TSDB_TABLE_NUM_UNIT 100000
278

279
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
280
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
281
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
282

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

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

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

300
typedef enum ENodeType {
301
  // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
302
  // VALUE, OPERATOR, FUNCTION and so on.
303
  QUERY_NODE_COLUMN = 1,
304
  QUERY_NODE_VALUE,
305
  QUERY_NODE_OPERATOR,
306
  QUERY_NODE_LOGIC_CONDITION,
307
  QUERY_NODE_FUNCTION,
308
  QUERY_NODE_REAL_TABLE,
309
  QUERY_NODE_TEMP_TABLE,
310
  QUERY_NODE_JOIN_TABLE,
311
  QUERY_NODE_GROUPING_SET,
312
  QUERY_NODE_ORDER_BY_EXPR,
313
  QUERY_NODE_LIMIT,
314
  QUERY_NODE_STATE_WINDOW,
315
  QUERY_NODE_SESSION_WINDOW,
316
  QUERY_NODE_INTERVAL_WINDOW,
317
  QUERY_NODE_NODE_LIST,
318
  QUERY_NODE_FILL,
319
  QUERY_NODE_RAW_EXPR,  // Only be used in parser module.
320
  QUERY_NODE_TARGET,
321
  QUERY_NODE_DATABLOCK_DESC,
322
  QUERY_NODE_SLOT_DESC,
323
  QUERY_NODE_COLUMN_DEF,
324
  QUERY_NODE_DOWNSTREAM_SOURCE,
325
  QUERY_NODE_DATABASE_OPTIONS,
326
  QUERY_NODE_TABLE_OPTIONS,
327
  QUERY_NODE_INDEX_OPTIONS,
328
  QUERY_NODE_EXPLAIN_OPTIONS,
329
  QUERY_NODE_LEFT_VALUE,
330
  QUERY_NODE_COLUMN_REF,
331
  QUERY_NODE_WHEN_THEN,
332
  QUERY_NODE_CASE_WHEN,
333
  QUERY_NODE_EVENT_WINDOW,
334
  QUERY_NODE_HINT,
335
  QUERY_NODE_VIEW,
336
  QUERY_NODE_WINDOW_OFFSET,
337
  QUERY_NODE_COUNT_WINDOW,
338
  QUERY_NODE_COLUMN_OPTIONS,
339
  QUERY_NODE_TSMA_OPTIONS,
340
  QUERY_NODE_ANOMALY_WINDOW,
341
  QUERY_NODE_RANGE_AROUND,
342
  QUERY_NODE_STREAM_NOTIFY_OPTIONS,
343
  QUERY_NODE_VIRTUAL_TABLE,
344
  QUERY_NODE_SLIDING_WINDOW,
345
  QUERY_NODE_PERIOD_WINDOW,
346
  QUERY_NODE_STREAM_TRIGGER,
347
  QUERY_NODE_STREAM,
348
  QUERY_NODE_STREAM_TAG_DEF,
349
  QUERY_NODE_EXTERNAL_WINDOW,
350
  QUERY_NODE_STREAM_TRIGGER_OPTIONS,
351
  QUERY_NODE_PLACE_HOLDER_TABLE,
352
  QUERY_NODE_TIME_RANGE,
353
  QUERY_NODE_STREAM_OUT_TABLE,
354
  QUERY_NODE_STREAM_CALC_RANGE,
355
  QUERY_NODE_COUNT_WINDOW_ARGS,
356
  QUERY_NODE_BNODE_OPTIONS,
357
  QUERY_NODE_DATE_TIME_RANGE,
358
  QUERY_NODE_IP_RANGE,
359
  QUERY_NODE_USER_OPTIONS,
360
  QUERY_NODE_REMOTE_VALUE,
361
  QUERY_NODE_TOKEN_OPTIONS,
362
  QUERY_NODE_TRUE_FOR,
363
  QUERY_NODE_REMOTE_VALUE_LIST,
364
  QUERY_NODE_SURROUND,
365
  QUERY_NODE_REMOTE_ROW,
366
  QUERY_NODE_REMOTE_ZERO_ROWS,
367
  
368
  // Statement nodes are used in parser and planner module.
369
  QUERY_NODE_SET_OPERATOR = 100,
370
  QUERY_NODE_SELECT_STMT,
371
  QUERY_NODE_VNODE_MODIFY_STMT,
372
  QUERY_NODE_CREATE_DATABASE_STMT,
373
  QUERY_NODE_DROP_DATABASE_STMT,
374
  QUERY_NODE_ALTER_DATABASE_STMT,
375
  QUERY_NODE_FLUSH_DATABASE_STMT,
376
  QUERY_NODE_TRIM_DATABASE_STMT,
377
  QUERY_NODE_CREATE_TABLE_STMT,
378
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
379
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
380
  QUERY_NODE_DROP_TABLE_CLAUSE,
381
  QUERY_NODE_DROP_TABLE_STMT,
382
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
383
  QUERY_NODE_ALTER_TABLE_STMT,
384
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
385
  QUERY_NODE_CREATE_USER_STMT,
386
  QUERY_NODE_ALTER_USER_STMT,
387
  QUERY_NODE_DROP_USER_STMT,
388
  QUERY_NODE_USE_DATABASE_STMT,
389
  QUERY_NODE_CREATE_DNODE_STMT,
390
  QUERY_NODE_DROP_DNODE_STMT,
391
  QUERY_NODE_ALTER_DNODE_STMT,
392
  QUERY_NODE_CREATE_INDEX_STMT,
393
  QUERY_NODE_DROP_INDEX_STMT,
394
  QUERY_NODE_CREATE_QNODE_STMT,
395
  QUERY_NODE_DROP_QNODE_STMT,
396
  QUERY_NODE_CREATE_BACKUP_NODE_STMT,  // no longer used
397
  QUERY_NODE_DROP_BACKUP_NODE_STMT,    // no longer used
398
  QUERY_NODE_CREATE_SNODE_STMT,
399
  QUERY_NODE_DROP_SNODE_STMT,
400
  QUERY_NODE_CREATE_MNODE_STMT,
401
  QUERY_NODE_DROP_MNODE_STMT,
402
  QUERY_NODE_CREATE_TOPIC_STMT,
403
  QUERY_NODE_DROP_TOPIC_STMT,
404
  QUERY_NODE_DROP_CGROUP_STMT,
405
  QUERY_NODE_ALTER_LOCAL_STMT,
406
  QUERY_NODE_EXPLAIN_STMT,
407
  QUERY_NODE_DESCRIBE_STMT,
408
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
409
  QUERY_NODE_COMPACT_DATABASE_STMT,
410
  QUERY_NODE_COMPACT_VGROUPS_STMT,
411
  QUERY_NODE_CREATE_FUNCTION_STMT,
412
  QUERY_NODE_DROP_FUNCTION_STMT,
413
  QUERY_NODE_CREATE_STREAM_STMT,
414
  QUERY_NODE_DROP_STREAM_STMT,
415
  QUERY_NODE_BALANCE_VGROUP_STMT,
416
  QUERY_NODE_MERGE_VGROUP_STMT,
417
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
418
  QUERY_NODE_SPLIT_VGROUP_STMT,
419
  QUERY_NODE_SYNCDB_STMT,
420
  QUERY_NODE_GRANT_STMT,
421
  QUERY_NODE_REVOKE_STMT,
422
  QUERY_NODE_ALTER_CLUSTER_STMT,
423
  QUERY_NODE_SSMIGRATE_DATABASE_STMT,
424
  QUERY_NODE_CREATE_TSMA_STMT,
425
  QUERY_NODE_DROP_TSMA_STMT,
426
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
427
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
428
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
429
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
430
  QUERY_NODE_CREATE_MOUNT_STMT,
431
  QUERY_NODE_DROP_MOUNT_STMT,
432
  QUERY_NODE_SCAN_DATABASE_STMT,
433
  QUERY_NODE_SCAN_VGROUPS_STMT,
434
  QUERY_NODE_TRIM_DATABASE_WAL_STMT,
435
  QUERY_NODE_ALTER_DNODES_RELOAD_TLS_STMT,
436
  QUERY_NODE_CREATE_TOKEN_STMT,
437
  QUERY_NODE_ALTER_TOKEN_STMT,
438
  QUERY_NODE_DROP_TOKEN_STMT,
439
  QUERY_NODE_ALTER_ENCRYPT_KEY_STMT,
440
  QUERY_NODE_CREATE_ROLE_STMT,
441
  QUERY_NODE_DROP_ROLE_STMT,
442
  QUERY_NODE_ALTER_ROLE_STMT,
443
  QUERY_NODE_CREATE_TOTP_SECRET_STMT,
444
  QUERY_NODE_DROP_TOTP_SECRET_STMT,
445
  QUERY_NODE_ALTER_KEY_EXPIRATION_STMT,
446

447

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

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

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

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

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

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

696
typedef struct SField {
697
  char    name[TSDB_COL_NAME_LEN];
698
  uint8_t type;
699
  int8_t  flags;
700
  int32_t bytes;
701
} SField;
702

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

712
typedef struct SRetention {
713
  int64_t freq;
714
  int64_t keep;
715
  int8_t  freqUnit;
716
  int8_t  keepUnit;
717
} SRetention;
718

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

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

728
typedef struct {
729
  int32_t contLen;
730
  int32_t vgId;
731
} SMsgHead;
732

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

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

753
typedef struct {
754
  int32_t totalLen;
755
  int32_t len;
756
  STSRow* row;
757
} SSubmitBlkIter;
758

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

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

781
typedef struct {
782
  bool     hasRef;
783
  col_id_t id;
784
  char     refDbName[TSDB_DB_NAME_LEN];
785
  char     refTableName[TSDB_TABLE_NAME_LEN];
786
  char     refColName[TSDB_COL_NAME_LEN];
787
} SColRef;
788

789
typedef struct {
790
  int32_t  nCols;
791
  int32_t  version;
792
  SColRef* pColRef;
793
} SColRefWrapper;
794

795
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
796
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
797
typedef struct {
798
  int32_t vgId;
799
  SColRef colRef;
800
} SColRefEx;
801

802
typedef struct {
803
  int16_t colId;
804
  char    refDbName[TSDB_DB_NAME_LEN];
805
  char    refTableName[TSDB_TABLE_NAME_LEN];
806
  char    refColName[TSDB_COL_NAME_LEN];
807
} SRefColInfo;
808

809
typedef struct SVCTableRefCols {
810
  uint64_t     uid;
811
  int32_t      numOfSrcTbls;
812
  int32_t      numOfColRefs;
813
  SRefColInfo* refCols;
814
} SVCTableRefCols;
815

816
typedef struct SVCTableMergeInfo {
817
  uint64_t uid;
818
  int32_t  numOfSrcTbls;
819
} SVCTableMergeInfo;
820

821
typedef struct {
822
  int32_t    nCols;
823
  SColRefEx* pColRefEx;
824
} SColRefExWrapper;
825

826
struct SSchema {
827
  int8_t   type;
828
  int8_t   flags;
829
  col_id_t colId;
830
  int32_t  bytes;
831
  char     name[TSDB_COL_NAME_LEN];
832
};
833
struct SSchemaExt {
834
  col_id_t colId;
835
  uint32_t compress;
836
  STypeMod typeMod;
837
};
838

839
struct SSchemaRsma {
840
  int64_t    interval[2];
841
  int32_t    nFuncs;
842
  int8_t     tbType;
843
  tb_uid_t   tbUid;
844
  func_id_t* funcIds;
845
  char       tbName[TSDB_TABLE_NAME_LEN];
846
};
847

848
struct SSchema2 {
849
  int8_t   type;
850
  int8_t   flags;
851
  col_id_t colId;
852
  int32_t  bytes;
853
  char     name[TSDB_COL_NAME_LEN];
854
  uint32_t compress;
855
};
856

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

889
typedef struct {
890
  int32_t        code;
891
  int64_t        uid;
892
  char*          tblFName;
893
  int32_t        numOfRows;
894
  int32_t        affectedRows;
895
  int64_t        sver;
896
  STableMetaRsp* pMeta;
897
} SSubmitBlkRsp;
898

899
typedef struct {
900
  int32_t numOfRows;
901
  int32_t affectedRows;
902
  int32_t nBlocks;
903
  union {
904
    SArray*        pArray;
905
    SSubmitBlkRsp* pBlocks;
906
  };
907
} SSubmitRsp;
908

909
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
910
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
911
// void    tFreeSSubmitBlkRsp(void* param);
912
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
913

914
#define COL_SMA_ON       ((int8_t)0x1)
915
#define COL_IDX_ON       ((int8_t)0x2)
916
#define COL_IS_KEY       ((int8_t)0x4)
917
#define COL_SET_NULL     ((int8_t)0x10)
918
#define COL_SET_VAL      ((int8_t)0x20)
919
#define COL_IS_SYSINFO   ((int8_t)0x40)
920
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
921
#define COL_REF_BY_STM   ((int8_t)0x08)
922

923
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
924
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
925

926
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
927
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
928
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
929

930
#define SSCHMEA_SET_IDX_ON(s) \
931
  do {                        \
932
    (s)->flags |= COL_IDX_ON; \
933
  } while (0)
934

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

940
#define SSCHEMA_SET_TYPE_MOD(s)     \
941
  do {                              \
942
    (s)->flags |= COL_HAS_TYPE_MOD; \
943
  } while (0)
944

945
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
946

947
#define SSCHMEA_TYPE(s)  ((s)->type)
948
#define SSCHMEA_FLAGS(s) ((s)->flags)
949
#define SSCHMEA_COLID(s) ((s)->colId)
950
#define SSCHMEA_BYTES(s) ((s)->bytes)
951
#define SSCHMEA_NAME(s)  ((s)->name)
952

953
typedef struct {
954
  bool    tsEnableMonitor;
955
  int32_t tsMonitorInterval;
956
  int32_t tsSlowLogThreshold;
957
  int32_t tsSlowLogMaxLen;
958
  int32_t tsSlowLogScope;
959
  int32_t tsSlowLogThresholdTest;  // Obsolete
960
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
961
} SMonitorParas;
962

963
typedef struct {
964
  STypeMod typeMod;
965
} SExtSchema;
966

967
bool hasExtSchema(const SExtSchema* pExtSchema);
968

969
typedef struct {
970
  int32_t      nCols;
971
  int32_t      version;
972
  SSchema*     pSchema;
973
  SSchemaRsma* pRsma;
974
} SSchemaWrapper;
975

976
typedef struct {
977
  col_id_t id;
978
  uint32_t alg;
979
} SColCmpr;
980

981
typedef struct {
982
  int32_t   nCols;
983
  int32_t   version;
984
  SColCmpr* pColCmpr;
985
} SColCmprWrapper;
986

987
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
988
  if (pRef->pColRef) {
402,271✔
UNCOV
989
    return TSDB_CODE_INVALID_PARA;
×
990
  }
991
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
402,271✔
992
  if (pRef->pColRef == NULL) {
402,271✔
UNCOV
993
    return terrno;
×
994
  }
995
  pRef->nCols = nCols;
402,271✔
996
  for (int32_t i = 0; i < nCols; i++) {
146,858,619✔
997
    pRef->pColRef[i].hasRef = false;
146,456,348✔
998
    pRef->pColRef[i].id = (col_id_t)(i + 1);
146,456,348✔
999
  }
1000
  return 0;
402,271✔
1001
}
1002

1003
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
1004
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
1005
    terrno = TSDB_CODE_INVALID_PARA;
1006
    return NULL;
1007
  }
1008

1009
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
1010
  if (pDstWrapper == NULL) {
1011
    return NULL;
1012
  }
1013
  pDstWrapper->nCols = pSrcWrapper->nCols;
1014
  pDstWrapper->version = pSrcWrapper->version;
1015

1016
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
1017
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
1018
  if (pDstWrapper->pColCmpr == NULL) {
1019
    taosMemoryFree(pDstWrapper);
1020
    return NULL;
1021
  }
1022
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
1023

1024
  return pDstWrapper;
1025
}
1026

1027
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
1028
  if (!(!pCmpr->pColCmpr)) {
6,797,297✔
UNCOV
1029
    return TSDB_CODE_INVALID_PARA;
×
1030
  }
1031
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
6,797,297✔
1032
  if (pCmpr->pColCmpr == NULL) {
6,797,297✔
UNCOV
1033
    return terrno;
×
1034
  }
1035
  pCmpr->nCols = nCols;
6,797,297✔
1036
  return 0;
6,797,297✔
1037
}
1038

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

1057
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
1058
  if (pWrapper == NULL) return;
1059

1060
  taosMemoryFreeClear(pWrapper->pColCmpr);
1061
  taosMemoryFreeClear(pWrapper);
1062
}
1063
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1064
  if (pSchemaWrapper->pSchema == NULL) return NULL;
655,480,064✔
1065

1066
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
655,329,995✔
1067
  if (pSW == NULL) {
655,325,906✔
UNCOV
1068
    return NULL;
×
1069
  }
1070
  pSW->nCols = pSchemaWrapper->nCols;
655,325,906✔
1071
  pSW->version = pSchemaWrapper->version;
655,300,611✔
1072
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
655,449,680✔
1073
  if (pSW->pSchema == NULL) {
655,116,234✔
UNCOV
1074
    taosMemoryFree(pSW);
×
UNCOV
1075
    return NULL;
×
1076
  }
1077

1078
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
655,162,986✔
1079
  return pSW;
655,541,485✔
1080
}
1081

1082
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
163,605,124✔
1083
  if (pSchemaWrapper) {
1,827,013,081✔
1084
    taosMemoryFree(pSchemaWrapper->pSchema);
1,023,687,765✔
1085
    if (pSchemaWrapper->pRsma) {
1,023,634,410✔
1086
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
26,603✔
1087
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
26,603✔
1088
    }
1089
    taosMemoryFree(pSchemaWrapper);
1,023,524,259✔
1090
  }
1091
}
1,782,905,953✔
1092

1093
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1094
  if (pSchemaWrapper) {
1095
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1096
    if (pSchemaWrapper->pRsma) {
1097
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1098
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1099
    }
1100
  }
1101
}
1102

1103
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
8,211,531✔
1104
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
8,211,531✔
1105
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
8,211,531✔
1106
  }
1107
}
8,212,535✔
1108

1109
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1110
  int32_t tlen = 0;
2,698,198✔
1111
  tlen += taosEncodeFixedI8(buf, pSchema->type);
2,699,470✔
1112
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
2,698,198✔
1113
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
2,698,198✔
1114
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
2,698,198✔
1115
  tlen += taosEncodeString(buf, pSchema->name);
2,698,198✔
1116
  return tlen;
2,698,198✔
1117
}
1118

1119
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1120
  buf = taosDecodeFixedI8(buf, &pSchema->type);
1,200,470✔
1121
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
1,200,152✔
1122
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
1,200,152✔
1123
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
1,200,152✔
1124
  buf = taosDecodeStringTo(buf, pSchema->name);
1,200,152✔
1125
  return (void*)buf;
1,200,152✔
1126
}
1127

1128
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1129
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1130
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1131
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1132
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1133
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1134
  return 0;
2,147,483,647✔
1135
}
1136

1137
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1138
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1139
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1140
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1141
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1142
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1143
  return 0;
2,147,483,647✔
1144
}
1145

1146
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1147
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1148
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1149
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1150
  return 0;
2,147,483,647✔
1151
}
1152

1153
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1154
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1155
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1156
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1157
  return 0;
2,147,483,647✔
1158
}
1159

1160
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1161
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
891,543,448✔
1162
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
891,543,448✔
1163
  if (pColRef->hasRef) {
445,771,724✔
1164
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
592,378,280✔
1165
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
592,378,280✔
1166
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
592,378,280✔
1167
  }
1168
  return 0;
445,771,724✔
1169
}
1170

1171
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1172
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
446,962,092✔
1173
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
446,962,092✔
1174
  if (pColRef->hasRef) {
223,481,046✔
1175
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
148,531,800✔
1176
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
148,531,800✔
1177
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
148,531,800✔
1178
  }
1179

1180
  return 0;
223,481,046✔
1181
}
1182

1183
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1184
  int32_t tlen = 0;
443,902✔
1185
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
443,902✔
1186
  tlen += taosEncodeVariantI32(buf, pSW->version);
443,902✔
1187
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,142,100✔
1188
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,396,396✔
1189
  }
1190
  return tlen;
443,902✔
1191
}
1192

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

1202
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,391,569✔
1203
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,400,304✔
1204
    }
1205
  } else {
UNCOV
1206
    pSW->pSchema = NULL;
×
1207
  }
1208
  return (void*)buf;
191,417✔
1209
}
1210

1211
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1212
  if (pSW == NULL) {
296,395,001✔
UNCOV
1213
    return TSDB_CODE_INVALID_PARA;
×
1214
  }
1215
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
592,807,767✔
1216
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
592,707,525✔
1217
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1218
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1219
  }
1220
  return 0;
296,558,156✔
1221
}
1222

1223
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1224
  if (pSW == NULL) {
129,397,781✔
UNCOV
1225
    return TSDB_CODE_INVALID_PARA;
×
1226
  }
1227
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
258,780,607✔
1228
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
258,761,744✔
1229

1230
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
129,378,918✔
1231
  if (pSW->pSchema == NULL) {
129,338,097✔
UNCOV
1232
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1233
  }
1234
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,375,801,835✔
1235
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1236
  }
1237

1238
  return 0;
129,431,502✔
1239
}
1240

1241
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1242
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1243
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1244

1245
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1246
  if (pSW->pSchema == NULL) {
2,110,569,052✔
UNCOV
1247
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1248
  }
1249
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1250
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1251
  }
1252

1253
  return 0;
2,111,255,786✔
1254
}
1255

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

1289
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1290
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1291
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1292

1293
typedef struct {
1294
  STableMetaRsp* pMeta;
1295
} SMCreateStbRsp;
1296

1297
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1298
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1299
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1300

1301
typedef struct {
1302
  char     name[TSDB_TABLE_FNAME_LEN];
1303
  int8_t   igNotExists;
1304
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1305
  int8_t   reserved[6];
1306
  tb_uid_t suid;
1307
  int32_t  sqlLen;
1308
  char*    sql;
1309
} SMDropStbReq;
1310

1311
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1312
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1313
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1314

1315
typedef struct {
1316
  char    name[TSDB_TABLE_FNAME_LEN];
1317
  int8_t  alterType;
1318
  int32_t numOfFields;
1319
  SArray* pFields;
1320
  int32_t ttl;
1321
  int32_t commentLen;
1322
  char*   comment;
1323
  int32_t sqlLen;
1324
  char*   sql;
1325
  int64_t keep;
1326
  SArray* pTypeMods;
1327
} SMAlterStbReq;
1328

1329
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1330
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1331
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1332

1333
typedef struct SEpSet {
1334
  int8_t inUse;
1335
  int8_t numOfEps;
1336
  SEp    eps[TSDB_MAX_REPLICA];
1337
} SEpSet;
1338

1339
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1340
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1341
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1342
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1343

1344
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1345
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1346

1347
typedef struct {
1348
  int8_t  connType;
1349
  int32_t pid;
1350
  int32_t totpCode;
1351
  char    app[TSDB_APP_NAME_LEN];
1352
  char    db[TSDB_DB_NAME_LEN];
1353
  char    user[TSDB_USER_LEN];
1354
  char    passwd[TSDB_PASSWORD_LEN];
1355
  char    token[TSDB_TOKEN_LEN];
1356
  int64_t startTime;
1357
  int64_t connectTime;
1358
  char    sVer[TSDB_VERSION_LEN];
1359
  char    signature[20]; // SHA1 produces a 20-byte signature
1360
} SConnectReq;
1361

1362
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1363
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1364
void    tSignConnectReq(SConnectReq* pReq);
1365
int32_t tVerifyConnectReqSignature(const SConnectReq* pReq);
1366

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

1393
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1394
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1395

1396
typedef struct {
1397
  char    user[TSDB_USER_LEN];
1398
  char    pass[TSDB_PASSWORD_LEN];
1399
  int32_t maxUsers;
1400
  int32_t maxDbs;
1401
  int32_t maxTimeSeries;
1402
  int32_t maxStreams;
1403
  int32_t accessState;  // Configured only by command
1404
  int64_t maxStorage;
1405
} SCreateAcctReq, SAlterAcctReq;
1406

1407
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1408
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1409

1410
typedef struct {
1411
  char    user[TSDB_USER_LEN];
1412
  int8_t  ignoreNotExists;
1413
  int32_t sqlLen;
1414
  char*   sql;
1415
} SDropUserReq, SDropAcctReq;
1416

1417
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1418
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1419
void    tFreeSDropUserReq(SDropUserReq* pReq);
1420

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

1434
int32_t tSerializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1435
int32_t tDeserializeSCreateRoleReq(void* buf, int32_t bufLen, SCreateRoleReq* pReq);
1436
void    tFreeSCreateRoleReq(SCreateRoleReq* pReq);
1437

1438
typedef struct {
1439
  char name[TSDB_ROLE_LEN];
1440
  union {
1441
    uint8_t flag;
1442
    struct {
1443
      uint8_t ignoreNotExists : 1;
1444
      uint8_t reserve : 7;
1445
    };
1446
  };
1447
  int32_t sqlLen;
1448
  char*   sql;
1449
} SDropRoleReq;
1450

1451
int32_t tSerializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1452
int32_t tDeserializeSDropRoleReq(void* buf, int32_t bufLen, SDropRoleReq* pReq);
1453
void    tFreeSDropRoleReq(SDropRoleReq* pReq);
1454

1455
typedef struct {
1456
  SPrivSet privSet;
1457
  SArray*  selectCols;  // SColIdNameKV, for table privileges
1458
  SArray*  insertCols;  // SColIdNameKV, for table privileges
1459
  SArray*  updateCols;  // SColIdNameKV, for table privileges
1460
  // delete can only specify conditions by cond and cannot specify columns
1461
  char*    cond;     // for table privileges
1462
  int32_t  condLen;  // for table privileges
1463
} SPrivSetReqArgs;
1464

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

1490
int32_t tSerializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1491
int32_t tDeserializeSAlterRoleReq(void* buf, int32_t bufLen, SAlterRoleReq* pReq);
1492
void    tFreeSAlterRoleReq(SAlterRoleReq* pReq);
1493

1494
typedef struct {
1495
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1496
  int32_t sqlLen;
1497
  char*   sql;
1498
} SDropEncryptAlgrReq;
1499

1500
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1501
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1502
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1503

1504
typedef struct SIpV4Range {
1505
  uint32_t ip;
1506
  uint32_t mask;
1507
} SIpV4Range;
1508

1509
typedef struct SIpv6Range {
1510
  uint64_t addr[2];
1511
  uint32_t mask;
1512
} SIpV6Range;
1513

1514
typedef struct {
1515
  int8_t type;   // 0: IPv4, 1: IPv6
1516
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1517
  union {
1518
    SIpV4Range ipV4;
1519
    SIpV6Range ipV6;
1520
  };
1521
} SIpRange;
1522

1523
typedef struct {
1524
  int32_t    num;
1525
  SIpV4Range pIpRange[];
1526
} SIpWhiteList;
1527

1528
typedef struct {
1529
  int32_t  num;
1530
  SIpRange pIpRanges[];
1531
} SIpWhiteListDual;
1532

1533
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1534
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1535
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1536
int32_t           createDefaultIp6Range(SIpRange* pRange);
1537
int32_t           createDefaultIp4Range(SIpRange* pRange);
1538

1539
typedef struct {
1540
  int32_t sessPerUser;
1541
  int32_t sessConnTime;
1542
  int32_t sessConnIdleTime;
1543
  int32_t sessMaxConcurrency;
1544
  int32_t sessMaxCallVnodeNum;
1545
} SUserSessCfg;
1546

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

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

1563
bool isValidDateTimeRange(SDateTimeRange* pRange);
1564
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1565
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1566

1567
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges.
1568
typedef struct {
1569
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1570
  bool neg;         // this is a negative entry
1571
  int32_t duration; // duration in seconds
1572
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1573
} SDateTimeWhiteListItem;
1574

1575
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1576
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1577

1578
typedef struct {
1579
  int32_t num;
1580
  SDateTimeWhiteListItem ranges[];
1581
} SDateTimeWhiteList;
1582

1583
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1584
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1585

1586

1587
typedef struct {
1588
  int8_t createType;
1589

1590
  int8_t hasSessionPerUser;
1591
  int8_t hasConnectTime;
1592
  int8_t hasConnectIdleTime;
1593
  int8_t hasCallPerSession;
1594
  int8_t hasVnodePerCall;
1595
  int8_t hasFailedLoginAttempts;
1596
  int8_t hasPasswordLifeTime;
1597
  int8_t hasPasswordReuseTime;
1598
  int8_t hasPasswordReuseMax;
1599
  int8_t hasPasswordLockTime;
1600
  int8_t hasPasswordGraceTime;
1601
  int8_t hasInactiveAccountTime;
1602
  int8_t hasAllowTokenNum;
1603

1604
  int8_t superUser;  // denote if it is a super user or not
1605
  int8_t ignoreExists;
1606

1607
  char   user[TSDB_USER_LEN];
1608
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1609
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1610

1611
  int8_t sysInfo;
1612
  int8_t createDb;
1613
  int8_t isImport;
1614
  int8_t changepass;
1615
  int8_t enable;
1616

1617
  int8_t negIpRanges;
1618
  int8_t negTimeRanges;
1619

1620
  int32_t sessionPerUser;
1621
  int32_t connectTime;
1622
  int32_t connectIdleTime;
1623
  int32_t callPerSession;
1624
  int32_t vnodePerCall;
1625
  int32_t failedLoginAttempts;
1626
  int32_t passwordLifeTime;
1627
  int32_t passwordReuseTime;
1628
  int32_t passwordReuseMax;
1629
  int32_t passwordLockTime;
1630
  int32_t passwordGraceTime;
1631
  int32_t inactiveAccountTime;
1632
  int32_t allowTokenNum;
1633

1634
  int32_t         numIpRanges;
1635
  SIpRange*       pIpDualRanges;
1636
  int32_t         numTimeRanges;
1637
  SDateTimeRange* pTimeRanges;
1638

1639
  int32_t sqlLen;
1640
  char*   sql;
1641
} SCreateUserReq;
1642

1643
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1644
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1645
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1646

1647
typedef struct {
1648
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1649
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1650
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1651
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1652
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1653
  int32_t sqlLen;
1654
  char*   sql;
1655
} SCreateEncryptAlgrReq;
1656

1657
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1658
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1659
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1660

1661
typedef struct {
1662
  int32_t dnodeId;
1663
  int64_t analVer;
1664
} SRetrieveAnalyticsAlgoReq;
1665

1666
typedef struct {
1667
  int64_t   ver;
1668
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1669
} SRetrieveAnalyticAlgoRsp;
1670

1671
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1672
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1673
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1674
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1675
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1676

1677
typedef struct {
1678
  int8_t alterType;
1679

1680
  int8_t isView;
1681

1682
  int8_t hasPassword;
1683
  int8_t hasTotpseed;
1684
  int8_t hasEnable;
1685
  int8_t hasSysinfo;
1686
  int8_t hasCreatedb;
1687
  int8_t hasChangepass;
1688
  int8_t hasSessionPerUser;
1689
  int8_t hasConnectTime;
1690
  int8_t hasConnectIdleTime;
1691
  int8_t hasCallPerSession;
1692
  int8_t hasVnodePerCall;
1693
  int8_t hasFailedLoginAttempts;
1694
  int8_t hasPasswordLifeTime;
1695
  int8_t hasPasswordReuseTime;
1696
  int8_t hasPasswordReuseMax;
1697
  int8_t hasPasswordLockTime;
1698
  int8_t hasPasswordGraceTime;
1699
  int8_t hasInactiveAccountTime;
1700
  int8_t hasAllowTokenNum;
1701

1702
  int8_t enable;
1703
  int8_t sysinfo;
1704
  int8_t createdb;
1705
  int8_t changepass;
1706

1707
  char   user[TSDB_USER_LEN];
1708
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1709
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1710
  int32_t sessionPerUser;
1711
  int32_t connectTime;
1712
  int32_t connectIdleTime;
1713
  int32_t callPerSession;
1714
  int32_t vnodePerCall;
1715
  int32_t failedLoginAttempts;
1716
  int32_t passwordLifeTime;
1717
  int32_t passwordReuseTime;
1718
  int32_t passwordReuseMax;
1719
  int32_t passwordLockTime;
1720
  int32_t passwordGraceTime;
1721
  int32_t inactiveAccountTime;
1722
  int32_t allowTokenNum;
1723

1724
  int32_t         numIpRanges;
1725
  int32_t         numTimeRanges;
1726
  int32_t         numDropIpRanges;
1727
  int32_t         numDropTimeRanges;
1728
  SIpRange*       pIpRanges;
1729
  SDateTimeRange* pTimeRanges;
1730
  SIpRange*       pDropIpRanges;
1731
  SDateTimeRange* pDropTimeRanges;
1732
  SPrivSet        privileges;
1733

1734
  char        objname[TSDB_OBJ_FNAME_LEN];  // db or topic
1735
  char        tabName[TSDB_TABLE_NAME_LEN];
1736
  char*       tagCond;
1737
  int32_t     tagCondLen;
1738
  int32_t     sqlLen;
1739
  char*       sql;
1740
} SAlterUserReq;
1741

1742
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1743
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1744
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1745

1746
typedef struct {
1747
  char    name[TSDB_TOKEN_NAME_LEN];
1748
  char    user[TSDB_USER_LEN];
1749
  int8_t  enable;
1750
  int8_t  ignoreExists;
1751
  int32_t ttl;
1752
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1753
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1754

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

1759
int32_t tSerializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1760
int32_t tDeserializeSCreateTokenReq(void* buf, int32_t bufLen, SCreateTokenReq* pReq);
1761
void    tFreeSCreateTokenReq(SCreateTokenReq* pReq);
1762

1763
typedef struct {
1764
  char name[TSDB_TOKEN_NAME_LEN];
1765
  char user[TSDB_USER_LEN];
1766
  char token[TSDB_TOKEN_LEN];
1767
} SCreateTokenRsp;
1768

1769
int32_t tSerializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1770
int32_t tDeserializeSCreateTokenResp(void* buf, int32_t bufLen, SCreateTokenRsp* pRsp);
1771
void    tFreeSCreateTokenResp(SCreateTokenRsp* pRsp);
1772

1773
typedef struct {
1774
  char    name[TSDB_TOKEN_NAME_LEN];
1775

1776
  int8_t hasEnable;
1777
  int8_t hasTtl;
1778
  int8_t hasProvider;
1779
  int8_t hasExtraInfo;
1780

1781
  int8_t  enable;
1782
  int32_t ttl;
1783
  char    provider[TSDB_TOKEN_PROVIDER_LEN];
1784
  char    extraInfo[TSDB_TOKEN_EXTRA_INFO_LEN];
1785

1786
  int32_t     sqlLen;
1787
  char*       sql;
1788
} SAlterTokenReq;
1789

1790
int32_t tSerializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1791
int32_t tDeserializeSAlterTokenReq(void* buf, int32_t bufLen, SAlterTokenReq* pReq);
1792
void    tFreeSAlterTokenReq(SAlterTokenReq* pReq);
1793

1794
typedef struct {
1795
  char    name[TSDB_TOKEN_NAME_LEN];
1796
  int8_t  ignoreNotExists;
1797
  int32_t sqlLen;
1798
  char*   sql;
1799
} SDropTokenReq;
1800

1801
int32_t tSerializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1802
int32_t tDeserializeSDropTokenReq(void* buf, int32_t bufLen, SDropTokenReq* pReq);
1803
void    tFreeSDropTokenReq(SDropTokenReq* pReq);
1804

1805
typedef struct {
1806
  char    user[TSDB_USER_LEN];
1807
  int32_t sqlLen;
1808
  char*   sql;
1809
} SCreateTotpSecretReq;
1810

1811
int32_t tSerializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1812
int32_t tDeserializeSCreateTotpSecretReq(void* buf, int32_t bufLen, SCreateTotpSecretReq* pReq);
1813
void    tFreeSCreateTotpSecretReq(SCreateTotpSecretReq* pReq);
1814

1815
typedef struct {
1816
  char user[TSDB_USER_LEN];
1817
  char totpSecret[(TSDB_TOTP_SECRET_LEN * 8 + 4) / 5 + 1];  // base32 encoded totp secret + null terminator
1818
} SCreateTotpSecretRsp;
1819

1820
int32_t tSerializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1821
int32_t tDeserializeSCreateTotpSecretRsp(void* buf, int32_t bufLen, SCreateTotpSecretRsp* pRsp);
1822

1823
typedef SCreateTotpSecretReq SDropTotpSecretReq;
1824
#define tSerializeSDropTotpSecretReq tSerializeSCreateTotpSecretReq
1825
#define tDeserializeSDropTotpSecretReq tDeserializeSCreateTotpSecretReq
1826
#define tFreeSDropTotpSecretReq tFreeSCreateTotpSecretReq
1827

1828
typedef struct {
1829
  char user[TSDB_USER_LEN];
1830
} SGetUserAuthReq;
1831

1832
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1833
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1834

1835
typedef struct {
1836
  int8_t  enabled;
1837
  int32_t expireTime;
1838
} STokenStatus;
1839

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

1865
  SUserSessCfg sessCfg;
1866
  int64_t      timeWhiteListVer;
1867
  SHashObj*    tokens;
1868
} SGetUserAuthRsp;
1869

1870
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1871
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1872
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1873

1874
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1875
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1876
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1877
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1878

1879
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1880
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1881
typedef struct {
1882
  int64_t ver;
1883
  char    user[TSDB_USER_LEN];
1884
  int32_t numOfRange;
1885
  union {
1886
    SIpV4Range* pIpRanges;
1887
    SIpRange*   pIpDualRanges;
1888
  };
1889
} SUpdateUserIpWhite;
1890

1891
typedef struct {
1892
  int64_t             ver;
1893
  int                 numOfUser;
1894
  SUpdateUserIpWhite* pUserIpWhite;
1895
} SUpdateIpWhite;
1896

1897
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1898
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1899
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1900
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1901

1902
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1903
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1904
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1905

1906

1907
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1908
// corresponding response struct is different.
1909
typedef struct {
1910
  int64_t ver;
1911
} SRetrieveWhiteListReq;
1912

1913
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1914
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1915

1916

1917
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1918
// corresponding response struct is different.
1919
typedef struct {
1920
  char user[TSDB_USER_LEN];
1921
} SGetUserWhiteListReq;
1922

1923
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1924
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1925

1926
typedef struct {
1927
  char    user[TSDB_USER_LEN];
1928
  int32_t numWhiteLists;
1929
  union {
1930
    SIpV4Range* pWhiteLists;
1931
    SIpRange*   pWhiteListsDual;
1932
  };
1933
} SGetUserIpWhiteListRsp;
1934

1935
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1936
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1937
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1938
void    tIpRangeSetDefaultMask(SIpRange* range);
1939

1940
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1941
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1942
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1943

1944
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1945
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1946
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1947

1948
typedef struct {
1949
  int64_t ver;
1950
  char    user[TSDB_USER_LEN];
1951
  int32_t numWhiteLists;
1952
  SDateTimeWhiteListItem* pWhiteLists;
1953
} SUserDateTimeWhiteList;
1954

1955

1956
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1957
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1958
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1959
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1960

1961
typedef struct {
1962
  int64_t             ver;
1963
  int                 numOfUser;
1964
  SUserDateTimeWhiteList *pUsers;
1965
} SRetrieveDateTimeWhiteListRsp;
1966

1967
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1968
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1969
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1970
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1971

1972
/*
1973
 * for client side struct, only column id, type, bytes are necessary
1974
 * But for data in vnode side, we need all the following information.
1975
 */
1976
typedef struct {
1977
  union {
1978
    col_id_t colId;
1979
    int16_t  slotId;
1980
  };
1981

1982
  uint8_t precision;
1983
  uint8_t scale;
1984
  int32_t bytes;
1985
  int8_t  type;
1986
  uint8_t pk;
1987
  bool    noData;
1988
} SColumnInfo;
1989

1990
typedef struct STimeWindow {
1991
  TSKEY skey;
1992
  TSKEY ekey;
1993
} STimeWindow;
1994

1995
typedef struct SQueryHint {
1996
  bool batchScan;
1997
} SQueryHint;
1998

1999
typedef struct {
2000
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
2001
  int32_t tsLen;          // total length of ts comp block
2002
  int32_t tsNumOfBlocks;  // ts comp block numbers
2003
  int32_t tsOrder;        // ts comp block order
2004
} STsBufInfo;
2005

2006
typedef struct {
2007
  void*       timezone;
2008
  char        intervalUnit;
2009
  char        slidingUnit;
2010
  char        offsetUnit;
2011
  int8_t      precision;
2012
  int64_t     interval;
2013
  int64_t     sliding;
2014
  int64_t     offset;
2015
  STimeWindow timeRange;
2016
} SInterval;
2017

2018
typedef struct STbVerInfo {
2019
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2020
  int32_t sversion;
2021
  int32_t tversion;
2022
  int32_t rversion;  // virtual table's column ref's version
2023
} STbVerInfo;
2024

2025
typedef struct {
2026
  int32_t code;
2027
  int64_t affectedRows;
2028
  SArray* tbVerInfo;  // STbVerInfo
2029
} SQueryTableRsp;
2030

2031
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2032

2033
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2034

2035
typedef struct {
2036
  SMsgHead header;
2037
  char     dbFName[TSDB_DB_FNAME_LEN];
2038
  char     tbName[TSDB_TABLE_NAME_LEN];
2039
} STableCfgReq;
2040

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

2073
typedef STableCfg STableCfgRsp;
2074

2075
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2076
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2077

2078
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2079
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2080
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2081

2082
typedef struct {
2083
  SMsgHead header;
2084
  tb_uid_t suid;
2085
} SVSubTablesReq;
2086

2087
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2088
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2089

2090
typedef struct {
2091
  int32_t vgId;
2092
  SArray* pTables;  // SArray<SVCTableRefCols*>
2093
} SVSubTablesRsp;
2094

2095
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2096
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2097
void    tDestroySVSubTablesRsp(void* rsp);
2098

2099
typedef struct {
2100
  SMsgHead header;
2101
  tb_uid_t suid;
2102
} SVStbRefDbsReq;
2103

2104
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2105
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2106

2107
typedef struct {
2108
  int32_t vgId;
2109
  SArray* pDbs;  // SArray<char* (db name)>
2110
} SVStbRefDbsRsp;
2111

2112
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2113
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2114
void    tDestroySVStbRefDbsRsp(void* rsp);
2115

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

2168
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2169
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2170
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2171

2172
typedef struct {
2173
  char    db[TSDB_DB_FNAME_LEN];
2174
  int32_t buffer;
2175
  int32_t pageSize;
2176
  int32_t pages;
2177
  int32_t cacheLastSize;
2178
  int32_t daysPerFile;
2179
  int32_t daysToKeep0;
2180
  int32_t daysToKeep1;
2181
  int32_t daysToKeep2;
2182
  int32_t keepTimeOffset;
2183
  int32_t walFsyncPeriod;
2184
  int8_t  walLevel;
2185
  int8_t  strict;
2186
  int8_t  cacheLast;
2187
  int8_t  replications;
2188
  int32_t sstTrigger;
2189
  int32_t minRows;
2190
  int32_t walRetentionPeriod;
2191
  int32_t walRetentionSize;
2192
  int32_t ssKeepLocal;
2193
  int8_t  ssCompact;
2194
  int32_t sqlLen;
2195
  char*   sql;
2196
  int8_t  withArbitrator;
2197
  // 1. add auto-compact parameters
2198
  int32_t compactInterval;
2199
  int32_t compactStartTime;
2200
  int32_t compactEndTime;
2201
  int8_t  compactTimeOffset;
2202
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2203
  int8_t  isAudit;
2204
  int8_t  allowDrop;
2205
} SAlterDbReq;
2206

2207
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2208
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2209
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2210

2211
typedef struct {
2212
  char    db[TSDB_DB_FNAME_LEN];
2213
  int8_t  ignoreNotExists;
2214
  int8_t  force;
2215
  int32_t sqlLen;
2216
  char*   sql;
2217
} SDropDbReq;
2218

2219
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2220
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2221
void    tFreeSDropDbReq(SDropDbReq* pReq);
2222

2223
typedef struct {
2224
  char    db[TSDB_DB_FNAME_LEN];
2225
  int64_t uid;
2226
} SDropDbRsp;
2227

2228
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2229
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2230

2231
typedef struct {
2232
  char    name[TSDB_MOUNT_NAME_LEN];
2233
  int64_t uid;
2234
} SDropMountRsp;
2235

2236
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2237
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2238

2239
typedef struct {
2240
  char    db[TSDB_DB_FNAME_LEN];
2241
  int64_t dbId;
2242
  int32_t vgVersion;
2243
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2244
  int64_t stateTs;     // ms
2245
} SUseDbReq;
2246

2247
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2248
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2249

2250
typedef struct {
2251
  char    db[TSDB_DB_FNAME_LEN];
2252
  int64_t uid;
2253
  int32_t vgVersion;
2254
  int32_t vgNum;
2255
  int16_t hashPrefix;
2256
  int16_t hashSuffix;
2257
  int8_t  hashMethod;
2258
  union {
2259
    uint8_t flags;
2260
    struct {
2261
      uint8_t isMount : 1;  // TS-5868
2262
      uint8_t padding : 7;
2263
    };
2264
  };
2265
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2266
  int32_t errCode;
2267
  int64_t stateTs;  // ms
2268
} SUseDbRsp;
2269

2270
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2271
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2272
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2273
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2274
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2275

2276
typedef struct {
2277
  char db[TSDB_DB_FNAME_LEN];
2278
} SDbCfgReq;
2279

2280
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2281
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2282

2283
typedef struct {
2284
  char db[TSDB_DB_FNAME_LEN];
2285
} SSsMigrateDbReq;
2286

2287
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2288
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2289

2290
typedef struct {
2291
  int32_t ssMigrateId;
2292
  bool    bAccepted;
2293
} SSsMigrateDbRsp;
2294

2295
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2296
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2297

2298
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2299
typedef struct {
2300
  int32_t ssMigrateId;
2301
} SListSsMigrateFileSetsReq;
2302

2303
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2304
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2305

2306
typedef struct {
2307
  int32_t ssMigrateId;
2308
  int32_t vgId;       // vgroup id
2309
  SArray* pFileSets;  // SArray<int32_t>
2310
} SListSsMigrateFileSetsRsp;
2311

2312
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2313
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2314
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2315

2316
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2317
typedef struct {
2318
  int32_t ssMigrateId;
2319
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2320
  int32_t fid;
2321
  int64_t startTimeSec;
2322
} SSsMigrateFileSetReq;
2323

2324
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2325
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2326

2327
typedef struct {
2328
  int32_t ssMigrateId;
2329
  int32_t nodeId;  // node id of the leader vnode
2330
  int32_t vgId;
2331
  int32_t fid;
2332
} SSsMigrateFileSetRsp;
2333

2334
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2335
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2336

2337
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2338
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2339
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2340
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2341
#define SSMIGRATE_FILESET_STATE_FAILED      4
2342

2343
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2344
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2345
// while as a request, the 'state' field is not used.
2346
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2347
typedef struct {
2348
  int32_t ssMigrateId;  // ss migrate id
2349
  int32_t nodeId;       // node id of the leader vnode
2350
  int32_t vgId;         // vgroup id
2351
  int32_t fid;          // file set id
2352
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2353
} SSsMigrateProgress;
2354

2355
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2356
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2357

2358
// Request for TDMT_MND_KILL_SSMIGRATE
2359
typedef struct {
2360
  int32_t ssMigrateId;
2361
  int32_t sqlLen;
2362
  char*   sql;
2363
} SKillSsMigrateReq;
2364

2365
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2366
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2367
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2368

2369
// Request for TDMT_VND_KILL_SSMIGRATE
2370
typedef struct {
2371
  int32_t ssMigrateId;
2372
} SVnodeKillSsMigrateReq;
2373

2374
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2375
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2376

2377
typedef struct {
2378
  int32_t vgId;
2379
  int64_t keepVersion;
2380
} SMndSetVgroupKeepVersionReq;
2381

2382
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2383
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2384

2385
typedef struct {
2386
  int32_t timestampSec;
2387
  int32_t ttlDropMaxCount;
2388
  int32_t nUids;
2389
  SArray* pTbUids;
2390
} SVDropTtlTableReq;
2391

2392
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2393
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2394

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

2453
typedef SDbCfgRsp SDbCfgInfo;
2454

2455
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2456
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2457
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2458
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2459
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2460

2461
typedef struct {
2462
  int32_t rowNum;
2463
} SQnodeListReq;
2464

2465
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2466
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2467

2468
typedef struct {
2469
  int32_t rowNum;
2470
} SDnodeListReq;
2471

2472
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2473

2474
typedef struct {
2475
  int32_t useless;  // useless
2476
} SServerVerReq;
2477

2478
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2479
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2480

2481
typedef struct {
2482
  char ver[TSDB_VERSION_LEN];
2483
} SServerVerRsp;
2484

2485
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2486
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2487

2488
typedef struct SQueryNodeAddr {
2489
  int32_t nodeId;  // vgId or qnodeId
2490
  SEpSet  epSet;
2491
} SQueryNodeAddr;
2492

2493
typedef struct {
2494
  SQueryNodeAddr addr;
2495
  uint64_t       load;
2496
} SQueryNodeLoad;
2497

2498
typedef struct {
2499
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2500
} SQnodeListRsp;
2501

2502
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2503
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2504
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2505

2506

2507
typedef struct SDownstreamSourceNode {
2508
  ENodeType      type;
2509
  SQueryNodeAddr addr;
2510
  uint64_t       clientId;
2511
  uint64_t       taskId;
2512
  uint64_t       sId;
2513
  uint64_t       srcTaskId;
2514
  int32_t        execId;
2515
  int32_t        fetchMsgType;
2516
  bool           localExec;
2517
} SDownstreamSourceNode;
2518

2519

2520

2521
typedef struct SDNodeAddr {
2522
  int32_t nodeId;  // dnodeId
2523
  SEpSet  epSet;
2524
} SDNodeAddr;
2525

2526
typedef struct {
2527
  SArray* dnodeList;  // SArray<SDNodeAddr>
2528
} SDnodeListRsp;
2529

2530
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2531
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2532
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2533

2534
typedef struct {
2535
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2536
} STableTSMAInfoRsp;
2537

2538
typedef struct {
2539
  SUseDbRsp*         useDbRsp;
2540
  SDbCfgRsp*         cfgRsp;
2541
  STableTSMAInfoRsp* pTsmaRsp;
2542
  int32_t            dbTsmaVersion;
2543
  char               db[TSDB_DB_FNAME_LEN];
2544
  int64_t            dbId;
2545
} SDbHbRsp;
2546

2547
typedef struct {
2548
  SArray* pArray;  // Array of SDbHbRsp
2549
} SDbHbBatchRsp;
2550

2551
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2552
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2553
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2554

2555
typedef struct {
2556
  SArray* pArray;  // Array of SGetUserAuthRsp
2557
} SUserAuthBatchRsp;
2558

2559
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2560
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2561
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2562

2563
typedef struct {
2564
  char        db[TSDB_DB_FNAME_LEN];
2565
  STimeWindow timeRange;
2566
  int32_t     sqlLen;
2567
  char*       sql;
2568
  SArray*     vgroupIds;
2569
  int32_t     compactId;
2570
  int8_t      metaOnly;
2571
  int8_t      force;
2572
} SCompactDbReq;
2573

2574
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2575
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2576
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2577

2578
typedef struct {
2579
  union {
2580
    int32_t compactId;
2581
    int32_t id;
2582
  };
2583
  int8_t bAccepted;
2584
} SCompactDbRsp;
2585

2586
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2587
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2588

2589
typedef struct {
2590
  union {
2591
    int32_t compactId;
2592
    int32_t id;
2593
  };
2594
  int32_t sqlLen;
2595
  char*   sql;
2596
} SKillCompactReq;
2597

2598
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2599
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2600
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2601

2602
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2603
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2604

2605
typedef struct {
2606
  char    name[TSDB_FUNC_NAME_LEN];
2607
  int8_t  igExists;
2608
  int8_t  funcType;
2609
  int8_t  scriptType;
2610
  int8_t  outputType;
2611
  int32_t outputLen;
2612
  int32_t bufSize;
2613
  int32_t codeLen;
2614
  int64_t signature;
2615
  char*   pComment;
2616
  char*   pCode;
2617
  int8_t  orReplace;
2618
} SCreateFuncReq;
2619

2620
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2621
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2622
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2623

2624
typedef struct {
2625
  char   name[TSDB_FUNC_NAME_LEN];
2626
  int8_t igNotExists;
2627
} SDropFuncReq;
2628

2629
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2630
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2631

2632
typedef struct {
2633
  int32_t numOfFuncs;
2634
  bool    ignoreCodeComment;
2635
  SArray* pFuncNames;
2636
} SRetrieveFuncReq;
2637

2638
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2639
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2640
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2641

2642
typedef struct {
2643
  char    name[TSDB_FUNC_NAME_LEN];
2644
  int8_t  funcType;
2645
  int8_t  scriptType;
2646
  int8_t  outputType;
2647
  int32_t outputLen;
2648
  int32_t bufSize;
2649
  int64_t signature;
2650
  int32_t commentSize;
2651
  int32_t codeSize;
2652
  char*   pComment;
2653
  char*   pCode;
2654
} SFuncInfo;
2655

2656
typedef struct {
2657
  int32_t funcVersion;
2658
  int64_t funcCreatedTime;
2659
} SFuncExtraInfo;
2660

2661
typedef struct {
2662
  int32_t numOfFuncs;
2663
  SArray* pFuncInfos;
2664
  SArray* pFuncExtraInfos;
2665
} SRetrieveFuncRsp;
2666

2667
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2668
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2669
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2670
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2671

2672
typedef struct {
2673
  int32_t       statusInterval;
2674
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2675
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2676
  char          locale[TD_LOCALE_LEN];      // tsLocale
2677
  char          charset[TD_LOCALE_LEN];     // tsCharset
2678
  int8_t        ttlChangeOnWrite;
2679
  int8_t        enableWhiteList;
2680
  int8_t        encryptionKeyStat;
2681
  uint32_t      encryptionKeyChksum;
2682
  SMonitorParas monitorParas;
2683
  int32_t       statusIntervalMs;
2684
} SClusterCfg;
2685

2686
typedef struct {
2687
  int32_t openVnodes;
2688
  int32_t dropVnodes;
2689
  int32_t totalVnodes;
2690
  int32_t masterNum;
2691
  int64_t numOfSelectReqs;
2692
  int64_t numOfInsertReqs;
2693
  int64_t numOfInsertSuccessReqs;
2694
  int64_t numOfBatchInsertReqs;
2695
  int64_t numOfBatchInsertSuccessReqs;
2696
  int64_t errors;
2697
} SVnodesStat;
2698

2699
typedef struct {
2700
  int32_t vgId;
2701
  int8_t  syncState;
2702
  int8_t  syncRestore;
2703
  int64_t syncTerm;
2704
  int64_t roleTimeMs;
2705
  int64_t startTimeMs;
2706
  int8_t  syncCanRead;
2707
  int64_t cacheUsage;
2708
  int64_t numOfTables;
2709
  int64_t numOfTimeSeries;
2710
  int64_t totalStorage;
2711
  int64_t compStorage;
2712
  int64_t pointsWritten;
2713
  int64_t numOfSelectReqs;
2714
  int64_t numOfInsertReqs;
2715
  int64_t numOfInsertSuccessReqs;
2716
  int64_t numOfBatchInsertReqs;
2717
  int64_t numOfBatchInsertSuccessReqs;
2718
  int32_t numOfCachedTables;
2719
  int32_t learnerProgress;  // use one reservered
2720
  int64_t syncAppliedIndex;
2721
  int64_t syncCommitIndex;
2722
  int64_t bufferSegmentUsed;
2723
  int64_t bufferSegmentSize;
2724
  int32_t snapSeq;
2725
  int64_t syncTotalIndex;
2726
} SVnodeLoad;
2727

2728
typedef struct {
2729
  int64_t total_requests;
2730
  int64_t total_rows;
2731
  int64_t total_bytes;
2732
  double  write_size;
2733
  double  cache_hit_ratio;
2734
  int64_t rpc_queue_wait;
2735
  int64_t preprocess_time;
2736

2737
  int64_t memory_table_size;
2738
  int64_t commit_count;
2739
  int64_t merge_count;
2740
  double  commit_time;
2741
  double  merge_time;
2742
  int64_t block_commit_time;
2743
  int64_t memtable_wait_time;
2744
} SVnodeMetrics;
2745

2746
typedef struct {
2747
  int32_t     vgId;
2748
  int64_t     numOfTables;
2749
  int64_t     memSize;
2750
  int64_t     l1Size;
2751
  int64_t     l2Size;
2752
  int64_t     l3Size;
2753
  int64_t     cacheSize;
2754
  int64_t     walSize;
2755
  int64_t     metaSize;
2756
  int64_t     rawDataSize;
2757
  int64_t     ssSize;
2758
  const char* dbname;
2759
  int8_t      estimateRawData;
2760
} SDbSizeStatisInfo;
2761

2762
typedef struct {
2763
  int32_t vgId;
2764
  int64_t nTimeSeries;
2765
} SVnodeLoadLite;
2766

2767
typedef struct {
2768
  int8_t  syncState;
2769
  int64_t syncTerm;
2770
  int8_t  syncRestore;
2771
  int64_t roleTimeMs;
2772
} SMnodeLoad;
2773

2774
typedef struct {
2775
  int32_t dnodeId;
2776
  int64_t numOfProcessedQuery;
2777
  int64_t numOfProcessedCQuery;
2778
  int64_t numOfProcessedFetch;
2779
  int64_t numOfProcessedDrop;
2780
  int64_t numOfProcessedNotify;
2781
  int64_t numOfProcessedHb;
2782
  int64_t numOfProcessedDelete;
2783
  int64_t cacheDataSize;
2784
  int64_t numOfQueryInQueue;
2785
  int64_t numOfFetchInQueue;
2786
  int64_t timeInQueryQueue;
2787
  int64_t timeInFetchQueue;
2788
} SQnodeLoad;
2789

2790
typedef struct {
2791
  int32_t     sver;      // software version
2792
  int64_t     dnodeVer;  // dnode table version in sdb
2793
  int32_t     dnodeId;
2794
  int64_t     clusterId;
2795
  int64_t     rebootTime;
2796
  int64_t     updateTime;
2797
  float       numOfCores;
2798
  int32_t     numOfSupportVnodes;
2799
  int32_t     numOfDiskCfg;
2800
  int64_t     memTotal;
2801
  int64_t     memAvail;
2802
  char        dnodeEp[TSDB_EP_LEN];
2803
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2804
  SMnodeLoad  mload;
2805
  SQnodeLoad  qload;
2806
  SClusterCfg clusterCfg;
2807
  SArray*     pVloads;  // array of SVnodeLoad
2808
  int32_t     statusSeq;
2809
  int64_t     ipWhiteVer;
2810
  int64_t     timeWhiteVer;
2811
  int64_t     analVer;
2812
  int64_t     timestamp;
2813
  char        auditDB[TSDB_DB_FNAME_LEN];
2814
  char        auditToken[TSDB_TOKEN_LEN];
2815
} SStatusReq;
2816

2817
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2818
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2819
void    tFreeSStatusReq(SStatusReq* pReq);
2820

2821
typedef struct {
2822
  int32_t forceReadConfig;
2823
  int32_t cver;
2824
  SArray* array;
2825
} SConfigReq;
2826

2827
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2828
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2829
void    tFreeSConfigReq(SConfigReq* pReq);
2830

2831
typedef struct {
2832
  int32_t dnodeId;
2833
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2834
} SDnodeInfoReq;
2835

2836
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2837
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2838

2839
typedef enum {
2840
  MONITOR_TYPE_COUNTER = 0,
2841
  MONITOR_TYPE_SLOW_LOG = 1,
2842
} MONITOR_TYPE;
2843

2844
typedef struct {
2845
  int32_t      contLen;
2846
  char*        pCont;
2847
  MONITOR_TYPE type;
2848
} SStatisReq;
2849

2850
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2851
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2852
void    tFreeSStatisReq(SStatisReq* pReq);
2853

2854
typedef struct {
2855
  char    db[TSDB_DB_FNAME_LEN];
2856
  char    table[TSDB_TABLE_NAME_LEN];
2857
  char    operation[AUDIT_OPERATION_LEN];
2858
  int32_t sqlLen;
2859
  char*   pSql;
2860
  double  duration;
2861
  int64_t affectedRows;
2862
} SAuditReq;
2863
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2864
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2865
void    tFreeSAuditReq(SAuditReq* pReq);
2866

2867
typedef struct {
2868
  SArray* auditArr;
2869
} SBatchAuditReq;
2870
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2871
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2872
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2873

2874
typedef struct {
2875
  int32_t dnodeId;
2876
  int64_t clusterId;
2877
  SArray* pVloads;
2878
} SNotifyReq;
2879

2880
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2881
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2882
void    tFreeSNotifyReq(SNotifyReq* pReq);
2883

2884
typedef struct {
2885
  int32_t dnodeId;
2886
  int64_t clusterId;
2887
} SDnodeCfg;
2888

2889
typedef struct {
2890
  int32_t id;
2891
  int8_t  isMnode;
2892
  SEp     ep;
2893
} SDnodeEp;
2894

2895
typedef struct {
2896
  int32_t id;
2897
  int8_t  isMnode;
2898
  int8_t  offlineReason;
2899
  SEp     ep;
2900
  char    active[TSDB_ACTIVE_KEY_LEN];
2901
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2902
} SDnodeInfo;
2903

2904
typedef struct {
2905
  int64_t   dnodeVer;
2906
  SDnodeCfg dnodeCfg;
2907
  SArray*   pDnodeEps;  // Array of SDnodeEp
2908
  int32_t   statusSeq;
2909
  int64_t   ipWhiteVer;
2910
  int64_t   analVer;
2911
  int64_t   timeWhiteVer;
2912
  char      auditDB[TSDB_DB_FNAME_LEN];
2913
  char      auditToken[TSDB_TOKEN_LEN];
2914
} SStatusRsp;
2915

2916
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2917
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2918
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2919

2920
typedef struct {
2921
  int32_t forceReadConfig;
2922
  int32_t isConifgVerified;
2923
  int32_t isVersionVerified;
2924
  int32_t cver;
2925
  SArray* array;
2926
} SConfigRsp;
2927

2928
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2929
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2930
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2931

2932
typedef struct {
2933
  int32_t dnodeId;
2934
  int32_t keyVersion;  // Local key version
2935
} SKeySyncReq;
2936

2937
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2938
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2939

2940
typedef struct {
2941
  int32_t keyVersion;        // mnode's key version
2942
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2943
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2944
  char    svrKey[129];       // Server key (if needUpdate)
2945
  char    dbKey[129];        // Database key (if needUpdate)
2946
  char    cfgKey[129];       // Config key (if needUpdate)
2947
  char    metaKey[129];      // Metadata key (if needUpdate)
2948
  char    dataKey[129];      // Data key (if needUpdate)
2949
  int32_t algorithm;         // Encryption algorithm for master keys
2950
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2951
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2952
  int64_t createTime;        // Key creation time
2953
  int64_t svrKeyUpdateTime;  // Server key update time
2954
  int64_t dbKeyUpdateTime;   // Database key update time
2955
} SKeySyncRsp;
2956

2957
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2958
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2959

2960
typedef struct {
2961
  int32_t reserved;
2962
} SMTimerReq;
2963

2964
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2965
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2966

2967
typedef struct SOrphanTask {
2968
  int64_t streamId;
2969
  int32_t taskId;
2970
  int32_t nodeId;
2971
} SOrphanTask;
2972

2973
typedef struct SMStreamDropOrphanMsg {
2974
  SArray* pList;  // SArray<SOrphanTask>
2975
} SMStreamDropOrphanMsg;
2976

2977
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2978
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2979
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2980

2981
typedef struct {
2982
  int32_t  id;
2983
  uint16_t port;                 // node sync Port
2984
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2985
} SReplica;
2986

2987
typedef struct {
2988
  int32_t  vgId;
2989
  char     db[TSDB_DB_FNAME_LEN];
2990
  int64_t  dbUid;
2991
  int32_t  vgVersion;
2992
  int32_t  numOfStables;
2993
  int32_t  buffer;
2994
  int32_t  pageSize;
2995
  int32_t  pages;
2996
  int32_t  cacheLastSize;
2997
  int32_t  daysPerFile;
2998
  int32_t  daysToKeep0;
2999
  int32_t  daysToKeep1;
3000
  int32_t  daysToKeep2;
3001
  int32_t  keepTimeOffset;
3002
  int32_t  minRows;
3003
  int32_t  maxRows;
3004
  int32_t  walFsyncPeriod;
3005
  uint32_t hashBegin;
3006
  uint32_t hashEnd;
3007
  int8_t   hashMethod;
3008
  int8_t   walLevel;
3009
  int8_t   precision;
3010
  int8_t   compression;
3011
  int8_t   strict;
3012
  int8_t   cacheLast;
3013
  int8_t   isTsma;
3014
  int8_t   replica;
3015
  int8_t   selfIndex;
3016
  SReplica replicas[TSDB_MAX_REPLICA];
3017
  int32_t  numOfRetensions;
3018
  SArray*  pRetensions;  // SRetention
3019
  void*    pTsma;
3020
  int32_t  walRetentionPeriod;
3021
  int64_t  walRetentionSize;
3022
  int32_t  walRollPeriod;
3023
  int64_t  walSegmentSize;
3024
  int16_t  sstTrigger;
3025
  int16_t  hashPrefix;
3026
  int16_t  hashSuffix;
3027
  int32_t  tsdbPageSize;
3028
  int32_t  ssChunkSize;
3029
  int32_t  ssKeepLocal;
3030
  int8_t   ssCompact;
3031
  int64_t  reserved[6];
3032
  int8_t   learnerReplica;
3033
  int8_t   learnerSelfIndex;
3034
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3035
  int32_t  changeVersion;
3036
  int8_t   encryptAlgorithm;
3037
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
3038
  union {
3039
    uint8_t flags;
3040
    struct {
3041
      uint8_t isAudit : 1;
3042
      uint8_t allowDrop : 1;
3043
      uint8_t padding : 6;
3044
    };
3045
  };
3046
} SCreateVnodeReq;
3047

3048
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3049
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
3050
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
3051

3052
typedef struct {
3053
  union {
3054
    int32_t compactId;
3055
    int32_t id;
3056
  };
3057
  int32_t vgId;
3058
  int32_t dnodeId;
3059
} SQueryCompactProgressReq;
3060

3061
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3062
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3063

3064
typedef struct {
3065
  union {
3066
    int32_t compactId;
3067
    int32_t id;
3068
  };
3069
  int32_t vgId;
3070
  int32_t dnodeId;
3071
  int32_t numberFileset;
3072
  int32_t finished;
3073
  int32_t progress;
3074
  int64_t remainingTime;
3075
} SQueryCompactProgressRsp;
3076

3077
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3078
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3079

3080
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3081
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3082

3083
typedef struct {
3084
  int32_t vgId;
3085
  int32_t dnodeId;
3086
  int64_t dbUid;
3087
  char    db[TSDB_DB_FNAME_LEN];
3088
  int64_t reserved[8];
3089
} SDropVnodeReq;
3090

3091
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3092
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3093

3094
typedef struct {
3095
  char    colName[TSDB_COL_NAME_LEN];
3096
  char    stb[TSDB_TABLE_FNAME_LEN];
3097
  int64_t stbUid;
3098
  int64_t dbUid;
3099
  int64_t reserved[8];
3100
} SDropIndexReq;
3101

3102
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3103
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3104

3105
typedef struct {
3106
  int64_t dbUid;
3107
  char    db[TSDB_DB_FNAME_LEN];
3108
  union {
3109
    int64_t compactStartTime;
3110
    int64_t startTime;
3111
  };
3112

3113
  STimeWindow tw;
3114
  union {
3115
    int32_t compactId;
3116
    int32_t id;
3117
  };
3118
  int8_t metaOnly;
3119
  union {
3120
    uint16_t flags;
3121
    struct {
3122
      uint16_t optrType : 3;     // ETsdbOpType
3123
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3124
      uint16_t reserved : 12;
3125
    };
3126
  };
3127
  int8_t force;  // force compact
3128
} SCompactVnodeReq;
3129

3130
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3131
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3132

3133
typedef struct {
3134
  union {
3135
    int32_t compactId;
3136
    int32_t taskId;
3137
  };
3138
  int32_t vgId;
3139
  int32_t dnodeId;
3140
} SVKillCompactReq;
3141

3142
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3143
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3144

3145
typedef SVKillCompactReq SVKillRetentionReq;
3146

3147
typedef struct {
3148
  char        db[TSDB_DB_FNAME_LEN];
3149
  int32_t     maxSpeed;
3150
  int32_t     sqlLen;
3151
  char*       sql;
3152
  SArray*     vgroupIds;
3153
  STimeWindow tw;  // unit is second
3154
  union {
3155
    uint32_t flags;
3156
    struct {
3157
      uint32_t optrType : 3;     // ETsdbOpType
3158
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3159
      uint32_t reserved : 28;
3160
    };
3161
  };
3162
} STrimDbReq;
3163

3164
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3165
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3166
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3167

3168
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3169

3170
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3171
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3172

3173
typedef struct {
3174
  int32_t vgVersion;
3175
  int32_t buffer;
3176
  int32_t pageSize;
3177
  int32_t pages;
3178
  int32_t cacheLastSize;
3179
  int32_t daysPerFile;
3180
  int32_t daysToKeep0;
3181
  int32_t daysToKeep1;
3182
  int32_t daysToKeep2;
3183
  int32_t keepTimeOffset;
3184
  int32_t walFsyncPeriod;
3185
  int8_t  walLevel;
3186
  int8_t  strict;
3187
  int8_t  cacheLast;
3188
  int64_t reserved[7];
3189
  // 1st modification
3190
  int16_t sttTrigger;
3191
  int32_t minRows;
3192
  // 2nd modification
3193
  int32_t walRetentionPeriod;
3194
  int32_t walRetentionSize;
3195
  int32_t ssKeepLocal;
3196
  int8_t  ssCompact;
3197
  int8_t  allowDrop;
3198
} SAlterVnodeConfigReq;
3199

3200
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3201
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3202

3203
typedef struct {
3204
  int32_t  vgId;
3205
  int8_t   strict;
3206
  int8_t   selfIndex;
3207
  int8_t   replica;
3208
  SReplica replicas[TSDB_MAX_REPLICA];
3209
  int64_t  reserved[8];
3210
  int8_t   learnerSelfIndex;
3211
  int8_t   learnerReplica;
3212
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3213
  int32_t  changeVersion;
3214
  int32_t  electBaseLine;
3215
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3216

3217
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3218
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3219

3220
typedef struct {
3221
  int32_t vgId;
3222
  int8_t  disable;
3223
} SDisableVnodeWriteReq;
3224

3225
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3226
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3227

3228
typedef struct {
3229
  int32_t  srcVgId;
3230
  int32_t  dstVgId;
3231
  uint32_t hashBegin;
3232
  uint32_t hashEnd;
3233
  int32_t  changeVersion;
3234
  int32_t  reserved;
3235
} SAlterVnodeHashRangeReq;
3236

3237
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3238
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3239

3240
#define REQ_OPT_TBNAME 0x0
3241
#define REQ_OPT_TBUID  0x01
3242
typedef struct {
3243
  SMsgHead header;
3244
  char     dbFName[TSDB_DB_FNAME_LEN];
3245
  char     tbName[TSDB_TABLE_NAME_LEN];
3246
  uint8_t  option;
3247
  uint8_t  autoCreateCtb;
3248
} STableInfoReq;
3249

3250
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3251
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3252

3253
typedef struct {
3254
  int8_t  metaClone;  // create local clone of the cached table meta
3255
  int32_t numOfVgroups;
3256
  int32_t numOfTables;
3257
  int32_t numOfUdfs;
3258
  char    tableNames[];
3259
} SMultiTableInfoReq;
3260

3261
// todo refactor
3262
typedef struct SVgroupInfo {
3263
  int32_t  vgId;
3264
  uint32_t hashBegin;
3265
  uint32_t hashEnd;
3266
  SEpSet   epSet;
3267
  union {
3268
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3269
    int32_t taskId;      // used in stream
3270
  };
3271
} SVgroupInfo;
3272

3273
typedef struct {
3274
  int32_t     numOfVgroups;
3275
  SVgroupInfo vgroups[];
3276
} SVgroupsInfo;
3277

3278
typedef struct {
3279
  STableMetaRsp* pMeta;
3280
} SMAlterStbRsp;
3281

3282
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3283
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3284
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3285

3286
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3287
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3288
void    tFreeSTableMetaRsp(void* pRsp);
3289
void    tFreeSTableIndexRsp(void* info);
3290

3291
typedef struct {
3292
  SArray* pMetaRsp;   // Array of STableMetaRsp
3293
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3294
} SSTbHbRsp;
3295

3296
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3297
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3298
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3299

3300
typedef struct {
3301
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3302
} SViewHbRsp;
3303

3304
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3305
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3306
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3307

3308
typedef struct {
3309
  int32_t numOfTables;
3310
  int32_t numOfVgroup;
3311
  int32_t numOfUdf;
3312
  int32_t contLen;
3313
  int8_t  compressed;  // denote if compressed or not
3314
  int32_t rawLen;      // size before compress
3315
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3316
  char    meta[];
3317
} SMultiTableMeta;
3318

3319
typedef struct {
3320
  int32_t dataLen;
3321
  char    name[TSDB_TABLE_FNAME_LEN];
3322
  char*   data;
3323
} STagData;
3324

3325
typedef struct {
3326
  int32_t  opType;
3327
  uint32_t valLen;
3328
  char*    val;
3329
} SShowVariablesReq;
3330

3331
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3332
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3333
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3334

3335
typedef struct {
3336
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3337
  char value[TSDB_CONFIG_PATH_LEN + 1];
3338
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3339
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3340
  char info[TSDB_CONFIG_INFO_LEN + 1];
3341
} SVariablesInfo;
3342

3343
typedef struct {
3344
  SArray* variables;  // SArray<SVariablesInfo>
3345
} SShowVariablesRsp;
3346

3347
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3348
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3349

3350
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3351

3352
/*
3353
 * sql: show tables like '%a_%'
3354
 * payload is the query condition, e.g., '%a_%'
3355
 * payloadLen is the length of payload
3356
 */
3357
typedef struct {
3358
  int32_t type;
3359
  char    db[TSDB_DB_FNAME_LEN];
3360
  int32_t payloadLen;
3361
  char*   payload;
3362
} SShowReq;
3363

3364
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3365
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3366
void tFreeSShowReq(SShowReq* pReq);
3367

3368
typedef struct {
3369
  int64_t       showId;
3370
  STableMetaRsp tableMeta;
3371
} SShowRsp, SVShowTablesRsp;
3372

3373
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3374
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3375
// void    tFreeSShowRsp(SShowRsp* pRsp);
3376

3377
typedef struct {
3378
  char    db[TSDB_DB_FNAME_LEN];
3379
  char    tb[TSDB_TABLE_NAME_LEN];
3380
  char    user[TSDB_USER_LEN];
3381
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3382
  int64_t showId;
3383
  int64_t compactId;  // for compact
3384
  bool    withFull;   // for show users full
3385
} SRetrieveTableReq;
3386

3387
typedef struct SSysTableSchema {
3388
  int8_t   type;
3389
  col_id_t colId;
3390
  int32_t  bytes;
3391
} SSysTableSchema;
3392

3393
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3394
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3395

3396
#define RETRIEVE_TABLE_RSP_VERSION         0
3397
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3398
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3399

3400
typedef struct {
3401
  int64_t useconds;
3402
  int8_t  completed;  // all results are returned to client
3403
  int8_t  precision;
3404
  int8_t  compressed;
3405
  int8_t  streamBlockType;
3406
  int32_t payloadLen;
3407
  int32_t compLen;
3408
  int32_t numOfBlocks;
3409
  int64_t numOfRows;  // from int32_t change to int64_t
3410
  int64_t numOfCols;
3411
  int64_t skey;
3412
  int64_t ekey;
3413
  int64_t version;                         // for stream
3414
  TSKEY   watermark;                       // for stream
3415
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3416
  char    data[];
3417
} SRetrieveTableRsp;
3418

3419
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3420

3421
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3422
  do {                                          \
3423
    ((int32_t*)(_p))[0] = (_compLen);           \
3424
    ((int32_t*)(_p))[1] = (_fullLen);           \
3425
  } while (0);
3426

3427
typedef struct {
3428
  int64_t version;
3429
  int64_t numOfRows;
3430
  int8_t  compressed;
3431
  int8_t  precision;
3432
  char    data[];
3433
} SRetrieveTableRspForTmq;
3434

3435
typedef struct {
3436
  int64_t handle;
3437
  int64_t useconds;
3438
  int8_t  completed;  // all results are returned to client
3439
  int8_t  precision;
3440
  int8_t  compressed;
3441
  int32_t compLen;
3442
  int32_t numOfRows;
3443
  int32_t fullLen;
3444
  char    data[];
3445
} SRetrieveMetaTableRsp;
3446

3447
typedef struct SExplainExecInfo {
3448
  double   startupCost;
3449
  double   totalCost;
3450
  uint64_t numOfRows;
3451
  uint32_t verboseLen;
3452
  void*    verboseInfo;
3453
} SExplainExecInfo;
3454

3455
typedef struct {
3456
  int32_t           numOfPlans;
3457
  SExplainExecInfo* subplanInfo;
3458
} SExplainRsp;
3459

3460
typedef struct {
3461
  SExplainRsp rsp;
3462
  uint64_t    qId;
3463
  uint64_t    cId;
3464
  uint64_t    tId;
3465
  int64_t     rId;
3466
  int32_t     eId;
3467
} SExplainLocalRsp;
3468

3469
typedef struct STableScanAnalyzeInfo {
3470
  uint64_t totalRows;
3471
  uint64_t totalCheckedRows;
3472
  uint32_t totalBlocks;
3473
  uint32_t loadBlocks;
3474
  uint32_t loadBlockStatis;
3475
  uint32_t skipBlocks;
3476
  uint32_t filterOutBlocks;
3477
  double   elapsedTime;
3478
  double   filterTime;
3479
} STableScanAnalyzeInfo;
3480

3481
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3482
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3483
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3484

3485
typedef struct {
3486
  char    config[TSDB_DNODE_CONFIG_LEN];
3487
  char    value[TSDB_CLUSTER_VALUE_LEN];
3488
  int32_t sqlLen;
3489
  char*   sql;
3490
} SMCfgClusterReq;
3491

3492
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3493
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3494
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3495

3496
typedef struct {
3497
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3498
  int32_t port;
3499
  int32_t sqlLen;
3500
  char*   sql;
3501
} SCreateDnodeReq;
3502

3503
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3504
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3505
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3506

3507
typedef struct {
3508
  int32_t dnodeId;
3509
  char    fqdn[TSDB_FQDN_LEN];
3510
  int32_t port;
3511
  int8_t  force;
3512
  int8_t  unsafe;
3513
  int32_t sqlLen;
3514
  char*   sql;
3515
} SDropDnodeReq;
3516

3517
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3518
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3519
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3520

3521
enum {
3522
  RESTORE_TYPE__ALL = 1,
3523
  RESTORE_TYPE__MNODE,
3524
  RESTORE_TYPE__VNODE,
3525
  RESTORE_TYPE__QNODE,
3526
};
3527

3528
typedef struct {
3529
  int32_t dnodeId;
3530
  int8_t  restoreType;
3531
  int32_t sqlLen;
3532
  char*   sql;
3533
} SRestoreDnodeReq;
3534

3535
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3536
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3537
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3538

3539
typedef struct {
3540
  int32_t dnodeId;
3541
  char    config[TSDB_DNODE_CONFIG_LEN];
3542
  char    value[TSDB_DNODE_VALUE_LEN];
3543
  int32_t sqlLen;
3544
  char*   sql;
3545
} SMCfgDnodeReq;
3546

3547
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3548
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3549
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3550

3551
typedef struct {
3552
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3553
  char    newKey[ENCRYPT_KEY_LEN + 1];
3554
  int32_t sqlLen;
3555
  char*   sql;
3556
} SMAlterEncryptKeyReq;
3557

3558
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3559
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3560
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3561

3562
typedef struct {
3563
  int32_t days;
3564
  char    strategy[ENCRYPT_KEY_EXPIRE_STRATEGY_LEN + 1];
3565
  int32_t sqlLen;
3566
  char*   sql;
3567
} SMAlterKeyExpirationReq;
3568

3569
int32_t tSerializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3570
int32_t tDeserializeSMAlterKeyExpirationReq(void* buf, int32_t bufLen, SMAlterKeyExpirationReq* pReq);
3571
void    tFreeSMAlterKeyExpirationReq(SMAlterKeyExpirationReq* pReq);
3572

3573
typedef struct {
3574
  char    config[TSDB_DNODE_CONFIG_LEN];
3575
  char    value[TSDB_DNODE_VALUE_LEN];
3576
  int32_t version;
3577
} SDCfgDnodeReq;
3578

3579
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3580
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3581

3582
typedef struct {
3583
  int32_t dnodeId;
3584
  int32_t sqlLen;
3585
  char*   sql;
3586
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3587
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3588

3589
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3590
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3591

3592
typedef struct {
3593
  int32_t nodeId;
3594
  SEpSet  epSet;
3595
} SNodeEpSet;
3596

3597
typedef struct {
3598
  int32_t    snodeId;
3599
  SNodeEpSet leaders[2];
3600
  SNodeEpSet replica;
3601
  int32_t    sqlLen;
3602
  char*      sql;
3603
} SDCreateSnodeReq;
3604

3605
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3606
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3607
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3608

3609
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3610
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3611
typedef struct {
3612
  int8_t   replica;
3613
  SReplica replicas[TSDB_MAX_REPLICA];
3614
  int8_t   learnerReplica;
3615
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3616
  int64_t  lastIndex;
3617
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3618
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3619

3620
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3621
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3622

3623
typedef struct {
3624
  int32_t urlLen;
3625
  int32_t sqlLen;
3626
  char*   url;
3627
  char*   sql;
3628
} SMCreateAnodeReq;
3629

3630
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3631
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3632
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3633

3634
typedef struct {
3635
  int32_t anodeId;
3636
  int32_t sqlLen;
3637
  char*   sql;
3638
} SMDropAnodeReq, SMUpdateAnodeReq;
3639

3640
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3641
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3642
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3643
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3644
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3645
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3646

3647
typedef struct {
3648
  int32_t dnodeId;
3649
  int32_t bnodeProto;
3650
  int32_t sqlLen;
3651
  char*   sql;
3652
} SMCreateBnodeReq, SDCreateBnodeReq;
3653

3654
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3655
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3656
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3657

3658
typedef struct {
3659
  int32_t dnodeId;
3660
  int32_t sqlLen;
3661
  char*   sql;
3662
} SMDropBnodeReq, SDDropBnodeReq;
3663

3664
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3665
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3666
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3667

3668
typedef struct {
3669
  bool        shouldFree;
3670
  int32_t     len;
3671
  const char* ptr;
3672
} CowStr;
3673
/**
3674
 * @brief Create a CowStr object.
3675
 *
3676
 * @param len: length of the string.
3677
 * @param ptr: pointer to the string input.
3678
 * @param shouldClone: whether to clone the string.
3679
 * @return CowStr object.
3680
 */
3681
CowStr xCreateCowStr(int32_t len, const char* ptr, bool shouldClone);
3682
/**
3683
 * @brief Set a CowStr object with given string.
3684
 *
3685
 * @param cow: pointer to the CowStr object.
3686
 * @param len: length of the string.
3687
 * @param ptr: pointer to the string input.
3688
 * @param shouldFree: whether to free the string.
3689
 */
3690
void xSetCowStr(CowStr* cow, int32_t len, const char* ptr, bool shouldFree);
3691
/**
3692
 * @brief Clone a CowStr object without copy the string.
3693
 *
3694
 * @param cow: pointer to the CowStr object.
3695
 * @return CowStr object.
3696
 */
3697
CowStr xCloneRefCowStr(CowStr* cow);
3698
/**
3699
 * @brief Convert a CowStr object to a string.
3700
 *
3701
 * @param cow: pointer to the CowStr object.
3702
 */
3703
char* xCowStrToStr(CowStr* cow);
3704
/**
3705
 * @brief Deallocate a CowStr object. Clears the string and resets length to 0.
3706
 *
3707
 * @param cow: pointer to the CowStr object.
3708
 */
3709
void xFreeCowStr(CowStr* cow);
3710
/**
3711
 * @brief Encode and push a CowStr object into the encoder.
3712
 *
3713
 * @param encoder
3714
 * @param cow
3715
 * @return int32_t
3716
 */
3717
int32_t xEncodeCowStr(SEncoder* encoder, CowStr* cow);
3718
/**
3719
 * @brief Decode a CowStr from the encoder.
3720
 *
3721
 * @param decoder
3722
 * @param cow
3723
 * @param shouldClone
3724
 * @return int32_t
3725
 */
3726
int32_t xDecodeCowStr(SDecoder* decoder, CowStr* cow, bool shouldClone);
3727

3728
typedef struct {
3729
  int32_t sqlLen;
3730
  int32_t urlLen;
3731
  int32_t userLen;
3732
  int32_t passLen;
3733
  int32_t passIsMd5;
3734
  char*   sql;
3735
  char*   url;
3736
  char*   user;
3737
  char*   pass;
3738
  CowStr  token;
3739
} SMCreateXnodeReq, SDCreateXnodeReq;
3740

3741
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3742
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3743
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3744

3745
typedef struct {
3746
  int32_t xnodeId;
3747
  int32_t force;
3748
  int32_t urlLen;
3749
  int32_t sqlLen;
3750
  char*   url;
3751
  char*   sql;
3752
} SMDropXnodeReq, SDDropXnodeReq;
3753

3754
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3755
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3756
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3757

3758
typedef struct {
3759
  int32_t id;
3760
  CowStr  token;
3761
  CowStr  user;
3762
  CowStr  pass;
3763
  int32_t urlLen;
3764
  int32_t sqlLen;
3765
  char*   url;
3766
  char*   sql;
3767
} SMUpdateXnodeReq;
3768
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3769
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3770
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3771

3772
typedef struct {
3773
  int32_t xnodeId;
3774
  int32_t sqlLen;
3775
  char*   sql;
3776
} SMDrainXnodeReq;
3777
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3778
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3779
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3780
typedef enum {
3781
  XNODE_TASK_SOURCE_DSN = 1,
3782
  XNODE_TASK_SOURCE_DATABASE,
3783
  XNODE_TASK_SOURCE_TOPIC,
3784
} ENodeXTaskSourceType;
3785

3786
typedef enum {
3787
  XNODE_TASK_SINK_DSN = 1,
3788
  XNODE_TASK_SINK_DATABASE,
3789
} ENodeXTaskSinkType;
3790

3791
typedef struct {
3792
  ENodeXTaskSourceType type;
3793
  CowStr               cstr;
3794
} xTaskSource;
3795
/**
3796
 * @brief Deallocate a xTaskSource object.
3797
 *
3798
 * @param source ptr
3799
 */
3800
void xFreeTaskSource(xTaskSource* source);
3801
/**
3802
 * @brief Create a xTaskSource object with cloned source string.
3803
 *
3804
 * @param sourceType: source type.
3805
 * @param len: length of source string.
3806
 * @param source: source string ptr.
3807
 * @return xTaskSource object
3808
 */
3809
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3810
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3811
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3812
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3813
const char* xGetTaskSourceStr(xTaskSource* source);
3814
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3815
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3816

3817
typedef struct {
3818
  ENodeXTaskSinkType type;
3819
  CowStr             cstr;
3820
} xTaskSink;
3821
/**
3822
 * @brief Deallocate a xTaskSink object.
3823
 *
3824
 * @param sink ptr
3825
 */
3826
void xFreeTaskSink(xTaskSink* sink);
3827
/**
3828
 * @brief Create a xTaskSink object with cloned name string.
3829
 *
3830
 * @param sinkType: sink type.
3831
 * @param len: length of sink string.
3832
 * @param ptr: sink string ptr.
3833
 * @return xTaskSink object
3834
 */
3835
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3836
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3837
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3838
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3839
const char* xGetTaskSinkStr(xTaskSink* sink);
3840
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3841
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3842

3843
typedef struct {
3844
  int32_t via;
3845
  CowStr  parser;
3846
  // CowStr  reason;
3847
  CowStr  trigger;
3848
  CowStr  health;
3849
  int32_t optionsNum;
3850
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3851
} xTaskOptions;
3852
/**
3853
 * @brief Deallocate a xTaskOptions object.
3854
 *
3855
 * @param options ptr
3856
 */
3857
void    xFreeTaskOptions(xTaskOptions* options);
3858
void    printXnodeTaskOptions(xTaskOptions* options);
3859
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3860
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3861

3862
typedef struct {
3863
  int32_t sqlLen;
3864
  char*   sql;
3865
  int32_t      xnodeId;
3866
  CowStr       name;
3867
  xTaskSource  source;
3868
  xTaskSink    sink;
3869
  xTaskOptions options;
3870
} SMCreateXnodeTaskReq;
3871
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3872
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3873
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3874

3875
typedef struct {
3876
  int32_t     tid;
3877
  CowStr      name;
3878
  int32_t     via;
3879
  int32_t     xnodeId;
3880
  CowStr      status;
3881
  xTaskSource source;
3882
  xTaskSink   sink;
3883
  CowStr      parser;
3884
  CowStr      reason;
3885
  CowStr      updateName;
3886
  CowStr      labels;
3887
  int32_t     sqlLen;
3888
  char*       sql;
3889
} SMUpdateXnodeTaskReq;
3890
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3891
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3892
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3893

3894
typedef struct {
3895
  int32_t id;
3896
  bool    force;
3897
  CowStr  name;
3898
  int32_t sqlLen;
3899
  char*   sql;
3900
} SMDropXnodeTaskReq;
3901
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3902
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3903
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3904

3905
typedef struct {
3906
  int32_t tid;
3907
  CowStr  name;
3908
  int32_t sqlLen;
3909
  char*   sql;
3910
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3911
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3912
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3913
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3914

3915
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3916
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3917
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3918

3919
typedef struct {
3920
  int32_t tid;
3921
  int32_t via;
3922
  int32_t xnodeId;
3923
  CowStr  status;
3924
  CowStr  config;
3925
  CowStr  reason;
3926
  int32_t sqlLen;
3927
  char*   sql;
3928
} SMCreateXnodeJobReq;
3929
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3930
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3931
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3932

3933
typedef struct {
3934
  int32_t jid;
3935
  int32_t via;
3936
  int32_t xnodeId;
3937
  CowStr  status;
3938
  int32_t configLen;
3939
  int32_t reasonLen;
3940
  int32_t sqlLen;
3941
  char*   config;
3942
  char*   reason;
3943
  char*   sql;
3944
} SMUpdateXnodeJobReq;
3945
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3946
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3947
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3948

3949
typedef struct {
3950
  int32_t jid;
3951
  int32_t xnodeId;
3952
  int32_t sqlLen;
3953
  char*   sql;
3954
} SMRebalanceXnodeJobReq;
3955
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3956
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3957
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3958

3959
typedef struct {
3960
  CowStr  ast;
3961
  int32_t sqlLen;
3962
  char*   sql;
3963
} SMRebalanceXnodeJobsWhereReq;
3964
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3965
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3966
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3967

3968
typedef struct {
3969
  int32_t jid;
3970
  CowStr  ast;
3971
  int32_t sqlLen;
3972
  char*   sql;
3973
} SMDropXnodeJobReq;
3974
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3975
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3976
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3977

3978
typedef struct {
3979
  int32_t      sqlLen;
3980
  char*        sql;
3981
  CowStr       name;
3982
  CowStr       status;
3983
  xTaskOptions options;
3984
} SMCreateXnodeAgentReq;
3985
int32_t tSerializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3986
int32_t tDeserializeSMCreateXnodeAgentReq(void* buf, int32_t bufLen, SMCreateXnodeAgentReq* pReq);
3987
void    tFreeSMCreateXnodeAgentReq(SMCreateXnodeAgentReq* pReq);
3988

3989
typedef struct {
3990
  int32_t      sqlLen;
3991
  char*        sql;
3992
  int32_t      id;
3993
  CowStr       name;
3994
  xTaskOptions options;
3995
} SMUpdateXnodeAgentReq;
3996
int32_t tSerializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3997
int32_t tDeserializeSMUpdateXnodeAgentReq(void* buf, int32_t bufLen, SMUpdateXnodeAgentReq* pReq);
3998
void    tFreeSMUpdateXnodeAgentReq(SMUpdateXnodeAgentReq* pReq);
3999

4000
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
4001
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4002
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
4003
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
4004

4005
typedef struct {
4006
  int32_t vgId;
4007
  int32_t hbSeq;
4008
} SVArbHbReqMember;
4009

4010
typedef struct {
4011
  int32_t dnodeId;
4012
  char*   arbToken;
4013
  int64_t arbTerm;
4014
  SArray* hbMembers;  // SVArbHbReqMember
4015
} SVArbHeartBeatReq;
4016

4017
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4018
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
4019
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
4020

4021
typedef struct {
4022
  int32_t vgId;
4023
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
4024
  int32_t hbSeq;
4025
} SVArbHbRspMember;
4026

4027
typedef struct {
4028
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
4029
  int32_t dnodeId;
4030
  SArray* hbMembers;  // SVArbHbRspMember
4031
} SVArbHeartBeatRsp;
4032

4033
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4034
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
4035
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
4036

4037
typedef struct {
4038
  char*   arbToken;
4039
  int64_t arbTerm;
4040
  char*   member0Token;
4041
  char*   member1Token;
4042
} SVArbCheckSyncReq;
4043

4044
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4045
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
4046
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
4047

4048
typedef struct {
4049
  char*   arbToken;
4050
  char*   member0Token;
4051
  char*   member1Token;
4052
  int32_t vgId;
4053
  int32_t errCode;
4054
} SVArbCheckSyncRsp;
4055

4056
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4057
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
4058
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
4059

4060
typedef struct {
4061
  char*   arbToken;
4062
  int64_t arbTerm;
4063
  char*   memberToken;
4064
  int8_t  force;
4065
} SVArbSetAssignedLeaderReq;
4066

4067
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4068
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
4069
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
4070

4071
typedef struct {
4072
  char*   arbToken;
4073
  char*   memberToken;
4074
  int32_t vgId;
4075
} SVArbSetAssignedLeaderRsp;
4076

4077
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4078
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4079
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4080

4081
typedef struct {
4082
  int32_t dnodeId;
4083
  char*   token;
4084
} SMArbUpdateGroupMember;
4085

4086
typedef struct {
4087
  int32_t dnodeId;
4088
  char*   token;
4089
  int8_t  acked;
4090
} SMArbUpdateGroupAssigned;
4091

4092
typedef struct {
4093
  int32_t                  vgId;
4094
  int64_t                  dbUid;
4095
  SMArbUpdateGroupMember   members[2];
4096
  int8_t                   isSync;
4097
  int8_t                   assignedAcked;
4098
  SMArbUpdateGroupAssigned assignedLeader;
4099
  int64_t                  version;
4100
  int32_t                  code;
4101
  int64_t                  updateTimeMs;
4102
} SMArbUpdateGroup;
4103

4104
typedef struct {
4105
  SArray* updateArray;  // SMArbUpdateGroup
4106
} SMArbUpdateGroupBatchReq;
4107

4108
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4109
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4110
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4111

4112
typedef struct {
4113
  char queryStrId[TSDB_QUERY_ID_LEN];
4114
} SKillQueryReq;
4115

4116
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4117
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4118

4119
typedef struct {
4120
  uint32_t connId;
4121
} SKillConnReq;
4122

4123
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4124
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4125

4126
typedef struct {
4127
  int32_t transId;
4128
} SKillTransReq;
4129

4130
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4131
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4132

4133
typedef struct {
4134
  int32_t useless;  // useless
4135
  int32_t sqlLen;
4136
  char*   sql;
4137
} SBalanceVgroupReq;
4138

4139
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4140
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4141
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4142

4143
typedef struct {
4144
  int32_t useless;  // useless
4145
  int32_t sqlLen;
4146
  char*   sql;
4147
} SAssignLeaderReq;
4148

4149
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4150
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4151
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4152
typedef struct {
4153
  int32_t vgId1;
4154
  int32_t vgId2;
4155
} SMergeVgroupReq;
4156

4157
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4158
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4159

4160
typedef struct {
4161
  int32_t vgId;
4162
  int32_t dnodeId1;
4163
  int32_t dnodeId2;
4164
  int32_t dnodeId3;
4165
  int32_t sqlLen;
4166
  char*   sql;
4167
} SRedistributeVgroupReq;
4168

4169
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4170
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4171
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4172

4173
typedef struct {
4174
  int32_t reserved;
4175
  int32_t vgId;
4176
  int32_t sqlLen;
4177
  char*   sql;
4178
  char    db[TSDB_DB_FNAME_LEN];
4179
} SBalanceVgroupLeaderReq;
4180

4181
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4182
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4183
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4184

4185
typedef struct {
4186
  int32_t vgId;
4187
} SForceBecomeFollowerReq;
4188

4189
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4190
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4191

4192
typedef struct {
4193
  int32_t vgId;
4194
  bool    force;
4195
} SSplitVgroupReq;
4196

4197
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4198
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4199

4200
typedef struct {
4201
  char user[TSDB_USER_LEN];
4202
  char spi;
4203
  char encrypt;
4204
  char secret[TSDB_PASSWORD_LEN];
4205
  char ckey[TSDB_PASSWORD_LEN];
4206
} SAuthReq, SAuthRsp;
4207

4208
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4209
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4210

4211
typedef struct {
4212
  int32_t statusCode;
4213
  char    details[1024];
4214
} SServerStatusRsp;
4215

4216
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4217
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4218

4219
/**
4220
 * The layout of the query message payload is as following:
4221
 * +--------------------+---------------------------------+
4222
 * |Sql statement       | Physical plan                   |
4223
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4224
 * +--------------------+---------------------------------+
4225
 */
4226
typedef struct SSubQueryMsg {
4227
  SMsgHead header;
4228
  uint64_t sId;
4229
  uint64_t queryId;
4230
  uint64_t clientId;
4231
  uint64_t taskId;
4232
  int64_t  refId;
4233
  int32_t  execId;
4234
  int32_t  msgMask;
4235
  int32_t  subQType;
4236
  int8_t   taskType;
4237
  int8_t   explain;
4238
  int8_t   needFetch;
4239
  int8_t   compress;
4240
  uint32_t sqlLen;
4241
  char*    sql;
4242
  uint32_t msgLen;
4243
  char*    msg;
4244
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4245
} SSubQueryMsg;
4246

4247
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4248
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4249
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4250

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

4258
typedef struct {
4259
  SMsgHead header;
4260
  uint64_t sId;
4261
  uint64_t queryId;
4262
  uint64_t clientId;
4263
  uint64_t taskId;
4264
  int32_t  execId;
4265
} SQueryContinueReq;
4266

4267
typedef struct {
4268
  SMsgHead header;
4269
  uint64_t sId;
4270
  uint64_t queryId;
4271
  uint64_t taskId;
4272
} SResReadyReq;
4273

4274
typedef struct {
4275
  int32_t code;
4276
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4277
  int32_t sversion;
4278
  int32_t tversion;
4279
} SResReadyRsp;
4280

4281
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4282

4283
typedef struct SOperatorParam {
4284
  int32_t opType;
4285
  int32_t downstreamIdx;
4286
  void*   value;
4287
  SArray* pChildren;  // SArray<SOperatorParam*>
4288
  bool    reUse;
4289
} SOperatorParam;
4290

4291
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4292

4293
// virtual table's colId to origin table's colname
4294
typedef struct SColIdNameKV {
4295
  col_id_t colId;
4296
  char     colName[TSDB_COL_NAME_LEN];
4297
} SColIdNameKV;
4298

4299
#define COL_MASK_ON   ((int8_t)0x1)
4300
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4301
#define COL_SET_MASK_ON(c)     \
4302
  do {                         \
4303
    (c)->flags |= COL_MASK_ON; \
4304
  } while (0)
4305

4306
typedef struct SColNameFlag {
4307
  col_id_t colId;
4308
  char     colName[TSDB_COL_NAME_LEN];
4309
  int8_t   flags;  // 0x01: COL_MASK_ON
4310
} SColNameFlag;
4311

4312
typedef struct SColIdPair {
4313
  col_id_t  vtbColId;
4314
  col_id_t  orgColId;
4315
  SDataType type;
4316
} SColIdPair;
4317

4318
typedef struct SColIdSlotIdPair {
4319
  int32_t  vtbSlotId;
4320
  col_id_t orgColId;
4321
} SColIdSlotIdPair;
4322

4323
typedef struct SOrgTbInfo {
4324
  int32_t vgId;
4325
  char    tbName[TSDB_TABLE_FNAME_LEN];
4326
  SArray* colMap;  // SArray<SColIdNameKV>
4327
} SOrgTbInfo;
4328

4329
void destroySOrgTbInfo(void *info);
4330

4331
typedef enum {
4332
  DYN_TYPE_STB_JOIN = 1,
4333
  DYN_TYPE_VSTB_SINGLE_SCAN,
4334
  DYN_TYPE_VSTB_BATCH_SCAN,
4335
  DYN_TYPE_VSTB_WIN_SCAN,
4336
} ETableScanDynType;
4337

4338
typedef enum {
4339
  DYN_TYPE_SCAN_PARAM = 1,
4340
  NOTIFY_TYPE_SCAN_PARAM,
4341
} ETableScanGetParamType;
4342

4343
typedef struct STableScanOperatorParam {
4344
  ETableScanGetParamType paramType;
4345
  /* for building scan data source */
4346
  bool                   tableSeq;
4347
  bool                   isNewParam;
4348
  uint64_t               groupid;
4349
  SArray*                pUidList;
4350
  SOrgTbInfo*            pOrgTbInfo;
4351
  SArray*                pBatchTbInfo;  // SArray<SOrgTbInfo>
4352
  SArray*                pTagList;
4353
  STimeWindow            window;
4354
  ETableScanDynType      dynType;
4355
  /* for notifying source step done */
4356
  bool                   notifyToProcess;  // received notify STEP DONE message
4357
  TSKEY                  notifyTs;         // notify timestamp
4358
} STableScanOperatorParam;
4359

4360
typedef struct STagScanOperatorParam {
4361
  tb_uid_t vcUid;
4362
} STagScanOperatorParam;
4363

4364
typedef struct SRefColIdGroup {
4365
  SArray* pSlotIdList;  // SArray<int32_t>
4366
} SRefColIdGroup;
4367

4368
typedef struct SVTableScanOperatorParam {
4369
  uint64_t        uid;
4370
  STimeWindow     window;
4371
  SOperatorParam* pTagScanOp;
4372
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4373
  SArray*         pRefColGroups;  // SArray<SRefColIdGroup>
4374
} SVTableScanOperatorParam;
4375

4376
typedef struct SMergeOperatorParam {
4377
  int32_t         winNum;
4378
} SMergeOperatorParam;
4379

4380
typedef struct SAggOperatorParam {
4381
  bool            needCleanRes;
4382
} SAggOperatorParam;
4383

4384
typedef struct SExternalWindowOperatorParam {
4385
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4386
} SExternalWindowOperatorParam;
4387

4388
typedef struct SDynQueryCtrlOperatorParam {
4389
  STimeWindow    window;
4390
} SDynQueryCtrlOperatorParam;
4391

4392
struct SStreamRuntimeFuncInfo;
4393
typedef struct {
4394
  SMsgHead        header;
4395
  uint64_t        sId;
4396
  uint64_t        queryId;
4397
  uint64_t        clientId;
4398
  uint64_t        taskId;
4399
  uint64_t        srcTaskId;  // used for subQ
4400
  uint64_t        blockIdx;   // used for subQ
4401
  int32_t         execId;
4402
  SOperatorParam* pOpParam;
4403

4404
  // used for new-stream
4405
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4406
  bool                           reset;
4407
  bool                           dynTbname;
4408
  // used for new-stream
4409
} SResFetchReq;
4410

4411
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4412
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4413
void    tDestroySResFetchReq(SResFetchReq* pReq);
4414
typedef struct {
4415
  SMsgHead header;
4416
  uint64_t clientId;
4417
} SSchTasksStatusReq;
4418

4419
typedef struct {
4420
  uint64_t queryId;
4421
  uint64_t clientId;
4422
  uint64_t taskId;
4423
  int64_t  refId;
4424
  int32_t  subJobId;
4425
  int32_t  execId;
4426
  int8_t   status;
4427
} STaskStatus;
4428

4429
typedef struct {
4430
  int64_t refId;
4431
  SArray* taskStatus;  // SArray<STaskStatus>
4432
} SSchedulerStatusRsp;
4433

4434
typedef struct {
4435
  uint64_t queryId;
4436
  uint64_t taskId;
4437
  int8_t   action;
4438
} STaskAction;
4439

4440
typedef struct SQueryNodeEpId {
4441
  int32_t nodeId;  // vgId or qnodeId
4442
  SEp     ep;
4443
} SQueryNodeEpId;
4444

4445
typedef struct {
4446
  SMsgHead       header;
4447
  uint64_t       clientId;
4448
  SQueryNodeEpId epId;
4449
  SArray*        taskAction;  // SArray<STaskAction>
4450
} SSchedulerHbReq;
4451

4452
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4453
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4454
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4455

4456
typedef struct {
4457
  SQueryNodeEpId epId;
4458
  SArray*        taskStatus;  // SArray<STaskStatus>
4459
} SSchedulerHbRsp;
4460

4461
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4462
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4463
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4464

4465
typedef struct {
4466
  SMsgHead header;
4467
  uint64_t sId;
4468
  uint64_t queryId;
4469
  uint64_t clientId;
4470
  uint64_t taskId;
4471
  int64_t  refId;
4472
  int32_t  execId;
4473
} STaskCancelReq;
4474

4475
typedef struct {
4476
  int32_t code;
4477
} STaskCancelRsp;
4478

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

4489
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4490
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4491

4492
typedef enum {
4493
  TASK_NOTIFY_FINISHED = 1,
4494
} ETaskNotifyType;
4495

4496
typedef struct {
4497
  SMsgHead        header;
4498
  uint64_t        sId;
4499
  uint64_t        queryId;
4500
  uint64_t        clientId;
4501
  uint64_t        taskId;
4502
  int64_t         refId;
4503
  int32_t         execId;
4504
  ETaskNotifyType type;
4505
} STaskNotifyReq;
4506

4507
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4508
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4509

4510
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4511
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4512

4513
typedef struct {
4514
  int32_t code;
4515
} STaskDropRsp;
4516

4517
#define STREAM_TRIGGER_AT_ONCE                 1
4518
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4519
#define STREAM_TRIGGER_MAX_DELAY               3
4520
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4521
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4522

4523
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4524
#define STREAM_FILL_HISTORY_ON        1
4525
#define STREAM_FILL_HISTORY_OFF       0
4526
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4527
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4528
#define STREAM_CREATE_STABLE_TRUE     1
4529
#define STREAM_CREATE_STABLE_FALSE    0
4530

4531
typedef struct SVgroupVer {
4532
  int32_t vgId;
4533
  int64_t ver;
4534
} SVgroupVer;
4535

4536
typedef struct STaskNotifyEventStat {
4537
  int64_t notifyEventAddTimes;     // call times of add function
4538
  int64_t notifyEventAddElems;     // elements added by add function
4539
  double  notifyEventAddCostSec;   // time cost of add function
4540
  int64_t notifyEventPushTimes;    // call times of push function
4541
  int64_t notifyEventPushElems;    // elements pushed by push function
4542
  double  notifyEventPushCostSec;  // time cost of push function
4543
  int64_t notifyEventPackTimes;    // call times of pack function
4544
  int64_t notifyEventPackElems;    // elements packed by pack function
4545
  double  notifyEventPackCostSec;  // time cost of pack function
4546
  int64_t notifyEventSendTimes;    // call times of send function
4547
  int64_t notifyEventSendElems;    // elements sent by send function
4548
  double  notifyEventSendCostSec;  // time cost of send function
4549
  int64_t notifyEventHoldElems;    // elements hold due to watermark
4550
} STaskNotifyEventStat;
4551

4552
enum {
4553
  TOPIC_SUB_TYPE__DB = 1,
4554
  TOPIC_SUB_TYPE__TABLE,
4555
  TOPIC_SUB_TYPE__COLUMN,
4556
};
4557

4558
#define DEFAULT_MAX_POLL_INTERVAL  300000
4559
#define DEFAULT_SESSION_TIMEOUT    12000
4560
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4561
#define DEFAULT_MIN_POLL_ROWS      4096
4562

4563
typedef struct {
4564
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4565
  int8_t igExists;
4566
  int8_t subType;
4567
  int8_t withMeta;
4568
  char*  sql;
4569
  char   subDbName[TSDB_DB_FNAME_LEN];
4570
  char*  ast;
4571
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4572
  int8_t reload;
4573
} SCMCreateTopicReq;
4574

4575
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4576
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4577
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4578

4579
typedef struct {
4580
  int64_t consumerId;
4581
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4582

4583
typedef struct {
4584
  int64_t consumerId;
4585
  char    cgroup[TSDB_CGROUP_LEN];
4586
  char    clientId[TSDB_CLIENT_ID_LEN];
4587
  char    user[TSDB_USER_LEN];
4588
  char    fqdn[TSDB_FQDN_LEN];
4589
  SArray* topicNames;  // SArray<char**>
4590

4591
  int8_t  withTbName;
4592
  int8_t  autoCommit;
4593
  int32_t autoCommitInterval;
4594
  int8_t  resetOffsetCfg;
4595
  int8_t  enableReplay;
4596
  int8_t  enableBatchMeta;
4597
  int32_t sessionTimeoutMs;
4598
  int32_t maxPollIntervalMs;
4599
  int64_t ownerId;
4600
} SCMSubscribeReq;
4601

4602
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4603
  int32_t tlen = 0;
693,190✔
4604
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
693,190✔
4605
  tlen += taosEncodeString(buf, pReq->cgroup);
692,871✔
4606
  tlen += taosEncodeString(buf, pReq->clientId);
692,871✔
4607

4608
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
693,190✔
4609
  tlen += taosEncodeFixedI32(buf, topicNum);
693,190✔
4610

4611
  for (int32_t i = 0; i < topicNum; i++) {
968,349✔
4612
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
550,318✔
4613
  }
4614

4615
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
693,190✔
4616
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
692,871✔
4617
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
692,871✔
4618
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
692,871✔
4619
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
692,871✔
4620
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
692,871✔
4621
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
692,871✔
4622
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
693,190✔
4623
  tlen += taosEncodeString(buf, pReq->user);
692,871✔
4624
  tlen += taosEncodeString(buf, pReq->fqdn);
692,552✔
4625

4626
  return tlen;
692,552✔
4627
}
4628

4629
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4630
  void* start = buf;
361,744✔
4631
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
361,744✔
4632
  buf = taosDecodeStringTo(buf, pReq->cgroup);
361,744✔
4633
  buf = taosDecodeStringTo(buf, pReq->clientId);
361,744✔
4634

4635
  int32_t topicNum = 0;
361,744✔
4636
  buf = taosDecodeFixedI32(buf, &topicNum);
361,744✔
4637

4638
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
361,744✔
4639
  if (pReq->topicNames == NULL) {
361,744✔
UNCOV
4640
    return terrno;
×
4641
  }
4642
  for (int32_t i = 0; i < topicNum; i++) {
525,979✔
4643
    char* name = NULL;
164,235✔
4644
    buf = taosDecodeString(buf, &name);
164,235✔
4645
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
328,470✔
UNCOV
4646
      return terrno;
×
4647
    }
4648
  }
4649

4650
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
361,744✔
4651
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
361,744✔
4652
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
361,744✔
4653
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
361,744✔
4654
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
361,744✔
4655
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
361,744✔
4656
  if ((char*)buf - (char*)start < len) {
361,744✔
4657
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
361,744✔
4658
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
361,744✔
4659
    buf = taosDecodeStringTo(buf, pReq->user);
361,744✔
4660
    buf = taosDecodeStringTo(buf, pReq->fqdn);
723,488✔
4661
  } else {
UNCOV
4662
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4663
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4664
  }
4665

4666
  return 0;
361,744✔
4667
}
4668

4669
typedef struct {
4670
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4671
  SArray* removedConsumers;  // SArray<int64_t>
4672
  SArray* newConsumers;      // SArray<int64_t>
4673
} SMqRebInfo;
4674

4675
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4676
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
338,181✔
4677
  if (pRebInfo == NULL) {
338,181✔
UNCOV
4678
    return NULL;
×
4679
  }
4680
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
338,181✔
4681
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
338,181✔
4682
  if (pRebInfo->removedConsumers == NULL) {
338,181✔
UNCOV
4683
    goto _err;
×
4684
  }
4685
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
338,181✔
4686
  if (pRebInfo->newConsumers == NULL) {
338,181✔
UNCOV
4687
    goto _err;
×
4688
  }
4689
  return pRebInfo;
338,181✔
4690
_err:
×
4691
  taosArrayDestroy(pRebInfo->removedConsumers);
×
4692
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
4693
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
4694
  return NULL;
×
4695
}
4696

4697
typedef struct {
4698
  int64_t streamId;
4699
  int64_t checkpointId;
4700
  char    streamName[TSDB_STREAM_FNAME_LEN];
4701
} SMStreamDoCheckpointMsg;
4702

4703
typedef struct {
4704
  int64_t status;
4705
} SMVSubscribeRsp;
4706

4707
typedef struct {
4708
  char    name[TSDB_TOPIC_FNAME_LEN];
4709
  int8_t  igNotExists;
4710
  int32_t sqlLen;
4711
  char*   sql;
4712
  int8_t  force;
4713
} SMDropTopicReq;
4714

4715
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4716
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4717
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4718

4719
typedef struct {
4720
  char    name[TSDB_TOPIC_FNAME_LEN];
4721
  int8_t  igNotExists;
4722
  int32_t sqlLen;
4723
  char*   sql;
4724
} SMReloadTopicReq;
4725

4726
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4727
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4728
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4729

4730
typedef struct {
4731
  char   topic[TSDB_TOPIC_FNAME_LEN];
4732
  char   cgroup[TSDB_CGROUP_LEN];
4733
  int8_t igNotExists;
4734
  int8_t force;
4735
} SMDropCgroupReq;
4736

4737
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4738
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4739

4740
typedef struct {
4741
  int8_t reserved;
4742
} SMDropCgroupRsp;
4743

4744
typedef struct {
4745
  char    name[TSDB_TABLE_FNAME_LEN];
4746
  int8_t  alterType;
4747
  SSchema schema;
4748
} SAlterTopicReq;
4749

4750
typedef struct {
4751
  SMsgHead head;
4752
  char     name[TSDB_TABLE_FNAME_LEN];
4753
  int64_t  tuid;
4754
  int32_t  sverson;
4755
  int32_t  execLen;
4756
  char*    executor;
4757
  int32_t  sqlLen;
4758
  char*    sql;
4759
} SDCreateTopicReq;
4760

4761
typedef struct {
4762
  SMsgHead head;
4763
  char     name[TSDB_TABLE_FNAME_LEN];
4764
  int64_t  tuid;
4765
} SDDropTopicReq;
4766

4767
typedef struct {
4768
  char*      name;
4769
  int64_t    uid;
4770
  int64_t    interval[2];
4771
  int8_t     intervalUnit;
4772
  int16_t    nFuncs;
4773
  col_id_t*  funcColIds;  // column ids specified by user
4774
  func_id_t* funcIds;     // function ids specified by user
4775
} SRSmaParam;
4776

4777
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4778
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4779

4780
// TDMT_VND_CREATE_STB ==============
4781
typedef struct SVCreateStbReq {
4782
  char*           name;
4783
  tb_uid_t        suid;
4784
  int8_t          rollup;
4785
  SSchemaWrapper  schemaRow;
4786
  SSchemaWrapper  schemaTag;
4787
  SRSmaParam      rsmaParam;
4788
  int32_t         alterOriDataLen;
4789
  void*           alterOriData;
4790
  int8_t          source;
4791
  int8_t          colCmpred;
4792
  SColCmprWrapper colCmpr;
4793
  int64_t         keep;
4794
  int64_t         ownerId;
4795
  SExtSchema*     pExtSchemas;
4796
  int8_t          virtualStb;
4797
} SVCreateStbReq;
4798

4799
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4800
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4801

4802
// TDMT_VND_DROP_STB ==============
4803
typedef struct SVDropStbReq {
4804
  char*    name;
4805
  tb_uid_t suid;
4806
} SVDropStbReq;
4807

4808
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4809
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4810

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

4844
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4845
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4846
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4847
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4848

4849
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4850
  if (NULL == req) {
2,147,483,647✔
4851
    return;
2,147,483,647✔
4852
  }
4853

4854
  taosMemoryFreeClear(req->sql);
83,973,610✔
4855
  taosMemoryFreeClear(req->name);
83,968,069✔
4856
  taosMemoryFreeClear(req->comment);
83,976,328✔
4857
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
83,972,106✔
4858
    taosMemoryFreeClear(req->ctb.pTag);
76,895,766✔
4859
    taosMemoryFreeClear(req->ctb.stbName);
76,885,622✔
4860
    taosArrayDestroy(req->ctb.tagName);
76,890,906✔
4861
    req->ctb.tagName = NULL;
76,844,078✔
4862
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
7,082,193✔
4863
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
7,082,686✔
4864
  }
4865
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
83,938,367✔
4866
  taosMemoryFreeClear(req->pExtSchemas);
83,963,554✔
4867
  taosMemoryFreeClear(req->colRef.pColRef);
83,965,305✔
4868
}
4869

4870
typedef struct {
4871
  int32_t nReqs;
4872
  union {
4873
    SVCreateTbReq* pReqs;
4874
    SArray*        pArray;
4875
  };
4876
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4877
} SVCreateTbBatchReq;
4878

4879
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4880
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4881
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4882

4883
typedef struct {
4884
  int32_t        code;
4885
  STableMetaRsp* pMeta;
4886
} SVCreateTbRsp, SVUpdateTbRsp;
4887

4888
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4889
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4890
void tFreeSVCreateTbRsp(void* param);
4891

4892
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4893
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4894

4895
typedef struct {
4896
  int32_t nRsps;
4897
  union {
4898
    SVCreateTbRsp* pRsps;
4899
    SArray*        pArray;
4900
  };
4901
} SVCreateTbBatchRsp;
4902

4903
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4904
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4905

4906
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4907
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4908

4909
// TDMT_VND_DROP_TABLE =================
4910
typedef struct {
4911
  char*    name;
4912
  uint64_t suid;  // for tmq in wal format
4913
  int64_t  uid;
4914
  int8_t   igNotExists;
4915
  int8_t   isVirtual;
4916
} SVDropTbReq;
4917

4918
typedef struct {
4919
  int32_t code;
4920
} SVDropTbRsp;
4921

4922
typedef struct {
4923
  int32_t nReqs;
4924
  union {
4925
    SVDropTbReq* pReqs;
4926
    SArray*      pArray;
4927
  };
4928
} SVDropTbBatchReq;
4929

4930
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4931
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4932

4933
typedef struct {
4934
  int32_t nRsps;
4935
  union {
4936
    SVDropTbRsp* pRsps;
4937
    SArray*      pArray;
4938
  };
4939
} SVDropTbBatchRsp;
4940

4941
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4942
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4943

4944
// TDMT_VND_ALTER_TABLE =====================
4945
typedef struct SMultiTagUpateVal {
4946
  char*    tagName;
4947
  int32_t  colId;
4948
  int8_t   tagType;
4949
  int8_t   tagFree;
4950
  uint32_t nTagVal;
4951
  uint8_t* pTagVal;
4952
  int8_t   isNull;
4953
  SArray*  pTagArray;
4954
} SMultiTagUpateVal;
4955
typedef struct SVAlterTbReq {
4956
  char*   tbName;
4957
  int8_t  action;
4958
  char*   colName;
4959
  int32_t colId;
4960
  // TSDB_ALTER_TABLE_ADD_COLUMN
4961
  int8_t  type;
4962
  int8_t  flags;
4963
  int32_t bytes;
4964
  // TSDB_ALTER_TABLE_DROP_COLUMN
4965
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4966
  int8_t   colModType;
4967
  int32_t  colModBytes;
4968
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4969
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4970
  int8_t   isNull;
4971
  int8_t   tagType;
4972
  int8_t   tagFree;
4973
  uint32_t nTagVal;
4974
  uint8_t* pTagVal;
4975
  SArray*  pTagArray;
4976
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4977
  int8_t   updateTTL;
4978
  int32_t  newTTL;
4979
  int32_t  newCommentLen;
4980
  char*    newComment;
4981
  int64_t  ctimeMs;    // fill by vnode
4982
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4983
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4984
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4985
  // for Add column
4986
  STypeMod typeMod;
4987
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4988
  char* refDbName;
4989
  char* refTbName;
4990
  char* refColName;
4991
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4992
} SVAlterTbReq;
4993

4994
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4995
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4996
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4997
void    tfreeMultiTagUpateVal(void* pMultiTag);
4998

4999
typedef struct {
5000
  int32_t        code;
5001
  STableMetaRsp* pMeta;
5002
} SVAlterTbRsp;
5003

5004
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
5005
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
5006
// ======================
5007

5008
typedef struct {
5009
  SMsgHead head;
5010
  int64_t  uid;
5011
  int32_t  tid;
5012
  int16_t  tversion;
5013
  int16_t  colId;
5014
  int8_t   type;
5015
  int16_t  bytes;
5016
  int32_t  tagValLen;
5017
  int16_t  numOfTags;
5018
  int32_t  schemaLen;
5019
  char     data[];
5020
} SUpdateTagValReq;
5021

5022
typedef struct {
5023
  SMsgHead head;
5024
} SUpdateTagValRsp;
5025

5026
typedef struct {
5027
  SMsgHead head;
5028
} SVShowTablesReq;
5029

5030
typedef struct {
5031
  SMsgHead head;
5032
  int32_t  id;
5033
} SVShowTablesFetchReq;
5034

5035
typedef struct {
5036
  int64_t useconds;
5037
  int8_t  completed;  // all results are returned to client
5038
  int8_t  precision;
5039
  int8_t  compressed;
5040
  int32_t compLen;
5041
  int32_t numOfRows;
5042
  char    data[];
5043
} SVShowTablesFetchRsp;
5044

5045
typedef struct {
5046
  int64_t consumerId;
5047
  int32_t epoch;
5048
  char    cgroup[TSDB_CGROUP_LEN];
5049
} SMqAskEpReq;
5050

5051
typedef struct {
5052
  int32_t key;
5053
  int32_t valueLen;
5054
  void*   value;
5055
} SKv;
5056

5057
typedef struct {
5058
  int64_t tscRid;
5059
  int8_t  connType;
5060
} SClientHbKey;
5061

5062
typedef struct {
5063
  int64_t tid;
5064
  char    status[TSDB_JOB_STATUS_LEN];
5065
} SQuerySubDesc;
5066

5067
typedef struct {
5068
  char     sql[TSDB_SHOW_SQL_LEN];
5069
  uint64_t queryId;
5070
  int64_t  useconds;
5071
  int64_t  stime;  // timestamp precision ms
5072
  int64_t  reqRid;
5073
  bool     stableQuery;
5074
  bool     isSubQuery;
5075
  char     fqdn[TSDB_FQDN_LEN];
5076
  int32_t  subPlanNum;
5077
  SArray*  subDesc;  // SArray<SQuerySubDesc>
5078
} SQueryDesc;
5079

5080
typedef struct {
5081
  uint32_t connId;
5082
  SArray*  queryDesc;  // SArray<SQueryDesc>
5083
} SQueryHbReqBasic;
5084

5085
typedef struct {
5086
  uint32_t connId;
5087
  uint64_t killRid;
5088
  int32_t  totalDnodes;
5089
  int32_t  onlineDnodes;
5090
  int8_t   killConnection;
5091
  int8_t   align[3];
5092
  SEpSet   epSet;
5093
  SArray*  pQnodeList;
5094
} SQueryHbRspBasic;
5095

5096
typedef struct SAppClusterSummary {
5097
  uint64_t numOfInsertsReq;
5098
  uint64_t numOfInsertRows;
5099
  uint64_t insertElapsedTime;
5100
  uint64_t insertBytes;  // submit to tsdb since launched.
5101

5102
  uint64_t fetchBytes;
5103
  uint64_t numOfQueryReq;
5104
  uint64_t queryElapsedTime;
5105
  uint64_t numOfSlowQueries;
5106
  uint64_t totalRequests;
5107
  uint64_t currentRequests;  // the number of SRequestObj
5108
} SAppClusterSummary;
5109

5110
typedef struct {
5111
  int64_t            appId;
5112
  int32_t            pid;
5113
  char               name[TSDB_APP_NAME_LEN];
5114
  int64_t            startTime;
5115
  SAppClusterSummary summary;
5116
} SAppHbReq;
5117

5118
typedef struct {
5119
  SClientHbKey      connKey;
5120
  int64_t           clusterId;
5121
  SAppHbReq         app;
5122
  SQueryHbReqBasic* query;
5123
  SHashObj*         info;  // hash<Skv.key, Skv>
5124
  char              user[TSDB_USER_LEN];
5125
  char              tokenName[TSDB_TOKEN_NAME_LEN];
5126
  char              userApp[TSDB_APP_NAME_LEN];
5127
  uint32_t          userIp;
5128
  SIpRange          userDualIp;
5129
  char              sVer[TSDB_VERSION_LEN];
5130
  char              cInfo[CONNECTOR_INFO_LEN];
5131
} SClientHbReq;
5132

5133
typedef struct {
5134
  int64_t reqId;
5135
  SArray* reqs;  // SArray<SClientHbReq>
5136
  int64_t ipWhiteListVer;
5137
} SClientHbBatchReq;
5138

5139
typedef struct {
5140
  SClientHbKey      connKey;
5141
  int32_t           status;
5142
  SQueryHbRspBasic* query;
5143
  SArray*           info;  // Array<Skv>
5144
} SClientHbRsp;
5145

5146
typedef struct {
5147
  int64_t       reqId;
5148
  int64_t       rspId;
5149
  int32_t       svrTimestamp;
5150
  SArray*       rsps;  // SArray<SClientHbRsp>
5151
  SMonitorParas monitorParas;
5152
  int8_t        enableAuditDelete;
5153
  int8_t        enableStrongPass;
5154
  int8_t        enableAuditSelect;
5155
  int8_t        enableAuditInsert;
5156
  int8_t        auditLevel;
5157
} SClientHbBatchRsp;
5158

5159
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
395,094,248✔
5160

5161
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5162
  void* pIter = taosHashIterate(info, NULL);
57,234,014✔
5163
  while (pIter != NULL) {
135,024,053✔
5164
    SKv* kv = (SKv*)pIter;
77,788,884✔
5165
    taosMemoryFreeClear(kv->value);
77,788,884✔
5166
    pIter = taosHashIterate(info, pIter);
77,789,561✔
5167
  }
5168
}
57,235,169✔
5169

5170
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
38,496,819✔
5171
  SQueryDesc* desc = (SQueryDesc*)pDesc;
38,496,819✔
5172
  if (desc->subDesc) {
38,496,819✔
5173
    taosArrayDestroy(desc->subDesc);
26,841,976✔
5174
    desc->subDesc = NULL;
26,841,976✔
5175
  }
5176
}
38,497,861✔
5177

5178
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
65,252,636✔
5179
  SClientHbReq* req = (SClientHbReq*)pReq;
146,283,667✔
5180
  if (req->query) {
146,283,667✔
5181
    if (req->query->queryDesc) {
65,252,861✔
5182
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
30,123,883✔
5183
    }
5184
    taosMemoryFreeClear(req->query);
65,253,930✔
5185
  }
5186

5187
  if (req->info) {
146,287,788✔
5188
    tFreeReqKvHash(req->info);
57,234,263✔
5189
    taosHashCleanup(req->info);
57,235,169✔
5190
    req->info = NULL;
57,234,715✔
5191
  }
5192
}
112,896,208✔
5193

5194
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5195
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5196

5197
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5198
  if (pReq == NULL) return;
27,711,306✔
5199
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
27,711,306✔
5200
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
27,711,306✔
5201
  taosMemoryFree(pReq);
27,711,306✔
5202
}
5203

5204
static FORCE_INLINE void tFreeClientKv(void* pKv) {
77,517,090✔
5205
  SKv* kv = (SKv*)pKv;
77,517,090✔
5206
  if (kv) {
77,517,090✔
5207
    taosMemoryFreeClear(kv->value);
77,516,572✔
5208
  }
5209
}
77,516,341✔
5210

5211
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
64,895,833✔
5212
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
64,895,833✔
5213
  if (rsp->query) {
64,895,833✔
5214
    taosArrayDestroy(rsp->query->pQnodeList);
64,893,411✔
5215
    taosMemoryFreeClear(rsp->query);
64,882,379✔
5216
  }
5217
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
64,894,726✔
5218
}
33,037,797✔
5219

5220
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5221
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
54,364,579✔
5222
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
54,364,579✔
5223
}
54,366,596✔
5224

5225
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5226
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5227
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5228

5229
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5230
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
485,120,735✔
5231
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
485,125,095✔
5232
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
485,124,625✔
5233
  return 0;
242,561,391✔
5234
}
5235

5236
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5237
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
160,038,290✔
5238
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
160,039,372✔
5239
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
80,020,046✔
5240
  if (pKv->value == NULL) {
80,018,658✔
UNCOV
5241
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5242
  }
5243
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
80,019,964✔
5244
  return 0;
80,019,964✔
5245
}
5246

5247
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5248
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
408,649,786✔
5249
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
408,646,798✔
5250
  return 0;
204,322,491✔
5251
}
5252

5253
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5254
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
134,288,744✔
5255
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
134,291,740✔
5256
  return 0;
67,147,302✔
5257
}
5258

5259
typedef struct {
5260
  int32_t vgId;
5261
  // TODO stas
5262
} SMqReportVgInfo;
5263

5264
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5265
  int32_t tlen = 0;
5266
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5267
  return tlen;
5268
}
5269

5270
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5271
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5272
  return buf;
5273
}
5274

5275
typedef struct {
5276
  int32_t epoch;
5277
  int64_t topicUid;
5278
  char    name[TSDB_TOPIC_FNAME_LEN];
5279
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5280
} SMqTopicInfo;
5281

5282
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5283
  int32_t tlen = 0;
5284
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5285
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5286
  tlen += taosEncodeString(buf, pTopicInfo->name);
5287
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5288
  tlen += taosEncodeFixedI32(buf, sz);
5289
  for (int32_t i = 0; i < sz; i++) {
5290
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5291
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5292
  }
5293
  return tlen;
5294
}
5295

5296
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5297
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5298
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5299
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5300
  int32_t sz;
5301
  buf = taosDecodeFixedI32(buf, &sz);
5302
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5303
    return NULL;
5304
  }
5305
  for (int32_t i = 0; i < sz; i++) {
5306
    SMqReportVgInfo vgInfo;
5307
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5308
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5309
      return NULL;
5310
    }
5311
  }
5312
  return buf;
5313
}
5314

5315
typedef struct {
5316
  int32_t status;  // ask hb endpoint
5317
  int32_t epoch;
5318
  int64_t consumerId;
5319
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5320
} SMqReportReq;
5321

5322
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5323
  int32_t tlen = 0;
5324
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5325
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5326
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5327
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5328
  tlen += taosEncodeFixedI32(buf, sz);
5329
  for (int32_t i = 0; i < sz; i++) {
5330
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5331
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5332
  }
5333
  return tlen;
5334
}
5335

5336
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5337
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5338
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5339
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5340
  int32_t sz;
5341
  buf = taosDecodeFixedI32(buf, &sz);
5342
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5343
    return NULL;
5344
  }
5345
  for (int32_t i = 0; i < sz; i++) {
5346
    SMqTopicInfo topicInfo;
5347
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5348
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5349
      return NULL;
5350
    }
5351
  }
5352
  return buf;
5353
}
5354

5355
typedef struct {
5356
  SMsgHead head;
5357
  int64_t  leftForVer;
5358
  int32_t  vgId;
5359
  int64_t  consumerId;
5360
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5361
} SMqVDeleteReq;
5362

5363
typedef struct {
5364
  int8_t reserved;
5365
} SMqVDeleteRsp;
5366

5367
typedef struct {
5368
  char**  name;
5369
  int32_t count;
5370
  int8_t igNotExists;
5371
} SMDropStreamReq;
5372

5373
typedef struct {
5374
  int8_t reserved;
5375
} SMDropStreamRsp;
5376

5377
typedef struct {
5378
  SMsgHead head;
5379
  int64_t  resetRelHalt;  // reset related stream task halt status
5380
  int64_t  streamId;
5381
  int32_t  taskId;
5382
} SVDropStreamTaskReq;
5383

5384
typedef struct {
5385
  int8_t reserved;
5386
} SVDropStreamTaskRsp;
5387

5388
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5389
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5390
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5391

5392
typedef struct {
5393
  char*  name;
5394
  int8_t igNotExists;
5395
} SMPauseStreamReq;
5396

5397
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5398
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5399
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5400

5401
typedef struct {
5402
  char*  name;
5403
  int8_t igNotExists;
5404
  int8_t igUntreated;
5405
} SMResumeStreamReq;
5406

5407
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5408
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5409
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5410

5411
typedef struct {
5412
  char*       name;
5413
  int8_t      calcAll;
5414
  STimeWindow timeRange;
5415
} SMRecalcStreamReq;
5416

5417
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5418
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5419
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5420

5421

5422
typedef struct SVndSetKeepVersionReq {
5423
  int64_t keepVersion;
5424
} SVndSetKeepVersionReq;
5425

5426
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5427
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5428

5429
typedef struct SVUpdateCheckpointInfoReq {
5430
  SMsgHead head;
5431
  int64_t  streamId;
5432
  int32_t  taskId;
5433
  int64_t  checkpointId;
5434
  int64_t  checkpointVer;
5435
  int64_t  checkpointTs;
5436
  int32_t  transId;
5437
  int64_t  hStreamId;  // add encode/decode
5438
  int64_t  hTaskId;
5439
  int8_t   dropRelHTask;
5440
} SVUpdateCheckpointInfoReq;
5441

5442
typedef struct {
5443
  int64_t leftForVer;
5444
  int32_t vgId;
5445
  int64_t oldConsumerId;
5446
  int64_t newConsumerId;
5447
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5448
  int8_t  subType;
5449
  int8_t  withMeta;
5450
  char*   qmsg;  // SubPlanToString
5451
  SSchemaWrapper schema;
5452
  int64_t suid;
5453
} SMqRebVgReq;
5454

5455
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5456
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5457

5458
// tqOffset
5459
enum {
5460
  TMQ_OFFSET__RESET_NONE = -3,
5461
  TMQ_OFFSET__RESET_EARLIEST = -2,
5462
  TMQ_OFFSET__RESET_LATEST = -1,
5463
  TMQ_OFFSET__LOG = 1,
5464
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5465
  TMQ_OFFSET__SNAPSHOT_META = 3,
5466
};
5467

5468
enum {
5469
  WITH_DATA = 0,
5470
  WITH_META = 1,
5471
  ONLY_META = 2,
5472
};
5473

5474
#define TQ_OFFSET_VERSION 1
5475

5476
typedef struct {
5477
  int8_t type;
5478
  union {
5479
    // snapshot
5480
    struct {
5481
      int64_t uid;
5482
      int64_t ts;
5483
      SValue  primaryKey;
5484
    };
5485
    // log
5486
    struct {
5487
      int64_t version;
5488
    };
5489
  };
5490
} STqOffsetVal;
5491

5492
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5493
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,817,287✔
5494
  pOffsetVal->uid = uid;
7,817,298✔
5495
  pOffsetVal->ts = ts;
7,817,301✔
5496
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,816,360✔
5497
    taosMemoryFree(pOffsetVal->primaryKey.pData);
294✔
5498
  }
5499
  pOffsetVal->primaryKey = primaryKey;
7,816,662✔
5500
}
7,816,677✔
5501

5502
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5503
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
41,083✔
5504
  pOffsetVal->uid = uid;
41,083✔
5505
}
41,083✔
5506

5507
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5508
  pOffsetVal->type = TMQ_OFFSET__LOG;
29,697,734✔
5509
  pOffsetVal->version = ver;
29,697,409✔
5510
}
29,697,388✔
5511

5512
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5513
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5514
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5515
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5516
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5517
void    tOffsetDestroy(void* pVal);
5518

5519
typedef struct {
5520
  STqOffsetVal val;
5521
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5522
} STqOffset;
5523

5524
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5525
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5526
void    tDeleteSTqOffset(void* val);
5527

5528
typedef struct SMqVgOffset {
5529
  int64_t   consumerId;
5530
  STqOffset offset;
5531
} SMqVgOffset;
5532

5533
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5534
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5535

5536
typedef struct {
5537
  char    name[TSDB_TABLE_FNAME_LEN];
5538
  char    stb[TSDB_TABLE_FNAME_LEN];
5539
  int8_t  igExists;
5540
  int8_t  intervalUnit;
5541
  int8_t  slidingUnit;
5542
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5543
  int32_t dstVgId;   // for stream
5544
  int64_t interval;
5545
  int64_t offset;
5546
  int64_t sliding;
5547
  int64_t maxDelay;
5548
  int64_t watermark;
5549
  int32_t exprLen;        // strlen + 1
5550
  int32_t tagsFilterLen;  // strlen + 1
5551
  int32_t sqlLen;         // strlen + 1
5552
  int32_t astLen;         // strlen + 1
5553
  char*   expr;
5554
  char*   tagsFilter;
5555
  char*   sql;
5556
  char*   ast;
5557
  int64_t deleteMark;
5558
  int64_t lastTs;
5559
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5560
  SArray* pVgroupVerList;
5561
  int8_t  recursiveTsma;
5562
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5563
  char*   createStreamReq;
5564
  int32_t streamReqLen;
5565
  char*   dropStreamReq;
5566
  int32_t dropStreamReqLen;
5567
  int64_t uid;
5568
} SMCreateSmaReq;
5569

5570
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5571
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5572
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5573

5574
typedef struct {
5575
  char    name[TSDB_TABLE_FNAME_LEN];
5576
  int8_t  igNotExists;
5577
  char*   dropStreamReq;
5578
  int32_t dropStreamReqLen;
5579
} SMDropSmaReq;
5580

5581
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5582
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5583
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5584

5585
typedef struct {
5586
  char name[TSDB_TABLE_NAME_LEN];
5587
  union {
5588
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5589
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5590
  };
5591
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5592
  union {
5593
    int8_t igExists;   // used by mnode
5594
    int8_t alterType;  // used by vnode
5595
  };
5596
  int8_t     intervalUnit;
5597
  int16_t    nFuncs;       // number of functions specified by user
5598
  col_id_t*  funcColIds;   // column ids specified by user
5599
  func_id_t* funcIds;      // function ids specified by user
5600
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5601
  int64_t    tbUid;
5602
  int64_t    uid;     // rsma uid
5603
  int32_t    sqlLen;  // strlen + 1
5604
  char*      sql;
5605
} SMCreateRsmaReq;
5606

5607
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5608
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5609
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5610

5611
typedef SMCreateRsmaReq SVCreateRsmaReq;
5612

5613
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5614
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5615
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5616

5617
typedef SMCreateRsmaReq SVAlterRsmaReq;
5618

5619
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5620
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5621
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5622

5623
typedef struct {
5624
  char       name[TSDB_TABLE_NAME_LEN];
5625
  int8_t     alterType;
5626
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5627
  int8_t     igNotExists;
5628
  int16_t    nFuncs;      // number of functions specified by user
5629
  col_id_t*  funcColIds;  // column ids specified by user
5630
  func_id_t* funcIds;     // function ids specified by user
5631
  int32_t    sqlLen;      // strlen + 1
5632
  char*      sql;
5633
} SMAlterRsmaReq;
5634

5635
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5636
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5637
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5638

5639
typedef struct {
5640
  int64_t    id;
5641
  char       name[TSDB_TABLE_NAME_LEN];
5642
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5643
  int64_t    ownerId;
5644
  int32_t    code;
5645
  int32_t    version;
5646
  int8_t     tbType;
5647
  int8_t     intervalUnit;
5648
  col_id_t   nFuncs;
5649
  col_id_t   nColNames;
5650
  int64_t    interval[2];
5651
  col_id_t*  funcColIds;
5652
  func_id_t* funcIds;
5653
  SArray*    colNames;
5654
} SRsmaInfoRsp;
5655

5656
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5657
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5658
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5659

5660
typedef struct {
5661
  char   name[TSDB_TABLE_FNAME_LEN];
5662
  int8_t igNotExists;
5663
} SMDropRsmaReq;
5664

5665
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5666
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5667

5668
typedef struct {
5669
  char    name[TSDB_TABLE_NAME_LEN];
5670
  char    tbName[TSDB_TABLE_NAME_LEN];
5671
  int64_t uid;
5672
  int64_t tbUid;
5673
  int8_t  tbType;
5674
} SVDropRsmaReq;
5675

5676
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5677
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5678

5679
typedef struct {
5680
  char   dbFName[TSDB_DB_FNAME_LEN];
5681
  char   stbName[TSDB_TABLE_NAME_LEN];
5682
  char   colName[TSDB_COL_NAME_LEN];
5683
  char   idxName[TSDB_INDEX_FNAME_LEN];
5684
  int8_t idxType;
5685
} SCreateTagIndexReq;
5686

5687
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5688
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5689

5690
typedef SMDropSmaReq SDropTagIndexReq;
5691

5692
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5693
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5694

5695
typedef struct {
5696
  int8_t         version;       // for compatibility(default 0)
5697
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5698
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5699
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5700
  int32_t        dstVgId;
5701
  char           indexName[TSDB_INDEX_NAME_LEN];
5702
  int32_t        exprLen;
5703
  int32_t        tagsFilterLen;
5704
  int64_t        indexUid;
5705
  tb_uid_t       tableUid;  // super/child/common table uid
5706
  tb_uid_t       dstTbUid;  // for dstVgroup
5707
  int64_t        interval;
5708
  int64_t        offset;  // use unit by precision of DB
5709
  int64_t        sliding;
5710
  char*          dstTbName;  // for dstVgroup
5711
  char*          expr;       // sma expression
5712
  char*          tagsFilter;
5713
  SSchemaWrapper schemaRow;  // for dstVgroup
5714
  SSchemaWrapper schemaTag;  // for dstVgroup
5715
} STSma;                     // Time-range-wise SMA
5716

5717
typedef STSma SVCreateTSmaReq;
5718

5719
typedef struct {
5720
  int8_t  type;  // 0 status report, 1 update data
5721
  int64_t indexUid;
5722
  int64_t skey;  // start TS key of interval/sliding window
5723
} STSmaMsg;
5724

5725
typedef struct {
5726
  int64_t indexUid;
5727
  char    indexName[TSDB_INDEX_NAME_LEN];
5728
} SVDropTSmaReq;
5729

5730
typedef struct {
5731
  int tmp;  // TODO: to avoid compile error
5732
} SVCreateTSmaRsp, SVDropTSmaRsp;
5733

5734
#if 0
5735
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5736
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5737
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5738
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5739
#endif
5740

5741
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5742
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5743
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5744
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5745

5746
typedef struct {
5747
  int32_t number;
5748
  STSma*  tSma;
5749
} STSmaWrapper;
5750

5751
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5752
  if (pSma) {
×
5753
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5754
    taosMemoryFreeClear(pSma->expr);
×
5755
    taosMemoryFreeClear(pSma->tagsFilter);
×
5756
  }
UNCOV
5757
}
×
5758

5759
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5760
  if (pSW) {
×
5761
    if (pSW->tSma) {
×
5762
      if (deepCopy) {
×
UNCOV
5763
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5764
          tDestroyTSma(pSW->tSma + i);
×
5765
        }
5766
      }
UNCOV
5767
      taosMemoryFreeClear(pSW->tSma);
×
5768
    }
5769
  }
UNCOV
5770
}
×
5771

5772
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5773
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5774
  taosMemoryFreeClear(pSW);
×
UNCOV
5775
  return NULL;
×
5776
}
5777

5778
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5779
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5780

5781
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5782
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5783

5784
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5785
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
5786
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5787
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5788
  }
UNCOV
5789
  return 0;
×
5790
}
5791

5792
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5793
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5794
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5795
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5796
  }
UNCOV
5797
  return 0;
×
5798
}
5799

5800
typedef struct {
5801
  int idx;
5802
} SMCreateFullTextReq;
5803

5804
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5805
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5806
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5807

5808
typedef struct {
5809
  char   name[TSDB_TABLE_FNAME_LEN];
5810
  int8_t igNotExists;
5811
} SMDropFullTextReq;
5812

5813
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5814
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5815

5816
typedef struct {
5817
  char indexFName[TSDB_INDEX_FNAME_LEN];
5818
} SUserIndexReq;
5819

5820
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5821
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5822

5823
typedef struct {
5824
  char dbFName[TSDB_DB_FNAME_LEN];
5825
  char tblFName[TSDB_TABLE_FNAME_LEN];
5826
  char colName[TSDB_COL_NAME_LEN];
5827
  char owner[TSDB_USER_LEN];
5828
  char indexType[TSDB_INDEX_TYPE_LEN];
5829
  char indexExts[TSDB_INDEX_EXTS_LEN];
5830
} SUserIndexRsp;
5831

5832
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5833
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5834

5835
typedef struct {
5836
  char tbFName[TSDB_TABLE_FNAME_LEN];
5837
} STableIndexReq;
5838

5839
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5840
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5841

5842
typedef struct {
5843
  int8_t  intervalUnit;
5844
  int8_t  slidingUnit;
5845
  int64_t interval;
5846
  int64_t offset;
5847
  int64_t sliding;
5848
  int64_t dstTbUid;
5849
  int32_t dstVgId;
5850
  SEpSet  epSet;
5851
  char*   expr;
5852
} STableIndexInfo;
5853

5854
typedef struct {
5855
  char     tbName[TSDB_TABLE_NAME_LEN];
5856
  char     dbFName[TSDB_DB_FNAME_LEN];
5857
  uint64_t suid;
5858
  int32_t  version;
5859
  int32_t  indexSize;
5860
  SArray*  pIndex;  // STableIndexInfo
5861
} STableIndexRsp;
5862

5863
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5864
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5865
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5866

5867
void tFreeSTableIndexInfo(void* pInfo);
5868

5869
typedef struct {
5870
  int8_t  mqMsgType;
5871
  int32_t code;
5872
  int32_t epoch;
5873
  int64_t consumerId;
5874
  int64_t walsver;
5875
  int64_t walever;
5876
} SMqRspHead;
5877

5878
typedef struct {
5879
  SMsgHead     head;
5880
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5881
  int8_t       withTbName;
5882
  int8_t       useSnapshot;
5883
  int32_t      epoch;
5884
  uint64_t     reqId;
5885
  int64_t      consumerId;
5886
  int64_t      timeout;
5887
  STqOffsetVal reqOffset;
5888
  int8_t       enableReplay;
5889
  int8_t       sourceExcluded;
5890
  int8_t       rawData;
5891
  int32_t      minPollRows;
5892
  int8_t       enableBatchMeta;
5893
  SHashObj*    uidHash;  // to find if uid is duplicated
5894
} SMqPollReq;
5895

5896
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5897
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5898
void    tDestroySMqPollReq(SMqPollReq* pReq);
5899

5900
typedef struct {
5901
  int32_t vgId;
5902
  int64_t offset;
5903
  SEpSet  epSet;
5904
} SMqSubVgEp;
5905

5906
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5907
  int32_t tlen = 0;
2,469,406✔
5908
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,469,406✔
5909
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,469,406✔
5910
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,469,406✔
5911
  return tlen;
2,469,406✔
5912
}
5913

5914
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5915
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,223,639✔
5916
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,223,639✔
5917
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,223,639✔
5918
  return buf;
1,223,639✔
5919
}
5920

5921
typedef struct {
5922
  char           topic[TSDB_TOPIC_FNAME_LEN];
5923
  char           db[TSDB_DB_FNAME_LEN];
5924
  SArray*        vgs;  // SArray<SMqSubVgEp>
5925
} SMqSubTopicEp;
5926

5927
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5928
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5929
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5930

5931
typedef struct {
5932
  SMqRspHead   head;
5933
  STqOffsetVal rspOffset;
5934
  int16_t      resMsgType;
5935
  int32_t      metaRspLen;
5936
  void*        metaRsp;
5937
} SMqMetaRsp;
5938

5939
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5940
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5941
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5942

5943
#define MQ_DATA_RSP_VERSION 100
5944

5945
typedef struct {
5946
  SMqRspHead   head;
5947
  STqOffsetVal rspOffset;
5948
  STqOffsetVal reqOffset;
5949
  int32_t      blockNum;
5950
  int8_t       withTbName;
5951
  int8_t       withSchema;
5952
  SArray*      blockDataLen;
5953
  SArray*      blockData;
5954
  SArray*      blockTbName;
5955
  SArray*      blockSchema;
5956

5957
  union {
5958
    struct {
5959
      int64_t sleepTime;
5960
    };
5961
    struct {
5962
      int32_t createTableNum;
5963
      SArray* createTableLen;
5964
      SArray* createTableReq;
5965
    };
5966
    struct {
5967
      int32_t len;
5968
      void*   rawData;
5969
    };
5970
  };
5971
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5972
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5973
  bool  timeout;
5974
} SMqDataRsp;
5975

5976
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5977
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5978
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5979
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5980
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5981

5982
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5983
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5984
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5985

5986
typedef struct SMqBatchMetaRsp {
5987
  SMqRspHead   head;  // not serialize
5988
  STqOffsetVal rspOffset;
5989
  SArray*      batchMetaLen;
5990
  SArray*      batchMetaReq;
5991
  void*        pMetaBuff;    // not serialize
5992
  uint32_t     metaBuffLen;  // not serialize
5993
} SMqBatchMetaRsp;
5994

5995
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5996
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5997
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5998
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5999

6000
typedef struct {
6001
  int32_t    code;
6002
  SArray*    topics;  // SArray<SMqSubTopicEp>
6003
} SMqAskEpRsp;
6004

6005
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
6006
  int32_t tlen = 0;
7,680,968✔
6007
  // tlen += taosEncodeString(buf, pRsp->cgroup);
6008
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,680,968✔
6009
  tlen += taosEncodeFixedI32(buf, sz);
7,680,968✔
6010
  for (int32_t i = 0; i < sz; i++) {
9,469,852✔
6011
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,788,884✔
6012
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,788,884✔
6013
  }
6014
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,680,968✔
6015

6016
  return tlen;
7,680,968✔
6017
}
6018

6019
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
6020
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
6021
  int32_t sz;
3,332,939✔
6022
  buf = taosDecodeFixedI32(buf, &sz);
3,404,055✔
6023
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,404,055✔
6024
  if (pRsp->topics == NULL) {
3,404,055✔
UNCOV
6025
    return NULL;
×
6026
  }
6027
  for (int32_t i = 0; i < sz; i++) {
4,275,556✔
6028
    SMqSubTopicEp topicEp;
858,950✔
6029
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
871,501✔
6030
    if (buf == NULL) {
871,501✔
UNCOV
6031
      return NULL;
×
6032
    }
6033
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,743,002✔
UNCOV
6034
      return NULL;
×
6035
    }
6036
  }
6037
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,404,055✔
6038

6039
  return buf;
3,404,055✔
6040
}
6041

6042
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
6043
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,618,814✔
6044
}
9,618,814✔
6045

6046
typedef struct {
6047
  int32_t      vgId;
6048
  STqOffsetVal offset;
6049
  int64_t      rows;
6050
  int64_t      ever;
6051
} OffsetRows;
6052

6053
typedef struct {
6054
  char    topicName[TSDB_TOPIC_FNAME_LEN];
6055
  SArray* offsetRows;
6056
} TopicOffsetRows;
6057

6058
typedef struct {
6059
  int64_t consumerId;
6060
  int32_t epoch;
6061
  SArray* topics;
6062
  int8_t  pollFlag;
6063
} SMqHbReq;
6064

6065
typedef struct {
6066
  char   topic[TSDB_TOPIC_FNAME_LEN];
6067
  int8_t noPrivilege;
6068
} STopicPrivilege;
6069

6070
typedef struct {
6071
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
6072
  int32_t debugFlag;
6073
} SMqHbRsp;
6074

6075
typedef struct {
6076
  SMsgHead head;
6077
  int64_t  consumerId;
6078
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
6079
} SMqSeekReq;
6080

6081
#define TD_AUTO_CREATE_TABLE 0x1
6082
typedef struct {
6083
  int64_t       suid;
6084
  int64_t       uid;
6085
  int32_t       sver;
6086
  uint32_t      nData;
6087
  uint8_t*      pData;
6088
  SVCreateTbReq cTbReq;
6089
} SVSubmitBlk;
6090

6091
typedef struct {
6092
  SMsgHead header;
6093
  uint64_t sId;
6094
  uint64_t queryId;
6095
  uint64_t clientId;
6096
  uint64_t taskId;
6097
  uint32_t sqlLen;
6098
  uint32_t phyLen;
6099
  char*    sql;
6100
  char*    msg;
6101
  int8_t   source;
6102
} SVDeleteReq;
6103

6104
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6105
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6106

6107
typedef struct {
6108
  int64_t affectedRows;
6109
} SVDeleteRsp;
6110

6111
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6112
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6113

6114
typedef struct SDeleteRes {
6115
  uint64_t suid;
6116
  SArray*  uidList;
6117
  int64_t  skey;
6118
  int64_t  ekey;
6119
  int64_t  affectedRows;
6120
  char     tableFName[TSDB_TABLE_NAME_LEN];
6121
  char     tsColName[TSDB_COL_NAME_LEN];
6122
  int64_t  ctimeMs;  // fill by vnode
6123
  int8_t   source;
6124
} SDeleteRes;
6125

6126
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6127
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6128

6129
typedef struct {
6130
  // int64_t uid;
6131
  char    tbname[TSDB_TABLE_NAME_LEN];
6132
  int64_t startTs;
6133
  int64_t endTs;
6134
} SSingleDeleteReq;
6135

6136
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6137
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6138

6139
typedef struct {
6140
  int64_t suid;
6141
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6142
  int64_t ctimeMs;     // fill by vnode
6143
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6144
} SBatchDeleteReq;
6145

6146
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6147
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6148
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6149

6150
typedef struct {
6151
  int32_t msgIdx;
6152
  int32_t msgType;
6153
  int32_t msgLen;
6154
  void*   msg;
6155
} SBatchMsg;
6156

6157
typedef struct {
6158
  SMsgHead header;
6159
  SArray*  pMsgs;  // SArray<SBatchMsg>
6160
} SBatchReq;
6161

6162
typedef struct {
6163
  int32_t reqType;
6164
  int32_t msgIdx;
6165
  int32_t msgLen;
6166
  int32_t rspCode;
6167
  void*   msg;
6168
} SBatchRspMsg;
6169

6170
typedef struct {
6171
  SArray* pRsps;  // SArray<SBatchRspMsg>
6172
} SBatchRsp;
6173

6174
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6175
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6176
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
93,670,182✔
6177
  if (NULL == msg) {
93,670,182✔
UNCOV
6178
    return;
×
6179
  }
6180
  SBatchMsg* pMsg = (SBatchMsg*)msg;
93,670,182✔
6181
  taosMemoryFree(pMsg->msg);
93,670,182✔
6182
}
6183

6184
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6185
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6186

6187
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
130,300,905✔
6188
  if (NULL == p) {
130,300,905✔
UNCOV
6189
    return;
×
6190
  }
6191

6192
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
130,300,905✔
6193
  taosMemoryFree(pRsp->msg);
130,300,905✔
6194
}
6195

6196
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6197
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6198
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6199
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6200
void    tDestroySMqHbReq(SMqHbReq* pReq);
6201

6202
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6203
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6204
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6205

6206
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6207
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6208

6209
#define TD_REQ_FROM_APP               0x0
6210
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6211
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6212
#define SUBMIT_REQ_FROM_FILE          0x4
6213
#define TD_REQ_FROM_TAOX              0x8
6214
#define TD_REQ_FROM_SML               0x10
6215
#define SUBMIT_REQUEST_VERSION        (2)
6216
#define SUBMIT_REQ_WITH_BLOB          0x10
6217
#define SUBMIT_REQ_SCHEMA_RES         0x20
6218
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6219

6220
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6221

6222
typedef struct {
6223
  int32_t        flags;
6224
  SVCreateTbReq* pCreateTbReq;
6225
  int64_t        suid;
6226
  int64_t        uid;
6227
  int32_t        sver;
6228
  union {
6229
    SArray* aRowP;
6230
    SArray* aCol;
6231
  };
6232
  int64_t   ctimeMs;
6233
  SBlobSet* pBlobSet;
6234
} SSubmitTbData;
6235

6236
typedef struct {
6237
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6238
  SArray* aSubmitBlobData;
6239
  bool    raw;
6240
} SSubmitReq2;
6241

6242
typedef struct {
6243
  SMsgHead header;
6244
  int64_t  version;
6245
  char     data[];  // SSubmitReq2
6246
} SSubmitReq2Msg;
6247

6248
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6249
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6250
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6251
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6252
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6253

6254
typedef struct {
6255
  int32_t affectedRows;
6256
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6257
} SSubmitRsp2;
6258

6259
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6260
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6261
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6262

6263
#define TSDB_MSG_FLG_ENCODE 0x1
6264
#define TSDB_MSG_FLG_DECODE 0x2
6265
#define TSDB_MSG_FLG_CMPT   0x3
6266

6267
typedef struct {
6268
  union {
6269
    struct {
6270
      void*   msgStr;
6271
      int32_t msgLen;
6272
      int64_t ver;
6273
    };
6274
    void* pDataBlock;
6275
  };
6276
} SPackedData;
6277

6278
typedef struct {
6279
  char     fullname[TSDB_VIEW_FNAME_LEN];
6280
  char     name[TSDB_VIEW_NAME_LEN];
6281
  char     dbFName[TSDB_DB_FNAME_LEN];
6282
  char*    querySql;
6283
  char*    sql;
6284
  int8_t   orReplace;
6285
  int8_t   precision;
6286
  int32_t  numOfCols;
6287
  SSchema* pSchema;
6288
} SCMCreateViewReq;
6289

6290
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6291
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6292
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6293

6294
typedef struct {
6295
  char   fullname[TSDB_VIEW_FNAME_LEN];
6296
  char   name[TSDB_VIEW_NAME_LEN];
6297
  char   dbFName[TSDB_DB_FNAME_LEN];
6298
  char*  sql;
6299
  int8_t igNotExists;
6300
} SCMDropViewReq;
6301

6302
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6303
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6304
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6305

6306
typedef struct {
6307
  char fullname[TSDB_VIEW_FNAME_LEN];
6308
} SViewMetaReq;
6309
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6310
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6311

6312
typedef struct {
6313
  char     name[TSDB_VIEW_NAME_LEN];
6314
  char     dbFName[TSDB_DB_FNAME_LEN];
6315
  char*    createUser;
6316
  int64_t  ownerId;
6317
  uint64_t dbId;
6318
  uint64_t viewId;
6319
  char*    querySql;
6320
  int8_t   precision;
6321
  int8_t   type;
6322
  int32_t  version;
6323
  int32_t  numOfCols;
6324
  SSchema* pSchema;
6325
} SViewMetaRsp;
6326
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6327
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6328
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6329
typedef struct {
6330
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6331
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6332
} STableTSMAInfoReq;
6333

6334
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6335
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6336

6337
typedef struct {
6338
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6339
  union {
6340
    uint8_t flags;
6341
    struct {
6342
      uint8_t withColName : 1;
6343
      uint8_t reserved : 7;
6344
    };
6345
  };
6346

6347
} SRsmaInfoReq;
6348

6349
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6350
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6351

6352
typedef struct {
6353
  int32_t  funcId;
6354
  col_id_t colId;
6355
} STableTSMAFuncInfo;
6356

6357
typedef struct {
6358
  char     name[TSDB_TABLE_NAME_LEN];
6359
  uint64_t tsmaId;
6360
  char     targetTb[TSDB_TABLE_NAME_LEN];
6361
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6362
  char     tb[TSDB_TABLE_NAME_LEN];
6363
  char     dbFName[TSDB_DB_FNAME_LEN];
6364
  uint64_t suid;
6365
  uint64_t destTbUid;
6366
  uint64_t dbId;
6367
  int32_t  version;
6368
  int64_t  interval;
6369
  int8_t   unit;
6370
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6371
  SArray*  pTags;      // SArray<SSchema>
6372
  SArray*  pUsedCols;  // SArray<SSchema>
6373
  char*    ast;
6374

6375
  int64_t streamUid;
6376
  int64_t reqTs;
6377
  int64_t rspTs;
6378
  int64_t delayDuration;  // ms
6379
  bool    fillHistoryFinished;
6380

6381
  void* streamAddr;  // for stream task, the address of the stream task
6382
} STableTSMAInfo;
6383

6384
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6385
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6386
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6387
void    tFreeTableTSMAInfo(void* p);
6388
void    tFreeAndClearTableTSMAInfo(void* p);
6389
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6390

6391
#define STSMAHbRsp            STableTSMAInfoRsp
6392
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6393
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6394
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6395

6396
typedef struct SDropCtbWithTsmaSingleVgReq {
6397
  SVgroupInfo vgInfo;
6398
  SArray*     pTbs;  // SVDropTbReq
6399
} SMDropTbReqsOnSingleVg;
6400

6401
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6402
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6403
void    tFreeSMDropTbReqOnSingleVg(void* p);
6404

6405
typedef struct SDropTbsReq {
6406
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6407
} SMDropTbsReq;
6408

6409
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6410
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6411
void    tFreeSMDropTbsReq(void*);
6412

6413
typedef struct SVFetchTtlExpiredTbsRsp {
6414
  SArray* pExpiredTbs;  // SVDropTbReq
6415
  int32_t vgId;
6416
} SVFetchTtlExpiredTbsRsp;
6417

6418
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6419
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6420

6421
void tFreeFetchTtlExpiredTbsRsp(void* p);
6422

6423
void setDefaultOptionsForField(SFieldWithOptions* field);
6424
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6425

6426
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6427
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6428

6429

6430
typedef struct {
6431
  char    id[TSDB_INSTANCE_ID_LEN];
6432
  char    type[TSDB_INSTANCE_TYPE_LEN];
6433
  char    desc[TSDB_INSTANCE_DESC_LEN];
6434
  int32_t expire;
6435
} SInstanceRegisterReq;
6436

6437
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6438
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6439

6440
typedef struct {
6441
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6442
} SInstanceListReq;
6443

6444
typedef struct {
6445
  int32_t count;
6446
  char**  ids;  // Array of instance IDs
6447
} SInstanceListRsp;
6448

6449
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6450
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6451
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6452
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6453

6454
#ifdef USE_MOUNT
6455
typedef struct {
6456
  char     mountName[TSDB_MOUNT_NAME_LEN];
6457
  int8_t   ignoreExist;
6458
  int16_t  nMounts;
6459
  int32_t* dnodeIds;
6460
  char**   mountPaths;
6461
  int32_t  sqlLen;
6462
  char*    sql;
6463
} SCreateMountReq;
6464

6465
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6466
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6467
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6468

6469
typedef struct {
6470
  char    mountName[TSDB_MOUNT_NAME_LEN];
6471
  int8_t  ignoreNotExists;
6472
  int32_t sqlLen;
6473
  char*   sql;
6474
} SDropMountReq;
6475

6476
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6477
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6478
void    tFreeSDropMountReq(SDropMountReq* pReq);
6479

6480
typedef struct {
6481
  char     mountName[TSDB_MOUNT_NAME_LEN];
6482
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6483
  int64_t  mountUid;
6484
  int32_t  dnodeId;
6485
  uint32_t valLen;
6486
  int8_t   ignoreExist;
6487
  void*    pVal;
6488
} SRetrieveMountPathReq;
6489

6490
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6491
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6492

6493
typedef struct {
6494
  // path
6495
  int32_t diskPrimary;
6496
  // vgInfo
6497
  int32_t  vgId;
6498
  int32_t  cacheLastSize;
6499
  int32_t  szPage;
6500
  int32_t  szCache;
6501
  uint64_t szBuf;
6502
  int8_t   cacheLast;
6503
  int8_t   standby;
6504
  int8_t   hashMethod;
6505
  uint32_t hashBegin;
6506
  uint32_t hashEnd;
6507
  int16_t  hashPrefix;
6508
  int16_t  hashSuffix;
6509
  int16_t  sttTrigger;
6510
  // syncInfo
6511
  int32_t replications;
6512
  // tsdbInfo
6513
  int8_t  precision;
6514
  int8_t  compression;
6515
  int8_t  slLevel;
6516
  int32_t daysPerFile;
6517
  int32_t keep0;
6518
  int32_t keep1;
6519
  int32_t keep2;
6520
  int32_t keepTimeOffset;
6521
  int32_t minRows;
6522
  int32_t maxRows;
6523
  int32_t tsdbPageSize;
6524
  int32_t ssChunkSize;
6525
  int32_t ssKeepLocal;
6526
  int8_t  ssCompact;
6527
  union {
6528
    uint8_t flags;
6529
    struct {
6530
      uint8_t isAudit : 1;
6531
      uint8_t allowDrop : 1;
6532
      uint8_t reserved : 6;
6533
    };
6534
  };
6535
  // walInfo
6536
  int32_t walFsyncPeriod;      // millisecond
6537
  int32_t walRetentionPeriod;  // secs
6538
  int32_t walRollPeriod;       // secs
6539
  int64_t walRetentionSize;
6540
  int64_t walSegSize;
6541
  int32_t walLevel;
6542
  // encryptInfo
6543
  int32_t encryptAlgorithm;
6544
  // SVState
6545
  int64_t committed;
6546
  int64_t commitID;
6547
  int64_t commitTerm;
6548
  // stats
6549
  int64_t numOfSTables;
6550
  int64_t numOfCTables;
6551
  int64_t numOfNTables;
6552
  // dbInfo
6553
  uint64_t dbId;
6554
} SMountVgInfo;
6555

6556
typedef struct {
6557
  SMCreateStbReq req;
6558
  SArray*        pColExts;  // element: column id
6559
  SArray*        pTagExts;  // element: tag id
6560
} SMountStbInfo;
6561

6562
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6563
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6564

6565
typedef struct {
6566
  char     dbName[TSDB_DB_FNAME_LEN];
6567
  uint64_t dbId;
6568
  SArray*  pVgs;   // SMountVgInfo
6569
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6570
} SMountDbInfo;
6571

6572
typedef struct {
6573
  // common fields
6574
  char     mountName[TSDB_MOUNT_NAME_LEN];
6575
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6576
  int8_t   ignoreExist;
6577
  int64_t  mountUid;
6578
  int64_t  clusterId;
6579
  int32_t  dnodeId;
6580
  uint32_t valLen;
6581
  void*    pVal;
6582

6583
  // response fields
6584
  SArray* pDbs;  // SMountDbInfo
6585

6586
  // memory fields, no serialized
6587
  SArray*   pDisks[TFS_MAX_TIERS];
6588
  TdFilePtr pFile;
6589
} SMountInfo;
6590

6591
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6592
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6593
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6594

6595
typedef struct {
6596
  SCreateVnodeReq createReq;
6597
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6598
  char            mountName[TSDB_MOUNT_NAME_LEN];
6599
  int64_t         mountId;
6600
  int32_t         diskPrimary;
6601
  int32_t         mountVgId;
6602
  int64_t         committed;
6603
  int64_t         commitID;
6604
  int64_t         commitTerm;
6605
  int64_t         numOfSTables;
6606
  int64_t         numOfCTables;
6607
  int64_t         numOfNTables;
6608
} SMountVnodeReq;
6609

6610
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6611
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6612
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6613

6614
#endif  // USE_MOUNT
6615

6616
#pragma pack(pop)
6617

6618
typedef struct {
6619
  char        db[TSDB_DB_FNAME_LEN];
6620
  STimeWindow timeRange;
6621
  int32_t     sqlLen;
6622
  char*       sql;
6623
  SArray*     vgroupIds;
6624
} SScanDbReq;
6625

6626
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6627
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6628
void    tFreeSScanDbReq(SScanDbReq* pReq);
6629

6630
typedef struct {
6631
  int32_t scanId;
6632
  int8_t  bAccepted;
6633
} SScanDbRsp;
6634

6635
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6636
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6637

6638
typedef struct {
6639
  int32_t scanId;
6640
  int32_t sqlLen;
6641
  char*   sql;
6642
} SKillScanReq;
6643

6644
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6645
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6646
void    tFreeSKillScanReq(SKillScanReq* pReq);
6647

6648
typedef struct {
6649
  int32_t scanId;
6650
  int32_t vgId;
6651
  int32_t dnodeId;
6652
} SVKillScanReq;
6653

6654
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6655
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6656

6657
typedef struct {
6658
  int32_t scanId;
6659
  int32_t vgId;
6660
  int32_t dnodeId;
6661
  int32_t numberFileset;
6662
  int32_t finished;
6663
  int32_t progress;
6664
  int64_t remainingTime;
6665
} SQueryScanProgressRsp;
6666

6667
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6668
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6669

6670
typedef struct {
6671
  int32_t scanId;
6672
  int32_t vgId;
6673
  int32_t dnodeId;
6674
} SQueryScanProgressReq;
6675

6676
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6677
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6678

6679
typedef struct {
6680
  int64_t     dbUid;
6681
  char        db[TSDB_DB_FNAME_LEN];
6682
  int64_t     scanStartTime;
6683
  STimeWindow tw;
6684
  int32_t     scanId;
6685
} SScanVnodeReq;
6686

6687
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6688
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6689

6690
#ifdef __cplusplus
6691
}
6692
#endif
6693

6694
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6695
 
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