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

taosdata / TDengine / #4915

06 Jan 2026 01:30AM UTC coverage: 65.711% (+0.8%) from 64.876%
#4915

push

travis-ci

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

185 of 324 new or added lines in 15 files covered. (57.1%)

3013 existing lines in 16 files now uncovered.

206438 of 314159 relevant lines covered (65.71%)

119372024.93 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;
51✔
107
}
108

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

111
static inline bool vnodeIsMsgBlock(tmsg_t type) {
978,823,510✔
112
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
922,403,363✔
113
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,901,226,873✔
114
         (type == TDMT_SYNC_CONFIG_CHANGE);
115
}
116

117
static inline bool syncUtilUserCommit(tmsg_t msgType) {
2,105,918,451✔
118
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
2,105,918,451✔
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

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

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

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

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

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

671
} ENodeType;
672

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

952
bool hasExtSchema(const SExtSchema* pExtSchema);
953

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

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

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

972
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
973
  if (pRef->pColRef) {
258,960✔
UNCOV
974
    return TSDB_CODE_INVALID_PARA;
×
975
  }
976
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
258,960✔
977
  if (pRef->pColRef == NULL) {
258,960✔
UNCOV
978
    return terrno;
×
979
  }
980
  pRef->nCols = nCols;
258,960✔
981
  for (int32_t i = 0; i < nCols; i++) {
121,748,506✔
982
    pRef->pColRef[i].hasRef = false;
121,489,546✔
983
    pRef->pColRef[i].id = (col_id_t)(i + 1);
121,489,546✔
984
  }
985
  return 0;
258,960✔
986
}
987

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

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

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

1009
  return pDstWrapper;
1010
}
1011

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

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

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

1045
  taosMemoryFreeClear(pWrapper->pColCmpr);
1046
  taosMemoryFreeClear(pWrapper);
1047
}
1048
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
1049
  if (pSchemaWrapper->pSchema == NULL) return NULL;
710,300,891✔
1050

1051
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
710,185,749✔
1052
  if (pSW == NULL) {
709,710,179✔
UNCOV
1053
    return NULL;
×
1054
  }
1055
  pSW->nCols = pSchemaWrapper->nCols;
709,710,179✔
1056
  pSW->version = pSchemaWrapper->version;
709,760,298✔
1057
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
709,552,916✔
1058
  if (pSW->pSchema == NULL) {
709,045,650✔
UNCOV
1059
    taosMemoryFree(pSW);
×
UNCOV
1060
    return NULL;
×
1061
  }
1062

1063
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
709,163,423✔
1064
  return pSW;
710,289,936✔
1065
}
1066

1067
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
289,793,356✔
1068
  if (pSchemaWrapper) {
1,963,739,902✔
1069
    taosMemoryFree(pSchemaWrapper->pSchema);
1,114,085,390✔
1070
    if (pSchemaWrapper->pRsma) {
1,114,019,668✔
1071
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
26,316✔
1072
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
26,316✔
1073
    }
1074
    taosMemoryFree(pSchemaWrapper);
1,113,562,612✔
1075
  }
1076
}
1,922,414,592✔
1077

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

1088
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
3,488,634✔
1089
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
3,488,634✔
1090
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
3,488,634✔
1091
  }
1092
}
3,488,634✔
1093

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

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

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

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

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

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

1145
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1146
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
608,641,428✔
1147
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
608,641,428✔
1148
  if (pColRef->hasRef) {
304,320,714✔
1149
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
364,037,268✔
1150
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
364,037,268✔
1151
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
364,037,268✔
1152
  }
1153
  return 0;
304,320,714✔
1154
}
1155

1156
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1157
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
304,558,242✔
1158
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
304,558,242✔
1159
  if (pColRef->hasRef) {
152,279,121✔
1160
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
91,113,756✔
1161
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
91,113,756✔
1162
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
91,113,756✔
1163
  }
1164

1165
  return 0;
152,279,121✔
1166
}
1167

1168
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1169
  int32_t tlen = 0;
423,974✔
1170
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
423,974✔
1171
  tlen += taosEncodeVariantI32(buf, pSW->version);
423,974✔
1172
  for (int32_t i = 0; i < pSW->nCols; i++) {
3,017,074✔
1173
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
5,186,200✔
1174
  }
1175
  return tlen;
423,974✔
1176
}
1177

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

1187
    for (int32_t i = 0; i < pSW->nCols; i++) {
1,355,364✔
1188
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
2,340,466✔
1189
    }
1190
  } else {
UNCOV
1191
    pSW->pSchema = NULL;
×
1192
  }
1193
  return (void*)buf;
185,131✔
1194
}
1195

1196
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1197
  if (pSW == NULL) {
515,477,768✔
UNCOV
1198
    return TSDB_CODE_INVALID_PARA;
×
1199
  }
1200
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,030,979,023✔
1201
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,030,921,530✔
1202
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1203
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1204
  }
1205
  return 0;
515,739,176✔
1206
}
1207

1208
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1209
  if (pSW == NULL) {
197,564,632✔
UNCOV
1210
    return TSDB_CODE_INVALID_PARA;
×
1211
  }
1212
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
395,054,055✔
1213
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
395,046,753✔
1214

1215
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
197,557,330✔
1216
  if (pSW->pSchema == NULL) {
197,485,049✔
UNCOV
1217
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1218
  }
1219
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,669,885,461✔
1220
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1221
  }
1222

1223
  return 0;
197,601,633✔
1224
}
1225

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

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

1238
  return 0;
1,844,574,226✔
1239
}
1240

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1570

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

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

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

1586
  int8_t negIpRanges;
1587
  int8_t negTimeRanges;
1588

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

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

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

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

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

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

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

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

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

1646
typedef struct {
1647
  int8_t alterType;
1648

1649
  int8_t isView;
1650

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1825
  SUserSessCfg sessCfg;
1826
  int64_t      timeWhiteListVer;
1827
} SGetUserAuthRsp;
1828

1829
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1830
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1831
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1832

1833
int32_t tSerializePrivSysObjPolicies(SEncoder* pEncoder, SPrivSet* sysPriv, SHashObj* pHash);
1834
int32_t tDeserializePrivSysObjPolicies(SDecoder* pDecoder, SPrivSet* sysPriv, SHashObj** pHash);
1835
int32_t tSerializePrivTblPolicies(SEncoder* pEncoder, SHashObj* pHash);
1836
int32_t tDeserializePrivTblPolicies(SDecoder* pDecoder, SHashObj** pHash);
1837

1838
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1839
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1840
typedef struct {
1841
  int64_t ver;
1842
  char    user[TSDB_USER_LEN];
1843
  int32_t numOfRange;
1844
  union {
1845
    SIpV4Range* pIpRanges;
1846
    SIpRange*   pIpDualRanges;
1847
  };
1848
} SUpdateUserIpWhite;
1849

1850
typedef struct {
1851
  int64_t             ver;
1852
  int                 numOfUser;
1853
  SUpdateUserIpWhite* pUserIpWhite;
1854
} SUpdateIpWhite;
1855

1856
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1857
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1858
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1859
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1860

1861
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1862
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1863
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1864

1865

1866
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1867
// corresponding response struct is different.
1868
typedef struct {
1869
  int64_t ver;
1870
} SRetrieveWhiteListReq;
1871

1872
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1873
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1874

1875

1876
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1877
// corresponding response struct is different.
1878
typedef struct {
1879
  char user[TSDB_USER_LEN];
1880
} SGetUserWhiteListReq;
1881

1882
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1883
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1884

1885
typedef struct {
1886
  char    user[TSDB_USER_LEN];
1887
  int32_t numWhiteLists;
1888
  union {
1889
    SIpV4Range* pWhiteLists;
1890
    SIpRange*   pWhiteListsDual;
1891
  };
1892
} SGetUserIpWhiteListRsp;
1893

1894
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1895
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1896
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1897
void    tIpRangeSetDefaultMask(SIpRange* range);
1898

1899
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1900
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1901
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1902

1903
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1904
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1905
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1906

1907
typedef struct {
1908
  int64_t ver;
1909
  char    user[TSDB_USER_LEN];
1910
  int32_t numWhiteLists;
1911
  SDateTimeWhiteListItem* pWhiteLists;
1912
} SUserDateTimeWhiteList;
1913

1914

1915
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1916
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1917
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1918
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1919

1920
typedef struct {
1921
  int64_t             ver;
1922
  int                 numOfUser;
1923
  SUserDateTimeWhiteList *pUsers;
1924
} SRetrieveDateTimeWhiteListRsp;
1925

1926
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1927
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1928
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1929
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1930

1931
/*
1932
 * for client side struct, only column id, type, bytes are necessary
1933
 * But for data in vnode side, we need all the following information.
1934
 */
1935
typedef struct {
1936
  union {
1937
    col_id_t colId;
1938
    int16_t  slotId;
1939
  };
1940

1941
  uint8_t precision;
1942
  uint8_t scale;
1943
  int32_t bytes;
1944
  int8_t  type;
1945
  uint8_t pk;
1946
  bool    noData;
1947
} SColumnInfo;
1948

1949
typedef struct STimeWindow {
1950
  TSKEY skey;
1951
  TSKEY ekey;
1952
} STimeWindow;
1953

1954
typedef struct SQueryHint {
1955
  bool batchScan;
1956
} SQueryHint;
1957

1958
typedef struct {
1959
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1960
  int32_t tsLen;          // total length of ts comp block
1961
  int32_t tsNumOfBlocks;  // ts comp block numbers
1962
  int32_t tsOrder;        // ts comp block order
1963
} STsBufInfo;
1964

1965
typedef struct {
1966
  void*       timezone;
1967
  char        intervalUnit;
1968
  char        slidingUnit;
1969
  char        offsetUnit;
1970
  int8_t      precision;
1971
  int64_t     interval;
1972
  int64_t     sliding;
1973
  int64_t     offset;
1974
  STimeWindow timeRange;
1975
} SInterval;
1976

1977
typedef struct STbVerInfo {
1978
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1979
  int32_t sversion;
1980
  int32_t tversion;
1981
  int32_t rversion;  // virtual table's column ref's version
1982
} STbVerInfo;
1983

1984
typedef struct {
1985
  int32_t code;
1986
  int64_t affectedRows;
1987
  SArray* tbVerInfo;  // STbVerInfo
1988
} SQueryTableRsp;
1989

1990
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1991

1992
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1993

1994
typedef struct {
1995
  SMsgHead header;
1996
  char     dbFName[TSDB_DB_FNAME_LEN];
1997
  char     tbName[TSDB_TABLE_NAME_LEN];
1998
} STableCfgReq;
1999

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

2025
typedef STableCfg STableCfgRsp;
2026

2027
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2028
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
2029

2030
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2031
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
2032
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
2033

2034
typedef struct {
2035
  SMsgHead header;
2036
  tb_uid_t suid;
2037
} SVSubTablesReq;
2038

2039
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2040
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
2041

2042
typedef struct {
2043
  int32_t vgId;
2044
  SArray* pTables;  // SArray<SVCTableRefCols*>
2045
} SVSubTablesRsp;
2046

2047
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2048
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
2049
void    tDestroySVSubTablesRsp(void* rsp);
2050

2051
typedef struct {
2052
  SMsgHead header;
2053
  tb_uid_t suid;
2054
} SVStbRefDbsReq;
2055

2056
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2057
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
2058

2059
typedef struct {
2060
  int32_t vgId;
2061
  SArray* pDbs;  // SArray<char* (db name)>
2062
} SVStbRefDbsRsp;
2063

2064
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2065
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
2066
void    tDestroySVStbRefDbsRsp(void* rsp);
2067

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

2119
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2120
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
2121
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
2122

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

2157
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2158
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
2159
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
2160

2161
typedef struct {
2162
  char    db[TSDB_DB_FNAME_LEN];
2163
  int8_t  ignoreNotExists;
2164
  int8_t  force;
2165
  int32_t sqlLen;
2166
  char*   sql;
2167
} SDropDbReq;
2168

2169
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2170
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
2171
void    tFreeSDropDbReq(SDropDbReq* pReq);
2172

2173
typedef struct {
2174
  char    db[TSDB_DB_FNAME_LEN];
2175
  int64_t uid;
2176
} SDropDbRsp;
2177

2178
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2179
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
2180

2181
typedef struct {
2182
  char    name[TSDB_MOUNT_NAME_LEN];
2183
  int64_t uid;
2184
} SDropMountRsp;
2185

2186
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2187
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
2188

2189
typedef struct {
2190
  char    db[TSDB_DB_FNAME_LEN];
2191
  int64_t dbId;
2192
  int32_t vgVersion;
2193
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2194
  int64_t stateTs;     // ms
2195
} SUseDbReq;
2196

2197
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2198
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
2199

2200
typedef struct {
2201
  char    db[TSDB_DB_FNAME_LEN];
2202
  int64_t uid;
2203
  int32_t vgVersion;
2204
  int32_t vgNum;
2205
  int16_t hashPrefix;
2206
  int16_t hashSuffix;
2207
  int8_t  hashMethod;
2208
  union {
2209
    uint8_t flags;
2210
    struct {
2211
      uint8_t isMount : 1;  // TS-5868
2212
      uint8_t padding : 7;
2213
    };
2214
  };
2215
  SArray* pVgroupInfos;  // Array of SVgroupInfo
2216
  int32_t errCode;
2217
  int64_t stateTs;  // ms
2218
} SUseDbRsp;
2219

2220
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
2221
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
2222
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
2223
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
2224
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
2225

2226
typedef struct {
2227
  char db[TSDB_DB_FNAME_LEN];
2228
} SDbCfgReq;
2229

2230
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2231
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2232

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

2237
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2238
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2239

2240
typedef struct {
2241
  int32_t ssMigrateId;
2242
  bool    bAccepted;
2243
} SSsMigrateDbRsp;
2244

2245
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2246
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2247

2248
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2249
typedef struct {
2250
  int32_t ssMigrateId;
2251
} SListSsMigrateFileSetsReq;
2252

2253
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2254
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2255

2256
typedef struct {
2257
  int32_t ssMigrateId;
2258
  int32_t vgId;       // vgroup id
2259
  SArray* pFileSets;  // SArray<int32_t>
2260
} SListSsMigrateFileSetsRsp;
2261

2262
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2263
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2264
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2265

2266
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2267
typedef struct {
2268
  int32_t ssMigrateId;
2269
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2270
  int32_t fid;
2271
  int64_t startTimeSec;
2272
} SSsMigrateFileSetReq;
2273

2274
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2275
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2276

2277
typedef struct {
2278
  int32_t ssMigrateId;
2279
  int32_t nodeId;  // node id of the leader vnode
2280
  int32_t vgId;
2281
  int32_t fid;
2282
} SSsMigrateFileSetRsp;
2283

2284
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2285
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2286

2287
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2288
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2289
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2290
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2291
#define SSMIGRATE_FILESET_STATE_FAILED      4
2292

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

2305
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2306
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2307

2308
// Request for TDMT_MND_KILL_SSMIGRATE
2309
typedef struct {
2310
  int32_t ssMigrateId;
2311
  int32_t sqlLen;
2312
  char*   sql;
2313
} SKillSsMigrateReq;
2314

2315
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2316
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2317
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2318

2319
// Request for TDMT_VND_KILL_SSMIGRATE
2320
typedef struct {
2321
  int32_t ssMigrateId;
2322
} SVnodeKillSsMigrateReq;
2323

2324
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2325
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2326

2327
typedef struct {
2328
  int32_t vgId;
2329
  int64_t keepVersion;
2330
} SMndSetVgroupKeepVersionReq;
2331

2332
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2333
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2334

2335
typedef struct {
2336
  int32_t timestampSec;
2337
  int32_t ttlDropMaxCount;
2338
  int32_t nUids;
2339
  SArray* pTbUids;
2340
} SVDropTtlTableReq;
2341

2342
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2343
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2344

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

2402
typedef SDbCfgRsp SDbCfgInfo;
2403

2404
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2405
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2406
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2407
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2408
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2409

2410
typedef struct {
2411
  int32_t rowNum;
2412
} SQnodeListReq;
2413

2414
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2415
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2416

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

2421
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2422

2423
typedef struct {
2424
  int32_t useless;  // useless
2425
} SServerVerReq;
2426

2427
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2428
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2429

2430
typedef struct {
2431
  char ver[TSDB_VERSION_LEN];
2432
} SServerVerRsp;
2433

2434
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2435
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2436

2437
typedef struct SQueryNodeAddr {
2438
  int32_t nodeId;  // vgId or qnodeId
2439
  SEpSet  epSet;
2440
} SQueryNodeAddr;
2441

2442
typedef struct {
2443
  SQueryNodeAddr addr;
2444
  uint64_t       load;
2445
} SQueryNodeLoad;
2446

2447
typedef struct {
2448
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2449
} SQnodeListRsp;
2450

2451
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2452
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2453
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2454

2455

2456
typedef struct SDownstreamSourceNode {
2457
  ENodeType      type;
2458
  SQueryNodeAddr addr;
2459
  uint64_t       clientId;
2460
  uint64_t       taskId;
2461
  uint64_t       sId;
2462
  int32_t        execId;
2463
  int32_t        fetchMsgType;
2464
  bool           localExec;
2465
} SDownstreamSourceNode;
2466

2467

2468

2469
typedef struct SDNodeAddr {
2470
  int32_t nodeId;  // dnodeId
2471
  SEpSet  epSet;
2472
} SDNodeAddr;
2473

2474
typedef struct {
2475
  SArray* dnodeList;  // SArray<SDNodeAddr>
2476
} SDnodeListRsp;
2477

