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

taosdata / TDengine / #4935

22 Jan 2026 06:38AM UTC coverage: 66.708% (+0.02%) from 66.691%
#4935

push

travis-ci

web-flow
merge: from main to 3.0 #34371

121 of 271 new or added lines in 17 files covered. (44.65%)

9066 existing lines in 149 files now uncovered.

203884 of 305637 relevant lines covered (66.71%)

125811266.68 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;
1,663✔
107
}
108

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

953
bool hasExtSchema(const SExtSchema* pExtSchema);
954

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

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

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

973
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
974
  if (pRef->pColRef) {
340,713✔
UNCOV
975
    return TSDB_CODE_INVALID_PARA;
×
976
  }
977
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
340,713✔
978
  if (pRef->pColRef == NULL) {
340,713✔
UNCOV
979
    return terrno;
×
980
  }
981
  pRef->nCols = nCols;
340,713✔
982
  for (int32_t i = 0; i < nCols; i++) {
144,321,256✔
983
    pRef->pColRef[i].hasRef = false;
143,980,543✔
984
    pRef->pColRef[i].id = (col_id_t)(i + 1);
143,980,543✔
985
  }
986
  return 0;
340,713✔
987
}
988

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

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

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

1010
  return pDstWrapper;
1011
}
1012

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

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

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

1046
  taosMemoryFreeClear(pWrapper->pColCmpr);
1047
  taosMemoryFreeClear(pWrapper);
1048
}
1049
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1050
  if (pSchemaWrapper->pSchema == NULL) return NULL;
633,368,046✔
1051

1052
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
633,135,002✔
1053
  if (pSW == NULL) {
633,083,317✔
UNCOV
1054
    return NULL;
×
1055
  }
1056
  pSW->nCols = pSchemaWrapper->nCols;
633,083,317✔
1057
  pSW->version = pSchemaWrapper->version;
633,273,408✔
1058
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
633,028,349✔
1059
  if (pSW->pSchema == NULL) {
632,648,180✔
1060
    taosMemoryFree(pSW);
×
UNCOV
1061
    return NULL;
×
1062
  }
1063

1064
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
632,871,604✔
1065
  return pSW;
633,493,439✔
1066
}
1067

1068
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
310,425,572✔
1069
  if (pSchemaWrapper) {
1,807,728,947✔
1070
    taosMemoryFree(pSchemaWrapper->pSchema);
1,014,580,823✔
1071
    if (pSchemaWrapper->pRsma) {
1,014,326,095✔
1072
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
25,596✔
1073
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
25,596✔
1074
    }
1075
    taosMemoryFree(pSchemaWrapper);
1,014,472,568✔
1076
  }
1077
}
1,764,907,777✔
1078

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

1089
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
7,400,407✔
1090
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
7,400,407✔
1091
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
7,400,910✔
1092
  }
1093
}
7,400,052✔
1094

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

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

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

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

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

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

1146
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1147
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
728,902,672✔
1148
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
728,902,672✔
1149
  if (pColRef->hasRef) {
364,451,336✔
1150
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
437,169,444✔
1151
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
437,169,444✔
1152
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
437,169,444✔
1153
  }
1154
  return 0;
364,451,336✔
1155
}
1156

1157
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1158
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
364,785,222✔
1159
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
364,785,222✔
1160
  if (pColRef->hasRef) {
182,392,611✔
1161
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
109,436,338✔
1162
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
109,436,338✔
1163
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
109,436,338✔
1164
  }
1165

1166
  return 0;
182,392,611✔
1167
}
1168

1169
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1170
  int32_t tlen = 0;
448,130✔
1171
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
448,130✔
1172
  tlen += taosEncodeVariantI32(buf, pSW->version);
448,130✔
1173
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,111,692✔
1174
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,327,124✔
1175
  }
1176
  return tlen;
448,130✔
1177
}
1178

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

1188
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,377,428✔
1189
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,372,318✔
1190
    }
1191
  } else {
UNCOV
1192
    pSW->pSchema = NULL;
×
1193
  }
1194
  return (void*)buf;
191,269✔
1195
}
1196

1197
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1198
  if (pSW == NULL) {
461,875,723✔
UNCOV
1199
    return TSDB_CODE_INVALID_PARA;
×
1200
  }
1201
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
923,866,759✔
1202
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
923,976,371✔
1203
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1204
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1205
  }
1206
  return 0;
462,149,349✔
1207
}
1208

1209
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1210
  if (pSW == NULL) {
186,825,746✔
UNCOV
1211
    return TSDB_CODE_INVALID_PARA;
×
1212
  }
1213
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
373,625,876✔
1214
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
373,611,654✔
1215

1216
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
186,811,524✔
1217
  if (pSW->pSchema == NULL) {
186,762,142✔
UNCOV
1218
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1219
  }
1220
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,695,174,729✔
1221
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1222
  }
1223

1224
  return 0;
186,847,790✔
1225
}
1226

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

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

1239
  return 0;
1,853,988,186✔
1240
}
1241

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1571

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

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

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

1587
  int8_t negIpRanges;
1588
  int8_t negTimeRanges;
1589

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

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

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

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

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

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

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

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

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

