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

taosdata / TDengine / #3660

15 Mar 2025 09:06AM UTC coverage: 62.039% (-1.3%) from 63.314%
#3660

push

travis-ci

web-flow
feat(stream): support stream processing for virtual tables (#30144)

* enh: add client processing

* enh: add mnode vtables processing

* enh: add mnode vtable processing

* enh: add normal child vtable support

* fix: compile issues

* fix: compile issues

* fix: create stream issues

* fix: multi stream scan issue

* fix: remove debug info

* fix: agg task and task level issues

* fix: correct task output type

* fix: split vtablescan from agg

* fix: memory leak issues

* fix: add limitations

* Update 09-error-code.md

* Update 09-error-code.md

* fix: remove usless case

* feat(stream): extract original table data in source scan task

Implemented functionality in the source task to extract data
corresponding to the virtual table from the original table using WAL.
The extracted data is then sent to the downstream merge task for further
processing.

* feat(stream): multi-way merge using loser tree in virtual merge task

Implemented multi-way merge in the merge task using a loser tree to
combine data from multiple original table into a single virtual table.
The merged virtual table data is then pushed downstream for further
processing.  Introduced memory limit handling during the merge process
with configurable behavior when the memory limit is reached.

* fix(test): remove useless cases

---------

Co-authored-by: dapan1121 <wpan@taosdata.com>
Co-authored-by: Pan Wei <72057773+dapan1121@users.noreply.github.com>

154078 of 317582 branches covered (48.52%)

Branch coverage included in aggregate %.

313 of 2391 new or added lines in 34 files covered. (13.09%)

26134 existing lines in 205 files now uncovered.

240261 of 318051 relevant lines covered (75.54%)

16655189.27 hits per line

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

39.83
/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
static inline bool tmsgIsValid(tmsg_t type) {
80,788,183✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
80,788,183✔
74
  int    segIdx = TMSG_SEG_CODE(type);
80,788,183✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
80,788,183✔
76
    return type < tMsgRangeDict[segIdx];
80,791,349✔
77
  }
78
  return false;
1✔
79
}
80

81
#define TMSG_INFO(type) (tmsgIsValid(type) ? tMsgInfo[TMSG_INDEX(type)] : "unKnown")
82

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
2,918,117✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
2,892,218!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
5,810,335!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
33,293,545✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
33,293,545✔
91
}
92

93
/* ------------------------ OTHER DEFINITIONS ------------------------ */
94
// IE type
95
#define TSDB_IE_TYPE_SEC         1
96
#define TSDB_IE_TYPE_META        2
97
#define TSDB_IE_TYPE_MGMT_IP     3
98
#define TSDB_IE_TYPE_DNODE_CFG   4
99
#define TSDB_IE_TYPE_NEW_VERSION 5
100
#define TSDB_IE_TYPE_DNODE_EXT   6
101
#define TSDB_IE_TYPE_DNODE_STATE 7
102

103
enum {
104
  CONN_TYPE__QUERY = 1,
105
  CONN_TYPE__TMQ,
106
  CONN_TYPE__UDFD,
107
  CONN_TYPE__MAX,
108
};
109

110
enum {
111
  HEARTBEAT_KEY_USER_AUTHINFO = 1,
112
  HEARTBEAT_KEY_DBINFO,
113
  HEARTBEAT_KEY_STBINFO,
114
  HEARTBEAT_KEY_TMQ,
115
  HEARTBEAT_KEY_DYN_VIEW,
116
  HEARTBEAT_KEY_VIEWINFO,
117
  HEARTBEAT_KEY_TSMA,
118
};
119

120
typedef enum _mgmt_table {
121
  TSDB_MGMT_TABLE_START,
122
  TSDB_MGMT_TABLE_DNODE,
123
  TSDB_MGMT_TABLE_MNODE,
124
  TSDB_MGMT_TABLE_MODULE,
125
  TSDB_MGMT_TABLE_QNODE,
126
  TSDB_MGMT_TABLE_SNODE,
127
  TSDB_MGMT_TABLE_BNODE,  // no longer used
128
  TSDB_MGMT_TABLE_CLUSTER,
129
  TSDB_MGMT_TABLE_DB,
130
  TSDB_MGMT_TABLE_FUNC,
131
  TSDB_MGMT_TABLE_INDEX,
132
  TSDB_MGMT_TABLE_STB,
133
  TSDB_MGMT_TABLE_STREAMS,
134
  TSDB_MGMT_TABLE_TABLE,
135
  TSDB_MGMT_TABLE_TAG,
136
  TSDB_MGMT_TABLE_COL,
137
  TSDB_MGMT_TABLE_USER,
138
  TSDB_MGMT_TABLE_GRANTS,
139
  TSDB_MGMT_TABLE_VGROUP,
140
  TSDB_MGMT_TABLE_TOPICS,
141
  TSDB_MGMT_TABLE_CONSUMERS,
142
  TSDB_MGMT_TABLE_SUBSCRIPTIONS,
143
  TSDB_MGMT_TABLE_TRANS,
144
  TSDB_MGMT_TABLE_SMAS,
145
  TSDB_MGMT_TABLE_CONFIGS,
146
  TSDB_MGMT_TABLE_CONNS,
147
  TSDB_MGMT_TABLE_QUERIES,
148
  TSDB_MGMT_TABLE_VNODES,
149
  TSDB_MGMT_TABLE_APPS,
150
  TSDB_MGMT_TABLE_STREAM_TASKS,
151
  TSDB_MGMT_TABLE_PRIVILEGES,
152
  TSDB_MGMT_TABLE_VIEWS,
153
  TSDB_MGMT_TABLE_TSMAS,
154
  TSDB_MGMT_TABLE_COMPACT,
155
  TSDB_MGMT_TABLE_COMPACT_DETAIL,
156
  TSDB_MGMT_TABLE_GRANTS_FULL,
157
  TSDB_MGMT_TABLE_GRANTS_LOGS,
158
  TSDB_MGMT_TABLE_MACHINES,
159
  TSDB_MGMT_TABLE_ARBGROUP,
160
  TSDB_MGMT_TABLE_ENCRYPTIONS,
161
  TSDB_MGMT_TABLE_USER_FULL,
162
  TSDB_MGMT_TABLE_ANODE,
163
  TSDB_MGMT_TABLE_ANODE_FULL,
164
  TSDB_MGMT_TABLE_USAGE,
165
  TSDB_MGMT_TABLE_FILESETS,
166
  TSDB_MGMT_TABLE_TRANSACTION_DETAIL,
167
  TSDB_MGMT_TABLE_MAX,
168
} EShowType;
169

170
#define TSDB_ALTER_TABLE_ADD_TAG                         1
171
#define TSDB_ALTER_TABLE_DROP_TAG                        2
172
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME                 3
173
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL                  4
174
#define TSDB_ALTER_TABLE_ADD_COLUMN                      5
175
#define TSDB_ALTER_TABLE_DROP_COLUMN                     6
176
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES             7
177
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES                8
178
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS                  9
179
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME              10
180
#define TSDB_ALTER_TABLE_ADD_TAG_INDEX                   11
181
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX                  12
182
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS          13
183
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
184
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL            15
185
#define TSDB_ALTER_TABLE_ALTER_COLUMN_REF                16
186
#define TSDB_ALTER_TABLE_REMOVE_COLUMN_REF               17
187
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF      18
188

189
#define TSDB_FILL_NONE        0
190
#define TSDB_FILL_NULL        1
191
#define TSDB_FILL_NULL_F      2
192
#define TSDB_FILL_SET_VALUE   3
193
#define TSDB_FILL_SET_VALUE_F 4
194
#define TSDB_FILL_LINEAR      5
195
#define TSDB_FILL_PREV        6
196
#define TSDB_FILL_NEXT        7
197
#define TSDB_FILL_NEAR        8
198

199
#define TSDB_ALTER_USER_PASSWD          0x1
200
#define TSDB_ALTER_USER_SUPERUSER       0x2
201
#define TSDB_ALTER_USER_ENABLE          0x3
202
#define TSDB_ALTER_USER_SYSINFO         0x4
203
#define TSDB_ALTER_USER_ADD_PRIVILEGES  0x5
204
#define TSDB_ALTER_USER_DEL_PRIVILEGES  0x6
205
#define TSDB_ALTER_USER_ADD_WHITE_LIST  0x7
206
#define TSDB_ALTER_USER_DROP_WHITE_LIST 0x8
207
#define TSDB_ALTER_USER_CREATEDB        0x9
208

209
#define TSDB_KILL_MSG_LEN 30
210

211
#define TSDB_TABLE_NUM_UNIT 100000
212

213
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
214
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
215
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
216

217
#define TSDB_COL_NORMAL 0x0u  // the normal column of the table
218
#define TSDB_COL_TAG    0x1u  // the tag column type
219
#define TSDB_COL_UDC    0x2u  // the user specified normal string column, it is a dummy column
220
#define TSDB_COL_TMP    0x4u  // internal column generated by the previous operators
221
#define TSDB_COL_NULL   0x8u  // the column filter NULL or not
222

223
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
224
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
225
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
226
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
227

228
#define TD_SUPER_TABLE          TSDB_SUPER_TABLE
229
#define TD_CHILD_TABLE          TSDB_CHILD_TABLE
230
#define TD_NORMAL_TABLE         TSDB_NORMAL_TABLE
231
#define TD_VIRTUAL_NORMAL_TABLE TSDB_VIRTUAL_NORMAL_TABLE
232
#define TD_VIRTUAL_CHILD_TABLE  TSDB_VIRTUAL_CHILD_TABLE
233

234
typedef enum ENodeType {
235
  // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
236
  // VALUE, OPERATOR, FUNCTION and so on.
237
  QUERY_NODE_COLUMN = 1,
238
  QUERY_NODE_VALUE,
239
  QUERY_NODE_OPERATOR,
240
  QUERY_NODE_LOGIC_CONDITION,
241
  QUERY_NODE_FUNCTION,
242
  QUERY_NODE_REAL_TABLE,
243
  QUERY_NODE_TEMP_TABLE,
244
  QUERY_NODE_JOIN_TABLE,
245
  QUERY_NODE_GROUPING_SET,
246
  QUERY_NODE_ORDER_BY_EXPR,
247
  QUERY_NODE_LIMIT,
248
  QUERY_NODE_STATE_WINDOW,
249
  QUERY_NODE_SESSION_WINDOW,
250
  QUERY_NODE_INTERVAL_WINDOW,
251
  QUERY_NODE_NODE_LIST,
252
  QUERY_NODE_FILL,
253
  QUERY_NODE_RAW_EXPR,  // Only be used in parser module.
254
  QUERY_NODE_TARGET,
255
  QUERY_NODE_DATABLOCK_DESC,
256
  QUERY_NODE_SLOT_DESC,
257
  QUERY_NODE_COLUMN_DEF,
258
  QUERY_NODE_DOWNSTREAM_SOURCE,
259
  QUERY_NODE_DATABASE_OPTIONS,
260
  QUERY_NODE_TABLE_OPTIONS,
261
  QUERY_NODE_INDEX_OPTIONS,
262
  QUERY_NODE_EXPLAIN_OPTIONS,
263
  QUERY_NODE_STREAM_OPTIONS,
264
  QUERY_NODE_LEFT_VALUE,
265
  QUERY_NODE_COLUMN_REF,
266
  QUERY_NODE_WHEN_THEN,
267
  QUERY_NODE_CASE_WHEN,
268
  QUERY_NODE_EVENT_WINDOW,
269
  QUERY_NODE_HINT,
270
  QUERY_NODE_VIEW,
271
  QUERY_NODE_WINDOW_OFFSET,
272
  QUERY_NODE_COUNT_WINDOW,
273
  QUERY_NODE_COLUMN_OPTIONS,
274
  QUERY_NODE_TSMA_OPTIONS,
275
  QUERY_NODE_ANOMALY_WINDOW,
276
  QUERY_NODE_RANGE_AROUND,
277
  QUERY_NODE_STREAM_NOTIFY_OPTIONS,
278
  QUERY_NODE_VIRTUAL_TABLE,
279

280
  // Statement nodes are used in parser and planner module.
281
  QUERY_NODE_SET_OPERATOR = 100,
282
  QUERY_NODE_SELECT_STMT,
283
  QUERY_NODE_VNODE_MODIFY_STMT,
284
  QUERY_NODE_CREATE_DATABASE_STMT,
285
  QUERY_NODE_DROP_DATABASE_STMT,
286
  QUERY_NODE_ALTER_DATABASE_STMT,
287
  QUERY_NODE_FLUSH_DATABASE_STMT,
288
  QUERY_NODE_TRIM_DATABASE_STMT,
289
  QUERY_NODE_CREATE_TABLE_STMT,
290
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
291
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
292
  QUERY_NODE_DROP_TABLE_CLAUSE,
293
  QUERY_NODE_DROP_TABLE_STMT,
294
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
295
  QUERY_NODE_ALTER_TABLE_STMT,
296
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
297
  QUERY_NODE_CREATE_USER_STMT,
298
  QUERY_NODE_ALTER_USER_STMT,
299
  QUERY_NODE_DROP_USER_STMT,
300
  QUERY_NODE_USE_DATABASE_STMT,
301
  QUERY_NODE_CREATE_DNODE_STMT,
302
  QUERY_NODE_DROP_DNODE_STMT,
303
  QUERY_NODE_ALTER_DNODE_STMT,
304
  QUERY_NODE_CREATE_INDEX_STMT,
305
  QUERY_NODE_DROP_INDEX_STMT,
306
  QUERY_NODE_CREATE_QNODE_STMT,
307
  QUERY_NODE_DROP_QNODE_STMT,
308
  QUERY_NODE_CREATE_BNODE_STMT,
309
  QUERY_NODE_DROP_BNODE_STMT,
310
  QUERY_NODE_CREATE_SNODE_STMT,
311
  QUERY_NODE_DROP_SNODE_STMT,
312
  QUERY_NODE_CREATE_MNODE_STMT,
313
  QUERY_NODE_DROP_MNODE_STMT,
314
  QUERY_NODE_CREATE_TOPIC_STMT,
315
  QUERY_NODE_DROP_TOPIC_STMT,
316
  QUERY_NODE_DROP_CGROUP_STMT,
317
  QUERY_NODE_ALTER_LOCAL_STMT,
318
  QUERY_NODE_EXPLAIN_STMT,
319
  QUERY_NODE_DESCRIBE_STMT,
320
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
321
  QUERY_NODE_COMPACT_DATABASE_STMT,
322
  QUERY_NODE_COMPACT_VGROUPS_STMT,
323
  QUERY_NODE_CREATE_FUNCTION_STMT,
324
  QUERY_NODE_DROP_FUNCTION_STMT,
325
  QUERY_NODE_CREATE_STREAM_STMT,
326
  QUERY_NODE_DROP_STREAM_STMT,
327
  QUERY_NODE_BALANCE_VGROUP_STMT,
328
  QUERY_NODE_MERGE_VGROUP_STMT,
329
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
330
  QUERY_NODE_SPLIT_VGROUP_STMT,
331
  QUERY_NODE_SYNCDB_STMT,
332
  QUERY_NODE_GRANT_STMT,
333
  QUERY_NODE_REVOKE_STMT,
334
  QUERY_NODE_ALTER_CLUSTER_STMT,
335
  QUERY_NODE_S3MIGRATE_DATABASE_STMT,
336
  QUERY_NODE_CREATE_TSMA_STMT,
337
  QUERY_NODE_DROP_TSMA_STMT,
338
  QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT,
339
  QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT,
340
  QUERY_NODE_DROP_VIRTUAL_TABLE_STMT,
341
  QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT,
342

343
  // placeholder for [154, 180]
344
  QUERY_NODE_SHOW_CREATE_VIEW_STMT = 181,
345
  QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
346
  QUERY_NODE_SHOW_CREATE_TABLE_STMT,
347
  QUERY_NODE_SHOW_CREATE_STABLE_STMT,
348
  QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT,
349
  QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT,
350
  QUERY_NODE_SHOW_SCORES_STMT,
351
  QUERY_NODE_SHOW_TABLE_TAGS_STMT,
352
  QUERY_NODE_KILL_CONNECTION_STMT,
353
  QUERY_NODE_KILL_QUERY_STMT,
354
  QUERY_NODE_KILL_TRANSACTION_STMT,
355
  QUERY_NODE_KILL_COMPACT_STMT,
356
  QUERY_NODE_DELETE_STMT,
357
  QUERY_NODE_INSERT_STMT,
358
  QUERY_NODE_QUERY,
359
  QUERY_NODE_SHOW_DB_ALIVE_STMT,
360
  QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
361
  QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
362
  QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT,
363
  QUERY_NODE_RESTORE_DNODE_STMT,
364
  QUERY_NODE_RESTORE_QNODE_STMT,
365
  QUERY_NODE_RESTORE_MNODE_STMT,
366
  QUERY_NODE_RESTORE_VNODE_STMT,
367
  QUERY_NODE_PAUSE_STREAM_STMT,
368
  QUERY_NODE_RESUME_STREAM_STMT,
369
  QUERY_NODE_CREATE_VIEW_STMT,
370
  QUERY_NODE_DROP_VIEW_STMT,
371
  QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE,
372
  QUERY_NODE_CREATE_ANODE_STMT,
373
  QUERY_NODE_DROP_ANODE_STMT,
374
  QUERY_NODE_UPDATE_ANODE_STMT,
375
  QUERY_NODE_ASSIGN_LEADER_STMT,
376
  QUERY_NODE_SHOW_CREATE_TSMA_STMT,
377
  QUERY_NODE_SHOW_CREATE_VTABLE_STMT,
378

379
  // show statement nodes
380
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
381
  QUERY_NODE_SHOW_DNODES_STMT = 400,
382
  QUERY_NODE_SHOW_MNODES_STMT,
383
  QUERY_NODE_SHOW_MODULES_STMT,
384
  QUERY_NODE_SHOW_QNODES_STMT,
385
  QUERY_NODE_SHOW_SNODES_STMT,
386
  QUERY_NODE_SHOW_BNODES_STMT,
387
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
388
  QUERY_NODE_SHOW_CLUSTER_STMT,
389
  QUERY_NODE_SHOW_DATABASES_STMT,
390
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
391
  QUERY_NODE_SHOW_INDEXES_STMT,
392
  QUERY_NODE_SHOW_STABLES_STMT,
393
  QUERY_NODE_SHOW_STREAMS_STMT,
394
  QUERY_NODE_SHOW_TABLES_STMT,
395
  QUERY_NODE_SHOW_TAGS_STMT,
396
  QUERY_NODE_SHOW_USERS_STMT,
397
  QUERY_NODE_SHOW_USERS_FULL_STMT,
398
  QUERY_NODE_SHOW_LICENCES_STMT,
399
  QUERY_NODE_SHOW_VGROUPS_STMT,
400
  QUERY_NODE_SHOW_TOPICS_STMT,
401
  QUERY_NODE_SHOW_CONSUMERS_STMT,
402
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
403
  QUERY_NODE_SHOW_QUERIES_STMT,
404
  QUERY_NODE_SHOW_APPS_STMT,
405
  QUERY_NODE_SHOW_VARIABLES_STMT,
406
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
407
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
408
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
409
  QUERY_NODE_SHOW_VNODES_STMT,
410
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
411
  QUERY_NODE_SHOW_VIEWS_STMT,
412
  QUERY_NODE_SHOW_COMPACTS_STMT,
413
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
414
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
415
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
416
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
417
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
418
  QUERY_NODE_SHOW_TSMAS_STMT,
419
  QUERY_NODE_SHOW_ANODES_STMT,
420
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
421
  QUERY_NODE_SHOW_USAGE_STMT,
422
  QUERY_NODE_SHOW_FILESETS_STMT,
423
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
424
  QUERY_NODE_SHOW_VTABLES_STMT,
425

426
  // logic plan node
427
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
428
  QUERY_NODE_LOGIC_PLAN_JOIN,
429
  QUERY_NODE_LOGIC_PLAN_AGG,
430
  QUERY_NODE_LOGIC_PLAN_PROJECT,
431
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
432
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
433
  QUERY_NODE_LOGIC_PLAN_MERGE,
434
  QUERY_NODE_LOGIC_PLAN_WINDOW,
435
  QUERY_NODE_LOGIC_PLAN_FILL,
436
  QUERY_NODE_LOGIC_PLAN_SORT,
437
  QUERY_NODE_LOGIC_PLAN_PARTITION,
438
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
439
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
440
  QUERY_NODE_LOGIC_SUBPLAN,
441
  QUERY_NODE_LOGIC_PLAN,
442
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
443
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
444
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
445
  QUERY_NODE_LOGIC_PLAN_VIRTUAL_TABLE_SCAN,
446

447
  // physical plan node
448
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
449
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
450
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
451
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
452
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
453
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
454
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
455
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
456
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
457
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
458
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
459
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
460
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
461
  QUERY_NODE_PHYSICAL_PLAN_SORT,
462
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
463
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
464
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
465
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
466
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL,
467
  QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL,
468
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL,
469
  QUERY_NODE_PHYSICAL_PLAN_FILL,
470
  QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL,
471
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
472
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION,
473
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION,
474
  QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION,
475
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
476
  QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE,
477
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
478
  QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION,
479
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
480
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
481
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
482
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
483
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
484
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
485
  QUERY_NODE_PHYSICAL_SUBPLAN,
486
  QUERY_NODE_PHYSICAL_PLAN,
487
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
488
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
489
  QUERY_NODE_PHYSICAL_PLAN_STREAM_EVENT,
490
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
491
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
492
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
493
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
494
  QUERY_NODE_PHYSICAL_PLAN_STREAM_COUNT,
495
  QUERY_NODE_PHYSICAL_PLAN_STREAM_MID_INTERVAL,
496
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_INTERVAL,
497
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
498
  QUERY_NODE_PHYSICAL_PLAN_STREAM_ANOMALY,
499
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
500
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERP_FUNC,
501
  QUERY_NODE_RESET_STREAM_STMT,
502
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_SEMI_INTERVAL,
503
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_FINAL_INTERVAL,
504
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_SESSION,
505
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_SEMI_SESSION,
506
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_FINAL_SESSION,
507
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_STATE,
508
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_EVENT,
509
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_COUNT,
510
  QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN,
511
} ENodeType;
512