2478
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2479
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2480
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2481

2482
typedef struct {
2483
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2484
} STableTSMAInfoRsp;
2485

2486
typedef struct {
2487
  SUseDbRsp*         useDbRsp;
2488
  SDbCfgRsp*         cfgRsp;
2489
  STableTSMAInfoRsp* pTsmaRsp;
2490
  int32_t            dbTsmaVersion;
2491
  char               db[TSDB_DB_FNAME_LEN];
2492
  int64_t            dbId;
2493
} SDbHbRsp;
2494

2495
typedef struct {
2496
  SArray* pArray;  // Array of SDbHbRsp
2497
} SDbHbBatchRsp;
2498

2499
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2500
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2501
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2502

2503
typedef struct {
2504
  SArray* pArray;  // Array of SGetUserAuthRsp
2505
} SUserAuthBatchRsp;
2506

2507
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2508
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2509
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2510

2511
typedef struct {
2512
  char        db[TSDB_DB_FNAME_LEN];
2513
  STimeWindow timeRange;
2514
  int32_t     sqlLen;
2515
  char*       sql;
2516
  SArray*     vgroupIds;
2517
  int32_t     compactId;
2518
  int8_t      metaOnly;
2519
  int8_t      force;
2520
} SCompactDbReq;
2521

2522
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2523
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2524
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2525

2526
typedef struct {
2527
  union {
2528
    int32_t compactId;
2529
    int32_t id;
2530
  };
2531
  int8_t bAccepted;
2532
} SCompactDbRsp;
2533

2534
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2535
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2536

2537
typedef struct {
2538
  union {
2539
    int32_t compactId;
2540
    int32_t id;
2541
  };
2542
  int32_t sqlLen;
2543
  char*   sql;
2544
} SKillCompactReq;
2545

2546
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2547
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2548
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2549

2550
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2551
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2552

2553
typedef struct {
2554
  char    name[TSDB_FUNC_NAME_LEN];
2555
  int8_t  igExists;
2556
  int8_t  funcType;
2557
  int8_t  scriptType;
2558
  int8_t  outputType;
2559
  int32_t outputLen;
2560
  int32_t bufSize;
2561
  int32_t codeLen;
2562
  int64_t signature;
2563
  char*   pComment;
2564
  char*   pCode;
2565
  int8_t  orReplace;
2566
} SCreateFuncReq;
2567

2568
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2569
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2570
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2571

2572
typedef struct {
2573
  char   name[TSDB_FUNC_NAME_LEN];
2574
  int8_t igNotExists;
2575
} SDropFuncReq;
2576

2577
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2578
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2579

2580
typedef struct {
2581
  int32_t numOfFuncs;
2582
  bool    ignoreCodeComment;
2583
  SArray* pFuncNames;
2584
} SRetrieveFuncReq;
2585

2586
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2587
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2588
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2589

2590
typedef struct {
2591
  char    name[TSDB_FUNC_NAME_LEN];
2592
  int8_t  funcType;
2593
  int8_t  scriptType;
2594
  int8_t  outputType;
2595
  int32_t outputLen;
2596
  int32_t bufSize;
2597
  int64_t signature;
2598
  int32_t commentSize;
2599
  int32_t codeSize;
2600
  char*   pComment;
2601
  char*   pCode;
2602
} SFuncInfo;
2603

2604
typedef struct {
2605
  int32_t funcVersion;
2606
  int64_t funcCreatedTime;
2607
} SFuncExtraInfo;
2608

2609
typedef struct {
2610
  int32_t numOfFuncs;
2611
  SArray* pFuncInfos;
2612
  SArray* pFuncExtraInfos;
2613
} SRetrieveFuncRsp;
2614

2615
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2616
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2617
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2618
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2619

2620
typedef struct {
2621
  int32_t       statusInterval;
2622
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2623
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2624
  char          locale[TD_LOCALE_LEN];      // tsLocale
2625
  char          charset[TD_LOCALE_LEN];     // tsCharset
2626
  int8_t        ttlChangeOnWrite;
2627
  int8_t        enableWhiteList;
2628
  int8_t        encryptionKeyStat;
2629
  uint32_t      encryptionKeyChksum;
2630
  SMonitorParas monitorParas;
2631
  int32_t       statusIntervalMs;
2632
} SClusterCfg;
2633

2634
typedef struct {
2635
  int32_t openVnodes;
2636
  int32_t dropVnodes;
2637
  int32_t totalVnodes;
2638
  int32_t masterNum;
2639
  int64_t numOfSelectReqs;
2640
  int64_t numOfInsertReqs;
2641
  int64_t numOfInsertSuccessReqs;
2642
  int64_t numOfBatchInsertReqs;
2643
  int64_t numOfBatchInsertSuccessReqs;
2644
  int64_t errors;
2645
} SVnodesStat;
2646

2647
typedef struct {
2648
  int32_t vgId;
2649
  int8_t  syncState;
2650
  int8_t  syncRestore;
2651
  int64_t syncTerm;
2652
  int64_t roleTimeMs;
2653
  int64_t startTimeMs;
2654
  int8_t  syncCanRead;
2655
  int64_t cacheUsage;
2656
  int64_t numOfTables;
2657
  int64_t numOfTimeSeries;
2658
  int64_t totalStorage;
2659
  int64_t compStorage;
2660
  int64_t pointsWritten;
2661
  int64_t numOfSelectReqs;
2662
  int64_t numOfInsertReqs;
2663
  int64_t numOfInsertSuccessReqs;
2664
  int64_t numOfBatchInsertReqs;
2665
  int64_t numOfBatchInsertSuccessReqs;
2666
  int32_t numOfCachedTables;
2667
  int32_t learnerProgress;  // use one reservered
2668
  int64_t syncAppliedIndex;
2669
  int64_t syncCommitIndex;
2670
  int64_t bufferSegmentUsed;
2671
  int64_t bufferSegmentSize;
2672
} SVnodeLoad;
2673

2674
typedef struct {
2675
  int64_t total_requests;
2676
  int64_t total_rows;
2677
  int64_t total_bytes;
2678
  double  write_size;
2679
  double  cache_hit_ratio;
2680
  int64_t rpc_queue_wait;
2681
  int64_t preprocess_time;
2682

2683
  int64_t memory_table_size;
2684
  int64_t commit_count;
2685
  int64_t merge_count;
2686
  double  commit_time;
2687
  double  merge_time;
2688
  int64_t block_commit_time;
2689
  int64_t memtable_wait_time;
2690
} SVnodeMetrics;
2691

2692
typedef struct {
2693
  int32_t     vgId;
2694
  int64_t     numOfTables;
2695
  int64_t     memSize;
2696
  int64_t     l1Size;
2697
  int64_t     l2Size;
2698
  int64_t     l3Size;
2699
  int64_t     cacheSize;
2700
  int64_t     walSize;
2701
  int64_t     metaSize;
2702
  int64_t     rawDataSize;
2703
  int64_t     ssSize;
2704
  const char* dbname;
2705
  int8_t      estimateRawData;
2706
} SDbSizeStatisInfo;
2707

2708
typedef struct {
2709
  int32_t vgId;
2710
  int64_t nTimeSeries;
2711
} SVnodeLoadLite;
2712

2713
typedef struct {
2714
  int8_t  syncState;
2715
  int64_t syncTerm;
2716
  int8_t  syncRestore;
2717
  int64_t roleTimeMs;
2718
} SMnodeLoad;
2719

2720
typedef struct {
2721
  int32_t dnodeId;
2722
  int64_t numOfProcessedQuery;
2723
  int64_t numOfProcessedCQuery;
2724
  int64_t numOfProcessedFetch;
2725
  int64_t numOfProcessedDrop;
2726
  int64_t numOfProcessedNotify;
2727
  int64_t numOfProcessedHb;
2728
  int64_t numOfProcessedDelete;
2729
  int64_t cacheDataSize;
2730
  int64_t numOfQueryInQueue;
2731
  int64_t numOfFetchInQueue;
2732
  int64_t timeInQueryQueue;
2733
  int64_t timeInFetchQueue;
2734
} SQnodeLoad;
2735

2736
typedef struct {
2737
  int32_t     sver;      // software version
2738
  int64_t     dnodeVer;  // dnode table version in sdb
2739
  int32_t     dnodeId;
2740
  int64_t     clusterId;
2741
  int64_t     rebootTime;
2742
  int64_t     updateTime;
2743
  float       numOfCores;
2744
  int32_t     numOfSupportVnodes;
2745
  int32_t     numOfDiskCfg;
2746
  int64_t     memTotal;
2747
  int64_t     memAvail;
2748
  char        dnodeEp[TSDB_EP_LEN];
2749
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2750
  SMnodeLoad  mload;
2751
  SQnodeLoad  qload;
2752
  SClusterCfg clusterCfg;
2753
  SArray*     pVloads;  // array of SVnodeLoad
2754
  int32_t     statusSeq;
2755
  int64_t     ipWhiteVer;
2756
  int64_t     timeWhiteVer;
2757
  int64_t     analVer;
2758
  int64_t     timestamp;
2759
  char        auditDB[TSDB_DB_FNAME_LEN];
2760
  char        auditToken[TSDB_TOKEN_LEN];
2761
} SStatusReq;
2762

2763
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2764
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2765
void    tFreeSStatusReq(SStatusReq* pReq);
2766

2767
typedef struct {
2768
  int32_t forceReadConfig;
2769
  int32_t cver;
2770
  SArray* array;
2771
} SConfigReq;
2772

2773
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2774
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2775
void    tFreeSConfigReq(SConfigReq* pReq);
2776

2777
typedef struct {
2778
  int32_t dnodeId;
2779
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2780
} SDnodeInfoReq;
2781

2782
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2783
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2784

2785
typedef enum {
2786
  MONITOR_TYPE_COUNTER = 0,
2787
  MONITOR_TYPE_SLOW_LOG = 1,
2788
} MONITOR_TYPE;
2789

2790
typedef struct {
2791
  int32_t      contLen;
2792
  char*        pCont;
2793
  MONITOR_TYPE type;
2794
} SStatisReq;
2795

2796
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2797
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2798
void    tFreeSStatisReq(SStatisReq* pReq);
2799

2800
typedef struct {
2801
  char    db[TSDB_DB_FNAME_LEN];
2802
  char    table[TSDB_TABLE_NAME_LEN];
2803
  char    operation[AUDIT_OPERATION_LEN];
2804
  int32_t sqlLen;
2805
  char*   pSql;
2806
  double  duration;
2807
  int64_t affectedRows;
2808
} SAuditReq;
2809
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2810
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2811
void    tFreeSAuditReq(SAuditReq* pReq);
2812

2813
typedef struct {
2814
  SArray* auditArr;
2815
} SBatchAuditReq;
2816
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2817
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2818
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2819

2820
typedef struct {
2821
  int32_t dnodeId;
2822
  int64_t clusterId;
2823
  SArray* pVloads;
2824
} SNotifyReq;
2825

2826
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2827
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2828
void    tFreeSNotifyReq(SNotifyReq* pReq);
2829

2830
typedef struct {
2831
  int32_t dnodeId;
2832
  int64_t clusterId;
2833
} SDnodeCfg;
2834

2835
typedef struct {
2836
  int32_t id;
2837
  int8_t  isMnode;
2838
  SEp     ep;
2839
} SDnodeEp;
2840

2841
typedef struct {
2842
  int32_t id;
2843
  int8_t  isMnode;
2844
  int8_t  offlineReason;
2845
  SEp     ep;
2846
  char    active[TSDB_ACTIVE_KEY_LEN];
2847
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2848
} SDnodeInfo;
2849

2850
typedef struct {
2851
  int64_t   dnodeVer;
2852
  SDnodeCfg dnodeCfg;
2853
  SArray*   pDnodeEps;  // Array of SDnodeEp
2854
  int32_t   statusSeq;
2855
  int64_t   ipWhiteVer;
2856
  int64_t   analVer;
2857
  int64_t   timeWhiteVer;
2858
  char      auditDB[TSDB_DB_FNAME_LEN];
2859
  char      auditToken[TSDB_TOKEN_LEN];
2860
} SStatusRsp;
2861

2862
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2863
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2864
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2865

2866
typedef struct {
2867
  int32_t forceReadConfig;
2868
  int32_t isConifgVerified;
2869
  int32_t isVersionVerified;
2870
  int32_t cver;
2871
  SArray* array;
2872
} SConfigRsp;
2873

2874
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2875
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2876
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2877

2878
typedef struct {
2879
  int32_t dnodeId;
2880
  int32_t keyVersion;  // Local key version
2881
} SKeySyncReq;
2882

2883
int32_t tSerializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2884
int32_t tDeserializeSKeySyncReq(void* buf, int32_t bufLen, SKeySyncReq* pReq);
2885

2886
typedef struct {
2887
  int32_t keyVersion;        // mnode's key version
2888
  int8_t  needUpdate;        // 1 if dnode needs to update keys
2889
  int32_t encryptionKeyStatus;  // Encryption key status (TSDB_ENCRYPT_KEY_STAT_*)
2890
  char    svrKey[129];       // Server key (if needUpdate)
2891
  char    dbKey[129];        // Database key (if needUpdate)
2892
  char    cfgKey[129];       // Config key (if needUpdate)
2893
  char    metaKey[129];      // Metadata key (if needUpdate)
2894
  char    dataKey[129];      // Data key (if needUpdate)
2895
  int32_t algorithm;         // Encryption algorithm for master keys
2896
  int32_t cfgAlgorithm;      // Encryption algorithm for CFG_KEY
2897
  int32_t metaAlgorithm;     // Encryption algorithm for META_KEY
2898
  int64_t createTime;        // Key creation time
2899
  int64_t svrKeyUpdateTime;  // Server key update time
2900
  int64_t dbKeyUpdateTime;   // Database key update time
2901
} SKeySyncRsp;
2902

2903
int32_t tSerializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2904
int32_t tDeserializeSKeySyncRsp(void* buf, int32_t bufLen, SKeySyncRsp* pRsp);
2905

2906
typedef struct {
2907
  int32_t reserved;
2908
} SMTimerReq;
2909

2910
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2911
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2912

2913
typedef struct SOrphanTask {
2914
  int64_t streamId;
2915
  int32_t taskId;
2916
  int32_t nodeId;
2917
} SOrphanTask;
2918

2919
typedef struct SMStreamDropOrphanMsg {
2920
  SArray* pList;  // SArray<SOrphanTask>
2921
} SMStreamDropOrphanMsg;
2922

2923
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2924
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2925
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2926

2927
typedef struct {
2928
  int32_t  id;
2929
  uint16_t port;                 // node sync Port
2930
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2931
} SReplica;
2932

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

2986
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2987
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2988
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2989

2990
typedef struct {
2991
  union {
2992
    int32_t compactId;
2993
    int32_t id;
2994
  };
2995
  int32_t vgId;
2996
  int32_t dnodeId;
2997
} SQueryCompactProgressReq;
2998

2999
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3000
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
3001

3002
typedef struct {
3003
  union {
3004
    int32_t compactId;
3005
    int32_t id;
3006
  };
3007
  int32_t vgId;
3008
  int32_t dnodeId;
3009
  int32_t numberFileset;
3010
  int32_t finished;
3011
  int32_t progress;
3012
  int64_t remainingTime;
3013
} SQueryCompactProgressRsp;
3014

3015
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3016
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
3017

3018
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
3019
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
3020

3021
typedef struct {
3022
  int32_t vgId;
3023
  int32_t dnodeId;
3024
  int64_t dbUid;
3025
  char    db[TSDB_DB_FNAME_LEN];
3026
  int64_t reserved[8];
3027
} SDropVnodeReq;
3028

3029
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3030
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
3031

3032
typedef struct {
3033
  char    colName[TSDB_COL_NAME_LEN];
3034
  char    stb[TSDB_TABLE_FNAME_LEN];
3035
  int64_t stbUid;
3036
  int64_t dbUid;
3037
  int64_t reserved[8];
3038
} SDropIndexReq;
3039

3040
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3041
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
3042

3043
typedef struct {
3044
  int64_t dbUid;
3045
  char    db[TSDB_DB_FNAME_LEN];
3046
  union {
3047
    int64_t compactStartTime;
3048
    int64_t startTime;
3049
  };
3050

3051
  STimeWindow tw;
3052
  union {
3053
    int32_t compactId;
3054
    int32_t id;
3055
  };
3056
  int8_t metaOnly;
3057
  union {
3058
    uint16_t flags;
3059
    struct {
3060
      uint16_t optrType : 3;     // ETsdbOpType
3061
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3062
      uint16_t reserved : 12;
3063
    };
3064
  };
3065
  int8_t force;  // force compact
3066
} SCompactVnodeReq;
3067

3068
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3069
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
3070

3071
typedef struct {
3072
  union {
3073
    int32_t compactId;
3074
    int32_t taskId;
3075
  };
3076
  int32_t vgId;
3077
  int32_t dnodeId;
3078
} SVKillCompactReq;
3079

3080
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3081
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
3082

3083
typedef SVKillCompactReq SVKillRetentionReq;
3084

3085
typedef struct {
3086
  char        db[TSDB_DB_FNAME_LEN];
3087
  int32_t     maxSpeed;
3088
  int32_t     sqlLen;
3089
  char*       sql;
3090
  SArray*     vgroupIds;
3091
  STimeWindow tw;  // unit is second
3092
  union {
3093
    uint32_t flags;
3094
    struct {
3095
      uint32_t optrType : 3;     // ETsdbOpType
3096
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
3097
      uint32_t reserved : 28;
3098
    };
3099
  };
3100
} STrimDbReq;
3101