1647
typedef struct {
1648
  int8_t alterType;
1649

1650
  int8_t isView;
1651

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1872

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

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

1882

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

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

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

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

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

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

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

1921

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2032
typedef STableCfg STableCfgRsp;
2033

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2409
typedef SDbCfgRsp SDbCfgInfo;
2410

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

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

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

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

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

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

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

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

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

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

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

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

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

2462

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

2475

2476

2477
typedef struct SDNodeAddr {
2478
  int32_t nodeId;  // dnodeId
2479
  SEpSet  epSet;
2480
} SDNodeAddr;
2481

2482
typedef struct {
2483
  SArray* dnodeList;  // SArray<SDNodeAddr>
2484
} SDnodeListRsp;
2485

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

2490
typedef struct {
2491
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2492
} STableTSMAInfoRsp;
2493

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

2503
typedef struct {
2504
  SArray* pArray;  // Array of SDbHbRsp
2505
} SDbHbBatchRsp;
2506

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

2511
typedef struct {
2512
  SArray* pArray;  // Array of SGetUserAuthRsp
2513
} SUserAuthBatchRsp;
2514

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

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

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

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

2542
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2543
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2544

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

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

2558
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2559
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2560

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

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

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

2585
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2586
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2587

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

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

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

2612
typedef struct {
2613
  int32_t funcVersion;
2614
  int64_t funcCreatedTime;
2615
} SFuncExtraInfo;
2616

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

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

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

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

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

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

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

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

2718
typedef struct {
2719
  int32_t vgId;
2720
  int64_t nTimeSeries;
2721
} SVnodeLoadLite;
2722

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

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

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

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

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

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

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

2792
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2793
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2794

2795
typedef enum {
2796
  MONITOR_TYPE_COUNTER = 0,
2797
  MONITOR_TYPE_SLOW_LOG = 1,
2798
} MONITOR_TYPE;
2799

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

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

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

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

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

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

2840
typedef struct {
2841
  int32_t dnodeId;
2842
  int64_t clusterId;
2843
} SDnodeCfg;
2844

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

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

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

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

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

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

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

2893
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2894
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2895

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

2913
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2914
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2915

2916
typedef struct {
2917
  int32_t reserved;
2918
} SMTimerReq;
2919

2920
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2921
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2922

2923
typedef struct SOrphanTask {
2924
  int64_t streamId;
2925
  int32_t taskId;
2926
  int32_t nodeId;
2927
} SOrphanTask;
2928

2929
typedef struct SMStreamDropOrphanMsg {
2930
  SArray* pList;  // SArray<SOrphanTask>
2931
} SMStreamDropOrphanMsg;
2932

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

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

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

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

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

3009
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3010
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3011

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

3025
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3026
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3027

3028
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3029
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3030

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

3039
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3040
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3041

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

3050
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3051
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3052

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

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

3078
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3079
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3080

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

3090
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3091
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3092

3093
typedef SVKillCompactReq SVKillRetentionReq;
3094

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

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

3116
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3117

3118
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3119
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3120

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

3147
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3148
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3149

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

3164
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3165
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3166

3167
typedef struct {
3168
  int32_t vgId;
3169
  int8_t  disable;
3170
} SDisableVnodeWriteReq;
3171

3172
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3173
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3174

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

3184
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3185
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3186

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

3197
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3198
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3199

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

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

3220
typedef struct {
3221
  int32_t     numOfVgroups;
3222
  SVgroupInfo vgroups[];
3223
} SVgroupsInfo;
3224

3225
typedef struct {
3226
  STableMetaRsp* pMeta;
3227
} SMAlterStbRsp;
3228

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

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

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

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

3247
typedef struct {
3248
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3249
} SViewHbRsp;
3250

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

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

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

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

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

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

3290
typedef struct {
3291
  SArray* variables;  // SArray<SVariablesInfo>
3292
} SShowVariablesRsp;
3293

3294
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3295
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3296

3297
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3298

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

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

3315
typedef struct {
3316
  int64_t       showId;
3317
  STableMetaRsp tableMeta;
3318
} SShowRsp, SVShowTablesRsp;
3319

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

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

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

3340
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3341
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3342

3343
#define RETRIEVE_TABLE_RSP_VERSION         0
3344
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3345
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3346

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

3366
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3367

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

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

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

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

3402
typedef struct {
3403
  int32_t           numOfPlans;
3404
  SExplainExecInfo* subplanInfo;
3405
} SExplainRsp;
3406

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3515
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3516
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3517

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

3525
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3526
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3527

3528
typedef struct {
3529
  int32_t nodeId;
3530
  SEpSet  epSet;
3531
} SNodeEpSet;
3532

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

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

3545
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3546
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3547
typedef struct {
3548
  int8_t   replica;
3549
  SReplica replicas[TSDB_MAX_REPLICA];
3550
  int8_t   learnerReplica;
3551
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3552
  int64_t  lastIndex;
3553
  int8_t   encrypted;  // Whether sdb.data is encrypted (0=false, 1=true)
3554
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3555

3556
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3557
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3558

3559
typedef struct {
3560
  int32_t urlLen;
3561
  int32_t sqlLen;
3562
  char*   url;
3563
  char*   sql;
3564
} SMCreateAnodeReq;
3565

3566
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3567
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3568
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3569

3570
typedef struct {
3571
  int32_t anodeId;
3572
  int32_t sqlLen;
3573
  char*   sql;
3574
} SMDropAnodeReq, SMUpdateAnodeReq;
3575

3576
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3577
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3578
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3579
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3580
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3581
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3582

3583
typedef struct {
3584
  int32_t dnodeId;
3585
  int32_t bnodeProto;
3586
  int32_t sqlLen;
3587
  char*   sql;
3588
} SMCreateBnodeReq, SDCreateBnodeReq;
3589

3590
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3591
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3592
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3593

3594
typedef struct {
3595
  int32_t dnodeId;
3596
  int32_t sqlLen;
3597
  char*   sql;
3598
} SMDropBnodeReq, SDDropBnodeReq;
3599

3600
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3601
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3602
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3603

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

3616
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3617
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3618
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3619

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

3629
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3630
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3631
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3632
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3633
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3634
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3635

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

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

3705
typedef enum {
3706
  XNODE_TASK_SOURCE_DSN = 1,
3707
  XNODE_TASK_SOURCE_DATABASE,
3708
  XNODE_TASK_SOURCE_TOPIC,
3709
} ENodeXTaskSourceType;
3710

3711
typedef enum {
3712
  XNODE_TASK_SINK_DSN = 1,
3713
  XNODE_TASK_SINK_DATABASE,
3714
} ENodeXTaskSinkType;
3715

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

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

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

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

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

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

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

3840
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3841
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3842
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3843

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

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

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

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

3893
typedef struct {
3894
  int32_t jid;
3895
  CowStr  ast;
3896
  int32_t sqlLen;
3897
  char*   sql;
3898
} SMDropXnodeJobReq;
3899
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3900
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3901
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3902

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

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

3925
typedef SMDropXnodeTaskReq SMDropXnodeAgentReq;
3926
int32_t                    tSerializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
3927
int32_t                    tDeserializeSMDropXnodeAgentReq(void* buf, int32_t bufLen, SMDropXnodeAgentReq* pReq);
3928
void                       tFreeSMDropXnodeAgentReq(SMDropXnodeAgentReq* pReq);
3929

3930
typedef struct {
3931
  int32_t vgId;
3932
  int32_t hbSeq;
3933
} SVArbHbReqMember;
3934

3935
typedef struct {
3936
  int32_t dnodeId;
3937
  char*   arbToken;
3938
  int64_t arbTerm;
3939
  SArray* hbMembers;  // SVArbHbReqMember
3940
} SVArbHeartBeatReq;
3941

3942
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3943
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3944
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3945

3946
typedef struct {
3947
  int32_t vgId;
3948
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3949
  int32_t hbSeq;
3950
} SVArbHbRspMember;
3951

3952
typedef struct {
3953
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3954
  int32_t dnodeId;
3955
  SArray* hbMembers;  // SVArbHbRspMember
3956
} SVArbHeartBeatRsp;
3957

3958
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3959
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3960
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3961

3962
typedef struct {
3963
  char*   arbToken;
3964
  int64_t arbTerm;
3965
  char*   member0Token;
3966
  char*   member1Token;
3967
} SVArbCheckSyncReq;
3968

3969
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3970
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3971
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3972

3973
typedef struct {
3974
  char*   arbToken;
3975
  char*   member0Token;
3976
  char*   member1Token;
3977
  int32_t vgId;
3978
  int32_t errCode;
3979
} SVArbCheckSyncRsp;
3980

3981
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3982
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3983
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3984

3985
typedef struct {
3986
  char*   arbToken;
3987
  int64_t arbTerm;
3988
  char*   memberToken;
3989
  int8_t  force;
3990
} SVArbSetAssignedLeaderReq;
3991

3992
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3993
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3994
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3995

3996
typedef struct {
3997
  char*   arbToken;
3998
  char*   memberToken;
3999
  int32_t vgId;
4000
} SVArbSetAssignedLeaderRsp;
4001

4002
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4003
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
4004
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
4005

4006
typedef struct {
4007
  int32_t dnodeId;
4008
  char*   token;
4009
} SMArbUpdateGroupMember;
4010

4011
typedef struct {
4012
  int32_t dnodeId;
4013
  char*   token;
4014
  int8_t  acked;
4015
} SMArbUpdateGroupAssigned;
4016

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

4029
typedef struct {
4030
  SArray* updateArray;  // SMArbUpdateGroup
4031
} SMArbUpdateGroupBatchReq;
4032

4033
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4034
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
4035
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4036

4037
typedef struct {
4038
  char queryStrId[TSDB_QUERY_ID_LEN];
4039
} SKillQueryReq;
4040

4041
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4042
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4043

4044
typedef struct {
4045
  uint32_t connId;
4046
} SKillConnReq;
4047

4048
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4049
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4050

4051
typedef struct {
4052
  int32_t transId;
4053
} SKillTransReq;
4054

4055
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4056
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4057

4058
typedef struct {
4059
  int32_t useless;  // useless
4060
  int32_t sqlLen;
4061
  char*   sql;
4062
} SBalanceVgroupReq;
4063

4064
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4065
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4066
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4067

4068
typedef struct {
4069
  int32_t useless;  // useless
4070
  int32_t sqlLen;
4071
  char*   sql;
4072
} SAssignLeaderReq;
4073

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

4082
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4083
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4084

4085
typedef struct {
4086
  int32_t vgId;
4087
  int32_t dnodeId1;
4088
  int32_t dnodeId2;
4089
  int32_t dnodeId3;
4090
  int32_t sqlLen;
4091
  char*   sql;
4092
} SRedistributeVgroupReq;
4093

4094
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4095
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4096
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4097

4098
typedef struct {
4099
  int32_t reserved;
4100
  int32_t vgId;
4101
  int32_t sqlLen;
4102
  char*   sql;
4103
  char    db[TSDB_DB_FNAME_LEN];
4104
} SBalanceVgroupLeaderReq;
4105

4106
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4107
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4108
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4109

4110
typedef struct {
4111
  int32_t vgId;
4112
} SForceBecomeFollowerReq;
4113

4114
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4115
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4116

4117
typedef struct {
4118
  int32_t vgId;
4119
  bool    force;
4120
} SSplitVgroupReq;
4121

4122
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4123
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4124

4125
typedef struct {
4126
  char user[TSDB_USER_LEN];
4127
  char spi;
4128
  char encrypt;
4129
  char secret[TSDB_PASSWORD_LEN];
4130
  char ckey[TSDB_PASSWORD_LEN];
4131
} SAuthReq, SAuthRsp;
4132

4133
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4134
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4135

4136
typedef struct {
4137
  int32_t statusCode;
4138
  char    details[1024];
4139
} SServerStatusRsp;
4140

4141
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4142
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4143

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

4172
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4173
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4174
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4175

4176
typedef struct {
4177
  SMsgHead header;
4178
  uint64_t sId;
4179
  uint64_t queryId;
4180
  uint64_t taskId;
4181
} SSinkDataReq;
4182

4183
typedef struct {
4184
  SMsgHead header;
4185
  uint64_t sId;
4186
  uint64_t queryId;
4187
  uint64_t clientId;
4188
  uint64_t taskId;
4189
  int32_t  execId;
4190
} SQueryContinueReq;
4191

4192
typedef struct {
4193
  SMsgHead header;
4194
  uint64_t sId;
4195
  uint64_t queryId;
4196
  uint64_t taskId;
4197
} SResReadyReq;
4198

4199
typedef struct {
4200
  int32_t code;
4201
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4202
  int32_t sversion;
4203
  int32_t tversion;
4204
} SResReadyRsp;
4205

4206
typedef enum { OP_GET_PARAM = 1, OP_NOTIFY_PARAM } SOperatorParamType;
4207

4208
typedef struct SOperatorParam {
4209
  int32_t opType;
4210
  int32_t downstreamIdx;
4211
  void*   value;
4212
  SArray* pChildren;  // SArray<SOperatorParam*>
4213
  bool    reUse;
4214
} SOperatorParam;
4215

4216
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type);
4217

4218
typedef struct SColIdNameKV {
4219
  col_id_t colId;
4220
  char     colName[TSDB_COL_NAME_LEN];
4221
} SColIdNameKV;
4222

4223
#define COL_MASK_ON   ((int8_t)0x1)
4224
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4225
#define COL_SET_MASK_ON(c)     \
4226
  do {                         \
4227
    (c)->flags |= COL_MASK_ON; \
4228
  } while (0)
4229

4230
typedef struct SColNameFlag {
4231
  col_id_t colId;
4232
  char     colName[TSDB_COL_NAME_LEN];
4233
  int8_t   flags;  // 0x01: COL_MASK_ON
4234
} SColNameFlag;
4235

4236
typedef struct SColIdPair {
4237
  col_id_t  vtbColId;
4238
  col_id_t  orgColId;
4239
  SDataType type;
4240
} SColIdPair;
4241

4242
typedef struct SColIdSlotIdPair {
4243
  int32_t  vtbSlotId;
4244
  col_id_t orgColId;
4245
} SColIdSlotIdPair;
4246

4247
typedef struct SOrgTbInfo {
4248
  int32_t vgId;
4249
  char    tbName[TSDB_TABLE_FNAME_LEN];
4250
  SArray* colMap;  // SArray<SColIdNameKV>
4251
} SOrgTbInfo;
4252

4253
void destroySOrgTbInfo(void *info);
4254

4255
typedef enum {
4256
  DYN_TYPE_STB_JOIN = 1,
4257
  DYN_TYPE_VSTB_SINGLE_SCAN,
4258
  DYN_TYPE_VSTB_BATCH_SCAN,
4259
  DYN_TYPE_VSTB_WIN_SCAN,
4260
} ETableScanDynType;
4261

4262
typedef enum {
4263
  DYN_TYPE_SCAN_PARAM = 1,
4264
  NOTIFY_TYPE_SCAN_PARAM,
4265
} ETableScanGetParamType;
4266

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

4284
typedef struct STagScanOperatorParam {
4285
  tb_uid_t vcUid;
4286
} STagScanOperatorParam;
4287

4288
typedef struct SVTableScanOperatorParam {
4289
  uint64_t        uid;
4290
  STimeWindow     window;
4291
  SOperatorParam* pTagScanOp;
4292
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4293
} SVTableScanOperatorParam;
4294

4295
typedef struct SMergeOperatorParam {
4296
  int32_t         winNum;
4297
} SMergeOperatorParam;
4298

4299
typedef struct SAggOperatorParam {
4300
  bool            needCleanRes;
4301
} SAggOperatorParam;
4302

4303
typedef struct SExternalWindowOperatorParam {
4304
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4305
} SExternalWindowOperatorParam;
4306

4307
typedef struct SDynQueryCtrlOperatorParam {
4308
  STimeWindow    window;
4309
} SDynQueryCtrlOperatorParam;
4310

4311
struct SStreamRuntimeFuncInfo;
4312
typedef struct {
4313
  SMsgHead        header;
4314
  uint64_t        sId;
4315
  uint64_t        queryId;
4316
  uint64_t        clientId;
4317
  uint64_t        taskId;
4318
  uint64_t        srcTaskId;  // used for subQ
4319
  uint64_t        blockIdx;   // used for subQ
4320
  int32_t         execId;
4321
  SOperatorParam* pOpParam;
4322

4323
  // used for new-stream
4324
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4325
  bool                           reset;
4326
  bool                           dynTbname;
4327
  // used for new-stream
4328
} SResFetchReq;
4329

4330
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4331
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4332
void    tDestroySResFetchReq(SResFetchReq* pReq);
4333
typedef struct {
4334
  SMsgHead header;
4335
  uint64_t clientId;
4336
} SSchTasksStatusReq;
4337

4338
typedef struct {
4339
  uint64_t queryId;
4340
  uint64_t clientId;
4341
  uint64_t taskId;
4342
  int64_t  refId;
4343
  int32_t  subJobId;
4344
  int32_t  execId;
4345
  int8_t   status;
4346
} STaskStatus;
4347

4348
typedef struct {
4349
  int64_t refId;
4350
  SArray* taskStatus;  // SArray<STaskStatus>
4351
} SSchedulerStatusRsp;
4352

4353
typedef struct {
4354
  uint64_t queryId;
4355
  uint64_t taskId;
4356
  int8_t   action;
4357
} STaskAction;
4358

4359
typedef struct SQueryNodeEpId {
4360
  int32_t nodeId;  // vgId or qnodeId
4361
  SEp     ep;
4362
} SQueryNodeEpId;
4363

4364
typedef struct {
4365
  SMsgHead       header;
4366
  uint64_t       clientId;
4367
  SQueryNodeEpId epId;
4368
  SArray*        taskAction;  // SArray<STaskAction>
4369
} SSchedulerHbReq;
4370

4371
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4372
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4373
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4374

4375
typedef struct {
4376
  SQueryNodeEpId epId;
4377
  SArray*        taskStatus;  // SArray<STaskStatus>
4378
} SSchedulerHbRsp;
4379

4380
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4381
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4382
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4383

4384
typedef struct {
4385
  SMsgHead header;
4386
  uint64_t sId;
4387
  uint64_t queryId;
4388
  uint64_t clientId;
4389
  uint64_t taskId;
4390
  int64_t  refId;
4391
  int32_t  execId;
4392
} STaskCancelReq;
4393

4394
typedef struct {
4395
  int32_t code;
4396
} STaskCancelRsp;
4397

4398
typedef struct {
4399
  SMsgHead header;
4400
  uint64_t sId;
4401
  uint64_t queryId;
4402
  uint64_t clientId;
4403
  uint64_t taskId;
4404
  int64_t  refId;
4405
  int32_t  execId;
4406
} STaskDropReq;
4407

4408
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4409
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4410

4411
typedef enum {
4412
  TASK_NOTIFY_FINISHED = 1,
4413
} ETaskNotifyType;
4414

4415
typedef struct {
4416
  SMsgHead        header;
4417
  uint64_t        sId;
4418
  uint64_t        queryId;
4419
  uint64_t        clientId;
4420
  uint64_t        taskId;
4421
  int64_t         refId;
4422
  int32_t         execId;
4423
  ETaskNotifyType type;
4424
} STaskNotifyReq;
4425

4426
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4427
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4428

4429
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4430
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4431

4432
typedef struct {
4433
  int32_t code;
4434
} STaskDropRsp;
4435

4436
#define STREAM_TRIGGER_AT_ONCE                 1
4437
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4438
#define STREAM_TRIGGER_MAX_DELAY               3
4439
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4440
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4441

4442
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4443
#define STREAM_FILL_HISTORY_ON        1
4444
#define STREAM_FILL_HISTORY_OFF       0
4445
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4446
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4447
#define STREAM_CREATE_STABLE_TRUE     1
4448
#define STREAM_CREATE_STABLE_FALSE    0
4449

4450
typedef struct SVgroupVer {
4451
  int32_t vgId;
4452
  int64_t ver;
4453
} SVgroupVer;
4454

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

4471
enum {
4472
  TOPIC_SUB_TYPE__DB = 1,
4473
  TOPIC_SUB_TYPE__TABLE,
4474
  TOPIC_SUB_TYPE__COLUMN,
4475
};
4476

4477
#define DEFAULT_MAX_POLL_INTERVAL  300000
4478
#define DEFAULT_SESSION_TIMEOUT    12000
4479
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4480
#define DEFAULT_MIN_POLL_ROWS      4096
4481

4482
typedef struct {
4483
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4484
  int8_t igExists;
4485
  int8_t subType;
4486
  int8_t withMeta;
4487
  char*  sql;
4488
  char   subDbName[TSDB_DB_FNAME_LEN];
4489
  char*  ast;
4490
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4491
  int8_t reload;
4492
} SCMCreateTopicReq;
4493

4494
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4495
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4496
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4497

4498
typedef struct {
4499
  int64_t consumerId;
4500
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4501

4502
typedef struct {
4503
  int64_t consumerId;
4504
  char    cgroup[TSDB_CGROUP_LEN];
4505
  char    clientId[TSDB_CLIENT_ID_LEN];
4506
  char    user[TSDB_USER_LEN];
4507
  char    fqdn[TSDB_FQDN_LEN];
4508
  SArray* topicNames;  // SArray<char**>
4509

4510
  int8_t  withTbName;
4511
  int8_t  autoCommit;
4512
  int32_t autoCommitInterval;
4513
  int8_t  resetOffsetCfg;
4514
  int8_t  enableReplay;
4515
  int8_t  enableBatchMeta;
4516
  int32_t sessionTimeoutMs;
4517
  int32_t maxPollIntervalMs;
4518
} SCMSubscribeReq;
4519

4520
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4521
  int32_t tlen = 0;
703,140✔
4522
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
703,140✔
4523
  tlen += taosEncodeString(buf, pReq->cgroup);
703,140✔
4524
  tlen += taosEncodeString(buf, pReq->clientId);
703,140✔
4525

4526
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
703,140✔
4527
  tlen += taosEncodeFixedI32(buf, topicNum);
703,140✔
4528

4529
  for (int32_t i = 0; i < topicNum; i++) {
987,586✔
4530
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
568,892✔
4531
  }
4532

4533
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
703,140✔
4534
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
703,140✔
4535
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
703,140✔
4536
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
703,140✔
4537
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
703,140✔
4538
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
703,140✔
4539
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
703,140✔
4540
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
703,140✔
4541
  tlen += taosEncodeString(buf, pReq->user);
703,140✔
4542
  tlen += taosEncodeString(buf, pReq->fqdn);
703,140✔
4543

4544
  return tlen;
703,140✔
4545
}
4546

4547
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4548
  void* start = buf;
358,877✔
4549
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
358,877✔
4550
  buf = taosDecodeStringTo(buf, pReq->cgroup);
358,877✔
4551
  buf = taosDecodeStringTo(buf, pReq->clientId);
358,877✔
4552

4553
  int32_t topicNum = 0;
358,877✔
4554
  buf = taosDecodeFixedI32(buf, &topicNum);
358,877✔
4555

4556
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
358,877✔
4557
  if (pReq->topicNames == NULL) {
358,877✔
UNCOV
4558
    return terrno;
×
4559
  }
4560
  for (int32_t i = 0; i < topicNum; i++) {
523,982✔
4561
    char* name = NULL;
165,105✔
4562
    buf = taosDecodeString(buf, &name);
165,105✔
4563
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
330,210✔
UNCOV
4564
      return terrno;
×
4565
    }
4566
  }
