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

taosdata / TDengine / #4892

20 Dec 2025 01:15PM UTC coverage: 65.571% (+0.02%) from 65.549%
#4892

push

travis-ci

web-flow
feat: support taos_connect_with func (#33952)

* feat: support taos_connect_with

* refactor: enhance connection options and add tests for taos_set_option and taos_connect_with

* fix: handle NULL keys and values in taos_connect_with options

* fix: revert TAOSWS_GIT_TAG to default value "main"

* docs: add TLS configuration options for WebSocket connections in documentation

* docs: modify zh docs and add en docs

* chore: update taos.cfg

* docs: add examples

* docs: add error handling for connection failure in example code

2 of 82 new or added lines in 3 files covered. (2.44%)

527 existing lines in 120 files now uncovered.

182859 of 278870 relevant lines covered (65.57%)

104634355.9 hits per line

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

84.03
/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 "taosdef.h"
20
#include "taoserror.h"
21
#include "tarray.h"
22
#include "tcoding.h"
23
#include "tcol.h"
24
#include "tencode.h"
25
#include "thash.h"
26
#include "tlist.h"
27
#include "tname.h"
28
#include "trow.h"
29
#include "tuuid.h"
30

31
#ifdef __cplusplus
32
extern "C" {
33
#endif
34

35
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
36

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

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

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

61
extern char*   tMsgInfo[];
62
extern int32_t tMsgDict[];
63
extern int32_t tMsgRangeDict[];
64

65
typedef uint16_t tmsg_t;
66

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

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

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

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

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

107
#define TMSG_INFO(type) (tmsgIsValid(type) ? tMsgInfo[TMSG_INDEX(type)] : "unKnown")
108

109
static inline bool vnodeIsMsgBlock(tmsg_t type) {
707,038,643✔
110
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
669,436,418✔
111
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,376,475,061✔
112
         (type == TDMT_SYNC_CONFIG_CHANGE);
113
}
114

115
static inline bool syncUtilUserCommit(tmsg_t msgType) {
1,887,910,979✔
116
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
1,887,910,979✔
117
}
118

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

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

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

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

209
typedef enum {
210
  TSDB_OPTR_NORMAL = 0,  // default
211
  TSDB_OPTR_SSMIGRATE = 1,
212
  TSDB_OPTR_ROLLUP = 2,
213
} ETsdbOpType;
214

215
typedef enum {
216
  TSDB_TRIGGER_MANUAL = 0,  // default
217
  TSDB_TRIGGER_AUTO = 1,
218
} ETriggerType;
219

220
#define TSDB_ALTER_TABLE_ADD_TAG                         1
221
#define TSDB_ALTER_TABLE_DROP_TAG                        2
222
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
223
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4
224
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
225
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
226
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
227
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
228
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
229
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
230
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
231
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
232
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
233
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
234
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15
235
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
236
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
237
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
238

239
#define TSDB_FILL_NONE        0
240
#define TSDB_FILL_NULL        1
241
#define TSDB_FILL_NULL_F      2
242
#define TSDB_FILL_SET_VALUE   3
243
#define TSDB_FILL_SET_VALUE_F 4
244
#define TSDB_FILL_LINEAR      5
245
#define TSDB_FILL_PREV        6
246
#define TSDB_FILL_NEXT        7
247
#define TSDB_FILL_NEAR        8
248

249

250
#define TSDB_ALTER_USER_BASIC_INFO             1
251
// these definitions start from 5 is to keep compatible with old versions
252
#define TSDB_ALTER_USER_ADD_PRIVILEGES         5
253
#define TSDB_ALTER_USER_DEL_PRIVILEGES         6
254

255

256
#define TSDB_ALTER_RSMA_FUNCTION 0x1
257

258
#define TSDB_KILL_MSG_LEN 30
259

260
#define TSDB_TABLE_NUM_UNIT 100000
261

262
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
263
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
264
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
265

266
#define TSDB_COL_NORMAL 0x0u  // the normal column of the table
267
#define TSDB_COL_TAG    0x1u  // the tag column type
268
#define TSDB_COL_UDC    0x2u  // the user specified normal string column, it is a dummy column
269
#define TSDB_COL_TMP    0x4u  // internal column generated by the previous operators
270
#define TSDB_COL_NULL   0x8u  // the column filter NULL or not
271

272
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
273
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
274
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
275
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
276

277
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
278
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
279
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
280
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
281
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
282

283
typedef enum ENodeType {
284
  // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
285
  // VALUE, OPERATOR, FUNCTION and so on.
286
  QUERY_NODE_COLUMN = 1,
287
  QUERY_NODE_VALUE,
288
  QUERY_NODE_OPERATOR,
289
  QUERY_NODE_LOGIC_CONDITION,
290
  QUERY_NODE_FUNCTION,
291
  QUERY_NODE_REAL_TABLE,
292
  QUERY_NODE_TEMP_TABLE,
293
  QUERY_NODE_JOIN_TABLE,
294
  QUERY_NODE_GROUPING_SET,
295
  QUERY_NODE_ORDER_BY_EXPR,
296
  QUERY_NODE_LIMIT,
297
  QUERY_NODE_STATE_WINDOW,
298
  QUERY_NODE_SESSION_WINDOW,
299
  QUERY_NODE_INTERVAL_WINDOW,
300
  QUERY_NODE_NODE_LIST,
301
  QUERY_NODE_FILL,
302
  QUERY_NODE_RAW_EXPR,  // Only be used in parser module.
303
  QUERY_NODE_TARGET,
304
  QUERY_NODE_DATABLOCK_DESC,
305
  QUERY_NODE_SLOT_DESC,
306
  QUERY_NODE_COLUMN_DEF,
307
  QUERY_NODE_DOWNSTREAM_SOURCE,
308
  QUERY_NODE_DATABASE_OPTIONS,
309
  QUERY_NODE_TABLE_OPTIONS,
310
  QUERY_NODE_INDEX_OPTIONS,
311
  QUERY_NODE_EXPLAIN_OPTIONS,
312
  QUERY_NODE_LEFT_VALUE,
313
  QUERY_NODE_COLUMN_REF,
314
  QUERY_NODE_WHEN_THEN,
315
  QUERY_NODE_CASE_WHEN,
316
  QUERY_NODE_EVENT_WINDOW,
317
  QUERY_NODE_HINT,
318
  QUERY_NODE_VIEW,
319
  QUERY_NODE_WINDOW_OFFSET,
320
  QUERY_NODE_COUNT_WINDOW,
321
  QUERY_NODE_COLUMN_OPTIONS,
322
  QUERY_NODE_TSMA_OPTIONS,
323
  QUERY_NODE_ANOMALY_WINDOW,
324
  QUERY_NODE_RANGE_AROUND,
325
  QUERY_NODE_STREAM_NOTIFY_OPTIONS,
326
  QUERY_NODE_VIRTUAL_TABLE,
327
  QUERY_NODE_SLIDING_WINDOW,
328
  QUERY_NODE_PERIOD_WINDOW,
329
  QUERY_NODE_STREAM_TRIGGER,
330
  QUERY_NODE_STREAM,
331
  QUERY_NODE_STREAM_TAG_DEF,
332
  QUERY_NODE_EXTERNAL_WINDOW,
333
  QUERY_NODE_STREAM_TRIGGER_OPTIONS,
334
  QUERY_NODE_PLACE_HOLDER_TABLE,
335
  QUERY_NODE_TIME_RANGE,
336
  QUERY_NODE_STREAM_OUT_TABLE,
337
  QUERY_NODE_STREAM_CALC_RANGE,
338
  QUERY_NODE_COUNT_WINDOW_ARGS,
339
  QUERY_NODE_BNODE_OPTIONS,
340
  QUERY_NODE_DATE_TIME_RANGE,
341
  QUERY_NODE_IP_RANGE,
342
  QUERY_NODE_USER_OPTIONS,
343

344
  // Statement nodes are used in parser and planner module.
345
  QUERY_NODE_SET_OPERATOR = 100,
346
  QUERY_NODE_SELECT_STMT,
347
  QUERY_NODE_VNODE_MODIFY_STMT,
348
  QUERY_NODE_CREATE_DATABASE_STMT,
349
  QUERY_NODE_DROP_DATABASE_STMT,
350
  QUERY_NODE_ALTER_DATABASE_STMT,
351
  QUERY_NODE_FLUSH_DATABASE_STMT,
352
  QUERY_NODE_TRIM_DATABASE_STMT,
353
  QUERY_NODE_CREATE_TABLE_STMT,
354
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
355
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
356
  QUERY_NODE_DROP_TABLE_CLAUSE,
357
  QUERY_NODE_DROP_TABLE_STMT,
358
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
359
  QUERY_NODE_ALTER_TABLE_STMT,
360
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
361
  QUERY_NODE_CREATE_USER_STMT,
362
  QUERY_NODE_ALTER_USER_STMT,
363
  QUERY_NODE_DROP_USER_STMT,
364
  QUERY_NODE_USE_DATABASE_STMT,
365
  QUERY_NODE_CREATE_DNODE_STMT,
366
  QUERY_NODE_DROP_DNODE_STMT,
367
  QUERY_NODE_ALTER_DNODE_STMT,
368
  QUERY_NODE_CREATE_INDEX_STMT,
369
  QUERY_NODE_DROP_INDEX_STMT,
370
  QUERY_NODE_CREATE_QNODE_STMT,
371
  QUERY_NODE_DROP_QNODE_STMT,
372
  QUERY_NODE_CREATE_BACKUP_NODE_STMT,  // no longer used
373
  QUERY_NODE_DROP_BACKUP_NODE_STMT,    // no longer used
374
  QUERY_NODE_CREATE_SNODE_STMT,
375
  QUERY_NODE_DROP_SNODE_STMT,
376
  QUERY_NODE_CREATE_MNODE_STMT,
377
  QUERY_NODE_DROP_MNODE_STMT,
378
  QUERY_NODE_CREATE_TOPIC_STMT,
379
  QUERY_NODE_DROP_TOPIC_STMT,
380
  QUERY_NODE_DROP_CGROUP_STMT,
381
  QUERY_NODE_ALTER_LOCAL_STMT,
382
  QUERY_NODE_EXPLAIN_STMT,
383
  QUERY_NODE_DESCRIBE_STMT,
384
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
385
  QUERY_NODE_COMPACT_DATABASE_STMT,
386
  QUERY_NODE_COMPACT_VGROUPS_STMT,
387
  QUERY_NODE_CREATE_FUNCTION_STMT,
388
  QUERY_NODE_DROP_FUNCTION_STMT,
389
  QUERY_NODE_CREATE_STREAM_STMT,
390
  QUERY_NODE_DROP_STREAM_STMT,
391
  QUERY_NODE_BALANCE_VGROUP_STMT,
392
  QUERY_NODE_MERGE_VGROUP_STMT,
393
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
394
  QUERY_NODE_SPLIT_VGROUP_STMT,
395
  QUERY_NODE_SYNCDB_STMT,
396
  QUERY_NODE_GRANT_STMT,
397
  QUERY_NODE_REVOKE_STMT,
398
  QUERY_NODE_ALTER_CLUSTER_STMT,
399
  QUERY_NODE_SSMIGRATE_DATABASE_STMT,
400
  QUERY_NODE_CREATE_TSMA_STMT,
401
  QUERY_NODE_DROP_TSMA_STMT,
402
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
403
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
404
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
405
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
406
  QUERY_NODE_CREATE_MOUNT_STMT,
407
  QUERY_NODE_DROP_MOUNT_STMT,
408
  QUERY_NODE_SCAN_DATABASE_STMT,
409
  QUERY_NODE_SCAN_VGROUPS_STMT,
410
  QUERY_NODE_TRIM_DATABASE_WAL_STMT,
411
  QUERY_NODE_ALTER_DNODES_RELOAD_TLS_STMT,
412

413
  // placeholder for [154, 180]
414
  QUERY_NODE_SHOW_CREATE_VIEW_STMT = 181,
415
  QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
416
  QUERY_NODE_SHOW_CREATE_TABLE_STMT,
417
  QUERY_NODE_SHOW_CREATE_STABLE_STMT,
418
  QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT,
419
  QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT,
420
  QUERY_NODE_SHOW_SCORES_STMT,
421
  QUERY_NODE_SHOW_TABLE_TAGS_STMT,
422
  QUERY_NODE_KILL_CONNECTION_STMT,
423
  QUERY_NODE_KILL_QUERY_STMT,
424
  QUERY_NODE_KILL_TRANSACTION_STMT,
425
  QUERY_NODE_KILL_COMPACT_STMT,
426
  QUERY_NODE_DELETE_STMT,
427
  QUERY_NODE_INSERT_STMT,
428
  QUERY_NODE_QUERY,
429
  QUERY_NODE_SHOW_DB_ALIVE_STMT,
430
  QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
431
  QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
432
  QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT,
433
  QUERY_NODE_RESTORE_DNODE_STMT,
434
  QUERY_NODE_RESTORE_QNODE_STMT,
435
  QUERY_NODE_RESTORE_MNODE_STMT,
436
  QUERY_NODE_RESTORE_VNODE_STMT,
437
  QUERY_NODE_PAUSE_STREAM_STMT,
438
  QUERY_NODE_RESUME_STREAM_STMT,
439
  QUERY_NODE_CREATE_VIEW_STMT,
440
  QUERY_NODE_DROP_VIEW_STMT,
441
  QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE,
442
  QUERY_NODE_CREATE_ANODE_STMT,
443
  QUERY_NODE_DROP_ANODE_STMT,
444
  QUERY_NODE_UPDATE_ANODE_STMT,
445
  QUERY_NODE_ASSIGN_LEADER_STMT,
446
  QUERY_NODE_SHOW_CREATE_TSMA_STMT,
447
  QUERY_NODE_SHOW_CREATE_VTABLE_STMT,
448
  QUERY_NODE_RECALCULATE_STREAM_STMT,
449
  QUERY_NODE_CREATE_BNODE_STMT,
450
  QUERY_NODE_DROP_BNODE_STMT,
451
  QUERY_NODE_KILL_SSMIGRATE_STMT,
452
  QUERY_NODE_KILL_SCAN_STMT,
453
  QUERY_NODE_CREATE_RSMA_STMT,
454
  QUERY_NODE_DROP_RSMA_STMT,
455
  QUERY_NODE_ALTER_RSMA_STMT,
456
  QUERY_NODE_SHOW_CREATE_RSMA_STMT,
457
  QUERY_NODE_ROLLUP_DATABASE_STMT,
458
  QUERY_NODE_ROLLUP_VGROUPS_STMT,
459
  QUERY_NODE_KILL_RETENTION_STMT,
460
  QUERY_NODE_SET_VGROUP_KEEP_VERSION_STMT,
461
  QUERY_NODE_CREATE_ENCRYPT_ALGORITHMS_STMT,
462
  QUERY_NODE_DROP_ENCRYPT_ALGR_STMT,
463

464
  // show statement nodes
465
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
466
  QUERY_NODE_SHOW_DNODES_STMT = 400,
467
  QUERY_NODE_SHOW_MNODES_STMT,
468
  QUERY_NODE_SHOW_MODULES_STMT,
469
  QUERY_NODE_SHOW_QNODES_STMT,
470
  QUERY_NODE_SHOW_SNODES_STMT,
471
  QUERY_NODE_SHOW_BACKUP_NODES_STMT,  // no longer used
472
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
473
  QUERY_NODE_SHOW_CLUSTER_STMT,
474
  QUERY_NODE_SHOW_DATABASES_STMT,
475
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
476
  QUERY_NODE_SHOW_INDEXES_STMT,
477
  QUERY_NODE_SHOW_STABLES_STMT,
478
  QUERY_NODE_SHOW_STREAMS_STMT,
479
  QUERY_NODE_SHOW_TABLES_STMT,
480
  QUERY_NODE_SHOW_TAGS_STMT,
481
  QUERY_NODE_SHOW_USERS_STMT,
482
  QUERY_NODE_SHOW_USERS_FULL_STMT,
483
  QUERY_NODE_SHOW_LICENCES_STMT,
484
  QUERY_NODE_SHOW_VGROUPS_STMT,
485
  QUERY_NODE_SHOW_TOPICS_STMT,
486
  QUERY_NODE_SHOW_CONSUMERS_STMT,
487
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
488
  QUERY_NODE_SHOW_QUERIES_STMT,
489
  QUERY_NODE_SHOW_APPS_STMT,
490
  QUERY_NODE_SHOW_VARIABLES_STMT,
491
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
492
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
493
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
494
  QUERY_NODE_SHOW_VNODES_STMT,
495
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
496
  QUERY_NODE_SHOW_VIEWS_STMT,
497
  QUERY_NODE_SHOW_COMPACTS_STMT,
498
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
499
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
500
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
501
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
502
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
503
  QUERY_NODE_SHOW_TSMAS_STMT,
504
  QUERY_NODE_SHOW_ANODES_STMT,
505
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
506
  QUERY_NODE_SHOW_USAGE_STMT,
507
  QUERY_NODE_SHOW_FILESETS_STMT,
508
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
509
  QUERY_NODE_SHOW_VTABLES_STMT,
510
  QUERY_NODE_SHOW_BNODES_STMT,
511
  QUERY_NODE_SHOW_MOUNTS_STMT,
512
  QUERY_NODE_SHOW_SSMIGRATES_STMT,
513
  QUERY_NODE_SHOW_SCANS_STMT,
514
  QUERY_NODE_SHOW_SCAN_DETAILS_STMT,
515
  QUERY_NODE_SHOW_RSMAS_STMT,
516
  QUERY_NODE_SHOW_RETENTIONS_STMT,
517
  QUERY_NODE_SHOW_RETENTION_DETAILS_STMT,
518
  QUERY_NODE_SHOW_INSTANCES_STMT,
519
  QUERY_NODE_SHOW_ENCRYPT_ALGORITHMS_STMT,
520

521
  // logic plan node
522
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
523
  QUERY_NODE_LOGIC_PLAN_JOIN,
524
  QUERY_NODE_LOGIC_PLAN_AGG,
525
  QUERY_NODE_LOGIC_PLAN_PROJECT,
526
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
527
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
528
  QUERY_NODE_LOGIC_PLAN_MERGE,
529
  QUERY_NODE_LOGIC_PLAN_WINDOW,
530
  QUERY_NODE_LOGIC_PLAN_FILL,
531
  QUERY_NODE_LOGIC_PLAN_SORT,
532
  QUERY_NODE_LOGIC_PLAN_PARTITION,
533
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
534
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
535
  QUERY_NODE_LOGIC_SUBPLAN,
536
  QUERY_NODE_LOGIC_PLAN,
537
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
538
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
539
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
540
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
541
  QUERY_NODE_LOGIC_PLAN_ANALYSIS_FUNC,
542

543
  // physical plan node
544
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
545
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
546
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
547
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
548
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
549
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
550
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
551
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
552
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
553
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
554
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
555
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
556
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
557
  QUERY_NODE_PHYSICAL_PLAN_SORT,
558
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
559
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
560
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
561
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
562
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_1,
563
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_2,
564
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_3,
565
  QUERY_NODE_PHYSICAL_PLAN_FILL,
566
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_4,
567
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
568
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_5,
569
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_6,
570
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_7,
571
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
572
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_8,
573
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
574
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_9,
575
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
576
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
577
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
578
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
579
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
580
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
581
  QUERY_NODE_PHYSICAL_SUBPLAN,
582
  QUERY_NODE_PHYSICAL_PLAN,
583
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
584
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
585
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_10,
586
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
587
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
588
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
589
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
590
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_11,
591
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_12,
592
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_13,
593
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
594
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_14,
595
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
596
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_15,
597
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_16,
598
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_17,
599
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_18,
600
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_19,
601
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_20,
602
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_21,
603
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_22,
604
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_23,
605
  QUERY_NODE_PHYSICAL_PLAN_UNUSED_24,
606
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
607
  QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW,
608
  QUERY_NODE_PHYSICAL_PLAN_HASH_EXTERNAL,
609
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_EXTERNAL,
610
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INSERT,
611
  QUERY_NODE_PHYSICAL_PLAN_ANALYSIS_FUNC,
612
} ENodeType;
613

614
typedef struct {
615
  int32_t     vgId;
616
  uint8_t     option;         // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
617
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
618
  const char* dbFName;
619
  const char* tbName;
620
} SBuildTableInput;
621

622
typedef struct {
623
  char    db[TSDB_DB_FNAME_LEN];
624
  int64_t dbId;
625
  int32_t vgVersion;
626
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
627
  int64_t stateTs;
628
} SBuildUseDBInput;
629

630
typedef struct SField {
631
  char    name[TSDB_COL_NAME_LEN];
632
  uint8_t type;
633
  int8_t  flags;
634
  int32_t bytes;
635
} SField;
636

637
typedef struct SFieldWithOptions {
638
  char     name[TSDB_COL_NAME_LEN];
639
  uint8_t  type;
640
  int8_t   flags;
641
  int32_t  bytes;
642
  uint32_t compress;
643
  STypeMod typeMod;
644
} SFieldWithOptions;
645

646
typedef struct SRetention {
647
  int64_t freq;
648
  int64_t keep;
649
  int8_t  freqUnit;
650
  int8_t  keepUnit;
651
} SRetention;
652

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

655
#pragma pack(push, 1)
656
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
657
typedef struct SEp {
658
  char     fqdn[TSDB_FQDN_LEN];
659
  uint16_t port;
660
} SEp;
661

662
typedef struct {
663
  int32_t contLen;
664
  int32_t vgId;
665
} SMsgHead;
666

667
// Submit message for one table
668
typedef struct SSubmitBlk {
669
  int64_t uid;        // table unique id
670
  int64_t suid;       // stable id
671
  int32_t sversion;   // data schema version
672
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
673
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
674
  int32_t numOfRows;  // total number of rows in current submit block
675
  char    data[];
676
} SSubmitBlk;
677

678
// Submit message for this TSDB
679
typedef struct {
680
  SMsgHead header;
681
  int64_t  version;
682
  int32_t  length;
683
  int32_t  numOfBlocks;
684
  char     blocks[];
685
} SSubmitReq;
686

687
typedef struct {
688
  int32_t totalLen;
689
  int32_t len;
690
  STSRow* row;
691
} SSubmitBlkIter;
692

693
typedef struct {
694
  int32_t totalLen;
695
  int32_t len;
696
  // head of SSubmitBlk
697
  int64_t uid;        // table unique id
698
  int64_t suid;       // stable id
699
  int32_t sversion;   // data schema version
700
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
701
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
702
  int32_t numOfRows;  // total number of rows in current submit block
703
  // head of SSubmitBlk
704
  int32_t     numOfBlocks;
705
  const void* pMsg;
706
} SSubmitMsgIter;
707

708
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
709
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
710
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
711
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
712
// for debug
713
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
714

715
typedef struct {
716
  bool     hasRef;
717
  col_id_t id;
718
  char     refDbName[TSDB_DB_NAME_LEN];
719
  char     refTableName[TSDB_TABLE_NAME_LEN];
720
  char     refColName[TSDB_COL_NAME_LEN];
721
} SColRef;
722

723
typedef struct {
724
  int32_t  nCols;
725
  int32_t  version;
726
  SColRef* pColRef;
727
} SColRefWrapper;
728

729
int32_t tEncodeSColRefWrapper(SEncoder* pCoder, const SColRefWrapper* pWrapper);
730
int32_t tDecodeSColRefWrapperEx(SDecoder* pDecoder, SColRefWrapper* pWrapper, bool decoderMalloc);
731
typedef struct {
732
  int32_t vgId;
733
  SColRef colRef;
734
} SColRefEx;
735

736
typedef struct {
737
  int16_t colId;
738
  char    refDbName[TSDB_DB_NAME_LEN];
739
  char    refTableName[TSDB_TABLE_NAME_LEN];
740
  char    refColName[TSDB_COL_NAME_LEN];
741
} SRefColInfo;
742

743
typedef struct SVCTableRefCols {
744
  uint64_t     uid;
745
  int32_t      numOfSrcTbls;
746
  int32_t      numOfColRefs;
747
  SRefColInfo* refCols;
748
} SVCTableRefCols;
749

750
typedef struct SVCTableMergeInfo {
751
  uint64_t uid;
752
  int32_t  numOfSrcTbls;
753
} SVCTableMergeInfo;
754

755
typedef struct {
756
  int32_t    nCols;
757
  SColRefEx* pColRefEx;
758
} SColRefExWrapper;
759

760
struct SSchema {
761
  int8_t   type;
762
  int8_t   flags;
763
  col_id_t colId;
764
  int32_t  bytes;
765
  char     name[TSDB_COL_NAME_LEN];
766
};
767
struct SSchemaExt {
768
  col_id_t colId;
769
  uint32_t compress;
770
  STypeMod typeMod;
771
};
772

773
struct SSchemaRsma {
774
  int64_t    interval[2];
775
  int32_t    nFuncs;
776
  int8_t     tbType;
777
  tb_uid_t   tbUid;
778
  func_id_t* funcIds;
779
  char       tbName[TSDB_TABLE_NAME_LEN];
780
};
781

782
struct SSchema2 {
783
  int8_t   type;
784
  int8_t   flags;
785
  col_id_t colId;
786
  int32_t  bytes;
787
  char     name[TSDB_COL_NAME_LEN];
788
  uint32_t compress;
789
};
790

791
typedef struct {
792
  char        tbName[TSDB_TABLE_NAME_LEN];
793
  char        stbName[TSDB_TABLE_NAME_LEN];
794
  char        dbFName[TSDB_DB_FNAME_LEN];
795
  int64_t     dbId;
796
  int32_t     numOfTags;
797
  int32_t     numOfColumns;
798
  int8_t      precision;
799
  int8_t      tableType;
800
  int32_t     sversion;
801
  int32_t     tversion;
802
  int32_t     rversion;
803
  uint64_t    suid;
804
  uint64_t    tuid;
805
  int32_t     vgId;
806
  int8_t      sysInfo;
807
  SSchema*    pSchemas;
808
  SSchemaExt* pSchemaExt;
809
  int8_t      virtualStb;
810
  int32_t     numOfColRefs;
811
  SColRef*    pColRefs;
812
} STableMetaRsp;
813

814
typedef struct {
815
  int32_t        code;
816
  int64_t        uid;
817
  char*          tblFName;
818
  int32_t        numOfRows;
819
  int32_t        affectedRows;
820
  int64_t        sver;
821
  STableMetaRsp* pMeta;
822
} SSubmitBlkRsp;
823

824
typedef struct {
825
  int32_t numOfRows;
826
  int32_t affectedRows;
827
  int32_t nBlocks;
828
  union {
829
    SArray*        pArray;
830
    SSubmitBlkRsp* pBlocks;
831
  };
832
} SSubmitRsp;
833

834
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
835
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
836
// void    tFreeSSubmitBlkRsp(void* param);
837
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
838

839
#define COL_SMA_ON       ((int8_t)0x1)
840
#define COL_IDX_ON       ((int8_t)0x2)
841
#define COL_IS_KEY       ((int8_t)0x4)
842
#define COL_SET_NULL     ((int8_t)0x10)
843
#define COL_SET_VAL      ((int8_t)0x20)
844
#define COL_IS_SYSINFO   ((int8_t)0x40)
845
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
846
#define COL_REF_BY_STM   ((int8_t)0x08)
847

848
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
849
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
850

851
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
852
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
853
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
854

855
#define SSCHMEA_SET_IDX_ON(s) \
856
  do {                        \
857
    (s)->flags |= COL_IDX_ON; \
858
  } while (0)
859

860
#define SSCHMEA_SET_IDX_OFF(s)   \
861
  do {                           \
862
    (s)->flags &= (~COL_IDX_ON); \
863
  } while (0)
864

865
#define SSCHEMA_SET_TYPE_MOD(s)     \
866
  do {                              \
867
    (s)->flags |= COL_HAS_TYPE_MOD; \
868
  } while (0)
869

870
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
871

872
#define SSCHMEA_TYPE(s)  ((s)->type)
873
#define SSCHMEA_FLAGS(s) ((s)->flags)
874
#define SSCHMEA_COLID(s) ((s)->colId)
875
#define SSCHMEA_BYTES(s) ((s)->bytes)
876
#define SSCHMEA_NAME(s)  ((s)->name)
877

878
typedef struct {
879
  bool    tsEnableMonitor;
880
  int32_t tsMonitorInterval;
881
  int32_t tsSlowLogThreshold;
882
  int32_t tsSlowLogMaxLen;
883
  int32_t tsSlowLogScope;
884
  int32_t tsSlowLogThresholdTest;  // Obsolete
885
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
886
} SMonitorParas;
887

888
typedef struct {
889
  STypeMod typeMod;
890
} SExtSchema;
891

892
bool hasExtSchema(const SExtSchema* pExtSchema);
893

894
typedef struct {
895
  int32_t      nCols;
896
  int32_t      version;
897
  SSchema*     pSchema;
898
  SSchemaRsma* pRsma;
899
} SSchemaWrapper;
900

901
typedef struct {
902
  col_id_t id;
903
  uint32_t alg;
904
} SColCmpr;
905

906
typedef struct {
907
  int32_t   nCols;
908
  int32_t   version;
909
  SColCmpr* pColCmpr;
910
} SColCmprWrapper;
911

912
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
913
  if (pRef->pColRef) {
383,740✔
914
    return TSDB_CODE_INVALID_PARA;
×
915
  }
916
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
383,740✔
917
  if (pRef->pColRef == NULL) {
383,740✔
918
    return terrno;
×
919
  }
920
  pRef->nCols = nCols;
383,740✔
921
  for (int32_t i = 0; i < nCols; i++) {
4,761,445✔
922
    pRef->pColRef[i].hasRef = false;
4,377,705✔
923
    pRef->pColRef[i].id = (col_id_t)(i + 1);
4,377,705✔
924
  }
925
  return 0;
383,740✔
926
}
927

928
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
929
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
930
    terrno = TSDB_CODE_INVALID_PARA;
931
    return NULL;
932
  }