3102
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3103
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
3104
void    tFreeSTrimDbReq(STrimDbReq* pReq);
3105

3106
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
3107

3108
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3109
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
3110

3111
typedef struct {
3112
  int32_t vgVersion;
3113
  int32_t buffer;
3114
  int32_t pageSize;
3115
  int32_t pages;
3116
  int32_t cacheLastSize;
3117
  int32_t daysPerFile;
3118
  int32_t daysToKeep0;
3119
  int32_t daysToKeep1;
3120
  int32_t daysToKeep2;
3121
  int32_t keepTimeOffset;
3122
  int32_t walFsyncPeriod;
3123
  int8_t  walLevel;
3124
  int8_t  strict;
3125
  int8_t  cacheLast;
3126
  int64_t reserved[7];
3127
  // 1st modification
3128
  int16_t sttTrigger;
3129
  int32_t minRows;
3130
  // 2nd modification
3131
  int32_t walRetentionPeriod;
3132
  int32_t walRetentionSize;
3133
  int32_t ssKeepLocal;
3134
  int8_t  ssCompact;
3135
} SAlterVnodeConfigReq;
3136

3137
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3138
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
3139

3140
typedef struct {
3141
  int32_t  vgId;
3142
  int8_t   strict;
3143
  int8_t   selfIndex;
3144
  int8_t   replica;
3145
  SReplica replicas[TSDB_MAX_REPLICA];
3146
  int64_t  reserved[8];
3147
  int8_t   learnerSelfIndex;
3148
  int8_t   learnerReplica;
3149
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3150
  int32_t  changeVersion;
3151
  int32_t  electBaseLine;
3152
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
3153

3154
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3155
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
3156

3157
typedef struct {
3158
  int32_t vgId;
3159
  int8_t  disable;
3160
} SDisableVnodeWriteReq;
3161

3162
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3163
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
3164

3165
typedef struct {
3166
  int32_t  srcVgId;
3167
  int32_t  dstVgId;
3168
  uint32_t hashBegin;
3169
  uint32_t hashEnd;
3170
  int32_t  changeVersion;
3171
  int32_t  reserved;
3172
} SAlterVnodeHashRangeReq;
3173

3174
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3175
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
3176

3177
#define REQ_OPT_TBNAME 0x0
3178
#define REQ_OPT_TBUID  0x01
3179
typedef struct {
3180
  SMsgHead header;
3181
  char     dbFName[TSDB_DB_FNAME_LEN];
3182
  char     tbName[TSDB_TABLE_NAME_LEN];
3183
  uint8_t  option;
3184
  uint8_t  autoCreateCtb;
3185
} STableInfoReq;
3186

3187
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3188
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
3189

3190
typedef struct {
3191
  int8_t  metaClone;  // create local clone of the cached table meta
3192
  int32_t numOfVgroups;
3193
  int32_t numOfTables;
3194
  int32_t numOfUdfs;
3195
  char    tableNames[];
3196
} SMultiTableInfoReq;
3197

3198
// todo refactor
3199
typedef struct SVgroupInfo {
3200
  int32_t  vgId;
3201
  uint32_t hashBegin;
3202
  uint32_t hashEnd;
3203
  SEpSet   epSet;
3204
  union {
3205
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
3206
    int32_t taskId;      // used in stream
3207
  };
3208
} SVgroupInfo;
3209

3210
typedef struct {
3211
  int32_t     numOfVgroups;
3212
  SVgroupInfo vgroups[];
3213
} SVgroupsInfo;
3214

3215
typedef struct {
3216
  STableMetaRsp* pMeta;
3217
} SMAlterStbRsp;
3218

3219
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
3220
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
3221
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
3222

3223
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3224
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
3225
void    tFreeSTableMetaRsp(void* pRsp);
3226
void    tFreeSTableIndexRsp(void* info);
3227

3228
typedef struct {
3229
  SArray* pMetaRsp;   // Array of STableMetaRsp
3230
  SArray* pIndexRsp;  // Array of STableIndexRsp;
3231
} SSTbHbRsp;
3232

3233
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3234
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
3235
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
3236

3237
typedef struct {
3238
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
3239
} SViewHbRsp;
3240

3241
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3242
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
3243
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
3244

3245
typedef struct {
3246
  int32_t numOfTables;
3247
  int32_t numOfVgroup;
3248
  int32_t numOfUdf;
3249
  int32_t contLen;
3250
  int8_t  compressed;  // denote if compressed or not
3251
  int32_t rawLen;      // size before compress
3252
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
3253
  char    meta[];
3254
} SMultiTableMeta;
3255

3256
typedef struct {
3257
  int32_t dataLen;
3258
  char    name[TSDB_TABLE_FNAME_LEN];
3259
  char*   data;
3260
} STagData;
3261

3262
typedef struct {
3263
  int32_t  opType;
3264
  uint32_t valLen;
3265
  char*    val;
3266
} SShowVariablesReq;
3267

3268
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3269
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
3270
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
3271

3272
typedef struct {
3273
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3274
  char value[TSDB_CONFIG_PATH_LEN + 1];
3275
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3276
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3277
  char info[TSDB_CONFIG_INFO_LEN + 1];
3278
} SVariablesInfo;
3279

3280
typedef struct {
3281
  SArray* variables;  // SArray<SVariablesInfo>
3282
} SShowVariablesRsp;
3283

3284
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3285
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3286

3287
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3288

3289
/*
3290
 * sql: show tables like '%a_%'
3291
 * payload is the query condition, e.g., '%a_%'
3292
 * payloadLen is the length of payload
3293
 */
3294
typedef struct {
3295
  int32_t type;
3296
  char    db[TSDB_DB_FNAME_LEN];
3297
  int32_t payloadLen;
3298
  char*   payload;
3299
} SShowReq;
3300

3301
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3302
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3303
void tFreeSShowReq(SShowReq* pReq);
3304

3305
typedef struct {
3306
  int64_t       showId;
3307
  STableMetaRsp tableMeta;
3308
} SShowRsp, SVShowTablesRsp;
3309

3310
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3311
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3312
// void    tFreeSShowRsp(SShowRsp* pRsp);
3313

3314
typedef struct {
3315
  char    db[TSDB_DB_FNAME_LEN];
3316
  char    tb[TSDB_TABLE_NAME_LEN];
3317
  char    user[TSDB_USER_LEN];
3318
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3319
  int64_t showId;
3320
  int64_t compactId;  // for compact
3321
  bool    withFull;   // for show users full
3322
} SRetrieveTableReq;
3323

3324
typedef struct SSysTableSchema {
3325
  int8_t   type;
3326
  col_id_t colId;
3327
  int32_t  bytes;
3328
} SSysTableSchema;
3329

3330
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3331
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3332

3333
#define RETRIEVE_TABLE_RSP_VERSION         0
3334
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3335
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3336

3337
typedef struct {
3338
  int64_t useconds;
3339
  int8_t  completed;  // all results are returned to client
3340
  int8_t  precision;
3341
  int8_t  compressed;
3342
  int8_t  streamBlockType;
3343
  int32_t payloadLen;
3344
  int32_t compLen;
3345
  int32_t numOfBlocks;
3346
  int64_t numOfRows;  // from int32_t change to int64_t
3347
  int64_t numOfCols;
3348
  int64_t skey;
3349
  int64_t ekey;
3350
  int64_t version;                         // for stream
3351
  TSKEY   watermark;                       // for stream
3352
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3353
  char    data[];
3354
} SRetrieveTableRsp;
3355

3356
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3357

3358
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3359
  do {                                          \
3360
    ((int32_t*)(_p))[0] = (_compLen);           \
3361
    ((int32_t*)(_p))[1] = (_fullLen);           \
3362
  } while (0);
3363

3364
typedef struct {
3365
  int64_t version;
3366
  int64_t numOfRows;
3367
  int8_t  compressed;
3368
  int8_t  precision;
3369
  char    data[];
3370
} SRetrieveTableRspForTmq;
3371

3372
typedef struct {
3373
  int64_t handle;
3374
  int64_t useconds;
3375
  int8_t  completed;  // all results are returned to client
3376
  int8_t  precision;
3377
  int8_t  compressed;
3378
  int32_t compLen;
3379
  int32_t numOfRows;
3380
  int32_t fullLen;
3381
  char    data[];
3382
} SRetrieveMetaTableRsp;
3383

3384
typedef struct SExplainExecInfo {
3385
  double   startupCost;
3386
  double   totalCost;
3387
  uint64_t numOfRows;
3388
  uint32_t verboseLen;
3389
  void*    verboseInfo;
3390
} SExplainExecInfo;
3391

3392
typedef struct {
3393
  int32_t           numOfPlans;
3394
  SExplainExecInfo* subplanInfo;
3395
} SExplainRsp;
3396

3397
typedef struct {
3398
  SExplainRsp rsp;
3399
  uint64_t    qId;
3400
  uint64_t    cId;
3401
  uint64_t    tId;
3402
  int64_t     rId;
3403
  int32_t     eId;
3404
} SExplainLocalRsp;
3405

3406
typedef struct STableScanAnalyzeInfo {
3407
  uint64_t totalRows;
3408
  uint64_t totalCheckedRows;
3409
  uint32_t totalBlocks;
3410
  uint32_t loadBlocks;
3411
  uint32_t loadBlockStatis;
3412
  uint32_t skipBlocks;
3413
  uint32_t filterOutBlocks;
3414
  double   elapsedTime;
3415
  double   filterTime;
3416
} STableScanAnalyzeInfo;
3417

3418
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3419
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3420
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3421

3422
typedef struct {
3423
  char    config[TSDB_DNODE_CONFIG_LEN];
3424
  char    value[TSDB_CLUSTER_VALUE_LEN];
3425
  int32_t sqlLen;
3426
  char*   sql;
3427
} SMCfgClusterReq;
3428

3429
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3430
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3431
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3432

3433
typedef struct {
3434
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3435
  int32_t port;
3436
  int32_t sqlLen;
3437
  char*   sql;
3438
} SCreateDnodeReq;
3439

3440
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3441
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3442
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3443

3444
typedef struct {
3445
  int32_t dnodeId;
3446
  char    fqdn[TSDB_FQDN_LEN];
3447
  int32_t port;
3448
  int8_t  force;
3449
  int8_t  unsafe;
3450
  int32_t sqlLen;
3451
  char*   sql;
3452
} SDropDnodeReq;
3453

3454
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3455
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3456
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3457

3458
enum {
3459
  RESTORE_TYPE__ALL = 1,
3460
  RESTORE_TYPE__MNODE,
3461
  RESTORE_TYPE__VNODE,
3462
  RESTORE_TYPE__QNODE,
3463
};
3464

3465
typedef struct {
3466
  int32_t dnodeId;
3467
  int8_t  restoreType;
3468
  int32_t sqlLen;
3469
  char*   sql;
3470
} SRestoreDnodeReq;
3471

3472
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3473
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3474
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3475

3476
typedef struct {
3477
  int32_t dnodeId;
3478
  char    config[TSDB_DNODE_CONFIG_LEN];
3479
  char    value[TSDB_DNODE_VALUE_LEN];
3480
  int32_t sqlLen;
3481
  char*   sql;
3482
} SMCfgDnodeReq;
3483

3484
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3485
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3486
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3487

3488
typedef struct {
3489
  int8_t  keyType;  // 0: SVR_KEY, 1: DB_KEY
3490
  char    newKey[ENCRYPT_KEY_LEN + 1];
3491
  int32_t sqlLen;
3492
  char*   sql;
3493
} SMAlterEncryptKeyReq;
3494

3495
int32_t tSerializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3496
int32_t tDeserializeSMAlterEncryptKeyReq(void* buf, int32_t bufLen, SMAlterEncryptKeyReq* pReq);
3497
void    tFreeSMAlterEncryptKeyReq(SMAlterEncryptKeyReq* pReq);
3498

3499
typedef struct {
3500
  char    config[TSDB_DNODE_CONFIG_LEN];
3501
  char    value[TSDB_DNODE_VALUE_LEN];
3502
  int32_t version;
3503
} SDCfgDnodeReq;
3504

3505
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3506
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3507

3508
typedef struct {
3509
  int32_t dnodeId;
3510
  int32_t sqlLen;
3511
  char*   sql;
3512
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3513
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3514

3515
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3516
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3517

3518
typedef struct {
3519
  int32_t nodeId;
3520
  SEpSet  epSet;
3521
} SNodeEpSet;
3522

3523
typedef struct {
3524
  int32_t    snodeId;
3525
  SNodeEpSet leaders[2];
3526
  SNodeEpSet replica;
3527
  int32_t    sqlLen;
3528
  char*      sql;
3529
} SDCreateSnodeReq;
3530

3531
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3532
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3533
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3534

3535
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3536
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3537
typedef struct {
3538
  int8_t   replica;
3539
  SReplica replicas[TSDB_MAX_REPLICA];
3540
  int8_t   learnerReplica;
3541
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3542
  int64_t  lastIndex;
3543
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3544

3545
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3546
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3547

3548
typedef struct {
3549
  int32_t urlLen;
3550
  int32_t sqlLen;
3551
  char*   url;
3552
  char*   sql;
3553
} SMCreateAnodeReq;
3554

3555
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3556
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3557
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3558

3559
typedef struct {
3560
  int32_t anodeId;
3561
  int32_t sqlLen;
3562
  char*   sql;
3563
} SMDropAnodeReq, SMUpdateAnodeReq;
3564

3565
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3566
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3567
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3568
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3569
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3570
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3571

3572
typedef struct {
3573
  int32_t dnodeId;
3574
  int32_t bnodeProto;
3575
  int32_t sqlLen;
3576
  char*   sql;
3577
} SMCreateBnodeReq, SDCreateBnodeReq;
3578

3579
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3580
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3581
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3582

3583
typedef struct {
3584
  int32_t dnodeId;
3585
  int32_t sqlLen;
3586
  char*   sql;
3587
} SMDropBnodeReq, SDDropBnodeReq;
3588

3589
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3590
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3591
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3592

3593
typedef struct {
3594
  int32_t sqlLen;
3595
  int32_t urlLen;
3596
  int32_t userLen;
3597
  int32_t passLen;
3598
  int32_t passIsMd5;
3599
  char*   sql;
3600
  char*   url;
3601
  char*   user;
3602
  char*   pass;
3603
} SMCreateXnodeReq, SDCreateXnodeReq;
3604

3605
int32_t tSerializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3606
int32_t tDeserializeSMCreateXnodeReq(void* buf, int32_t bufLen, SMCreateXnodeReq* pReq);
3607
void    tFreeSMCreateXnodeReq(SMCreateXnodeReq* pReq);
3608

3609
typedef struct {
3610
  int32_t xnodeId;
3611
  int32_t force;
3612
  int32_t urlLen;
3613
  int32_t sqlLen;
3614
  char*   url;
3615
  char*   sql;
3616
} SMDropXnodeReq, SMUpdateXnodeReq, SDDropXnodeReq;
3617

3618
int32_t tSerializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3619
int32_t tDeserializeSMDropXnodeReq(void* buf, int32_t bufLen, SMDropXnodeReq* pReq);
3620
void    tFreeSMDropXnodeReq(SMDropXnodeReq* pReq);
3621
int32_t tSerializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3622
int32_t tDeserializeSMUpdateXnodeReq(void* buf, int32_t bufLen, SMUpdateXnodeReq* pReq);
3623
void    tFreeSMUpdateXnodeReq(SMUpdateXnodeReq* pReq);
3624

3625
typedef struct {
3626
  int32_t xnodeId;
3627
  int32_t sqlLen;
3628
  char*   sql;
3629
} SMDrainXnodeReq;
3630
int32_t tSerializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3631
int32_t tDeserializeSMDrainXnodeReq(void* buf, int32_t bufLen, SMDrainXnodeReq* pReq);
3632
void    tFreeSMDrainXnodeReq(SMDrainXnodeReq* pReq);
3633

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

3694
typedef enum {
3695
  XNODE_TASK_SOURCE_DSN = 1,
3696
  XNODE_TASK_SOURCE_DATABASE,
3697
  XNODE_TASK_SOURCE_TOPIC,
3698
} ENodeXTaskSourceType;
3699

3700
typedef enum {
3701
  XNODE_TASK_SINK_DSN = 1,
3702
  XNODE_TASK_SINK_DATABASE,
3703
} ENodeXTaskSinkType;
3704

3705
typedef struct {
3706
  ENodeXTaskSourceType type;
3707
  CowStr               cstr;
3708
} xTaskSource;
3709
/**
3710
 * @brief Deallocate a xTaskSource object.
3711
 *
3712
 * @param source ptr
3713
 */
3714
void xFreeTaskSource(xTaskSource* source);
3715
/**
3716
 * @brief Create a xTaskSource object with cloned source string.
3717
 *
3718
 * @param sourceType: source type.
3719
 * @param len: length of source string.
3720
 * @param source: source string ptr.
3721
 * @return xTaskSource object
3722
 */
3723
xTaskSource xCreateClonedTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3724
xTaskSource xCloneTaskSourceRef(xTaskSource* source);
3725
xTaskSource xCreateTaskSource(ENodeXTaskSourceType sourceType, int32_t len, char* ptr);
3726
const char* xGetTaskSourceTypeAsStr(xTaskSource* source);
3727
const char* xGetTaskSourceStr(xTaskSource* source);
3728
int32_t     xSerializeTaskSource(SEncoder* encoder, xTaskSource* source);
3729
int32_t     xDeserializeTaskSource(SDecoder* decoder, xTaskSource* source);
3730

3731
typedef struct {
3732
  ENodeXTaskSinkType type;
3733
  CowStr             cstr;
3734
} xTaskSink;
3735
/**
3736
 * @brief Deallocate a xTaskSink object.
3737
 *
3738
 * @param sink ptr
3739
 */
3740
void xFreeTaskSink(xTaskSink* sink);
3741
/**
3742
 * @brief Create a xTaskSink object with cloned name string.
3743
 *
3744
 * @param sinkType: sink type.
3745
 * @param len: length of sink string.
3746
 * @param ptr: sink string ptr.
3747
 * @return xTaskSink object
3748
 */
3749
xTaskSink   xCreateClonedTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3750
xTaskSink   xCreateTaskSink(ENodeXTaskSinkType sinkType, int32_t len, char* ptr);
3751
xTaskSink   xCloneTaskSinkRef(xTaskSink* sink);
3752
const char* xGetTaskSinkTypeAsStr(xTaskSink* sink);
3753
const char* xGetTaskSinkStr(xTaskSink* sink);
3754
int32_t     xSerializeTaskSink(SEncoder* encoder, xTaskSink* sink);
3755
int32_t     xDeserializeTaskSink(SDecoder* decoder, xTaskSink* sink);
3756

3757
typedef struct {
3758
  int32_t via;
3759
  CowStr  parser;
3760
  // CowStr  reason;
3761
  CowStr  trigger;
3762
  CowStr  health;
3763
  int32_t optionsNum;
3764
  CowStr  options[TSDB_XNODE_TASK_OPTIONS_MAX_NUM];
3765
} xTaskOptions;
3766
/**
3767
 * @brief Deallocate a xTaskOptions object.
3768
 *
3769
 * @param options ptr
3770
 */
3771
void    xFreeTaskOptions(xTaskOptions* options);
3772
void    printXnodeTaskOptions(xTaskOptions* options);
3773
int32_t xSerializeTaskOptions(SEncoder* encoder, xTaskOptions* options);
3774
int32_t xDeserializeTaskOptions(SDecoder* decoder, xTaskOptions* options);
3775

3776
typedef struct {
3777
  int32_t sqlLen;
3778
  char*   sql;
3779
  int32_t      xnodeId;
3780
  CowStr       name;
3781
  xTaskSource  source;
3782
  xTaskSink    sink;
3783
  xTaskOptions options;
3784
} SMCreateXnodeTaskReq;
3785
int32_t tSerializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3786
int32_t tDeserializeSMCreateXnodeTaskReq(void* buf, int32_t bufLen, SMCreateXnodeTaskReq* pReq);
3787
void    tFreeSMCreateXnodeTaskReq(SMCreateXnodeTaskReq* pReq);
3788

3789
typedef struct {
3790
  int32_t     tid;
3791
  CowStr      name;
3792
  int32_t     via;
3793
  int32_t     xnodeId;
3794
  CowStr      status;
3795
  xTaskSource source;
3796
  xTaskSink   sink;
3797
  CowStr      parser;
3798
  CowStr      reason;
3799
  CowStr      updateName;
3800
  int32_t     sqlLen;
3801
  char*       sql;
3802
} SMUpdateXnodeTaskReq;
3803
int32_t tSerializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3804
int32_t tDeserializeSMUpdateXnodeTaskReq(void* buf, int32_t bufLen, SMUpdateXnodeTaskReq* pReq);
3805
void    tFreeSMUpdateXnodeTaskReq(SMUpdateXnodeTaskReq* pReq);
3806

3807
typedef struct {
3808
  int32_t tid;
3809
  bool    force;
3810
  int32_t nameLen;
3811
  int32_t sqlLen;
3812
  char*   name;
3813
  char*   sql;
3814
} SMDropXnodeTaskReq;
3815
int32_t tSerializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3816
int32_t tDeserializeSMDropXnodeTaskReq(void* buf, int32_t bufLen, SMDropXnodeTaskReq* pReq);
3817
void    tFreeSMDropXnodeTaskReq(SMDropXnodeTaskReq* pReq);
3818

3819
typedef struct {
3820
  int32_t tid;
3821
  CowStr  name;
3822
  int32_t sqlLen;
3823
  char*   sql;
3824
} SMStartXnodeTaskReq, SMStopXnodeTaskReq;
3825
int32_t tSerializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3826
int32_t tDeserializeSMStartXnodeTaskReq(void* buf, int32_t bufLen, SMStartXnodeTaskReq* pReq);
3827
void    tFreeSMStartXnodeTaskReq(SMStartXnodeTaskReq* pReq);
3828

3829
int32_t tSerializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3830
int32_t tDeserializeSMStopXnodeTaskReq(void* buf, int32_t bufLen, SMStopXnodeTaskReq* pReq);
3831
void    tFreeSMStopXnodeTaskReq(SMStopXnodeTaskReq* pReq);
3832

3833
typedef struct {
3834
  int32_t tid;
3835
  int32_t via;
3836
  int32_t xnodeId;
3837
  CowStr  status;
3838
  int32_t configLen;
3839
  int32_t reasonLen;
3840
  int32_t sqlLen;
3841
  char*   config;
3842
  char*   reason;
3843
  char*   sql;
3844
} SMCreateXnodeJobReq;
3845
int32_t tSerializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3846
int32_t tDeserializeSMCreateXnodeJobReq(void* buf, int32_t bufLen, SMCreateXnodeJobReq* pReq);
3847
void    tFreeSMCreateXnodeJobReq(SMCreateXnodeJobReq* pReq);
3848

3849
typedef struct {
3850
  int32_t jid;
3851
  int32_t via;
3852
  int32_t xnodeId;
3853
  CowStr  status;
3854
  int32_t configLen;
3855
  int32_t reasonLen;
3856
  int32_t sqlLen;
3857
  char*   config;
3858
  char*   reason;
3859
  char*   sql;
3860
} SMUpdateXnodeJobReq;
3861
int32_t tSerializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3862
int32_t tDeserializeSMUpdateXnodeJobReq(void* buf, int32_t bufLen, SMUpdateXnodeJobReq* pReq);
3863
void    tFreeSMUpdateXnodeJobReq(SMUpdateXnodeJobReq* pReq);
3864

3865
typedef struct {
3866
  int32_t jid;
3867
  int32_t xnodeId;
3868
  int32_t sqlLen;
3869
  char*   sql;
3870
} SMRebalanceXnodeJobReq;
3871
int32_t tSerializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3872
int32_t tDeserializeSMRebalanceXnodeJobReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobReq* pReq);
3873
void    tFreeSMRebalanceXnodeJobReq(SMRebalanceXnodeJobReq* pReq);
3874

3875
typedef struct {
3876
  CowStr  ast;
3877
  int32_t sqlLen;
3878
  char*   sql;
3879
} SMRebalanceXnodeJobsWhereReq;
3880
int32_t tSerializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3881
int32_t tDeserializeSMRebalanceXnodeJobsWhereReq(void* buf, int32_t bufLen, SMRebalanceXnodeJobsWhereReq* pReq);
3882
void    tFreeSMRebalanceXnodeJobsWhereReq(SMRebalanceXnodeJobsWhereReq* pReq);
3883

3884
typedef struct {
3885
  int32_t jid;
3886
  int32_t tid;
3887
  int32_t sqlLen;
3888
  char*   sql;
3889
} SMDropXnodeJobReq;
3890
int32_t tSerializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3891
int32_t tDeserializeSMDropXnodeJobReq(void* buf, int32_t bufLen, SMDropXnodeJobReq* pReq);
3892
void    tFreeSMDropXnodeJobReq(SMDropXnodeJobReq* pReq);
3893

3894
typedef struct {
3895
  int32_t vgId;
3896
  int32_t hbSeq;
3897
} SVArbHbReqMember;
3898

3899
typedef struct {
3900
  int32_t dnodeId;
3901
  char*   arbToken;
3902
  int64_t arbTerm;
3903
  SArray* hbMembers;  // SVArbHbReqMember
3904
} SVArbHeartBeatReq;
3905

3906
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3907
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3908
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3909

3910
typedef struct {
3911
  int32_t vgId;
3912
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3913
  int32_t hbSeq;
3914
} SVArbHbRspMember;
3915

3916
typedef struct {
3917
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3918
  int32_t dnodeId;
3919
  SArray* hbMembers;  // SVArbHbRspMember
3920
} SVArbHeartBeatRsp;
3921

3922
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3923
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3924
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3925

3926
typedef struct {
3927
  char*   arbToken;
3928
  int64_t arbTerm;
3929
  char*   member0Token;
3930
  char*   member1Token;
3931
} SVArbCheckSyncReq;
3932

3933
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3934
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3935
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3936

3937
typedef struct {
3938
  char*   arbToken;
3939
  char*   member0Token;
3940
  char*   member1Token;
3941
  int32_t vgId;
3942
  int32_t errCode;
3943
} SVArbCheckSyncRsp;
3944

3945
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3946
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3947
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3948

3949
typedef struct {
3950
  char*   arbToken;
3951
  int64_t arbTerm;
3952
  char*   memberToken;
3953
  int8_t  force;
3954
} SVArbSetAssignedLeaderReq;
3955

3956
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3957
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3958
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3959

3960
typedef struct {
3961
  char*   arbToken;
3962
  char*   memberToken;
3963
  int32_t vgId;
3964
} SVArbSetAssignedLeaderRsp;
3965

3966
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3967
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3968
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3969

3970
typedef struct {
3971
  int32_t dnodeId;
3972
  char*   token;
3973
} SMArbUpdateGroupMember;
3974

3975
typedef struct {
3976
  int32_t dnodeId;
3977
  char*   token;
3978
  int8_t  acked;
3979
} SMArbUpdateGroupAssigned;
3980

3981
typedef struct {
3982
  int32_t                  vgId;
3983
  int64_t                  dbUid;
3984
  SMArbUpdateGroupMember   members[2];
3985
  int8_t                   isSync;
3986
  int8_t                   assignedAcked;
3987
  SMArbUpdateGroupAssigned assignedLeader;
3988
  int64_t                  version;
3989
  int32_t                  code;
3990
  int64_t                  updateTimeMs;
3991
} SMArbUpdateGroup;
3992

3993
typedef struct {
3994
  SArray* updateArray;  // SMArbUpdateGroup
3995
} SMArbUpdateGroupBatchReq;
3996

3997
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3998
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3999
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
4000

4001
typedef struct {
4002
  char queryStrId[TSDB_QUERY_ID_LEN];
4003
} SKillQueryReq;
4004

4005
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4006
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
4007

4008
typedef struct {
4009
  uint32_t connId;
4010
} SKillConnReq;
4011

4012
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4013
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
4014

4015
typedef struct {
4016
  int32_t transId;
4017
} SKillTransReq;
4018

4019
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4020
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
4021

4022
typedef struct {
4023
  int32_t useless;  // useless
4024
  int32_t sqlLen;
4025
  char*   sql;
4026
} SBalanceVgroupReq;
4027

4028
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4029
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
4030
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
4031

4032
typedef struct {
4033
  int32_t useless;  // useless
4034
  int32_t sqlLen;
4035
  char*   sql;
4036
} SAssignLeaderReq;
4037

4038
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4039
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
4040
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
4041
typedef struct {
4042
  int32_t vgId1;
4043
  int32_t vgId2;
4044
} SMergeVgroupReq;
4045

4046
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4047
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
4048

4049
typedef struct {
4050
  int32_t vgId;
4051
  int32_t dnodeId1;
4052
  int32_t dnodeId2;
4053
  int32_t dnodeId3;
4054
  int32_t sqlLen;
4055
  char*   sql;
4056
} SRedistributeVgroupReq;
4057

4058
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4059
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
4060
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
4061

4062
typedef struct {
4063
  int32_t reserved;
4064
  int32_t vgId;
4065
  int32_t sqlLen;
4066
  char*   sql;
4067
  char    db[TSDB_DB_FNAME_LEN];
4068
} SBalanceVgroupLeaderReq;
4069

4070
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4071
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
4072
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
4073

4074
typedef struct {
4075
  int32_t vgId;
4076
} SForceBecomeFollowerReq;
4077

4078
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4079
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
4080

4081
typedef struct {
4082
  int32_t vgId;
4083
  bool    force;
4084
} SSplitVgroupReq;
4085

4086
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4087
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
4088

4089
typedef struct {
4090
  char user[TSDB_USER_LEN];
4091
  char spi;
4092
  char encrypt;
4093
  char secret[TSDB_PASSWORD_LEN];
4094
  char ckey[TSDB_PASSWORD_LEN];
4095
} SAuthReq, SAuthRsp;
4096

4097
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4098
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
4099

4100
typedef struct {
4101
  int32_t statusCode;
4102
  char    details[1024];
4103
} SServerStatusRsp;
4104

4105
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4106
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
4107

4108
/**
4109
 * The layout of the query message payload is as following:
4110
 * +--------------------+---------------------------------+
4111
 * |Sql statement       | Physical plan                   |
4112
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
4113
 * +--------------------+---------------------------------+
4114
 */
4115
typedef struct SSubQueryMsg {
4116
  SMsgHead header;
4117
  uint64_t sId;
4118
  uint64_t queryId;
4119
  uint64_t clientId;
4120
  uint64_t taskId;
4121
  int64_t  refId;
4122
  int32_t  execId;
4123
  int32_t  msgMask;
4124
  int8_t   taskType;
4125
  int8_t   explain;
4126
  int8_t   needFetch;
4127
  int8_t   compress;
4128
  uint32_t sqlLen;
4129
  char*    sql;
4130
  uint32_t msgLen;
4131
  char*    msg;
4132
  SArray*  subEndPoints;  // subJobs's endpoints, element is SDownstreamSourceNode*
4133
} SSubQueryMsg;
4134

4135
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4136
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
4137
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
4138

4139
typedef struct {
4140
  SMsgHead header;
4141
  uint64_t sId;
4142
  uint64_t queryId;
4143
  uint64_t taskId;
4144
} SSinkDataReq;
4145

4146
typedef struct {
4147
  SMsgHead header;
4148
  uint64_t sId;
4149
  uint64_t queryId;
4150
  uint64_t clientId;
4151
  uint64_t taskId;
4152
  int32_t  execId;
4153
} SQueryContinueReq;
4154

4155
typedef struct {
4156
  SMsgHead header;
4157
  uint64_t sId;
4158
  uint64_t queryId;
4159
  uint64_t taskId;
4160
} SResReadyReq;
4161

4162
typedef struct {
4163
  int32_t code;
4164
  char    tbFName[TSDB_TABLE_FNAME_LEN];
4165
  int32_t sversion;
4166
  int32_t tversion;
4167
} SResReadyRsp;
4168

4169
typedef struct SOperatorParam {
4170
  int32_t opType;
4171
  int32_t downstreamIdx;
4172
  void*   value;
4173
  SArray* pChildren;  // SArray<SOperatorParam*>
4174
  bool    reUse;
4175
} SOperatorParam;
4176

4177
typedef struct SColIdNameKV {
4178
  col_id_t colId;
4179
  char     colName[TSDB_COL_NAME_LEN];
4180
} SColIdNameKV;
4181

4182
#define COL_MASK_ON   ((int8_t)0x1)
4183
#define IS_MASK_ON(c) (((c)->flags & 0x01) == COL_MASK_ON)
4184
#define COL_SET_MASK_ON(c)     \
4185
  do {                         \
4186
    (c)->flags |= COL_MASK_ON; \
4187
  } while (0)
4188

4189
typedef struct SColNameFlag {
4190
  col_id_t colId;
4191
  char     colName[TSDB_COL_NAME_LEN];
4192
  int8_t   flags;  // 0x01: COL_MASK_ON
4193
} SColNameFlag;
4194

4195
typedef struct SColIdPair {
4196
  col_id_t  vtbColId;
4197
  col_id_t  orgColId;
4198
  SDataType type;
4199
} SColIdPair;
4200

4201
typedef struct SColIdSlotIdPair {
4202
  int32_t  vtbSlotId;
4203
  col_id_t orgColId;
4204
} SColIdSlotIdPair;
4205

4206
typedef struct SOrgTbInfo {
4207
  int32_t vgId;
4208
  char    tbName[TSDB_TABLE_FNAME_LEN];
4209
  SArray* colMap;  // SArray<SColIdNameKV>
4210
} SOrgTbInfo;
4211

4212
void destroySOrgTbInfo(void *info);
4213

4214
typedef enum {
4215
  DYN_TYPE_STB_JOIN = 1,
4216
  DYN_TYPE_VSTB_SINGLE_SCAN,
4217
  DYN_TYPE_VSTB_BATCH_SCAN,
4218
} ETableScanDynType;
4219

4220
typedef struct STableScanOperatorParam {
4221
  bool              tableSeq;
4222
  bool              isNewParam;
4223
  uint64_t          groupid;
4224
  SArray*           pUidList;
4225
  SOrgTbInfo*       pOrgTbInfo;
4226
  SArray*           pBatchTbInfo;  // SArray<SOrgTbInfo>
4227
  SArray*           pTagList;
4228
  STimeWindow       window;
4229
  ETableScanDynType type;
4230
} STableScanOperatorParam;
4231

4232
typedef struct STagScanOperatorParam {
4233
  tb_uid_t vcUid;
4234
} STagScanOperatorParam;
4235

4236
typedef struct SVTableScanOperatorParam {
4237
  uint64_t        uid;
4238
  STimeWindow     window;
4239
  SOperatorParam* pTagScanOp;
4240
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
4241
} SVTableScanOperatorParam;
4242

4243
typedef struct SMergeOperatorParam {
4244
  int32_t         winNum;
4245
} SMergeOperatorParam;
4246

4247
typedef struct SAggOperatorParam {
4248
  bool            needCleanRes;
4249
} SAggOperatorParam;
4250

4251
typedef struct SExternalWindowOperatorParam {
4252
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
4253
} SExternalWindowOperatorParam;
4254

4255
typedef struct SDynQueryCtrlOperatorParam {
4256
  STimeWindow    window;
4257
} SDynQueryCtrlOperatorParam;
4258

4259
struct SStreamRuntimeFuncInfo;
4260
typedef struct {
4261
  SMsgHead        header;
4262
  uint64_t        sId;
4263
  uint64_t        queryId;
4264
  uint64_t        clientId;
4265
  uint64_t        taskId;
4266
  int32_t         execId;
4267
  SOperatorParam* pOpParam;
4268

4269
  // used for new-stream
4270
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
4271
  bool                           reset;
4272
  bool                           dynTbname;
4273
  // used for new-stream
4274
} SResFetchReq;
4275

4276
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
4277
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
4278
void    tDestroySResFetchReq(SResFetchReq* pReq);
4279
typedef struct {
4280
  SMsgHead header;
4281
  uint64_t clientId;
4282
} SSchTasksStatusReq;
4283

4284
typedef struct {
4285
  uint64_t queryId;
4286
  uint64_t clientId;
4287
  uint64_t taskId;
4288
  int64_t  refId;
4289
  int32_t  subJobId;
4290
  int32_t  execId;
4291
  int8_t   status;
4292
} STaskStatus;
4293

4294
typedef struct {
4295
  int64_t refId;
4296
  SArray* taskStatus;  // SArray<STaskStatus>
4297
} SSchedulerStatusRsp;
4298

4299
typedef struct {
4300
  uint64_t queryId;
4301
  uint64_t taskId;
4302
  int8_t   action;
4303
} STaskAction;
4304

4305
typedef struct SQueryNodeEpId {
4306
  int32_t nodeId;  // vgId or qnodeId
4307
  SEp     ep;
4308
} SQueryNodeEpId;
4309

4310
typedef struct {
4311
  SMsgHead       header;
4312
  uint64_t       clientId;
4313
  SQueryNodeEpId epId;
4314
  SArray*        taskAction;  // SArray<STaskAction>
4315
} SSchedulerHbReq;
4316

4317
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4318
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
4319
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
4320

4321
typedef struct {
4322
  SQueryNodeEpId epId;
4323
  SArray*        taskStatus;  // SArray<STaskStatus>
4324
} SSchedulerHbRsp;
4325

4326
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4327
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
4328
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
4329

4330
typedef struct {
4331
  SMsgHead header;
4332
  uint64_t sId;
4333
  uint64_t queryId;
4334
  uint64_t clientId;
4335
  uint64_t taskId;
4336
  int64_t  refId;
4337
  int32_t  execId;
4338
} STaskCancelReq;
4339

4340
typedef struct {
4341
  int32_t code;
4342
} STaskCancelRsp;
4343

4344
typedef struct {
4345
  SMsgHead header;
4346
  uint64_t sId;
4347
  uint64_t queryId;
4348
  uint64_t clientId;
4349
  uint64_t taskId;
4350
  int64_t  refId;
4351
  int32_t  execId;
4352
} STaskDropReq;
4353

4354
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4355
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
4356

4357
typedef enum {
4358
  TASK_NOTIFY_FINISHED = 1,
4359
} ETaskNotifyType;
4360

4361
typedef struct {
4362
  SMsgHead        header;
4363
  uint64_t        sId;
4364
  uint64_t        queryId;
4365
  uint64_t        clientId;
4366
  uint64_t        taskId;
4367
  int64_t         refId;
4368
  int32_t         execId;
4369
  ETaskNotifyType type;
4370
} STaskNotifyReq;
4371

4372
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4373
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
4374

4375
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4376
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
4377

4378
typedef struct {
4379
  int32_t code;
4380
} STaskDropRsp;
4381

4382
#define STREAM_TRIGGER_AT_ONCE                 1
4383
#define STREAM_TRIGGER_WINDOW_CLOSE            2
4384
#define STREAM_TRIGGER_MAX_DELAY               3
4385
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
4386
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
4387

4388
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
4389
#define STREAM_FILL_HISTORY_ON        1
4390
#define STREAM_FILL_HISTORY_OFF       0
4391
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
4392
#define STREAM_DEFAULT_IGNORE_UPDATE  1
4393
#define STREAM_CREATE_STABLE_TRUE     1
4394
#define STREAM_CREATE_STABLE_FALSE    0
4395

4396
typedef struct SVgroupVer {
4397
  int32_t vgId;
4398
  int64_t ver;
4399
} SVgroupVer;
4400

4401
typedef struct STaskNotifyEventStat {
4402
  int64_t notifyEventAddTimes;     // call times of add function
4403
  int64_t notifyEventAddElems;     // elements added by add function
4404
  double  notifyEventAddCostSec;   // time cost of add function
4405
  int64_t notifyEventPushTimes;    // call times of push function
4406
  int64_t notifyEventPushElems;    // elements pushed by push function
4407
  double  notifyEventPushCostSec;  // time cost of push function
4408
  int64_t notifyEventPackTimes;    // call times of pack function
4409
  int64_t notifyEventPackElems;    // elements packed by pack function
4410
  double  notifyEventPackCostSec;  // time cost of pack function
4411
  int64_t notifyEventSendTimes;    // call times of send function
4412
  int64_t notifyEventSendElems;    // elements sent by send function
4413
  double  notifyEventSendCostSec;  // time cost of send function
4414
  int64_t notifyEventHoldElems;    // elements hold due to watermark
4415
} STaskNotifyEventStat;
4416

4417
enum {
4418
  TOPIC_SUB_TYPE__DB = 1,
4419
  TOPIC_SUB_TYPE__TABLE,
4420
  TOPIC_SUB_TYPE__COLUMN,
4421
};
4422

4423
#define DEFAULT_MAX_POLL_INTERVAL  300000
4424
#define DEFAULT_SESSION_TIMEOUT    12000
4425
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
4426
#define DEFAULT_MIN_POLL_ROWS      4096
4427

4428
typedef struct {
4429
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
4430
  int8_t igExists;
4431
  int8_t subType;
4432
  int8_t withMeta;
4433
  char*  sql;
4434
  char   subDbName[TSDB_DB_FNAME_LEN];
4435
  char*  ast;
4436
  char   subStbName[TSDB_TABLE_FNAME_LEN];
4437
  int8_t reload;
4438
} SCMCreateTopicReq;
4439

4440
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
4441
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
4442
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
4443

4444
typedef struct {
4445
  int64_t consumerId;
4446
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
4447

4448
typedef struct {
4449
  int64_t consumerId;
4450
  char    cgroup[TSDB_CGROUP_LEN];
4451
  char    clientId[TSDB_CLIENT_ID_LEN];
4452
  char    user[TSDB_USER_LEN];
4453
  char    fqdn[TSDB_FQDN_LEN];
4454
  SArray* topicNames;  // SArray<char**>
4455

4456
  int8_t  withTbName;
4457
  int8_t  autoCommit;
4458
  int32_t autoCommitInterval;
4459
  int8_t  resetOffsetCfg;
4460
  int8_t  enableReplay;
4461
  int8_t  enableBatchMeta;
4462
  int32_t sessionTimeoutMs;
4463
  int32_t maxPollIntervalMs;
4464
} SCMSubscribeReq;
4465

4466
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
4467
  int32_t tlen = 0;
642,914✔
4468
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
642,914✔
4469
  tlen += taosEncodeString(buf, pReq->cgroup);
642,914✔
4470
  tlen += taosEncodeString(buf, pReq->clientId);
642,914✔
4471

4472
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
642,914✔
4473
  tlen += taosEncodeFixedI32(buf, topicNum);
642,914✔
4474

4475
  for (int32_t i = 0; i < topicNum; i++) {
892,790✔
4476
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
499,752✔
4477
  }
4478

4479
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
642,914✔
4480
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
642,914✔
4481
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
642,914✔
4482
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
642,914✔
4483
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
642,914✔
4484
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
642,914✔
4485
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
642,914✔
4486
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
642,914✔
4487
  tlen += taosEncodeString(buf, pReq->user);
642,914✔
4488
  tlen += taosEncodeString(buf, pReq->fqdn);
642,914✔
4489

4490
  return tlen;
642,914✔
4491
}
4492

4493
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
4494
  void* start = buf;
346,163✔
4495
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
346,163✔
4496
  buf = taosDecodeStringTo(buf, pReq->cgroup);
346,163✔
4497
  buf = taosDecodeStringTo(buf, pReq->clientId);
346,163✔
4498

4499
  int32_t topicNum = 0;
346,163✔
4500
  buf = taosDecodeFixedI32(buf, &topicNum);
346,163✔
4501

4502
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
346,163✔
4503
  if (pReq->topicNames == NULL) {
346,163✔
UNCOV
4504
    return terrno;
×
4505
  }
4506
  for (int32_t i = 0; i < topicNum; i++) {
500,913✔
4507
    char* name = NULL;
154,750✔
4508
    buf = taosDecodeString(buf, &name);
154,750✔
4509
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
309,500✔
UNCOV
4510
      return terrno;
×
4511
    }
4512
  }
4513

4514
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
346,163✔
4515
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
346,163✔
4516
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
346,163✔
4517
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
346,163✔
4518
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
346,163✔
4519
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
346,163✔
4520
  if ((char*)buf - (char*)start < len) {
346,163✔
4521
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
346,163✔
4522
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
346,163✔
4523
    buf = taosDecodeStringTo(buf, pReq->user);
346,163✔
4524
    buf = taosDecodeStringTo(buf, pReq->fqdn);
692,326✔
4525
  } else {
UNCOV
4526
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
4527
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
4528
  }
4529

4530
  return 0;
346,163✔
4531
}
4532