4567

4568
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
358,877✔
4569
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
358,877✔
4570
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
358,877✔
4571
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
358,877✔
4572
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
358,877✔
4573
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
358,877✔
4574
  if ((char*)buf - (char*)start < len) {
358,877✔
4575
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
358,877✔
4576
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
358,877✔
4577
    buf = taosDecodeStringTo(buf, pReq->user);
358,877✔
4578
    buf = taosDecodeStringTo(buf, pReq->fqdn);
717,754✔
4579
  } else {
UNCOV
4580
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4581
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4582
  }
4583

4584
  return 0;
358,877✔
4585
}
4586

4587
typedef struct {
4588
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4589
  SArray* removedConsumers;  // SArray<int64_t>
4590
  SArray* newConsumers;      // SArray<int64_t>
4591
} SMqRebInfo;
4592

4593
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4594
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
333,061✔
4595
  if (pRebInfo == NULL) {
333,061✔
4596
    return NULL;
×
4597
  }
4598
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
333,061✔
4599
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
333,061✔
4600
  if (pRebInfo->removedConsumers == NULL) {
333,061✔
UNCOV
4601
    goto _err;
×
4602
  }
4603
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
333,061✔
4604
  if (pRebInfo->newConsumers == NULL) {
333,061✔
4605
    goto _err;
×
4606
  }