933

934
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
935
  if (pDstWrapper == NULL) {
936
    return NULL;
937
  }
938
  pDstWrapper->nCols = pSrcWrapper->nCols;
939
  pDstWrapper->version = pSrcWrapper->version;
940

941
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
942
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
943
  if (pDstWrapper->pColCmpr == NULL) {
944
    taosMemoryFree(pDstWrapper);
945
    return NULL;
946
  }
947
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
948

949
  return pDstWrapper;
950
}
951

952
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
953
  if (!(!pCmpr->pColCmpr)) {
2,308,467✔
954
    return TSDB_CODE_INVALID_PARA;
×
955
  }
956
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
2,308,467✔
957
  if (pCmpr->pColCmpr == NULL) {
2,308,467✔
958
    return terrno;
×
959
  }
960
  pCmpr->nCols = nCols;
2,308,467✔
961
  return 0;
2,308,467✔
962
}
963

964
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
965
  pCmpr->nCols = pSchema->nCols;
966
  if (!(!pCmpr->pColCmpr)) {
967
    return TSDB_CODE_INVALID_PARA;
968
  }
969
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
970
  if (pCmpr->pColCmpr == NULL) {
971
    return terrno;
972
  }
973
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
974
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
975
    SSchema*  pColSchema = &pSchema->pSchema[i];
976
    pColCmpr->id = pColSchema->colId;
977
    pColCmpr->alg = 0;
978
  }
979
  return 0;
980
}
981

982
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
983
  if (pWrapper == NULL) return;
984

985
  taosMemoryFreeClear(pWrapper->pColCmpr);
986
  taosMemoryFreeClear(pWrapper);
987
}
988
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
989
  if (pSchemaWrapper->pSchema == NULL) return NULL;
318,877,781✔
990

991
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
318,780,020✔
992
  if (pSW == NULL) {
318,889,983✔
993
    return NULL;
×
994
  }
995
  pSW->nCols = pSchemaWrapper->nCols;
318,889,983✔
996
  pSW->version = pSchemaWrapper->version;
318,815,124✔
997
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
318,850,954✔
998
  if (pSW->pSchema == NULL) {
318,754,115✔
999
    taosMemoryFree(pSW);
×
1000
    return NULL;
×
1001
  }
1002

1003
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
318,788,888✔
1004
  return pSW;
318,863,658✔
1005
}
1006

1007
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
93,757,088✔
1008
  if (pSchemaWrapper) {
859,667,029✔
1009
    taosMemoryFree(pSchemaWrapper->pSchema);
478,106,411✔
1010
    if (pSchemaWrapper->pRsma) {
478,082,741✔
1011
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
28,656✔
1012
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
28,656✔
1013
    }
1014
    taosMemoryFree(pSchemaWrapper);
478,025,445✔
1015
  }
1016
}
846,612,142✔
1017

1018
static FORCE_INLINE void tDestroySchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
1019
  if (pSchemaWrapper) {
1020
    taosMemoryFreeClear(pSchemaWrapper->pSchema);
1021
    if (pSchemaWrapper->pRsma) {
1022
      taosMemoryFreeClear(pSchemaWrapper->pRsma->funcIds);
1023
      taosMemoryFreeClear(pSchemaWrapper->pRsma);
1024
    }
1025
  }
1026
}
1027

1028
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,421,647✔
1029
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,421,647✔
1030
    tDeleteSchemaWrapper(*(SSchemaWrapper**)pSchemaWrapper);
1,421,647✔
1031
  }
1032
}
1,421,647✔
1033

1034
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
1035
  int32_t tlen = 0;
1,371,062✔
1036
  tlen += taosEncodeFixedI8(buf, pSchema->type);
1,371,134✔
1037
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
1,371,062✔
1038
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
1,371,062✔
1039
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
1,371,062✔
1040
  tlen += taosEncodeString(buf, pSchema->name);
1,371,062✔
1041
  return tlen;
1,371,062✔
1042
}
1043

1044
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
1045
  buf = taosDecodeFixedI8(buf, &pSchema->type);
605,064✔
1046
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
605,046✔
1047
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
605,046✔
1048
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
605,046✔
1049
  buf = taosDecodeStringTo(buf, pSchema->name);
605,046✔
1050
  return (void*)buf;
605,046✔
1051
}
1052

1053
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
1054
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
2,147,483,647✔
1055
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
2,147,483,647✔
1056
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
2,147,483,647✔
1057
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
2,147,483,647✔
1058
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
2,147,483,647✔
1059
  return 0;
2,147,483,647✔
1060
}
1061

1062
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
1063
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
2,147,483,647✔
1064
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
2,147,483,647✔
1065
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
2,147,483,647✔
1066
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
2,147,483,647✔
1067
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
2,147,483,647✔
1068
  return 0;
2,147,483,647✔
1069
}
1070

1071
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
1072
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
2,147,483,647✔
1073
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
2,147,483,647✔
1074
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
2,147,483,647✔
1075
  return 0;
2,147,483,647✔
1076
}
1077

1078
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
1079
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
2,147,483,647✔
1080
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
2,147,483,647✔
1081
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
2,147,483,647✔
1082
  return 0;
2,147,483,647✔
1083
}
1084

1085
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
1086
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
23,818,148✔
1087
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
23,818,148✔
1088
  if (pColRef->hasRef) {
11,909,074✔
1089
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
13,191,100✔
1090
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
13,191,100✔
1091
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
13,191,100✔
1092
  }
1093
  return 0;
11,909,074✔
1094
}
1095

1096
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
1097
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
14,846,260✔
1098
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
14,846,260✔
1099
  if (pColRef->hasRef) {
7,423,130✔
1100
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
4,288,785✔
1101
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
4,288,785✔
1102
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
4,288,785✔
1103
  }
1104

1105
  return 0;
7,423,130✔
1106
}
1107

1108
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
1109
  int32_t tlen = 0;
179,374✔
1110
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
179,374✔
1111
  tlen += taosEncodeVariantI32(buf, pSW->version);
179,374✔
1112
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,550,436✔
1113
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
2,742,124✔
1114
  }
1115
  return tlen;
179,374✔
1116
}
1117

1118
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
1119
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
76,251✔
1120
  buf = taosDecodeVariantI32(buf, &pSW->version);
76,251✔
1121
  if (pSW->nCols > 0) {
76,251✔
1122
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
76,251✔
1123
    if (pSW->pSchema == NULL) {
76,251✔
1124
      return NULL;
×
1125
    }
1126

1127
    for (int32_t i = 0; i < pSW->nCols; i++) {
681,297✔
1128
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
1,210,092✔
1129
    }
1130
  } else {
1131
    pSW->pSchema = NULL;
×
1132
  }
1133
  return (void*)buf;
76,251✔
1134
}
1135

1136
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1137
  if (pSW == NULL) {
273,911,611✔
1138
    return TSDB_CODE_INVALID_PARA;
×
1139
  }
1140
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
547,905,550✔
1141
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
547,912,137✔
1142
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1143
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
2,147,483,647✔
1144
  }
1145
  return 0;
274,055,343✔
1146
}
1147

1148
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1149
  if (pSW == NULL) {
74,895,300✔
1150
    return TSDB_CODE_INVALID_PARA;
×
1151
  }
1152
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
149,778,474✔
1153
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
149,784,558✔
1154

1155
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
74,901,384✔
1156
  if (pSW->pSchema == NULL) {
74,858,516✔
1157
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1158
  }
1159
  for (int32_t i = 0; i < pSW->nCols; i++) {
726,651,380✔
1160
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,303,416,567✔
1161
  }
1162

1163
  return 0;
74,928,754✔
1164
}
1165

1166
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1167
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,147,483,647✔
1168
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,147,483,647✔
1169

1170
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
2,147,483,647✔
1171
  if (pSW->pSchema == NULL) {
1,399,826,500✔
1172
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1173
  }
1174
  for (int32_t i = 0; i < pSW->nCols; i++) {
2,147,483,647✔
1175
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,147,483,647✔
1176
  }
1177

1178
  return 0;
1,400,123,544✔
1179
}
1180

1181
typedef struct {
1182
  char     name[TSDB_TABLE_FNAME_LEN];
1183
  int8_t   igExists;
1184
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1185
  int8_t   reserved[6];
1186
  tb_uid_t suid;
1187
  int64_t  delay1;
1188
  int64_t  delay2;
1189
  int64_t  watermark1;
1190
  int64_t  watermark2;
1191
  int32_t  ttl;
1192
  int32_t  colVer;
1193
  int32_t  tagVer;
1194
  int32_t  numOfColumns;
1195
  int32_t  numOfTags;
1196
  int32_t  numOfFuncs;
1197
  int32_t  commentLen;
1198
  int32_t  ast1Len;
1199
  int32_t  ast2Len;
1200
  SArray*  pColumns;  // array of SFieldWithOptions
1201
  SArray*  pTags;     // array of SField
1202
  SArray*  pFuncs;
1203
  char*    pComment;
1204
  char*    pAst1;
1205
  char*    pAst2;
1206
  int64_t  deleteMark1;
1207
  int64_t  deleteMark2;
1208
  int32_t  sqlLen;
1209
  char*    sql;
1210
  int64_t  keep;
1211
  int8_t   virtualStb;
1212
} SMCreateStbReq;
1213

1214
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1215
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1216
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1217

1218
typedef struct {
1219
  STableMetaRsp* pMeta;
1220
} SMCreateStbRsp;
1221

1222
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1223
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1224
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1225

1226
typedef struct {
1227
  char     name[TSDB_TABLE_FNAME_LEN];
1228
  int8_t   igNotExists;
1229
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1230
  int8_t   reserved[6];
1231
  tb_uid_t suid;
1232
  int32_t  sqlLen;
1233
  char*    sql;
1234
} SMDropStbReq;
1235

1236
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1237
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1238
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1239

1240
typedef struct {
1241
  char    name[TSDB_TABLE_FNAME_LEN];
1242
  int8_t  alterType;
1243
  int32_t numOfFields;
1244
  SArray* pFields;
1245
  int32_t ttl;
1246
  int32_t commentLen;
1247
  char*   comment;
1248
  int32_t sqlLen;
1249
  char*   sql;
1250
  int64_t keep;
1251
  SArray* pTypeMods;
1252
} SMAlterStbReq;
1253

1254
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1255
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1256
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1257

1258
typedef struct SEpSet {
1259
  int8_t inUse;
1260
  int8_t numOfEps;
1261
  SEp    eps[TSDB_MAX_REPLICA];
1262
} SEpSet;
1263

1264
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1265
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1266
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1267
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1268

1269
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1270
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1271

1272
typedef struct {
1273
  int8_t  connType;
1274
  int32_t pid;
1275
  char    app[TSDB_APP_NAME_LEN];
1276
  char    db[TSDB_DB_NAME_LEN];
1277
  char    user[TSDB_USER_LEN];
1278
  char    passwd[TSDB_PASSWORD_LEN];
1279
  int64_t startTime;
1280
  char    sVer[TSDB_VERSION_LEN];
1281
  int32_t totpCode;
1282
} SConnectReq;
1283

1284
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1285
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1286

1287
typedef struct {
1288
  int64_t       clusterId;
1289
  int32_t       acctId;
1290
  uint32_t      connId;
1291
  int32_t       dnodeNum;
1292
  int8_t        superUser;
1293
  int8_t        sysInfo;
1294
  int8_t        connType;
1295
  SEpSet        epSet;
1296
  int32_t       svrTimestamp;
1297
  int32_t       passVer;
1298
  int32_t       authVer;
1299
  char          sVer[TSDB_VERSION_LEN];
1300
  char          sDetailVer[128];
1301
  int64_t       whiteListVer;
1302
  int64_t       timeWhiteListVer;
1303
  SMonitorParas monitorParas;
1304
  int8_t        enableAuditDelete;
1305
  int8_t        enableAuditSelect;
1306
  int8_t        enableAuditInsert;
1307
  int8_t        auditLevel;
1308
} SConnectRsp;
1309

1310
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1311
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1312

1313
typedef struct {
1314
  char    user[TSDB_USER_LEN];
1315
  char    pass[TSDB_PASSWORD_LEN];
1316
  int32_t maxUsers;
1317
  int32_t maxDbs;
1318
  int32_t maxTimeSeries;
1319
  int32_t maxStreams;
1320
  int32_t accessState;  // Configured only by command
1321
  int64_t maxStorage;
1322
} SCreateAcctReq, SAlterAcctReq;
1323

1324
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1325
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1326

1327
typedef struct {
1328
  char    user[TSDB_USER_LEN];
1329
  int32_t sqlLen;
1330
  char*   sql;
1331
} SDropUserReq, SDropAcctReq;
1332

1333
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1334
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1335
void    tFreeSDropUserReq(SDropUserReq* pReq);
1336

1337
typedef struct {
1338
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1339
  int32_t sqlLen;
1340
  char*   sql;
1341
} SDropEncryptAlgrReq;
1342

1343
int32_t tSerializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1344
int32_t tDeserializeSDropEncryptAlgrReq(void* buf, int32_t bufLen, SDropEncryptAlgrReq* pReq);
1345
void    tFreeSDropEncryptAlgrReq(SDropEncryptAlgrReq* pReq);
1346

1347
typedef struct SIpV4Range {
1348
  uint32_t ip;
1349
  uint32_t mask;
1350
} SIpV4Range;
1351

1352
typedef struct SIpv6Range {
1353
  uint64_t addr[2];
1354
  uint32_t mask;
1355
} SIpV6Range;
1356

1357
typedef struct {
1358
  int8_t type;   // 0: IPv4, 1: IPv6
1359
  int8_t neg;    // only used in SIpWhiteListDual, if neg is 1, means this is a blacklist entry
1360
  union {
1361
    SIpV4Range ipV4;
1362
    SIpV6Range ipV6;
1363
  };
1364
} SIpRange;
1365

1366
typedef struct {
1367
  int32_t    num;
1368
  SIpV4Range pIpRange[];
1369
} SIpWhiteList;
1370

1371
typedef struct {
1372
  int32_t  num;
1373
  SIpRange pIpRanges[];
1374
} SIpWhiteListDual;
1375

1376
SIpWhiteListDual* cloneIpWhiteList(const SIpWhiteListDual* src);
1377
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1378
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1379
int32_t           createDefaultIp6Range(SIpRange* pRange);
1380
int32_t           createDefaultIp4Range(SIpRange* pRange);
1381

1382
typedef struct {
1383
  int32_t sessPerUser;
1384
  int32_t sessConnTime;
1385
  int32_t sessConnIdleTime;
1386
  int32_t sessMaxConcurrency;
1387
  int32_t sessMaxCallVnodeNum;
1388
} SUserSessCfg;
1389

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

1394
// SDateTimeRange is used in client side during SQL statement parsing, client sends this structure
1395
// to server, and server will convert it to SDateTimeWhiteListItem for internal usage.
1396
typedef struct {
1397
  int16_t year;
1398
  int8_t month; // 1-12, when month is -1, it means day is week day and year is not used.
1399
  int8_t day;   // 1-31 or 0-6 (0 means Sunday), depends on the month value.
1400
  int8_t hour;
1401
  int8_t minute;
1402
  int8_t neg;   // this is a negative entry
1403
  int32_t duration; // duration in minute
1404
} SDateTimeRange;
1405

1406
bool isValidDateTimeRange(SDateTimeRange* pRange);
1407
int32_t tEncodeSDateTimeRange(SEncoder* pEncoder, const SDateTimeRange* pRange);
1408
int32_t tDecodeSDateTimeRange(SDecoder* pDecoder, SDateTimeRange* pRange);
1409

1410

1411
// SDateTimeWhiteListItem is used by server internally to represent datetime ranges. 
1412
typedef struct {
1413
  bool absolute;    // true: absolute datetime range; false: weekly recurring datetime range
1414
  bool neg;         // this is a negative entry
1415
  int32_t duration; // duration in seconds
1416
  int64_t start;    // absolute timestamp in seconds or weekly offset in seconds
1417
} SDateTimeWhiteListItem;
1418

1419
void DateTimeRangeToWhiteListItem(SDateTimeWhiteListItem* dst, const SDateTimeRange* src);
1420
bool isDateTimeWhiteListItemExpired(const SDateTimeWhiteListItem* item);
1421

1422
typedef struct {
1423
  int32_t num;
1424
  SDateTimeWhiteListItem ranges[];
1425
} SDateTimeWhiteList;
1426

1427
SDateTimeWhiteList* cloneDateTimeWhiteList(const SDateTimeWhiteList* src);
1428
bool isTimeInDateTimeWhiteList(const SDateTimeWhiteList *wl, int64_t tm);
1429

1430

1431
typedef struct {
1432
  int8_t createType;
1433
  int8_t superUser;  // denote if it is a super user or not
1434
  int8_t ignoreExisting;
1435

1436
  char   user[TSDB_USER_LEN];
1437
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1438
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1439

1440
  int8_t sysInfo;
1441
  int8_t createDb;
1442
  int8_t isImport;
1443
  int8_t changepass;
1444
  int8_t enable;
1445

1446
  int8_t negIpRanges;
1447
  int8_t negTimeRanges;
1448

1449
  int32_t sessionPerUser;
1450
  int32_t connectTime;
1451
  int32_t connectIdleTime;
1452
  int32_t callPerSession;
1453
  int32_t vnodePerCall;
1454
  int32_t failedLoginAttempts;
1455
  int32_t passwordLifeTime;
1456
  int32_t passwordReuseTime;
1457
  int32_t passwordReuseMax;
1458
  int32_t passwordLockTime;
1459
  int32_t passwordGraceTime;
1460
  int32_t inactiveAccountTime;
1461
  int32_t allowTokenNum;
1462

1463
  int32_t         numIpRanges;
1464
  SIpRange*       pIpDualRanges;
1465
  int32_t         numTimeRanges;
1466
  SDateTimeRange* pTimeRanges;
1467

1468
  int32_t sqlLen;
1469
  char*   sql;
1470
} SCreateUserReq;
1471

1472
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1473
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1474
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1475