4533
typedef struct {
4534
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
4535
  SArray* removedConsumers;  // SArray<int64_t>
4536
  SArray* newConsumers;      // SArray<int64_t>
4537
} SMqRebInfo;
4538

4539
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
4540
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
325,734✔
4541
  if (pRebInfo == NULL) {
325,734✔
UNCOV
4542
    return NULL;
×
4543
  }
4544
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
325,734✔
4545
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
325,734✔
4546
  if (pRebInfo->removedConsumers == NULL) {
325,734✔
UNCOV
4547
    goto _err;
×
4548
  }
4549
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
325,734✔
4550
  if (pRebInfo->newConsumers == NULL) {
325,734✔
4551
    goto _err;
×
4552
  }
4553
  return pRebInfo;
325,734✔
UNCOV
4554
_err:
×
UNCOV
4555
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
4556
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
4557
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
4558
  return NULL;
×
4559
}
4560

4561
typedef struct {
4562
  int64_t streamId;
4563
  int64_t checkpointId;
4564
  char    streamName[TSDB_STREAM_FNAME_LEN];
4565
} SMStreamDoCheckpointMsg;
4566

4567
typedef struct {
4568
  int64_t status;
4569
} SMVSubscribeRsp;
4570

4571
typedef struct {
4572
  char    name[TSDB_TOPIC_FNAME_LEN];
4573
  int8_t  igNotExists;
4574
  int32_t sqlLen;
4575
  char*   sql;
4576
  int8_t  force;
4577
} SMDropTopicReq;
4578