513
typedef struct {
514
  int32_t     vgId;
515
  uint8_t     option;  // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
516
  uint8_t     autoCreateCtb;  // 0x0 not auto create, 0x01 auto create
517
  const char* dbFName;
518
  const char* tbName;
519
} SBuildTableInput;
520

521
typedef struct {
522
  char    db[TSDB_DB_FNAME_LEN];
523
  int64_t dbId;
524
  int32_t vgVersion;
525
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
526
  int64_t stateTs;
527
} SBuildUseDBInput;
528

529
typedef struct SField {
530
  char    name[TSDB_COL_NAME_LEN];
531
  uint8_t type;
532
  int8_t  flags;
533
  int32_t bytes;
534
} SField;
535
typedef struct SFieldWithOptions {
536
  char     name[TSDB_COL_NAME_LEN];
537
  uint8_t  type;
538
  int8_t   flags;
539
  int32_t  bytes;
540
  uint32_t compress;
541
  STypeMod typeMod;
542
} SFieldWithOptions;
543

544
typedef struct SRetention {
545
  int64_t freq;
546
  int64_t keep;
547
  int8_t  freqUnit;
548
  int8_t  keepUnit;
549
} SRetention;
550

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

553
#pragma pack(push, 1)
554
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
555
typedef struct SEp {
556
  char     fqdn[TSDB_FQDN_LEN];
557
  uint16_t port;
558
} SEp;
559

560
typedef struct {
561
  int32_t contLen;
562
  int32_t vgId;
563
} SMsgHead;
564

565
// Submit message for one table
566
typedef struct SSubmitBlk {
567
  int64_t uid;        // table unique id
568
  int64_t suid;       // stable id
569
  int32_t sversion;   // data schema version
570
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
571
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
572
  int32_t numOfRows;  // total number of rows in current submit block
573
  char    data[];
574
} SSubmitBlk;
575

576
// Submit message for this TSDB
577
typedef struct {
578
  SMsgHead header;
579
  int64_t  version;
580
  int32_t  length;
581
  int32_t  numOfBlocks;
582
  char     blocks[];
583
} SSubmitReq;
584

585
typedef struct {
586
  int32_t totalLen;
587
  int32_t len;
588
  STSRow* row;
589
} SSubmitBlkIter;
590

591
typedef struct {
592
  int32_t totalLen;
593
  int32_t len;
594
  // head of SSubmitBlk
595
  int64_t uid;        // table unique id
596
  int64_t suid;       // stable id
597
  int32_t sversion;   // data schema version
598
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
599
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
600
  int32_t numOfRows;  // total number of rows in current submit block
601
  // head of SSubmitBlk
602
  int32_t     numOfBlocks;
603
  const void* pMsg;
604
} SSubmitMsgIter;
605

606
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
607
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
608
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
609
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
610
// for debug
611
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
612

613
typedef struct {
614
  bool     hasRef;
615
  col_id_t id;
616
  char     refDbName[TSDB_DB_NAME_LEN];
617
  char     refTableName[TSDB_TABLE_NAME_LEN];
618
  char     refColName[TSDB_COL_NAME_LEN];
619
} SColRef;
620

621
typedef struct {
622
  int32_t   nCols;
623
  int32_t   version;
624
  SColRef*  pColRef;
625
} SColRefWrapper;
626

627
typedef struct {
628
  int32_t vgId;
629
  SColRef colRef;
630
} SColRefEx;
631

632
typedef struct {
633
  int16_t colId;
634
  char    refDbName[TSDB_DB_NAME_LEN];
635
  char    refTableName[TSDB_TABLE_NAME_LEN];
636
  char    refColName[TSDB_COL_NAME_LEN];
637
} SRefColInfo;
638

639
typedef struct SVCTableRefCols {
640
  uint64_t     uid;
641
  int32_t      numOfSrcTbls;
642
  int32_t      numOfColRefs;
643
  SRefColInfo* refCols;
644
} SVCTableRefCols;
645

646
typedef struct SVCTableMergeInfo {
647
  uint64_t     uid;
648
  int32_t      numOfSrcTbls;
649
} SVCTableMergeInfo;
650

651
typedef struct {
652
  int32_t     nCols;
653
  SColRefEx*  pColRefEx;
654
} SColRefExWrapper;
655

656
struct SSchema {
657
  int8_t   type;
658
  int8_t   flags;
659
  col_id_t colId;
660
  int32_t  bytes;
661
  char     name[TSDB_COL_NAME_LEN];
662
};
663
struct SSchemaExt {
664
  col_id_t colId;
665
  uint32_t compress;
666
  STypeMod typeMod;
667
};
668

669
//
670

671
struct SSchema2 {
672
  int8_t   type;
673
  int8_t   flags;
674
  col_id_t colId;
675
  int32_t  bytes;
676
  char     name[TSDB_COL_NAME_LEN];
677
  uint32_t compress;
678
};
679

680
typedef struct {
681
  char        tbName[TSDB_TABLE_NAME_LEN];
682
  char        stbName[TSDB_TABLE_NAME_LEN];
683
  char        dbFName[TSDB_DB_FNAME_LEN];
684
  int64_t     dbId;
685
  int32_t     numOfTags;
686
  int32_t     numOfColumns;
687
  int8_t      precision;
688
  int8_t      tableType;
689
  int32_t     sversion;
690
  int32_t     tversion;
691
  uint64_t    suid;
692
  uint64_t    tuid;
693
  int32_t     vgId;
694
  int8_t      sysInfo;
695
  SSchema*    pSchemas;
696
  SSchemaExt* pSchemaExt;
697
  int8_t      virtualStb;
698
  int32_t     numOfColRefs;
699
  SColRef*    pColRefs;
700
} STableMetaRsp;
701

702
typedef struct {
703
  int32_t        code;
704
  int64_t        uid;
705
  char*          tblFName;
706
  int32_t        numOfRows;
707
  int32_t        affectedRows;
708
  int64_t        sver;
709
  STableMetaRsp* pMeta;
710
} SSubmitBlkRsp;
711

712
typedef struct {
713
  int32_t numOfRows;
714
  int32_t affectedRows;
715
  int32_t nBlocks;
716
  union {
717
    SArray*        pArray;
718
    SSubmitBlkRsp* pBlocks;
719
  };
720
} SSubmitRsp;
721

722
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
723
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
724
// void    tFreeSSubmitBlkRsp(void* param);
725
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
726

727
#define COL_SMA_ON     ((int8_t)0x1)
728
#define COL_IDX_ON     ((int8_t)0x2)
729
#define COL_IS_KEY     ((int8_t)0x4)
730
#define COL_SET_NULL   ((int8_t)0x10)
731
#define COL_SET_VAL    ((int8_t)0x20)
732
#define COL_IS_SYSINFO ((int8_t)0x40)
733
#define COL_HAS_TYPE_MOD ((int8_t)0x80)
734

735
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
736
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
737

738
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
739
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
740
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
741

742
#define SSCHMEA_SET_IDX_ON(s) \
743
  do {                        \
744
    (s)->flags |= COL_IDX_ON; \
745
  } while (0)
746

747
#define SSCHMEA_SET_IDX_OFF(s)   \
748
  do {                           \
749
    (s)->flags &= (~COL_IDX_ON); \
750
  } while (0)
751

752
#define SSCHEMA_SET_TYPE_MOD(s)     \
753
  do {                              \
754
    (s)->flags |= COL_HAS_TYPE_MOD; \
755
  } while (0)
756

757
#define HAS_TYPE_MOD(s) (((s)->flags & COL_HAS_TYPE_MOD))
758

759
#define SSCHMEA_TYPE(s)  ((s)->type)
760
#define SSCHMEA_FLAGS(s) ((s)->flags)
761
#define SSCHMEA_COLID(s) ((s)->colId)
762
#define SSCHMEA_BYTES(s) ((s)->bytes)
763
#define SSCHMEA_NAME(s)  ((s)->name)
764

765
typedef struct {
766
  bool    tsEnableMonitor;
767
  int32_t tsMonitorInterval;
768
  int32_t tsSlowLogThreshold;
769
  int32_t tsSlowLogMaxLen;
770
  int32_t tsSlowLogScope;
771
  int32_t tsSlowLogThresholdTest;  // Obsolete
772
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
773
} SMonitorParas;
774

775
typedef struct {
776
  STypeMod typeMod;
777
} SExtSchema;
778

779
bool hasExtSchema(const SExtSchema* pExtSchema);
780

781
typedef struct {
782
  int32_t  nCols;
783
  int32_t  version;
784
  SSchema* pSchema;
785
} SSchemaWrapper;
786

787
typedef struct {
788
  col_id_t id;
789
  uint32_t alg;
790
} SColCmpr;
791

792
typedef struct {
793
  int32_t   nCols;
794
  int32_t   version;
795
  SColCmpr* pColCmpr;
796
} SColCmprWrapper;
797

798

799
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
800
  if (pRef->pColRef) {
251!
UNCOV
801
    return TSDB_CODE_INVALID_PARA;
×
802
  }
803
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
251!
804
  if (pRef->pColRef == NULL) {
251!
UNCOV
805
    return terrno;
×
806
  }
807
  pRef->nCols = nCols;
251✔
808
  for (int32_t i = 0; i < nCols; i++) {
3,660✔
809
    pRef->pColRef[i].hasRef = false;
3,409✔
810
    pRef->pColRef[i].id = (col_id_t)(i + 1);
3,409✔
811
  }
812
  return 0;
251✔
813
}
814

815
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
816
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
817
    terrno = TSDB_CODE_INVALID_PARA;
818
    return NULL;
819
  }
820

821
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
822
  if (pDstWrapper == NULL) {
823
    return NULL;
824
  }
825
  pDstWrapper->nCols = pSrcWrapper->nCols;
826
  pDstWrapper->version = pSrcWrapper->version;
827

828
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
829
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
830
  if (pDstWrapper->pColCmpr == NULL) {
831
    taosMemoryFree(pDstWrapper);
832
    return NULL;
833
  }
834
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
835

836
  return pDstWrapper;
837
}
838

839
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
840
  if (!(!pCmpr->pColCmpr)) {
13,260!
UNCOV
841
    return TSDB_CODE_INVALID_PARA;
×
842
  }
843
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
13,260!
844
  if (pCmpr->pColCmpr == NULL) {
13,260!
UNCOV
845
    return terrno;
×
846
  }
847
  pCmpr->nCols = nCols;
13,260✔
848
  return 0;
13,260✔
849
}
850

851
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
852
  pCmpr->nCols = pSchema->nCols;
853
  if (!(!pCmpr->pColCmpr)) {
854
    return TSDB_CODE_INVALID_PARA;
855
  }
856
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
857
  if (pCmpr->pColCmpr == NULL) {
858
    return terrno;
859
  }
860
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
861
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
862
    SSchema*  pColSchema = &pSchema->pSchema[i];
863
    pColCmpr->id = pColSchema->colId;
864
    pColCmpr->alg = 0;
865
  }
866
  return 0;
867
}
868

869
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
870
  if (pWrapper == NULL) return;
871

872
  taosMemoryFreeClear(pWrapper->pColCmpr);
873
  taosMemoryFreeClear(pWrapper);
874
}
875
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
876
  if (pSchemaWrapper->pSchema == NULL) return NULL;
11,319,646!
877

878
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
11,319,646!
879
  if (pSW == NULL) {
11,317,920!
UNCOV
880
    return NULL;
×
881
  }
882
  pSW->nCols = pSchemaWrapper->nCols;
11,317,920✔
883
  pSW->version = pSchemaWrapper->version;
11,317,920✔
884
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
11,317,920!
885
  if (pSW->pSchema == NULL) {
11,312,744!
UNCOV
886
    taosMemoryFree(pSW);
×
UNCOV
887
    return NULL;
×
888
  }
889

890
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
11,312,744✔
891
  return pSW;
11,312,744✔
892
}
893

894
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
584,355✔
895
  if (pSchemaWrapper) {
26,796,317!
896
    taosMemoryFree(pSchemaWrapper->pSchema);
10,191,578!
897
    taosMemoryFree(pSchemaWrapper);
10,191,906!
898
  }
899
}
26,679,624✔
900

901
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,533,469✔
902
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,533,469!
903
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,533,745!
904
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,534,019!
905
  }
906
}
1,533,495✔
907

908
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
909
  int32_t tlen = 0;
8,361,171✔
910
  tlen += taosEncodeFixedI8(buf, pSchema->type);
16,722,342✔
911
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
8,361,171!
912
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
8,361,171!
913
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
8,361,171!
914
  tlen += taosEncodeString(buf, pSchema->name);
8,361,171✔
915
  return tlen;
8,361,171✔
916
}
917

918
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
919
  buf = taosDecodeFixedI8(buf, &pSchema->type);
10,356,664✔
920
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
5,178,332✔
921
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
5,178,332!
922
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
5,178,332!
923
  buf = taosDecodeStringTo(buf, pSchema->name);
5,178,332✔
924
  return (void*)buf;
5,178,332✔
925
}
926

927
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
928
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
353,227,533!
929
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
372,168,108!
930
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
372,168,108!
931
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
372,168,108!
932
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
372,168,108!
933
  return 0;
186,084,054✔
934
}
935

936
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
937
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
701,432,659!
938
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,383,018,965!
939
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,380,782,809!
940
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,393,549,582!
941
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
697,059,587!
942
  return 0;
728,073,102✔
943
}
944

945
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
946
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
207,004,536!
947
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
207,004,536!
948
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
207,004,536!
949
  return 0;
103,502,268✔
950
}
951

952
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
953
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
4,252,231!
954
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
4,252,227!
955
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
4,252,208!
956
  return 0;
2,126,100✔
957
}
958

959
static FORCE_INLINE int32_t tEncodeSColRef(SEncoder* pEncoder, const SColRef* pColRef) {
UNCOV
960
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pColRef->hasRef));
×
UNCOV
961
  TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pColRef->id));
×
UNCOV
962
  if (pColRef->hasRef) {
×
UNCOV
963
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refDbName));
×
UNCOV
964
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refTableName));
×
UNCOV
965
    TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pColRef->refColName));
×
966
  }
UNCOV
967
  return 0;
×
968
}
969

970
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
971
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
12,128!
972
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
12,128!
973
  if (pColRef->hasRef) {
6,064✔
974
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
3,255!
975
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
3,255!
976
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
3,255!
977
  }
978

979
  return 0;
6,064✔
980
}
981

982
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
983
  int32_t tlen = 0;
1,099,696✔
984
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
1,099,696✔
985
  tlen += taosEncodeVariantI32(buf, pSW->version);
1,099,696✔
986
  for (int32_t i = 0; i < pSW->nCols; i++) {
9,460,867✔
987
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
16,722,342!
988
  }
989
  return tlen;
1,099,696✔
990
}
991

992
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
993
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
632,865✔
994
  buf = taosDecodeVariantI32(buf, &pSW->version);
632,865✔
995
  if (pSW->nCols > 0) {
632,865✔
996
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
432,231!
997
    if (pSW->pSchema == NULL) {
432,231!
UNCOV
998
      return NULL;
×
999
    }
1000

1001
    for (int32_t i = 0; i < pSW->nCols; i++) {
5,610,563✔
1002
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
10,356,664✔
1003
    }
1004
  } else {
1005
    pSW->pSchema = NULL;
200,634✔
1006
  }
1007
  return (void*)buf;
632,865✔
1008
}
1009

1010
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1011
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
734,127!
1012
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,468,254!
1013
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,468,254!
1014
  for (int32_t i = 0; i < pSW->nCols; i++) {
19,674,702!
1015
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
37,881,150!
1016
  }
1017
  return 0;
734,127✔
1018
}
1019

1020
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1021
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
1,506,266!
1022
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
3,012,536!
1023
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
3,012,562!
1024

1025
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,506,292!
1026
  if (pSW->pSchema == NULL) {
1,506,481!
UNCOV
1027
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1028
  }
1029
  for (int32_t i = 0; i < pSW->nCols; i++) {
18,112,686!
1030
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
33,213,004!
1031
  }
1032

1033
  return 0;
1,505,887✔
1034
}
1035

1036
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1037
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
79,047,782!
1038
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
80,021,389!
1039

1040
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
39,995,992!
1041
  if (pSW->pSchema == NULL) {
40,136,364!
UNCOV
1042
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1043
  }