1476
typedef struct {
1477
  char    algorithmId[TSDB_ENCRYPT_ALGR_NAME_LEN];
1478
  char    name[TSDB_ENCRYPT_ALGR_NAME_LEN];
1479
  char    desc[TSDB_ENCRYPT_ALGR_DESC_LEN];
1480
  char    type[TSDB_ENCRYPT_ALGR_TYPE_LEN];
1481
  char    osslAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1482
  int32_t sqlLen;
1483
  char*   sql;
1484
} SCreateEncryptAlgrReq;
1485

1486
int32_t tSerializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1487
int32_t tDeserializeSCreateEncryptAlgrReq(void* buf, int32_t bufLen, SCreateEncryptAlgrReq* pReq);
1488
void    tFreeSCreateEncryptAlgrReq(SCreateEncryptAlgrReq* pReq);
1489

1490
typedef struct {
1491
  int32_t dnodeId;
1492
  int64_t analVer;
1493
} SRetrieveAnalyticsAlgoReq;
1494

1495
typedef struct {
1496
  int64_t   ver;
1497
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1498
} SRetrieveAnalyticAlgoRsp;
1499

1500
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1501
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1502
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1503
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1504
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1505

1506
typedef struct {
1507
  int8_t alterType;
1508

1509
  int8_t isView;
1510
  
1511
  int8_t hasPassword;
1512
  int8_t hasTotpseed;
1513
  int8_t hasEnable;
1514
  int8_t hasSysinfo;
1515
  int8_t hasCreatedb;
1516
  int8_t hasChangepass;
1517
  int8_t hasSessionPerUser;
1518
  int8_t hasConnectTime;
1519
  int8_t hasConnectIdleTime;
1520
  int8_t hasCallPerSession;
1521
  int8_t hasVnodePerCall;
1522
  int8_t hasFailedLoginAttempts;
1523
  int8_t hasPasswordLifeTime;
1524
  int8_t hasPasswordReuseTime;
1525
  int8_t hasPasswordReuseMax;
1526
  int8_t hasPasswordLockTime;
1527
  int8_t hasPasswordGraceTime;
1528
  int8_t hasInactiveAccountTime;
1529
  int8_t hasAllowTokenNum;
1530

1531
  int8_t enable;
1532
  int8_t sysinfo;
1533
  int8_t createdb;
1534
  int8_t changepass;
1535

1536
  char   user[TSDB_USER_LEN];
1537
  char   pass[TSDB_USER_PASSWORD_LONGLEN];
1538
  char   totpseed[TSDB_USER_TOTPSEED_MAX_LEN + 1];
1539
  int32_t sessionPerUser;
1540
  int32_t connectTime;
1541
  int32_t connectIdleTime;
1542
  int32_t callPerSession;
1543
  int32_t vnodePerCall;
1544
  int32_t failedLoginAttempts;
1545
  int32_t passwordLifeTime;
1546
  int32_t passwordReuseTime;
1547
  int32_t passwordReuseMax;
1548
  int32_t passwordLockTime;
1549
  int32_t passwordGraceTime;
1550
  int32_t inactiveAccountTime;
1551
  int32_t allowTokenNum;
1552

1553
  int32_t         numIpRanges;
1554
  int32_t         numTimeRanges;
1555
  int32_t         numDropIpRanges;
1556
  int32_t         numDropTimeRanges;
1557
  SIpRange*       pIpRanges;
1558
  SDateTimeRange* pTimeRanges;
1559
  SIpRange*       pDropIpRanges;
1560
  SDateTimeRange* pDropTimeRanges;
1561

1562
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1563
  char        tabName[TSDB_TABLE_NAME_LEN];
1564
  char*       tagCond;
1565
  int32_t     tagCondLen;
1566
  int32_t     sqlLen;
1567
  char*       sql;
1568
  int64_t     privileges;
1569
} SAlterUserReq;
1570

1571
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1572
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1573
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1574

1575
typedef struct {
1576
  char user[TSDB_USER_LEN];
1577
} SGetUserAuthReq;
1578

1579
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1580
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1581

1582
typedef struct {
1583
  char      user[TSDB_USER_LEN];
1584
  int32_t   version;
1585
  int32_t   passVer;
1586
  int8_t    superAuth;
1587
  int8_t    sysInfo;
1588
  int8_t    enable;
1589
  int8_t    dropped;
1590
  SHashObj* createdDbs;
1591
  SHashObj* readDbs;
1592
  SHashObj* writeDbs;
1593
  SHashObj* readTbs;
1594
  SHashObj* writeTbs;
1595
  SHashObj* alterTbs;
1596
  SHashObj* readViews;
1597
  SHashObj* writeViews;
1598
  SHashObj* alterViews;
1599
  SHashObj* useDbs;
1600
  int64_t   whiteListVer;
1601

1602
  SUserSessCfg sessCfg;
1603
  int64_t      timeWhiteListVer;
1604
} SGetUserAuthRsp;
1605

1606
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1607
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1608
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1609

1610
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1611
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange, bool supportNeg);
1612
typedef struct {
1613
  int64_t ver;
1614
  char    user[TSDB_USER_LEN];
1615
  int32_t numOfRange;
1616
  union {
1617
    SIpV4Range* pIpRanges;
1618
    SIpRange*   pIpDualRanges;
1619
  };
1620
} SUpdateUserIpWhite;
1621

1622
typedef struct {
1623
  int64_t             ver;
1624
  int                 numOfUser;
1625
  SUpdateUserIpWhite* pUserIpWhite;
1626
} SUpdateIpWhite;
1627

1628
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1629
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1630
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1631
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1632

1633
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1634
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1635
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1636

1637

1638
// SRetrieveWhiteListReq is used to retrieve both ip and datetime whitelist, but the
1639
// corresponding response struct is different.
1640
typedef struct {
1641
  int64_t ver;
1642
} SRetrieveWhiteListReq;
1643

1644
int32_t tSerializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1645
int32_t tDeserializeRetrieveWhiteListReq(void* buf, int32_t bufLen, SRetrieveWhiteListReq* pReq);
1646

1647

1648
// SGetUserWhiteListReq is used to get both ip and datetime whitelist, but the
1649
// corresponding response struct is different.
1650
typedef struct {
1651
  char user[TSDB_USER_LEN];
1652
} SGetUserWhiteListReq;
1653

1654
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1655
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1656

1657
typedef struct {
1658
  char    user[TSDB_USER_LEN];
1659
  int32_t numWhiteLists;
1660
  union {
1661
    SIpV4Range* pWhiteLists;
1662
    SIpRange*   pWhiteListsDual;
1663
  };
1664
} SGetUserIpWhiteListRsp;
1665

1666
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1667
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1668
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1669
void    tIpRangeSetDefaultMask(SIpRange* range);
1670

1671
int32_t tSerializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1672
int32_t tDeserializeSGetUserIpWhiteListRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1673
void    tFreeSGetUserIpWhiteListRsp(SGetUserIpWhiteListRsp* pRsp);
1674

1675
int32_t tSerializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1676
int32_t tDeserializeSGetUserIpWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserIpWhiteListRsp* pRsp);
1677
void    tFreeSGetUserIpWhiteListDualRsp(SGetUserIpWhiteListRsp* pRsp);
1678

1679
typedef struct {
1680
  int64_t ver;
1681
  char    user[TSDB_USER_LEN];
1682
  int32_t numWhiteLists;
1683
  SDateTimeWhiteListItem* pWhiteLists;
1684
} SUserDateTimeWhiteList;
1685

1686

1687
int32_t tSerializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1688
int32_t tDeserializeSUserDateTimeWhiteList(void* buf, int32_t bufLen, SUserDateTimeWhiteList* pRsp);
1689
void    tFreeSUserDateTimeWhiteList(SUserDateTimeWhiteList* pRsp);
1690
int32_t cloneSUserDateTimeWhiteList(const SUserDateTimeWhiteList* src, SUserDateTimeWhiteList* dest);
1691

1692
typedef struct {
1693
  int64_t             ver;
1694
  int                 numOfUser;
1695
  SUserDateTimeWhiteList *pUsers;
1696
} SRetrieveDateTimeWhiteListRsp;
1697

1698
int32_t tSerializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1699
int32_t tDeserializeSRetrieveDateTimeWhiteListRsp(void* buf, int32_t bufLen, SRetrieveDateTimeWhiteListRsp* pRsp);
1700
void    tFreeSRetrieveDateTimeWhiteListRsp(SRetrieveDateTimeWhiteListRsp* pRsp);
1701
int32_t cloneDataTimeWhiteListRsp(const SRetrieveDateTimeWhiteListRsp* src, SRetrieveDateTimeWhiteListRsp** dest);
1702

1703
/*
1704
 * for client side struct, only column id, type, bytes are necessary
1705
 * But for data in vnode side, we need all the following information.
1706
 */
1707
typedef struct {
1708
  union {
1709
    col_id_t colId;
1710
    int16_t  slotId;
1711
  };
1712

1713
  uint8_t precision;
1714
  uint8_t scale;
1715
  int32_t bytes;
1716
  int8_t  type;
1717
  uint8_t pk;
1718
  bool    noData;
1719
} SColumnInfo;
1720

1721
typedef struct STimeWindow {
1722
  TSKEY skey;
1723
  TSKEY ekey;
1724
} STimeWindow;
1725

1726
typedef struct SQueryHint {
1727
  bool batchScan;
1728
} SQueryHint;
1729

1730
typedef struct {
1731
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1732
  int32_t tsLen;          // total length of ts comp block
1733
  int32_t tsNumOfBlocks;  // ts comp block numbers
1734
  int32_t tsOrder;        // ts comp block order
1735
} STsBufInfo;
1736

1737
typedef struct {
1738
  void*       timezone;
1739
  char        intervalUnit;
1740
  char        slidingUnit;
1741
  char        offsetUnit;
1742
  int8_t      precision;
1743
  int64_t     interval;
1744
  int64_t     sliding;
1745
  int64_t     offset;
1746
  STimeWindow timeRange;
1747
} SInterval;
1748

1749
typedef struct STbVerInfo {
1750
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1751
  int32_t sversion;
1752
  int32_t tversion;
1753
  int32_t rversion;  // virtual table's column ref's version
1754
} STbVerInfo;
1755

1756
typedef struct {
1757
  int32_t code;
1758
  int64_t affectedRows;
1759
  SArray* tbVerInfo;  // STbVerInfo
1760
} SQueryTableRsp;
1761

1762
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1763

1764
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1765

1766
typedef struct {
1767
  SMsgHead header;
1768
  char     dbFName[TSDB_DB_FNAME_LEN];
1769
  char     tbName[TSDB_TABLE_NAME_LEN];
1770
} STableCfgReq;
1771

1772
typedef struct {
1773
  char        tbName[TSDB_TABLE_NAME_LEN];
1774
  char        stbName[TSDB_TABLE_NAME_LEN];
1775
  char        dbFName[TSDB_DB_FNAME_LEN];
1776
  int32_t     numOfTags;
1777
  int32_t     numOfColumns;
1778
  int8_t      tableType;
1779
  int64_t     delay1;
1780
  int64_t     delay2;
1781
  int64_t     watermark1;
1782
  int64_t     watermark2;
1783
  int32_t     ttl;
1784
  int32_t     keep;
1785
  SArray*     pFuncs;
1786
  int32_t     commentLen;
1787
  char*       pComment;
1788
  SSchema*    pSchemas;
1789
  int32_t     tagsLen;
1790
  char*       pTags;
1791
  SSchemaExt* pSchemaExt;
1792
  int8_t      virtualStb;
1793
  SColRef*    pColRefs;
1794
} STableCfg;
1795

1796
typedef STableCfg STableCfgRsp;
1797

1798
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1799
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1800

1801
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1802
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1803
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1804

1805
typedef struct {
1806
  SMsgHead header;
1807
  tb_uid_t suid;
1808
} SVSubTablesReq;
1809

1810
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1811
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1812

1813
typedef struct {
1814
  int32_t vgId;
1815
  SArray* pTables;  // SArray<SVCTableRefCols*>
1816
} SVSubTablesRsp;
1817

1818
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1819
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1820
void    tDestroySVSubTablesRsp(void* rsp);
1821

1822
typedef struct {
1823
  SMsgHead header;
1824
  tb_uid_t suid;
1825
} SVStbRefDbsReq;
1826

1827
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1828
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1829

1830
typedef struct {
1831
  int32_t vgId;
1832
  SArray* pDbs;  // SArray<char* (db name)>
1833
} SVStbRefDbsRsp;
1834

1835
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1836
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1837
void    tDestroySVStbRefDbsRsp(void* rsp);
1838

1839
typedef struct {
1840
  char    db[TSDB_DB_FNAME_LEN];
1841
  int32_t numOfVgroups;
1842
  int32_t numOfStables;  // single_stable
1843
  int32_t buffer;        // MB
1844
  int32_t pageSize;
1845
  int32_t pages;
1846
  int32_t cacheLastSize;
1847
  int32_t daysPerFile;
1848
  int32_t daysToKeep0;
1849
  int32_t daysToKeep1;
1850
  int32_t daysToKeep2;
1851
  int32_t keepTimeOffset;
1852
  int32_t minRows;
1853
  int32_t maxRows;
1854
  int32_t walFsyncPeriod;
1855
  int8_t  walLevel;
1856
  int8_t  precision;  // time resolution
1857
  int8_t  compression;
1858
  int8_t  replications;
1859
  int8_t  strict;
1860
  int8_t  cacheLast;
1861
  int8_t  schemaless;
1862
  int8_t  ignoreExist;
1863
  int32_t numOfRetensions;
1864
  SArray* pRetensions;  // SRetention
1865
  int32_t walRetentionPeriod;
1866
  int64_t walRetentionSize;
1867
  int32_t walRollPeriod;
1868
  int64_t walSegmentSize;
1869
  int32_t sstTrigger;
1870
  int16_t hashPrefix;
1871
  int16_t hashSuffix;
1872
  int32_t ssChunkSize;
1873
  int32_t ssKeepLocal;
1874
  int8_t  ssCompact;
1875
  int32_t tsdbPageSize;
1876
  int32_t sqlLen;
1877
  char*   sql;
1878
  int8_t  withArbitrator;
1879
  int8_t  encryptAlgorithm;
1880
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1881
  // 1. add auto-compact parameters
1882
  int32_t compactInterval;    // minutes
1883
  int32_t compactStartTime;   // minutes
1884
  int32_t compactEndTime;     // minutes
1885
  int8_t  compactTimeOffset;  // hour
1886
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1887
  int8_t  isAudit;
1888
} SCreateDbReq;
1889

1890
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1891
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1892
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1893

1894
typedef struct {
1895
  char    db[TSDB_DB_FNAME_LEN];
1896
  int32_t buffer;
1897
  int32_t pageSize;
1898
  int32_t pages;
1899
  int32_t cacheLastSize;
1900
  int32_t daysPerFile;
1901
  int32_t daysToKeep0;
1902
  int32_t daysToKeep1;
1903
  int32_t daysToKeep2;
1904
  int32_t keepTimeOffset;
1905
  int32_t walFsyncPeriod;
1906
  int8_t  walLevel;
1907
  int8_t  strict;
1908
  int8_t  cacheLast;
1909
  int8_t  replications;
1910
  int32_t sstTrigger;
1911
  int32_t minRows;
1912
  int32_t walRetentionPeriod;
1913
  int32_t walRetentionSize;
1914
  int32_t ssKeepLocal;
1915
  int8_t  ssCompact;
1916
  int32_t sqlLen;
1917
  char*   sql;
1918
  int8_t  withArbitrator;
1919
  // 1. add auto-compact parameters
1920
  int32_t compactInterval;
1921
  int32_t compactStartTime;
1922
  int32_t compactEndTime;
1923
  int8_t  compactTimeOffset;
1924
  char    encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
1925
  int8_t  isAudit;
1926
} SAlterDbReq;
1927

1928
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1929
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1930
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1931

1932
typedef struct {
1933
  char    db[TSDB_DB_FNAME_LEN];
1934
  int8_t  ignoreNotExists;
1935
  int8_t  force;
1936
  int32_t sqlLen;
1937
  char*   sql;
1938
} SDropDbReq;
1939

1940
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1941
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1942
void    tFreeSDropDbReq(SDropDbReq* pReq);
1943

1944
typedef struct {
1945
  char    db[TSDB_DB_FNAME_LEN];
1946
  int64_t uid;
1947
} SDropDbRsp;
1948

1949
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1950
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1951

1952
typedef struct {
1953
  char    name[TSDB_MOUNT_NAME_LEN];
1954
  int64_t uid;
1955
} SDropMountRsp;
1956

1957
int32_t tSerializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1958
int32_t tDeserializeSDropMountRsp(void* buf, int32_t bufLen, SDropMountRsp* pRsp);
1959

1960
typedef struct {
1961
  char    db[TSDB_DB_FNAME_LEN];
1962
  int64_t dbId;
1963
  int32_t vgVersion;
1964
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1965
  int64_t stateTs;     // ms
1966
} SUseDbReq;
1967

1968
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1969
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1970

1971
typedef struct {
1972
  char    db[TSDB_DB_FNAME_LEN];
1973
  int64_t uid;
1974
  int32_t vgVersion;
1975
  int32_t vgNum;
1976
  int16_t hashPrefix;
1977
  int16_t hashSuffix;
1978
  int8_t  hashMethod;
1979
  union {
1980
    uint8_t flags;
1981
    struct {
1982
      uint8_t isMount : 1;  // TS-5868
1983
      uint8_t padding : 7;
1984
    };
1985
  };
1986
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1987
  int32_t errCode;
1988
  int64_t stateTs;  // ms
1989
} SUseDbRsp;
1990

1991
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1992
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1993
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1994
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1995
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1996

1997
typedef struct {
1998
  char db[TSDB_DB_FNAME_LEN];
1999
} SDbCfgReq;
2000

2001
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2002
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
2003

2004
typedef struct {
2005
  char db[TSDB_DB_FNAME_LEN];
2006
} SSsMigrateDbReq;
2007

2008
int32_t tSerializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2009
int32_t tDeserializeSSsMigrateDbReq(void* buf, int32_t bufLen, SSsMigrateDbReq* pReq);
2010

2011
typedef struct {
2012
  int32_t ssMigrateId;
2013
  bool    bAccepted;
2014
} SSsMigrateDbRsp;
2015

2016
int32_t tSerializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2017
int32_t tDeserializeSSsMigrateDbRsp(void* buf, int32_t bufLen, SSsMigrateDbRsp* pRsp);
2018

2019
// Request and response for TDMT_VND_LIST_SSMIGRATE_FILESETS
2020
typedef struct {
2021
  int32_t ssMigrateId;
2022
} SListSsMigrateFileSetsReq;
2023

2024
int32_t tSerializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2025
int32_t tDeserializeSListSsMigrateFileSetsReq(void* buf, int32_t bufLen, SListSsMigrateFileSetsReq* pReq);
2026

2027
typedef struct {
2028
  int32_t ssMigrateId;
2029
  int32_t vgId;       // vgroup id
2030
  SArray* pFileSets;  // SArray<int32_t>
2031
} SListSsMigrateFileSetsRsp;
2032

2033
int32_t tSerializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2034
int32_t tDeserializeSListSsMigrateFileSetsRsp(void* buf, int32_t bufLen, SListSsMigrateFileSetsRsp* pRsp);
2035
void    tFreeSListSsMigrateFileSetsRsp(SListSsMigrateFileSetsRsp* pRsp);
2036

2037
// Request and response for TDMT_VND_SSMIGRATE_FILESET
2038
typedef struct {
2039
  int32_t ssMigrateId;
2040
  int32_t nodeId;  // node id of the leader vnode, filled by vnode
2041
  int32_t fid;
2042
  int64_t startTimeSec;
2043
} SSsMigrateFileSetReq;
2044

2045
int32_t tSerializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2046
int32_t tDeserializeSSsMigrateFileSetReq(void* buf, int32_t bufLen, SSsMigrateFileSetReq* pReq);
2047

2048
typedef struct {
2049
  int32_t ssMigrateId;
2050
  int32_t nodeId;  // node id of the leader vnode
2051
  int32_t vgId;
2052
  int32_t fid;
2053
} SSsMigrateFileSetRsp;
2054

2055
int32_t tSerializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2056
int32_t tDeserializeSSsMigrateFileSetRsp(void* buf, int32_t bufLen, SSsMigrateFileSetRsp* pRsp);
2057

2058
#define SSMIGRATE_FILESET_STATE_IN_PROGRESS 0
2059
#define SSMIGRATE_FILESET_STATE_SUCCEEDED   1
2060
#define SSMIGRATE_FILESET_STATE_COMPACT     2
2061
#define SSMIGRATE_FILESET_STATE_SKIPPED     3
2062
#define SSMIGRATE_FILESET_STATE_FAILED      4
2063

2064
// Request and response for TDMT_VND_QUERY_SSMIGRATE_PROGRESS and TDMT_VND_FOLLOWER_SSMIGRATE
2065
// Note this struct is reused as both request and response in TDMT_VND_QUERY_SSMIGRATE_PROGRESS,
2066
// while as a request, the 'state' field is not used.
2067
// This struct is also used in TDMT_VND_FOLLOWER_SSMIGRATE as request, which don't need a response.
2068
typedef struct {
2069
  int32_t ssMigrateId;  // ss migrate id
2070
  int32_t nodeId;       // node id of the leader vnode
2071
  int32_t vgId;         // vgroup id
2072
  int32_t fid;          // file set id
2073
  int32_t state;        // SSMIGRATE_FILESET_STATE_*
2074
} SSsMigrateProgress;
2075

2076
int tSerializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2077
int tDeserializeSSsMigrateProgress(void* buf, int32_t bufLen, SSsMigrateProgress* pProgress);
2078

2079
// Request for TDMT_MND_KILL_SSMIGRATE
2080
typedef struct {
2081
  int32_t ssMigrateId;
2082
  int32_t sqlLen;
2083
  char*   sql;
2084
} SKillSsMigrateReq;
2085

2086
int32_t tSerializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2087
int32_t tDeserializeSKillSsMigrateReq(void* buf, int32_t bufLen, SKillSsMigrateReq* pReq);
2088
void    tFreeSKillSsMigrateReq(SKillSsMigrateReq* pReq);
2089

2090
// Request for TDMT_VND_KILL_SSMIGRATE
2091
typedef struct {
2092
  int32_t ssMigrateId;
2093
} SVnodeKillSsMigrateReq;
2094

2095
int32_t tSerializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2096
int32_t tDeserializeSVnodeKillSsMigrateReq(void* buf, int32_t bufLen, SVnodeKillSsMigrateReq* pReq);
2097

2098
typedef struct {
2099
  int32_t vgId;
2100
  int64_t keepVersion;
2101
} SMndSetVgroupKeepVersionReq;
2102

2103
int32_t tSerializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2104
int32_t tDeserializeSMndSetVgroupKeepVersionReq(void* buf, int32_t bufLen, SMndSetVgroupKeepVersionReq* pReq);
2105

2106
typedef struct {
2107
  int32_t timestampSec;
2108
  int32_t ttlDropMaxCount;
2109
  int32_t nUids;
2110
  SArray* pTbUids;
2111
} SVDropTtlTableReq;
2112

2113
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2114
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
2115