4579
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4580
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
4581
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
4582

4583
typedef struct {
4584
  char    name[TSDB_TOPIC_FNAME_LEN];
4585
  int8_t  igNotExists;
4586
  int32_t sqlLen;
4587
  char*   sql;
4588
} SMReloadTopicReq;
4589

4590
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4591
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
4592
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
4593

4594
typedef struct {
4595
  char   topic[TSDB_TOPIC_FNAME_LEN];
4596
  char   cgroup[TSDB_CGROUP_LEN];
4597
  int8_t igNotExists;
4598
  int8_t force;
4599
} SMDropCgroupReq;
4600

4601
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4602
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
4603

4604
typedef struct {
4605
  int8_t reserved;
4606
} SMDropCgroupRsp;
4607

4608
typedef struct {
4609
  char    name[TSDB_TABLE_FNAME_LEN];
4610
  int8_t  alterType;
4611
  SSchema schema;
4612
} SAlterTopicReq;
4613

4614
typedef struct {
4615
  SMsgHead head;
4616
  char     name[TSDB_TABLE_FNAME_LEN];
4617
  int64_t  tuid;
4618
  int32_t  sverson;
4619
  int32_t  execLen;
4620
  char*    executor;
4621
  int32_t  sqlLen;
4622
  char*    sql;
4623
} SDCreateTopicReq;
4624

4625
typedef struct {
4626
  SMsgHead head;
4627
  char     name[TSDB_TABLE_FNAME_LEN];
4628
  int64_t  tuid;
4629
} SDDropTopicReq;
4630

4631
typedef struct {
4632
  char*      name;
4633
  int64_t    uid;
4634
  int64_t    interval[2];
4635
  int8_t     intervalUnit;
4636
  int16_t    nFuncs;
4637
  col_id_t*  funcColIds;  // column ids specified by user
4638
  func_id_t* funcIds;     // function ids specified by user
4639
} SRSmaParam;
4640

4641
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4642
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4643

4644
// TDMT_VND_CREATE_STB ==============
4645
typedef struct SVCreateStbReq {
4646
  char*           name;
4647
  tb_uid_t        suid;
4648
  int8_t          rollup;
4649
  SSchemaWrapper  schemaRow;
4650
  SSchemaWrapper  schemaTag;
4651
  SRSmaParam      rsmaParam;
4652
  int32_t         alterOriDataLen;
4653
  void*           alterOriData;
4654
  int8_t          source;
4655
  int8_t          colCmpred;
4656
  SColCmprWrapper colCmpr;
4657
  int64_t         keep;
4658
  int64_t         ownerId;
4659
  SExtSchema*     pExtSchemas;
4660
  int8_t          virtualStb;
4661
} SVCreateStbReq;
4662

4663
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4664
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4665

4666
// TDMT_VND_DROP_STB ==============
4667
typedef struct SVDropStbReq {
4668
  char*    name;
4669
  tb_uid_t suid;
4670
} SVDropStbReq;
4671

4672
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4673
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4674

4675
// TDMT_VND_CREATE_TABLE ==============
4676
#define TD_CREATE_IF_NOT_EXISTS       0x1
4677
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4678
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4679
typedef struct SVCreateTbReq {
4680
  int32_t  flags;
4681
  char*    name;
4682
  tb_uid_t uid;
4683
  int64_t  btime;
4684
  int32_t  ttl;
4685
  int32_t  commentLen;
4686
  char*    comment;
4687
  int8_t   type;
4688
  union {
4689
    struct {
4690
      char*    stbName;  // super table name
4691
      uint8_t  tagNum;
4692
      tb_uid_t suid;
4693
      SArray*  tagName;
4694
      uint8_t* pTag;
4695
    } ctb;
4696
    struct {
4697
      SSchemaWrapper schemaRow;
4698
    } ntb;
4699
  };
4700
  int32_t         sqlLen;
4701
  char*           sql;
4702
  SColCmprWrapper colCmpr;
4703
  SExtSchema*     pExtSchemas;
4704
  SColRefWrapper  colRef;  // col reference for virtual table
4705
} SVCreateTbReq;
4706

4707
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4708
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4709
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4710
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4711

4712
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4713
  if (NULL == req) {
2,147,483,647✔
4714
    return;
2,091,813,824✔
4715
  }
4716

4717
  taosMemoryFreeClear(req->sql);
71,778,993✔
4718
  taosMemoryFreeClear(req->name);
71,779,114✔
4719
  taosMemoryFreeClear(req->comment);
71,775,547✔
4720
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
71,775,137✔
4721
    taosMemoryFreeClear(req->ctb.pTag);
53,371,350✔
4722
    taosMemoryFreeClear(req->ctb.stbName);
53,367,839✔
4723
    taosArrayDestroy(req->ctb.tagName);
53,374,057✔
4724
    req->ctb.tagName = NULL;
53,350,101✔
4725
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
18,405,242✔
4726
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
18,405,272✔
4727
  }
4728
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
71,767,834✔
4729
  taosMemoryFreeClear(req->pExtSchemas);
71,779,313✔
4730
  taosMemoryFreeClear(req->colRef.pColRef);
71,778,483✔
4731
}
4732

4733
typedef struct {
4734
  int32_t nReqs;
4735
  union {
4736
    SVCreateTbReq* pReqs;
4737
    SArray*        pArray;
4738
  };
4739
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4740
} SVCreateTbBatchReq;
4741

4742
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4743
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4744
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4745

4746
typedef struct {
4747
  int32_t        code;
4748
  STableMetaRsp* pMeta;
4749
} SVCreateTbRsp, SVUpdateTbRsp;
4750

4751
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4752
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4753
void tFreeSVCreateTbRsp(void* param);
4754

4755
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4756
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4757

4758
typedef struct {
4759
  int32_t nRsps;
4760
  union {
4761
    SVCreateTbRsp* pRsps;
4762
    SArray*        pArray;
4763
  };
4764
} SVCreateTbBatchRsp;
4765

4766
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4767
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4768

4769
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4770
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4771

4772
// TDMT_VND_DROP_TABLE =================
4773
typedef struct {
4774
  char*    name;
4775
  uint64_t suid;  // for tmq in wal format
4776
  int64_t  uid;
4777
  int8_t   igNotExists;
4778
  int8_t   isVirtual;
4779
} SVDropTbReq;
4780