1044
  for (int32_t i = 0; i < pSW->nCols; i++) {
748,896,748!
1045
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,417,346,647!
1046
  }
1047

1048
  return 0;
40,310,485✔
1049
}
1050

1051
typedef struct {
1052
  char     name[TSDB_TABLE_FNAME_LEN];
1053
  int8_t   igExists;
1054
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1055
  int8_t   reserved[6];
1056
  tb_uid_t suid;
1057
  int64_t  delay1;
1058
  int64_t  delay2;
1059
  int64_t  watermark1;
1060
  int64_t  watermark2;
1061
  int32_t  ttl;
1062
  int32_t  colVer;
1063
  int32_t  tagVer;
1064
  int32_t  numOfColumns;
1065
  int32_t  numOfTags;
1066
  int32_t  numOfFuncs;
1067
  int32_t  commentLen;
1068
  int32_t  ast1Len;
1069
  int32_t  ast2Len;
1070
  SArray*  pColumns;  // array of SFieldWithOptions
1071
  SArray*  pTags;     // array of SField
1072
  SArray*  pFuncs;
1073
  char*    pComment;
1074
  char*    pAst1;
1075
  char*    pAst2;
1076
  int64_t  deleteMark1;
1077
  int64_t  deleteMark2;
1078
  int32_t  sqlLen;
1079
  char*    sql;
1080
  int64_t  keep;
1081
  int8_t   virtualStb;
1082
} SMCreateStbReq;
1083

1084
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1085
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1086
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1087

1088
typedef struct {
1089
  STableMetaRsp* pMeta;
1090
} SMCreateStbRsp;
1091

1092
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1093
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1094
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1095

1096
typedef struct {
1097
  char     name[TSDB_TABLE_FNAME_LEN];
1098
  int8_t   igNotExists;
1099
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
1100
  int8_t   reserved[6];
1101
  tb_uid_t suid;
1102
  int32_t  sqlLen;
1103
  char*    sql;
1104
} SMDropStbReq;
1105

1106
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1107
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1108
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1109

1110
typedef struct {
1111
  char    name[TSDB_TABLE_FNAME_LEN];
1112
  int8_t  alterType;
1113
  int32_t numOfFields;
1114
  SArray* pFields;
1115
  int32_t ttl;
1116
  int32_t commentLen;
1117
  char*   comment;
1118
  int32_t sqlLen;
1119
  char*   sql;
1120
  int64_t keep;
1121
  SArray* pTypeMods;
1122
} SMAlterStbReq;
1123

1124
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1125
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1126
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1127

1128
typedef struct SEpSet {
1129
  int8_t inUse;
1130
  int8_t numOfEps;
1131
  SEp    eps[TSDB_MAX_REPLICA];
1132
} SEpSet;
1133

1134
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1135
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1136
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1137
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1138

1139
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1140
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1141

1142
typedef struct {
1143
  int8_t  connType;
1144
  int32_t pid;
1145
  char    app[TSDB_APP_NAME_LEN];
1146
  char    db[TSDB_DB_NAME_LEN];
1147
  char    user[TSDB_USER_LEN];
1148
  char    passwd[TSDB_PASSWORD_LEN];
1149
  int64_t startTime;
1150
  char    sVer[TSDB_VERSION_LEN];
1151
} SConnectReq;
1152

1153
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1154
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1155

1156
typedef struct {
1157
  int32_t       acctId;
1158
  int64_t       clusterId;
1159
  uint32_t      connId;
1160
  int32_t       dnodeNum;
1161
  int8_t        superUser;
1162
  int8_t        sysInfo;
1163
  int8_t        connType;
1164
  SEpSet        epSet;
1165
  int32_t       svrTimestamp;
1166
  int32_t       passVer;
1167
  int32_t       authVer;
1168
  char          sVer[TSDB_VERSION_LEN];
1169
  char          sDetailVer[128];
1170
  int64_t       whiteListVer;
1171
  SMonitorParas monitorParas;
1172
  int8_t        enableAuditDelete;
1173
} SConnectRsp;
1174

1175
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1176
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1177

1178
typedef struct {
1179
  char    user[TSDB_USER_LEN];
1180
  char    pass[TSDB_PASSWORD_LEN];
1181
  int32_t maxUsers;
1182
  int32_t maxDbs;
1183
  int32_t maxTimeSeries;
1184
  int32_t maxStreams;
1185
  int32_t accessState;  // Configured only by command
1186
  int64_t maxStorage;
1187
} SCreateAcctReq, SAlterAcctReq;
1188

1189
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1190
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1191

1192
typedef struct {
1193
  char    user[TSDB_USER_LEN];
1194
  int32_t sqlLen;
1195
  char*   sql;
1196
} SDropUserReq, SDropAcctReq;
1197

1198
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1199
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1200
void    tFreeSDropUserReq(SDropUserReq* pReq);
1201

1202
typedef struct SIpV4Range {
1203
  uint32_t ip;
1204
  uint32_t mask;
1205
} SIpV4Range;
1206

1207
typedef struct {
1208
  int32_t    num;
1209
  SIpV4Range pIpRange[];
1210
} SIpWhiteList;
1211

1212
SIpWhiteList* cloneIpWhiteList(SIpWhiteList* pIpWhiteList);
1213
typedef struct {
1214
  int8_t      createType;
1215
  int8_t      superUser;  // denote if it is a super user or not
1216
  int8_t      sysInfo;
1217
  int8_t      enable;
1218
  char        user[TSDB_USER_LEN];
1219
  char        pass[TSDB_USET_PASSWORD_LEN];
1220
  int32_t     numIpRanges;
1221
  SIpV4Range* pIpRanges;
1222
  int32_t     sqlLen;
1223
  char*       sql;
1224
  int8_t      isImport;
1225
  int8_t      createDb;
1226
  int8_t      passIsMd5;
1227
} SCreateUserReq;
1228

1229
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1230
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1231
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1232

1233
typedef struct {
1234
  int64_t     ver;
1235
  char        user[TSDB_USER_LEN];
1236
  int32_t     numOfRange;
1237
  SIpV4Range* pIpRanges;
1238
} SUpdateUserIpWhite;
1239
typedef struct {
1240
  int64_t             ver;
1241
  int                 numOfUser;
1242
  SUpdateUserIpWhite* pUserIpWhite;
1243
} SUpdateIpWhite;
1244

1245
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1246
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1247
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1248
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1249

1250
typedef struct {
1251
  int64_t ipWhiteVer;
1252
} SRetrieveIpWhiteReq;
1253

1254
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1255
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1256

1257
typedef struct {
1258
  int32_t dnodeId;
1259
  int64_t analVer;
1260
} SRetrieveAnalAlgoReq;
1261

1262
typedef struct {
1263
  int64_t   ver;
1264
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1265
} SRetrieveAnalAlgoRsp;
1266

1267
int32_t tSerializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1268
int32_t tDeserializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1269
int32_t tSerializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1270
int32_t tDeserializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1271
void    tFreeRetrieveAnalAlgoRsp(SRetrieveAnalAlgoRsp* pRsp);
1272

1273
typedef struct {
1274
  int8_t alterType;
1275
  int8_t superUser;
1276
  int8_t sysInfo;
1277
  int8_t enable;
1278
  int8_t isView;
1279
  union {
1280
    uint8_t flag;
1281
    struct {
1282
      uint8_t createdb : 1;
1283
      uint8_t reserve : 7;
1284
    };
1285
  };
1286
  char        user[TSDB_USER_LEN];
1287
  char        pass[TSDB_USET_PASSWORD_LEN];
1288
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1289
  char        tabName[TSDB_TABLE_NAME_LEN];
1290
  char*       tagCond;
1291
  int32_t     tagCondLen;
1292
  int32_t     numIpRanges;
1293
  SIpV4Range* pIpRanges;
1294
  int64_t     privileges;
1295
  int32_t     sqlLen;
1296
  char*       sql;
1297
  int8_t      passIsMd5;
1298
} SAlterUserReq;
1299

1300
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1301
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1302
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1303

1304
typedef struct {
1305
  char user[TSDB_USER_LEN];
1306
} SGetUserAuthReq;
1307

1308
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1309
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1310

1311
typedef struct {
1312
  char      user[TSDB_USER_LEN];
1313
  int32_t   version;
1314
  int32_t   passVer;
1315
  int8_t    superAuth;
1316
  int8_t    sysInfo;
1317
  int8_t    enable;
1318
  int8_t    dropped;
1319
  SHashObj* createdDbs;
1320
  SHashObj* readDbs;
1321
  SHashObj* writeDbs;
1322
  SHashObj* readTbs;
1323
  SHashObj* writeTbs;
1324
  SHashObj* alterTbs;
1325
  SHashObj* readViews;
1326
  SHashObj* writeViews;
1327
  SHashObj* alterViews;
1328
  SHashObj* useDbs;
1329
  int64_t   whiteListVer;
1330
} SGetUserAuthRsp;
1331

1332
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1333
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1334
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1335

1336
typedef struct {
1337
  char user[TSDB_USER_LEN];
1338
} SGetUserWhiteListReq;
1339

1340
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1341
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1342

1343
typedef struct {
1344
  char        user[TSDB_USER_LEN];
1345
  int32_t     numWhiteLists;
1346
  SIpV4Range* pWhiteLists;
1347
} SGetUserWhiteListRsp;
1348

1349
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1350
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1351
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1352

1353
/*
1354
 * for client side struct, only column id, type, bytes are necessary
1355
 * But for data in vnode side, we need all the following information.
1356
 */
1357
typedef struct {
1358
  union {
1359
    col_id_t colId;
1360
    int16_t  slotId;
1361
  };
1362

1363
  uint8_t precision;
1364
  uint8_t scale;
1365
  int32_t bytes;
1366
  int8_t  type;
1367
  uint8_t pk;
1368
  bool    noData;
1369
} SColumnInfo;
1370

1371
typedef struct STimeWindow {
1372
  TSKEY skey;
1373
  TSKEY ekey;
1374
} STimeWindow;
1375

1376
typedef struct SQueryHint {
1377
  bool batchScan;
1378
} SQueryHint;
1379

1380
typedef struct {
1381
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1382
  int32_t tsLen;          // total length of ts comp block
1383
  int32_t tsNumOfBlocks;  // ts comp block numbers
1384
  int32_t tsOrder;        // ts comp block order
1385
} STsBufInfo;
1386

1387
typedef struct {
1388
  void*       timezone;
1389
  char        intervalUnit;
1390
  char        slidingUnit;
1391
  char        offsetUnit;
1392
  int8_t      precision;
1393
  int64_t     interval;
1394
  int64_t     sliding;
1395
  int64_t     offset;
1396
  STimeWindow timeRange;
1397
} SInterval;
1398

1399
typedef struct STbVerInfo {
1400
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1401
  int32_t sversion;
1402
  int32_t tversion;
1403
} STbVerInfo;
1404

1405
typedef struct {
1406
  int32_t code;
1407
  int64_t affectedRows;
1408
  SArray* tbVerInfo;  // STbVerInfo
1409
} SQueryTableRsp;
1410

1411
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1412

1413
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1414

1415
typedef struct {
1416
  SMsgHead header;
1417
  char     dbFName[TSDB_DB_FNAME_LEN];
1418
  char     tbName[TSDB_TABLE_NAME_LEN];
1419
} STableCfgReq;
1420

1421
typedef struct {
1422
  char        tbName[TSDB_TABLE_NAME_LEN];
1423
  char        stbName[TSDB_TABLE_NAME_LEN];
1424
  char        dbFName[TSDB_DB_FNAME_LEN];
1425
  int32_t     numOfTags;
1426
  int32_t     numOfColumns;
1427
  int8_t      tableType;
1428
  int64_t     delay1;
1429
  int64_t     delay2;
1430
  int64_t     watermark1;
1431
  int64_t     watermark2;
1432
  int32_t     ttl;
1433
  SArray*     pFuncs;
1434
  int32_t     commentLen;
1435
  char*       pComment;
1436
  SSchema*    pSchemas;
1437
  int32_t     tagsLen;
1438
  char*       pTags;
1439
  SSchemaExt* pSchemaExt;
1440
  int8_t      virtualStb;
1441
  SColRef*    pColRefs;
1442
} STableCfg;
1443

1444
typedef STableCfg STableCfgRsp;
1445

1446
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1447
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1448

1449
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1450
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1451
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1452

1453
typedef struct {
1454
  SMsgHead header;
1455
  tb_uid_t suid;
1456
} SVSubTablesReq;
1457

1458
int32_t tSerializeSVSubTablesReq(void *buf, int32_t bufLen, SVSubTablesReq *pReq);
1459
int32_t tDeserializeSVSubTablesReq(void *buf, int32_t bufLen, SVSubTablesReq *pReq);
1460

1461
typedef struct {
1462
  int32_t  vgId;
1463
  SArray*  pTables;   //SArray<SVCTableRefCols*>
1464
} SVSubTablesRsp;
1465

1466
int32_t tSerializeSVSubTablesRsp(void *buf, int32_t bufLen, SVSubTablesRsp *pRsp);
1467
int32_t tDeserializeSVSubTablesRsp(void *buf, int32_t bufLen, SVSubTablesRsp *pRsp);
1468
void tDestroySVSubTablesRsp(void* rsp);
1469

1470

1471
typedef struct {
1472
  char    db[TSDB_DB_FNAME_LEN];
1473
  int32_t numOfVgroups;
1474
  int32_t numOfStables;  // single_stable
1475
  int32_t buffer;        // MB
1476
  int32_t pageSize;
1477
  int32_t pages;
1478
  int32_t cacheLastSize;
1479
  int32_t daysPerFile;
1480
  int32_t daysToKeep0;
1481
  int32_t daysToKeep1;
1482
  int32_t daysToKeep2;
1483
  int32_t keepTimeOffset;
1484
  int32_t minRows;
1485
  int32_t maxRows;
1486
  int32_t walFsyncPeriod;
1487
  int8_t  walLevel;
1488
  int8_t  precision;  // time resolution
1489
  int8_t  compression;
1490
  int8_t  replications;
1491
  int8_t  strict;
1492
  int8_t  cacheLast;
1493
  int8_t  schemaless;
1494
  int8_t  ignoreExist;
1495
  int32_t numOfRetensions;
1496
  SArray* pRetensions;  // SRetention
1497
  int32_t walRetentionPeriod;
1498
  int64_t walRetentionSize;
1499
  int32_t walRollPeriod;
1500
  int64_t walSegmentSize;
1501
  int32_t sstTrigger;
1502
  int16_t hashPrefix;
1503
  int16_t hashSuffix;
1504
  int32_t s3ChunkSize;
1505
  int32_t s3KeepLocal;
1506
  int8_t  s3Compact;
1507
  int32_t tsdbPageSize;
1508
  int32_t sqlLen;
1509
  char*   sql;
1510
  int8_t  withArbitrator;
1511
  int8_t  encryptAlgorithm;
1512
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1513
  // 1. add auto-compact parameters
1514
  int32_t compactInterval;    // minutes
1515
  int32_t compactStartTime;   // minutes
1516
  int32_t compactEndTime;     // minutes
1517
  int8_t  compactTimeOffset;  // hour
1518
} SCreateDbReq;
1519

1520
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1521
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1522
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1523

1524
typedef struct {
1525
  char    db[TSDB_DB_FNAME_LEN];
1526
  int32_t buffer;
1527
  int32_t pageSize;
1528
  int32_t pages;
1529
  int32_t cacheLastSize;
1530
  int32_t daysPerFile;
1531
  int32_t daysToKeep0;
1532
  int32_t daysToKeep1;
1533
  int32_t daysToKeep2;
1534
  int32_t keepTimeOffset;
1535
  int32_t walFsyncPeriod;
1536
  int8_t  walLevel;
1537
  int8_t  strict;
1538
  int8_t  cacheLast;
1539
  int8_t  replications;
1540
  int32_t sstTrigger;
1541
  int32_t minRows;
1542
  int32_t walRetentionPeriod;
1543
  int32_t walRetentionSize;
1544
  int32_t s3KeepLocal;
1545
  int8_t  s3Compact;
1546
  int32_t sqlLen;
1547
  char*   sql;
1548
  int8_t  withArbitrator;
1549
  // 1. add auto-compact parameters
1550
  int32_t compactInterval;
1551
  int32_t compactStartTime;
1552
  int32_t compactEndTime;
1553
  int8_t  compactTimeOffset;
1554
} SAlterDbReq;
1555

1556
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1557
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1558
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1559

1560
typedef struct {
1561
  char    db[TSDB_DB_FNAME_LEN];
1562
  int8_t  ignoreNotExists;
1563
  int32_t sqlLen;
1564
  char*   sql;
1565
} SDropDbReq;
1566

1567
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1568
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1569
void    tFreeSDropDbReq(SDropDbReq* pReq);
1570

1571
typedef struct {
1572
  char    db[TSDB_DB_FNAME_LEN];
1573
  int64_t uid;
1574
} SDropDbRsp;
1575

1576
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1577
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1578

1579
typedef struct {
1580
  char    db[TSDB_DB_FNAME_LEN];
1581
  int64_t dbId;
1582
  int32_t vgVersion;
1583
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1584
  int64_t stateTs;     // ms
1585
} SUseDbReq;
1586

1587
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1588
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1589

1590
typedef struct {
1591
  char    db[TSDB_DB_FNAME_LEN];
1592
  int64_t uid;
1593
  int32_t vgVersion;
1594
  int32_t vgNum;
1595
  int16_t hashPrefix;
1596
  int16_t hashSuffix;
1597
  int8_t  hashMethod;
1598
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1599
  int32_t errCode;
1600
  int64_t stateTs;  // ms
1601
} SUseDbRsp;
1602

1603
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1604
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1605
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1606
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1607
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1608

1609
typedef struct {
1610
  char db[TSDB_DB_FNAME_LEN];
1611
} SDbCfgReq;
1612

1613
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1614
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1615

1616
typedef struct {
1617
  char    db[TSDB_DB_FNAME_LEN];
1618
  int32_t maxSpeed;
1619
} STrimDbReq;
1620

1621
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1622
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1623

1624
typedef struct {
1625
  int32_t timestamp;
1626
} SVTrimDbReq;
1627

1628
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1629
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1630

1631
typedef struct {
1632
  char db[TSDB_DB_FNAME_LEN];
1633
} SS3MigrateDbReq;
1634

1635
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1636
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1637

1638
typedef struct {
1639
  int32_t timestamp;
1640
} SVS3MigrateDbReq;
1641

1642
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1643
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1644

1645
typedef struct {
1646
  int32_t timestampSec;
1647
  int32_t ttlDropMaxCount;
1648
  int32_t nUids;
1649
  SArray* pTbUids;
1650
} SVDropTtlTableReq;
1651

1652
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1653
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1654