2116
typedef struct {
2117
  char    db[TSDB_DB_FNAME_LEN];
2118
  int64_t dbId;
2119
  int32_t cfgVersion;
2120
  int32_t numOfVgroups;
2121
  int32_t numOfStables;
2122
  int32_t buffer;
2123
  int32_t cacheSize;
2124
  int32_t pageSize;
2125
  int32_t pages;
2126
  int32_t daysPerFile;
2127
  int32_t daysToKeep0;
2128
  int32_t daysToKeep1;
2129
  int32_t daysToKeep2;
2130
  int32_t keepTimeOffset;
2131
  int32_t minRows;
2132
  int32_t maxRows;
2133
  int32_t walFsyncPeriod;
2134
  int16_t hashPrefix;
2135
  int16_t hashSuffix;
2136
  int8_t  hashMethod;
2137
  int8_t  walLevel;
2138
  int8_t  precision;
2139
  int8_t  compression;
2140
  int8_t  replications;
2141
  int8_t  strict;
2142
  int8_t  cacheLast;
2143
  int8_t  encryptAlgr;
2144
  char    algorithmsId[TSDB_ENCRYPT_ALGR_NAME_LEN];
2145
  int32_t ssChunkSize;
2146
  int32_t ssKeepLocal;
2147
  int8_t  ssCompact;
2148
  union {
2149
    uint8_t flags;
2150
    struct {
2151
      uint8_t isMount : 1;  // TS-5868
2152
      uint8_t padding : 7;
2153
    };
2154
  };
2155
  int8_t  compactTimeOffset;
2156
  int32_t compactInterval;
2157
  int32_t compactStartTime;
2158
  int32_t compactEndTime;
2159
  int32_t tsdbPageSize;
2160
  int32_t walRetentionPeriod;
2161
  int32_t walRollPeriod;
2162
  int64_t walRetentionSize;
2163
  int64_t walSegmentSize;
2164
  int32_t numOfRetensions;
2165
  SArray* pRetensions;
2166
  int8_t  schemaless;
2167
  int16_t sstTrigger;
2168
  int8_t  withArbitrator;
2169
  int8_t  isAudit;
2170
} SDbCfgRsp;
2171

2172
typedef SDbCfgRsp SDbCfgInfo;
2173

2174
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
2175
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
2176
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
2177
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
2178
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
2179

2180
typedef struct {
2181
  int32_t rowNum;
2182
} SQnodeListReq;
2183

2184
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2185
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
2186

2187
typedef struct {
2188
  int32_t rowNum;
2189
} SDnodeListReq;
2190

2191
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
2192

2193
typedef struct {
2194
  int32_t useless;  // useless
2195
} SServerVerReq;
2196

2197
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2198
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
2199

2200
typedef struct {
2201
  char ver[TSDB_VERSION_LEN];
2202
} SServerVerRsp;
2203

2204
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2205
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
2206

2207
typedef struct SQueryNodeAddr {
2208
  int32_t nodeId;  // vgId or qnodeId
2209
  SEpSet  epSet;
2210
} SQueryNodeAddr;
2211

2212
typedef struct {
2213
  SQueryNodeAddr addr;
2214
  uint64_t       load;
2215
} SQueryNodeLoad;
2216

2217
typedef struct {
2218
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
2219
} SQnodeListRsp;
2220

2221
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2222
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
2223
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
2224

2225
typedef struct SDNodeAddr {
2226
  int32_t nodeId;  // dnodeId
2227
  SEpSet  epSet;
2228
} SDNodeAddr;
2229

2230
typedef struct {
2231
  SArray* dnodeList;  // SArray<SDNodeAddr>
2232
} SDnodeListRsp;
2233

2234
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2235
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
2236
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
2237

2238
typedef struct {
2239
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
2240
} STableTSMAInfoRsp;
2241

2242
typedef struct {
2243
  SUseDbRsp*         useDbRsp;
2244
  SDbCfgRsp*         cfgRsp;
2245
  STableTSMAInfoRsp* pTsmaRsp;
2246
  int32_t            dbTsmaVersion;
2247
  char               db[TSDB_DB_FNAME_LEN];
2248
  int64_t            dbId;
2249
} SDbHbRsp;
2250

2251
typedef struct {
2252
  SArray* pArray;  // Array of SDbHbRsp
2253
} SDbHbBatchRsp;
2254

2255
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2256
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
2257
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
2258

2259
typedef struct {
2260
  SArray* pArray;  // Array of SGetUserAuthRsp
2261
} SUserAuthBatchRsp;
2262

2263
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2264
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
2265
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
2266

2267
typedef struct {
2268
  char        db[TSDB_DB_FNAME_LEN];
2269
  STimeWindow timeRange;
2270
  int32_t     sqlLen;
2271
  char*       sql;
2272
  SArray*     vgroupIds;
2273
  int32_t     compactId;
2274
  int8_t      metaOnly;
2275
  int8_t      force;
2276
} SCompactDbReq;
2277

2278
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2279
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
2280
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
2281

2282
typedef struct {
2283
  union {
2284
    int32_t compactId;
2285
    int32_t id;
2286
  };
2287
  int8_t bAccepted;
2288
} SCompactDbRsp;
2289

2290
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2291
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
2292

2293
typedef struct {
2294
  union {
2295
    int32_t compactId;
2296
    int32_t id;
2297
  };
2298
  int32_t sqlLen;
2299
  char*   sql;
2300
} SKillCompactReq;
2301

2302
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2303
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
2304
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
2305

2306
typedef SCompactDbRsp   STrimDbRsp;         // reuse structs
2307
typedef SKillCompactReq SKillRetentionReq;  // reuse structs
2308

2309
typedef struct {
2310
  char    name[TSDB_FUNC_NAME_LEN];
2311
  int8_t  igExists;
2312
  int8_t  funcType;
2313
  int8_t  scriptType;
2314
  int8_t  outputType;
2315
  int32_t outputLen;
2316
  int32_t bufSize;
2317
  int32_t codeLen;
2318
  int64_t signature;
2319
  char*   pComment;
2320
  char*   pCode;
2321
  int8_t  orReplace;
2322
} SCreateFuncReq;
2323

2324
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2325
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
2326
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
2327

2328
typedef struct {
2329
  char   name[TSDB_FUNC_NAME_LEN];
2330
  int8_t igNotExists;
2331
} SDropFuncReq;
2332

2333
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2334
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
2335

2336
typedef struct {
2337
  int32_t numOfFuncs;
2338
  bool    ignoreCodeComment;
2339
  SArray* pFuncNames;
2340
} SRetrieveFuncReq;
2341

2342
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2343
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
2344
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
2345

2346
typedef struct {
2347
  char    name[TSDB_FUNC_NAME_LEN];
2348
  int8_t  funcType;
2349
  int8_t  scriptType;
2350
  int8_t  outputType;
2351
  int32_t outputLen;
2352
  int32_t bufSize;
2353
  int64_t signature;
2354
  int32_t commentSize;
2355
  int32_t codeSize;
2356
  char*   pComment;
2357
  char*   pCode;
2358
} SFuncInfo;
2359

2360
typedef struct {
2361
  int32_t funcVersion;
2362
  int64_t funcCreatedTime;
2363
} SFuncExtraInfo;
2364

2365
typedef struct {
2366
  int32_t numOfFuncs;
2367
  SArray* pFuncInfos;
2368
  SArray* pFuncExtraInfos;
2369
} SRetrieveFuncRsp;
2370

2371
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2372
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
2373
void    tFreeSFuncInfo(SFuncInfo* pInfo);
2374
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
2375

2376
typedef struct {
2377
  int32_t       statusInterval;
2378
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
2379
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
2380
  char          locale[TD_LOCALE_LEN];      // tsLocale
2381
  char          charset[TD_LOCALE_LEN];     // tsCharset
2382
  int8_t        ttlChangeOnWrite;
2383
  int8_t        enableWhiteList;
2384
  int8_t        encryptionKeyStat;
2385
  uint32_t      encryptionKeyChksum;
2386
  SMonitorParas monitorParas;
2387
  int32_t       statusIntervalMs;
2388
} SClusterCfg;
2389

2390
typedef struct {
2391
  int32_t openVnodes;
2392
  int32_t dropVnodes;
2393
  int32_t totalVnodes;
2394
  int32_t masterNum;
2395
  int64_t numOfSelectReqs;
2396
  int64_t numOfInsertReqs;
2397
  int64_t numOfInsertSuccessReqs;
2398
  int64_t numOfBatchInsertReqs;
2399
  int64_t numOfBatchInsertSuccessReqs;
2400
  int64_t errors;
2401
} SVnodesStat;
2402

2403
typedef struct {
2404
  int32_t vgId;
2405
  int8_t  syncState;
2406
  int8_t  syncRestore;
2407
  int64_t syncTerm;
2408
  int64_t roleTimeMs;
2409
  int64_t startTimeMs;
2410
  int8_t  syncCanRead;
2411
  int64_t cacheUsage;
2412
  int64_t numOfTables;
2413
  int64_t numOfTimeSeries;
2414
  int64_t totalStorage;
2415
  int64_t compStorage;
2416
  int64_t pointsWritten;
2417
  int64_t numOfSelectReqs;
2418
  int64_t numOfInsertReqs;
2419
  int64_t numOfInsertSuccessReqs;
2420
  int64_t numOfBatchInsertReqs;
2421
  int64_t numOfBatchInsertSuccessReqs;
2422
  int32_t numOfCachedTables;
2423
  int32_t learnerProgress;  // use one reservered
2424
  int64_t syncAppliedIndex;
2425
  int64_t syncCommitIndex;
2426
  int64_t bufferSegmentUsed;
2427
  int64_t bufferSegmentSize;
2428
} SVnodeLoad;
2429

2430
typedef struct {
2431
  int64_t total_requests;
2432
  int64_t total_rows;
2433
  int64_t total_bytes;
2434
  double  write_size;
2435
  double  cache_hit_ratio;
2436
  int64_t rpc_queue_wait;
2437
  int64_t preprocess_time;
2438

2439
  int64_t memory_table_size;
2440
  int64_t commit_count;
2441
  int64_t merge_count;
2442
  double  commit_time;
2443
  double  merge_time;
2444
  int64_t block_commit_time;
2445
  int64_t memtable_wait_time;
2446
} SVnodeMetrics;
2447

2448
typedef struct {
2449
  int32_t     vgId;
2450
  int64_t     numOfTables;
2451
  int64_t     memSize;
2452
  int64_t     l1Size;
2453
  int64_t     l2Size;
2454
  int64_t     l3Size;
2455
  int64_t     cacheSize;
2456
  int64_t     walSize;
2457
  int64_t     metaSize;
2458
  int64_t     rawDataSize;
2459
  int64_t     ssSize;
2460
  const char* dbname;
2461
  int8_t      estimateRawData;
2462
} SDbSizeStatisInfo;
2463

2464
typedef struct {
2465
  int32_t vgId;
2466
  int64_t nTimeSeries;
2467
} SVnodeLoadLite;
2468

2469
typedef struct {
2470
  int8_t  syncState;
2471
  int64_t syncTerm;
2472
  int8_t  syncRestore;
2473
  int64_t roleTimeMs;
2474
} SMnodeLoad;
2475

2476
typedef struct {
2477
  int32_t dnodeId;
2478
  int64_t numOfProcessedQuery;
2479
  int64_t numOfProcessedCQuery;
2480
  int64_t numOfProcessedFetch;
2481
  int64_t numOfProcessedDrop;
2482
  int64_t numOfProcessedNotify;
2483
  int64_t numOfProcessedHb;
2484
  int64_t numOfProcessedDelete;
2485
  int64_t cacheDataSize;
2486
  int64_t numOfQueryInQueue;
2487
  int64_t numOfFetchInQueue;
2488
  int64_t timeInQueryQueue;
2489
  int64_t timeInFetchQueue;
2490
} SQnodeLoad;
2491

2492
typedef struct {
2493
  int32_t     sver;      // software version
2494
  int64_t     dnodeVer;  // dnode table version in sdb
2495
  int32_t     dnodeId;
2496
  int64_t     clusterId;
2497
  int64_t     rebootTime;
2498
  int64_t     updateTime;
2499
  float       numOfCores;
2500
  int32_t     numOfSupportVnodes;
2501
  int32_t     numOfDiskCfg;
2502
  int64_t     memTotal;
2503
  int64_t     memAvail;
2504
  char        dnodeEp[TSDB_EP_LEN];
2505
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2506
  SMnodeLoad  mload;
2507
  SQnodeLoad  qload;
2508
  SClusterCfg clusterCfg;
2509
  SArray*     pVloads;  // array of SVnodeLoad
2510
  int32_t     statusSeq;
2511
  int64_t     ipWhiteVer;
2512
  int64_t     timeWhiteVer;
2513
  int64_t     analVer;
2514
  int64_t     timestamp;
2515
  char        auditDB[TSDB_DB_FNAME_LEN];
2516
  char        auditToken[AUDIT_TOKEN_LEN];
2517
} SStatusReq;
2518

2519
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2520
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2521
void    tFreeSStatusReq(SStatusReq* pReq);
2522

2523
typedef struct {
2524
  int32_t forceReadConfig;
2525
  int32_t cver;
2526
  SArray* array;
2527
} SConfigReq;
2528

2529
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2530
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2531
void    tFreeSConfigReq(SConfigReq* pReq);
2532

2533
typedef struct {
2534
  int32_t dnodeId;
2535
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2536
} SDnodeInfoReq;
2537

2538
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2539
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2540

2541
typedef enum {
2542
  MONITOR_TYPE_COUNTER = 0,
2543
  MONITOR_TYPE_SLOW_LOG = 1,
2544
} MONITOR_TYPE;
2545

2546
typedef struct {
2547
  int32_t      contLen;
2548
  char*        pCont;
2549
  MONITOR_TYPE type;
2550
} SStatisReq;
2551

2552
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2553
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2554
void    tFreeSStatisReq(SStatisReq* pReq);
2555

2556
typedef struct {
2557
  char    db[TSDB_DB_FNAME_LEN];
2558
  char    table[TSDB_TABLE_NAME_LEN];
2559
  char    operation[AUDIT_OPERATION_LEN];
2560
  int32_t sqlLen;
2561
  char*   pSql;
2562
  double  duration;
2563
  int64_t affectedRows;
2564
} SAuditReq;
2565
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2566
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2567
void    tFreeSAuditReq(SAuditReq* pReq);
2568

2569
typedef struct {
2570
  SArray* auditArr;
2571
} SBatchAuditReq;
2572
int32_t tSerializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2573
int32_t tDeserializeSBatchAuditReq(void* buf, int32_t bufLen, SBatchAuditReq* pReq);
2574
void    tFreeSBatchAuditReq(SBatchAuditReq* pReq);
2575

2576
typedef struct {
2577
  int32_t dnodeId;
2578
  int64_t clusterId;
2579
  SArray* pVloads;
2580
} SNotifyReq;
2581

2582
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2583
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2584
void    tFreeSNotifyReq(SNotifyReq* pReq);
2585

2586
typedef struct {
2587
  int32_t dnodeId;
2588
  int64_t clusterId;
2589
} SDnodeCfg;
2590

2591
typedef struct {
2592
  int32_t id;
2593
  int8_t  isMnode;
2594
  SEp     ep;
2595
} SDnodeEp;
2596

2597
typedef struct {
2598
  int32_t id;
2599
  int8_t  isMnode;
2600
  int8_t  offlineReason;
2601
  SEp     ep;
2602
  char    active[TSDB_ACTIVE_KEY_LEN];
2603
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2604
} SDnodeInfo;
2605

2606
typedef struct {
2607
  int64_t   dnodeVer;
2608
  SDnodeCfg dnodeCfg;
2609
  SArray*   pDnodeEps;  // Array of SDnodeEp
2610
  int32_t   statusSeq;
2611
  int64_t   ipWhiteVer;
2612
  int64_t   analVer;
2613
  int64_t   timeWhiteVer;
2614
  char      auditDB[TSDB_DB_FNAME_LEN];
2615
  char      auditToken[AUDIT_TOKEN_LEN];
2616
} SStatusRsp;
2617

2618
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2619
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2620
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2621

2622
typedef struct {
2623
  int32_t forceReadConfig;
2624
  int32_t isConifgVerified;
2625
  int32_t isVersionVerified;
2626
  int32_t cver;
2627
  SArray* array;
2628
} SConfigRsp;
2629

2630
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2631
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2632
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2633

2634
typedef struct {
2635
  int32_t reserved;
2636
} SMTimerReq;
2637

2638
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2639
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2640

2641
typedef struct SOrphanTask {
2642
  int64_t streamId;
2643
  int32_t taskId;
2644
  int32_t nodeId;
2645
} SOrphanTask;
2646

2647
typedef struct SMStreamDropOrphanMsg {
2648
  SArray* pList;  // SArray<SOrphanTask>
2649
} SMStreamDropOrphanMsg;
2650

2651
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2652
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2653
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2654

2655
typedef struct {
2656
  int32_t  id;
2657
  uint16_t port;                 // node sync Port
2658
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2659
} SReplica;
2660

2661
typedef struct {
2662
  int32_t  vgId;
2663
  char     db[TSDB_DB_FNAME_LEN];
2664
  int64_t  dbUid;
2665
  int32_t  vgVersion;
2666
  int32_t  numOfStables;
2667
  int32_t  buffer;
2668
  int32_t  pageSize;
2669
  int32_t  pages;
2670
  int32_t  cacheLastSize;
2671
  int32_t  daysPerFile;
2672
  int32_t  daysToKeep0;
2673
  int32_t  daysToKeep1;
2674
  int32_t  daysToKeep2;
2675
  int32_t  keepTimeOffset;
2676
  int32_t  minRows;
2677
  int32_t  maxRows;
2678
  int32_t  walFsyncPeriod;
2679
  uint32_t hashBegin;
2680
  uint32_t hashEnd;
2681
  int8_t   hashMethod;
2682
  int8_t   walLevel;
2683
  int8_t   precision;
2684
  int8_t   compression;
2685
  int8_t   strict;
2686
  int8_t   cacheLast;
2687
  int8_t   isTsma;
2688
  int8_t   replica;
2689
  int8_t   selfIndex;
2690
  SReplica replicas[TSDB_MAX_REPLICA];
2691
  int32_t  numOfRetensions;
2692
  SArray*  pRetensions;  // SRetention
2693
  void*    pTsma;
2694
  int32_t  walRetentionPeriod;
2695
  int64_t  walRetentionSize;
2696
  int32_t  walRollPeriod;
2697
  int64_t  walSegmentSize;
2698
  int16_t  sstTrigger;
2699
  int16_t  hashPrefix;
2700
  int16_t  hashSuffix;
2701
  int32_t  tsdbPageSize;
2702
  int32_t  ssChunkSize;
2703
  int32_t  ssKeepLocal;
2704
  int8_t   ssCompact;
2705
  int64_t  reserved[6];
2706
  int8_t   learnerReplica;
2707
  int8_t   learnerSelfIndex;
2708
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2709
  int32_t  changeVersion;
2710
  int8_t   encryptAlgorithm;
2711
  char     encryptAlgrName[TSDB_ENCRYPT_ALGR_NAME_LEN];
2712
} SCreateVnodeReq;
2713

2714
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2715
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2716
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2717

2718
typedef struct {
2719
  union {
2720
    int32_t compactId;
2721
    int32_t id;
2722
  };
2723
  int32_t vgId;
2724
  int32_t dnodeId;
2725
} SQueryCompactProgressReq;
2726

2727
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2728
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2729

2730
typedef struct {
2731
  union {
2732
    int32_t compactId;
2733
    int32_t id;
2734
  };
2735
  int32_t vgId;
2736
  int32_t dnodeId;
2737
  int32_t numberFileset;
2738
  int32_t finished;
2739
  int32_t progress;
2740
  int64_t remainingTime;
2741
} SQueryCompactProgressRsp;
2742

2743
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2744
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2745

2746
typedef SQueryCompactProgressReq SQueryRetentionProgressReq;
2747
typedef SQueryCompactProgressRsp SQueryRetentionProgressRsp;
2748

2749
typedef struct {
2750
  int32_t vgId;
2751
  int32_t dnodeId;
2752
  int64_t dbUid;
2753
  char    db[TSDB_DB_FNAME_LEN];
2754
  int64_t reserved[8];
2755
} SDropVnodeReq;
2756

2757
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2758
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2759

2760
typedef struct {
2761
  char    colName[TSDB_COL_NAME_LEN];
2762
  char    stb[TSDB_TABLE_FNAME_LEN];
2763
  int64_t stbUid;
2764
  int64_t dbUid;
2765
  int64_t reserved[8];
2766
} SDropIndexReq;
2767

2768
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2769
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2770

2771
typedef struct {
2772
  int64_t dbUid;
2773
  char    db[TSDB_DB_FNAME_LEN];
2774
  union {
2775
    int64_t compactStartTime;
2776
    int64_t startTime;
2777
  };
2778

2779
  STimeWindow tw;
2780
  union {
2781
    int32_t compactId;
2782
    int32_t id;
2783
  };
2784
  int8_t metaOnly;
2785
  union {
2786
    uint16_t flags;
2787
    struct {
2788
      uint16_t optrType : 3;     // ETsdbOpType
2789
      uint16_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2790
      uint16_t reserved : 12;
2791
    };
2792
  };
2793
  int8_t force;  // force compact
2794
} SCompactVnodeReq;
2795

2796
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2797
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2798

2799
typedef struct {
2800
  union {
2801
    int32_t compactId;
2802
    int32_t taskId;
2803
  };
2804
  int32_t vgId;
2805
  int32_t dnodeId;
2806
} SVKillCompactReq;
2807

2808
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2809
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2810

2811
typedef SVKillCompactReq SVKillRetentionReq;
2812

2813
typedef struct {
2814
  char        db[TSDB_DB_FNAME_LEN];
2815
  int32_t     maxSpeed;
2816
  int32_t     sqlLen;
2817
  char*       sql;
2818
  SArray*     vgroupIds;
2819
  STimeWindow tw;  // unit is second
2820
  union {
2821
    uint32_t flags;
2822
    struct {
2823
      uint32_t optrType : 3;     // ETsdbOpType
2824
      uint32_t triggerType : 1;  // ETriggerType 0 manual, 1 auto
2825
      uint32_t reserved : 28;
2826
    };
2827
  };
2828
} STrimDbReq;
2829

2830
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2831
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
2832
void    tFreeSTrimDbReq(STrimDbReq* pReq);
2833

2834
typedef SCompactVnodeReq SVTrimDbReq;  // reuse SCompactVnodeReq, add task monitor since 3.3.8.0
2835

2836
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2837
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
2838

2839
typedef struct {
2840
  int32_t vgVersion;
2841
  int32_t buffer;
2842
  int32_t pageSize;
2843
  int32_t pages;
2844
  int32_t cacheLastSize;
2845
  int32_t daysPerFile;
2846
  int32_t daysToKeep0;
2847
  int32_t daysToKeep1;
2848
  int32_t daysToKeep2;
2849
  int32_t keepTimeOffset;
2850
  int32_t walFsyncPeriod;
2851
  int8_t  walLevel;
2852
  int8_t  strict;
2853
  int8_t  cacheLast;
2854
  int64_t reserved[7];
2855
  // 1st modification
2856
  int16_t sttTrigger;
2857
  int32_t minRows;
2858
  // 2nd modification
2859
  int32_t walRetentionPeriod;
2860
  int32_t walRetentionSize;
2861
  int32_t ssKeepLocal;
2862
  int8_t  ssCompact;
2863
} SAlterVnodeConfigReq;
2864

2865
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2866
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2867