4607
  return pRebInfo;
333,061✔
UNCOV
4608
_err:
×
UNCOV
4609
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
4610
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
4611
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
4612
  return NULL;
×
4613
}
4614

4615
typedef struct {
4616
  int64_t streamId;
4617
  int64_t checkpointId;
4618
  char    streamName[TSDB_STREAM_FNAME_LEN];
4619
} SMStreamDoCheckpointMsg;
4620

4621
typedef struct {
4622
  int64_t status;
4623
} SMVSubscribeRsp;
4624

4625
typedef struct {
4626
  char    name[TSDB_TOPIC_FNAME_LEN];
4627
  int8_t  igNotExists;
4628
  int32_t sqlLen;
4629
  char*   sql;
4630
  int8_t  force;
4631
} SMDropTopicReq;
4632

4633
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4634
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4635
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4636

4637
typedef struct {
4638
  char    name[TSDB_TOPIC_FNAME_LEN];
4639
  int8_t  igNotExists;
4640
  int32_t sqlLen;
4641
  char*   sql;
4642
} SMReloadTopicReq;
4643

4644
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4645
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4646
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4647

4648
typedef struct {
4649
  char   topic[TSDB_TOPIC_FNAME_LEN];
4650
  char   cgroup[TSDB_CGROUP_LEN];
4651
  int8_t igNotExists;
4652
  int8_t force;
4653
} SMDropCgroupReq;
4654

4655
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4656
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4657

4658
typedef struct {
4659
  int8_t reserved;
4660
} SMDropCgroupRsp;
4661

4662
typedef struct {
4663
  char    name[TSDB_TABLE_FNAME_LEN];
4664
  int8_t  alterType;
4665
  SSchema schema;
4666
} SAlterTopicReq;
4667

4668
typedef struct {
4669
  SMsgHead head;
4670
  char     name[TSDB_TABLE_FNAME_LEN];
4671
  int64_t  tuid;
4672
  int32_t  sverson;
4673
  int32_t  execLen;
4674
  char*    executor;
4675
  int32_t  sqlLen;
4676
  char*    sql;
4677
} SDCreateTopicReq;
4678

4679
typedef struct {
4680
  SMsgHead head;
4681
  char     name[TSDB_TABLE_FNAME_LEN];
4682
  int64_t  tuid;
4683
} SDDropTopicReq;
4684

4685
typedef struct {
4686
  char*      name;
4687
  int64_t    uid;
4688
  int64_t    interval[2];
4689
  int8_t     intervalUnit;
4690
  int16_t    nFuncs;
4691
  col_id_t*  funcColIds;  // column ids specified by user
4692
  func_id_t* funcIds;     // function ids specified by user
4693
} SRSmaParam;
4694

4695
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4696
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4697

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

4717
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4718
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4719

4720
// TDMT_VND_DROP_STB ==============
4721
typedef struct SVDropStbReq {
4722
  char*    name;
4723
  tb_uid_t suid;
4724
} SVDropStbReq;
4725

4726
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4727
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4728

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

4761
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4762
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4763
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4764
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4765

4766
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4767
  if (NULL == req) {
2,147,483,647✔
4768
    return;
2,147,483,647✔
4769
  }
4770

4771
  taosMemoryFreeClear(req->sql);
89,077,558✔
4772
  taosMemoryFreeClear(req->name);
89,078,817✔
4773
  taosMemoryFreeClear(req->comment);
89,074,639✔
4774
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
89,064,302✔
4775
    taosMemoryFreeClear(req->ctb.pTag);
83,475,001✔
4776
    taosMemoryFreeClear(req->ctb.stbName);
83,483,467✔
4777
    taosArrayDestroy(req->ctb.tagName);
83,490,326✔
4778
    req->ctb.tagName = NULL;
83,444,476✔
4779
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
5,594,313✔
4780
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
5,594,313✔
4781
  }
4782
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
89,053,609✔
4783
  taosMemoryFreeClear(req->pExtSchemas);
89,069,117✔
4784
  taosMemoryFreeClear(req->colRef.pColRef);
89,078,579✔
4785
}
4786

4787
typedef struct {
4788
  int32_t nReqs;
4789
  union {
4790
    SVCreateTbReq* pReqs;
4791
    SArray*        pArray;
4792
  };
4793
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4794
} SVCreateTbBatchReq;
4795

4796
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4797
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4798
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4799

4800
typedef struct {
4801
  int32_t        code;
4802
  STableMetaRsp* pMeta;
4803
} SVCreateTbRsp, SVUpdateTbRsp;
4804

4805
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4806
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4807
void tFreeSVCreateTbRsp(void* param);
4808

4809
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4810
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4811

4812
typedef struct {
4813
  int32_t nRsps;
4814
  union {
4815
    SVCreateTbRsp* pRsps;
4816
    SArray*        pArray;
4817
  };
4818
} SVCreateTbBatchRsp;
4819

4820
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4821
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4822

4823
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4824
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4825

4826
// TDMT_VND_DROP_TABLE =================
4827
typedef struct {
4828
  char*    name;
4829
  uint64_t suid;  // for tmq in wal format
4830
  int64_t  uid;
4831
  int8_t   igNotExists;
4832
  int8_t   isVirtual;
4833
} SVDropTbReq;
4834

4835
typedef struct {
4836
  int32_t code;
4837
} SVDropTbRsp;
4838

4839
typedef struct {
4840
  int32_t nReqs;
4841
  union {
4842
    SVDropTbReq* pReqs;
4843
    SArray*      pArray;
4844
  };
4845
} SVDropTbBatchReq;
4846

4847
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4848
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4849

4850
typedef struct {
4851
  int32_t nRsps;
4852
  union {
4853
    SVDropTbRsp* pRsps;
4854
    SArray*      pArray;
4855
  };
4856
} SVDropTbBatchRsp;
4857

4858
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4859
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4860

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

4911
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4912
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4913
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4914
void    tfreeMultiTagUpateVal(void* pMultiTag);
4915

4916
typedef struct {
4917
  int32_t        code;
4918
  STableMetaRsp* pMeta;
4919
} SVAlterTbRsp;
4920

4921
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4922
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4923
// ======================
4924

4925
typedef struct {
4926
  SMsgHead head;
4927
  int64_t  uid;
4928
  int32_t  tid;
4929
  int16_t  tversion;
4930
  int16_t  colId;
4931
  int8_t   type;
4932
  int16_t  bytes;
4933
  int32_t  tagValLen;
4934
  int16_t  numOfTags;
4935
  int32_t  schemaLen;
4936
  char     data[];
4937
} SUpdateTagValReq;
4938

4939
typedef struct {
4940
  SMsgHead head;
4941
} SUpdateTagValRsp;
4942

4943
typedef struct {
4944
  SMsgHead head;
4945
} SVShowTablesReq;
4946

4947
typedef struct {
4948
  SMsgHead head;
4949
  int32_t  id;
4950
} SVShowTablesFetchReq;
4951

4952
typedef struct {
4953
  int64_t useconds;
4954
  int8_t  completed;  // all results are returned to client
4955
  int8_t  precision;
4956
  int8_t  compressed;
4957
  int32_t compLen;
4958
  int32_t numOfRows;
4959
  char    data[];
4960
} SVShowTablesFetchRsp;
4961

4962
typedef struct {
4963
  int64_t consumerId;
4964
  int32_t epoch;
4965
  char    cgroup[TSDB_CGROUP_LEN];
4966
} SMqAskEpReq;
4967

4968
typedef struct {
4969
  int32_t key;
4970
  int32_t valueLen;
4971
  void*   value;
4972
} SKv;
4973

4974
typedef struct {
4975
  int64_t tscRid;
4976
  int8_t  connType;
4977
} SClientHbKey;
4978

4979
typedef struct {
4980
  int64_t tid;
4981
  char    status[TSDB_JOB_STATUS_LEN];
4982
} SQuerySubDesc;
4983

4984
typedef struct {
4985
  char     sql[TSDB_SHOW_SQL_LEN];
4986
  uint64_t queryId;
4987
  int64_t  useconds;
4988
  int64_t  stime;  // timestamp precision ms
4989
  int64_t  reqRid;
4990
  bool     stableQuery;
4991
  bool     isSubQuery;
4992
  char     fqdn[TSDB_FQDN_LEN];
4993
  int32_t  subPlanNum;
4994
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4995
} SQueryDesc;
4996

4997
typedef struct {
4998
  uint32_t connId;
4999
  SArray*  queryDesc;  // SArray<SQueryDesc>
5000
} SQueryHbReqBasic;
5001

5002
typedef struct {
5003
  uint32_t connId;
5004
  uint64_t killRid;
5005
  int32_t  totalDnodes;
5006
  int32_t  onlineDnodes;
5007
  int8_t   killConnection;
5008
  int8_t   align[3];
5009
  SEpSet   epSet;
5010
  SArray*  pQnodeList;
5011
} SQueryHbRspBasic;
5012