1655
typedef struct {
1656
  char    db[TSDB_DB_FNAME_LEN];
1657
  int64_t dbId;
1658
  int32_t cfgVersion;
1659
  int32_t numOfVgroups;
1660
  int32_t numOfStables;
1661
  int32_t buffer;
1662
  int32_t cacheSize;
1663
  int32_t pageSize;
1664
  int32_t pages;
1665
  int32_t daysPerFile;
1666
  int32_t daysToKeep0;
1667
  int32_t daysToKeep1;
1668
  int32_t daysToKeep2;
1669
  int32_t keepTimeOffset;
1670
  int32_t minRows;
1671
  int32_t maxRows;
1672
  int32_t walFsyncPeriod;
1673
  int16_t hashPrefix;
1674
  int16_t hashSuffix;
1675
  int8_t  hashMethod;
1676
  int8_t  walLevel;
1677
  int8_t  precision;
1678
  int8_t  compression;
1679
  int8_t  replications;
1680
  int8_t  strict;
1681
  int8_t  cacheLast;
1682
  int8_t  encryptAlgorithm;
1683
  int32_t s3ChunkSize;
1684
  int32_t s3KeepLocal;
1685
  int8_t  s3Compact;
1686
  int8_t  compactTimeOffset;
1687
  int32_t compactInterval;
1688
  int32_t compactStartTime;
1689
  int32_t compactEndTime;
1690
  int32_t tsdbPageSize;
1691
  int32_t walRetentionPeriod;
1692
  int32_t walRollPeriod;
1693
  int64_t walRetentionSize;
1694
  int64_t walSegmentSize;
1695
  int32_t numOfRetensions;
1696
  SArray* pRetensions;
1697
  int8_t  schemaless;
1698
  int16_t sstTrigger;
1699
  int8_t  withArbitrator;
1700
} SDbCfgRsp;
1701

1702
typedef SDbCfgRsp SDbCfgInfo;
1703

1704
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1705
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1706
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1707
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1708
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1709

1710
typedef struct {
1711
  int32_t rowNum;
1712
} SQnodeListReq;
1713

1714
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1715
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1716

1717
typedef struct {
1718
  int32_t rowNum;
1719
} SDnodeListReq;
1720

1721
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1722

1723
typedef struct {
1724
  int32_t useless;  // useless
1725
} SServerVerReq;
1726

1727
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1728
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1729

1730
typedef struct {
1731
  char ver[TSDB_VERSION_LEN];
1732
} SServerVerRsp;
1733

1734
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1735
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1736

1737
typedef struct SQueryNodeAddr {
1738
  int32_t nodeId;  // vgId or qnodeId
1739
  SEpSet  epSet;
1740
} SQueryNodeAddr;
1741

1742
typedef struct {
1743
  SQueryNodeAddr addr;
1744
  uint64_t       load;
1745
} SQueryNodeLoad;
1746

1747
typedef struct {
1748
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1749
} SQnodeListRsp;
1750

1751
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1752
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1753
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1754

1755
typedef struct {
1756
  SArray* dnodeList;  // SArray<SEpSet>
1757
} SDnodeListRsp;
1758

1759
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1760
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1761
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1762

1763
typedef struct {
1764
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1765
} STableTSMAInfoRsp;
1766

1767
typedef struct {
1768
  SUseDbRsp*         useDbRsp;
1769
  SDbCfgRsp*         cfgRsp;
1770
  STableTSMAInfoRsp* pTsmaRsp;
1771
  int32_t            dbTsmaVersion;
1772
  char               db[TSDB_DB_FNAME_LEN];
1773
  int64_t            dbId;
1774
} SDbHbRsp;
1775

1776
typedef struct {
1777
  SArray* pArray;  // Array of SDbHbRsp
1778
} SDbHbBatchRsp;
1779

1780
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1781
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1782
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1783

1784
typedef struct {
1785
  SArray* pArray;  // Array of SGetUserAuthRsp
1786
} SUserAuthBatchRsp;
1787

1788
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1789
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1790
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1791

1792
typedef struct {
1793
  char        db[TSDB_DB_FNAME_LEN];
1794
  STimeWindow timeRange;
1795
  int32_t     sqlLen;
1796
  char*       sql;
1797
  SArray*     vgroupIds;
1798
  int8_t      metaOnly;
1799
} SCompactDbReq;
1800

1801
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1802
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1803
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1804

1805
typedef struct {
1806
  int32_t compactId;
1807
  int8_t  bAccepted;
1808
} SCompactDbRsp;
1809

1810
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1811
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1812

1813
typedef struct {
1814
  int32_t compactId;
1815
  int32_t sqlLen;
1816
  char*   sql;
1817
} SKillCompactReq;
1818

1819
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1820
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1821
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1822

1823
typedef struct {
1824
  char    name[TSDB_FUNC_NAME_LEN];
1825
  int8_t  igExists;
1826
  int8_t  funcType;
1827
  int8_t  scriptType;
1828
  int8_t  outputType;
1829
  int32_t outputLen;
1830
  int32_t bufSize;
1831
  int32_t codeLen;
1832
  int64_t signature;
1833
  char*   pComment;
1834
  char*   pCode;
1835
  int8_t  orReplace;
1836
} SCreateFuncReq;
1837

1838
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1839
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1840
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1841

1842
typedef struct {
1843
  char   name[TSDB_FUNC_NAME_LEN];
1844
  int8_t igNotExists;
1845
} SDropFuncReq;
1846

1847
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1848
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1849

1850
typedef struct {
1851
  int32_t numOfFuncs;
1852
  bool    ignoreCodeComment;
1853
  SArray* pFuncNames;
1854
} SRetrieveFuncReq;
1855

1856
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1857
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1858
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1859

1860
typedef struct {
1861
  char    name[TSDB_FUNC_NAME_LEN];
1862
  int8_t  funcType;
1863
  int8_t  scriptType;
1864
  int8_t  outputType;
1865
  int32_t outputLen;
1866
  int32_t bufSize;
1867
  int64_t signature;
1868
  int32_t commentSize;
1869
  int32_t codeSize;
1870
  char*   pComment;
1871
  char*   pCode;
1872
} SFuncInfo;
1873

1874
typedef struct {
1875
  int32_t funcVersion;
1876
  int64_t funcCreatedTime;
1877
} SFuncExtraInfo;
1878

1879
typedef struct {
1880
  int32_t numOfFuncs;
1881
  SArray* pFuncInfos;
1882
  SArray* pFuncExtraInfos;
1883
} SRetrieveFuncRsp;
1884

1885
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1886
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1887
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1888
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1889

1890
typedef struct {
1891
  int32_t       statusInterval;
1892
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
1893
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
1894
  char          locale[TD_LOCALE_LEN];      // tsLocale
1895
  char          charset[TD_LOCALE_LEN];     // tsCharset
1896
  int8_t        ttlChangeOnWrite;
1897
  int8_t        enableWhiteList;
1898
  int8_t        encryptionKeyStat;
1899
  uint32_t      encryptionKeyChksum;
1900
  SMonitorParas monitorParas;
1901
} SClusterCfg;
1902

1903
typedef struct {
1904
  int32_t openVnodes;
1905
  int32_t dropVnodes;
1906
  int32_t totalVnodes;
1907
  int32_t masterNum;
1908
  int64_t numOfSelectReqs;
1909
  int64_t numOfInsertReqs;
1910
  int64_t numOfInsertSuccessReqs;
1911
  int64_t numOfBatchInsertReqs;
1912
  int64_t numOfBatchInsertSuccessReqs;
1913
  int64_t errors;
1914
} SVnodesStat;
1915

1916
typedef struct {
1917
  int32_t vgId;
1918
  int8_t  syncState;
1919
  int8_t  syncRestore;
1920
  int64_t syncTerm;
1921
  int64_t roleTimeMs;
1922
  int64_t startTimeMs;
1923
  int8_t  syncCanRead;
1924
  int64_t cacheUsage;
1925
  int64_t numOfTables;
1926
  int64_t numOfTimeSeries;
1927
  int64_t totalStorage;
1928
  int64_t compStorage;
1929
  int64_t pointsWritten;
1930
  int64_t numOfSelectReqs;
1931
  int64_t numOfInsertReqs;
1932
  int64_t numOfInsertSuccessReqs;
1933
  int64_t numOfBatchInsertReqs;
1934
  int64_t numOfBatchInsertSuccessReqs;
1935
  int32_t numOfCachedTables;
1936
  int32_t learnerProgress;  // use one reservered
1937
  int64_t syncAppliedIndex;
1938
  int64_t syncCommitIndex;
1939
} SVnodeLoad;
1940

1941
typedef struct {
1942
  int32_t     vgId;
1943
  int64_t     numOfTables;
1944
  int64_t     memSize;
1945
  int64_t     l1Size;
1946
  int64_t     l2Size;
1947
  int64_t     l3Size;
1948
  int64_t     cacheSize;
1949
  int64_t     walSize;
1950
  int64_t     metaSize;
1951
  int64_t     rawDataSize;
1952
  int64_t     s3Size;
1953
  const char* dbname;
1954
} SDbSizeStatisInfo;
1955

1956
typedef struct {
1957
  int32_t vgId;
1958
  int64_t nTimeSeries;
1959
} SVnodeLoadLite;
1960

1961
typedef struct {
1962
  int8_t  syncState;
1963
  int64_t syncTerm;
1964
  int8_t  syncRestore;
1965
  int64_t roleTimeMs;
1966
} SMnodeLoad;
1967

1968
typedef struct {
1969
  int32_t dnodeId;
1970
  int64_t numOfProcessedQuery;
1971
  int64_t numOfProcessedCQuery;
1972
  int64_t numOfProcessedFetch;
1973
  int64_t numOfProcessedDrop;
1974
  int64_t numOfProcessedNotify;
1975
  int64_t numOfProcessedHb;
1976
  int64_t numOfProcessedDelete;
1977
  int64_t cacheDataSize;
1978
  int64_t numOfQueryInQueue;
1979
  int64_t numOfFetchInQueue;
1980
  int64_t timeInQueryQueue;
1981
  int64_t timeInFetchQueue;
1982
} SQnodeLoad;
1983

1984
typedef struct {
1985
  int32_t     sver;      // software version
1986
  int64_t     dnodeVer;  // dnode table version in sdb
1987
  int32_t     dnodeId;
1988
  int64_t     clusterId;
1989
  int64_t     rebootTime;
1990
  int64_t     updateTime;
1991
  float       numOfCores;
1992
  int32_t     numOfSupportVnodes;
1993
  int32_t     numOfDiskCfg;
1994
  int64_t     memTotal;
1995
  int64_t     memAvail;
1996
  char        dnodeEp[TSDB_EP_LEN];
1997
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
1998
  SMnodeLoad  mload;
1999
  SQnodeLoad  qload;
2000
  SClusterCfg clusterCfg;
2001
  SArray*     pVloads;  // array of SVnodeLoad
2002
  int32_t     statusSeq;
2003
  int64_t     ipWhiteVer;
2004
  int64_t     analVer;
2005
  int64_t     timestamp;
2006
} SStatusReq;
2007

2008
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2009
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2010
void    tFreeSStatusReq(SStatusReq* pReq);
2011

2012
typedef struct {
2013
  int32_t forceReadConfig;
2014
  int32_t cver;
2015
  SArray* array;
2016
} SConfigReq;
2017

2018
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2019
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2020
void    tFreeSConfigReq(SConfigReq* pReq);
2021

2022
typedef struct {
2023
  int32_t dnodeId;
2024
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2025
} SDnodeInfoReq;
2026

2027
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2028
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2029

2030
typedef enum {
2031
  MONITOR_TYPE_COUNTER = 0,
2032
  MONITOR_TYPE_SLOW_LOG = 1,
2033
} MONITOR_TYPE;
2034

2035
typedef struct {
2036
  int32_t      contLen;
2037
  char*        pCont;
2038
  MONITOR_TYPE type;
2039
} SStatisReq;
2040

2041
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2042
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2043
void    tFreeSStatisReq(SStatisReq* pReq);
2044

2045
typedef struct {
2046
  char    db[TSDB_DB_FNAME_LEN];
2047
  char    table[TSDB_TABLE_NAME_LEN];
2048
  char    operation[AUDIT_OPERATION_LEN];
2049
  int32_t sqlLen;
2050
  char*   pSql;
2051
} SAuditReq;
2052
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2053
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2054
void    tFreeSAuditReq(SAuditReq* pReq);
2055

2056
typedef struct {
2057
  int32_t dnodeId;
2058
  int64_t clusterId;
2059
  SArray* pVloads;
2060
} SNotifyReq;
2061

2062
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2063
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2064
void    tFreeSNotifyReq(SNotifyReq* pReq);
2065

2066
typedef struct {
2067
  int32_t dnodeId;
2068
  int64_t clusterId;
2069
} SDnodeCfg;
2070

2071
typedef struct {
2072
  int32_t id;
2073
  int8_t  isMnode;
2074
  SEp     ep;
2075
} SDnodeEp;
2076

2077
typedef struct {
2078
  int32_t id;
2079
  int8_t  isMnode;
2080
  int8_t  offlineReason;
2081
  SEp     ep;
2082
  char    active[TSDB_ACTIVE_KEY_LEN];
2083
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2084
} SDnodeInfo;
2085

2086
typedef struct {
2087
  int64_t   dnodeVer;
2088
  SDnodeCfg dnodeCfg;
2089
  SArray*   pDnodeEps;  // Array of SDnodeEp
2090
  int32_t   statusSeq;
2091
  int64_t   ipWhiteVer;
2092
  int64_t   analVer;
2093
} SStatusRsp;
2094

2095
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2096
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2097
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2098

2099
typedef struct {
2100
  int32_t forceReadConfig;
2101
  int32_t isConifgVerified;
2102
  int32_t isVersionVerified;
2103
  int32_t cver;
2104
  SArray* array;
2105
} SConfigRsp;
2106

2107
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2108
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2109
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2110

2111
typedef struct {
2112
  int32_t reserved;
2113
} SMTimerReq;
2114

2115
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2116
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2117

2118
typedef struct SOrphanTask {
2119
  int64_t streamId;
2120
  int32_t taskId;
2121
  int32_t nodeId;
2122
} SOrphanTask;
2123

2124
typedef struct SMStreamDropOrphanMsg {
2125
  SArray* pList;  // SArray<SOrphanTask>
2126
} SMStreamDropOrphanMsg;
2127

2128
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2129
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2130
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2131

2132
typedef struct {
2133
  int32_t  id;
2134
  uint16_t port;                 // node sync Port
2135
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2136
} SReplica;
2137

2138
typedef struct {
2139
  int32_t  vgId;
2140
  char     db[TSDB_DB_FNAME_LEN];
2141
  int64_t  dbUid;
2142
  int32_t  vgVersion;
2143
  int32_t  numOfStables;
2144
  int32_t  buffer;
2145
  int32_t  pageSize;
2146
  int32_t  pages;
2147
  int32_t  cacheLastSize;
2148
  int32_t  daysPerFile;
2149
  int32_t  daysToKeep0;
2150
  int32_t  daysToKeep1;
2151
  int32_t  daysToKeep2;
2152
  int32_t  keepTimeOffset;
2153
  int32_t  minRows;
2154
  int32_t  maxRows;
2155
  int32_t  walFsyncPeriod;
2156
  uint32_t hashBegin;
2157
  uint32_t hashEnd;
2158
  int8_t   hashMethod;
2159
  int8_t   walLevel;
2160
  int8_t   precision;
2161
  int8_t   compression;
2162
  int8_t   strict;
2163
  int8_t   cacheLast;
2164
  int8_t   isTsma;
2165
  int8_t   replica;
2166
  int8_t   selfIndex;
2167
  SReplica replicas[TSDB_MAX_REPLICA];
2168
  int32_t  numOfRetensions;
2169
  SArray*  pRetensions;  // SRetention
2170
  void*    pTsma;
2171
  int32_t  walRetentionPeriod;
2172
  int64_t  walRetentionSize;
2173
  int32_t  walRollPeriod;
2174
  int64_t  walSegmentSize;
2175
  int16_t  sstTrigger;
2176
  int16_t  hashPrefix;
2177
  int16_t  hashSuffix;
2178
  int32_t  tsdbPageSize;
2179
  int32_t  s3ChunkSize;
2180
  int32_t  s3KeepLocal;
2181
  int8_t   s3Compact;
2182
  int64_t  reserved[6];
2183
  int8_t   learnerReplica;
2184
  int8_t   learnerSelfIndex;
2185
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2186
  int32_t  changeVersion;
2187
  int8_t   encryptAlgorithm;
2188
} SCreateVnodeReq;
2189

2190
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2191
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2192
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2193

2194
typedef struct {
2195
  int32_t compactId;
2196
  int32_t vgId;
2197
  int32_t dnodeId;
2198
} SQueryCompactProgressReq;
2199

2200
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2201
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2202

2203
typedef struct {
2204
  int32_t compactId;
2205
  int32_t vgId;
2206
  int32_t dnodeId;
2207
  int32_t numberFileset;
2208
  int32_t finished;
2209
  int32_t progress;
2210
  int64_t remainingTime;
2211
} SQueryCompactProgressRsp;
2212

2213
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2214
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2215

2216
typedef struct {
2217
  int32_t vgId;
2218
  int32_t dnodeId;
2219
  int64_t dbUid;
2220
  char    db[TSDB_DB_FNAME_LEN];
2221
  int64_t reserved[8];
2222
} SDropVnodeReq;
2223

2224
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2225
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2226

2227
typedef struct {
2228
  char    colName[TSDB_COL_NAME_LEN];
2229
  char    stb[TSDB_TABLE_FNAME_LEN];
2230
  int64_t stbUid;
2231
  int64_t dbUid;
2232
  int64_t reserved[8];
2233
} SDropIndexReq;
2234

2235
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2236
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2237

2238
typedef struct {
2239
  int64_t     dbUid;
2240
  char        db[TSDB_DB_FNAME_LEN];
2241
  int64_t     compactStartTime;
2242
  STimeWindow tw;
2243
  int32_t     compactId;
2244
  int8_t      metaOnly;
2245
} SCompactVnodeReq;
2246

2247
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2248
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2249

2250
typedef struct {
2251
  int32_t compactId;
2252
  int32_t vgId;
2253
  int32_t dnodeId;
2254
} SVKillCompactReq;
2255

2256
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2257
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2258

2259
typedef struct {
2260
  int32_t vgVersion;
2261
  int32_t buffer;
2262
  int32_t pageSize;
2263
  int32_t pages;
2264
  int32_t cacheLastSize;
2265
  int32_t daysPerFile;
2266
  int32_t daysToKeep0;
2267
  int32_t daysToKeep1;
2268
  int32_t daysToKeep2;
2269
  int32_t keepTimeOffset;
2270
  int32_t walFsyncPeriod;
2271
  int8_t  walLevel;
2272
  int8_t  strict;
2273
  int8_t  cacheLast;
2274
  int64_t reserved[7];
2275
  // 1st modification
2276
  int16_t sttTrigger;
2277
  int32_t minRows;
2278
  // 2nd modification
2279
  int32_t walRetentionPeriod;
2280
  int32_t walRetentionSize;
2281
  int32_t s3KeepLocal;
2282
  int8_t  s3Compact;
2283
} SAlterVnodeConfigReq;
2284

2285
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2286
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2287