2868
typedef struct {
2869
  int32_t  vgId;
2870
  int8_t   strict;
2871
  int8_t   selfIndex;
2872
  int8_t   replica;
2873
  SReplica replicas[TSDB_MAX_REPLICA];
2874
  int64_t  reserved[8];
2875
  int8_t   learnerSelfIndex;
2876
  int8_t   learnerReplica;
2877
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2878
  int32_t  changeVersion;
2879
  int32_t  electBaseLine;
2880
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq, SAlterVnodeElectBaselineReq;
2881

2882
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2883
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2884

2885
typedef struct {
2886
  int32_t vgId;
2887
  int8_t  disable;
2888
} SDisableVnodeWriteReq;
2889

2890
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2891
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2892

2893
typedef struct {
2894
  int32_t  srcVgId;
2895
  int32_t  dstVgId;
2896
  uint32_t hashBegin;
2897
  uint32_t hashEnd;
2898
  int32_t  changeVersion;
2899
  int32_t  reserved;
2900
} SAlterVnodeHashRangeReq;
2901

2902
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2903
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2904

2905
#define REQ_OPT_TBNAME 0x0
2906
#define REQ_OPT_TBUID  0x01
2907
typedef struct {
2908
  SMsgHead header;
2909
  char     dbFName[TSDB_DB_FNAME_LEN];
2910
  char     tbName[TSDB_TABLE_NAME_LEN];
2911
  uint8_t  option;
2912
  uint8_t  autoCreateCtb;
2913
} STableInfoReq;
2914

2915
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2916
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2917

2918
typedef struct {
2919
  int8_t  metaClone;  // create local clone of the cached table meta
2920
  int32_t numOfVgroups;
2921
  int32_t numOfTables;
2922
  int32_t numOfUdfs;
2923
  char    tableNames[];
2924
} SMultiTableInfoReq;
2925

2926
// todo refactor
2927
typedef struct SVgroupInfo {
2928
  int32_t  vgId;
2929
  uint32_t hashBegin;
2930
  uint32_t hashEnd;
2931
  SEpSet   epSet;
2932
  union {
2933
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2934
    int32_t taskId;      // used in stream
2935
  };
2936
} SVgroupInfo;
2937

2938
typedef struct {
2939
  int32_t     numOfVgroups;
2940
  SVgroupInfo vgroups[];
2941
} SVgroupsInfo;
2942

2943
typedef struct {
2944
  STableMetaRsp* pMeta;
2945
} SMAlterStbRsp;
2946

2947
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2948
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2949
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2950

2951
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2952
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2953
void    tFreeSTableMetaRsp(void* pRsp);
2954
void    tFreeSTableIndexRsp(void* info);
2955

2956
typedef struct {
2957
  SArray* pMetaRsp;   // Array of STableMetaRsp
2958
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2959
} SSTbHbRsp;
2960

2961
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2962
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2963
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2964

2965
typedef struct {
2966
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2967
} SViewHbRsp;
2968

2969
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2970
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2971
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2972

2973
typedef struct {
2974
  int32_t numOfTables;
2975
  int32_t numOfVgroup;
2976
  int32_t numOfUdf;
2977
  int32_t contLen;
2978
  int8_t  compressed;  // denote if compressed or not
2979
  int32_t rawLen;      // size before compress
2980
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2981
  char    meta[];
2982
} SMultiTableMeta;
2983

2984
typedef struct {
2985
  int32_t dataLen;
2986
  char    name[TSDB_TABLE_FNAME_LEN];
2987
  char*   data;
2988
} STagData;
2989

2990
typedef struct {
2991
  int32_t  opType;
2992
  uint32_t valLen;
2993
  char*    val;
2994
} SShowVariablesReq;
2995

2996
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2997
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2998
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2999

3000
typedef struct {
3001
  char name[TSDB_CONFIG_OPTION_LEN + 1];
3002
  char value[TSDB_CONFIG_PATH_LEN + 1];
3003
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
3004
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
3005
  char info[TSDB_CONFIG_INFO_LEN + 1];
3006
} SVariablesInfo;
3007

3008
typedef struct {
3009
  SArray* variables;  // SArray<SVariablesInfo>
3010
} SShowVariablesRsp;
3011

3012
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3013
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
3014

3015
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
3016

3017
/*
3018
 * sql: show tables like '%a_%'
3019
 * payload is the query condition, e.g., '%a_%'
3020
 * payloadLen is the length of payload
3021
 */
3022
typedef struct {
3023
  int32_t type;
3024
  char    db[TSDB_DB_FNAME_LEN];
3025
  int32_t payloadLen;
3026
  char*   payload;
3027
} SShowReq;
3028

3029
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3030
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
3031
void tFreeSShowReq(SShowReq* pReq);
3032

3033
typedef struct {
3034
  int64_t       showId;
3035
  STableMetaRsp tableMeta;
3036
} SShowRsp, SVShowTablesRsp;
3037

3038
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3039
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
3040
// void    tFreeSShowRsp(SShowRsp* pRsp);
3041

3042
typedef struct {
3043
  char    db[TSDB_DB_FNAME_LEN];
3044
  char    tb[TSDB_TABLE_NAME_LEN];
3045
  char    user[TSDB_USER_LEN];
3046
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
3047
  int64_t showId;
3048
  int64_t compactId;  // for compact
3049
  bool    withFull;   // for show users full
3050
} SRetrieveTableReq;
3051

3052
typedef struct SSysTableSchema {
3053
  int8_t   type;
3054
  col_id_t colId;
3055
  int32_t  bytes;
3056
} SSysTableSchema;
3057

3058
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3059
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
3060

3061
#define RETRIEVE_TABLE_RSP_VERSION         0
3062
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
3063
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
3064

3065
typedef struct {
3066
  int64_t useconds;
3067
  int8_t  completed;  // all results are returned to client
3068
  int8_t  precision;
3069
  int8_t  compressed;
3070
  int8_t  streamBlockType;
3071
  int32_t payloadLen;
3072
  int32_t compLen;
3073
  int32_t numOfBlocks;
3074
  int64_t numOfRows;  // from int32_t change to int64_t
3075
  int64_t numOfCols;
3076
  int64_t skey;
3077
  int64_t ekey;
3078
  int64_t version;                         // for stream
3079
  TSKEY   watermark;                       // for stream
3080
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
3081
  char    data[];
3082
} SRetrieveTableRsp;
3083

3084
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
3085

3086
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
3087
  do {                                          \
3088
    ((int32_t*)(_p))[0] = (_compLen);           \
3089
    ((int32_t*)(_p))[1] = (_fullLen);           \
3090
  } while (0);
3091

3092
typedef struct {
3093
  int64_t version;
3094
  int64_t numOfRows;
3095
  int8_t  compressed;
3096
  int8_t  precision;
3097
  char    data[];
3098
} SRetrieveTableRspForTmq;
3099

3100
typedef struct {
3101
  int64_t handle;
3102
  int64_t useconds;
3103
  int8_t  completed;  // all results are returned to client
3104
  int8_t  precision;
3105
  int8_t  compressed;
3106
  int32_t compLen;
3107
  int32_t numOfRows;
3108
  int32_t fullLen;
3109
  char    data[];
3110
} SRetrieveMetaTableRsp;
3111

3112
typedef struct SExplainExecInfo {
3113
  double   startupCost;
3114
  double   totalCost;
3115
  uint64_t numOfRows;
3116
  uint32_t verboseLen;
3117
  void*    verboseInfo;
3118
} SExplainExecInfo;
3119

3120
typedef struct {
3121
  int32_t           numOfPlans;
3122
  SExplainExecInfo* subplanInfo;
3123
} SExplainRsp;
3124

3125
typedef struct {
3126
  SExplainRsp rsp;
3127
  uint64_t    qId;
3128
  uint64_t    cId;
3129
  uint64_t    tId;
3130
  int64_t     rId;
3131
  int32_t     eId;
3132
} SExplainLocalRsp;
3133

3134
typedef struct STableScanAnalyzeInfo {
3135
  uint64_t totalRows;
3136
  uint64_t totalCheckedRows;
3137
  uint32_t totalBlocks;
3138
  uint32_t loadBlocks;
3139
  uint32_t loadBlockStatis;
3140
  uint32_t skipBlocks;
3141
  uint32_t filterOutBlocks;
3142
  double   elapsedTime;
3143
  double   filterTime;
3144
} STableScanAnalyzeInfo;
3145

3146
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3147
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
3148
void    tFreeSExplainRsp(SExplainRsp* pRsp);
3149

3150
typedef struct {
3151
  char    config[TSDB_DNODE_CONFIG_LEN];
3152
  char    value[TSDB_CLUSTER_VALUE_LEN];
3153
  int32_t sqlLen;
3154
  char*   sql;
3155
} SMCfgClusterReq;
3156

3157
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3158
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
3159
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
3160

3161
typedef struct {
3162
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
3163
  int32_t port;
3164
  int32_t sqlLen;
3165
  char*   sql;
3166
} SCreateDnodeReq;
3167

3168
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3169
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
3170
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
3171

3172
typedef struct {
3173
  int32_t dnodeId;
3174
  char    fqdn[TSDB_FQDN_LEN];
3175
  int32_t port;
3176
  int8_t  force;
3177
  int8_t  unsafe;
3178
  int32_t sqlLen;
3179
  char*   sql;
3180
} SDropDnodeReq;
3181

3182
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3183
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
3184
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
3185

3186
enum {
3187
  RESTORE_TYPE__ALL = 1,
3188
  RESTORE_TYPE__MNODE,
3189
  RESTORE_TYPE__VNODE,
3190
  RESTORE_TYPE__QNODE,
3191
};
3192

3193
typedef struct {
3194
  int32_t dnodeId;
3195
  int8_t  restoreType;
3196
  int32_t sqlLen;
3197
  char*   sql;
3198
} SRestoreDnodeReq;
3199

3200
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3201
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
3202
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
3203

3204
typedef struct {
3205
  int32_t dnodeId;
3206
  char    config[TSDB_DNODE_CONFIG_LEN];
3207
  char    value[TSDB_DNODE_VALUE_LEN];
3208
  int32_t sqlLen;
3209
  char*   sql;
3210
} SMCfgDnodeReq;
3211

3212
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3213
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
3214
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
3215

3216
typedef struct {
3217
  char    config[TSDB_DNODE_CONFIG_LEN];
3218
  char    value[TSDB_DNODE_VALUE_LEN];
3219
  int32_t version;
3220
} SDCfgDnodeReq;
3221

3222
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3223
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
3224

3225
typedef struct {
3226
  int32_t dnodeId;
3227
  int32_t sqlLen;
3228
  char*   sql;
3229
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
3230
    SMCreateSnodeReq, SMDropSnodeReq, SDDropSnodeReq;
3231

3232
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3233
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
3234

3235
typedef struct {
3236
  int32_t nodeId;
3237
  SEpSet  epSet;
3238
} SNodeEpSet;
3239

3240
typedef struct {
3241
  int32_t    snodeId;
3242
  SNodeEpSet leaders[2];
3243
  SNodeEpSet replica;
3244
  int32_t    sqlLen;
3245
  char*      sql;
3246
} SDCreateSnodeReq;
3247

3248
int32_t tSerializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3249
int32_t tDeserializeSDCreateSNodeReq(void* buf, int32_t bufLen, SDCreateSnodeReq* pReq);
3250
void    tFreeSDCreateSnodeReq(SDCreateSnodeReq* pReq);
3251

3252
void tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
3253
void tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
3254
typedef struct {
3255
  int8_t   replica;
3256
  SReplica replicas[TSDB_MAX_REPLICA];
3257
  int8_t   learnerReplica;
3258
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
3259
  int64_t  lastIndex;
3260
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
3261

3262
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3263
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
3264

3265
typedef struct {
3266
  int32_t urlLen;
3267
  int32_t sqlLen;
3268
  char*   url;
3269
  char*   sql;
3270
} SMCreateAnodeReq;
3271

3272
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3273
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
3274
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
3275

3276
typedef struct {
3277
  int32_t anodeId;
3278
  int32_t sqlLen;
3279
  char*   sql;
3280
} SMDropAnodeReq, SMUpdateAnodeReq;
3281

3282
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3283
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
3284
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
3285
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3286
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
3287
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
3288

3289
typedef struct {
3290
  int32_t dnodeId;
3291
  int32_t bnodeProto;
3292
  int32_t sqlLen;
3293
  char*   sql;
3294
} SMCreateBnodeReq, SDCreateBnodeReq;
3295

3296
int32_t tSerializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3297
int32_t tDeserializeSMCreateBnodeReq(void* buf, int32_t bufLen, SMCreateBnodeReq* pReq);
3298
void    tFreeSMCreateBnodeReq(SMCreateBnodeReq* pReq);
3299

3300
typedef struct {
3301
  int32_t dnodeId;
3302
  int32_t sqlLen;
3303
  char*   sql;
3304
} SMDropBnodeReq, SDDropBnodeReq;
3305

3306
int32_t tSerializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3307
int32_t tDeserializeSMDropBnodeReq(void* buf, int32_t bufLen, SMDropBnodeReq* pReq);
3308
void    tFreeSMDropBnodeReq(SMDropBnodeReq* pReq);
3309

3310
typedef struct {
3311
  int32_t vgId;
3312
  int32_t hbSeq;
3313
} SVArbHbReqMember;
3314

3315
typedef struct {
3316
  int32_t dnodeId;
3317
  char*   arbToken;
3318
  int64_t arbTerm;
3319
  SArray* hbMembers;  // SVArbHbReqMember
3320
} SVArbHeartBeatReq;
3321

3322
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3323
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
3324
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
3325

3326
typedef struct {
3327
  int32_t vgId;
3328
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
3329
  int32_t hbSeq;
3330
} SVArbHbRspMember;
3331

3332
typedef struct {
3333
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
3334
  int32_t dnodeId;
3335
  SArray* hbMembers;  // SVArbHbRspMember
3336
} SVArbHeartBeatRsp;
3337

3338
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3339
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
3340
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
3341

3342
typedef struct {
3343
  char*   arbToken;
3344
  int64_t arbTerm;
3345
  char*   member0Token;
3346
  char*   member1Token;
3347
} SVArbCheckSyncReq;
3348

3349
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3350
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
3351
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
3352

3353
typedef struct {
3354
  char*   arbToken;
3355
  char*   member0Token;
3356
  char*   member1Token;
3357
  int32_t vgId;
3358
  int32_t errCode;
3359
} SVArbCheckSyncRsp;
3360

3361
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3362
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
3363
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
3364

3365
typedef struct {
3366
  char*   arbToken;
3367
  int64_t arbTerm;
3368
  char*   memberToken;
3369
  int8_t  force;
3370
} SVArbSetAssignedLeaderReq;
3371

3372
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3373
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
3374
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
3375

3376
typedef struct {
3377
  char*   arbToken;
3378
  char*   memberToken;
3379
  int32_t vgId;
3380
} SVArbSetAssignedLeaderRsp;
3381

3382
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3383
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
3384
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
3385

3386
typedef struct {
3387
  int32_t dnodeId;
3388
  char*   token;
3389
} SMArbUpdateGroupMember;
3390

3391
typedef struct {
3392
  int32_t dnodeId;
3393
  char*   token;
3394
  int8_t  acked;
3395
} SMArbUpdateGroupAssigned;
3396

3397
typedef struct {
3398
  int32_t                  vgId;
3399
  int64_t                  dbUid;
3400
  SMArbUpdateGroupMember   members[2];
3401
  int8_t                   isSync;
3402
  int8_t                   assignedAcked;
3403
  SMArbUpdateGroupAssigned assignedLeader;
3404
  int64_t                  version;
3405
  int32_t                  code;
3406
  int64_t                  updateTimeMs;
3407
} SMArbUpdateGroup;
3408

3409
typedef struct {
3410
  SArray* updateArray;  // SMArbUpdateGroup
3411
} SMArbUpdateGroupBatchReq;
3412

3413
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3414
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
3415
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
3416

3417
typedef struct {
3418
  char queryStrId[TSDB_QUERY_ID_LEN];
3419
} SKillQueryReq;
3420

3421
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3422
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
3423

3424
typedef struct {
3425
  uint32_t connId;
3426
} SKillConnReq;
3427

3428
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3429
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
3430

3431
typedef struct {
3432
  int32_t transId;
3433
} SKillTransReq;
3434

3435
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3436
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
3437

3438
typedef struct {
3439
  int32_t useless;  // useless
3440
  int32_t sqlLen;
3441
  char*   sql;
3442
} SBalanceVgroupReq;
3443

3444
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3445
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
3446
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
3447

3448
typedef struct {
3449
  int32_t useless;  // useless
3450
  int32_t sqlLen;
3451
  char*   sql;
3452
} SAssignLeaderReq;
3453

3454
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3455
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
3456
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
3457
typedef struct {
3458
  int32_t vgId1;
3459
  int32_t vgId2;
3460
} SMergeVgroupReq;
3461

3462
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3463
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
3464

3465
typedef struct {
3466
  int32_t vgId;
3467
  int32_t dnodeId1;
3468
  int32_t dnodeId2;
3469
  int32_t dnodeId3;
3470
  int32_t sqlLen;
3471
  char*   sql;
3472
} SRedistributeVgroupReq;
3473

3474
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3475
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
3476
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
3477

3478
typedef struct {
3479
  int32_t reserved;
3480
  int32_t vgId;
3481
  int32_t sqlLen;
3482
  char*   sql;
3483
  char    db[TSDB_DB_FNAME_LEN];
3484
} SBalanceVgroupLeaderReq;
3485

3486
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3487
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
3488
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
3489

3490
typedef struct {
3491
  int32_t vgId;
3492
} SForceBecomeFollowerReq;
3493

3494
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3495
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
3496

3497
typedef struct {
3498
  int32_t vgId;
3499
  bool    force;
3500
} SSplitVgroupReq;
3501

3502
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3503
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
3504

3505
typedef struct {
3506
  char user[TSDB_USER_LEN];
3507
  char spi;
3508
  char encrypt;
3509
  char secret[TSDB_PASSWORD_LEN];
3510
  char ckey[TSDB_PASSWORD_LEN];
3511
} SAuthReq, SAuthRsp;
3512

3513
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3514
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
3515

3516
typedef struct {
3517
  int32_t statusCode;
3518
  char    details[1024];
3519
} SServerStatusRsp;
3520

3521
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3522
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
3523

3524
/**
3525
 * The layout of the query message payload is as following:
3526
 * +--------------------+---------------------------------+
3527
 * |Sql statement       | Physical plan                   |
3528
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
3529
 * +--------------------+---------------------------------+
3530
 */
3531
typedef struct SSubQueryMsg {
3532
  SMsgHead header;
3533
  uint64_t sId;
3534
  uint64_t queryId;
3535
  uint64_t clientId;
3536
  uint64_t taskId;
3537
  int64_t  refId;
3538
  int32_t  execId;
3539
  int32_t  msgMask;
3540
  int8_t   taskType;
3541
  int8_t   explain;
3542
  int8_t   needFetch;
3543
  int8_t   compress;
3544
  uint32_t sqlLen;
3545
  char*    sql;
3546
  uint32_t msgLen;
3547
  char*    msg;
3548
} SSubQueryMsg;
3549

3550
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3551
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3552
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3553

3554
typedef struct {
3555
  SMsgHead header;
3556
  uint64_t sId;
3557
  uint64_t queryId;
3558
  uint64_t taskId;
3559
} SSinkDataReq;
3560

3561
typedef struct {
3562
  SMsgHead header;
3563
  uint64_t sId;
3564
  uint64_t queryId;
3565
  uint64_t clientId;
3566
  uint64_t taskId;
3567
  int32_t  execId;
3568
} SQueryContinueReq;
3569

3570
typedef struct {
3571
  SMsgHead header;
3572
  uint64_t sId;
3573
  uint64_t queryId;
3574
  uint64_t taskId;
3575
} SResReadyReq;
3576

3577
typedef struct {
3578
  int32_t code;
3579
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3580
  int32_t sversion;
3581
  int32_t tversion;
3582
} SResReadyRsp;
3583

3584
typedef struct SOperatorParam {
3585
  int32_t opType;
3586
  int32_t downstreamIdx;
3587
  void*   value;
3588
  SArray* pChildren;  // SArray<SOperatorParam*>
3589
  bool    reUse;
3590
} SOperatorParam;
3591

3592
typedef struct SColIdNameKV {
3593
  col_id_t colId;
3594
  char     colName[TSDB_COL_NAME_LEN];
3595
} SColIdNameKV;
3596

3597
typedef struct SColIdPair {
3598
  col_id_t  vtbColId;
3599
  col_id_t  orgColId;
3600
  SDataType type;
3601
} SColIdPair;
3602

3603
typedef struct SColIdSlotIdPair {
3604
  int32_t  vtbSlotId;
3605
  col_id_t orgColId;
3606
} SColIdSlotIdPair;
3607

3608
typedef struct SOrgTbInfo {
3609
  int32_t vgId;
3610
  char    tbName[TSDB_TABLE_FNAME_LEN];
3611
  SArray* colMap;  // SArray<SColIdNameKV>
3612
} SOrgTbInfo;
3613

3614
typedef struct STableScanOperatorParam {
3615
  bool        tableSeq;
3616
  bool        isNewParam;
3617
  SArray*     pUidList;
3618
  SOrgTbInfo* pOrgTbInfo;
3619
  STimeWindow window;
3620
} STableScanOperatorParam;
3621

3622
typedef struct STagScanOperatorParam {
3623
  tb_uid_t vcUid;
3624
} STagScanOperatorParam;
3625

3626
typedef struct SVTableScanOperatorParam {
3627
  uint64_t        uid;
3628
  STimeWindow     window;
3629
  SOperatorParam* pTagScanOp;
3630
  SArray*         pOpParamArray;  // SArray<SOperatorParam>
3631
} SVTableScanOperatorParam;
3632

3633
typedef struct SMergeOperatorParam {
3634
  int32_t         winNum;
3635
} SMergeOperatorParam;
3636

3637
typedef struct SExternalWindowOperatorParam {
3638
  SArray*         ExtWins;  // SArray<SExtWinTimeWindow>
3639
} SExternalWindowOperatorParam;
3640

3641
typedef struct SDynQueryCtrlOperatorParam {
3642
  STimeWindow    window;
3643
} SDynQueryCtrlOperatorParam;
3644

3645
struct SStreamRuntimeFuncInfo;
3646
typedef struct {
3647
  SMsgHead        header;
3648
  uint64_t        sId;
3649
  uint64_t        queryId;
3650
  uint64_t        clientId;
3651
  uint64_t        taskId;
3652
  int32_t         execId;
3653
  SOperatorParam* pOpParam;
3654

3655
  // used for new-stream
3656
  struct SStreamRuntimeFuncInfo* pStRtFuncInfo;
3657
  bool                           reset;
3658
  bool                           dynTbname;
3659
  // used for new-stream
3660
} SResFetchReq;
3661

3662
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq, bool needStreamPesudoFuncVals);
3663
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3664
void    tDestroySResFetchReq(SResFetchReq* pReq);
3665
typedef struct {
3666
  SMsgHead header;
3667
  uint64_t clientId;
3668
} SSchTasksStatusReq;
3669

3670
typedef struct {
3671
  uint64_t queryId;
3672
  uint64_t clientId;
3673
  uint64_t taskId;
3674
  int64_t  refId;
3675
  int32_t  execId;
3676
  int8_t   status;
3677
} STaskStatus;
3678

3679
typedef struct {
3680
  int64_t refId;
3681
  SArray* taskStatus;  // SArray<STaskStatus>
3682
} SSchedulerStatusRsp;
3683

3684
typedef struct {
3685
  uint64_t queryId;
3686
  uint64_t taskId;
3687
  int8_t   action;
3688
} STaskAction;
3689

3690
typedef struct SQueryNodeEpId {
3691
  int32_t nodeId;  // vgId or qnodeId
3692
  SEp     ep;
3693
} SQueryNodeEpId;
3694

3695
typedef struct {
3696
  SMsgHead       header;
3697
  uint64_t       clientId;
3698
  SQueryNodeEpId epId;
3699
  SArray*        taskAction;  // SArray<STaskAction>
3700
} SSchedulerHbReq;
3701

3702
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3703
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3704
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3705

3706
typedef struct {
3707
  SQueryNodeEpId epId;
3708
  SArray*        taskStatus;  // SArray<STaskStatus>
3709
} SSchedulerHbRsp;
3710

3711
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3712
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3713
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3714

3715
typedef struct {
3716
  SMsgHead header;
3717
  uint64_t sId;
3718
  uint64_t queryId;
3719
  uint64_t clientId;
3720
  uint64_t taskId;
3721
  int64_t  refId;
3722
  int32_t  execId;
3723
} STaskCancelReq;
3724

3725
typedef struct {
3726
  int32_t code;
3727
} STaskCancelRsp;
3728

3729
typedef struct {
3730
  SMsgHead header;
3731
  uint64_t sId;
3732
  uint64_t queryId;
3733
  uint64_t clientId;
3734
  uint64_t taskId;
3735
  int64_t  refId;
3736
  int32_t  execId;
3737
} STaskDropReq;
3738

3739
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3740
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3741

3742
typedef enum {
3743
  TASK_NOTIFY_FINISHED = 1,
3744
} ETaskNotifyType;
3745

3746
typedef struct {
3747
  SMsgHead        header;
3748
  uint64_t        sId;
3749
  uint64_t        queryId;
3750
  uint64_t        clientId;
3751
  uint64_t        taskId;
3752
  int64_t         refId;
3753
  int32_t         execId;
3754
  ETaskNotifyType type;
3755
} STaskNotifyReq;
3756

3757
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3758
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3759

3760
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3761
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3762

3763
typedef struct {
3764
  int32_t code;
3765
} STaskDropRsp;
3766

3767
#define STREAM_TRIGGER_AT_ONCE                 1
3768
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3769
#define STREAM_TRIGGER_MAX_DELAY               3
3770
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3771
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3772

3773
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3774
#define STREAM_FILL_HISTORY_ON        1
3775
#define STREAM_FILL_HISTORY_OFF       0
3776
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3777
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3778
#define STREAM_CREATE_STABLE_TRUE     1
3779
#define STREAM_CREATE_STABLE_FALSE    0
3780

3781
typedef struct SVgroupVer {
3782
  int32_t vgId;
3783
  int64_t ver;
3784
} SVgroupVer;
3785

3786
typedef struct STaskNotifyEventStat {
3787
  int64_t notifyEventAddTimes;     // call times of add function
3788
  int64_t notifyEventAddElems;     // elements added by add function
3789
  double  notifyEventAddCostSec;   // time cost of add function
3790
  int64_t notifyEventPushTimes;    // call times of push function
3791
  int64_t notifyEventPushElems;    // elements pushed by push function
3792
  double  notifyEventPushCostSec;  // time cost of push function
3793
  int64_t notifyEventPackTimes;    // call times of pack function
3794
  int64_t notifyEventPackElems;    // elements packed by pack function
3795
  double  notifyEventPackCostSec;  // time cost of pack function
3796
  int64_t notifyEventSendTimes;    // call times of send function
3797
  int64_t notifyEventSendElems;    // elements sent by send function
3798
  double  notifyEventSendCostSec;  // time cost of send function
3799
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3800
} STaskNotifyEventStat;
3801

3802
enum {
3803
  TOPIC_SUB_TYPE__DB = 1,
3804
  TOPIC_SUB_TYPE__TABLE,
3805
  TOPIC_SUB_TYPE__COLUMN,
3806
};
3807

3808
#define DEFAULT_MAX_POLL_INTERVAL  300000
3809
#define DEFAULT_SESSION_TIMEOUT    12000
3810
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3811
#define DEFAULT_MIN_POLL_ROWS      4096
3812

3813
typedef struct {
3814
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3815
  int8_t igExists;
3816
  int8_t subType;
3817
  int8_t withMeta;
3818
  char*  sql;
3819
  char   subDbName[TSDB_DB_FNAME_LEN];
3820
  char*  ast;
3821
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3822
  int8_t reload;
3823
} SCMCreateTopicReq;
3824

3825
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3826
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3827
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3828

3829
typedef struct {
3830
  int64_t consumerId;
3831
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3832

3833
typedef struct {
3834
  int64_t consumerId;
3835
  char    cgroup[TSDB_CGROUP_LEN];
3836
  char    clientId[TSDB_CLIENT_ID_LEN];
3837
  char    user[TSDB_USER_LEN];
3838
  char    fqdn[TSDB_FQDN_LEN];
3839
  SArray* topicNames;  // SArray<char**>
3840

3841
  int8_t  withTbName;
3842
  int8_t  autoCommit;
3843
  int32_t autoCommitInterval;
3844
  int8_t  resetOffsetCfg;
3845
  int8_t  enableReplay;
3846
  int8_t  enableBatchMeta;
3847
  int32_t sessionTimeoutMs;
3848
  int32_t maxPollIntervalMs;
3849
} SCMSubscribeReq;
3850

3851
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3852
  int32_t tlen = 0;
270,150✔
3853
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
270,150✔
3854
  tlen += taosEncodeString(buf, pReq->cgroup);
270,150✔
3855
  tlen += taosEncodeString(buf, pReq->clientId);
270,150✔
3856

3857
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
270,150✔
3858
  tlen += taosEncodeFixedI32(buf, topicNum);
270,150✔
3859

3860
  for (int32_t i = 0; i < topicNum; i++) {
376,416✔
3861
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
212,532✔
3862
  }
3863

3864
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
270,150✔
3865
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
270,150✔
3866
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
270,150✔
3867
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
270,150✔
3868
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
270,150✔
3869
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
270,150✔
3870
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
270,150✔
3871
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
270,150✔
3872
  tlen += taosEncodeString(buf, pReq->user);
270,150✔
3873
  tlen += taosEncodeString(buf, pReq->fqdn);
270,150✔
3874

3875
  return tlen;
270,150✔
3876
}
3877

3878
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3879
  void* start = buf;
110,298✔
3880
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
110,298✔
3881
  buf = taosDecodeStringTo(buf, pReq->cgroup);
110,298✔
3882
  buf = taosDecodeStringTo(buf, pReq->clientId);
110,298✔
3883

3884
  int32_t topicNum = 0;
110,298✔
3885
  buf = taosDecodeFixedI32(buf, &topicNum);
110,298✔
3886

3887
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
110,298✔
3888
  if (pReq->topicNames == NULL) {
110,298✔
3889
    return terrno;
×
3890
  }
3891
  for (int32_t i = 0; i < topicNum; i++) {
158,065✔
3892
    char* name = NULL;
47,767✔
3893
    buf = taosDecodeString(buf, &name);
47,767✔
3894
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
95,534✔
3895
      return terrno;
×
3896
    }
3897
  }
3898

3899
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
110,298✔
3900
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
110,298✔
3901
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
110,298✔
3902
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
110,298✔
3903
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
110,298✔
3904
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
110,298✔
3905
  if ((char*)buf - (char*)start < len) {
110,298✔
3906
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
110,298✔
3907
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
110,298✔
3908
    buf = taosDecodeStringTo(buf, pReq->user);
110,298✔
3909
    buf = taosDecodeStringTo(buf, pReq->fqdn);
220,596✔
3910
  } else {
3911
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3912
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3913
  }
3914

3915
  return 0;
110,298✔
3916
}
3917