5013
typedef struct SAppClusterSummary {
5014
  uint64_t numOfInsertsReq;
5015
  uint64_t numOfInsertRows;
5016
  uint64_t insertElapsedTime;
5017
  uint64_t insertBytes;  // submit to tsdb since launched.
5018

5019
  uint64_t fetchBytes;
5020
  uint64_t numOfQueryReq;
5021
  uint64_t queryElapsedTime;
5022
  uint64_t numOfSlowQueries;
5023
  uint64_t totalRequests;
5024
  uint64_t currentRequests;  // the number of SRequestObj
5025
} SAppClusterSummary;
5026

5027
typedef struct {
5028
  int64_t            appId;
5029
  int32_t            pid;
5030
  char               name[TSDB_APP_NAME_LEN];
5031
  int64_t            startTime;
5032
  SAppClusterSummary summary;
5033
} SAppHbReq;
5034

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

5050
typedef struct {
5051
  int64_t reqId;
5052
  SArray* reqs;  // SArray<SClientHbReq>
5053
  int64_t ipWhiteListVer;
5054
} SClientHbBatchReq;
5055

5056
typedef struct {
5057
  SClientHbKey      connKey;
5058
  int32_t           status;
5059
  SQueryHbRspBasic* query;
5060
  SArray*           info;  // Array<Skv>
5061
} SClientHbRsp;
5062

5063
typedef struct {
5064
  int64_t       reqId;
5065
  int64_t       rspId;
5066
  int32_t       svrTimestamp;
5067
  SArray*       rsps;  // SArray<SClientHbRsp>
5068
  SMonitorParas monitorParas;
5069
  int8_t        enableAuditDelete;
5070
  int8_t        enableStrongPass;
5071
  int8_t        enableAuditSelect;
5072
  int8_t        enableAuditInsert;
5073
  int8_t        auditLevel;
5074
} SClientHbBatchRsp;
5075

5076
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
69,410,031✔
5077

5078
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5079
  void* pIter = taosHashIterate(info, NULL);
48,087,185✔
5080
  while (pIter != NULL) {
112,986,563✔
5081
    SKv* kv = (SKv*)pIter;
64,898,865✔
5082
    taosMemoryFreeClear(kv->value);
64,898,865✔
5083
    pIter = taosHashIterate(info, pIter);
64,898,684✔
5084
  }
5085
}
48,087,698✔
5086

5087
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
30,764,902✔
5088
  SQueryDesc* desc = (SQueryDesc*)pDesc;
30,764,902✔
5089
  if (desc->subDesc) {
30,764,902✔
5090
    taosArrayDestroy(desc->subDesc);
21,371,853✔
5091
    desc->subDesc = NULL;
21,369,906✔
5092
  }
5093
}
30,761,967✔
5094

5095
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
54,927,576✔
5096
  SClientHbReq* req = (SClientHbReq*)pReq;
57,299,879✔
5097
  if (req->query) {
57,299,879✔
5098
    if (req->query->queryDesc) {
54,927,148✔
5099
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
25,240,424✔
5100
    }
5101
    taosMemoryFreeClear(req->query);
54,925,967✔
5102
  }
5103

5104
  if (req->info) {
57,298,347✔
5105
    tFreeReqKvHash(req->info);
48,086,396✔
5106
    taosHashCleanup(req->info);
48,087,698✔
5107
    req->info = NULL;
48,086,459✔
5108
  }
5109
}
29,031,882✔
5110

5111
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5112
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5113

5114
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5115
  if (pReq == NULL) return;
23,455,820✔
5116
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
23,455,820✔
5117
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
23,455,820✔
5118
  taosMemoryFree(pReq);
23,455,820✔
5119
}
5120

5121
static FORCE_INLINE void tFreeClientKv(void* pKv) {
64,660,627✔
5122
  SKv* kv = (SKv*)pKv;
64,660,627✔
5123
  if (kv) {
64,660,627✔
5124
    taosMemoryFreeClear(kv->value);
64,660,627✔
5125
  }
5126
}
64,658,234✔
5127

5128
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
54,725,016✔
5129
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
54,725,016✔
5130
  if (rsp->query) {
54,725,016✔
5131
    taosArrayDestroy(rsp->query->pQnodeList);
54,717,026✔
5132
    taosMemoryFreeClear(rsp->query);
54,722,456✔
5133
  }
5134
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
54,729,858✔
5135
}
28,070,633✔
5136

5137
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5138
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
45,669,122✔
5139
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
45,669,122✔
5140
}
45,675,381✔
5141

5142
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5143
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5144
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5145

5146
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5147
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
403,582,183✔
5148
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
403,582,921✔
5149
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
403,584,490✔
5150
  return 0;
201,793,270✔
5151
}
5152

5153
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5154
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
132,904,852✔
5155
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
132,907,152✔
5156
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
66,453,597✔
5157
  if (pKv->value == NULL) {
66,451,184✔
UNCOV
5158
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5159
  }
5160
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
66,452,660✔
5161
  return 0;
66,453,555✔
5162
}
5163

5164
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5165
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
343,412,176✔
5166
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
343,406,146✔
5167
  return 0;
171,707,197✔
5168
}
5169

5170
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5171
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
113,053,883✔
5172
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
113,057,333✔
5173
  return 0;
56,532,390✔
5174
}
5175

5176
typedef struct {
5177
  int32_t vgId;
5178
  // TODO stas
5179
} SMqReportVgInfo;
5180

5181
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5182
  int32_t tlen = 0;
5183
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5184
  return tlen;
5185
}
5186

5187
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5188
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5189
  return buf;
5190
}
5191

5192
typedef struct {
5193
  int32_t epoch;
5194
  int64_t topicUid;
5195
  char    name[TSDB_TOPIC_FNAME_LEN];
5196
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5197
} SMqTopicInfo;
5198

5199
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5200
  int32_t tlen = 0;
5201
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5202
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5203
  tlen += taosEncodeString(buf, pTopicInfo->name);
5204
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5205
  tlen += taosEncodeFixedI32(buf, sz);
5206
  for (int32_t i = 0; i < sz; i++) {
5207
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5208
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5209
  }
5210
  return tlen;
5211
}
5212

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

5232
typedef struct {
5233
  int32_t status;  // ask hb endpoint
5234
  int32_t epoch;
5235
  int64_t consumerId;
5236
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5237
} SMqReportReq;
5238

5239
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5240
  int32_t tlen = 0;
5241
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5242
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5243
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5244
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5245
  tlen += taosEncodeFixedI32(buf, sz);
5246
  for (int32_t i = 0; i < sz; i++) {
5247
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5248
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5249
  }
5250
  return tlen;
5251
}
5252

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

5272
typedef struct {
5273
  SMsgHead head;
5274
  int64_t  leftForVer;
5275
  int32_t  vgId;
5276
  int64_t  consumerId;
5277
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5278
} SMqVDeleteReq;
5279

5280
typedef struct {
5281
  int8_t reserved;
5282
} SMqVDeleteRsp;
5283

5284
typedef struct {
5285
  char**  name;
5286
  int32_t count;
5287
  int8_t igNotExists;
5288
} SMDropStreamReq;
5289

5290
typedef struct {
5291
  int8_t reserved;
5292
} SMDropStreamRsp;
5293

5294
typedef struct {
5295
  SMsgHead head;
5296
  int64_t  resetRelHalt;  // reset related stream task halt status
5297
  int64_t  streamId;
5298
  int32_t  taskId;
5299
} SVDropStreamTaskReq;
5300

5301
typedef struct {
5302
  int8_t reserved;
5303
} SVDropStreamTaskRsp;
5304

5305
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5306
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5307
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5308

5309
typedef struct {
5310
  char*  name;
5311
  int8_t igNotExists;
5312
} SMPauseStreamReq;
5313

5314
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5315
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5316
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5317

5318
typedef struct {
5319
  char*  name;
5320
  int8_t igNotExists;
5321
  int8_t igUntreated;
5322
} SMResumeStreamReq;
5323

5324
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5325
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5326
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5327

5328
typedef struct {
5329
  char*       name;
5330
  int8_t      calcAll;
5331
  STimeWindow timeRange;
5332
} SMRecalcStreamReq;
5333

5334
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5335
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5336
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5337

5338

5339
typedef struct SVndSetKeepVersionReq {
5340
  int64_t keepVersion;
5341
} SVndSetKeepVersionReq;
5342

5343
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5344
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5345

5346
typedef struct SVUpdateCheckpointInfoReq {
5347
  SMsgHead head;
5348
  int64_t  streamId;
5349
  int32_t  taskId;
5350
  int64_t  checkpointId;
5351
  int64_t  checkpointVer;
5352
  int64_t  checkpointTs;
5353
  int32_t  transId;
5354
  int64_t  hStreamId;  // add encode/decode
5355
  int64_t  hTaskId;
5356
  int8_t   dropRelHTask;
5357
} SVUpdateCheckpointInfoReq;
5358

5359
typedef struct {
5360
  int64_t leftForVer;
5361
  int32_t vgId;
5362
  int64_t oldConsumerId;
5363
  int64_t newConsumerId;
5364
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5365
  int8_t  subType;
5366
  int8_t  withMeta;
5367
  char*   qmsg;  // SubPlanToString
5368
  SSchemaWrapper schema;
5369
  int64_t suid;
5370
} SMqRebVgReq;
5371

5372
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5373
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5374

5375
// tqOffset
5376
enum {
5377
  TMQ_OFFSET__RESET_NONE = -3,
5378
  TMQ_OFFSET__RESET_EARLIEST = -2,
5379
  TMQ_OFFSET__RESET_LATEST = -1,
5380
  TMQ_OFFSET__LOG = 1,
5381
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5382
  TMQ_OFFSET__SNAPSHOT_META = 3,
5383
};
5384

5385
enum {
5386
  WITH_DATA = 0,
5387
  WITH_META = 1,
5388
  ONLY_META = 2,
5389
};
5390

5391
#define TQ_OFFSET_VERSION 1
5392

5393
typedef struct {
5394
  int8_t type;
5395
  union {
5396
    // snapshot
5397
    struct {
5398
      int64_t uid;
5399
      int64_t ts;
5400
      SValue  primaryKey;
5401
    };
5402
    // log
5403
    struct {
5404
      int64_t version;
5405
    };
5406
  };
5407
} STqOffsetVal;
5408

5409
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5410
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,493,736✔
5411
  pOffsetVal->uid = uid;
7,492,263✔
5412
  pOffsetVal->ts = ts;
7,492,821✔
5413
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,490,728✔
5414
    taosMemoryFree(pOffsetVal->primaryKey.pData);
301✔
5415
  }
5416
  pOffsetVal->primaryKey = primaryKey;
7,488,639✔
5417
}
7,490,423✔
5418

5419
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5420
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
43,513✔
5421
  pOffsetVal->uid = uid;
43,513✔
5422
}
43,513✔
5423

5424
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5425
  pOffsetVal->type = TMQ_OFFSET__LOG;
121,214,896✔
5426
  pOffsetVal->version = ver;
121,214,302✔
5427
}
121,204,806✔
5428

5429
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5430
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5431
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5432
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5433
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5434
void    tOffsetDestroy(void* pVal);
5435

5436
typedef struct {
5437
  STqOffsetVal val;
5438
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5439
} STqOffset;
5440

5441
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5442
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5443
void    tDeleteSTqOffset(void* val);
5444

5445
typedef struct SMqVgOffset {
5446
  int64_t   consumerId;
5447
  STqOffset offset;
5448
} SMqVgOffset;
5449

5450
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5451
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5452

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

5487
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5488
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5489
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5490

5491
typedef struct {
5492
  char    name[TSDB_TABLE_FNAME_LEN];
5493
  int8_t  igNotExists;
5494
  char*   dropStreamReq;
5495
  int32_t dropStreamReqLen;
5496
} SMDropSmaReq;
5497

5498
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5499
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5500
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5501

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

5524
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5525
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5526
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5527

5528
typedef SMCreateRsmaReq SVCreateRsmaReq;
5529

5530
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5531
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5532
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5533

5534
typedef SMCreateRsmaReq SVAlterRsmaReq;
5535

5536
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5537
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5538
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5539

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

5552
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5553
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5554
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5555

5556
typedef struct {
5557
  int64_t    id;
5558
  char       name[TSDB_TABLE_NAME_LEN];
5559
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5560
  int64_t    ownerId;
5561
  int32_t    code;
5562
  int32_t    version;
5563
  int8_t     tbType;
5564
  int8_t     intervalUnit;
5565
  col_id_t   nFuncs;
5566
  col_id_t   nColNames;
5567
  int64_t    interval[2];
5568
  col_id_t*  funcColIds;
5569
  func_id_t* funcIds;
5570
  SArray*    colNames;
5571
} SRsmaInfoRsp;
5572

5573
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5574
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5575
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5576

5577
typedef struct {
5578
  char   name[TSDB_TABLE_FNAME_LEN];
5579
  int8_t igNotExists;
5580
} SMDropRsmaReq;
5581

5582
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5583
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5584

5585
typedef struct {
5586
  char    name[TSDB_TABLE_NAME_LEN];
5587
  char    tbName[TSDB_TABLE_NAME_LEN];
5588
  int64_t uid;
5589
  int64_t tbUid;
5590
  int8_t  tbType;
5591
} SVDropRsmaReq;
5592

5593
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5594
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5595

5596
typedef struct {
5597
  char   dbFName[TSDB_DB_FNAME_LEN];
5598
  char   stbName[TSDB_TABLE_NAME_LEN];
5599
  char   colName[TSDB_COL_NAME_LEN];
5600
  char   idxName[TSDB_INDEX_FNAME_LEN];
5601
  int8_t idxType;
5602
} SCreateTagIndexReq;
5603

5604
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5605
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5606

5607
typedef SMDropSmaReq SDropTagIndexReq;
5608

5609
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5610
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5611

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

5634
typedef STSma SVCreateTSmaReq;
5635

5636
typedef struct {
5637
  int8_t  type;  // 0 status report, 1 update data
5638
  int64_t indexUid;
5639
  int64_t skey;  // start TS key of interval/sliding window
5640
} STSmaMsg;
5641

5642
typedef struct {
5643
  int64_t indexUid;
5644
  char    indexName[TSDB_INDEX_NAME_LEN];
5645
} SVDropTSmaReq;
5646

5647
typedef struct {
5648
  int tmp;  // TODO: to avoid compile error
5649
} SVCreateTSmaRsp, SVDropTSmaRsp;
5650

5651
#if 0
5652
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5653
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5654
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5655
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5656
#endif
5657

5658
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5659
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5660
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5661
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5662

5663
typedef struct {
5664
  int32_t number;
5665
  STSma*  tSma;
5666
} STSmaWrapper;
5667

5668
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
5669
  if (pSma) {
×
UNCOV
5670
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5671
    taosMemoryFreeClear(pSma->expr);
×
5672
    taosMemoryFreeClear(pSma->tagsFilter);
×
5673
  }
5674
}
×
5675

5676
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5677
  if (pSW) {
×
UNCOV
5678
    if (pSW->tSma) {
×
5679
      if (deepCopy) {
×
UNCOV
5680
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5681
          tDestroyTSma(pSW->tSma + i);
×
5682
        }
5683
      }
UNCOV
5684
      taosMemoryFreeClear(pSW->tSma);
×
5685
    }
5686
  }
5687
}
×
5688

5689
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5690
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5691
  taosMemoryFreeClear(pSW);
×
UNCOV
5692
  return NULL;
×
5693
}
5694

5695
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5696
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5697

5698
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5699
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5700

5701
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
5702
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
5703
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5704
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5705
  }
5706
  return 0;
×
5707
}
5708

5709
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5710
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5711
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
5712
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5713
  }
UNCOV
5714
  return 0;
×
5715
}
5716

5717
typedef struct {
5718
  int idx;
5719
} SMCreateFullTextReq;
5720

5721
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5722
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5723
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5724

5725
typedef struct {
5726
  char   name[TSDB_TABLE_FNAME_LEN];
5727
  int8_t igNotExists;
5728
} SMDropFullTextReq;
5729

5730
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5731
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5732

5733
typedef struct {
5734
  char indexFName[TSDB_INDEX_FNAME_LEN];
5735
} SUserIndexReq;
5736

5737
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5738
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5739

5740
typedef struct {
5741
  char dbFName[TSDB_DB_FNAME_LEN];
5742
  char tblFName[TSDB_TABLE_FNAME_LEN];
5743
  char colName[TSDB_COL_NAME_LEN];
5744
  char owner[TSDB_USER_LEN];
5745
  char indexType[TSDB_INDEX_TYPE_LEN];
5746
  char indexExts[TSDB_INDEX_EXTS_LEN];
5747
} SUserIndexRsp;
5748

5749
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5750
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5751

5752
typedef struct {
5753
  char tbFName[TSDB_TABLE_FNAME_LEN];
5754
} STableIndexReq;
5755

5756
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5757
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5758

5759
typedef struct {
5760
  int8_t  intervalUnit;
5761
  int8_t  slidingUnit;
5762
  int64_t interval;
5763
  int64_t offset;
5764
  int64_t sliding;
5765
  int64_t dstTbUid;
5766
  int32_t dstVgId;
5767
  SEpSet  epSet;
5768
  char*   expr;
5769
} STableIndexInfo;
5770

5771
typedef struct {
5772
  char     tbName[TSDB_TABLE_NAME_LEN];
5773
  char     dbFName[TSDB_DB_FNAME_LEN];
5774
  uint64_t suid;
5775
  int32_t  version;
5776
  int32_t  indexSize;
5777
  SArray*  pIndex;  // STableIndexInfo
5778
} STableIndexRsp;
5779

5780
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5781
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5782
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5783

5784
void tFreeSTableIndexInfo(void* pInfo);
5785

5786
typedef struct {
5787
  int8_t  mqMsgType;
5788
  int32_t code;
5789
  int32_t epoch;
5790
  int64_t consumerId;
5791
  int64_t walsver;
5792
  int64_t walever;
5793
} SMqRspHead;
5794

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

5813
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5814
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5815
void    tDestroySMqPollReq(SMqPollReq* pReq);
5816

5817
typedef struct {
5818
  int32_t vgId;
5819
  int64_t offset;
5820
  SEpSet  epSet;
5821
} SMqSubVgEp;
5822

5823
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5824
  int32_t tlen = 0;
2,693,582✔
5825
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,693,582✔
5826
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,693,582✔
5827
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,693,582✔
5828
  return tlen;
2,693,582✔
5829
}
5830

5831
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5832
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,339,879✔
5833
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,339,879✔
5834
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,339,879✔
5835
  return buf;
1,339,879✔
5836
}
5837

5838
typedef struct {
5839
  char           topic[TSDB_TOPIC_FNAME_LEN];
5840
  char           db[TSDB_DB_FNAME_LEN];
5841
  SArray*        vgs;  // SArray<SMqSubVgEp>
5842
} SMqSubTopicEp;
5843

5844
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5845
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5846
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5847

5848
typedef struct {
5849
  SMqRspHead   head;
5850
  STqOffsetVal rspOffset;
5851
  int16_t      resMsgType;
5852
  int32_t      metaRspLen;
5853
  void*        metaRsp;
5854
} SMqMetaRsp;
5855

5856
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5857
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5858
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5859

5860
#define MQ_DATA_RSP_VERSION 100
5861

5862
typedef struct {
5863
  SMqRspHead   head;
5864
  STqOffsetVal rspOffset;
5865
  STqOffsetVal reqOffset;
5866
  int32_t      blockNum;
5867
  int8_t       withTbName;
5868
  int8_t       withSchema;
5869
  SArray*      blockDataLen;
5870
  SArray*      blockData;
5871
  SArray*      blockTbName;
5872
  SArray*      blockSchema;
5873

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

5892
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5893
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5894
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5895
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5896
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5897

5898
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5899
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5900
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5901

5902
typedef struct SMqBatchMetaRsp {
5903
  SMqRspHead   head;  // not serialize
5904
  STqOffsetVal rspOffset;
5905
  SArray*      batchMetaLen;
5906
  SArray*      batchMetaReq;
5907
  void*        pMetaBuff;    // not serialize
5908
  uint32_t     metaBuffLen;  // not serialize
5909
} SMqBatchMetaRsp;
5910

5911
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5912
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5913
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5914
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5915

5916
typedef struct {
5917
  int32_t    code;
5918
  SArray*    topics;  // SArray<SMqSubTopicEp>
5919
} SMqAskEpRsp;
5920

5921
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5922
  int32_t tlen = 0;
7,715,043✔
5923
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5924
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,715,043✔
5925
  tlen += taosEncodeFixedI32(buf, sz);
7,714,712✔
5926
  for (int32_t i = 0; i < sz; i++) {
9,746,945✔
5927
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
2,032,564✔
5928
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
2,032,564✔
5929
  }
5930
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,714,381✔
5931

5932
  return tlen;
7,714,712✔
5933
}
5934

5935
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5936
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5937
  int32_t sz;
3,309,945✔
5938
  buf = taosDecodeFixedI32(buf, &sz);
3,386,131✔
5939
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,386,131✔
5940
  if (pRsp->topics == NULL) {
3,386,131✔
UNCOV
5941
    return NULL;
×
5942
  }
5943
  for (int32_t i = 0; i < sz; i++) {
4,391,093✔
5944
    SMqSubTopicEp topicEp;
992,060✔
5945
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
1,004,962✔
5946
    if (buf == NULL) {
1,004,962✔
UNCOV
5947
      return NULL;
×
5948
    }
5949
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
2,009,924✔
UNCOV
5950
      return NULL;
×
5951
    }
5952
  }
5953
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,386,131✔
5954

5955
  return buf;
3,386,131✔
5956
}
5957

5958
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5959
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,617,726✔
5960
}
9,616,754✔
5961

5962
typedef struct {
5963
  int32_t      vgId;
5964
  STqOffsetVal offset;
5965
  int64_t      rows;
5966
  int64_t      ever;
5967
} OffsetRows;
5968

5969
typedef struct {
5970
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5971
  SArray* offsetRows;
5972
} TopicOffsetRows;
5973

5974
typedef struct {
5975
  int64_t consumerId;
5976
  int32_t epoch;
5977
  SArray* topics;
5978
  int8_t  pollFlag;
5979
} SMqHbReq;
5980

5981
typedef struct {
5982
  char   topic[TSDB_TOPIC_FNAME_LEN];
5983
  int8_t noPrivilege;
5984
} STopicPrivilege;
5985

5986
typedef struct {
5987
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5988
  int32_t debugFlag;
5989
} SMqHbRsp;
5990

5991
typedef struct {
5992
  SMsgHead head;
5993
  int64_t  consumerId;
5994
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5995
} SMqSeekReq;
5996

5997
#define TD_AUTO_CREATE_TABLE 0x1
5998
typedef struct {
5999
  int64_t       suid;
6000
  int64_t       uid;
6001
  int32_t       sver;
6002
  uint32_t      nData;
6003
  uint8_t*      pData;
6004
  SVCreateTbReq cTbReq;
6005
} SVSubmitBlk;
6006

6007
typedef struct {
6008
  SMsgHead header;
6009
  uint64_t sId;
6010
  uint64_t queryId;
6011
  uint64_t clientId;
6012
  uint64_t taskId;
6013
  uint32_t sqlLen;
6014
  uint32_t phyLen;
6015
  char*    sql;
6016
  char*    msg;
6017
  int8_t   source;
6018
} SVDeleteReq;
6019

6020
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6021
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
6022

6023
typedef struct {
6024
  int64_t affectedRows;
6025
} SVDeleteRsp;
6026

6027
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
6028
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
6029

6030
typedef struct SDeleteRes {
6031
  uint64_t suid;
6032
  SArray*  uidList;
6033
  int64_t  skey;
6034
  int64_t  ekey;
6035
  int64_t  affectedRows;
6036
  char     tableFName[TSDB_TABLE_NAME_LEN];
6037
  char     tsColName[TSDB_COL_NAME_LEN];
6038
  int64_t  ctimeMs;  // fill by vnode
6039
  int8_t   source;
6040
} SDeleteRes;
6041

6042
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
6043
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
6044

6045
typedef struct {
6046
  // int64_t uid;
6047
  char    tbname[TSDB_TABLE_NAME_LEN];
6048
  int64_t startTs;
6049
  int64_t endTs;
6050
} SSingleDeleteReq;
6051

6052
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
6053
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6054

6055
typedef struct {
6056
  int64_t suid;
6057
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6058
  int64_t ctimeMs;     // fill by vnode
6059
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6060
} SBatchDeleteReq;
6061

6062
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6063
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6064
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6065

6066
typedef struct {
6067
  int32_t msgIdx;
6068
  int32_t msgType;
6069
  int32_t msgLen;
6070
  void*   msg;
6071
} SBatchMsg;
6072

6073
typedef struct {
6074
  SMsgHead header;
6075
  SArray*  pMsgs;  // SArray<SBatchMsg>
6076
} SBatchReq;
6077

6078
typedef struct {
6079
  int32_t reqType;
6080
  int32_t msgIdx;
6081
  int32_t msgLen;
6082
  int32_t rspCode;
6083
  void*   msg;
6084
} SBatchRspMsg;
6085

6086
typedef struct {
6087
  SArray* pRsps;  // SArray<SBatchRspMsg>
6088
} SBatchRsp;
6089

6090
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6091
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6092
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
89,947,598✔
6093
  if (NULL == msg) {
89,947,598✔
UNCOV
6094
    return;
×
6095
  }
6096
  SBatchMsg* pMsg = (SBatchMsg*)msg;
89,947,598✔
6097
  taosMemoryFree(pMsg->msg);
89,947,598✔
6098
}
6099

6100
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6101
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6102

6103
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
125,118,896✔
6104
  if (NULL == p) {
125,118,896✔
UNCOV
6105
    return;
×
6106
  }
6107

6108
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
125,118,896✔
6109
  taosMemoryFree(pRsp->msg);
125,118,896✔
6110
}
6111

6112
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6113
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6114
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6115
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6116
void    tDestroySMqHbReq(SMqHbReq* pReq);
6117

6118
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6119
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6120
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6121

6122
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6123
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6124

6125
#define TD_REQ_FROM_APP               0x0
6126
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6127
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6128
#define SUBMIT_REQ_FROM_FILE          0x4
6129
#define TD_REQ_FROM_TAOX              0x8
6130
#define TD_REQ_FROM_SML               0x10
6131
#define SUBMIT_REQUEST_VERSION        (2)
6132
#define SUBMIT_REQ_WITH_BLOB          0x10
6133
#define SUBMIT_REQ_SCHEMA_RES         0x20
6134
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6135

6136
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6137

6138
typedef struct {
6139
  int32_t        flags;
6140
  SVCreateTbReq* pCreateTbReq;
6141
  int64_t        suid;
6142
  int64_t        uid;
6143
  int32_t        sver;
6144
  union {
6145
    SArray* aRowP;
6146
    SArray* aCol;
6147
  };
6148
  int64_t   ctimeMs;
6149
  SBlobSet* pBlobSet;
6150
} SSubmitTbData;
6151

6152
typedef struct {
6153
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6154
  SArray* aSubmitBlobData;
6155
  bool    raw;
6156
} SSubmitReq2;
6157

6158
typedef struct {
6159
  SMsgHead header;
6160
  int64_t  version;
6161
  char     data[];  // SSubmitReq2
6162
} SSubmitReq2Msg;
6163

6164
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6165
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6166
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6167
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6168
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6169

6170
typedef struct {
6171
  int32_t affectedRows;
6172
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6173
} SSubmitRsp2;
6174

6175
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6176
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6177
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6178

6179
#define TSDB_MSG_FLG_ENCODE 0x1
6180
#define TSDB_MSG_FLG_DECODE 0x2
6181
#define TSDB_MSG_FLG_CMPT   0x3
6182

6183
typedef struct {
6184
  union {
6185
    struct {
6186
      void*   msgStr;
6187
      int32_t msgLen;
6188
      int64_t ver;
6189
    };
6190
    void* pDataBlock;
6191
  };
6192
} SPackedData;
6193

6194
typedef struct {
6195
  char     fullname[TSDB_VIEW_FNAME_LEN];
6196
  char     name[TSDB_VIEW_NAME_LEN];
6197
  char     dbFName[TSDB_DB_FNAME_LEN];
6198
  char*    querySql;
6199
  char*    sql;
6200
  int8_t   orReplace;
6201
  int8_t   precision;
6202
  int32_t  numOfCols;
6203
  SSchema* pSchema;
6204
} SCMCreateViewReq;
6205

6206
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6207
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6208
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6209

6210
typedef struct {
6211
  char   fullname[TSDB_VIEW_FNAME_LEN];
6212
  char   name[TSDB_VIEW_NAME_LEN];
6213
  char   dbFName[TSDB_DB_FNAME_LEN];
6214
  char*  sql;
6215
  int8_t igNotExists;
6216
} SCMDropViewReq;
6217

6218
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6219
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6220
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6221