2288
typedef struct {
2289
  int32_t  vgId;
2290
  int8_t   strict;
2291
  int8_t   selfIndex;
2292
  int8_t   replica;
2293
  SReplica replicas[TSDB_MAX_REPLICA];
2294
  int64_t  reserved[8];
2295
  int8_t   learnerSelfIndex;
2296
  int8_t   learnerReplica;
2297
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2298
  int32_t  changeVersion;
2299
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2300

2301
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2302
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2303

2304
typedef struct {
2305
  int32_t vgId;
2306
  int8_t  disable;
2307
} SDisableVnodeWriteReq;
2308

2309
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2310
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2311

2312
typedef struct {
2313
  int32_t  srcVgId;
2314
  int32_t  dstVgId;
2315
  uint32_t hashBegin;
2316
  uint32_t hashEnd;
2317
  int32_t  changeVersion;
2318
  int32_t  reserved;
2319
} SAlterVnodeHashRangeReq;
2320

2321
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2322
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2323

2324
#define REQ_OPT_TBNAME 0x0
2325
#define REQ_OPT_TBUID  0x01
2326
typedef struct {
2327
  SMsgHead header;
2328
  char     dbFName[TSDB_DB_FNAME_LEN];
2329
  char     tbName[TSDB_TABLE_NAME_LEN];
2330
  uint8_t  option;
2331
  uint8_t  autoCreateCtb;
2332
} STableInfoReq;
2333

2334
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2335
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2336

2337
typedef struct {
2338
  int8_t  metaClone;  // create local clone of the cached table meta
2339
  int32_t numOfVgroups;
2340
  int32_t numOfTables;
2341
  int32_t numOfUdfs;
2342
  char    tableNames[];
2343
} SMultiTableInfoReq;
2344

2345
// todo refactor
2346
typedef struct SVgroupInfo {
2347
  int32_t  vgId;
2348
  uint32_t hashBegin;
2349
  uint32_t hashEnd;
2350
  SEpSet   epSet;
2351
  union {
2352
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2353
    int32_t taskId;      // used in stream
2354
  };
2355
} SVgroupInfo;
2356

2357
typedef struct {
2358
  int32_t     numOfVgroups;
2359
  SVgroupInfo vgroups[];
2360
} SVgroupsInfo;
2361

2362
typedef struct {
2363
  STableMetaRsp* pMeta;
2364
} SMAlterStbRsp;
2365

2366
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2367
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2368
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2369

2370
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2371
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2372
void    tFreeSTableMetaRsp(void* pRsp);
2373
void    tFreeSTableIndexRsp(void* info);
2374

2375
typedef struct {
2376
  SArray* pMetaRsp;   // Array of STableMetaRsp
2377
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2378
} SSTbHbRsp;
2379

2380
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2381
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2382
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2383

2384
typedef struct {
2385
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2386
} SViewHbRsp;
2387

2388
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2389
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2390
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2391

2392
typedef struct {
2393
  int32_t numOfTables;
2394
  int32_t numOfVgroup;
2395
  int32_t numOfUdf;
2396
  int32_t contLen;
2397
  int8_t  compressed;  // denote if compressed or not
2398
  int32_t rawLen;      // size before compress
2399
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2400
  char    meta[];
2401
} SMultiTableMeta;
2402

2403
typedef struct {
2404
  int32_t dataLen;
2405
  char    name[TSDB_TABLE_FNAME_LEN];
2406
  char*   data;
2407
} STagData;
2408

2409
typedef struct {
2410
  int32_t  opType;
2411
  uint32_t valLen;
2412
  char*    val;
2413
} SShowVariablesReq;
2414

2415
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2416
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2417
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2418

2419
typedef struct {
2420
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2421
  char value[TSDB_CONFIG_PATH_LEN + 1];
2422
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2423
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2424
  char info[TSDB_CONFIG_INFO_LEN + 1];
2425
} SVariablesInfo;
2426

2427
typedef struct {
2428
  SArray* variables;  // SArray<SVariablesInfo>
2429
} SShowVariablesRsp;
2430

2431
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2432
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2433

2434
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2435

2436
/*
2437
 * sql: show tables like '%a_%'
2438
 * payload is the query condition, e.g., '%a_%'
2439
 * payloadLen is the length of payload
2440
 */
2441
typedef struct {
2442
  int32_t type;
2443
  char    db[TSDB_DB_FNAME_LEN];
2444
  int32_t payloadLen;
2445
  char*   payload;
2446
} SShowReq;
2447

2448
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2449
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2450
void tFreeSShowReq(SShowReq* pReq);
2451

2452
typedef struct {
2453
  int64_t       showId;
2454
  STableMetaRsp tableMeta;
2455
} SShowRsp, SVShowTablesRsp;
2456

2457
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2458
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2459
// void    tFreeSShowRsp(SShowRsp* pRsp);
2460

2461
typedef struct {
2462
  char    db[TSDB_DB_FNAME_LEN];
2463
  char    tb[TSDB_TABLE_NAME_LEN];
2464
  char    user[TSDB_USER_LEN];
2465
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2466
  int64_t showId;
2467
  int64_t compactId;  // for compact
2468
  bool    withFull;   // for show users full
2469
} SRetrieveTableReq;
2470

2471
typedef struct SSysTableSchema {
2472
  int8_t   type;
2473
  col_id_t colId;
2474
  int32_t  bytes;
2475
} SSysTableSchema;
2476

2477
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2478
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2479

2480
#define RETRIEVE_TABLE_RSP_VERSION          0
2481
#define RETRIEVE_TABLE_RSP_TMQ_VERSION      1
2482
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION  2
2483

2484
typedef struct {
2485
  int64_t useconds;
2486
  int8_t  completed;  // all results are returned to client
2487
  int8_t  precision;
2488
  int8_t  compressed;
2489
  int8_t  streamBlockType;
2490
  int32_t payloadLen;
2491
  int32_t compLen;
2492
  int32_t numOfBlocks;
2493
  int64_t numOfRows;  // from int32_t change to int64_t
2494
  int64_t numOfCols;
2495
  int64_t skey;
2496
  int64_t ekey;
2497
  int64_t version;                         // for stream
2498
  TSKEY   watermark;                       // for stream
2499
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2500
  char    data[];
2501
} SRetrieveTableRsp;
2502

2503
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2504

2505
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2506
  do {                                          \
2507
    ((int32_t*)(_p))[0] = (_compLen);           \
2508
    ((int32_t*)(_p))[1] = (_fullLen);           \
2509
  } while (0);
2510

2511
typedef struct {
2512
  int64_t version;
2513
  int64_t numOfRows;
2514
  int8_t  compressed;
2515
  int8_t  precision;
2516
  char    data[];
2517
} SRetrieveTableRspForTmq;
2518

2519
typedef struct {
2520
  int64_t handle;
2521
  int64_t useconds;
2522
  int8_t  completed;  // all results are returned to client
2523
  int8_t  precision;
2524
  int8_t  compressed;
2525
  int32_t compLen;
2526
  int32_t numOfRows;
2527
  int32_t fullLen;
2528
  char    data[];
2529
} SRetrieveMetaTableRsp;
2530

2531
typedef struct SExplainExecInfo {
2532
  double   startupCost;
2533
  double   totalCost;
2534
  uint64_t numOfRows;
2535
  uint32_t verboseLen;
2536
  void*    verboseInfo;
2537
} SExplainExecInfo;
2538

2539
typedef struct {
2540
  int32_t           numOfPlans;
2541
  SExplainExecInfo* subplanInfo;
2542
} SExplainRsp;
2543

2544
typedef struct {
2545
  SExplainRsp rsp;
2546
  uint64_t    qId;
2547
  uint64_t    cId;
2548
  uint64_t    tId;
2549
  int64_t     rId;
2550
  int32_t     eId;
2551
} SExplainLocalRsp;
2552

2553
typedef struct STableScanAnalyzeInfo {
2554
  uint64_t totalRows;
2555
  uint64_t totalCheckedRows;
2556
  uint32_t totalBlocks;
2557
  uint32_t loadBlocks;
2558
  uint32_t loadBlockStatis;
2559
  uint32_t skipBlocks;
2560
  uint32_t filterOutBlocks;
2561
  double   elapsedTime;
2562
  double   filterTime;
2563
} STableScanAnalyzeInfo;
2564

2565
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2566
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2567
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2568

2569
typedef struct {
2570
  char    config[TSDB_DNODE_CONFIG_LEN];
2571
  char    value[TSDB_CLUSTER_VALUE_LEN];
2572
  int32_t sqlLen;
2573
  char*   sql;
2574
} SMCfgClusterReq;
2575

2576
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2577
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2578
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2579

2580
typedef struct {
2581
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2582
  int32_t port;
2583
  int32_t sqlLen;
2584
  char*   sql;
2585
} SCreateDnodeReq;
2586

2587
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2588
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2589
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2590

2591
typedef struct {
2592
  int32_t dnodeId;
2593
  char    fqdn[TSDB_FQDN_LEN];
2594
  int32_t port;
2595
  int8_t  force;
2596
  int8_t  unsafe;
2597
  int32_t sqlLen;
2598
  char*   sql;
2599
} SDropDnodeReq;
2600

2601
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2602
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2603
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2604

2605
enum {
2606
  RESTORE_TYPE__ALL = 1,
2607
  RESTORE_TYPE__MNODE,
2608
  RESTORE_TYPE__VNODE,
2609
  RESTORE_TYPE__QNODE,
2610
};
2611

2612
typedef struct {
2613
  int32_t dnodeId;
2614
  int8_t  restoreType;
2615
  int32_t sqlLen;
2616
  char*   sql;
2617
} SRestoreDnodeReq;
2618

2619
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2620
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2621
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2622

2623
typedef struct {
2624
  int32_t dnodeId;
2625
  char    config[TSDB_DNODE_CONFIG_LEN];
2626
  char    value[TSDB_DNODE_VALUE_LEN];
2627
  int32_t sqlLen;
2628
  char*   sql;
2629
} SMCfgDnodeReq;
2630

2631
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2632
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2633
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2634

2635
typedef struct {
2636
  char    config[TSDB_DNODE_CONFIG_LEN];
2637
  char    value[TSDB_DNODE_VALUE_LEN];
2638
  int32_t version;
2639
} SDCfgDnodeReq;
2640

2641
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2642
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2643

2644
typedef struct {
2645
  int32_t dnodeId;
2646
  int32_t sqlLen;
2647
  char*   sql;
2648
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2649
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2650

2651
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2652
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2653
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2654
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2655
typedef struct {
2656
  int8_t   replica;
2657
  SReplica replicas[TSDB_MAX_REPLICA];
2658
  int8_t   learnerReplica;
2659
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2660
  int64_t  lastIndex;
2661
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2662

2663
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2664
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2665

2666
typedef struct {
2667
  int32_t urlLen;
2668
  int32_t sqlLen;
2669
  char*   url;
2670
  char*   sql;
2671
} SMCreateAnodeReq;
2672

2673
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2674
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2675
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2676

2677
typedef struct {
2678
  int32_t anodeId;
2679
  int32_t sqlLen;
2680
  char*   sql;
2681
} SMDropAnodeReq, SMUpdateAnodeReq;
2682

2683
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2684
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2685
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2686
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2687
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2688
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2689

2690
typedef struct {
2691
  int32_t vgId;
2692
  int32_t hbSeq;
2693
} SVArbHbReqMember;
2694

2695
typedef struct {
2696
  int32_t dnodeId;
2697
  char*   arbToken;
2698
  int64_t arbTerm;
2699
  SArray* hbMembers;  // SVArbHbReqMember
2700
} SVArbHeartBeatReq;
2701

2702
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2703
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2704
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2705

2706
typedef struct {
2707
  int32_t vgId;
2708
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2709
  int32_t hbSeq;
2710
} SVArbHbRspMember;
2711

2712
typedef struct {
2713
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2714
  int32_t dnodeId;
2715
  SArray* hbMembers;  // SVArbHbRspMember
2716
} SVArbHeartBeatRsp;
2717

2718
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2719
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2720
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2721

2722
typedef struct {
2723
  char*   arbToken;
2724
  int64_t arbTerm;
2725
  char*   member0Token;
2726
  char*   member1Token;
2727
} SVArbCheckSyncReq;
2728

2729
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2730
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2731
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2732

2733
typedef struct {
2734
  char*   arbToken;
2735
  char*   member0Token;
2736
  char*   member1Token;
2737
  int32_t vgId;
2738
  int32_t errCode;
2739
} SVArbCheckSyncRsp;
2740

2741
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2742
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2743
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2744

2745
typedef struct {
2746
  char*   arbToken;
2747
  int64_t arbTerm;
2748
  char*   memberToken;
2749
  int8_t  force;
2750
} SVArbSetAssignedLeaderReq;
2751

2752
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2753
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2754
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2755

2756
typedef struct {
2757
  char*   arbToken;
2758
  char*   memberToken;
2759
  int32_t vgId;
2760
} SVArbSetAssignedLeaderRsp;
2761

2762
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2763
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2764
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2765

2766
typedef struct {
2767
  int32_t dnodeId;
2768
  char*   token;
2769
} SMArbUpdateGroupMember;
2770

2771
typedef struct {
2772
  int32_t dnodeId;
2773
  char*   token;
2774
  int8_t  acked;
2775
} SMArbUpdateGroupAssigned;
2776

2777
typedef struct {
2778
  int32_t                  vgId;
2779
  int64_t                  dbUid;
2780
  SMArbUpdateGroupMember   members[2];
2781
  int8_t                   isSync;
2782
  int8_t                   assignedAcked;
2783
  SMArbUpdateGroupAssigned assignedLeader;
2784
  int64_t                  version;
2785
  int32_t                  code;
2786
  int64_t                  updateTimeMs;
2787
} SMArbUpdateGroup;
2788

2789
typedef struct {
2790
  SArray* updateArray;  // SMArbUpdateGroup
2791
} SMArbUpdateGroupBatchReq;
2792

2793
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2794
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2795
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2796

2797
typedef struct {
2798
  char queryStrId[TSDB_QUERY_ID_LEN];
2799
} SKillQueryReq;
2800

2801
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2802
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2803

2804
typedef struct {
2805
  uint32_t connId;
2806
} SKillConnReq;
2807

2808
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2809
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2810

2811
typedef struct {
2812
  int32_t transId;
2813
} SKillTransReq;
2814

2815
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2816
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2817

2818
typedef struct {
2819
  int32_t useless;  // useless
2820
  int32_t sqlLen;
2821
  char*   sql;
2822
} SBalanceVgroupReq;
2823

2824
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2825
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2826
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2827

2828
typedef struct {
2829
  int32_t useless;  // useless
2830
  int32_t sqlLen;
2831
  char*   sql;
2832
} SAssignLeaderReq;
2833

2834
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2835
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2836
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
2837
typedef struct {
2838
  int32_t vgId1;
2839
  int32_t vgId2;
2840
} SMergeVgroupReq;
2841

2842
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2843
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2844

2845
typedef struct {
2846
  int32_t vgId;
2847
  int32_t dnodeId1;
2848
  int32_t dnodeId2;
2849
  int32_t dnodeId3;
2850
  int32_t sqlLen;
2851
  char*   sql;
2852
} SRedistributeVgroupReq;
2853

2854
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2855
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2856
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2857

2858
typedef struct {
2859
  int32_t reserved;
2860
  int32_t vgId;
2861
  int32_t sqlLen;
2862
  char*   sql;
2863
  char    db[TSDB_DB_FNAME_LEN];
2864
} SBalanceVgroupLeaderReq;
2865

2866
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2867
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2868
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2869

2870
typedef struct {
2871
  int32_t vgId;
2872
} SForceBecomeFollowerReq;
2873

2874
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2875
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2876

2877
typedef struct {
2878
  int32_t vgId;
2879
} SSplitVgroupReq;
2880

2881
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2882
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2883

2884
typedef struct {
2885
  char user[TSDB_USER_LEN];
2886
  char spi;
2887
  char encrypt;
2888
  char secret[TSDB_PASSWORD_LEN];
2889
  char ckey[TSDB_PASSWORD_LEN];
2890
} SAuthReq, SAuthRsp;
2891

2892
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2893
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2894

2895
typedef struct {
2896
  int32_t statusCode;
2897
  char    details[1024];
2898
} SServerStatusRsp;
2899

2900
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2901
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2902

2903
/**
2904
 * The layout of the query message payload is as following:
2905
 * +--------------------+---------------------------------+
2906
 * |Sql statement       | Physical plan                   |
2907
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2908
 * +--------------------+---------------------------------+
2909
 */
2910
typedef struct SSubQueryMsg {
2911
  SMsgHead header;
2912
  uint64_t sId;
2913
  uint64_t queryId;
2914
  uint64_t clientId;
2915
  uint64_t taskId;
2916
  int64_t  refId;
2917
  int32_t  execId;
2918
  int32_t  msgMask;
2919
  int8_t   taskType;
2920
  int8_t   explain;
2921
  int8_t   needFetch;
2922
  int8_t   compress;
2923
  uint32_t sqlLen;
2924
  char*    sql;
2925
  uint32_t msgLen;
2926
  char*    msg;
2927
} SSubQueryMsg;
2928

2929
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2930
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2931
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2932

2933
typedef struct {
2934
  SMsgHead header;
2935
  uint64_t sId;
2936
  uint64_t queryId;
2937
  uint64_t taskId;
2938
} SSinkDataReq;
2939

2940
typedef struct {
2941
  SMsgHead header;
2942
  uint64_t sId;
2943
  uint64_t queryId;
2944
  uint64_t clientId;
2945
  uint64_t taskId;
2946
  int32_t  execId;
2947
} SQueryContinueReq;
2948

2949
typedef struct {
2950
  SMsgHead header;
2951
  uint64_t sId;
2952
  uint64_t queryId;
2953
  uint64_t taskId;
2954
} SResReadyReq;
2955

2956
typedef struct {
2957
  int32_t code;
2958
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2959
  int32_t sversion;
2960
  int32_t tversion;
2961
} SResReadyRsp;
2962

2963
typedef struct SOperatorParam {
2964
  int32_t opType;
2965
  int32_t downstreamIdx;
2966
  void*   value;
2967
  SArray* pChildren;  // SArray<SOperatorParam*>
2968
  bool    reUse;
2969
} SOperatorParam;
2970

2971
typedef struct SColIdNameKV {
2972
  col_id_t colId;
2973
  char     colName[TSDB_COL_NAME_LEN];
2974
} SColIdNameKV;
2975

2976
typedef struct SColIdPair {
2977
  col_id_t vtbColId;
2978
  col_id_t orgColId;
2979
} SColIdPair;
2980

2981
typedef struct SOrgTbInfo {
2982
  int32_t   vgId;
2983
  char      tbName[TSDB_TABLE_FNAME_LEN];
2984
  SArray*   colMap;  // SArray<SColIdNameKV>
2985
} SOrgTbInfo;
2986

2987
typedef struct STableScanOperatorParam {
2988
  bool           tableSeq;
2989
  SArray*        pUidList;
2990
  SOrgTbInfo*    pOrgTbInfo;
2991
  STimeWindow    window;
2992
} STableScanOperatorParam;
2993

2994
typedef struct SVTableScanOperatorParam {
2995
  uint64_t       uid;
2996
  SArray*        pOpParamArray;  // SArray<SOperatorParam>
2997
} SVTableScanOperatorParam;
2998

2999
typedef struct {
3000
  SMsgHead        header;
3001
  uint64_t        sId;
3002
  uint64_t        queryId;
3003
  uint64_t        clientId;
3004
  uint64_t        taskId;
3005
  int32_t         execId;
3006
  SOperatorParam* pOpParam;
3007
} SResFetchReq;
3008

3009
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3010
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3011

3012
typedef struct {
3013
  SMsgHead header;
3014
  uint64_t clientId;
3015
} SSchTasksStatusReq;
3016

3017
typedef struct {
3018
  uint64_t queryId;
3019
  uint64_t clientId;
3020
  uint64_t taskId;
3021
  int64_t  refId;
3022
  int32_t  execId;
3023
  int8_t   status;
3024
} STaskStatus;
3025

3026
typedef struct {
3027
  int64_t refId;
3028
  SArray* taskStatus;  // SArray<STaskStatus>
3029
} SSchedulerStatusRsp;
3030

3031
typedef struct {
3032
  uint64_t queryId;
3033
  uint64_t taskId;
3034
  int8_t   action;
3035
} STaskAction;
3036

3037
typedef struct SQueryNodeEpId {
3038
  int32_t nodeId;  // vgId or qnodeId
3039
  SEp     ep;
3040
} SQueryNodeEpId;
3041

3042
typedef struct {
3043
  SMsgHead       header;
3044
  uint64_t       clientId;
3045
  SQueryNodeEpId epId;
3046
  SArray*        taskAction;  // SArray<STaskAction>
3047
} SSchedulerHbReq;
3048

3049
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3050
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3051
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3052

3053
typedef struct {
3054
  SQueryNodeEpId epId;
3055
  SArray*        taskStatus;  // SArray<STaskStatus>
3056
} SSchedulerHbRsp;
3057

3058
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3059
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3060
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3061

3062
typedef struct {
3063
  SMsgHead header;
3064
  uint64_t sId;
3065
  uint64_t queryId;
3066
  uint64_t clientId;
3067
  uint64_t taskId;
3068
  int64_t  refId;
3069
  int32_t  execId;
3070
} STaskCancelReq;
3071

3072
typedef struct {
3073
  int32_t code;
3074
} STaskCancelRsp;
3075

3076
typedef struct {
3077
  SMsgHead header;
3078
  uint64_t sId;
3079
  uint64_t queryId;
3080
  uint64_t clientId;
3081
  uint64_t taskId;
3082
  int64_t  refId;
3083
  int32_t  execId;
3084
} STaskDropReq;
3085

3086
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3087
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3088

3089
typedef enum {
3090
  TASK_NOTIFY_FINISHED = 1,
3091
} ETaskNotifyType;
3092

3093
typedef struct {
3094
  SMsgHead        header;
3095
  uint64_t        sId;
3096
  uint64_t        queryId;
3097
  uint64_t        clientId;
3098
  uint64_t        taskId;
3099
  int64_t         refId;
3100
  int32_t         execId;
3101
  ETaskNotifyType type;
3102
} STaskNotifyReq;
3103

3104
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3105
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3106

3107
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3108
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3109

3110
typedef struct {
3111
  int32_t code;
3112
} STaskDropRsp;
3113

3114
#define STREAM_TRIGGER_AT_ONCE                 1
3115
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3116
#define STREAM_TRIGGER_MAX_DELAY               3
3117
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3118
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3119

3120
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3121
#define STREAM_FILL_HISTORY_ON        1
3122
#define STREAM_FILL_HISTORY_OFF       0
3123
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3124
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3125
#define STREAM_CREATE_STABLE_TRUE     1
3126
#define STREAM_CREATE_STABLE_FALSE    0
3127

3128
typedef struct SColLocation {
3129
  int16_t  slotId;
3130
  col_id_t colId;
3131
  int8_t   type;
3132
} SColLocation;
3133

3134
typedef struct SVgroupVer {
3135
  int32_t vgId;
3136
  int64_t ver;
3137
} SVgroupVer;
3138

3139
typedef struct {
3140
  char    name[TSDB_STREAM_FNAME_LEN];
3141
  char    sourceDB[TSDB_DB_FNAME_LEN];
3142
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
3143
  char*   sql;
3144
  char*   ast;
3145
  int8_t  igExists;
3146
  int8_t  triggerType;
3147
  int8_t  igExpired;
3148
  int8_t  fillHistory;  // process data inserted before creating stream
3149
  int64_t maxDelay;
3150
  int64_t watermark;
3151
  int32_t numOfTags;
3152
  SArray* pTags;  // array of SField
3153
  // 3.0.20
3154
  int64_t checkpointFreq;  // ms
3155
  // 3.0.2.3
3156
  int8_t   createStb;
3157
  uint64_t targetStbUid;
3158
  SArray*  fillNullCols;  // array of SColLocation
3159
  int64_t  deleteMark;
3160
  int8_t   igUpdate;
3161
  int64_t  lastTs;
3162
  SArray*  pVgroupVerList;
3163
  // 3.3.0.0
3164
  SArray* pCols;  // array of SField
3165
  int64_t smaId;
3166
  // 3.3.6.0
3167
  SArray* pNotifyAddrUrls;
3168
  int32_t notifyEventTypes;
3169
  int32_t notifyErrorHandle;
3170
  int8_t  notifyHistory;
3171
  int64_t recalculateInterval;
3172
  char    pWstartName[TSDB_COL_NAME_LEN];
3173
  char    pWendName[TSDB_COL_NAME_LEN];
3174
  char    pGroupIdName[TSDB_COL_NAME_LEN];
3175
  char    pIsWindowFilledName[TSDB_COL_NAME_LEN];
3176
  SArray* pVSubTables; // array of SVSubTablesRsp
3177
} SCMCreateStreamReq;
3178

3179
typedef struct STaskNotifyEventStat {
3180
  int64_t notifyEventAddTimes;     // call times of add function
3181
  int64_t notifyEventAddElems;     // elements added by add function
3182
  double  notifyEventAddCostSec;   // time cost of add function
3183
  int64_t notifyEventPushTimes;    // call times of push function
3184
  int64_t notifyEventPushElems;    // elements pushed by push function
3185
  double  notifyEventPushCostSec;  // time cost of push function
3186
  int64_t notifyEventPackTimes;    // call times of pack function
3187
  int64_t notifyEventPackElems;    // elements packed by pack function
3188
  double  notifyEventPackCostSec;  // time cost of pack function
3189
  int64_t notifyEventSendTimes;    // call times of send function
3190
  int64_t notifyEventSendElems;    // elements sent by send function
3191
  double  notifyEventSendCostSec;  // time cost of send function
3192
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3193
} STaskNotifyEventStat;
3194

3195
typedef struct {
3196
  int64_t streamId;
3197
} SCMCreateStreamRsp;
3198

3199
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3200
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3201
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3202

3203
enum {
3204
  TOPIC_SUB_TYPE__DB = 1,
3205
  TOPIC_SUB_TYPE__TABLE,
3206
  TOPIC_SUB_TYPE__COLUMN,
3207
};
3208

3209
#define DEFAULT_MAX_POLL_INTERVAL  300000
3210
#define DEFAULT_SESSION_TIMEOUT    12000
3211
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3212
#define DEFAULT_MIN_POLL_ROWS      4096
3213

3214
typedef struct {
3215
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3216
  int8_t igExists;
3217
  int8_t subType;
3218
  int8_t withMeta;
3219
  char*  sql;
3220
  char   subDbName[TSDB_DB_FNAME_LEN];
3221
  char*  ast;
3222
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3223
} SCMCreateTopicReq;
3224

3225
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3226
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3227
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3228

3229
typedef struct {
3230
  int64_t consumerId;
3231
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3232

3233
typedef struct {
3234
  int64_t consumerId;
3235
  char    cgroup[TSDB_CGROUP_LEN];
3236
  char    clientId[TSDB_CLIENT_ID_LEN];
3237
  char    user[TSDB_USER_LEN];
3238
  char    fqdn[TSDB_FQDN_LEN];
3239
  SArray* topicNames;  // SArray<char**>
3240

3241
  int8_t  withTbName;
3242
  int8_t  autoCommit;
3243
  int32_t autoCommitInterval;
3244
  int8_t  resetOffsetCfg;
3245
  int8_t  enableReplay;
3246
  int8_t  enableBatchMeta;
3247
  int32_t sessionTimeoutMs;
3248
  int32_t maxPollIntervalMs;
3249
} SCMSubscribeReq;
3250

3251
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3252
  int32_t tlen = 0;
2,456✔
3253
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,456!
3254
  tlen += taosEncodeString(buf, pReq->cgroup);
2,456✔
3255
  tlen += taosEncodeString(buf, pReq->clientId);
2,456✔
3256

3257
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,456!
3258
  tlen += taosEncodeFixedI32(buf, topicNum);
2,456✔
3259

3260
  for (int32_t i = 0; i < topicNum; i++) {
3,454✔
3261
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
1,996✔
3262
  }
3263

3264
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,456!
3265
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,456!
3266
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,456!
3267
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,456!
3268
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,456!
3269
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,456!
3270
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,456!
3271
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,456!
3272
  tlen += taosEncodeString(buf, pReq->user);
2,456✔
3273
  tlen += taosEncodeString(buf, pReq->fqdn);
2,456✔
3274

3275
  return tlen;
2,456✔
3276
}
3277

3278
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3279
  void* start = buf;
1,331✔
3280
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,331!
3281
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,331✔
3282
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,331✔
3283

3284
  int32_t topicNum = 0;
1,331!
3285
  buf = taosDecodeFixedI32(buf, &topicNum);
1,331✔
3286

3287
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,331✔
3288
  if (pReq->topicNames == NULL) {
1,331!
UNCOV
3289
    return terrno;
×
3290
  }
3291
  for (int32_t i = 0; i < topicNum; i++) {
1,937✔
3292
    char* name = NULL;
606✔
3293
    buf = taosDecodeString(buf, &name);
606✔
3294
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,212!
UNCOV
3295
      return terrno;
×
3296
    }
3297
  }
3298

3299
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,331✔
3300
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,331✔
3301
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,331!
3302
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,331✔
3303
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,331✔
3304
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,331✔
3305
  if ((char*)buf - (char*)start < len) {
1,331!
3306
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,331!
3307
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,331!
3308
    buf = taosDecodeStringTo(buf, pReq->user);
1,331✔
3309
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,662✔
3310
  } else {
UNCOV
3311
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
3312
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3313
  }
3314

3315
  return 0;
1,331✔
3316
}
3317

3318
typedef struct {
3319
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3320
  SArray* removedConsumers;  // SArray<int64_t>
3321
  SArray* newConsumers;      // SArray<int64_t>
3322
} SMqRebInfo;
3323

3324
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3325
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,297!
3326
  if (pRebInfo == NULL) {
1,297!
UNCOV
3327
    return NULL;
×
3328
  }
3329
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,297✔
3330
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,297✔
3331
  if (pRebInfo->removedConsumers == NULL) {
1,297!
UNCOV
3332
    goto _err;
×
3333
  }
3334
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,297✔
3335
  if (pRebInfo->newConsumers == NULL) {
1,297!
UNCOV
3336
    goto _err;
×
3337
  }
3338
  return pRebInfo;
1,297✔
UNCOV
3339
_err:
×
UNCOV
3340
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
3341
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
3342
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
3343
  return NULL;
×
3344
}
3345