3918
typedef struct {
3919
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3920
  SArray* removedConsumers;  // SArray<int64_t>
3921
  SArray* newConsumers;      // SArray<int64_t>
3922
} SMqRebInfo;
3923

3924
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3925
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
84,674✔
3926
  if (pRebInfo == NULL) {
84,674✔
3927
    return NULL;
×
3928
  }
3929
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
84,674✔
3930
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
84,674✔
3931
  if (pRebInfo->removedConsumers == NULL) {
84,674✔
3932
    goto _err;
×
3933
  }
3934
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
84,674✔
3935
  if (pRebInfo->newConsumers == NULL) {
84,674✔
3936
    goto _err;
×
3937
  }
3938
  return pRebInfo;
84,674✔
3939
_err:
×
3940
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3941
  taosArrayDestroy(pRebInfo->newConsumers);
×
3942
  taosMemoryFreeClear(pRebInfo);
×
3943
  return NULL;
×
3944
}
3945

3946
typedef struct {
3947
  int64_t streamId;
3948
  int64_t checkpointId;
3949
  char    streamName[TSDB_STREAM_FNAME_LEN];
3950
} SMStreamDoCheckpointMsg;
3951

3952
typedef struct {
3953
  int64_t status;
3954
} SMVSubscribeRsp;
3955

3956
typedef struct {
3957
  char    name[TSDB_TOPIC_FNAME_LEN];
3958
  int8_t  igNotExists;
3959
  int32_t sqlLen;
3960
  char*   sql;
3961
  int8_t  force;
3962
} SMDropTopicReq;
3963

3964
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3965
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3966
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3967

3968
typedef struct {
3969
  char    name[TSDB_TOPIC_FNAME_LEN];
3970
  int8_t  igNotExists;
3971
  int32_t sqlLen;
3972
  char*   sql;
3973
} SMReloadTopicReq;
3974

3975
int32_t tSerializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
3976
int32_t tDeserializeSMReloadTopicReq(void* buf, int32_t bufLen, SMReloadTopicReq* pReq);
3977
void    tFreeSMReloadTopicReq(SMReloadTopicReq* pReq);
3978

3979
typedef struct {
3980
  char   topic[TSDB_TOPIC_FNAME_LEN];
3981
  char   cgroup[TSDB_CGROUP_LEN];
3982
  int8_t igNotExists;
3983
  int8_t force;
3984
} SMDropCgroupReq;
3985

3986
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3987
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3988

3989
typedef struct {
3990
  int8_t reserved;
3991
} SMDropCgroupRsp;
3992

3993
typedef struct {
3994
  char    name[TSDB_TABLE_FNAME_LEN];
3995
  int8_t  alterType;
3996
  SSchema schema;
3997
} SAlterTopicReq;
3998

3999
typedef struct {
4000
  SMsgHead head;
4001
  char     name[TSDB_TABLE_FNAME_LEN];
4002
  int64_t  tuid;
4003
  int32_t  sverson;
4004
  int32_t  execLen;
4005
  char*    executor;
4006
  int32_t  sqlLen;
4007
  char*    sql;
4008
} SDCreateTopicReq;
4009

4010
typedef struct {
4011
  SMsgHead head;
4012
  char     name[TSDB_TABLE_FNAME_LEN];
4013
  int64_t  tuid;
4014
} SDDropTopicReq;
4015

4016
typedef struct {
4017
  char*      name;
4018
  int64_t    uid;
4019
  int64_t    interval[2];
4020
  int8_t     intervalUnit;
4021
  int16_t    nFuncs;
4022
  col_id_t*  funcColIds;  // column ids specified by user
4023
  func_id_t* funcIds;     // function ids specified by user
4024
} SRSmaParam;
4025

4026
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
4027
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
4028

4029
// TDMT_VND_CREATE_STB ==============
4030
typedef struct SVCreateStbReq {
4031
  char*           name;
4032
  tb_uid_t        suid;
4033
  int8_t          rollup;
4034
  SSchemaWrapper  schemaRow;
4035
  SSchemaWrapper  schemaTag;
4036
  SRSmaParam      rsmaParam;
4037
  int32_t         alterOriDataLen;
4038
  void*           alterOriData;
4039
  int8_t          source;
4040
  int8_t          colCmpred;
4041
  SColCmprWrapper colCmpr;
4042
  int64_t         keep;
4043
  SExtSchema*     pExtSchemas;
4044
  int8_t          virtualStb;
4045
} SVCreateStbReq;
4046

4047
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
4048
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
4049

4050
// TDMT_VND_DROP_STB ==============
4051
typedef struct SVDropStbReq {
4052
  char*    name;
4053
  tb_uid_t suid;
4054
} SVDropStbReq;
4055

4056
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
4057
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
4058

4059
// TDMT_VND_CREATE_TABLE ==============
4060
#define TD_CREATE_IF_NOT_EXISTS       0x1
4061
#define TD_CREATE_NORMAL_TB_IN_STREAM 0x2
4062
#define TD_CREATE_SUB_TB_IN_STREAM    0x4
4063
typedef struct SVCreateTbReq {
4064
  int32_t  flags;
4065
  char*    name;
4066
  tb_uid_t uid;
4067
  int64_t  btime;
4068
  int32_t  ttl;
4069
  int32_t  commentLen;
4070
  char*    comment;
4071
  int8_t   type;
4072
  union {
4073
    struct {
4074
      char*    stbName;  // super table name
4075
      uint8_t  tagNum;
4076
      tb_uid_t suid;
4077
      SArray*  tagName;
4078
      uint8_t* pTag;
4079
    } ctb;
4080
    struct {
4081
      SSchemaWrapper schemaRow;
4082
    } ntb;
4083
  };
4084
  int32_t         sqlLen;
4085
  char*           sql;
4086
  SColCmprWrapper colCmpr;
4087
  SExtSchema*     pExtSchemas;
4088
  SColRefWrapper  colRef;  // col reference for virtual table
4089
} SVCreateTbReq;
4090

4091
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
4092
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
4093
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4094
void tDestroySVSubmitCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
4095

4096
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
4097
  if (NULL == req) {
2,147,483,647✔
4098
    return;
2,147,483,647✔
4099
  }
4100

4101
  taosMemoryFreeClear(req->sql);
57,466,315✔
4102
  taosMemoryFreeClear(req->name);
57,467,511✔
4103
  taosMemoryFreeClear(req->comment);
57,476,310✔
4104
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
57,473,247✔
4105
    taosMemoryFreeClear(req->ctb.pTag);
54,867,270✔
4106
    taosMemoryFreeClear(req->ctb.stbName);
54,856,141✔
4107
    taosArrayDestroy(req->ctb.tagName);
54,881,522✔
4108
    req->ctb.tagName = NULL;
54,870,104✔
4109
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
2,586,290✔
4110
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
2,586,290✔
4111
  }
4112
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
57,460,678✔
4113
  taosMemoryFreeClear(req->pExtSchemas);
57,473,112✔
4114
  taosMemoryFreeClear(req->colRef.pColRef);
57,472,410✔
4115
}
4116

4117
typedef struct {
4118
  int32_t nReqs;
4119
  union {
4120
    SVCreateTbReq* pReqs;
4121
    SArray*        pArray;
4122
  };
4123
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4124
} SVCreateTbBatchReq;
4125

4126
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
4127
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
4128
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
4129

4130
typedef struct {
4131
  int32_t        code;
4132
  STableMetaRsp* pMeta;
4133
} SVCreateTbRsp, SVUpdateTbRsp;
4134

4135
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
4136
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
4137
void tFreeSVCreateTbRsp(void* param);
4138

4139
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
4140
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
4141

4142
typedef struct {
4143
  int32_t nRsps;
4144
  union {
4145
    SVCreateTbRsp* pRsps;
4146
    SArray*        pArray;
4147
  };
4148
} SVCreateTbBatchRsp;
4149

4150
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
4151
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
4152

4153
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4154
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
4155

4156
// TDMT_VND_DROP_TABLE =================
4157
typedef struct {
4158
  char*    name;
4159
  uint64_t suid;  // for tmq in wal format
4160
  int64_t  uid;
4161
  int8_t   igNotExists;
4162
  int8_t   isVirtual;
4163
} SVDropTbReq;
4164

4165
typedef struct {
4166
  int32_t code;
4167
} SVDropTbRsp;
4168

4169
typedef struct {
4170
  int32_t nReqs;
4171
  union {
4172
    SVDropTbReq* pReqs;
4173
    SArray*      pArray;
4174
  };
4175
} SVDropTbBatchReq;
4176

4177
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
4178
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
4179

4180
typedef struct {
4181
  int32_t nRsps;
4182
  union {
4183
    SVDropTbRsp* pRsps;
4184
    SArray*      pArray;
4185
  };
4186
} SVDropTbBatchRsp;
4187

4188
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
4189
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
4190

4191
// TDMT_VND_ALTER_TABLE =====================
4192
typedef struct SMultiTagUpateVal {
4193
  char*    tagName;
4194
  int32_t  colId;
4195
  int8_t   tagType;
4196
  int8_t   tagFree;
4197
  uint32_t nTagVal;
4198
  uint8_t* pTagVal;
4199
  int8_t   isNull;
4200
  SArray*  pTagArray;
4201
} SMultiTagUpateVal;
4202
typedef struct SVAlterTbReq {
4203
  char*   tbName;
4204
  int8_t  action;
4205
  char*   colName;
4206
  int32_t colId;
4207
  // TSDB_ALTER_TABLE_ADD_COLUMN
4208
  int8_t  type;
4209
  int8_t  flags;
4210
  int32_t bytes;
4211
  // TSDB_ALTER_TABLE_DROP_COLUMN
4212
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
4213
  int8_t   colModType;
4214
  int32_t  colModBytes;
4215
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
4216
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
4217
  int8_t   isNull;
4218
  int8_t   tagType;
4219
  int8_t   tagFree;
4220
  uint32_t nTagVal;
4221
  uint8_t* pTagVal;
4222
  SArray*  pTagArray;
4223
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
4224
  int8_t   updateTTL;
4225
  int32_t  newTTL;
4226
  int32_t  newCommentLen;
4227
  char*    newComment;
4228
  int64_t  ctimeMs;    // fill by vnode
4229
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
4230
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
4231
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
4232
  // for Add column
4233
  STypeMod typeMod;
4234
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
4235
  char* refDbName;
4236
  char* refTbName;
4237
  char* refColName;
4238
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
4239
} SVAlterTbReq;
4240

4241
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
4242
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
4243
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
4244
void    tfreeMultiTagUpateVal(void* pMultiTag);
4245

4246
typedef struct {
4247
  int32_t        code;
4248
  STableMetaRsp* pMeta;
4249
} SVAlterTbRsp;
4250

4251
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
4252
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
4253
// ======================
4254

4255
typedef struct {
4256
  SMsgHead head;
4257
  int64_t  uid;
4258
  int32_t  tid;
4259
  int16_t  tversion;
4260
  int16_t  colId;
4261
  int8_t   type;
4262
  int16_t  bytes;
4263
  int32_t  tagValLen;
4264
  int16_t  numOfTags;
4265
  int32_t  schemaLen;
4266
  char     data[];
4267
} SUpdateTagValReq;
4268

4269
typedef struct {
4270
  SMsgHead head;
4271
} SUpdateTagValRsp;
4272

4273
typedef struct {
4274
  SMsgHead head;
4275
} SVShowTablesReq;
4276

4277
typedef struct {
4278
  SMsgHead head;
4279
  int32_t  id;
4280
} SVShowTablesFetchReq;
4281

4282
typedef struct {
4283
  int64_t useconds;
4284
  int8_t  completed;  // all results are returned to client
4285
  int8_t  precision;
4286
  int8_t  compressed;
4287
  int32_t compLen;
4288
  int32_t numOfRows;
4289
  char    data[];
4290
} SVShowTablesFetchRsp;
4291

4292
typedef struct {
4293
  int64_t consumerId;
4294
  int32_t epoch;
4295
  char    cgroup[TSDB_CGROUP_LEN];
4296
} SMqAskEpReq;
4297

4298
typedef struct {
4299
  int32_t key;
4300
  int32_t valueLen;
4301
  void*   value;
4302
} SKv;
4303

4304
typedef struct {
4305
  int64_t tscRid;
4306
  int8_t  connType;
4307
} SClientHbKey;
4308

4309
typedef struct {
4310
  int64_t tid;
4311
  char    status[TSDB_JOB_STATUS_LEN];
4312
} SQuerySubDesc;
4313

4314
typedef struct {
4315
  char     sql[TSDB_SHOW_SQL_LEN];
4316
  uint64_t queryId;
4317
  int64_t  useconds;
4318
  int64_t  stime;  // timestamp precision ms
4319
  int64_t  reqRid;
4320
  bool     stableQuery;
4321
  bool     isSubQuery;
4322
  char     fqdn[TSDB_FQDN_LEN];
4323
  int32_t  subPlanNum;
4324
  SArray*  subDesc;  // SArray<SQuerySubDesc>
4325
} SQueryDesc;
4326

4327
typedef struct {
4328
  uint32_t connId;
4329
  SArray*  queryDesc;  // SArray<SQueryDesc>
4330
} SQueryHbReqBasic;
4331

4332
typedef struct {
4333
  uint32_t connId;
4334
  uint64_t killRid;
4335
  int32_t  totalDnodes;
4336
  int32_t  onlineDnodes;
4337
  int8_t   killConnection;
4338
  int8_t   align[3];
4339
  SEpSet   epSet;
4340
  SArray*  pQnodeList;
4341
} SQueryHbRspBasic;
4342

4343
typedef struct SAppClusterSummary {
4344
  uint64_t numOfInsertsReq;
4345
  uint64_t numOfInsertRows;
4346
  uint64_t insertElapsedTime;
4347
  uint64_t insertBytes;  // submit to tsdb since launched.
4348

4349
  uint64_t fetchBytes;
4350
  uint64_t numOfQueryReq;
4351
  uint64_t queryElapsedTime;
4352
  uint64_t numOfSlowQueries;
4353
  uint64_t totalRequests;
4354
  uint64_t currentRequests;  // the number of SRequestObj
4355
} SAppClusterSummary;
4356

4357
typedef struct {
4358
  int64_t            appId;
4359
  int32_t            pid;
4360
  char               name[TSDB_APP_NAME_LEN];
4361
  int64_t            startTime;
4362
  SAppClusterSummary summary;
4363
} SAppHbReq;
4364

4365
typedef struct {
4366
  SClientHbKey      connKey;
4367
  int64_t           clusterId;
4368
  SAppHbReq         app;
4369
  SQueryHbReqBasic* query;
4370
  SHashObj*         info;  // hash<Skv.key, Skv>
4371
  char              userApp[TSDB_APP_NAME_LEN];
4372
  uint32_t          userIp;
4373
  SIpRange          userDualIp;
4374
  char              sVer[TSDB_VERSION_LEN];
4375
  char              cInfo[CONNECTOR_INFO_LEN];
4376
} SClientHbReq;
4377

4378
typedef struct {
4379
  int64_t reqId;
4380
  SArray* reqs;  // SArray<SClientHbReq>
4381
  int64_t ipWhiteListVer;
4382
} SClientHbBatchReq;
4383

4384
typedef struct {
4385
  SClientHbKey      connKey;
4386
  int32_t           status;
4387
  SQueryHbRspBasic* query;
4388
  SArray*           info;  // Array<Skv>
4389
} SClientHbRsp;
4390

4391
typedef struct {
4392
  int64_t       reqId;
4393
  int64_t       rspId;
4394
  int32_t       svrTimestamp;
4395
  SArray*       rsps;  // SArray<SClientHbRsp>
4396
  SMonitorParas monitorParas;
4397
  int8_t        enableAuditDelete;
4398
  int8_t        enableStrongPass;
4399
  int8_t        enableAuditSelect;
4400
  int8_t        enableAuditInsert;
4401
  int8_t        auditLevel;
4402
} SClientHbBatchRsp;
4403

4404
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
81,879,947✔
4405

4406
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
4407
  void* pIter = taosHashIterate(info, NULL);
55,872,452✔
4408
  while (pIter != NULL) {
119,782,691✔
4409
    SKv* kv = (SKv*)pIter;
63,910,129✔
4410
    taosMemoryFreeClear(kv->value);
63,910,129✔
4411
    pIter = taosHashIterate(info, pIter);
63,910,756✔
4412
  }
4413
}
55,872,562✔
4414

4415
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
33,006,086✔
4416
  SQueryDesc* desc = (SQueryDesc*)pDesc;
33,006,086✔
4417
  if (desc->subDesc) {
33,006,086✔
4418
    taosArrayDestroy(desc->subDesc);
28,095,538✔
4419
    desc->subDesc = NULL;
28,095,322✔
4420
  }
4421
}
33,005,870✔
4422

4423
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
71,203,822✔
4424
  SClientHbReq* req = (SClientHbReq*)pReq;
74,029,514✔
4425
  if (req->query) {
74,029,514✔
4426
    if (req->query->queryDesc) {
63,089,097✔
4427
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
30,575,896✔
4428
    }
4429
    taosMemoryFreeClear(req->query);
63,089,004✔
4430
  }
4431

4432
  if (req->info) {
74,031,638✔
4433
    tFreeReqKvHash(req->info);
55,872,000✔
4434
    taosHashCleanup(req->info);
55,872,562✔
4435
    req->info = NULL;
55,871,813✔
4436
  }
4437
}
35,896,085✔
4438

4439
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
4440
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
4441

4442
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
4443
  if (pReq == NULL) return;
30,511,948✔
4444
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
30,511,948✔
4445
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
30,511,948✔
4446
  taosMemoryFree(pReq);
30,511,948✔
4447
}
4448

4449
static FORCE_INLINE void tFreeClientKv(void* pKv) {
23,004,342✔
4450
  SKv* kv = (SKv*)pKv;
23,004,342✔
4451
  if (kv) {
23,004,342✔
4452
    taosMemoryFreeClear(kv->value);
23,004,342✔
4453
  }
4454
}
23,004,969✔
4455