6222
typedef struct {
6223
  char fullname[TSDB_VIEW_FNAME_LEN];
6224
} SViewMetaReq;
6225
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6226
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6227

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

6250
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6251
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6252

6253
typedef struct {
6254
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6255
  union {
6256
    uint8_t flags;
6257
    struct {
6258
      uint8_t withColName : 1;
6259
      uint8_t reserved : 7;
6260
    };
6261
  };
6262

6263
} SRsmaInfoReq;
6264

6265
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6266
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6267

6268
typedef struct {
6269
  int32_t  funcId;
6270
  col_id_t colId;
6271
} STableTSMAFuncInfo;
6272

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

6291
  int64_t streamUid;
6292
  int64_t reqTs;
6293
  int64_t rspTs;
6294
  int64_t delayDuration;  // ms
6295
  bool    fillHistoryFinished;
6296

6297
  void* streamAddr;  // for stream task, the address of the stream task
6298
} STableTSMAInfo;
6299

6300
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6301
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6302
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6303
void    tFreeTableTSMAInfo(void* p);
6304
void    tFreeAndClearTableTSMAInfo(void* p);
6305
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6306

6307
#define STSMAHbRsp            STableTSMAInfoRsp
6308
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6309
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6310
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6311

6312
typedef struct SDropCtbWithTsmaSingleVgReq {
6313
  SVgroupInfo vgInfo;
6314
  SArray*     pTbs;  // SVDropTbReq
6315
} SMDropTbReqsOnSingleVg;
6316

6317
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6318
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6319
void    tFreeSMDropTbReqOnSingleVg(void* p);
6320

6321
typedef struct SDropTbsReq {
6322
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6323
} SMDropTbsReq;
6324

6325
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6326
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6327
void    tFreeSMDropTbsReq(void*);
6328

6329
typedef struct SVFetchTtlExpiredTbsRsp {
6330
  SArray* pExpiredTbs;  // SVDropTbReq
6331
  int32_t vgId;
6332
} SVFetchTtlExpiredTbsRsp;
6333

6334
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6335
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6336

6337
void tFreeFetchTtlExpiredTbsRsp(void* p);
6338

6339
void setDefaultOptionsForField(SFieldWithOptions* field);
6340
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6341

6342
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6343
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6344

6345

6346
typedef struct {
6347
  char    id[TSDB_INSTANCE_ID_LEN];
6348
  char    type[TSDB_INSTANCE_TYPE_LEN];
6349
  char    desc[TSDB_INSTANCE_DESC_LEN];
6350
  int32_t expire;
6351
} SInstanceRegisterReq;
6352

6353
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6354
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6355

6356
typedef struct {
6357
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6358
} SInstanceListReq;
6359

6360
typedef struct {
6361
  int32_t count;
6362
  char**  ids;  // Array of instance IDs
6363
} SInstanceListRsp;
6364

6365
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6366
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6367
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6368
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6369

6370
#ifdef USE_MOUNT
6371
typedef struct {
6372
  char     mountName[TSDB_MOUNT_NAME_LEN];
6373
  int8_t   ignoreExist;
6374
  int16_t  nMounts;
6375
  int32_t* dnodeIds;
6376
  char**   mountPaths;
6377
  int32_t  sqlLen;
6378
  char*    sql;
6379
} SCreateMountReq;
6380

6381
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6382
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6383
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6384

6385
typedef struct {
6386
  char    mountName[TSDB_MOUNT_NAME_LEN];
6387
  int8_t  ignoreNotExists;
6388
  int32_t sqlLen;
6389
  char*   sql;
6390
} SDropMountReq;
6391

6392
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6393
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6394
void    tFreeSDropMountReq(SDropMountReq* pReq);
6395

6396
typedef struct {
6397
  char     mountName[TSDB_MOUNT_NAME_LEN];
6398
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6399
  int64_t  mountUid;
6400
  int32_t  dnodeId;
6401
  uint32_t valLen;
6402
  int8_t   ignoreExist;
6403
  void*    pVal;
6404
} SRetrieveMountPathReq;
6405

6406
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6407
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6408

6409
typedef struct {
6410
  // path
6411
  int32_t diskPrimary;
6412
  // vgInfo
6413
  int32_t  vgId;
6414
  int32_t  cacheLastSize;
6415
  int32_t  szPage;
6416
  int32_t  szCache;
6417
  uint64_t szBuf;
6418
  int8_t   cacheLast;
6419
  int8_t   standby;
6420
  int8_t   hashMethod;
6421
  uint32_t hashBegin;
6422
  uint32_t hashEnd;
6423
  int16_t  hashPrefix;
6424
  int16_t  hashSuffix;
6425
  int16_t  sttTrigger;
6426
  // syncInfo
6427
  int32_t replications;
6428
  // tsdbInfo
6429
  int8_t  precision;
6430
  int8_t  compression;
6431
  int8_t  slLevel;
6432
  int32_t daysPerFile;
6433
  int32_t keep0;
6434
  int32_t keep1;
6435
  int32_t keep2;
6436
  int32_t keepTimeOffset;
6437
  int32_t minRows;
6438
  int32_t maxRows;
6439
  int32_t tsdbPageSize;
6440
  int32_t ssChunkSize;
6441
  int32_t ssKeepLocal;
6442
  int8_t  ssCompact;
6443
  // walInfo
6444
  int32_t walFsyncPeriod;      // millisecond
6445
  int32_t walRetentionPeriod;  // secs
6446
  int32_t walRollPeriod;       // secs
6447
  int64_t walRetentionSize;
6448
  int64_t walSegSize;
6449
  int32_t walLevel;
6450
  // encryptInfo
6451
  int32_t encryptAlgorithm;
6452
  // SVState
6453
  int64_t committed;
6454
  int64_t commitID;
6455
  int64_t commitTerm;
6456
  // stats
6457
  int64_t numOfSTables;
6458
  int64_t numOfCTables;
6459
  int64_t numOfNTables;
6460
  // dbInfo
6461
  uint64_t dbId;
6462
} SMountVgInfo;
6463

6464
typedef struct {
6465
  SMCreateStbReq req;
6466
  SArray*        pColExts;  // element: column id
6467
  SArray*        pTagExts;  // element: tag id
6468
} SMountStbInfo;
6469

6470
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6471
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6472

6473
typedef struct {
6474
  char     dbName[TSDB_DB_FNAME_LEN];
6475
  uint64_t dbId;
6476
  SArray*  pVgs;   // SMountVgInfo
6477
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6478
} SMountDbInfo;
6479

6480
typedef struct {
6481
  // common fields
6482
  char     mountName[TSDB_MOUNT_NAME_LEN];
6483
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6484
  int8_t   ignoreExist;
6485
  int64_t  mountUid;
6486
  int64_t  clusterId;
6487
  int32_t  dnodeId;
6488
  uint32_t valLen;
6489
  void*    pVal;
6490

6491
  // response fields
6492
  SArray* pDbs;  // SMountDbInfo
6493

6494
  // memory fields, no serialized
6495
  SArray*   pDisks[TFS_MAX_TIERS];
6496
  TdFilePtr pFile;
6497
} SMountInfo;
6498

6499
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6500
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6501
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6502

6503
typedef struct {
6504
  SCreateVnodeReq createReq;
6505
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6506
  char            mountName[TSDB_MOUNT_NAME_LEN];
6507
  int64_t         mountId;
6508
  int32_t         diskPrimary;
6509
  int32_t         mountVgId;
6510
  int64_t         committed;
6511
  int64_t         commitID;
6512
  int64_t         commitTerm;
6513
  int64_t         numOfSTables;
6514
  int64_t         numOfCTables;
6515
  int64_t         numOfNTables;
6516
} SMountVnodeReq;
6517

6518
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6519
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6520
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6521

6522
#endif  // USE_MOUNT
6523

6524
#pragma pack(pop)
6525

6526
typedef struct {
6527
  char        db[TSDB_DB_FNAME_LEN];
6528
  STimeWindow timeRange;
6529
  int32_t     sqlLen;
6530
  char*       sql;
6531
  SArray*     vgroupIds;
6532
} SScanDbReq;
6533

6534
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6535
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6536
void    tFreeSScanDbReq(SScanDbReq* pReq);
6537

6538
typedef struct {
6539
  int32_t scanId;
6540
  int8_t  bAccepted;
6541
} SScanDbRsp;
6542

6543
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6544
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6545

6546
typedef struct {
6547
  int32_t scanId;
6548
  int32_t sqlLen;
6549
  char*   sql;
6550
} SKillScanReq;
6551

6552
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6553
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6554
void    tFreeSKillScanReq(SKillScanReq* pReq);
6555

6556
typedef struct {
6557
  int32_t scanId;
6558
  int32_t vgId;
6559
  int32_t dnodeId;
6560
} SVKillScanReq;
6561

6562
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6563
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6564

6565
typedef struct {
6566
  int32_t scanId;
6567
  int32_t vgId;
6568
  int32_t dnodeId;
6569
  int32_t numberFileset;
6570
  int32_t finished;
6571
  int32_t progress;
6572
  int64_t remainingTime;
6573
} SQueryScanProgressRsp;
6574

6575
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6576
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6577

6578
typedef struct {
6579
  int32_t scanId;
6580
  int32_t vgId;
6581
  int32_t dnodeId;
6582
} SQueryScanProgressReq;
6583

6584
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6585
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6586

6587
typedef struct {
6588
  int64_t     dbUid;
6589
  char        db[TSDB_DB_FNAME_LEN];
6590
  int64_t     scanStartTime;
6591
  STimeWindow tw;
6592
  int32_t     scanId;
6593
} SScanVnodeReq;
6594

6595
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6596
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6597

6598
#ifdef __cplusplus
6599
}
6600
#endif
6601

6602
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6603
 
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