4781
typedef struct {
4782
  int32_t code;
4783
} SVDropTbRsp;
4784

4785
typedef struct {
4786
  int32_t nReqs;
4787
  union {
4788
    SVDropTbReq* pReqs;
4789
    SArray*      pArray;
4790
  };
4791
} SVDropTbBatchReq;
4792

4793
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4794
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4795

4796
typedef struct {
4797
  int32_t nRsps;
4798
  union {
4799
    SVDropTbRsp* pRsps;
4800
    SArray*      pArray;
4801
  };
4802
} SVDropTbBatchRsp;
4803

4804
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4805
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4806

4807
// TDMT_VND_ALTER_TABLE =====================
4808
typedef struct SMultiTagUpateVal {
4809
  char*    tagName;
4810
  int32_t  colId;
4811
  int8_t   tagType;
4812
  int8_t   tagFree;
4813
  uint32_t nTagVal;
4814
  uint8_t* pTagVal;
4815
  int8_t   isNull;
4816
  SArray*  pTagArray;
4817
} SMultiTagUpateVal;
4818
typedef struct SVAlterTbReq {
4819
  char*   tbName;
4820
  int8_t  action;
4821
  char*   colName;
4822
  int32_t colId;
4823
  // TSDB_ALTER_TABLE_ADD_COLUMN
4824
  int8_t  type;
4825
  int8_t  flags;
4826
  int32_t bytes;
4827
  // TSDB_ALTER_TABLE_DROP_COLUMN
4828
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4829
  int8_t   colModType;
4830
  int32_t  colModBytes;
4831
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4832
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4833
  int8_t   isNull;
4834
  int8_t   tagType;
4835
  int8_t   tagFree;
4836
  uint32_t nTagVal;
4837
  uint8_t* pTagVal;
4838
  SArray*  pTagArray;
4839
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4840
  int8_t   updateTTL;
4841
  int32_t  newTTL;
4842
  int32_t  newCommentLen;
4843
  char*    newComment;
4844
  int64_t  ctimeMs;    // fill by vnode
4845
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4846
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4847
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4848
  // for Add column
4849
  STypeMod typeMod;
4850
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4851
  char* refDbName;
4852
  char* refTbName;
4853
  char* refColName;
4854
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4855
} SVAlterTbReq;
4856

4857
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4858
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4859
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4860
void    tfreeMultiTagUpateVal(void* pMultiTag);
4861

4862
typedef struct {
4863
  int32_t        code;
4864
  STableMetaRsp* pMeta;
4865
} SVAlterTbRsp;
4866

4867
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4868
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4869
// ======================
4870

4871
typedef struct {
4872
  SMsgHead head;
4873
  int64_t  uid;
4874
  int32_t  tid;
4875
  int16_t  tversion;
4876
  int16_t  colId;
4877
  int8_t   type;
4878
  int16_t  bytes;
4879
  int32_t  tagValLen;
4880
  int16_t  numOfTags;
4881
  int32_t  schemaLen;
4882
  char     data[];
4883
} SUpdateTagValReq;
4884

4885
typedef struct {
4886
  SMsgHead head;
4887
} SUpdateTagValRsp;
4888

4889
typedef struct {
4890
  SMsgHead head;
4891
} SVShowTablesReq;
4892

4893
typedef struct {
4894
  SMsgHead head;
4895
  int32_t  id;
4896
} SVShowTablesFetchReq;
4897

4898
typedef struct {
4899
  int64_t useconds;
4900
  int8_t  completed;  // all results are returned to client
4901
  int8_t  precision;
4902
  int8_t  compressed;
4903
  int32_t compLen;
4904
  int32_t numOfRows;
4905
  char    data[];
4906
} SVShowTablesFetchRsp;
4907

4908
typedef struct {
4909
  int64_t consumerId;
4910
  int32_t epoch;
4911
  char    cgroup[TSDB_CGROUP_LEN];
4912
} SMqAskEpReq;
4913

4914
typedef struct {
4915
  int32_t key;
4916
  int32_t valueLen;
4917
  void*   value;
4918
} SKv;
4919

4920
typedef struct {
4921
  int64_t tscRid;
4922
  int8_t  connType;
4923
} SClientHbKey;
4924

4925
typedef struct {
4926
  int64_t tid;
4927
  char    status[TSDB_JOB_STATUS_LEN];
4928
} SQuerySubDesc;
4929

4930
typedef struct {
4931
  char     sql[TSDB_SHOW_SQL_LEN];
4932
  uint64_t queryId;
4933
  int64_t  useconds;
4934
  int64_t  stime;  // timestamp precision ms
4935
  int64_t  reqRid;
4936
  bool     stableQuery;
4937
  bool     isSubQuery;
4938
  char     fqdn[TSDB_FQDN_LEN];
4939
  int32_t  subPlanNum;
4940
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4941
} SQueryDesc;
4942

4943
typedef struct {
4944
  uint32_t connId;
4945
  SArray*  queryDesc;  // SArray<SQueryDesc>
4946
} SQueryHbReqBasic;
4947

4948
typedef struct {
4949
  uint32_t connId;
4950
  uint64_t killRid;
4951
  int32_t  totalDnodes;
4952
  int32_t  onlineDnodes;
4953
  int8_t   killConnection;
4954
  int8_t   align[3];
4955
  SEpSet   epSet;
4956
  SArray*  pQnodeList;
4957
} SQueryHbRspBasic;
4958

4959
typedef struct SAppClusterSummary {
4960
  uint64_t numOfInsertsReq;
4961
  uint64_t numOfInsertRows;
4962
  uint64_t insertElapsedTime;
4963
  uint64_t insertBytes;  // submit to tsdb since launched.
4964

4965
  uint64_t fetchBytes;
4966
  uint64_t numOfQueryReq;
4967
  uint64_t queryElapsedTime;
4968
  uint64_t numOfSlowQueries;
4969
  uint64_t totalRequests;
4970
  uint64_t currentRequests;  // the number of SRequestObj
4971
} SAppClusterSummary;
4972

4973
typedef struct {
4974
  int64_t            appId;
4975
  int32_t            pid;
4976
  char               name[TSDB_APP_NAME_LEN];
4977
  int64_t            startTime;
4978
  SAppClusterSummary summary;
4979
} SAppHbReq;
4980

4981
typedef struct {
4982
  SClientHbKey      connKey;
4983
  int64_t           clusterId;
4984
  SAppHbReq         app;
4985
  SQueryHbReqBasic* query;
4986
  SHashObj*         info;  // hash<Skv.key, Skv>
4987
  char              user[TSDB_USER_LEN];
4988
  char              tokenName[TSDB_TOKEN_NAME_LEN];
4989
  char              userApp[TSDB_APP_NAME_LEN];
4990
  uint32_t          userIp;
4991
  SIpRange          userDualIp;
4992
  char              sVer[TSDB_VERSION_LEN];
4993
  char              cInfo[CONNECTOR_INFO_LEN];
4994
} SClientHbReq;
4995

4996
typedef struct {
4997
  int64_t reqId;
4998
  SArray* reqs;  // SArray<SClientHbReq>
4999
  int64_t ipWhiteListVer;
5000
} SClientHbBatchReq;
5001

5002
typedef struct {
5003
  SClientHbKey      connKey;
5004
  int32_t           status;
5005
  SQueryHbRspBasic* query;
5006
  SArray*           info;  // Array<Skv>
5007
} SClientHbRsp;
5008

5009
typedef struct {
5010
  int64_t       reqId;
5011
  int64_t       rspId;
5012
  int32_t       svrTimestamp;
5013
  SArray*       rsps;  // SArray<SClientHbRsp>
5014
  SMonitorParas monitorParas;
5015
  int8_t        enableAuditDelete;
5016
  int8_t        enableStrongPass;
5017
  int8_t        enableAuditSelect;
5018
  int8_t        enableAuditInsert;
5019
  int8_t        auditLevel;
5020
} SClientHbBatchRsp;
5021

5022
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
60,494,026✔
5023

5024
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
5025
  void* pIter = taosHashIterate(info, NULL);
43,695,956✔
5026
  while (pIter != NULL) {
100,718,659✔
5027
    SKv* kv = (SKv*)pIter;
57,020,629✔
5028
    taosMemoryFreeClear(kv->value);
57,020,629✔
5029
    pIter = taosHashIterate(info, pIter);
57,020,803✔
5030
  }
5031
}
43,698,030✔
5032

5033
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
27,033,795✔
5034
  SQueryDesc* desc = (SQueryDesc*)pDesc;
27,033,795✔
5035
  if (desc->subDesc) {
27,033,795✔
5036
    taosArrayDestroy(desc->subDesc);
18,985,145✔
5037
    desc->subDesc = NULL;
18,981,453✔
5038
  }
5039
}
27,030,519✔
5040

5041
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
49,515,463✔
5042
  SClientHbReq* req = (SClientHbReq*)pReq;
51,830,989✔
5043
  if (req->query) {
51,830,989✔
5044
    if (req->query->queryDesc) {
49,515,158✔
5045
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
21,666,318✔
5046
    }
5047
    taosMemoryFreeClear(req->query);
49,515,302✔
5048
  }
5049

5050
  if (req->info) {
51,831,143✔
5051
    tFreeReqKvHash(req->info);
43,696,199✔
5052
    taosHashCleanup(req->info);
43,698,030✔
5053
    req->info = NULL;
43,695,884✔
5054
  }
5055
}
27,286,438✔
5056

5057
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
5058
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
5059

5060
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
5061
  if (pReq == NULL) return;
20,763,883✔
5062
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
20,763,883✔
5063
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
20,763,883✔
5064
  taosMemoryFree(pReq);
20,763,883✔
5065
}
5066

5067
static FORCE_INLINE void tFreeClientKv(void* pKv) {
21,250,683✔
5068
  SKv* kv = (SKv*)pKv;
21,250,683✔
5069
  if (kv) {
21,250,683✔
5070
    taosMemoryFreeClear(kv->value);
21,250,683✔
5071
  }
5072
}
21,250,799✔
5073

5074
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
49,323,528✔
5075
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
49,323,528✔
5076
  if (rsp->query) {
49,323,528✔
5077
    taosArrayDestroy(rsp->query->pQnodeList);
49,311,453✔
5078
    taosMemoryFreeClear(rsp->query);
49,308,526✔
5079
  }
5080
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
49,323,544✔
5081
}
24,357,359✔
5082

5083
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
5084
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
41,569,503✔
5085
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
41,569,503✔
5086
}
41,579,344✔
5087

5088
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
5089
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
5090
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
5091

5092
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
5093
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
154,395,898✔
5094
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
154,395,855✔
5095
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
154,395,106✔
5096
  return 0;
77,197,529✔
5097
}
5098

5099
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
5100
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
75,914,208✔
5101
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
75,914,476✔
5102
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
37,957,238✔
5103
  if (pKv->value == NULL) {
37,957,238✔
UNCOV
5104
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
5105
  }
5106
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
37,956,970✔
5107
  return 0;
37,957,238✔
5108
}
5109

5110
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
5111
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
193,509,915✔
5112
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
193,503,963✔
5113
  return 0;
96,750,863✔
5114
}
5115

5116
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
5117
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
96,371,534✔
5118
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
96,377,377✔
5119
  return 0;
48,190,979✔
5120
}
5121

5122
typedef struct {
5123
  int32_t vgId;
5124
  // TODO stas
5125
} SMqReportVgInfo;
5126

5127
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
5128
  int32_t tlen = 0;
5129
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
5130
  return tlen;
5131
}
5132

5133
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
5134
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
5135
  return buf;
5136
}
5137

5138
typedef struct {
5139
  int32_t epoch;
5140
  int64_t topicUid;
5141
  char    name[TSDB_TOPIC_FNAME_LEN];
5142
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
5143
} SMqTopicInfo;
5144

5145
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
5146
  int32_t tlen = 0;
5147
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
5148
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
5149
  tlen += taosEncodeString(buf, pTopicInfo->name);
5150
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
5151
  tlen += taosEncodeFixedI32(buf, sz);
5152
  for (int32_t i = 0; i < sz; i++) {
5153
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
5154
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
5155
  }
5156
  return tlen;
5157
}
5158

5159
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
5160
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
5161
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
5162
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
5163
  int32_t sz;
5164
  buf = taosDecodeFixedI32(buf, &sz);
5165
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
5166
    return NULL;
5167
  }
5168
  for (int32_t i = 0; i < sz; i++) {
5169
    SMqReportVgInfo vgInfo;
5170
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
5171
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
5172
      return NULL;
5173
    }
5174
  }
5175
  return buf;
5176
}
5177

5178
typedef struct {
5179
  int32_t status;  // ask hb endpoint
5180
  int32_t epoch;
5181
  int64_t consumerId;
5182
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
5183
} SMqReportReq;
5184

5185
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
5186
  int32_t tlen = 0;
5187
  tlen += taosEncodeFixedI32(buf, pMsg->status);
5188
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
5189
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
5190
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
5191
  tlen += taosEncodeFixedI32(buf, sz);
5192
  for (int32_t i = 0; i < sz; i++) {
5193
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
5194
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
5195
  }
5196
  return tlen;
5197
}
5198

5199
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
5200
  buf = taosDecodeFixedI32(buf, &pMsg->status);
5201
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
5202
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
5203
  int32_t sz;
5204
  buf = taosDecodeFixedI32(buf, &sz);
5205
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
5206
    return NULL;
5207
  }
5208
  for (int32_t i = 0; i < sz; i++) {
5209
    SMqTopicInfo topicInfo;
5210
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
5211
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
5212
      return NULL;
5213
    }
5214
  }
5215
  return buf;
5216
}
5217

5218
typedef struct {
5219
  SMsgHead head;
5220
  int64_t  leftForVer;
5221
  int32_t  vgId;
5222
  int64_t  consumerId;
5223
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5224
} SMqVDeleteReq;
5225

5226
typedef struct {
5227
  int8_t reserved;
5228
} SMqVDeleteRsp;
5229

5230
typedef struct {
5231
  char**  name;
5232
  int32_t count;
5233
  int8_t igNotExists;
5234
} SMDropStreamReq;
5235

5236
typedef struct {
5237
  int8_t reserved;
5238
} SMDropStreamRsp;
5239

5240
typedef struct {
5241
  SMsgHead head;
5242
  int64_t  resetRelHalt;  // reset related stream task halt status
5243
  int64_t  streamId;
5244
  int32_t  taskId;
5245
} SVDropStreamTaskReq;
5246

5247
typedef struct {
5248
  int8_t reserved;
5249
} SVDropStreamTaskRsp;
5250

5251
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
5252
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
5253
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
5254

5255
typedef struct {
5256
  char*  name;
5257
  int8_t igNotExists;
5258
} SMPauseStreamReq;
5259

5260
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
5261
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
5262
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
5263

5264
typedef struct {
5265
  char*  name;
5266
  int8_t igNotExists;
5267
  int8_t igUntreated;
5268
} SMResumeStreamReq;
5269

5270
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
5271
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
5272
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
5273

5274
typedef struct {
5275
  char*       name;
5276
  int8_t      calcAll;
5277
  STimeWindow timeRange;
5278
} SMRecalcStreamReq;
5279

5280
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
5281
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
5282
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
5283

5284

5285
typedef struct SVndSetKeepVersionReq {
5286
  int64_t keepVersion;
5287
} SVndSetKeepVersionReq;
5288

5289
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5290
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
5291

5292
typedef struct SVUpdateCheckpointInfoReq {
5293
  SMsgHead head;
5294
  int64_t  streamId;
5295
  int32_t  taskId;
5296
  int64_t  checkpointId;
5297
  int64_t  checkpointVer;
5298
  int64_t  checkpointTs;
5299
  int32_t  transId;
5300
  int64_t  hStreamId;  // add encode/decode
5301
  int64_t  hTaskId;
5302
  int8_t   dropRelHTask;
5303
} SVUpdateCheckpointInfoReq;
5304

5305
typedef struct {
5306
  int64_t leftForVer;
5307
  int32_t vgId;
5308
  int64_t oldConsumerId;
5309
  int64_t newConsumerId;
5310
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
5311
  int8_t  subType;
5312
  int8_t  withMeta;
5313
  char*   qmsg;  // SubPlanToString
5314
  SSchemaWrapper schema;
5315
  int64_t suid;
5316
} SMqRebVgReq;
5317

5318
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
5319
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
5320

5321
// tqOffset
5322
enum {
5323
  TMQ_OFFSET__RESET_NONE = -3,
5324
  TMQ_OFFSET__RESET_EARLIEST = -2,
5325
  TMQ_OFFSET__RESET_LATEST = -1,
5326
  TMQ_OFFSET__LOG = 1,
5327
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
5328
  TMQ_OFFSET__SNAPSHOT_META = 3,
5329
};
5330

5331
enum {
5332
  WITH_DATA = 0,
5333
  WITH_META = 1,
5334
  ONLY_META = 2,
5335
};
5336

5337
#define TQ_OFFSET_VERSION 1
5338

5339
typedef struct {
5340
  int8_t type;
5341
  union {
5342
    // snapshot
5343
    struct {
5344
      int64_t uid;
5345
      int64_t ts;
5346
      SValue  primaryKey;
5347
    };
5348
    // log
5349
    struct {
5350
      int64_t version;
5351
    };
5352
  };
5353
} STqOffsetVal;
5354

5355
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
5356
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
7,336,604✔
5357
  pOffsetVal->uid = uid;
7,333,948✔
5358
  pOffsetVal->ts = ts;
7,335,452✔
5359
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
7,335,452✔
5360
    taosMemoryFree(pOffsetVal->primaryKey.pData);
271✔
5361
  }
5362
  pOffsetVal->primaryKey = primaryKey;
7,332,727✔
5363
}
7,335,117✔
5364

5365
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
5366
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
37,597✔
5367
  pOffsetVal->uid = uid;
37,597✔
5368
}
37,597✔
5369

5370
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
5371
  pOffsetVal->type = TMQ_OFFSET__LOG;
118,229,103✔
5372
  pOffsetVal->version = ver;
118,229,356✔
5373
}
118,222,725✔
5374

5375
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
5376
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
5377
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
5378
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5379
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
5380
void    tOffsetDestroy(void* pVal);
5381

5382
typedef struct {
5383
  STqOffsetVal val;
5384
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5385
} STqOffset;
5386

5387
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
5388
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
5389
void    tDeleteSTqOffset(void* val);
5390

5391
typedef struct SMqVgOffset {
5392
  int64_t   consumerId;
5393
  STqOffset offset;
5394
} SMqVgOffset;
5395

5396
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
5397
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
5398

5399
typedef struct {
5400
  char    name[TSDB_TABLE_FNAME_LEN];
5401
  char    stb[TSDB_TABLE_FNAME_LEN];
5402
  int8_t  igExists;
5403
  int8_t  intervalUnit;
5404
  int8_t  slidingUnit;
5405
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
5406
  int32_t dstVgId;   // for stream
5407
  int64_t interval;
5408
  int64_t offset;
5409
  int64_t sliding;
5410
  int64_t maxDelay;
5411
  int64_t watermark;
5412
  int32_t exprLen;        // strlen + 1
5413
  int32_t tagsFilterLen;  // strlen + 1
5414
  int32_t sqlLen;         // strlen + 1
5415
  int32_t astLen;         // strlen + 1
5416
  char*   expr;
5417
  char*   tagsFilter;
5418
  char*   sql;
5419
  char*   ast;
5420
  int64_t deleteMark;
5421
  int64_t lastTs;
5422
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
5423
  SArray* pVgroupVerList;
5424
  int8_t  recursiveTsma;
5425
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
5426
  char*   createStreamReq;
5427
  int32_t streamReqLen;
5428
  char*   dropStreamReq;
5429
  int32_t dropStreamReqLen;
5430
  int64_t uid;
5431
} SMCreateSmaReq;
5432

5433
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5434
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
5435
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
5436

5437
typedef struct {
5438
  char    name[TSDB_TABLE_FNAME_LEN];
5439
  int8_t  igNotExists;
5440
  char*   dropStreamReq;
5441
  int32_t dropStreamReqLen;
5442
} SMDropSmaReq;
5443

5444
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5445
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
5446
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
5447

5448
typedef struct {
5449
  char name[TSDB_TABLE_NAME_LEN];
5450
  union {
5451
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
5452
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
5453
  };
5454
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
5455
  union {
5456
    int8_t igExists;   // used by mnode
5457
    int8_t alterType;  // used by vnode
5458
  };
5459
  int8_t     intervalUnit;
5460
  int16_t    nFuncs;       // number of functions specified by user
5461
  col_id_t*  funcColIds;   // column ids specified by user
5462
  func_id_t* funcIds;      // function ids specified by user
5463
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
5464
  int64_t    tbUid;
5465
  int64_t    uid;     // rsma uid
5466
  int32_t    sqlLen;  // strlen + 1
5467
  char*      sql;
5468
} SMCreateRsmaReq;
5469

5470
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5471
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
5472
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
5473

5474
typedef SMCreateRsmaReq SVCreateRsmaReq;
5475

5476
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5477
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
5478
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
5479

5480
typedef SMCreateRsmaReq SVAlterRsmaReq;
5481

5482
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5483
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
5484
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
5485

5486
typedef struct {
5487
  char       name[TSDB_TABLE_NAME_LEN];
5488
  int8_t     alterType;
5489
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
5490
  int8_t     igNotExists;
5491
  int16_t    nFuncs;      // number of functions specified by user
5492
  col_id_t*  funcColIds;  // column ids specified by user
5493
  func_id_t* funcIds;     // function ids specified by user
5494
  int32_t    sqlLen;      // strlen + 1
5495
  char*      sql;
5496
} SMAlterRsmaReq;
5497

5498
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5499
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
5500
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
5501

5502
typedef struct {
5503
  int64_t    id;
5504
  char       name[TSDB_TABLE_NAME_LEN];
5505
  char       tbFName[TSDB_TABLE_FNAME_LEN];
5506
  int64_t    ownerId;
5507
  int32_t    code;
5508
  int32_t    version;
5509
  int8_t     tbType;
5510
  int8_t     intervalUnit;
5511
  col_id_t   nFuncs;
5512
  col_id_t   nColNames;
5513
  int64_t    interval[2];
5514
  col_id_t*  funcColIds;
5515
  func_id_t* funcIds;
5516
  SArray*    colNames;
5517
} SRsmaInfoRsp;
5518

5519
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5520
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
5521
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
5522

5523
typedef struct {
5524
  char   name[TSDB_TABLE_FNAME_LEN];
5525
  int8_t igNotExists;
5526
} SMDropRsmaReq;
5527

5528
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5529
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
5530

5531
typedef struct {
5532
  char    name[TSDB_TABLE_NAME_LEN];
5533
  char    tbName[TSDB_TABLE_NAME_LEN];
5534
  int64_t uid;
5535
  int64_t tbUid;
5536
  int8_t  tbType;
5537
} SVDropRsmaReq;
5538

5539
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5540
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
5541

5542
typedef struct {
5543
  char   dbFName[TSDB_DB_FNAME_LEN];
5544
  char   stbName[TSDB_TABLE_NAME_LEN];
5545
  char   colName[TSDB_COL_NAME_LEN];
5546
  char   idxName[TSDB_INDEX_FNAME_LEN];
5547
  int8_t idxType;
5548
} SCreateTagIndexReq;
5549

5550
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5551
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
5552

5553
typedef SMDropSmaReq SDropTagIndexReq;
5554

5555
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5556
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
5557

5558
typedef struct {
5559
  int8_t         version;       // for compatibility(default 0)
5560
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
5561
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
5562
  int8_t         timezoneInt;   // sma data expired if timezone changes.
5563
  int32_t        dstVgId;
5564
  char           indexName[TSDB_INDEX_NAME_LEN];
5565
  int32_t        exprLen;
5566
  int32_t        tagsFilterLen;
5567
  int64_t        indexUid;
5568
  tb_uid_t       tableUid;  // super/child/common table uid
5569
  tb_uid_t       dstTbUid;  // for dstVgroup
5570
  int64_t        interval;
5571
  int64_t        offset;  // use unit by precision of DB
5572
  int64_t        sliding;
5573
  char*          dstTbName;  // for dstVgroup
5574
  char*          expr;       // sma expression
5575
  char*          tagsFilter;
5576
  SSchemaWrapper schemaRow;  // for dstVgroup
5577
  SSchemaWrapper schemaTag;  // for dstVgroup
5578
} STSma;                     // Time-range-wise SMA
5579

5580
typedef STSma SVCreateTSmaReq;
5581

5582
typedef struct {
5583
  int8_t  type;  // 0 status report, 1 update data
5584
  int64_t indexUid;
5585
  int64_t skey;  // start TS key of interval/sliding window
5586
} STSmaMsg;
5587

5588
typedef struct {
5589
  int64_t indexUid;
5590
  char    indexName[TSDB_INDEX_NAME_LEN];
5591
} SVDropTSmaReq;
5592

5593
typedef struct {
5594
  int tmp;  // TODO: to avoid compile error
5595
} SVCreateTSmaRsp, SVDropTSmaRsp;
5596

5597
#if 0
5598
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
5599
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
5600
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
5601
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
5602
#endif
5603

5604
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5605
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5606
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
5607
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
5608

5609
typedef struct {
5610
  int32_t number;
5611
  STSma*  tSma;
5612
} STSmaWrapper;
5613

5614
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
5615
  if (pSma) {
×
UNCOV
5616
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
5617
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
5618
    taosMemoryFreeClear(pSma->tagsFilter);
×
5619
  }
UNCOV
5620
}
×
5621

5622
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5623
  if (pSW) {
×
UNCOV
5624
    if (pSW->tSma) {
×
UNCOV
5625
      if (deepCopy) {
×
UNCOV
5626
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
5627
          tDestroyTSma(pSW->tSma + i);
×
5628
        }
5629
      }
UNCOV
5630
      taosMemoryFreeClear(pSW->tSma);
×
5631
    }
5632
  }
UNCOV
5633
}
×
5634

5635
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
5636
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
5637
  taosMemoryFreeClear(pSW);
×
UNCOV
5638
  return NULL;
×
5639
}
5640

5641
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5642
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5643

5644
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5645
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5646

UNCOV
5647
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5648
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5649
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5650
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5651
  }
5652
  return 0;
×
5653
}
5654

5655
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
5656
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
5657
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5658
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5659
  }
UNCOV
5660
  return 0;
×
5661
}
5662

5663
typedef struct {
5664
  int idx;
5665
} SMCreateFullTextReq;
5666

5667
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5668
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5669
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5670

5671
typedef struct {
5672
  char   name[TSDB_TABLE_FNAME_LEN];
5673
  int8_t igNotExists;
5674
} SMDropFullTextReq;
5675

5676
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5677
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5678

5679
typedef struct {
5680
  char indexFName[TSDB_INDEX_FNAME_LEN];
5681
} SUserIndexReq;
5682

5683
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5684
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5685

5686
typedef struct {
5687
  char dbFName[TSDB_DB_FNAME_LEN];
5688
  char tblFName[TSDB_TABLE_FNAME_LEN];
5689
  char colName[TSDB_COL_NAME_LEN];
5690
  char owner[TSDB_USER_LEN];
5691
  char indexType[TSDB_INDEX_TYPE_LEN];
5692
  char indexExts[TSDB_INDEX_EXTS_LEN];
5693
} SUserIndexRsp;
5694

5695
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5696
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5697

5698
typedef struct {
5699
  char tbFName[TSDB_TABLE_FNAME_LEN];
5700
} STableIndexReq;
5701

5702
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5703
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5704

5705
typedef struct {
5706
  int8_t  intervalUnit;
5707
  int8_t  slidingUnit;
5708
  int64_t interval;
5709
  int64_t offset;
5710
  int64_t sliding;
5711
  int64_t dstTbUid;
5712
  int32_t dstVgId;
5713
  SEpSet  epSet;
5714
  char*   expr;
5715
} STableIndexInfo;
5716

5717
typedef struct {
5718
  char     tbName[TSDB_TABLE_NAME_LEN];
5719
  char     dbFName[TSDB_DB_FNAME_LEN];
5720
  uint64_t suid;
5721
  int32_t  version;
5722
  int32_t  indexSize;
5723
  SArray*  pIndex;  // STableIndexInfo
5724
} STableIndexRsp;
5725

5726
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5727
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5728
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5729

5730
void tFreeSTableIndexInfo(void* pInfo);
5731

5732
typedef struct {
5733
  int8_t  mqMsgType;
5734
  int32_t code;
5735
  int32_t epoch;
5736
  int64_t consumerId;
5737
  int64_t walsver;
5738
  int64_t walever;
5739
} SMqRspHead;
5740

5741
typedef struct {
5742
  SMsgHead     head;
5743
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5744
  int8_t       withTbName;
5745
  int8_t       useSnapshot;
5746
  int32_t      epoch;
5747
  uint64_t     reqId;
5748
  int64_t      consumerId;
5749
  int64_t      timeout;
5750
  STqOffsetVal reqOffset;
5751
  int8_t       enableReplay;
5752
  int8_t       sourceExcluded;
5753
  int8_t       rawData;
5754
  int32_t      minPollRows;
5755
  int8_t       enableBatchMeta;
5756
  SHashObj*    uidHash;  // to find if uid is duplicated
5757
} SMqPollReq;
5758

5759
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5760
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5761
void    tDestroySMqPollReq(SMqPollReq* pReq);
5762

5763
typedef struct {
5764
  int32_t vgId;
5765
  int64_t offset;
5766
  SEpSet  epSet;
5767
} SMqSubVgEp;
5768

5769
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5770
  int32_t tlen = 0;
2,299,690✔
5771
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2,299,690✔
5772
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
2,299,690✔
5773
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
2,299,690✔
5774
  return tlen;
2,299,690✔
5775
}
5776

5777
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5778
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
1,143,693✔
5779
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
1,143,693✔
5780
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
1,143,693✔
5781
  return buf;
1,143,693✔
5782
}
5783

5784
typedef struct {
5785
  char           topic[TSDB_TOPIC_FNAME_LEN];
5786
  char           db[TSDB_DB_FNAME_LEN];
5787
  SArray*        vgs;  // SArray<SMqSubVgEp>
5788
} SMqSubTopicEp;
5789

5790
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5791
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5792
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5793

5794
typedef struct {
5795
  SMqRspHead   head;
5796
  STqOffsetVal rspOffset;
5797
  int16_t      resMsgType;
5798
  int32_t      metaRspLen;
5799
  void*        metaRsp;
5800
} SMqMetaRsp;
5801

5802
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5803
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5804
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5805

5806
#define MQ_DATA_RSP_VERSION 100
5807

5808
typedef struct {
5809
  SMqRspHead   head;
5810
  STqOffsetVal rspOffset;
5811
  STqOffsetVal reqOffset;
5812
  int32_t      blockNum;
5813
  int8_t       withTbName;
5814
  int8_t       withSchema;
5815
  SArray*      blockDataLen;
5816
  SArray*      blockData;
5817
  SArray*      blockTbName;
5818
  SArray*      blockSchema;
5819

5820
  union {
5821
    struct {
5822
      int64_t sleepTime;
5823
    };
5824
    struct {
5825
      int32_t createTableNum;
5826
      SArray* createTableLen;
5827
      SArray* createTableReq;
5828
    };
5829
    struct {
5830
      int32_t len;
5831
      void*   rawData;
5832
    };
5833
  };
5834
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5835
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5836
} SMqDataRsp;
5837

5838
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5839
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5840
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5841
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5842
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5843

5844
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5845
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5846
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5847

5848
typedef struct SMqBatchMetaRsp {
5849
  SMqRspHead   head;  // not serialize
5850
  STqOffsetVal rspOffset;
5851
  SArray*      batchMetaLen;
5852
  SArray*      batchMetaReq;
5853
  void*        pMetaBuff;    // not serialize
5854
  uint32_t     metaBuffLen;  // not serialize
5855
} SMqBatchMetaRsp;
5856

5857
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5858
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5859
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5860
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5861

5862
typedef struct {
5863
  int32_t    code;
5864
  SArray*    topics;  // SArray<SMqSubTopicEp>
5865
} SMqAskEpRsp;
5866

5867
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5868
  int32_t tlen = 0;
7,854,015✔
5869
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5870
  int32_t sz = taosArrayGetSize(pRsp->topics);
7,854,015✔
5871
  tlen += taosEncodeFixedI32(buf, sz);
7,853,036✔
5872
  for (int32_t i = 0; i < sz; i++) {
9,691,102✔
5873
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,837,738✔
5874
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,837,738✔
5875
  }
5876
  tlen += taosEncodeFixedI32(buf, pRsp->code);
7,853,364✔
5877

5878
  return tlen;
7,853,364✔
5879
}
5880

5881
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5882
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5883
  int32_t sz;
3,224,698✔
5884
  buf = taosDecodeFixedI32(buf, &sz);
3,297,997✔
5885
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
3,297,997✔
5886
  if (pRsp->topics == NULL) {
3,297,997✔
UNCOV
5887
    return NULL;
×
5888
  }
5889
  for (int32_t i = 0; i < sz; i++) {
4,169,213✔
5890
    SMqSubTopicEp topicEp;
858,315✔
5891
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
871,216✔
5892
    if (buf == NULL) {
871,216✔
UNCOV
5893
      return NULL;
×
5894
    }
5895
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,742,432✔
UNCOV
5896
      return NULL;
×
5897
    }
5898
  }
5899
  buf = taosDecodeFixedI32(buf, &pRsp->code);
3,297,997✔
5900

5901
  return buf;
3,297,997✔
5902
}
5903

5904
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5905
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
9,592,522✔
5906
}
9,591,851✔
5907

5908
typedef struct {
5909
  int32_t      vgId;
5910
  STqOffsetVal offset;
5911
  int64_t      rows;
5912
  int64_t      ever;
5913
} OffsetRows;
5914

5915
typedef struct {
5916
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5917
  SArray* offsetRows;
5918
} TopicOffsetRows;
5919

5920
typedef struct {
5921
  int64_t consumerId;
5922
  int32_t epoch;
5923
  SArray* topics;
5924
  int8_t  pollFlag;
5925
} SMqHbReq;
5926

5927
typedef struct {
5928
  char   topic[TSDB_TOPIC_FNAME_LEN];
5929
  int8_t noPrivilege;
5930
} STopicPrivilege;
5931

5932
typedef struct {
5933
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5934
  int32_t debugFlag;
5935
} SMqHbRsp;
5936

5937
typedef struct {
5938
  SMsgHead head;
5939
  int64_t  consumerId;
5940
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5941
} SMqSeekReq;
5942

5943
#define TD_AUTO_CREATE_TABLE 0x1
5944
typedef struct {
5945
  int64_t       suid;
5946
  int64_t       uid;
5947
  int32_t       sver;
5948
  uint32_t      nData;
5949
  uint8_t*      pData;
5950
  SVCreateTbReq cTbReq;
5951
} SVSubmitBlk;
5952