4456
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
70,939,202✔
4457
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
70,939,202✔
4458
  if (rsp->query) {
70,939,202✔
4459
    taosArrayDestroy(rsp->query->pQnodeList);
62,880,055✔
4460
    taosMemoryFreeClear(rsp->query);
62,879,673✔
4461
  }
4462
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
70,941,784✔
4463
}
37,871,513✔
4464

4465
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
4466
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
55,415,967✔
4467
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
55,415,967✔
4468
}
55,416,956✔
4469

4470
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
4471
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
4472
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
4473

4474
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
4475
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
173,487,636✔
4476
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
173,487,986✔
4477
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
173,488,336✔
4478
  return 0;
86,744,168✔
4479
}
4480

4481
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
4482
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
81,902,483✔
4483
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
81,903,032✔
4484
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
40,951,516✔
4485
  if (pKv->value == NULL) {
40,949,906✔
4486
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
4487
  }
4488
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
40,949,357✔
4489
  return 0;
40,951,516✔
4490
}
4491

4492
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
4493
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
275,984,916✔
4494
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
275,985,125✔
4495
  return 0;
137,993,129✔
4496
}
4497

4498
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
4499
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
137,481,805✔
4500
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
137,481,905✔
4501
  return 0;
68,741,025✔
4502
}
4503

4504
typedef struct {
4505
  int32_t vgId;
4506
  // TODO stas
4507
} SMqReportVgInfo;
4508

4509
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
4510
  int32_t tlen = 0;
4511
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
4512
  return tlen;
4513
}
4514

4515
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
4516
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
4517
  return buf;
4518
}
4519

4520
typedef struct {
4521
  int32_t epoch;
4522
  int64_t topicUid;
4523
  char    name[TSDB_TOPIC_FNAME_LEN];
4524
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
4525
} SMqTopicInfo;
4526

4527
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
4528
  int32_t tlen = 0;
4529
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
4530
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
4531
  tlen += taosEncodeString(buf, pTopicInfo->name);
4532
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
4533
  tlen += taosEncodeFixedI32(buf, sz);
4534
  for (int32_t i = 0; i < sz; i++) {
4535
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
4536
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
4537
  }
4538
  return tlen;
4539
}
4540

4541
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
4542
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
4543
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
4544
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4545
  int32_t sz;
4546
  buf = taosDecodeFixedI32(buf, &sz);
4547
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4548
    return NULL;
4549
  }
4550
  for (int32_t i = 0; i < sz; i++) {
4551
    SMqReportVgInfo vgInfo;
4552
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4553
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4554
      return NULL;
4555
    }
4556
  }
4557
  return buf;
4558
}
4559

4560
typedef struct {
4561
  int32_t status;  // ask hb endpoint
4562
  int32_t epoch;
4563
  int64_t consumerId;
4564
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4565
} SMqReportReq;
4566

4567
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4568
  int32_t tlen = 0;
4569
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4570
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4571
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4572
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4573
  tlen += taosEncodeFixedI32(buf, sz);
4574
  for (int32_t i = 0; i < sz; i++) {
4575
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4576
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4577
  }
4578
  return tlen;
4579
}
4580

4581
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4582
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4583
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4584
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4585
  int32_t sz;
4586
  buf = taosDecodeFixedI32(buf, &sz);
4587
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4588
    return NULL;
4589
  }
4590
  for (int32_t i = 0; i < sz; i++) {
4591
    SMqTopicInfo topicInfo;
4592
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4593
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4594
      return NULL;
4595
    }
4596
  }
4597
  return buf;
4598
}
4599

4600
typedef struct {
4601
  SMsgHead head;
4602
  int64_t  leftForVer;
4603
  int32_t  vgId;
4604
  int64_t  consumerId;
4605
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4606
} SMqVDeleteReq;
4607

4608
typedef struct {
4609
  int8_t reserved;
4610
} SMqVDeleteRsp;
4611

4612
typedef struct {
4613
  char*  name;
4614
  int8_t igNotExists;
4615
} SMDropStreamReq;
4616

4617
typedef struct {
4618
  int8_t reserved;
4619
} SMDropStreamRsp;
4620

4621
typedef struct {
4622
  SMsgHead head;
4623
  int64_t  resetRelHalt;  // reset related stream task halt status
4624
  int64_t  streamId;
4625
  int32_t  taskId;
4626
} SVDropStreamTaskReq;
4627

4628
typedef struct {
4629
  int8_t reserved;
4630
} SVDropStreamTaskRsp;
4631

4632
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4633
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4634
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4635

4636
typedef struct {
4637
  char*  name;
4638
  int8_t igNotExists;
4639
} SMPauseStreamReq;
4640

4641
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4642
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4643
void    tFreeMPauseStreamReq(SMPauseStreamReq* pReq);
4644

4645
typedef struct {
4646
  char*  name;
4647
  int8_t igNotExists;
4648
  int8_t igUntreated;
4649
} SMResumeStreamReq;
4650

4651
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4652
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4653
void    tFreeMResumeStreamReq(SMResumeStreamReq* pReq);
4654

4655
typedef struct {
4656
  char*       name;
4657
  int8_t      calcAll;
4658
  STimeWindow timeRange;
4659
} SMRecalcStreamReq;
4660

4661
int32_t tSerializeSMRecalcStreamReq(void* buf, int32_t bufLen, const SMRecalcStreamReq* pReq);
4662
int32_t tDeserializeSMRecalcStreamReq(void* buf, int32_t bufLen, SMRecalcStreamReq* pReq);
4663
void    tFreeMRecalcStreamReq(SMRecalcStreamReq* pReq);
4664

4665
typedef struct SVndSetKeepVersionReq {
4666
  int64_t keepVersion;
4667
} SVndSetKeepVersionReq;
4668

4669
int32_t tSerializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4670
int32_t tDeserializeSVndSetKeepVersionReq(void* buf, int32_t bufLen, SVndSetKeepVersionReq* pReq);
4671

4672
typedef struct SVUpdateCheckpointInfoReq {
4673
  SMsgHead head;
4674
  int64_t  streamId;
4675
  int32_t  taskId;
4676
  int64_t  checkpointId;
4677
  int64_t  checkpointVer;
4678
  int64_t  checkpointTs;
4679
  int32_t  transId;
4680
  int64_t  hStreamId;  // add encode/decode
4681
  int64_t  hTaskId;
4682
  int8_t   dropRelHTask;
4683
} SVUpdateCheckpointInfoReq;
4684

4685
typedef struct {
4686
  int64_t leftForVer;
4687
  int32_t vgId;
4688
  int64_t oldConsumerId;
4689
  int64_t newConsumerId;
4690
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4691
  int8_t  subType;
4692
  int8_t  withMeta;
4693
  char*   qmsg;  // SubPlanToString
4694
  SSchemaWrapper schema;
4695
  int64_t suid;
4696
} SMqRebVgReq;
4697

4698
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4699
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4700

4701
// tqOffset
4702
enum {
4703
  TMQ_OFFSET__RESET_NONE = -3,
4704
  TMQ_OFFSET__RESET_EARLIEST = -2,
4705
  TMQ_OFFSET__RESET_LATEST = -1,
4706
  TMQ_OFFSET__LOG = 1,
4707
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4708
  TMQ_OFFSET__SNAPSHOT_META = 3,
4709
};
4710

4711
enum {
4712
  WITH_DATA = 0,
4713
  WITH_META = 1,
4714
  ONLY_META = 2,
4715
};
4716

4717
#define TQ_OFFSET_VERSION 1
4718

4719
typedef struct {
4720
  int8_t type;
4721
  union {
4722
    // snapshot
4723
    struct {
4724
      int64_t uid;
4725
      int64_t ts;
4726
      SValue  primaryKey;
4727
    };
4728
    // log
4729
    struct {
4730
      int64_t version;
4731
    };
4732
  };
4733
} STqOffsetVal;
4734

4735
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4736
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
1,654,357✔
4737
  pOffsetVal->uid = uid;
1,654,356✔
4738
  pOffsetVal->ts = ts;
1,654,052✔
4739
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
1,653,972✔
4740
    taosMemoryFree(pOffsetVal->primaryKey.pData);
66✔
4741
  }
4742
  pOffsetVal->primaryKey = primaryKey;
1,653,378✔
4743
}
1,653,757✔
4744

4745
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4746
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
8,135✔
4747
  pOffsetVal->uid = uid;
8,135✔
4748
}
8,135✔
4749

4750
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4751
  pOffsetVal->type = TMQ_OFFSET__LOG;
45,874,890✔
4752
  pOffsetVal->version = ver;
45,874,758✔
4753
}
45,871,495✔
4754

4755
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4756
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4757
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4758
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4759
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4760
void    tOffsetDestroy(void* pVal);
4761

4762
typedef struct {
4763
  STqOffsetVal val;
4764
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4765
} STqOffset;
4766

4767
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4768
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4769
void    tDeleteSTqOffset(void* val);
4770

4771
typedef struct SMqVgOffset {
4772
  int64_t   consumerId;
4773
  STqOffset offset;
4774
} SMqVgOffset;
4775

4776
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4777
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4778

4779
typedef struct {
4780
  char    name[TSDB_TABLE_FNAME_LEN];
4781
  char    stb[TSDB_TABLE_FNAME_LEN];
4782
  int8_t  igExists;
4783
  int8_t  intervalUnit;
4784
  int8_t  slidingUnit;
4785
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4786
  int32_t dstVgId;   // for stream
4787
  int64_t interval;
4788
  int64_t offset;
4789
  int64_t sliding;
4790
  int64_t maxDelay;
4791
  int64_t watermark;
4792
  int32_t exprLen;        // strlen + 1
4793
  int32_t tagsFilterLen;  // strlen + 1
4794
  int32_t sqlLen;         // strlen + 1
4795
  int32_t astLen;         // strlen + 1
4796
  char*   expr;
4797
  char*   tagsFilter;
4798
  char*   sql;
4799
  char*   ast;
4800
  int64_t deleteMark;
4801
  int64_t lastTs;
4802
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4803
  SArray* pVgroupVerList;
4804
  int8_t  recursiveTsma;
4805
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4806
  char*   createStreamReq;
4807
  int32_t streamReqLen;
4808
  char*   dropStreamReq;
4809
  int32_t dropStreamReqLen;
4810
  int64_t uid;
4811
} SMCreateSmaReq;
4812

4813
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4814
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4815
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4816

4817
typedef struct {
4818
  char    name[TSDB_TABLE_FNAME_LEN];
4819
  int8_t  igNotExists;
4820
  char*   dropStreamReq;
4821
  int32_t dropStreamReqLen;
4822
} SMDropSmaReq;
4823

4824
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4825
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4826
void    tFreeSMDropSmaReq(SMDropSmaReq* pReq);
4827

4828
typedef struct {
4829
  char name[TSDB_TABLE_NAME_LEN];
4830
  union {
4831
    char tbFName[TSDB_TABLE_FNAME_LEN];  // used by mnode
4832
    char tbName[TSDB_TABLE_NAME_LEN];    // used by vnode
4833
  };
4834
  int8_t tbType;  // ETableType: 1 stable, 3 normal table
4835
  union {
4836
    int8_t igExists;   // used by mnode
4837
    int8_t alterType;  // used by vnode
4838
  };
4839
  int8_t     intervalUnit;
4840
  int16_t    nFuncs;       // number of functions specified by user
4841
  col_id_t*  funcColIds;   // column ids specified by user
4842
  func_id_t* funcIds;      // function ids specified by user
4843
  int64_t    interval[2];  // 0 unspecified, > 0 valid interval
4844
  int64_t    tbUid;
4845
  int64_t    uid;     // rsma uid
4846
  int32_t    sqlLen;  // strlen + 1
4847
  char*      sql;
4848
} SMCreateRsmaReq;
4849

4850
int32_t tSerializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4851
int32_t tDeserializeSMCreateRsmaReq(void* buf, int32_t bufLen, SMCreateRsmaReq* pReq);
4852
void    tFreeSMCreateRsmaReq(SMCreateRsmaReq* pReq);
4853

4854
typedef SMCreateRsmaReq SVCreateRsmaReq;
4855

4856
int32_t tSerializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4857
int32_t tDeserializeSVCreateRsmaReq(void* buf, int32_t bufLen, SVCreateRsmaReq* pReq);
4858
void    tFreeSVCreateRsmaReq(SVCreateRsmaReq* pReq);
4859

4860
typedef SMCreateRsmaReq SVAlterRsmaReq;
4861

4862
int32_t tSerializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4863
int32_t tDeserializeSVAlterRsmaReq(void* buf, int32_t bufLen, SVAlterRsmaReq* pReq);
4864
void    tFreeSVAlterRsmaReq(SVAlterRsmaReq* pReq);
4865

4866
typedef struct {
4867
  char       name[TSDB_TABLE_NAME_LEN];
4868
  int8_t     alterType;
4869
  int8_t     tbType;  // ETableType: 1 stable, 3 normal table
4870
  int8_t     igNotExists;
4871
  int16_t    nFuncs;      // number of functions specified by user
4872
  col_id_t*  funcColIds;  // column ids specified by user
4873
  func_id_t* funcIds;     // function ids specified by user
4874
  int32_t    sqlLen;      // strlen + 1
4875
  char*      sql;
4876
} SMAlterRsmaReq;
4877

4878
int32_t tSerializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4879
int32_t tDeserializeSMAlterRsmaReq(void* buf, int32_t bufLen, SMAlterRsmaReq* pReq);
4880
void    tFreeSMAlterRsmaReq(SMAlterRsmaReq* pReq);
4881

4882
typedef struct {
4883
  int64_t    id;
4884
  char       name[TSDB_TABLE_NAME_LEN];
4885
  char       tbFName[TSDB_TABLE_FNAME_LEN];
4886
  int32_t    code;
4887
  int32_t    version;
4888
  int8_t     tbType;
4889
  int8_t     intervalUnit;
4890
  col_id_t   nFuncs;
4891
  col_id_t   nColNames;
4892
  int64_t    interval[2];
4893
  col_id_t*  funcColIds;
4894
  func_id_t* funcIds;
4895
  SArray*    colNames;
4896
} SRsmaInfoRsp;
4897

4898
int32_t tSerializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4899
int32_t tDeserializeRsmaInfoRsp(void* buf, int32_t bufLen, SRsmaInfoRsp* pReq);
4900
void    tFreeRsmaInfoRsp(SRsmaInfoRsp* pReq, bool deep);
4901

4902
typedef struct {
4903
  char   name[TSDB_TABLE_FNAME_LEN];
4904
  int8_t igNotExists;
4905
} SMDropRsmaReq;
4906

4907
int32_t tSerializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4908
int32_t tDeserializeSMDropRsmaReq(void* buf, int32_t bufLen, SMDropRsmaReq* pReq);
4909

4910
typedef struct {
4911
  char    name[TSDB_TABLE_NAME_LEN];
4912
  char    tbName[TSDB_TABLE_NAME_LEN];
4913
  int64_t uid;
4914
  int64_t tbUid;
4915
  int8_t  tbType;
4916
} SVDropRsmaReq;
4917

4918
int32_t tSerializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4919
int32_t tDeserializeSVDropRsmaReq(void* buf, int32_t bufLen, SVDropRsmaReq* pReq);
4920

4921
typedef struct {
4922
  char   dbFName[TSDB_DB_FNAME_LEN];
4923
  char   stbName[TSDB_TABLE_NAME_LEN];
4924
  char   colName[TSDB_COL_NAME_LEN];
4925
  char   idxName[TSDB_INDEX_FNAME_LEN];
4926
  int8_t idxType;
4927
} SCreateTagIndexReq;
4928

4929
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4930
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4931

4932
typedef SMDropSmaReq SDropTagIndexReq;
4933

4934
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4935
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4936

4937
typedef struct {
4938
  int8_t         version;       // for compatibility(default 0)
4939
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4940
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4941
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4942
  int32_t        dstVgId;
4943
  char           indexName[TSDB_INDEX_NAME_LEN];
4944
  int32_t        exprLen;
4945
  int32_t        tagsFilterLen;
4946
  int64_t        indexUid;
4947
  tb_uid_t       tableUid;  // super/child/common table uid
4948
  tb_uid_t       dstTbUid;  // for dstVgroup
4949
  int64_t        interval;
4950
  int64_t        offset;  // use unit by precision of DB
4951
  int64_t        sliding;
4952
  char*          dstTbName;  // for dstVgroup
4953
  char*          expr;       // sma expression
4954
  char*          tagsFilter;
4955
  SSchemaWrapper schemaRow;  // for dstVgroup
4956
  SSchemaWrapper schemaTag;  // for dstVgroup
4957
} STSma;                     // Time-range-wise SMA
4958

4959
typedef STSma SVCreateTSmaReq;
4960

4961
typedef struct {
4962
  int8_t  type;  // 0 status report, 1 update data
4963
  int64_t indexUid;
4964
  int64_t skey;  // start TS key of interval/sliding window
4965
} STSmaMsg;
4966

4967
typedef struct {
4968
  int64_t indexUid;
4969
  char    indexName[TSDB_INDEX_NAME_LEN];
4970
} SVDropTSmaReq;
4971

4972
typedef struct {
4973
  int tmp;  // TODO: to avoid compile error
4974
} SVCreateTSmaRsp, SVDropTSmaRsp;
4975

4976
#if 0
4977
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4978
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4979
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4980
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4981
#endif
4982

4983
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4984
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4985
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4986
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4987

4988
typedef struct {
4989
  int32_t number;
4990
  STSma*  tSma;
4991
} STSmaWrapper;
4992

4993
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4994
  if (pSma) {
×
4995
    taosMemoryFreeClear(pSma->dstTbName);
×
4996
    taosMemoryFreeClear(pSma->expr);
×
4997
    taosMemoryFreeClear(pSma->tagsFilter);
×
4998
  }
4999
}
×
5000

5001
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5002
  if (pSW) {
×
5003
    if (pSW->tSma) {
×
5004
      if (deepCopy) {
×
5005
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
5006
          tDestroyTSma(pSW->tSma + i);
×
5007
        }
5008
      }
5009
      taosMemoryFreeClear(pSW->tSma);
×
5010
    }
5011
  }
5012
}
×
5013

5014
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
5015
  tDestroyTSmaWrapper(pSW, deepCopy);
×
5016
  taosMemoryFreeClear(pSW);
×
5017
  return NULL;
×
5018
}
5019

5020
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
5021
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
5022

5023
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
5024
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
5025

5026
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
5027
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
5028
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5029
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
5030
  }
5031
  return 0;
×
5032
}
5033

5034
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
5035
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
5036
  for (int32_t i = 0; i < pReq->number; ++i) {
×
5037
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
5038
  }
5039
  return 0;
×
5040
}
5041

5042
typedef struct {
5043
  int idx;
5044
} SMCreateFullTextReq;
5045

5046
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5047
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
5048
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
5049

5050
typedef struct {
5051
  char   name[TSDB_TABLE_FNAME_LEN];
5052
  int8_t igNotExists;
5053
} SMDropFullTextReq;
5054

5055
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5056
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
5057

5058
typedef struct {
5059
  char indexFName[TSDB_INDEX_FNAME_LEN];
5060
} SUserIndexReq;
5061

5062
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5063
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
5064

5065
typedef struct {
5066
  char dbFName[TSDB_DB_FNAME_LEN];
5067
  char tblFName[TSDB_TABLE_FNAME_LEN];
5068
  char colName[TSDB_COL_NAME_LEN];
5069
  char indexType[TSDB_INDEX_TYPE_LEN];
5070
  char indexExts[TSDB_INDEX_EXTS_LEN];
5071
} SUserIndexRsp;
5072

5073
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
5074
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
5075

5076
typedef struct {
5077
  char tbFName[TSDB_TABLE_FNAME_LEN];
5078
} STableIndexReq;
5079

5080
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5081
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
5082

5083
typedef struct {
5084
  int8_t  intervalUnit;
5085
  int8_t  slidingUnit;
5086
  int64_t interval;
5087
  int64_t offset;
5088
  int64_t sliding;
5089
  int64_t dstTbUid;
5090
  int32_t dstVgId;
5091
  SEpSet  epSet;
5092
  char*   expr;
5093
} STableIndexInfo;
5094

5095
typedef struct {
5096
  char     tbName[TSDB_TABLE_NAME_LEN];
5097
  char     dbFName[TSDB_DB_FNAME_LEN];
5098
  uint64_t suid;
5099
  int32_t  version;
5100
  int32_t  indexSize;
5101
  SArray*  pIndex;  // STableIndexInfo
5102
} STableIndexRsp;
5103

5104
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
5105
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
5106
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
5107

5108
void tFreeSTableIndexInfo(void* pInfo);
5109

5110
typedef struct {
5111
  int8_t  mqMsgType;
5112
  int32_t code;
5113
  int32_t epoch;
5114
  int64_t consumerId;
5115
  int64_t walsver;
5116
  int64_t walever;
5117
} SMqRspHead;
5118

5119
typedef struct {
5120
  SMsgHead     head;
5121
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
5122
  int8_t       withTbName;
5123
  int8_t       useSnapshot;
5124
  int32_t      epoch;
5125
  uint64_t     reqId;
5126
  int64_t      consumerId;
5127
  int64_t      timeout;
5128
  STqOffsetVal reqOffset;
5129
  int8_t       enableReplay;
5130
  int8_t       sourceExcluded;
5131
  int8_t       rawData;
5132
  int32_t      minPollRows;
5133
  int8_t       enableBatchMeta;
5134
  SHashObj*    uidHash;  // to find if uid is duplicated
5135
} SMqPollReq;
5136

5137
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5138
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
5139
void    tDestroySMqPollReq(SMqPollReq* pReq);
5140

5141
typedef struct {
5142
  int32_t vgId;
5143
  int64_t offset;
5144
  SEpSet  epSet;
5145
} SMqSubVgEp;
5146

5147
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
5148
  int32_t tlen = 0;
355,674✔
5149
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
355,674✔
5150
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
355,674✔
5151
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
355,674✔
5152
  return tlen;
355,674✔
5153
}
5154

5155
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
5156
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
200,924✔
5157
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
200,924✔
5158
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
200,924✔
5159
  return buf;
200,924✔
5160
}
5161

5162
typedef struct {
5163
  char           topic[TSDB_TOPIC_FNAME_LEN];
5164
  char           db[TSDB_DB_FNAME_LEN];
5165
  SArray*        vgs;  // SArray<SMqSubVgEp>
5166
} SMqSubTopicEp;
5167

5168
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
5169
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
5170
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
5171

5172
typedef struct {
5173
  SMqRspHead   head;
5174
  STqOffsetVal rspOffset;
5175
  int16_t      resMsgType;
5176
  int32_t      metaRspLen;
5177
  void*        metaRsp;
5178
} SMqMetaRsp;
5179

5180
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
5181
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
5182
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
5183

5184
#define MQ_DATA_RSP_VERSION 100
5185

5186
typedef struct {
5187
  SMqRspHead   head;
5188
  STqOffsetVal rspOffset;
5189
  STqOffsetVal reqOffset;
5190
  int32_t      blockNum;
5191
  int8_t       withTbName;
5192
  // int8_t       withSchema;
5193
  SArray*      blockDataLen;
5194
  SArray*      blockData;
5195
  SArray*      blockTbName;
5196
  SArray*      blockSchema;
5197

5198
  union {
5199
    struct {
5200
      int64_t sleepTime;
5201
    };
5202
    struct {
5203
      int32_t createTableNum;
5204
      SArray* createTableLen;
5205
      SArray* createTableReq;
5206
    };
5207
    struct {
5208
      int32_t len;
5209
      void*   rawData;
5210
    };
5211
  };
5212
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
5213
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
5214
} SMqDataRsp;
5215

5216
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
5217
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5218
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5219
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
5220
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
5221

5222
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
5223
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
5224
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
5225