3346
typedef struct {
3347
  int64_t streamId;
3348
  int64_t checkpointId;
3349
  char    streamName[TSDB_STREAM_FNAME_LEN];
3350
} SMStreamDoCheckpointMsg;
3351

3352
typedef struct {
3353
  int64_t status;
3354
} SMVSubscribeRsp;
3355

3356
typedef struct {
3357
  char    name[TSDB_TOPIC_FNAME_LEN];
3358
  int8_t  igNotExists;
3359
  int32_t sqlLen;
3360
  char*   sql;
3361
} SMDropTopicReq;
3362

3363
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3364
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3365
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3366

3367
typedef struct {
3368
  char   topic[TSDB_TOPIC_FNAME_LEN];
3369
  char   cgroup[TSDB_CGROUP_LEN];
3370
  int8_t igNotExists;
3371
} SMDropCgroupReq;
3372

3373
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3374
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3375

3376
typedef struct {
3377
  int8_t reserved;
3378
} SMDropCgroupRsp;
3379

3380
typedef struct {
3381
  char    name[TSDB_TABLE_FNAME_LEN];
3382
  int8_t  alterType;
3383
  SSchema schema;
3384
} SAlterTopicReq;
3385

3386
typedef struct {
3387
  SMsgHead head;
3388
  char     name[TSDB_TABLE_FNAME_LEN];
3389
  int64_t  tuid;
3390
  int32_t  sverson;
3391
  int32_t  execLen;
3392
  char*    executor;
3393
  int32_t  sqlLen;
3394
  char*    sql;
3395
} SDCreateTopicReq;
3396

3397
typedef struct {
3398
  SMsgHead head;
3399
  char     name[TSDB_TABLE_FNAME_LEN];
3400
  int64_t  tuid;
3401
} SDDropTopicReq;
3402

3403
typedef struct {
3404
  int64_t maxdelay[2];
3405
  int64_t watermark[2];
3406
  int64_t deleteMark[2];
3407
  int32_t qmsgLen[2];
3408
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3409
} SRSmaParam;
3410

3411
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3412
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3413

3414
// TDMT_VND_CREATE_STB ==============
3415
typedef struct SVCreateStbReq {
3416
  char*           name;
3417
  tb_uid_t        suid;
3418
  int8_t          rollup;
3419
  SSchemaWrapper  schemaRow;
3420
  SSchemaWrapper  schemaTag;
3421
  SRSmaParam      rsmaParam;
3422
  int32_t         alterOriDataLen;
3423
  void*           alterOriData;
3424
  int8_t          source;
3425
  int8_t          colCmpred;
3426
  SColCmprWrapper colCmpr;
3427
  int64_t         keep;
3428
  SExtSchema*     pExtSchemas;
3429
  int8_t          virtualStb;
3430
} SVCreateStbReq;
3431

3432
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3433
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3434

3435
// TDMT_VND_DROP_STB ==============
3436
typedef struct SVDropStbReq {
3437
  char*    name;
3438
  tb_uid_t suid;
3439
} SVDropStbReq;
3440

3441
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3442
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3443

3444
// TDMT_VND_CREATE_TABLE ==============
3445
#define TD_CREATE_IF_NOT_EXISTS 0x1
3446
typedef struct SVCreateTbReq {
3447
  int32_t  flags;
3448
  char*    name;
3449
  tb_uid_t uid;
3450
  int64_t  btime;
3451
  int32_t  ttl;
3452
  int32_t  commentLen;
3453
  char*    comment;
3454
  int8_t   type;
3455
  union {
3456
    struct {
3457
      char*    stbName;  // super table name
3458
      uint8_t  tagNum;
3459
      tb_uid_t suid;
3460
      SArray*  tagName;
3461
      uint8_t* pTag;
3462
    } ctb;
3463
    struct {
3464
      SSchemaWrapper schemaRow;
3465
    } ntb;
3466
  };
3467
  int32_t         sqlLen;
3468
  char*           sql;
3469
  SColCmprWrapper colCmpr;
3470
  SExtSchema*     pExtSchemas;
3471
  SColRefWrapper  colRef; // col reference for virtual table
3472
} SVCreateTbReq;
3473

3474
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3475
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3476
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3477

3478
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,830✔
3479
  if (NULL == req) {
19,558,136!
3480
    return;
19,340,540✔
3481
  }
3482

3483
  taosMemoryFreeClear(req->sql);
217,596!
3484
  taosMemoryFreeClear(req->name);
217,596!
3485
  taosMemoryFreeClear(req->comment);
217,607!
3486
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
217,607!
3487
    taosMemoryFreeClear(req->ctb.pTag);
204,205!
3488
    taosMemoryFreeClear(req->ctb.stbName);
204,220!
3489
    taosArrayDestroy(req->ctb.tagName);
204,223✔
3490
    req->ctb.tagName = NULL;
204,209✔
3491
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
13,402!
3492
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
13,402!
3493
  }
3494
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
217,611!
3495
  taosMemoryFreeClear(req->pExtSchemas);
217,611!
3496
  taosMemoryFreeClear(req->colRef.pColRef);
217,611!
3497
}
3498

3499
typedef struct {
3500
  int32_t nReqs;
3501
  union {
3502
    SVCreateTbReq* pReqs;
3503
    SArray*        pArray;
3504
  };
3505
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3506
} SVCreateTbBatchReq;
3507

3508
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3509
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3510
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3511

3512
typedef struct {
3513
  int32_t        code;
3514
  STableMetaRsp* pMeta;
3515
} SVCreateTbRsp, SVUpdateTbRsp;
3516

3517
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3518
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3519
void tFreeSVCreateTbRsp(void* param);
3520

3521
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3522
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3523

3524
typedef struct {
3525
  int32_t nRsps;
3526
  union {
3527
    SVCreateTbRsp* pRsps;
3528
    SArray*        pArray;
3529
  };
3530
} SVCreateTbBatchRsp;
3531

3532
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3533
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3534

3535
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3536
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3537

3538
// TDMT_VND_DROP_TABLE =================
3539
typedef struct {
3540
  char*    name;
3541
  uint64_t suid;  // for tmq in wal format
3542
  int64_t  uid;
3543
  int8_t   igNotExists;
3544
  int8_t   isVirtual;
3545
} SVDropTbReq;
3546

3547
typedef struct {
3548
  int32_t code;
3549
} SVDropTbRsp;
3550

3551
typedef struct {
3552
  int32_t nReqs;
3553
  union {
3554
    SVDropTbReq* pReqs;
3555
    SArray*      pArray;
3556
  };
3557
} SVDropTbBatchReq;
3558

3559
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3560
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3561

3562
typedef struct {
3563
  int32_t nRsps;
3564
  union {
3565
    SVDropTbRsp* pRsps;
3566
    SArray*      pArray;
3567
  };
3568
} SVDropTbBatchRsp;
3569

3570
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3571
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3572

3573
// TDMT_VND_ALTER_TABLE =====================
3574
typedef struct SMultiTagUpateVal {
3575
  char*    tagName;
3576
  int32_t  colId;
3577
  int8_t   tagType;
3578
  int8_t   tagFree;
3579
  uint32_t nTagVal;
3580
  uint8_t* pTagVal;
3581
  int8_t   isNull;
3582
  SArray*  pTagArray;
3583
} SMultiTagUpateVal;
3584
typedef struct SVAlterTbReq{
3585
  char*   tbName;
3586
  int8_t  action;
3587
  char*   colName;
3588
  int32_t colId;
3589
  // TSDB_ALTER_TABLE_ADD_COLUMN
3590
  int8_t  type;
3591
  int8_t  flags;
3592
  int32_t bytes;
3593
  // TSDB_ALTER_TABLE_DROP_COLUMN
3594
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3595
  int8_t   colModType;
3596
  int32_t  colModBytes;
3597
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3598
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3599
  int8_t   isNull;
3600
  int8_t   tagType;
3601
  int8_t   tagFree;
3602
  uint32_t nTagVal;
3603
  uint8_t* pTagVal;
3604
  SArray*  pTagArray;
3605
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3606
  int8_t   updateTTL;
3607
  int32_t  newTTL;
3608
  int32_t  newCommentLen;
3609
  char*    newComment;
3610
  int64_t  ctimeMs;    // fill by vnode
3611
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3612
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3613
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3614
  // for Add column
3615
  STypeMod typeMod;
3616
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3617
  char*    refDbName;
3618
  char*    refTbName;
3619
  char*    refColName;
3620
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
3621
} SVAlterTbReq;
3622

3623
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3624
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3625
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3626
void    tfreeMultiTagUpateVal(void* pMultiTag);
3627

3628
typedef struct {
3629
  int32_t        code;
3630
  STableMetaRsp* pMeta;
3631
} SVAlterTbRsp;
3632

3633
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3634
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3635
// ======================
3636

3637
typedef struct {
3638
  SMsgHead head;
3639
  int64_t  uid;
3640
  int32_t  tid;
3641
  int16_t  tversion;
3642
  int16_t  colId;
3643
  int8_t   type;
3644
  int16_t  bytes;
3645
  int32_t  tagValLen;
3646
  int16_t  numOfTags;
3647
  int32_t  schemaLen;
3648
  char     data[];
3649
} SUpdateTagValReq;
3650

3651
typedef struct {
3652
  SMsgHead head;
3653
} SUpdateTagValRsp;
3654

3655
typedef struct {
3656
  SMsgHead head;
3657
} SVShowTablesReq;
3658

3659
typedef struct {
3660
  SMsgHead head;
3661
  int32_t  id;
3662
} SVShowTablesFetchReq;
3663

3664
typedef struct {
3665
  int64_t useconds;
3666
  int8_t  completed;  // all results are returned to client
3667
  int8_t  precision;
3668
  int8_t  compressed;
3669
  int32_t compLen;
3670
  int32_t numOfRows;
3671
  char    data[];
3672
} SVShowTablesFetchRsp;
3673

3674
typedef struct {
3675
  int64_t consumerId;
3676
  int32_t epoch;
3677
  char    cgroup[TSDB_CGROUP_LEN];
3678
} SMqAskEpReq;
3679

3680
typedef struct {
3681
  int32_t key;
3682
  int32_t valueLen;
3683
  void*   value;
3684
} SKv;
3685

3686
typedef struct {
3687
  int64_t tscRid;
3688
  int8_t  connType;
3689
} SClientHbKey;
3690

3691
typedef struct {
3692
  int64_t tid;
3693
  char    status[TSDB_JOB_STATUS_LEN];
3694
} SQuerySubDesc;
3695

3696
typedef struct {
3697
  char     sql[TSDB_SHOW_SQL_LEN];
3698
  uint64_t queryId;
3699
  int64_t  useconds;
3700
  int64_t  stime;  // timestamp precision ms
3701
  int64_t  reqRid;
3702
  bool     stableQuery;
3703
  bool     isSubQuery;
3704
  char     fqdn[TSDB_FQDN_LEN];
3705
  int32_t  subPlanNum;
3706
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3707
} SQueryDesc;
3708

3709
typedef struct {
3710
  uint32_t connId;
3711
  SArray*  queryDesc;  // SArray<SQueryDesc>
3712
} SQueryHbReqBasic;
3713

3714
typedef struct {
3715
  uint32_t connId;
3716
  uint64_t killRid;
3717
  int32_t  totalDnodes;
3718
  int32_t  onlineDnodes;
3719
  int8_t   killConnection;
3720
  int8_t   align[3];
3721
  SEpSet   epSet;
3722
  SArray*  pQnodeList;
3723
} SQueryHbRspBasic;
3724

3725
typedef struct SAppClusterSummary {
3726
  uint64_t numOfInsertsReq;
3727
  uint64_t numOfInsertRows;
3728
  uint64_t insertElapsedTime;
3729
  uint64_t insertBytes;  // submit to tsdb since launched.
3730

3731
  uint64_t fetchBytes;
3732
  uint64_t numOfQueryReq;
3733
  uint64_t queryElapsedTime;
3734
  uint64_t numOfSlowQueries;
3735
  uint64_t totalRequests;
3736
  uint64_t currentRequests;  // the number of SRequestObj
3737
} SAppClusterSummary;
3738

3739
typedef struct {
3740
  int64_t            appId;
3741
  int32_t            pid;
3742
  char               name[TSDB_APP_NAME_LEN];
3743
  int64_t            startTime;
3744
  SAppClusterSummary summary;
3745
} SAppHbReq;
3746

3747
typedef struct {
3748
  SClientHbKey      connKey;
3749
  int64_t           clusterId;
3750
  SAppHbReq         app;
3751
  SQueryHbReqBasic* query;
3752
  SHashObj*         info;  // hash<Skv.key, Skv>
3753
  char              userApp[TSDB_APP_NAME_LEN];
3754
  uint32_t          userIp;
3755
} SClientHbReq;
3756

3757
typedef struct {
3758
  int64_t reqId;
3759
  SArray* reqs;  // SArray<SClientHbReq>
3760
  int64_t ipWhiteList;
3761
} SClientHbBatchReq;
3762

3763
typedef struct {
3764
  SClientHbKey      connKey;
3765
  int32_t           status;
3766
  SQueryHbRspBasic* query;
3767
  SArray*           info;  // Array<Skv>
3768
} SClientHbRsp;
3769

3770
typedef struct {
3771
  int64_t       reqId;
3772
  int64_t       rspId;
3773
  int32_t       svrTimestamp;
3774
  SArray*       rsps;  // SArray<SClientHbRsp>
3775
  SMonitorParas monitorParas;
3776
  int8_t        enableAuditDelete;
3777
  int8_t        enableStrongPass;
3778
} SClientHbBatchRsp;
3779

3780
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
270,647✔
3781

3782
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3783
  void* pIter = taosHashIterate(info, NULL);
599,605✔
3784
  while (pIter != NULL) {
1,035,536!
3785
    SKv* kv = (SKv*)pIter;
435,879✔
3786
    taosMemoryFreeClear(kv->value);
435,879!
3787
    pIter = taosHashIterate(info, pIter);
435,879✔
3788
  }
3789
}
599,657✔
3790

3791
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
405,289✔
3792
  SQueryDesc* desc = (SQueryDesc*)pDesc;
405,289✔
3793
  if (desc->subDesc) {
405,289✔
3794
    taosArrayDestroy(desc->subDesc);
396,714✔
3795
    desc->subDesc = NULL;
396,717✔
3796
  }
3797
}
405,292✔
3798

3799
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
689,876✔
3800
  SClientHbReq* req = (SClientHbReq*)pReq;
717,361✔
3801
  if (req->query) {
717,361!
3802
    if (req->query->queryDesc) {
677,151!
3803
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
46,595✔
3804
    }
3805
    taosMemoryFreeClear(req->query);
677,151!
3806
  }
3807

3808
  if (req->info) {
717,321!
3809
    tFreeReqKvHash(req->info);
599,605✔
3810
    taosHashCleanup(req->info);
599,657✔
3811
    req->info = NULL;
599,646✔
3812
  }
3813
}
591,309✔
3814

3815
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3816
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3817

3818
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3819
  if (pReq == NULL) return;
45,567!
3820
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
45,567✔
3821
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
45,567✔
3822
  taosMemoryFree(pReq);
45,567!
3823
}
3824

3825
static FORCE_INLINE void tFreeClientKv(void* pKv) {
162,502✔
3826
  SKv* kv = (SKv*)pKv;
162,502✔
3827
  if (kv) {
162,502!
3828
    taosMemoryFreeClear(kv->value);
162,502!
3829
  }
3830
}
162,501✔
3831

3832
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
686,348✔
3833
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
686,348✔
3834
  if (rsp->query) {
686,348✔
3835
    taosArrayDestroy(rsp->query->pQnodeList);
673,839✔
3836
    taosMemoryFreeClear(rsp->query);
673,889!
3837
  }
3838
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
686,441!
3839
}
122,882✔
3840

3841
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3842
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
493,843✔
3843
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
493,843✔
3844
}
493,976✔
3845

3846
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3847
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3848
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3849

3850
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3851
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
787,256!
3852
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
787,256!
3853
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
787,256!
3854
  return 0;
393,628✔
3855
}
3856

3857
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3858
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
803,056!
3859
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
803,040!
3860
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
401,529!
3861
  if (pKv->value == NULL) {
401,529!
UNCOV
3862
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3863
  }
3864
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
401,529!
3865
  return 0;
401,519✔
3866
}
3867

3868
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3869
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,758,366!
3870
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,758,366!
3871
  return 0;
1,379,183✔
3872
}
3873

3874
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3875
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,372,625!
3876
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,372,712!
3877
  return 0;
686,432✔
3878
}
3879

3880
typedef struct {
3881
  int32_t vgId;
3882
  // TODO stas
3883
} SMqReportVgInfo;
3884

3885
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3886
  int32_t tlen = 0;
3887
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3888
  return tlen;
3889
}
3890

3891
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3892
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3893
  return buf;
3894
}
3895

3896
typedef struct {
3897
  int32_t epoch;
3898
  int64_t topicUid;
3899
  char    name[TSDB_TOPIC_FNAME_LEN];
3900
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3901
} SMqTopicInfo;
3902

3903
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3904
  int32_t tlen = 0;
3905
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3906
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3907
  tlen += taosEncodeString(buf, pTopicInfo->name);
3908
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3909
  tlen += taosEncodeFixedI32(buf, sz);
3910
  for (int32_t i = 0; i < sz; i++) {
3911
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3912
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3913
  }
3914
  return tlen;
3915
}
3916

3917
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3918
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3919
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3920
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3921
  int32_t sz;
3922
  buf = taosDecodeFixedI32(buf, &sz);
3923
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3924
    return NULL;
3925
  }
3926
  for (int32_t i = 0; i < sz; i++) {
3927
    SMqReportVgInfo vgInfo;
3928
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3929
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3930
      return NULL;
3931
    }
3932
  }
3933
  return buf;
3934
}
3935

3936
typedef struct {
3937
  int32_t status;  // ask hb endpoint
3938
  int32_t epoch;
3939
  int64_t consumerId;
3940
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3941
} SMqReportReq;
3942

3943
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3944
  int32_t tlen = 0;
3945
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3946
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3947
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3948
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3949
  tlen += taosEncodeFixedI32(buf, sz);
3950
  for (int32_t i = 0; i < sz; i++) {
3951
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3952
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3953
  }
3954
  return tlen;
3955
}
3956

3957
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3958
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3959
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3960
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3961
  int32_t sz;
3962
  buf = taosDecodeFixedI32(buf, &sz);
3963
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3964
    return NULL;
3965
  }
3966
  for (int32_t i = 0; i < sz; i++) {
3967
    SMqTopicInfo topicInfo;
3968
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3969
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3970
      return NULL;
3971
    }
3972
  }
3973
  return buf;
3974
}
3975

3976
typedef struct {
3977
  SMsgHead head;
3978
  int64_t  leftForVer;
3979
  int32_t  vgId;
3980
  int64_t  consumerId;
3981
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3982
} SMqVDeleteReq;
3983

3984
typedef struct {
3985
  int8_t reserved;
3986
} SMqVDeleteRsp;
3987

3988
typedef struct {
3989
  char    name[TSDB_STREAM_FNAME_LEN];
3990
  int8_t  igNotExists;
3991
  int32_t sqlLen;
3992
  char*   sql;
3993
} SMDropStreamReq;
3994

3995
typedef struct {
3996
  int8_t reserved;
3997
} SMDropStreamRsp;
3998

3999
typedef struct {
4000
  SMsgHead head;
4001
  int64_t  resetRelHalt;  // reset related stream task halt status
4002
  int64_t  streamId;
4003
  int32_t  taskId;
4004
} SVDropStreamTaskReq;
4005

4006
typedef struct {
4007
  int8_t reserved;
4008
} SVDropStreamTaskRsp;
4009

4010
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4011
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4012
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4013

4014
typedef struct SVUpdateCheckpointInfoReq {
4015
  SMsgHead head;
4016
  int64_t  streamId;
4017
  int32_t  taskId;
4018
  int64_t  checkpointId;
4019
  int64_t  checkpointVer;
4020
  int64_t  checkpointTs;
4021
  int32_t  transId;
4022
  int64_t  hStreamId;  // add encode/decode
4023
  int64_t  hTaskId;
4024
  int8_t   dropRelHTask;
4025
} SVUpdateCheckpointInfoReq;
4026

4027
typedef struct {
4028
  int64_t leftForVer;
4029
  int32_t vgId;
4030
  int64_t oldConsumerId;
4031
  int64_t newConsumerId;
4032
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4033
  int8_t  subType;
4034
  int8_t  withMeta;
4035
  char*   qmsg;  // SubPlanToString
4036
  int64_t suid;
4037
} SMqRebVgReq;
4038

4039
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4040
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4041

4042
typedef struct {
4043
  char    topic[TSDB_TOPIC_FNAME_LEN];
4044
  int64_t ntbUid;
4045
  SArray* colIdList;  // SArray<int16_t>
4046
} STqCheckInfo;
4047

4048
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4049
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4050
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4051

4052
// tqOffset
4053
enum {
4054
  TMQ_OFFSET__RESET_NONE = -3,
4055
  TMQ_OFFSET__RESET_EARLIEST = -2,
4056
  TMQ_OFFSET__RESET_LATEST = -1,
4057
  TMQ_OFFSET__LOG = 1,
4058
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4059
  TMQ_OFFSET__SNAPSHOT_META = 3,
4060
};
4061

4062
enum {
4063
  WITH_DATA = 0,
4064
  WITH_META = 1,
4065
  ONLY_META = 2,
4066
};
4067

4068
#define TQ_OFFSET_VERSION 1
4069

4070
typedef struct {
4071
  int8_t type;
4072
  union {
4073
    // snapshot
4074
    struct {
4075
      int64_t uid;
4076
      int64_t ts;
4077
      SValue  primaryKey;
4078
    };
4079
    // log
4080
    struct {
4081
      int64_t version;
4082
    };
4083
  };
4084
} STqOffsetVal;
4085

4086
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4087
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
180,419✔
4088
  pOffsetVal->uid = uid;
180,419✔
4089
  pOffsetVal->ts = ts;
180,419✔
4090
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
180,419!
4091
    taosMemoryFree(pOffsetVal->primaryKey.pData);
1!
4092
  }
4093
  pOffsetVal->primaryKey = primaryKey;
180,441✔
4094
}
180,441✔
4095

4096
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4097
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
143✔
4098
  pOffsetVal->uid = uid;
143✔
4099
}
143✔
4100

4101
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4102
  pOffsetVal->type = TMQ_OFFSET__LOG;
3,351,162✔
4103
  pOffsetVal->version = ver;
3,351,162✔
4104
}
3,351,162✔
4105

4106
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4107
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4108
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4109
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4110
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4111
void    tOffsetDestroy(void* pVal);
4112

4113
typedef struct {
4114
  STqOffsetVal val;
4115
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4116
} STqOffset;
4117

4118
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4119
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4120
void    tDeleteSTqOffset(void* val);
4121

4122
typedef struct SMqVgOffset {
4123
  int64_t   consumerId;
4124
  STqOffset offset;
4125
} SMqVgOffset;
4126

4127
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4128
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4129

4130
typedef struct {
4131
  SMsgHead head;
4132
  int64_t  streamId;
4133
  int32_t  taskId;
4134
} SVPauseStreamTaskReq;
4135

4136
typedef struct {
4137
  SMsgHead head;
4138
  int64_t  streamId;
4139
  int32_t  taskId;
4140
  int64_t  chkptId;
4141
} SVResetStreamTaskReq;
4142

4143
typedef struct {
4144
  char   name[TSDB_STREAM_FNAME_LEN];
4145
  int8_t igNotExists;
4146
} SMPauseStreamReq;
4147

4148
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4149
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4150

4151
typedef struct {
4152
  SMsgHead head;
4153
  int32_t  taskId;
4154
  int64_t  streamId;
4155
  int8_t   igUntreated;
4156
} SVResumeStreamTaskReq;
4157

4158
typedef struct {
4159
  int8_t reserved;
4160
} SVResumeStreamTaskRsp;
4161

4162
typedef struct {
4163
  char   name[TSDB_STREAM_FNAME_LEN];
4164
  int8_t igNotExists;
4165
  int8_t igUntreated;
4166
} SMResumeStreamReq;
4167

4168
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4169
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4170

4171
typedef struct {
4172
  char   name[TSDB_STREAM_FNAME_LEN];
4173
  int8_t igNotExists;
4174
  int8_t igUntreated;
4175
} SMResetStreamReq;
4176

4177
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
4178
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
4179

4180
typedef struct {
4181
  char    name[TSDB_TABLE_FNAME_LEN];
4182
  char    stb[TSDB_TABLE_FNAME_LEN];
4183
  int8_t  igExists;
4184
  int8_t  intervalUnit;
4185
  int8_t  slidingUnit;
4186
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4187
  int32_t dstVgId;   // for stream
4188
  int64_t interval;
4189
  int64_t offset;
4190
  int64_t sliding;
4191
  int64_t maxDelay;
4192
  int64_t watermark;
4193
  int32_t exprLen;        // strlen + 1
4194
  int32_t tagsFilterLen;  // strlen + 1
4195
  int32_t sqlLen;         // strlen + 1
4196
  int32_t astLen;         // strlen + 1
4197
  char*   expr;
4198
  char*   tagsFilter;
4199
  char*   sql;
4200
  char*   ast;
4201
  int64_t deleteMark;
4202
  int64_t lastTs;
4203
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4204
  SArray* pVgroupVerList;
4205
  int8_t  recursiveTsma;
4206
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4207
} SMCreateSmaReq;
4208

4209
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4210
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4211
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4212

4213
typedef struct {
4214
  char   name[TSDB_TABLE_FNAME_LEN];
4215
  int8_t igNotExists;
4216
} SMDropSmaReq;
4217

4218
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4219
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4220

4221
typedef struct {
4222
  char   dbFName[TSDB_DB_FNAME_LEN];
4223
  char   stbName[TSDB_TABLE_NAME_LEN];
4224
  char   colName[TSDB_COL_NAME_LEN];
4225
  char   idxName[TSDB_INDEX_FNAME_LEN];
4226
  int8_t idxType;
4227
} SCreateTagIndexReq;
4228

4229
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4230
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4231

4232
typedef SMDropSmaReq SDropTagIndexReq;
4233

4234
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4235
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4236

4237
typedef struct {
4238
  int8_t         version;       // for compatibility(default 0)
4239
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4240
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4241
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4242
  int32_t        dstVgId;
4243
  char           indexName[TSDB_INDEX_NAME_LEN];
4244
  int32_t        exprLen;
4245
  int32_t        tagsFilterLen;
4246
  int64_t        indexUid;
4247
  tb_uid_t       tableUid;  // super/child/common table uid
4248
  tb_uid_t       dstTbUid;  // for dstVgroup
4249
  int64_t        interval;
4250
  int64_t        offset;  // use unit by precision of DB
4251
  int64_t        sliding;
4252
  char*          dstTbName;  // for dstVgroup
4253
  char*          expr;       // sma expression
4254
  char*          tagsFilter;
4255
  SSchemaWrapper schemaRow;  // for dstVgroup
4256
  SSchemaWrapper schemaTag;  // for dstVgroup
4257
} STSma;                     // Time-range-wise SMA
4258

4259
typedef STSma SVCreateTSmaReq;
4260

4261
typedef struct {
4262
  int8_t  type;  // 0 status report, 1 update data
4263
  int64_t indexUid;
4264
  int64_t skey;  // start TS key of interval/sliding window
4265
} STSmaMsg;
4266

4267
typedef struct {
4268
  int64_t indexUid;
4269
  char    indexName[TSDB_INDEX_NAME_LEN];
4270
} SVDropTSmaReq;
4271

4272
typedef struct {
4273
  int tmp;  // TODO: to avoid compile error
4274
} SVCreateTSmaRsp, SVDropTSmaRsp;
4275

4276
#if 0
4277
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4278
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4279
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4280
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4281
#endif
4282

4283
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4284
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4285
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4286
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4287

4288
typedef struct {
4289
  int32_t number;
4290
  STSma*  tSma;
4291
} STSmaWrapper;
4292

4293
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
UNCOV
4294
  if (pSma) {
×
UNCOV
4295
    taosMemoryFreeClear(pSma->dstTbName);
×
UNCOV
4296
    taosMemoryFreeClear(pSma->expr);
×
UNCOV
4297
    taosMemoryFreeClear(pSma->tagsFilter);
×
4298
  }
UNCOV
4299
}
×
4300

4301
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
4302
  if (pSW) {
×
UNCOV
4303
    if (pSW->tSma) {
×
UNCOV
4304
      if (deepCopy) {
×
UNCOV
4305
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
4306
          tDestroyTSma(pSW->tSma + i);
×
4307
        }
4308
      }
UNCOV
4309
      taosMemoryFreeClear(pSW->tSma);
×
4310
    }
4311
  }
UNCOV
4312
}
×
4313

4314
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
4315
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
4316
  taosMemoryFreeClear(pSW);
×
UNCOV
4317
  return NULL;
×
4318
}
4319

4320
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4321
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4322

4323
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4324
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4325

UNCOV
4326
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
4327
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
4328
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
4329
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4330
  }
UNCOV
4331
  return 0;
×
4332
}
4333

UNCOV
4334
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
4335
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
4336
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
4337
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4338
  }
UNCOV
4339
  return 0;
×
4340
}
4341

4342
typedef struct {
4343
  int idx;
4344
} SMCreateFullTextReq;
4345

4346
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4347
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4348
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4349

4350
typedef struct {
4351
  char   name[TSDB_TABLE_FNAME_LEN];
4352
  int8_t igNotExists;
4353
} SMDropFullTextReq;
4354

4355
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4356
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4357

4358
typedef struct {
4359
  char indexFName[TSDB_INDEX_FNAME_LEN];
4360
} SUserIndexReq;
4361

4362
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4363
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4364

4365
typedef struct {
4366
  char dbFName[TSDB_DB_FNAME_LEN];
4367
  char tblFName[TSDB_TABLE_FNAME_LEN];
4368
  char colName[TSDB_COL_NAME_LEN];
4369
  char indexType[TSDB_INDEX_TYPE_LEN];
4370
  char indexExts[TSDB_INDEX_EXTS_LEN];
4371
} SUserIndexRsp;
4372

4373
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4374
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4375

4376
typedef struct {
4377
  char tbFName[TSDB_TABLE_FNAME_LEN];
4378
} STableIndexReq;
4379

4380
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4381
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4382

4383
typedef struct {
4384
  int8_t  intervalUnit;
4385
  int8_t  slidingUnit;
4386
  int64_t interval;
4387
  int64_t offset;
4388
  int64_t sliding;
4389
  int64_t dstTbUid;
4390
  int32_t dstVgId;
4391
  SEpSet  epSet;
4392
  char*   expr;
4393
} STableIndexInfo;
4394

4395
typedef struct {
4396
  char     tbName[TSDB_TABLE_NAME_LEN];
4397
  char     dbFName[TSDB_DB_FNAME_LEN];
4398
  uint64_t suid;
4399
  int32_t  version;
4400
  int32_t  indexSize;
4401
  SArray*  pIndex;  // STableIndexInfo
4402
} STableIndexRsp;
4403

4404
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4405
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4406
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4407

4408
void tFreeSTableIndexInfo(void* pInfo);
4409

4410
typedef struct {
4411
  int8_t  mqMsgType;
4412
  int32_t code;
4413
  int32_t epoch;
4414
  int64_t consumerId;
4415
  int64_t walsver;
4416
  int64_t walever;
4417
} SMqRspHead;
4418

4419
typedef struct {
4420
  SMsgHead     head;
4421
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4422
  int8_t       withTbName;
4423
  int8_t       useSnapshot;
4424
  int32_t      epoch;
4425
  uint64_t     reqId;
4426
  int64_t      consumerId;
4427
  int64_t      timeout;
4428
  STqOffsetVal reqOffset;
4429
  int8_t       enableReplay;
4430
  int8_t       sourceExcluded;
4431
  int8_t       rawData;
4432
  int32_t      minPollRows;
4433
  int8_t       enableBatchMeta;
4434
  SHashObj     *uidHash;  // to find if uid is duplicated
4435
} SMqPollReq;
4436

4437
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4438
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4439
void    tDestroySMqPollReq(SMqPollReq* pReq);
4440

4441
typedef struct {
4442
  int32_t vgId;
4443
  int64_t offset;
4444
  SEpSet  epSet;
4445
} SMqSubVgEp;
4446

4447
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4448
  int32_t tlen = 0;
1,099,670✔
4449
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
1,099,670✔
4450
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
1,099,670✔
4451
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
1,099,670✔
4452
  return tlen;
1,099,670✔
4453
}
4454

4455
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4456
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
633,033!
4457
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
633,033!
4458
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
633,033✔
4459
  return buf;
633,033✔
4460
}
4461

4462
typedef struct {
4463
  char           topic[TSDB_TOPIC_FNAME_LEN];
4464
  char           db[TSDB_DB_FNAME_LEN];
4465
  SArray*        vgs;  // SArray<SMqSubVgEp>
4466
  SSchemaWrapper schema;
4467
} SMqSubTopicEp;
4468

4469
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4470
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4471
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4472

4473
typedef struct {
4474
  SMqRspHead   head;
4475
  STqOffsetVal rspOffset;
4476
  int16_t      resMsgType;
4477
  int32_t      metaRspLen;
4478
  void*        metaRsp;
4479
} SMqMetaRsp;
4480

4481
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4482
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4483
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4484

4485
#define MQ_DATA_RSP_VERSION 100
4486

4487
typedef struct {
4488
  SMqRspHead   head;
4489
  STqOffsetVal rspOffset;
4490
  STqOffsetVal reqOffset;
4491
  int32_t      blockNum;
4492
  int8_t       withTbName;
4493
  int8_t       withSchema;
4494
  SArray*      blockDataLen;
4495
  SArray*      blockData;
4496
  SArray*      blockTbName;
4497
  SArray*      blockSchema;
4498

4499
  union {
4500
    struct {
4501
      int64_t sleepTime;
4502
    };
4503
    struct {
4504
      int32_t createTableNum;
4505
      SArray* createTableLen;
4506
      SArray* createTableReq;
4507
    };
4508
    struct{
4509
      int32_t len;
4510
      void*   rawData;
4511
    };
4512
  };
4513
  void*   data;  //for free in client, only effected if type is data or metadata. raw data not effected
4514
  bool    blockDataElementFree;   // if true, free blockDataElement in blockData,(true in server, false in client)
4515
} SMqDataRsp;
4516

4517
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4518
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4519
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4520
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4521
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4522

4523
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4524
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4525
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4526

4527
typedef struct SMqBatchMetaRsp {
4528
  SMqRspHead   head;  // not serialize
4529
  STqOffsetVal rspOffset;
4530
  SArray*      batchMetaLen;
4531
  SArray*      batchMetaReq;
4532
  void*        pMetaBuff;    // not serialize
4533
  uint32_t     metaBuffLen;  // not serialize
4534
} SMqBatchMetaRsp;
4535

4536
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4537
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4538
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4539
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4540

4541
typedef struct {
4542
  SMqRspHead head;
4543
  char       cgroup[TSDB_CGROUP_LEN];
4544
  SArray*    topics;  // SArray<SMqSubTopicEp>
4545
} SMqAskEpRsp;
4546

4547
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4548
  int32_t tlen = 0;
1,108,272✔
4549
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4550
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,108,272!
4551
  tlen += taosEncodeFixedI32(buf, sz);
1,108,272✔
4552
  for (int32_t i = 0; i < sz; i++) {
2,206,174✔
4553
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,097,902✔
4554
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,097,902✔
4555
  }
4556
  return tlen;
1,108,272✔
4557
}
4558

4559
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4560
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4561
  int32_t sz;
4562
  buf = taosDecodeFixedI32(buf, &sz);
637,250✔
4563
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
637,250✔
4564
  if (pRsp->topics == NULL) {
637,248!
UNCOV
4565
    return NULL;
×
4566
  }
4567
  for (int32_t i = 0; i < sz; i++) {
1,269,398✔
4568
    SMqSubTopicEp topicEp;
4569
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
632,150✔
4570
    if (buf == NULL) {
632,150!
UNCOV
4571
      return NULL;
×
4572
    }
4573
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,264,300!
UNCOV
4574
      return NULL;
×
4575
    }
4576
  }
4577
  return buf;
637,248✔
4578
}
4579

4580
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4581
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
1,194,481✔
4582
}
1,194,481✔
4583

4584
typedef struct {
4585
  int32_t      vgId;
4586
  STqOffsetVal offset;
4587
  int64_t      rows;
4588
  int64_t      ever;
4589
} OffsetRows;
4590

4591
typedef struct {
4592
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4593
  SArray* offsetRows;
4594
} TopicOffsetRows;
4595

4596
typedef struct {
4597
  int64_t consumerId;
4598
  int32_t epoch;
4599
  SArray* topics;
4600
  int8_t  pollFlag;
4601
} SMqHbReq;
4602

4603
typedef struct {
4604
  char   topic[TSDB_TOPIC_FNAME_LEN];
4605
  int8_t noPrivilege;
4606
} STopicPrivilege;
4607

4608
typedef struct {
4609
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4610
  int32_t debugFlag;
4611
} SMqHbRsp;
4612

4613
typedef struct {
4614
  SMsgHead head;
4615
  int64_t  consumerId;
4616
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4617
} SMqSeekReq;
4618

4619
#define TD_AUTO_CREATE_TABLE 0x1
4620
typedef struct {
4621
  int64_t       suid;
4622
  int64_t       uid;
4623
  int32_t       sver;
4624
  uint32_t      nData;
4625
  uint8_t*      pData;
4626
  SVCreateTbReq cTbReq;
4627
} SVSubmitBlk;
4628

4629
typedef struct {
4630
  SMsgHead header;
4631
  uint64_t sId;
4632
  uint64_t queryId;
4633
  uint64_t clientId;
4634
  uint64_t taskId;
4635
  uint32_t sqlLen;
4636
  uint32_t phyLen;
4637
  char*    sql;
4638
  char*    msg;
4639
  int8_t   source;
4640
} SVDeleteReq;
4641

4642
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4643
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4644

4645
typedef struct {
4646
  int64_t affectedRows;
4647
} SVDeleteRsp;
4648

4649
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4650
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4651

4652
typedef struct SDeleteRes {
4653
  uint64_t suid;
4654
  SArray*  uidList;
4655
  int64_t  skey;
4656
  int64_t  ekey;
4657
  int64_t  affectedRows;
4658
  char     tableFName[TSDB_TABLE_NAME_LEN];
4659
  char     tsColName[TSDB_COL_NAME_LEN];
4660
  int64_t  ctimeMs;  // fill by vnode
4661
  int8_t   source;
4662
} SDeleteRes;
4663

4664
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4665
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4666

4667
typedef struct {
4668
  // int64_t uid;
4669
  char    tbname[TSDB_TABLE_NAME_LEN];
4670
  int64_t startTs;
4671
  int64_t endTs;
4672
} SSingleDeleteReq;
4673

4674
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4675
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4676

4677
typedef struct {
4678
  int64_t suid;
4679
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4680
  int64_t ctimeMs;     // fill by vnode
4681
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4682
} SBatchDeleteReq;
4683

4684
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4685
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4686
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4687

4688
typedef struct {
4689
  int32_t msgIdx;
4690
  int32_t msgType;
4691
  int32_t msgLen;
4692
  void*   msg;
4693
} SBatchMsg;
4694

4695
typedef struct {
4696
  SMsgHead header;
4697
  SArray*  pMsgs;  // SArray<SBatchMsg>
4698
} SBatchReq;
4699

4700
typedef struct {
4701
  int32_t reqType;
4702
  int32_t msgIdx;
4703
  int32_t msgLen;
4704
  int32_t rspCode;
4705
  void*   msg;
4706
} SBatchRspMsg;
4707

4708
typedef struct {
4709
  SArray* pRsps;  // SArray<SBatchRspMsg>
4710
} SBatchRsp;
4711

4712
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4713
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4714
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
6,887,921✔
4715
  if (NULL == msg) {
6,887,921!
UNCOV
4716
    return;
×
4717
  }
4718
  SBatchMsg* pMsg = (SBatchMsg*)msg;
6,887,921✔
4719
  taosMemoryFree(pMsg->msg);
6,887,921!
4720
}
4721

4722
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4723
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4724

4725
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,591,231✔
4726
  if (NULL == p) {
1,591,231!
UNCOV
4727
    return;
×
4728
  }
4729

4730
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,591,231✔
4731
  taosMemoryFree(pRsp->msg);
1,591,231!
4732
}
4733

4734
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4735
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4736
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4737
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4738
void    tDestroySMqHbReq(SMqHbReq* pReq);
4739

4740
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4741
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4742
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4743

4744
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4745
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4746

4747
#define TD_REQ_FROM_APP               0x0
4748
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4749
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4750
#define SUBMIT_REQ_FROM_FILE          0x4
4751
#define TD_REQ_FROM_TAOX              0x8
4752
#define SUBMIT_REQUEST_VERSION        (1)
4753

4754
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4755

4756
typedef struct {
4757
  int32_t        flags;
4758
  SVCreateTbReq* pCreateTbReq;
4759
  int64_t        suid;
4760
  int64_t        uid;
4761
  int32_t        sver;
4762
  union {
4763
    SArray* aRowP;
4764
    SArray* aCol;
4765
  };
4766
  int64_t ctimeMs;
4767
} SSubmitTbData;
4768

4769
typedef struct {
4770
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4771
  bool    raw;
4772
} SSubmitReq2;
4773

4774
typedef struct {
4775
  SMsgHead header;
4776
  int64_t  version;
4777
  char     data[];  // SSubmitReq2
4778
} SSubmitReq2Msg;
4779

4780
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4781
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4782
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4783
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4784
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4785

4786
typedef struct {
4787
  int32_t affectedRows;
4788
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4789
} SSubmitRsp2;
4790

4791
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4792
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4793
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4794

4795
#define TSDB_MSG_FLG_ENCODE 0x1
4796
#define TSDB_MSG_FLG_DECODE 0x2
4797
#define TSDB_MSG_FLG_CMPT   0x3
4798

4799
typedef struct {
4800
  union {
4801
    struct {
4802
      void*   msgStr;
4803
      int32_t msgLen;
4804
      int64_t ver;
4805
    };
4806
    void* pDataBlock;
4807
  };
4808
} SPackedData;
4809

4810
typedef struct {
4811
  char     fullname[TSDB_VIEW_FNAME_LEN];
4812
  char     name[TSDB_VIEW_NAME_LEN];
4813
  char     dbFName[TSDB_DB_FNAME_LEN];
4814
  char*    querySql;
4815
  char*    sql;
4816
  int8_t   orReplace;
4817
  int8_t   precision;
4818
  int32_t  numOfCols;
4819
  SSchema* pSchema;
4820
} SCMCreateViewReq;
4821

4822
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4823
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4824
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4825

4826
typedef struct {
4827
  char   fullname[TSDB_VIEW_FNAME_LEN];
4828
  char   name[TSDB_VIEW_NAME_LEN];
4829
  char   dbFName[TSDB_DB_FNAME_LEN];
4830
  char*  sql;
4831
  int8_t igNotExists;
4832
} SCMDropViewReq;
4833

4834
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4835
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4836
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4837

4838
typedef struct {
4839
  char fullname[TSDB_VIEW_FNAME_LEN];
4840
} SViewMetaReq;
4841
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4842
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4843

4844
typedef struct {
4845
  char     name[TSDB_VIEW_NAME_LEN];
4846
  char     dbFName[TSDB_DB_FNAME_LEN];
4847
  char*    user;
4848
  uint64_t dbId;
4849
  uint64_t viewId;
4850
  char*    querySql;
4851
  int8_t   precision;
4852
  int8_t   type;
4853
  int32_t  version;
4854
  int32_t  numOfCols;
4855
  SSchema* pSchema;
4856
} SViewMetaRsp;
4857
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4858
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4859
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4860
typedef struct {
4861
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4862
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4863
} STableTSMAInfoReq;
4864

4865
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4866
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4867

4868
typedef struct {
4869
  int32_t  funcId;
4870
  col_id_t colId;
4871
} STableTSMAFuncInfo;
4872

4873
typedef struct {
4874
  char     name[TSDB_TABLE_NAME_LEN];
4875
  uint64_t tsmaId;
4876
  char     targetTb[TSDB_TABLE_NAME_LEN];
4877
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4878
  char     tb[TSDB_TABLE_NAME_LEN];
4879
  char     dbFName[TSDB_DB_FNAME_LEN];
4880
  uint64_t suid;
4881
  uint64_t destTbUid;
4882
  uint64_t dbId;
4883
  int32_t  version;
4884
  int64_t  interval;
4885
  int8_t   unit;
4886
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4887
  SArray*  pTags;      // SArray<SSchema>
4888
  SArray*  pUsedCols;  // SArray<SSchema>
4889
  char*    ast;
4890

4891
  int64_t streamUid;
4892
  int64_t reqTs;
4893
  int64_t rspTs;
4894
  int64_t delayDuration;  // ms
4895
  bool    fillHistoryFinished;
4896
} STableTSMAInfo;
4897

4898
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4899
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4900
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4901
void    tFreeTableTSMAInfo(void* p);
4902
void    tFreeAndClearTableTSMAInfo(void* p);
4903
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4904

4905
#define STSMAHbRsp            STableTSMAInfoRsp
4906
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4907
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4908
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4909

4910
typedef struct SStreamProgressReq {
4911
  int64_t streamId;
4912
  int32_t vgId;
4913
  int32_t fetchIdx;
4914
  int32_t subFetchIdx;
4915
} SStreamProgressReq;
4916

4917
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4918
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4919

4920
typedef struct SStreamProgressRsp {
4921
  int64_t streamId;
4922
  int32_t vgId;
4923
  bool    fillHisFinished;
4924
  int64_t progressDelay;
4925
  int32_t fetchIdx;
4926
  int32_t subFetchIdx;
4927
} SStreamProgressRsp;
4928

4929
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4930
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4931

4932
typedef struct SDropCtbWithTsmaSingleVgReq {
4933
  SVgroupInfo vgInfo;
4934
  SArray*     pTbs;  // SVDropTbReq
4935
} SMDropTbReqsOnSingleVg;
4936

4937
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4938
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4939
void    tFreeSMDropTbReqOnSingleVg(void* p);
4940

4941
typedef struct SDropTbsReq {
4942
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4943
} SMDropTbsReq;
4944

4945
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4946
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4947
void    tFreeSMDropTbsReq(void*);
4948

4949
typedef struct SVFetchTtlExpiredTbsRsp {
4950
  SArray* pExpiredTbs;  // SVDropTbReq
4951
  int32_t vgId;
4952
} SVFetchTtlExpiredTbsRsp;
4953

4954
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4955
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4956

4957
void tFreeFetchTtlExpiredTbsRsp(void* p);
4958

4959
void setDefaultOptionsForField(SFieldWithOptions* field);
4960
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4961

4962
#pragma pack(pop)
4963

4964
#ifdef __cplusplus
4965
}
4966
#endif
4967

4968
#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