5953
typedef struct {
5954
  SMsgHead header;
5955
  uint64_t sId;
5956
  uint64_t queryId;
5957
  uint64_t clientId;
5958
  uint64_t taskId;
5959
  uint32_t sqlLen;
5960
  uint32_t phyLen;
5961
  char*    sql;
5962
  char*    msg;
5963
  int8_t   source;
5964
} SVDeleteReq;
5965

5966
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5967
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5968

5969
typedef struct {
5970
  int64_t affectedRows;
5971
} SVDeleteRsp;
5972

5973
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5974
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5975

5976
typedef struct SDeleteRes {
5977
  uint64_t suid;
5978
  SArray*  uidList;
5979
  int64_t  skey;
5980
  int64_t  ekey;
5981
  int64_t  affectedRows;
5982
  char     tableFName[TSDB_TABLE_NAME_LEN];
5983
  char     tsColName[TSDB_COL_NAME_LEN];
5984
  int64_t  ctimeMs;  // fill by vnode
5985
  int8_t   source;
5986
} SDeleteRes;
5987

5988
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5989
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5990

5991
typedef struct {
5992
  // int64_t uid;
5993
  char    tbname[TSDB_TABLE_NAME_LEN];
5994
  int64_t startTs;
5995
  int64_t endTs;
5996
} SSingleDeleteReq;
5997

5998
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5999
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
6000

6001
typedef struct {
6002
  int64_t suid;
6003
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
6004
  int64_t ctimeMs;     // fill by vnode
6005
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
6006
} SBatchDeleteReq;
6007

6008
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
6009
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
6010
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
6011

6012
typedef struct {
6013
  int32_t msgIdx;
6014
  int32_t msgType;
6015
  int32_t msgLen;
6016
  void*   msg;
6017
} SBatchMsg;
6018

6019
typedef struct {
6020
  SMsgHead header;
6021
  SArray*  pMsgs;  // SArray<SBatchMsg>
6022
} SBatchReq;
6023

6024
typedef struct {
6025
  int32_t reqType;
6026
  int32_t msgIdx;
6027
  int32_t msgLen;
6028
  int32_t rspCode;
6029
  void*   msg;
6030
} SBatchRspMsg;
6031

6032
typedef struct {
6033
  SArray* pRsps;  // SArray<SBatchRspMsg>
6034
} SBatchRsp;
6035

6036
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6037
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
6038
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
87,986,113✔
6039
  if (NULL == msg) {
87,986,113✔
UNCOV
6040
    return;
×
6041
  }
6042
  SBatchMsg* pMsg = (SBatchMsg*)msg;
87,986,113✔
6043
  taosMemoryFree(pMsg->msg);
87,986,113✔
6044
}
6045

6046
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6047
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
6048

6049
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
113,567,325✔
6050
  if (NULL == p) {
113,567,325✔
UNCOV
6051
    return;
×
6052
  }
6053

6054
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
113,567,325✔
6055
  taosMemoryFree(pRsp->msg);
113,567,325✔
6056
}
6057

6058
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6059
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
6060
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6061
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
6062
void    tDestroySMqHbReq(SMqHbReq* pReq);
6063

6064
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6065
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
6066
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
6067

6068
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6069
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
6070

6071
#define TD_REQ_FROM_APP               0x0
6072
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
6073
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
6074
#define SUBMIT_REQ_FROM_FILE          0x4
6075
#define TD_REQ_FROM_TAOX              0x8
6076
#define TD_REQ_FROM_SML               0x10
6077
#define SUBMIT_REQUEST_VERSION        (2)
6078
#define SUBMIT_REQ_WITH_BLOB          0x10
6079
#define SUBMIT_REQ_SCHEMA_RES         0x20
6080
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
6081

6082
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
6083

6084
typedef struct {
6085
  int32_t        flags;
6086
  SVCreateTbReq* pCreateTbReq;
6087
  int64_t        suid;
6088
  int64_t        uid;
6089
  int32_t        sver;
6090
  union {
6091
    SArray* aRowP;
6092
    SArray* aCol;
6093
  };
6094
  int64_t   ctimeMs;
6095
  SBlobSet* pBlobSet;
6096
} SSubmitTbData;
6097

6098
typedef struct {
6099
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
6100
  SArray* aSubmitBlobData;
6101
  bool    raw;
6102
} SSubmitReq2;
6103

6104
typedef struct {
6105
  SMsgHead header;
6106
  int64_t  version;
6107
  char     data[];  // SSubmitReq2
6108
} SSubmitReq2Msg;
6109

6110
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
6111
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
6112
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
6113
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
6114
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
6115

6116
typedef struct {
6117
  int32_t affectedRows;
6118
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
6119
} SSubmitRsp2;
6120

6121
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
6122
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
6123
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
6124

6125
#define TSDB_MSG_FLG_ENCODE 0x1
6126
#define TSDB_MSG_FLG_DECODE 0x2
6127
#define TSDB_MSG_FLG_CMPT   0x3
6128

6129
typedef struct {
6130
  union {
6131
    struct {
6132
      void*   msgStr;
6133
      int32_t msgLen;
6134
      int64_t ver;
6135
    };
6136
    void* pDataBlock;
6137
  };
6138
} SPackedData;
6139

6140
typedef struct {
6141
  char     fullname[TSDB_VIEW_FNAME_LEN];
6142
  char     name[TSDB_VIEW_NAME_LEN];
6143
  char     dbFName[TSDB_DB_FNAME_LEN];
6144
  char*    querySql;
6145
  char*    sql;
6146
  int8_t   orReplace;
6147
  int8_t   precision;
6148
  int32_t  numOfCols;
6149
  SSchema* pSchema;
6150
} SCMCreateViewReq;
6151

6152
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
6153
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
6154
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
6155

6156
typedef struct {
6157
  char   fullname[TSDB_VIEW_FNAME_LEN];
6158
  char   name[TSDB_VIEW_NAME_LEN];
6159
  char   dbFName[TSDB_DB_FNAME_LEN];
6160
  char*  sql;
6161
  int8_t igNotExists;
6162
} SCMDropViewReq;
6163

6164
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
6165
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
6166
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
6167

6168
typedef struct {
6169
  char fullname[TSDB_VIEW_FNAME_LEN];
6170
} SViewMetaReq;
6171
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
6172
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
6173

6174
typedef struct {
6175
  char     name[TSDB_VIEW_NAME_LEN];
6176
  char     dbFName[TSDB_DB_FNAME_LEN];
6177
  char*    createUser;
6178
  int64_t  ownerId;
6179
  uint64_t dbId;
6180
  uint64_t viewId;
6181
  char*    querySql;
6182
  int8_t   precision;
6183
  int8_t   type;
6184
  int32_t  version;
6185
  int32_t  numOfCols;
6186
  SSchema* pSchema;
6187
} SViewMetaRsp;
6188
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
6189
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
6190
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
6191
typedef struct {
6192
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
6193
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
6194
} STableTSMAInfoReq;
6195

6196
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
6197
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
6198

6199
typedef struct {
6200
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
6201
  union {
6202
    uint8_t flags;
6203
    struct {
6204
      uint8_t withColName : 1;
6205
      uint8_t reserved : 7;
6206
    };
6207
  };
6208

6209
} SRsmaInfoReq;
6210

6211
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
6212
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
6213

6214
typedef struct {
6215
  int32_t  funcId;
6216
  col_id_t colId;
6217
} STableTSMAFuncInfo;
6218

6219
typedef struct {
6220
  char     name[TSDB_TABLE_NAME_LEN];
6221
  uint64_t tsmaId;
6222
  char     targetTb[TSDB_TABLE_NAME_LEN];
6223
  char     targetDbFName[TSDB_DB_FNAME_LEN];
6224
  char     tb[TSDB_TABLE_NAME_LEN];
6225
  char     dbFName[TSDB_DB_FNAME_LEN];
6226
  uint64_t suid;
6227
  uint64_t destTbUid;
6228
  uint64_t dbId;
6229
  int32_t  version;
6230
  int64_t  interval;
6231
  int8_t   unit;
6232
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
6233
  SArray*  pTags;      // SArray<SSchema>
6234
  SArray*  pUsedCols;  // SArray<SSchema>
6235
  char*    ast;
6236

6237
  int64_t streamUid;
6238
  int64_t reqTs;
6239
  int64_t rspTs;
6240
  int64_t delayDuration;  // ms
6241
  bool    fillHistoryFinished;
6242

6243
  void* streamAddr;  // for stream task, the address of the stream task
6244
} STableTSMAInfo;
6245

6246
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
6247
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
6248
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
6249
void    tFreeTableTSMAInfo(void* p);
6250
void    tFreeAndClearTableTSMAInfo(void* p);
6251
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
6252

6253
#define STSMAHbRsp            STableTSMAInfoRsp
6254
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
6255
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
6256
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
6257

6258
typedef struct SDropCtbWithTsmaSingleVgReq {
6259
  SVgroupInfo vgInfo;
6260
  SArray*     pTbs;  // SVDropTbReq
6261
} SMDropTbReqsOnSingleVg;
6262

6263
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
6264
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
6265
void    tFreeSMDropTbReqOnSingleVg(void* p);
6266

6267
typedef struct SDropTbsReq {
6268
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
6269
} SMDropTbsReq;
6270

6271
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
6272
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
6273
void    tFreeSMDropTbsReq(void*);
6274

6275
typedef struct SVFetchTtlExpiredTbsRsp {
6276
  SArray* pExpiredTbs;  // SVDropTbReq
6277
  int32_t vgId;
6278
} SVFetchTtlExpiredTbsRsp;
6279

6280
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
6281
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
6282

6283
void tFreeFetchTtlExpiredTbsRsp(void* p);
6284

6285
void setDefaultOptionsForField(SFieldWithOptions* field);
6286
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
6287

6288
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
6289
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
6290

6291

6292
typedef struct {
6293
  char    id[TSDB_INSTANCE_ID_LEN];
6294
  char    type[TSDB_INSTANCE_TYPE_LEN];
6295
  char    desc[TSDB_INSTANCE_DESC_LEN];
6296
  int32_t expire;
6297
} SInstanceRegisterReq;
6298

6299
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6300
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
6301

6302
typedef struct {
6303
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
6304
} SInstanceListReq;
6305

6306
typedef struct {
6307
  int32_t count;
6308
  char**  ids;  // Array of instance IDs
6309
} SInstanceListRsp;
6310

6311
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6312
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
6313
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6314
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
6315

6316
#ifdef USE_MOUNT
6317
typedef struct {
6318
  char     mountName[TSDB_MOUNT_NAME_LEN];
6319
  int8_t   ignoreExist;
6320
  int16_t  nMounts;
6321
  int32_t* dnodeIds;
6322
  char**   mountPaths;
6323
  int32_t  sqlLen;
6324
  char*    sql;
6325
} SCreateMountReq;
6326

6327
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6328
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
6329
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
6330

6331
typedef struct {
6332
  char    mountName[TSDB_MOUNT_NAME_LEN];
6333
  int8_t  ignoreNotExists;
6334
  int32_t sqlLen;
6335
  char*   sql;
6336
} SDropMountReq;
6337

6338
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6339
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
6340
void    tFreeSDropMountReq(SDropMountReq* pReq);
6341

6342
typedef struct {
6343
  char     mountName[TSDB_MOUNT_NAME_LEN];
6344
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6345
  int64_t  mountUid;
6346
  int32_t  dnodeId;
6347
  uint32_t valLen;
6348
  int8_t   ignoreExist;
6349
  void*    pVal;
6350
} SRetrieveMountPathReq;
6351

6352
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6353
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
6354

6355
typedef struct {
6356
  // path
6357
  int32_t diskPrimary;
6358
  // vgInfo
6359
  int32_t  vgId;
6360
  int32_t  cacheLastSize;
6361
  int32_t  szPage;
6362
  int32_t  szCache;
6363
  uint64_t szBuf;
6364
  int8_t   cacheLast;
6365
  int8_t   standby;
6366
  int8_t   hashMethod;
6367
  uint32_t hashBegin;
6368
  uint32_t hashEnd;
6369
  int16_t  hashPrefix;
6370
  int16_t  hashSuffix;
6371
  int16_t  sttTrigger;
6372
  // syncInfo
6373
  int32_t replications;
6374
  // tsdbInfo
6375
  int8_t  precision;
6376
  int8_t  compression;
6377
  int8_t  slLevel;
6378
  int32_t daysPerFile;
6379
  int32_t keep0;
6380
  int32_t keep1;
6381
  int32_t keep2;
6382
  int32_t keepTimeOffset;
6383
  int32_t minRows;
6384
  int32_t maxRows;
6385
  int32_t tsdbPageSize;
6386
  int32_t ssChunkSize;
6387
  int32_t ssKeepLocal;
6388
  int8_t  ssCompact;
6389
  // walInfo
6390
  int32_t walFsyncPeriod;      // millisecond
6391
  int32_t walRetentionPeriod;  // secs
6392
  int32_t walRollPeriod;       // secs
6393
  int64_t walRetentionSize;
6394
  int64_t walSegSize;
6395
  int32_t walLevel;
6396
  // encryptInfo
6397
  int32_t encryptAlgorithm;
6398
  // SVState
6399
  int64_t committed;
6400
  int64_t commitID;
6401
  int64_t commitTerm;
6402
  // stats
6403
  int64_t numOfSTables;
6404
  int64_t numOfCTables;
6405
  int64_t numOfNTables;
6406
  // dbInfo
6407
  uint64_t dbId;
6408
} SMountVgInfo;
6409

6410
typedef struct {
6411
  SMCreateStbReq req;
6412
  SArray*        pColExts;  // element: column id
6413
  SArray*        pTagExts;  // element: tag id
6414
} SMountStbInfo;
6415

6416
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
6417
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
6418

6419
typedef struct {
6420
  char     dbName[TSDB_DB_FNAME_LEN];
6421
  uint64_t dbId;
6422
  SArray*  pVgs;   // SMountVgInfo
6423
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
6424
} SMountDbInfo;
6425

6426
typedef struct {
6427
  // common fields
6428
  char     mountName[TSDB_MOUNT_NAME_LEN];
6429
  char     mountPath[TSDB_MOUNT_PATH_LEN];
6430
  int8_t   ignoreExist;
6431
  int64_t  mountUid;
6432
  int64_t  clusterId;
6433
  int32_t  dnodeId;
6434
  uint32_t valLen;
6435
  void*    pVal;
6436

6437
  // response fields
6438
  SArray* pDbs;  // SMountDbInfo
6439

6440
  // memory fields, no serialized
6441
  SArray*   pDisks[TFS_MAX_TIERS];
6442
  TdFilePtr pFile;
6443
} SMountInfo;
6444

6445
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
6446
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
6447
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
6448

6449
typedef struct {
6450
  SCreateVnodeReq createReq;
6451
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
6452
  char            mountName[TSDB_MOUNT_NAME_LEN];
6453
  int64_t         mountId;
6454
  int32_t         diskPrimary;
6455
  int32_t         mountVgId;
6456
  int64_t         committed;
6457
  int64_t         commitID;
6458
  int64_t         commitTerm;
6459
  int64_t         numOfSTables;
6460
  int64_t         numOfCTables;
6461
  int64_t         numOfNTables;
6462
} SMountVnodeReq;
6463

6464
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
6465
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
6466
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
6467

6468
#endif  // USE_MOUNT
6469

6470
#pragma pack(pop)
6471

6472
typedef struct {
6473
  char        db[TSDB_DB_FNAME_LEN];
6474
  STimeWindow timeRange;
6475
  int32_t     sqlLen;
6476
  char*       sql;
6477
  SArray*     vgroupIds;
6478
} SScanDbReq;
6479

6480
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6481
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
6482
void    tFreeSScanDbReq(SScanDbReq* pReq);
6483

6484
typedef struct {
6485
  int32_t scanId;
6486
  int8_t  bAccepted;
6487
} SScanDbRsp;
6488

6489
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6490
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
6491

6492
typedef struct {
6493
  int32_t scanId;
6494
  int32_t sqlLen;
6495
  char*   sql;
6496
} SKillScanReq;
6497

6498
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6499
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
6500
void    tFreeSKillScanReq(SKillScanReq* pReq);
6501

6502
typedef struct {
6503
  int32_t scanId;
6504
  int32_t vgId;
6505
  int32_t dnodeId;
6506
} SVKillScanReq;
6507

6508
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6509
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
6510

6511
typedef struct {
6512
  int32_t scanId;
6513
  int32_t vgId;
6514
  int32_t dnodeId;
6515
  int32_t numberFileset;
6516
  int32_t finished;
6517
  int32_t progress;
6518
  int64_t remainingTime;
6519
} SQueryScanProgressRsp;
6520

6521
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6522
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
6523

6524
typedef struct {
6525
  int32_t scanId;
6526
  int32_t vgId;
6527
  int32_t dnodeId;
6528
} SQueryScanProgressReq;
6529

6530
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6531
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
6532

6533
typedef struct {
6534
  int64_t     dbUid;
6535
  char        db[TSDB_DB_FNAME_LEN];
6536
  int64_t     scanStartTime;
6537
  STimeWindow tw;
6538
  int32_t     scanId;
6539
} SScanVnodeReq;
6540

6541
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6542
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
6543

6544
#ifdef __cplusplus
6545
}
6546
#endif
6547

6548
#endif /*_TD_COMMON_TAOS_MSG_H_*/
6549
 
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