5226
typedef struct SMqBatchMetaRsp {
5227
  SMqRspHead   head;  // not serialize
5228
  STqOffsetVal rspOffset;
5229
  SArray*      batchMetaLen;
5230
  SArray*      batchMetaReq;
5231
  void*        pMetaBuff;    // not serialize
5232
  uint32_t     metaBuffLen;  // not serialize
5233
} SMqBatchMetaRsp;
5234

5235
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
5236
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5237
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
5238
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
5239

5240
typedef struct {
5241
  SMqRspHead head;
5242
  char       cgroup[TSDB_CGROUP_LEN];
5243
  SArray*    topics;  // SArray<SMqSubTopicEp>
5244
} SMqAskEpRsp;
5245

5246
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
5247
  int32_t tlen = 0;
3,799,654✔
5248
  // tlen += taosEncodeString(buf, pRsp->cgroup);
5249
  int32_t sz = taosArrayGetSize(pRsp->topics);
3,799,654✔
5250
  tlen += taosEncodeFixedI32(buf, sz);
3,799,756✔
5251
  for (int32_t i = 0; i < sz; i++) {
3,988,520✔
5252
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
188,866✔
5253
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
188,866✔
5254
  }
5255
  return tlen;
3,799,654✔
5256
}
5257

5258
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
5259
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
5260
  int32_t sz;
810,427✔
5261
  buf = taosDecodeFixedI32(buf, &sz);
857,975✔
5262
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
857,975✔
5263
  if (pRsp->topics == NULL) {
857,975✔
5264
    return NULL;
×
5265
  }
5266
  for (int32_t i = 0; i < sz; i++) {
987,002✔
5267
    SMqSubTopicEp topicEp;
111,776✔
5268
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
129,027✔
5269
    if (buf == NULL) {
129,027✔
5270
      return NULL;
×
5271
    }
5272
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
258,054✔
5273
      return NULL;
×
5274
    }
5275
  }
5276
  return buf;
857,975✔
5277
}
5278

5279
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
5280
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
3,168,107✔
5281
}
3,168,107✔
5282

5283
typedef struct {
5284
  int32_t      vgId;
5285
  STqOffsetVal offset;
5286
  int64_t      rows;
5287
  int64_t      ever;
5288
} OffsetRows;
5289

5290
typedef struct {
5291
  char    topicName[TSDB_TOPIC_FNAME_LEN];
5292
  SArray* offsetRows;
5293
} TopicOffsetRows;
5294

5295
typedef struct {
5296
  int64_t consumerId;
5297
  int32_t epoch;
5298
  SArray* topics;
5299
  int8_t  pollFlag;
5300
} SMqHbReq;
5301

5302
typedef struct {
5303
  char   topic[TSDB_TOPIC_FNAME_LEN];
5304
  int8_t noPrivilege;
5305
} STopicPrivilege;
5306

5307
typedef struct {
5308
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
5309
  int32_t debugFlag;
5310
} SMqHbRsp;
5311

5312
typedef struct {
5313
  SMsgHead head;
5314
  int64_t  consumerId;
5315
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
5316
} SMqSeekReq;
5317

5318
#define TD_AUTO_CREATE_TABLE 0x1
5319
typedef struct {
5320
  int64_t       suid;
5321
  int64_t       uid;
5322
  int32_t       sver;
5323
  uint32_t      nData;
5324
  uint8_t*      pData;
5325
  SVCreateTbReq cTbReq;
5326
} SVSubmitBlk;
5327

5328
typedef struct {
5329
  SMsgHead header;
5330
  uint64_t sId;
5331
  uint64_t queryId;
5332
  uint64_t clientId;
5333
  uint64_t taskId;
5334
  uint32_t sqlLen;
5335
  uint32_t phyLen;
5336
  char*    sql;
5337
  char*    msg;
5338
  int8_t   source;
5339
} SVDeleteReq;
5340

5341
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5342
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
5343

5344
typedef struct {
5345
  int64_t affectedRows;
5346
} SVDeleteRsp;
5347

5348
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
5349
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
5350

5351
typedef struct SDeleteRes {
5352
  uint64_t suid;
5353
  SArray*  uidList;
5354
  int64_t  skey;
5355
  int64_t  ekey;
5356
  int64_t  affectedRows;
5357
  char     tableFName[TSDB_TABLE_NAME_LEN];
5358
  char     tsColName[TSDB_COL_NAME_LEN];
5359
  int64_t  ctimeMs;  // fill by vnode
5360
  int8_t   source;
5361
} SDeleteRes;
5362

5363
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
5364
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
5365

5366
typedef struct {
5367
  // int64_t uid;
5368
  char    tbname[TSDB_TABLE_NAME_LEN];
5369
  int64_t startTs;
5370
  int64_t endTs;
5371
} SSingleDeleteReq;
5372

5373
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
5374
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
5375

5376
typedef struct {
5377
  int64_t suid;
5378
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
5379
  int64_t ctimeMs;     // fill by vnode
5380
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
5381
} SBatchDeleteReq;
5382

5383
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
5384
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
5385
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
5386

5387
typedef struct {
5388
  int32_t msgIdx;
5389
  int32_t msgType;
5390
  int32_t msgLen;
5391
  void*   msg;
5392
} SBatchMsg;
5393

5394
typedef struct {
5395
  SMsgHead header;
5396
  SArray*  pMsgs;  // SArray<SBatchMsg>
5397
} SBatchReq;
5398

5399
typedef struct {
5400
  int32_t reqType;
5401
  int32_t msgIdx;
5402
  int32_t msgLen;
5403
  int32_t rspCode;
5404
  void*   msg;
5405
} SBatchRspMsg;
5406

5407
typedef struct {
5408
  SArray* pRsps;  // SArray<SBatchRspMsg>
5409
} SBatchRsp;
5410

5411
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5412
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
5413
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
90,563,671✔
5414
  if (NULL == msg) {
90,563,671✔
5415
    return;
×
5416
  }
5417
  SBatchMsg* pMsg = (SBatchMsg*)msg;
90,563,671✔
5418
  taosMemoryFree(pMsg->msg);
90,563,671✔
5419
}
5420

5421
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5422
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
5423

5424
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
127,361,021✔
5425
  if (NULL == p) {
127,361,021✔
5426
    return;
×
5427
  }
5428

5429
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
127,361,021✔
5430
  taosMemoryFree(pRsp->msg);
127,361,021✔
5431
}
5432

5433
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5434
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
5435
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5436
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
5437
void    tDestroySMqHbReq(SMqHbReq* pReq);
5438

5439
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5440
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
5441
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
5442

5443
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5444
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
5445

5446
#define TD_REQ_FROM_APP               0x0
5447
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
5448
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
5449
#define SUBMIT_REQ_FROM_FILE          0x4
5450
#define TD_REQ_FROM_TAOX              0x8
5451
#define TD_REQ_FROM_SML               0x10
5452
#define SUBMIT_REQUEST_VERSION        (2)
5453
#define SUBMIT_REQ_WITH_BLOB          0x10
5454
#define SUBMIT_REQ_SCHEMA_RES         0x20
5455
#define SUBMIT_REQ_ONLY_CREATE_TABLE  0x40
5456

5457
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
5458

5459
typedef struct {
5460
  int32_t        flags;
5461
  SVCreateTbReq* pCreateTbReq;
5462
  int64_t        suid;
5463
  int64_t        uid;
5464
  int32_t        sver;
5465
  union {
5466
    SArray* aRowP;
5467
    SArray* aCol;
5468
  };
5469
  int64_t   ctimeMs;
5470
  SBlobSet* pBlobSet;
5471
} SSubmitTbData;
5472

5473
typedef struct {
5474
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
5475
  SArray* aSubmitBlobData;
5476
  bool    raw;
5477
} SSubmitReq2;
5478

5479
typedef struct {
5480
  SMsgHead header;
5481
  int64_t  version;
5482
  char     data[];  // SSubmitReq2
5483
} SSubmitReq2Msg;
5484

5485
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
5486
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
5487
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
5488
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
5489
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
5490

5491
typedef struct {
5492
  int32_t affectedRows;
5493
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
5494
} SSubmitRsp2;
5495

5496
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
5497
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
5498
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
5499

5500
#define TSDB_MSG_FLG_ENCODE 0x1
5501
#define TSDB_MSG_FLG_DECODE 0x2
5502
#define TSDB_MSG_FLG_CMPT   0x3
5503

5504
typedef struct {
5505
  union {
5506
    struct {
5507
      void*   msgStr;
5508
      int32_t msgLen;
5509
      int64_t ver;
5510
    };
5511
    void* pDataBlock;
5512
  };
5513
} SPackedData;
5514

5515
typedef struct {
5516
  char     fullname[TSDB_VIEW_FNAME_LEN];
5517
  char     name[TSDB_VIEW_NAME_LEN];
5518
  char     dbFName[TSDB_DB_FNAME_LEN];
5519
  char*    querySql;
5520
  char*    sql;
5521
  int8_t   orReplace;
5522
  int8_t   precision;
5523
  int32_t  numOfCols;
5524
  SSchema* pSchema;
5525
} SCMCreateViewReq;
5526

5527
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
5528
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
5529
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
5530

5531
typedef struct {
5532
  char   fullname[TSDB_VIEW_FNAME_LEN];
5533
  char   name[TSDB_VIEW_NAME_LEN];
5534
  char   dbFName[TSDB_DB_FNAME_LEN];
5535
  char*  sql;
5536
  int8_t igNotExists;
5537
} SCMDropViewReq;
5538

5539
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
5540
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
5541
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
5542

5543
typedef struct {
5544
  char fullname[TSDB_VIEW_FNAME_LEN];
5545
} SViewMetaReq;
5546
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
5547
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
5548

5549
typedef struct {
5550
  char     name[TSDB_VIEW_NAME_LEN];
5551
  char     dbFName[TSDB_DB_FNAME_LEN];
5552
  char*    user;
5553
  uint64_t dbId;
5554
  uint64_t viewId;
5555
  char*    querySql;
5556
  int8_t   precision;
5557
  int8_t   type;
5558
  int32_t  version;
5559
  int32_t  numOfCols;
5560
  SSchema* pSchema;
5561
} SViewMetaRsp;
5562
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
5563
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
5564
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
5565
typedef struct {
5566
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
5567
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
5568
} STableTSMAInfoReq;
5569

5570
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
5571
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
5572

5573
typedef struct {
5574
  char name[TSDB_TABLE_NAME_LEN];  // rsmaName
5575
  union {
5576
    uint8_t flags;
5577
    struct {
5578
      uint8_t withColName : 1;
5579
      uint8_t reserved : 7;
5580
    };
5581
  };
5582

5583
} SRsmaInfoReq;
5584

5585
int32_t tSerializeRsmaInfoReq(void* buf, int32_t bufLen, const SRsmaInfoReq* pReq);
5586
int32_t tDeserializeRsmaInfoReq(void* buf, int32_t bufLen, SRsmaInfoReq* pReq);
5587

5588
typedef struct {
5589
  int32_t  funcId;
5590
  col_id_t colId;
5591
} STableTSMAFuncInfo;
5592

5593
typedef struct {
5594
  char     name[TSDB_TABLE_NAME_LEN];
5595
  uint64_t tsmaId;
5596
  char     targetTb[TSDB_TABLE_NAME_LEN];
5597
  char     targetDbFName[TSDB_DB_FNAME_LEN];
5598
  char     tb[TSDB_TABLE_NAME_LEN];
5599
  char     dbFName[TSDB_DB_FNAME_LEN];
5600
  uint64_t suid;
5601
  uint64_t destTbUid;
5602
  uint64_t dbId;
5603
  int32_t  version;
5604
  int64_t  interval;
5605
  int8_t   unit;
5606
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
5607
  SArray*  pTags;      // SArray<SSchema>
5608
  SArray*  pUsedCols;  // SArray<SSchema>
5609
  char*    ast;
5610

5611
  int64_t streamUid;
5612
  int64_t reqTs;
5613
  int64_t rspTs;
5614
  int64_t delayDuration;  // ms
5615
  bool    fillHistoryFinished;
5616

5617
  void* streamAddr;  // for stream task, the address of the stream task
5618
} STableTSMAInfo;
5619

5620
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
5621
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
5622
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
5623
void    tFreeTableTSMAInfo(void* p);
5624
void    tFreeAndClearTableTSMAInfo(void* p);
5625
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
5626

5627
#define STSMAHbRsp            STableTSMAInfoRsp
5628
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
5629
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
5630
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
5631

5632
typedef struct SDropCtbWithTsmaSingleVgReq {
5633
  SVgroupInfo vgInfo;
5634
  SArray*     pTbs;  // SVDropTbReq
5635
} SMDropTbReqsOnSingleVg;
5636

5637
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5638
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5639
void    tFreeSMDropTbReqOnSingleVg(void* p);
5640

5641
typedef struct SDropTbsReq {
5642
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5643
} SMDropTbsReq;
5644

5645
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5646
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5647
void    tFreeSMDropTbsReq(void*);
5648

5649
typedef struct SVFetchTtlExpiredTbsRsp {
5650
  SArray* pExpiredTbs;  // SVDropTbReq
5651
  int32_t vgId;
5652
} SVFetchTtlExpiredTbsRsp;
5653

5654
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5655
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5656

5657
void tFreeFetchTtlExpiredTbsRsp(void* p);
5658

5659
void setDefaultOptionsForField(SFieldWithOptions* field);
5660
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5661

5662
int32_t tSerializeSVSubTablesRspImpl(SEncoder* pEncoder, SVSubTablesRsp* pRsp);
5663
int32_t tDeserializeSVSubTablesRspImpl(SDecoder* pDecoder, SVSubTablesRsp* pRsp);
5664

5665
typedef struct {
5666
  char    id[TSDB_INSTANCE_ID_LEN];
5667
  char    type[TSDB_INSTANCE_TYPE_LEN];
5668
  char    desc[TSDB_INSTANCE_DESC_LEN];
5669
  int32_t expire;
5670
} SInstanceRegisterReq;
5671

5672
int32_t tSerializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5673
int32_t tDeserializeSInstanceRegisterReq(void* buf, int32_t bufLen, SInstanceRegisterReq* pReq);
5674

5675
typedef struct {
5676
  char filter_type[TSDB_INSTANCE_TYPE_LEN];
5677
} SInstanceListReq;
5678

5679
typedef struct {
5680
  int32_t count;
5681
  char**  ids;  // Array of instance IDs
5682
} SInstanceListRsp;
5683

5684
int32_t tSerializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5685
int32_t tDeserializeSInstanceListReq(void* buf, int32_t bufLen, SInstanceListReq* pReq);
5686
int32_t tSerializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5687
int32_t tDeserializeSInstanceListRsp(void* buf, int32_t bufLen, SInstanceListRsp* pRsp);
5688

5689
#ifdef USE_MOUNT
5690
typedef struct {
5691
  char     mountName[TSDB_MOUNT_NAME_LEN];
5692
  int8_t   ignoreExist;
5693
  int16_t  nMounts;
5694
  int32_t* dnodeIds;
5695
  char**   mountPaths;
5696
  int32_t  sqlLen;
5697
  char*    sql;
5698
} SCreateMountReq;
5699

5700
int32_t tSerializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5701
int32_t tDeserializeSCreateMountReq(void* buf, int32_t bufLen, SCreateMountReq* pReq);
5702
void    tFreeSCreateMountReq(SCreateMountReq* pReq);
5703

5704
typedef struct {
5705
  char    mountName[TSDB_MOUNT_NAME_LEN];
5706
  int8_t  ignoreNotExists;
5707
  int32_t sqlLen;
5708
  char*   sql;
5709
} SDropMountReq;
5710

5711
int32_t tSerializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5712
int32_t tDeserializeSDropMountReq(void* buf, int32_t bufLen, SDropMountReq* pReq);
5713
void    tFreeSDropMountReq(SDropMountReq* pReq);
5714

5715
typedef struct {
5716
  char     mountName[TSDB_MOUNT_NAME_LEN];
5717
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5718
  int64_t  mountUid;
5719
  int32_t  dnodeId;
5720
  uint32_t valLen;
5721
  int8_t   ignoreExist;
5722
  void*    pVal;
5723
} SRetrieveMountPathReq;
5724

5725
int32_t tSerializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5726
int32_t tDeserializeSRetrieveMountPathReq(void* buf, int32_t bufLen, SRetrieveMountPathReq* pReq);
5727

5728
typedef struct {
5729
  // path
5730
  int32_t diskPrimary;
5731
  // vgInfo
5732
  int32_t  vgId;
5733
  int32_t  cacheLastSize;
5734
  int32_t  szPage;
5735
  int32_t  szCache;
5736
  uint64_t szBuf;
5737
  int8_t   cacheLast;
5738
  int8_t   standby;
5739
  int8_t   hashMethod;
5740
  uint32_t hashBegin;
5741
  uint32_t hashEnd;
5742
  int16_t  hashPrefix;
5743
  int16_t  hashSuffix;
5744
  int16_t  sttTrigger;
5745
  // syncInfo
5746
  int32_t replications;
5747
  // tsdbInfo
5748
  int8_t  precision;
5749
  int8_t  compression;
5750
  int8_t  slLevel;
5751
  int32_t daysPerFile;
5752
  int32_t keep0;
5753
  int32_t keep1;
5754
  int32_t keep2;
5755
  int32_t keepTimeOffset;
5756
  int32_t minRows;
5757
  int32_t maxRows;
5758
  int32_t tsdbPageSize;
5759
  int32_t ssChunkSize;
5760
  int32_t ssKeepLocal;
5761
  int8_t  ssCompact;
5762
  // walInfo
5763
  int32_t walFsyncPeriod;      // millisecond
5764
  int32_t walRetentionPeriod;  // secs
5765
  int32_t walRollPeriod;       // secs
5766
  int64_t walRetentionSize;
5767
  int64_t walSegSize;
5768
  int32_t walLevel;
5769
  // encryptInfo
5770
  int32_t encryptAlgorithm;
5771
  // SVState
5772
  int64_t committed;
5773
  int64_t commitID;
5774
  int64_t commitTerm;
5775
  // stats
5776
  int64_t numOfSTables;
5777
  int64_t numOfCTables;
5778
  int64_t numOfNTables;
5779
  // dbInfo
5780
  uint64_t dbId;
5781
} SMountVgInfo;
5782

5783
typedef struct {
5784
  SMCreateStbReq req;
5785
  SArray*        pColExts;  // element: column id
5786
  SArray*        pTagExts;  // element: tag id
5787
} SMountStbInfo;
5788

5789
int32_t tSerializeSMountStbInfo(void* buf, int32_t bufLen, int32_t* pFLen, SMountStbInfo* pInfo);
5790
int32_t tDeserializeSMountStbInfo(void* buf, int32_t bufLen, int32_t flen, SMountStbInfo* pInfo);
5791

5792
typedef struct {
5793
  char     dbName[TSDB_DB_FNAME_LEN];
5794
  uint64_t dbId;
5795
  SArray*  pVgs;   // SMountVgInfo
5796
  SArray*  pStbs;  // 0 serialized binary of SMountStbInfo, 1 SMountStbInfo
5797
} SMountDbInfo;
5798

5799
typedef struct {
5800
  // common fields
5801
  char     mountName[TSDB_MOUNT_NAME_LEN];
5802
  char     mountPath[TSDB_MOUNT_PATH_LEN];
5803
  int8_t   ignoreExist;
5804
  int64_t  mountUid;
5805
  int64_t  clusterId;
5806
  int32_t  dnodeId;
5807
  uint32_t valLen;
5808
  void*    pVal;
5809

5810
  // response fields
5811
  SArray* pDbs;  // SMountDbInfo
5812

5813
  // memory fields, no serialized
5814
  SArray*   pDisks[TFS_MAX_TIERS];
5815
  TdFilePtr pFile;
5816
} SMountInfo;
5817

5818
int32_t tSerializeSMountInfo(void* buf, int32_t bufLen, SMountInfo* pReq);
5819
int32_t tDeserializeSMountInfo(SDecoder* decoder, SMountInfo* pReq, bool extractStb);
5820
void    tFreeMountInfo(SMountInfo* pReq, bool stbExtracted);
5821

5822
typedef struct {
5823
  SCreateVnodeReq createReq;
5824
  char            mountPath[TSDB_MOUNT_FPATH_LEN];
5825
  char            mountName[TSDB_MOUNT_NAME_LEN];
5826
  int64_t         mountId;
5827
  int32_t         diskPrimary;
5828
  int32_t         mountVgId;
5829
  int64_t         committed;
5830
  int64_t         commitID;
5831
  int64_t         commitTerm;
5832
  int64_t         numOfSTables;
5833
  int64_t         numOfCTables;
5834
  int64_t         numOfNTables;
5835
} SMountVnodeReq;
5836

5837
int32_t tSerializeSMountVnodeReq(void* buf, int32_t* cBufLen, int32_t* tBufLen, SMountVnodeReq* pReq);
5838
int32_t tDeserializeSMountVnodeReq(void* buf, int32_t bufLen, SMountVnodeReq* pReq);
5839
int32_t tFreeSMountVnodeReq(SMountVnodeReq* pReq);
5840

5841
#endif  // USE_MOUNT
5842

5843
#pragma pack(pop)
5844

5845
typedef struct {
5846
  char        db[TSDB_DB_FNAME_LEN];
5847
  STimeWindow timeRange;
5848
  int32_t     sqlLen;
5849
  char*       sql;
5850
  SArray*     vgroupIds;
5851
} SScanDbReq;
5852

5853
int32_t tSerializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5854
int32_t tDeserializeSScanDbReq(void* buf, int32_t bufLen, SScanDbReq* pReq);
5855
void    tFreeSScanDbReq(SScanDbReq* pReq);
5856

5857
typedef struct {
5858
  int32_t scanId;
5859
  int8_t  bAccepted;
5860
} SScanDbRsp;
5861

5862
int32_t tSerializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5863
int32_t tDeserializeSScanDbRsp(void* buf, int32_t bufLen, SScanDbRsp* pRsp);
5864

5865
typedef struct {
5866
  int32_t scanId;
5867
  int32_t sqlLen;
5868
  char*   sql;
5869
} SKillScanReq;
5870

5871
int32_t tSerializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5872
int32_t tDeserializeSKillScanReq(void* buf, int32_t bufLen, SKillScanReq* pReq);
5873
void    tFreeSKillScanReq(SKillScanReq* pReq);
5874

5875
typedef struct {
5876
  int32_t scanId;
5877
  int32_t vgId;
5878
  int32_t dnodeId;
5879
} SVKillScanReq;
5880

5881
int32_t tSerializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5882
int32_t tDeserializeSVKillScanReq(void* buf, int32_t bufLen, SVKillScanReq* pReq);
5883

5884
typedef struct {
5885
  int32_t scanId;
5886
  int32_t vgId;
5887
  int32_t dnodeId;
5888
  int32_t numberFileset;
5889
  int32_t finished;
5890
  int32_t progress;
5891
  int64_t remainingTime;
5892
} SQueryScanProgressRsp;
5893

5894
int32_t tSerializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5895
int32_t tDeserializeSQueryScanProgressRsp(void* buf, int32_t bufLen, SQueryScanProgressRsp* pReq);
5896

5897
typedef struct {
5898
  int32_t scanId;
5899
  int32_t vgId;
5900
  int32_t dnodeId;
5901
} SQueryScanProgressReq;
5902

5903
int32_t tSerializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5904
int32_t tDeserializeSQueryScanProgressReq(void* buf, int32_t bufLen, SQueryScanProgressReq* pReq);
5905

5906
typedef struct {
5907
  int64_t     dbUid;
5908
  char        db[TSDB_DB_FNAME_LEN];
5909
  int64_t     scanStartTime;
5910
  STimeWindow tw;
5911
  int32_t     scanId;
5912
} SScanVnodeReq;
5913

5914
int32_t tSerializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5915
int32_t tDeserializeSScanVnodeReq(void* buf, int32_t bufLen, SScanVnodeReq* pReq);
5916

5917
#ifdef __cplusplus
5918
}
5919
#endif
5920

5921
#endif /*_TD_COMMON_TAOS_MSG_H_*/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc