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

taosdata / TDengine / #4066

12 May 2025 05:35AM UTC coverage: 62.547% (+0.04%) from 62.508%
#4066

push

travis-ci

web-flow
Merge pull request #31053 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

155777 of 317858 branches covered (49.01%)

Branch coverage included in aggregate %.

382 of 573 new or added lines in 31 files covered. (66.67%)

648 existing lines in 129 files now uncovered.

241270 of 316936 relevant lines covered (76.13%)

6462449.7 hits per line

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

40.63
/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) {
90,736,643✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
90,736,643✔
74
  int    segIdx = TMSG_SEG_CODE(type);
90,736,643✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
90,736,643✔
76
    return type < tMsgRangeDict[segIdx];
90,746,498✔
77
  }
78
  return false;
2✔
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
2,403,490✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
2,357,725✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
4,761,215!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
8,085,667✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
8,085,667✔
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
  int32_t     rversion;
692
  uint64_t    suid;
693
  uint64_t    tuid;
694
  int32_t     vgId;
695
  int8_t      sysInfo;
696
  SSchema*    pSchemas;
697
  SSchemaExt* pSchemaExt;
698
  int8_t      virtualStb;
699
  int32_t     numOfColRefs;
700
  SColRef*    pColRefs;
701
} STableMetaRsp;
702

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

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

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

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

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

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

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

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

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

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

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

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

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

780
bool hasExtSchema(const SExtSchema* pExtSchema);
781

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

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

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

799

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

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

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

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

837
  return pDstWrapper;
838
}
839

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

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

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

873
  taosMemoryFreeClear(pWrapper->pColCmpr);
874
  taosMemoryFreeClear(pWrapper);
875
}
876
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
877
  if (pSchemaWrapper->pSchema == NULL) return NULL;
3,040,942!
878

879
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
3,040,942!
880
  if (pSW == NULL) {
3,041,618!
881
    return NULL;
×
882
  }
883
  pSW->nCols = pSchemaWrapper->nCols;
3,041,618✔
884
  pSW->version = pSchemaWrapper->version;
3,041,618✔
885
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
3,041,618!
886
  if (pSW->pSchema == NULL) {
3,040,682!
887
    taosMemoryFree(pSW);
×
888
    return NULL;
×
889
  }
890

891
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
3,040,682✔
892
  return pSW;
3,040,682✔
893
}
894

895
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
585,793✔
896
  if (pSchemaWrapper) {
7,540,016!
897
    taosMemoryFree(pSchemaWrapper->pSchema);
3,316,785!
898
    taosMemoryFree(pSchemaWrapper);
3,316,777!
899
  }
900
}
7,422,025✔
901

902
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,037✔
903
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,037!
904
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,038!
905
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,038!
906
  }
907
}
1,037✔
908

909
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
910
  int32_t tlen = 0;
9,298,359✔
911
  tlen += taosEncodeFixedI8(buf, pSchema->type);
18,596,718✔
912
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
9,298,359!
913
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
9,298,359!
914
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
9,298,359!
915
  tlen += taosEncodeString(buf, pSchema->name);
9,298,359✔
916
  return tlen;
9,298,359✔
917
}
918

919
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
920
  buf = taosDecodeFixedI8(buf, &pSchema->type);
9,294,984✔
921
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
4,647,492✔
922
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
4,647,492!
923
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
4,647,492!
924
  buf = taosDecodeStringTo(buf, pSchema->name);
4,647,492✔
925
  return (void*)buf;
4,647,492✔
926
}
927

928
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
929
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
37,741,671!
930
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
60,295,970!
931
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
60,295,970!
932
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
60,295,970!
933
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
60,295,970!
934
  return 0;
30,147,985✔
935
}
936

937
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
938
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
143,909,911!
939
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
278,892,071!
940
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
278,342,332!
941
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
278,304,101!
942
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
139,324,692!
943
  return 0;
139,627,300✔
944
}
945

946
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
947
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
13,245,916!
948
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
13,245,916!
949
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
13,245,916!
950
  return 0;
6,622,958✔
951
}
952

953
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
954
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
7,094,431!
955
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
7,094,430!
956
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
7,094,422!
957
  return 0;
3,547,208✔
958
}
959

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

971
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
972
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
19,108!
973
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
19,108!
974
  if (pColRef->hasRef) {
9,554✔
975
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
5,559!
976
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
5,559!
977
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
5,559!
978
  }
979

980
  return 0;
9,554✔
981
}
982

983
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
984
  int32_t tlen = 0;
1,207,363✔
985
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
1,207,363✔
986
  tlen += taosEncodeVariantI32(buf, pSW->version);
1,207,363✔
987
  for (int32_t i = 0; i < pSW->nCols; i++) {
10,505,722✔
988
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
18,596,718!
989
  }
990
  return tlen;
1,207,363✔
991
}
992

993
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
994
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
603,395✔
995
  buf = taosDecodeVariantI32(buf, &pSW->version);
603,395✔
996
  if (pSW->nCols > 0) {
603,395✔
997
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
387,991!
998
    if (pSW->pSchema == NULL) {
387,991!
999
      return NULL;
×
1000
    }
1001

1002
    for (int32_t i = 0; i < pSW->nCols; i++) {
5,035,483✔
1003
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
9,294,984✔
1004
    }
1005
  } else {
1006
    pSW->pSchema = NULL;
215,404✔
1007
  }
1008
  return (void*)buf;
603,395✔
1009
}
1010

1011
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1012
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
687,473!
1013
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,374,946!
1014
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,374,946!
1015
  for (int32_t i = 0; i < pSW->nCols; i++) {
23,241,772!
1016
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
45,108,598!
1017
  }
1018
  return 0;
687,473✔
1019
}
1020

1021
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1022
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
1,447,942!
1023
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
2,895,929!
1024
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
2,895,863!
1025

1026
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,447,876!
1027
  if (pSW->pSchema == NULL) {
1,448,032!
1028
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1029
  }
1030
  for (int32_t i = 0; i < pSW->nCols; i++) {
17,209,134!
1031
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
31,523,122!
1032
  }
1033

1034
  return 0;
1,447,114✔
1035
}
1036

1037
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1038
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
16,432,041!
1039
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
16,439,204!
1040

1041
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
8,219,797!
1042
  if (pSW->pSchema == NULL) {
8,227,925!
1043
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1044
  }
1045
  for (int32_t i = 0; i < pSW->nCols; i++) {
127,713,369!
1046
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
238,982,195!
1047
  }
1048

1049
  return 0;
8,216,618✔
1050
}
1051

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1258
typedef struct {
1259
  int32_t dnodeId;
1260
  int64_t analVer;
1261
} SRetrieveAnalyticsAlgoReq;
1262

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

1268
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1269
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1270
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1271
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1272
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1273

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1400
typedef struct STbVerInfo {
1401
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1402
  int32_t sversion;
1403
  int32_t tversion;
1404
  int32_t rversion; // virtual table's column ref's version
1405
} STbVerInfo;
1406

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

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

1415
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1416

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

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

1447
typedef STableCfg STableCfgRsp;
1448

1449
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1450
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1451

1452
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1453
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1454
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1455

1456
typedef struct {
1457
  SMsgHead header;
1458
  tb_uid_t suid;
1459
} SVSubTablesReq;
1460

1461
int32_t tSerializeSVSubTablesReq(void *buf, int32_t bufLen, SVSubTablesReq *pReq);
1462
int32_t tDeserializeSVSubTablesReq(void *buf, int32_t bufLen, SVSubTablesReq *pReq);
1463

1464
typedef struct {
1465
  int32_t  vgId;
1466
  SArray*  pTables;   //SArray<SVCTableRefCols*>
1467
} SVSubTablesRsp;
1468

1469
int32_t tSerializeSVSubTablesRsp(void *buf, int32_t bufLen, SVSubTablesRsp *pRsp);
1470
int32_t tDeserializeSVSubTablesRsp(void *buf, int32_t bufLen, SVSubTablesRsp *pRsp);
1471
void tDestroySVSubTablesRsp(void* rsp);
1472

1473
typedef struct {
1474
  SMsgHead header;
1475
  tb_uid_t suid;
1476
} SVStbRefDbsReq;
1477

1478
int32_t tSerializeSVStbRefDbsReq(void *buf, int32_t bufLen, SVStbRefDbsReq *pReq);
1479
int32_t tDeserializeSVStbRefDbsReq(void *buf, int32_t bufLen, SVStbRefDbsReq *pReq);
1480

1481
typedef struct {
1482
  int32_t  vgId;
1483
  SArray*  pDbs;   // SArray<char* (db name)>
1484
} SVStbRefDbsRsp;
1485

1486
int32_t tSerializeSVStbRefDbsRsp(void *buf, int32_t bufLen, SVStbRefDbsRsp *pRsp);
1487
int32_t tDeserializeSVStbRefDbsRsp(void *buf, int32_t bufLen, SVStbRefDbsRsp *pRsp);
1488
void tDestroySVStbRefDbsRsp(void* rsp);
1489

1490
typedef struct {
1491
  char    db[TSDB_DB_FNAME_LEN];
1492
  int32_t numOfVgroups;
1493
  int32_t numOfStables;  // single_stable
1494
  int32_t buffer;        // MB
1495
  int32_t pageSize;
1496
  int32_t pages;
1497
  int32_t cacheLastSize;
1498
  int32_t daysPerFile;
1499
  int32_t daysToKeep0;
1500
  int32_t daysToKeep1;
1501
  int32_t daysToKeep2;
1502
  int32_t keepTimeOffset;
1503
  int32_t minRows;
1504
  int32_t maxRows;
1505
  int32_t walFsyncPeriod;
1506
  int8_t  walLevel;
1507
  int8_t  precision;  // time resolution
1508
  int8_t  compression;
1509
  int8_t  replications;
1510
  int8_t  strict;
1511
  int8_t  cacheLast;
1512
  int8_t  schemaless;
1513
  int8_t  ignoreExist;
1514
  int32_t numOfRetensions;
1515
  SArray* pRetensions;  // SRetention
1516
  int32_t walRetentionPeriod;
1517
  int64_t walRetentionSize;
1518
  int32_t walRollPeriod;
1519
  int64_t walSegmentSize;
1520
  int32_t sstTrigger;
1521
  int16_t hashPrefix;
1522
  int16_t hashSuffix;
1523
  int32_t s3ChunkSize;
1524
  int32_t s3KeepLocal;
1525
  int8_t  s3Compact;
1526
  int32_t tsdbPageSize;
1527
  int32_t sqlLen;
1528
  char*   sql;
1529
  int8_t  withArbitrator;
1530
  int8_t  encryptAlgorithm;
1531
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1532
  // 1. add auto-compact parameters
1533
  int32_t compactInterval;    // minutes
1534
  int32_t compactStartTime;   // minutes
1535
  int32_t compactEndTime;     // minutes
1536
  int8_t  compactTimeOffset;  // hour
1537
} SCreateDbReq;
1538

1539
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1540
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1541
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1542

1543
typedef struct {
1544
  char    db[TSDB_DB_FNAME_LEN];
1545
  int32_t buffer;
1546
  int32_t pageSize;
1547
  int32_t pages;
1548
  int32_t cacheLastSize;
1549
  int32_t daysPerFile;
1550
  int32_t daysToKeep0;
1551
  int32_t daysToKeep1;
1552
  int32_t daysToKeep2;
1553
  int32_t keepTimeOffset;
1554
  int32_t walFsyncPeriod;
1555
  int8_t  walLevel;
1556
  int8_t  strict;
1557
  int8_t  cacheLast;
1558
  int8_t  replications;
1559
  int32_t sstTrigger;
1560
  int32_t minRows;
1561
  int32_t walRetentionPeriod;
1562
  int32_t walRetentionSize;
1563
  int32_t s3KeepLocal;
1564
  int8_t  s3Compact;
1565
  int32_t sqlLen;
1566
  char*   sql;
1567
  int8_t  withArbitrator;
1568
  // 1. add auto-compact parameters
1569
  int32_t compactInterval;
1570
  int32_t compactStartTime;
1571
  int32_t compactEndTime;
1572
  int8_t  compactTimeOffset;
1573
} SAlterDbReq;
1574

1575
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1576
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1577
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1578

1579
typedef struct {
1580
  char    db[TSDB_DB_FNAME_LEN];
1581
  int8_t  ignoreNotExists;
1582
  int32_t sqlLen;
1583
  char*   sql;
1584
} SDropDbReq;
1585

1586
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1587
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1588
void    tFreeSDropDbReq(SDropDbReq* pReq);
1589

1590
typedef struct {
1591
  char    db[TSDB_DB_FNAME_LEN];
1592
  int64_t uid;
1593
} SDropDbRsp;
1594

1595
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1596
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1597

1598
typedef struct {
1599
  char    db[TSDB_DB_FNAME_LEN];
1600
  int64_t dbId;
1601
  int32_t vgVersion;
1602
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1603
  int64_t stateTs;     // ms
1604
} SUseDbReq;
1605

1606
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1607
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1608

1609
typedef struct {
1610
  char    db[TSDB_DB_FNAME_LEN];
1611
  int64_t uid;
1612
  int32_t vgVersion;
1613
  int32_t vgNum;
1614
  int16_t hashPrefix;
1615
  int16_t hashSuffix;
1616
  int8_t  hashMethod;
1617
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1618
  int32_t errCode;
1619
  int64_t stateTs;  // ms
1620
} SUseDbRsp;
1621

1622
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1623
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1624
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1625
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1626
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1627

1628
typedef struct {
1629
  char db[TSDB_DB_FNAME_LEN];
1630
} SDbCfgReq;
1631

1632
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1633
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1634

1635
typedef struct {
1636
  char    db[TSDB_DB_FNAME_LEN];
1637
  int32_t maxSpeed;
1638
} STrimDbReq;
1639

1640
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1641
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1642

1643
typedef struct {
1644
  int32_t timestamp;
1645
} SVTrimDbReq;
1646

1647
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1648
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1649

1650
typedef struct {
1651
  char db[TSDB_DB_FNAME_LEN];
1652
} SS3MigrateDbReq;
1653

1654
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1655
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1656

1657
typedef struct {
1658
  int32_t timestamp;
1659
} SVS3MigrateDbReq;
1660

1661
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1662
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1663

1664
typedef struct {
1665
  int32_t timestampSec;
1666
  int32_t ttlDropMaxCount;
1667
  int32_t nUids;
1668
  SArray* pTbUids;
1669
} SVDropTtlTableReq;
1670

1671
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1672
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1673

1674
typedef struct {
1675
  char    db[TSDB_DB_FNAME_LEN];
1676
  int64_t dbId;
1677
  int32_t cfgVersion;
1678
  int32_t numOfVgroups;
1679
  int32_t numOfStables;
1680
  int32_t buffer;
1681
  int32_t cacheSize;
1682
  int32_t pageSize;
1683
  int32_t pages;
1684
  int32_t daysPerFile;
1685
  int32_t daysToKeep0;
1686
  int32_t daysToKeep1;
1687
  int32_t daysToKeep2;
1688
  int32_t keepTimeOffset;
1689
  int32_t minRows;
1690
  int32_t maxRows;
1691
  int32_t walFsyncPeriod;
1692
  int16_t hashPrefix;
1693
  int16_t hashSuffix;
1694
  int8_t  hashMethod;
1695
  int8_t  walLevel;
1696
  int8_t  precision;
1697
  int8_t  compression;
1698
  int8_t  replications;
1699
  int8_t  strict;
1700
  int8_t  cacheLast;
1701
  int8_t  encryptAlgorithm;
1702
  int32_t s3ChunkSize;
1703
  int32_t s3KeepLocal;
1704
  int8_t  s3Compact;
1705
  int8_t  compactTimeOffset;
1706
  int32_t compactInterval;
1707
  int32_t compactStartTime;
1708
  int32_t compactEndTime;
1709
  int32_t tsdbPageSize;
1710
  int32_t walRetentionPeriod;
1711
  int32_t walRollPeriod;
1712
  int64_t walRetentionSize;
1713
  int64_t walSegmentSize;
1714
  int32_t numOfRetensions;
1715
  SArray* pRetensions;
1716
  int8_t  schemaless;
1717
  int16_t sstTrigger;
1718
  int8_t  withArbitrator;
1719
} SDbCfgRsp;
1720

1721
typedef SDbCfgRsp SDbCfgInfo;
1722

1723
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1724
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1725
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1726
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1727
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1728

1729
typedef struct {
1730
  int32_t rowNum;
1731
} SQnodeListReq;
1732

1733
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1734
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1735

1736
typedef struct {
1737
  int32_t rowNum;
1738
} SDnodeListReq;
1739

1740
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1741

1742
typedef struct {
1743
  int32_t useless;  // useless
1744
} SServerVerReq;
1745

1746
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1747
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1748

1749
typedef struct {
1750
  char ver[TSDB_VERSION_LEN];
1751
} SServerVerRsp;
1752

1753
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1754
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1755

1756
typedef struct SQueryNodeAddr {
1757
  int32_t nodeId;  // vgId or qnodeId
1758
  SEpSet  epSet;
1759
} SQueryNodeAddr;
1760

1761
typedef struct {
1762
  SQueryNodeAddr addr;
1763
  uint64_t       load;
1764
} SQueryNodeLoad;
1765

1766
typedef struct {
1767
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1768
} SQnodeListRsp;
1769

1770
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1771
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1772
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1773

1774
typedef struct SDNodeAddr {
1775
  int32_t nodeId;  // dnodeId
1776
  SEpSet  epSet;
1777
} SDNodeAddr;
1778

1779
typedef struct {
1780
  SArray* dnodeList;  // SArray<SDNodeAddr>
1781
} SDnodeListRsp;
1782

1783
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1784
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1785
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1786

1787
typedef struct {
1788
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1789
} STableTSMAInfoRsp;
1790

1791
typedef struct {
1792
  SUseDbRsp*         useDbRsp;
1793
  SDbCfgRsp*         cfgRsp;
1794
  STableTSMAInfoRsp* pTsmaRsp;
1795
  int32_t            dbTsmaVersion;
1796
  char               db[TSDB_DB_FNAME_LEN];
1797
  int64_t            dbId;
1798
} SDbHbRsp;
1799

1800
typedef struct {
1801
  SArray* pArray;  // Array of SDbHbRsp
1802
} SDbHbBatchRsp;
1803

1804
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1805
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1806
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1807

1808
typedef struct {
1809
  SArray* pArray;  // Array of SGetUserAuthRsp
1810
} SUserAuthBatchRsp;
1811

1812
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1813
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1814
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1815

1816
typedef struct {
1817
  char        db[TSDB_DB_FNAME_LEN];
1818
  STimeWindow timeRange;
1819
  int32_t     sqlLen;
1820
  char*       sql;
1821
  SArray*     vgroupIds;
1822
  int8_t      metaOnly;
1823
} SCompactDbReq;
1824

1825
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1826
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1827
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1828

1829
typedef struct {
1830
  int32_t compactId;
1831
  int8_t  bAccepted;
1832
} SCompactDbRsp;
1833

1834
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1835
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1836

1837
typedef struct {
1838
  int32_t compactId;
1839
  int32_t sqlLen;
1840
  char*   sql;
1841
} SKillCompactReq;
1842

1843
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1844
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1845
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1846

1847
typedef struct {
1848
  char    name[TSDB_FUNC_NAME_LEN];
1849
  int8_t  igExists;
1850
  int8_t  funcType;
1851
  int8_t  scriptType;
1852
  int8_t  outputType;
1853
  int32_t outputLen;
1854
  int32_t bufSize;
1855
  int32_t codeLen;
1856
  int64_t signature;
1857
  char*   pComment;
1858
  char*   pCode;
1859
  int8_t  orReplace;
1860
} SCreateFuncReq;
1861

1862
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1863
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1864
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1865

1866
typedef struct {
1867
  char   name[TSDB_FUNC_NAME_LEN];
1868
  int8_t igNotExists;
1869
} SDropFuncReq;
1870

1871
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1872
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1873

1874
typedef struct {
1875
  int32_t numOfFuncs;
1876
  bool    ignoreCodeComment;
1877
  SArray* pFuncNames;
1878
} SRetrieveFuncReq;
1879

1880
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1881
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1882
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1883

1884
typedef struct {
1885
  char    name[TSDB_FUNC_NAME_LEN];
1886
  int8_t  funcType;
1887
  int8_t  scriptType;
1888
  int8_t  outputType;
1889
  int32_t outputLen;
1890
  int32_t bufSize;
1891
  int64_t signature;
1892
  int32_t commentSize;
1893
  int32_t codeSize;
1894
  char*   pComment;
1895
  char*   pCode;
1896
} SFuncInfo;
1897

1898
typedef struct {
1899
  int32_t funcVersion;
1900
  int64_t funcCreatedTime;
1901
} SFuncExtraInfo;
1902

1903
typedef struct {
1904
  int32_t numOfFuncs;
1905
  SArray* pFuncInfos;
1906
  SArray* pFuncExtraInfos;
1907
} SRetrieveFuncRsp;
1908

1909
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1910
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1911
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1912
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1913

1914
typedef struct {
1915
  int32_t       statusInterval;
1916
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
1917
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
1918
  char          locale[TD_LOCALE_LEN];      // tsLocale
1919
  char          charset[TD_LOCALE_LEN];     // tsCharset
1920
  int8_t        ttlChangeOnWrite;
1921
  int8_t        enableWhiteList;
1922
  int8_t        encryptionKeyStat;
1923
  uint32_t      encryptionKeyChksum;
1924
  SMonitorParas monitorParas;
1925
} SClusterCfg;
1926

1927
typedef struct {
1928
  int32_t openVnodes;
1929
  int32_t dropVnodes;
1930
  int32_t totalVnodes;
1931
  int32_t masterNum;
1932
  int64_t numOfSelectReqs;
1933
  int64_t numOfInsertReqs;
1934
  int64_t numOfInsertSuccessReqs;
1935
  int64_t numOfBatchInsertReqs;
1936
  int64_t numOfBatchInsertSuccessReqs;
1937
  int64_t errors;
1938
} SVnodesStat;
1939

1940
typedef struct {
1941
  int32_t vgId;
1942
  int8_t  syncState;
1943
  int8_t  syncRestore;
1944
  int64_t syncTerm;
1945
  int64_t roleTimeMs;
1946
  int64_t startTimeMs;
1947
  int8_t  syncCanRead;
1948
  int64_t cacheUsage;
1949
  int64_t numOfTables;
1950
  int64_t numOfTimeSeries;
1951
  int64_t totalStorage;
1952
  int64_t compStorage;
1953
  int64_t pointsWritten;
1954
  int64_t numOfSelectReqs;
1955
  int64_t numOfInsertReqs;
1956
  int64_t numOfInsertSuccessReqs;
1957
  int64_t numOfBatchInsertReqs;
1958
  int64_t numOfBatchInsertSuccessReqs;
1959
  int32_t numOfCachedTables;
1960
  int32_t learnerProgress;  // use one reservered
1961
  int64_t syncAppliedIndex;
1962
  int64_t syncCommitIndex;
1963
} SVnodeLoad;
1964

1965
typedef struct {
1966
  int32_t     vgId;
1967
  int64_t     numOfTables;
1968
  int64_t     memSize;
1969
  int64_t     l1Size;
1970
  int64_t     l2Size;
1971
  int64_t     l3Size;
1972
  int64_t     cacheSize;
1973
  int64_t     walSize;
1974
  int64_t     metaSize;
1975
  int64_t     rawDataSize;
1976
  int64_t     s3Size;
1977
  const char* dbname;
1978
} SDbSizeStatisInfo;
1979

1980
typedef struct {
1981
  int32_t vgId;
1982
  int64_t nTimeSeries;
1983
} SVnodeLoadLite;
1984

1985
typedef struct {
1986
  int8_t  syncState;
1987
  int64_t syncTerm;
1988
  int8_t  syncRestore;
1989
  int64_t roleTimeMs;
1990
} SMnodeLoad;
1991

1992
typedef struct {
1993
  int32_t dnodeId;
1994
  int64_t numOfProcessedQuery;
1995
  int64_t numOfProcessedCQuery;
1996
  int64_t numOfProcessedFetch;
1997
  int64_t numOfProcessedDrop;
1998
  int64_t numOfProcessedNotify;
1999
  int64_t numOfProcessedHb;
2000
  int64_t numOfProcessedDelete;
2001
  int64_t cacheDataSize;
2002
  int64_t numOfQueryInQueue;
2003
  int64_t numOfFetchInQueue;
2004
  int64_t timeInQueryQueue;
2005
  int64_t timeInFetchQueue;
2006
} SQnodeLoad;
2007

2008
typedef struct {
2009
  int32_t     sver;      // software version
2010
  int64_t     dnodeVer;  // dnode table version in sdb
2011
  int32_t     dnodeId;
2012
  int64_t     clusterId;
2013
  int64_t     rebootTime;
2014
  int64_t     updateTime;
2015
  float       numOfCores;
2016
  int32_t     numOfSupportVnodes;
2017
  int32_t     numOfDiskCfg;
2018
  int64_t     memTotal;
2019
  int64_t     memAvail;
2020
  char        dnodeEp[TSDB_EP_LEN];
2021
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2022
  SMnodeLoad  mload;
2023
  SQnodeLoad  qload;
2024
  SClusterCfg clusterCfg;
2025
  SArray*     pVloads;  // array of SVnodeLoad
2026
  int32_t     statusSeq;
2027
  int64_t     ipWhiteVer;
2028
  int64_t     analVer;
2029
  int64_t     timestamp;
2030
} SStatusReq;
2031

2032
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2033
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2034
void    tFreeSStatusReq(SStatusReq* pReq);
2035

2036
typedef struct {
2037
  int32_t forceReadConfig;
2038
  int32_t cver;
2039
  SArray* array;
2040
} SConfigReq;
2041

2042
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2043
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2044
void    tFreeSConfigReq(SConfigReq* pReq);
2045

2046
typedef struct {
2047
  int32_t dnodeId;
2048
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2049
} SDnodeInfoReq;
2050

2051
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2052
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2053

2054
typedef enum {
2055
  MONITOR_TYPE_COUNTER = 0,
2056
  MONITOR_TYPE_SLOW_LOG = 1,
2057
} MONITOR_TYPE;
2058

2059
typedef struct {
2060
  int32_t      contLen;
2061
  char*        pCont;
2062
  MONITOR_TYPE type;
2063
} SStatisReq;
2064

2065
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2066
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2067
void    tFreeSStatisReq(SStatisReq* pReq);
2068

2069
typedef struct {
2070
  char    db[TSDB_DB_FNAME_LEN];
2071
  char    table[TSDB_TABLE_NAME_LEN];
2072
  char    operation[AUDIT_OPERATION_LEN];
2073
  int32_t sqlLen;
2074
  char*   pSql;
2075
} SAuditReq;
2076
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2077
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2078
void    tFreeSAuditReq(SAuditReq* pReq);
2079

2080
typedef struct {
2081
  int32_t dnodeId;
2082
  int64_t clusterId;
2083
  SArray* pVloads;
2084
} SNotifyReq;
2085

2086
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2087
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2088
void    tFreeSNotifyReq(SNotifyReq* pReq);
2089

2090
typedef struct {
2091
  int32_t dnodeId;
2092
  int64_t clusterId;
2093
} SDnodeCfg;
2094

2095
typedef struct {
2096
  int32_t id;
2097
  int8_t  isMnode;
2098
  SEp     ep;
2099
} SDnodeEp;
2100

2101
typedef struct {
2102
  int32_t id;
2103
  int8_t  isMnode;
2104
  int8_t  offlineReason;
2105
  SEp     ep;
2106
  char    active[TSDB_ACTIVE_KEY_LEN];
2107
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2108
} SDnodeInfo;
2109

2110
typedef struct {
2111
  int64_t   dnodeVer;
2112
  SDnodeCfg dnodeCfg;
2113
  SArray*   pDnodeEps;  // Array of SDnodeEp
2114
  int32_t   statusSeq;
2115
  int64_t   ipWhiteVer;
2116
  int64_t   analVer;
2117
} SStatusRsp;
2118

2119
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2120
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2121
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2122

2123
typedef struct {
2124
  int32_t forceReadConfig;
2125
  int32_t isConifgVerified;
2126
  int32_t isVersionVerified;
2127
  int32_t cver;
2128
  SArray* array;
2129
} SConfigRsp;
2130

2131
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2132
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2133
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2134

2135
typedef struct {
2136
  int32_t reserved;
2137
} SMTimerReq;
2138

2139
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2140
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2141

2142
typedef struct SOrphanTask {
2143
  int64_t streamId;
2144
  int32_t taskId;
2145
  int32_t nodeId;
2146
} SOrphanTask;
2147

2148
typedef struct SMStreamDropOrphanMsg {
2149
  SArray* pList;  // SArray<SOrphanTask>
2150
} SMStreamDropOrphanMsg;
2151

2152
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2153
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2154
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2155

2156
typedef struct {
2157
  int32_t  id;
2158
  uint16_t port;                 // node sync Port
2159
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2160
} SReplica;
2161

2162
typedef struct {
2163
  int32_t  vgId;
2164
  char     db[TSDB_DB_FNAME_LEN];
2165
  int64_t  dbUid;
2166
  int32_t  vgVersion;
2167
  int32_t  numOfStables;
2168
  int32_t  buffer;
2169
  int32_t  pageSize;
2170
  int32_t  pages;
2171
  int32_t  cacheLastSize;
2172
  int32_t  daysPerFile;
2173
  int32_t  daysToKeep0;
2174
  int32_t  daysToKeep1;
2175
  int32_t  daysToKeep2;
2176
  int32_t  keepTimeOffset;
2177
  int32_t  minRows;
2178
  int32_t  maxRows;
2179
  int32_t  walFsyncPeriod;
2180
  uint32_t hashBegin;
2181
  uint32_t hashEnd;
2182
  int8_t   hashMethod;
2183
  int8_t   walLevel;
2184
  int8_t   precision;
2185
  int8_t   compression;
2186
  int8_t   strict;
2187
  int8_t   cacheLast;
2188
  int8_t   isTsma;
2189
  int8_t   replica;
2190
  int8_t   selfIndex;
2191
  SReplica replicas[TSDB_MAX_REPLICA];
2192
  int32_t  numOfRetensions;
2193
  SArray*  pRetensions;  // SRetention
2194
  void*    pTsma;
2195
  int32_t  walRetentionPeriod;
2196
  int64_t  walRetentionSize;
2197
  int32_t  walRollPeriod;
2198
  int64_t  walSegmentSize;
2199
  int16_t  sstTrigger;
2200
  int16_t  hashPrefix;
2201
  int16_t  hashSuffix;
2202
  int32_t  tsdbPageSize;
2203
  int32_t  s3ChunkSize;
2204
  int32_t  s3KeepLocal;
2205
  int8_t   s3Compact;
2206
  int64_t  reserved[6];
2207
  int8_t   learnerReplica;
2208
  int8_t   learnerSelfIndex;
2209
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2210
  int32_t  changeVersion;
2211
  int8_t   encryptAlgorithm;
2212
} SCreateVnodeReq;
2213

2214
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2215
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2216
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2217

2218
typedef struct {
2219
  int32_t compactId;
2220
  int32_t vgId;
2221
  int32_t dnodeId;
2222
} SQueryCompactProgressReq;
2223

2224
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2225
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2226

2227
typedef struct {
2228
  int32_t compactId;
2229
  int32_t vgId;
2230
  int32_t dnodeId;
2231
  int32_t numberFileset;
2232
  int32_t finished;
2233
  int32_t progress;
2234
  int64_t remainingTime;
2235
} SQueryCompactProgressRsp;
2236

2237
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2238
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2239

2240
typedef struct {
2241
  int32_t vgId;
2242
  int32_t dnodeId;
2243
  int64_t dbUid;
2244
  char    db[TSDB_DB_FNAME_LEN];
2245
  int64_t reserved[8];
2246
} SDropVnodeReq;
2247

2248
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2249
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2250

2251
typedef struct {
2252
  char    colName[TSDB_COL_NAME_LEN];
2253
  char    stb[TSDB_TABLE_FNAME_LEN];
2254
  int64_t stbUid;
2255
  int64_t dbUid;
2256
  int64_t reserved[8];
2257
} SDropIndexReq;
2258

2259
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2260
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2261

2262
typedef struct {
2263
  int64_t     dbUid;
2264
  char        db[TSDB_DB_FNAME_LEN];
2265
  int64_t     compactStartTime;
2266
  STimeWindow tw;
2267
  int32_t     compactId;
2268
  int8_t      metaOnly;
2269
} SCompactVnodeReq;
2270

2271
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2272
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2273

2274
typedef struct {
2275
  int32_t compactId;
2276
  int32_t vgId;
2277
  int32_t dnodeId;
2278
} SVKillCompactReq;
2279

2280
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2281
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2282

2283
typedef struct {
2284
  int32_t vgVersion;
2285
  int32_t buffer;
2286
  int32_t pageSize;
2287
  int32_t pages;
2288
  int32_t cacheLastSize;
2289
  int32_t daysPerFile;
2290
  int32_t daysToKeep0;
2291
  int32_t daysToKeep1;
2292
  int32_t daysToKeep2;
2293
  int32_t keepTimeOffset;
2294
  int32_t walFsyncPeriod;
2295
  int8_t  walLevel;
2296
  int8_t  strict;
2297
  int8_t  cacheLast;
2298
  int64_t reserved[7];
2299
  // 1st modification
2300
  int16_t sttTrigger;
2301
  int32_t minRows;
2302
  // 2nd modification
2303
  int32_t walRetentionPeriod;
2304
  int32_t walRetentionSize;
2305
  int32_t s3KeepLocal;
2306
  int8_t  s3Compact;
2307
} SAlterVnodeConfigReq;
2308

2309
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2310
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2311

2312
typedef struct {
2313
  int32_t  vgId;
2314
  int8_t   strict;
2315
  int8_t   selfIndex;
2316
  int8_t   replica;
2317
  SReplica replicas[TSDB_MAX_REPLICA];
2318
  int64_t  reserved[8];
2319
  int8_t   learnerSelfIndex;
2320
  int8_t   learnerReplica;
2321
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2322
  int32_t  changeVersion;
2323
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2324

2325
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2326
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2327

2328
typedef struct {
2329
  int32_t vgId;
2330
  int8_t  disable;
2331
} SDisableVnodeWriteReq;
2332

2333
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2334
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2335

2336
typedef struct {
2337
  int32_t  srcVgId;
2338
  int32_t  dstVgId;
2339
  uint32_t hashBegin;
2340
  uint32_t hashEnd;
2341
  int32_t  changeVersion;
2342
  int32_t  reserved;
2343
} SAlterVnodeHashRangeReq;
2344

2345
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2346
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2347

2348
#define REQ_OPT_TBNAME 0x0
2349
#define REQ_OPT_TBUID  0x01
2350
typedef struct {
2351
  SMsgHead header;
2352
  char     dbFName[TSDB_DB_FNAME_LEN];
2353
  char     tbName[TSDB_TABLE_NAME_LEN];
2354
  uint8_t  option;
2355
  uint8_t  autoCreateCtb;
2356
} STableInfoReq;
2357

2358
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2359
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2360

2361
typedef struct {
2362
  int8_t  metaClone;  // create local clone of the cached table meta
2363
  int32_t numOfVgroups;
2364
  int32_t numOfTables;
2365
  int32_t numOfUdfs;
2366
  char    tableNames[];
2367
} SMultiTableInfoReq;
2368

2369
// todo refactor
2370
typedef struct SVgroupInfo {
2371
  int32_t  vgId;
2372
  uint32_t hashBegin;
2373
  uint32_t hashEnd;
2374
  SEpSet   epSet;
2375
  union {
2376
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2377
    int32_t taskId;      // used in stream
2378
  };
2379
} SVgroupInfo;
2380

2381
typedef struct {
2382
  int32_t     numOfVgroups;
2383
  SVgroupInfo vgroups[];
2384
} SVgroupsInfo;
2385

2386
typedef struct {
2387
  STableMetaRsp* pMeta;
2388
} SMAlterStbRsp;
2389

2390
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2391
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2392
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2393

2394
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2395
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2396
void    tFreeSTableMetaRsp(void* pRsp);
2397
void    tFreeSTableIndexRsp(void* info);
2398

2399
typedef struct {
2400
  SArray* pMetaRsp;   // Array of STableMetaRsp
2401
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2402
} SSTbHbRsp;
2403

2404
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2405
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2406
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2407

2408
typedef struct {
2409
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2410
} SViewHbRsp;
2411

2412
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2413
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2414
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2415

2416
typedef struct {
2417
  int32_t numOfTables;
2418
  int32_t numOfVgroup;
2419
  int32_t numOfUdf;
2420
  int32_t contLen;
2421
  int8_t  compressed;  // denote if compressed or not
2422
  int32_t rawLen;      // size before compress
2423
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2424
  char    meta[];
2425
} SMultiTableMeta;
2426

2427
typedef struct {
2428
  int32_t dataLen;
2429
  char    name[TSDB_TABLE_FNAME_LEN];
2430
  char*   data;
2431
} STagData;
2432

2433
typedef struct {
2434
  int32_t  opType;
2435
  uint32_t valLen;
2436
  char*    val;
2437
} SShowVariablesReq;
2438

2439
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2440
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2441
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2442

2443
typedef struct {
2444
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2445
  char value[TSDB_CONFIG_PATH_LEN + 1];
2446
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2447
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2448
  char info[TSDB_CONFIG_INFO_LEN + 1];
2449
} SVariablesInfo;
2450

2451
typedef struct {
2452
  SArray* variables;  // SArray<SVariablesInfo>
2453
} SShowVariablesRsp;
2454

2455
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2456
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2457

2458
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2459

2460
/*
2461
 * sql: show tables like '%a_%'
2462
 * payload is the query condition, e.g., '%a_%'
2463
 * payloadLen is the length of payload
2464
 */
2465
typedef struct {
2466
  int32_t type;
2467
  char    db[TSDB_DB_FNAME_LEN];
2468
  int32_t payloadLen;
2469
  char*   payload;
2470
} SShowReq;
2471

2472
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2473
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2474
void tFreeSShowReq(SShowReq* pReq);
2475

2476
typedef struct {
2477
  int64_t       showId;
2478
  STableMetaRsp tableMeta;
2479
} SShowRsp, SVShowTablesRsp;
2480

2481
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2482
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2483
// void    tFreeSShowRsp(SShowRsp* pRsp);
2484

2485
typedef struct {
2486
  char    db[TSDB_DB_FNAME_LEN];
2487
  char    tb[TSDB_TABLE_NAME_LEN];
2488
  char    user[TSDB_USER_LEN];
2489
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2490
  int64_t showId;
2491
  int64_t compactId;  // for compact
2492
  bool    withFull;   // for show users full
2493
} SRetrieveTableReq;
2494

2495
typedef struct SSysTableSchema {
2496
  int8_t   type;
2497
  col_id_t colId;
2498
  int32_t  bytes;
2499
} SSysTableSchema;
2500

2501
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2502
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2503

2504
#define RETRIEVE_TABLE_RSP_VERSION          0
2505
#define RETRIEVE_TABLE_RSP_TMQ_VERSION      1
2506
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION  2
2507

2508
typedef struct {
2509
  int64_t useconds;
2510
  int8_t  completed;  // all results are returned to client
2511
  int8_t  precision;
2512
  int8_t  compressed;
2513
  int8_t  streamBlockType;
2514
  int32_t payloadLen;
2515
  int32_t compLen;
2516
  int32_t numOfBlocks;
2517
  int64_t numOfRows;  // from int32_t change to int64_t
2518
  int64_t numOfCols;
2519
  int64_t skey;
2520
  int64_t ekey;
2521
  int64_t version;                         // for stream
2522
  TSKEY   watermark;                       // for stream
2523
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2524
  char    data[];
2525
} SRetrieveTableRsp;
2526

2527
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2528

2529
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2530
  do {                                          \
2531
    ((int32_t*)(_p))[0] = (_compLen);           \
2532
    ((int32_t*)(_p))[1] = (_fullLen);           \
2533
  } while (0);
2534

2535
typedef struct {
2536
  int64_t version;
2537
  int64_t numOfRows;
2538
  int8_t  compressed;
2539
  int8_t  precision;
2540
  char    data[];
2541
} SRetrieveTableRspForTmq;
2542

2543
typedef struct {
2544
  int64_t handle;
2545
  int64_t useconds;
2546
  int8_t  completed;  // all results are returned to client
2547
  int8_t  precision;
2548
  int8_t  compressed;
2549
  int32_t compLen;
2550
  int32_t numOfRows;
2551
  int32_t fullLen;
2552
  char    data[];
2553
} SRetrieveMetaTableRsp;
2554

2555
typedef struct SExplainExecInfo {
2556
  double   startupCost;
2557
  double   totalCost;
2558
  uint64_t numOfRows;
2559
  uint32_t verboseLen;
2560
  void*    verboseInfo;
2561
} SExplainExecInfo;
2562

2563
typedef struct {
2564
  int32_t           numOfPlans;
2565
  SExplainExecInfo* subplanInfo;
2566
} SExplainRsp;
2567

2568
typedef struct {
2569
  SExplainRsp rsp;
2570
  uint64_t    qId;
2571
  uint64_t    cId;
2572
  uint64_t    tId;
2573
  int64_t     rId;
2574
  int32_t     eId;
2575
} SExplainLocalRsp;
2576

2577
typedef struct STableScanAnalyzeInfo {
2578
  uint64_t totalRows;
2579
  uint64_t totalCheckedRows;
2580
  uint32_t totalBlocks;
2581
  uint32_t loadBlocks;
2582
  uint32_t loadBlockStatis;
2583
  uint32_t skipBlocks;
2584
  uint32_t filterOutBlocks;
2585
  double   elapsedTime;
2586
  double   filterTime;
2587
} STableScanAnalyzeInfo;
2588

2589
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2590
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2591
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2592

2593
typedef struct {
2594
  char    config[TSDB_DNODE_CONFIG_LEN];
2595
  char    value[TSDB_CLUSTER_VALUE_LEN];
2596
  int32_t sqlLen;
2597
  char*   sql;
2598
} SMCfgClusterReq;
2599

2600
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2601
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2602
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2603

2604
typedef struct {
2605
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2606
  int32_t port;
2607
  int32_t sqlLen;
2608
  char*   sql;
2609
} SCreateDnodeReq;
2610

2611
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2612
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2613
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2614

2615
typedef struct {
2616
  int32_t dnodeId;
2617
  char    fqdn[TSDB_FQDN_LEN];
2618
  int32_t port;
2619
  int8_t  force;
2620
  int8_t  unsafe;
2621
  int32_t sqlLen;
2622
  char*   sql;
2623
} SDropDnodeReq;
2624

2625
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2626
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2627
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2628

2629
enum {
2630
  RESTORE_TYPE__ALL = 1,
2631
  RESTORE_TYPE__MNODE,
2632
  RESTORE_TYPE__VNODE,
2633
  RESTORE_TYPE__QNODE,
2634
};
2635

2636
typedef struct {
2637
  int32_t dnodeId;
2638
  int8_t  restoreType;
2639
  int32_t sqlLen;
2640
  char*   sql;
2641
} SRestoreDnodeReq;
2642

2643
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2644
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2645
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2646

2647
typedef struct {
2648
  int32_t dnodeId;
2649
  char    config[TSDB_DNODE_CONFIG_LEN];
2650
  char    value[TSDB_DNODE_VALUE_LEN];
2651
  int32_t sqlLen;
2652
  char*   sql;
2653
} SMCfgDnodeReq;
2654

2655
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2656
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2657
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2658

2659
typedef struct {
2660
  char    config[TSDB_DNODE_CONFIG_LEN];
2661
  char    value[TSDB_DNODE_VALUE_LEN];
2662
  int32_t version;
2663
} SDCfgDnodeReq;
2664

2665
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2666
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2667

2668
typedef struct {
2669
  int32_t dnodeId;
2670
  int32_t sqlLen;
2671
  char*   sql;
2672
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2673
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2674

2675
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2676
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2677
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2678
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2679
typedef struct {
2680
  int8_t   replica;
2681
  SReplica replicas[TSDB_MAX_REPLICA];
2682
  int8_t   learnerReplica;
2683
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2684
  int64_t  lastIndex;
2685
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2686

2687
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2688
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2689

2690
typedef struct {
2691
  int32_t urlLen;
2692
  int32_t sqlLen;
2693
  char*   url;
2694
  char*   sql;
2695
} SMCreateAnodeReq;
2696

2697
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2698
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2699
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2700

2701
typedef struct {
2702
  int32_t anodeId;
2703
  int32_t sqlLen;
2704
  char*   sql;
2705
} SMDropAnodeReq, SMUpdateAnodeReq;
2706

2707
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2708
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2709
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2710
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2711
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2712
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2713

2714
typedef struct {
2715
  int32_t vgId;
2716
  int32_t hbSeq;
2717
} SVArbHbReqMember;
2718

2719
typedef struct {
2720
  int32_t dnodeId;
2721
  char*   arbToken;
2722
  int64_t arbTerm;
2723
  SArray* hbMembers;  // SVArbHbReqMember
2724
} SVArbHeartBeatReq;
2725

2726
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2727
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2728
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2729

2730
typedef struct {
2731
  int32_t vgId;
2732
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2733
  int32_t hbSeq;
2734
} SVArbHbRspMember;
2735

2736
typedef struct {
2737
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2738
  int32_t dnodeId;
2739
  SArray* hbMembers;  // SVArbHbRspMember
2740
} SVArbHeartBeatRsp;
2741

2742
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2743
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2744
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2745

2746
typedef struct {
2747
  char*   arbToken;
2748
  int64_t arbTerm;
2749
  char*   member0Token;
2750
  char*   member1Token;
2751
} SVArbCheckSyncReq;
2752

2753
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2754
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2755
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2756

2757
typedef struct {
2758
  char*   arbToken;
2759
  char*   member0Token;
2760
  char*   member1Token;
2761
  int32_t vgId;
2762
  int32_t errCode;
2763
} SVArbCheckSyncRsp;
2764

2765
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2766
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2767
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2768

2769
typedef struct {
2770
  char*   arbToken;
2771
  int64_t arbTerm;
2772
  char*   memberToken;
2773
  int8_t  force;
2774
} SVArbSetAssignedLeaderReq;
2775

2776
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2777
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2778
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2779

2780
typedef struct {
2781
  char*   arbToken;
2782
  char*   memberToken;
2783
  int32_t vgId;
2784
} SVArbSetAssignedLeaderRsp;
2785

2786
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2787
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2788
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2789

2790
typedef struct {
2791
  int32_t dnodeId;
2792
  char*   token;
2793
} SMArbUpdateGroupMember;
2794

2795
typedef struct {
2796
  int32_t dnodeId;
2797
  char*   token;
2798
  int8_t  acked;
2799
} SMArbUpdateGroupAssigned;
2800

2801
typedef struct {
2802
  int32_t                  vgId;
2803
  int64_t                  dbUid;
2804
  SMArbUpdateGroupMember   members[2];
2805
  int8_t                   isSync;
2806
  int8_t                   assignedAcked;
2807
  SMArbUpdateGroupAssigned assignedLeader;
2808
  int64_t                  version;
2809
  int32_t                  code;
2810
  int64_t                  updateTimeMs;
2811
} SMArbUpdateGroup;
2812

2813
typedef struct {
2814
  SArray* updateArray;  // SMArbUpdateGroup
2815
} SMArbUpdateGroupBatchReq;
2816

2817
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2818
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2819
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2820

2821
typedef struct {
2822
  char queryStrId[TSDB_QUERY_ID_LEN];
2823
} SKillQueryReq;
2824

2825
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2826
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2827

2828
typedef struct {
2829
  uint32_t connId;
2830
} SKillConnReq;
2831

2832
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2833
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2834

2835
typedef struct {
2836
  int32_t transId;
2837
} SKillTransReq;
2838

2839
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2840
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2841

2842
typedef struct {
2843
  int32_t useless;  // useless
2844
  int32_t sqlLen;
2845
  char*   sql;
2846
} SBalanceVgroupReq;
2847

2848
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2849
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2850
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2851

2852
typedef struct {
2853
  int32_t useless;  // useless
2854
  int32_t sqlLen;
2855
  char*   sql;
2856
} SAssignLeaderReq;
2857

2858
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2859
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2860
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
2861
typedef struct {
2862
  int32_t vgId1;
2863
  int32_t vgId2;
2864
} SMergeVgroupReq;
2865

2866
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2867
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2868

2869
typedef struct {
2870
  int32_t vgId;
2871
  int32_t dnodeId1;
2872
  int32_t dnodeId2;
2873
  int32_t dnodeId3;
2874
  int32_t sqlLen;
2875
  char*   sql;
2876
} SRedistributeVgroupReq;
2877

2878
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2879
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2880
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2881

2882
typedef struct {
2883
  int32_t reserved;
2884
  int32_t vgId;
2885
  int32_t sqlLen;
2886
  char*   sql;
2887
  char    db[TSDB_DB_FNAME_LEN];
2888
} SBalanceVgroupLeaderReq;
2889

2890
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2891
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2892
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2893

2894
typedef struct {
2895
  int32_t vgId;
2896
} SForceBecomeFollowerReq;
2897

2898
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2899
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2900

2901
typedef struct {
2902
  int32_t vgId;
2903
} SSplitVgroupReq;
2904

2905
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2906
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2907

2908
typedef struct {
2909
  char user[TSDB_USER_LEN];
2910
  char spi;
2911
  char encrypt;
2912
  char secret[TSDB_PASSWORD_LEN];
2913
  char ckey[TSDB_PASSWORD_LEN];
2914
} SAuthReq, SAuthRsp;
2915

2916
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2917
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2918

2919
typedef struct {
2920
  int32_t statusCode;
2921
  char    details[1024];
2922
} SServerStatusRsp;
2923

2924
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2925
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2926

2927
/**
2928
 * The layout of the query message payload is as following:
2929
 * +--------------------+---------------------------------+
2930
 * |Sql statement       | Physical plan                   |
2931
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2932
 * +--------------------+---------------------------------+
2933
 */
2934
typedef struct SSubQueryMsg {
2935
  SMsgHead header;
2936
  uint64_t sId;
2937
  uint64_t queryId;
2938
  uint64_t clientId;
2939
  uint64_t taskId;
2940
  int64_t  refId;
2941
  int32_t  execId;
2942
  int32_t  msgMask;
2943
  int8_t   taskType;
2944
  int8_t   explain;
2945
  int8_t   needFetch;
2946
  int8_t   compress;
2947
  uint32_t sqlLen;
2948
  char*    sql;
2949
  uint32_t msgLen;
2950
  char*    msg;
2951
} SSubQueryMsg;
2952

2953
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2954
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2955
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2956

2957
typedef struct {
2958
  SMsgHead header;
2959
  uint64_t sId;
2960
  uint64_t queryId;
2961
  uint64_t taskId;
2962
} SSinkDataReq;
2963

2964
typedef struct {
2965
  SMsgHead header;
2966
  uint64_t sId;
2967
  uint64_t queryId;
2968
  uint64_t clientId;
2969
  uint64_t taskId;
2970
  int32_t  execId;
2971
} SQueryContinueReq;
2972

2973
typedef struct {
2974
  SMsgHead header;
2975
  uint64_t sId;
2976
  uint64_t queryId;
2977
  uint64_t taskId;
2978
} SResReadyReq;
2979

2980
typedef struct {
2981
  int32_t code;
2982
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2983
  int32_t sversion;
2984
  int32_t tversion;
2985
} SResReadyRsp;
2986

2987
typedef struct SOperatorParam {
2988
  int32_t opType;
2989
  int32_t downstreamIdx;
2990
  void*   value;
2991
  SArray* pChildren;  // SArray<SOperatorParam*>
2992
  bool    reUse;
2993
} SOperatorParam;
2994

2995
typedef struct SColIdNameKV {
2996
  col_id_t colId;
2997
  char     colName[TSDB_COL_NAME_LEN];
2998
} SColIdNameKV;
2999

3000
typedef struct SColIdPair {
3001
  col_id_t vtbColId;
3002
  col_id_t orgColId;
3003
} SColIdPair;
3004

3005
typedef struct SOrgTbInfo {
3006
  int32_t   vgId;
3007
  char      tbName[TSDB_TABLE_FNAME_LEN];
3008
  SArray*   colMap;  // SArray<SColIdNameKV>
3009
} SOrgTbInfo;
3010

3011
typedef struct STableScanOperatorParam {
3012
  bool           tableSeq;
3013
  SArray*        pUidList;
3014
  SOrgTbInfo*    pOrgTbInfo;
3015
  STimeWindow    window;
3016
} STableScanOperatorParam;
3017

3018
typedef struct SVTableScanOperatorParam {
3019
  uint64_t       uid;
3020
  SArray*        pOpParamArray;  // SArray<SOperatorParam>
3021
} SVTableScanOperatorParam;
3022

3023
typedef struct {
3024
  SMsgHead        header;
3025
  uint64_t        sId;
3026
  uint64_t        queryId;
3027
  uint64_t        clientId;
3028
  uint64_t        taskId;
3029
  int32_t         execId;
3030
  SOperatorParam* pOpParam;
3031
} SResFetchReq;
3032

3033
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3034
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3035

3036
typedef struct {
3037
  SMsgHead header;
3038
  uint64_t clientId;
3039
} SSchTasksStatusReq;
3040

3041
typedef struct {
3042
  uint64_t queryId;
3043
  uint64_t clientId;
3044
  uint64_t taskId;
3045
  int64_t  refId;
3046
  int32_t  execId;
3047
  int8_t   status;
3048
} STaskStatus;
3049

3050
typedef struct {
3051
  int64_t refId;
3052
  SArray* taskStatus;  // SArray<STaskStatus>
3053
} SSchedulerStatusRsp;
3054

3055
typedef struct {
3056
  uint64_t queryId;
3057
  uint64_t taskId;
3058
  int8_t   action;
3059
} STaskAction;
3060

3061
typedef struct SQueryNodeEpId {
3062
  int32_t nodeId;  // vgId or qnodeId
3063
  SEp     ep;
3064
} SQueryNodeEpId;
3065

3066
typedef struct {
3067
  SMsgHead       header;
3068
  uint64_t       clientId;
3069
  SQueryNodeEpId epId;
3070
  SArray*        taskAction;  // SArray<STaskAction>
3071
} SSchedulerHbReq;
3072

3073
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3074
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3075
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3076

3077
typedef struct {
3078
  SQueryNodeEpId epId;
3079
  SArray*        taskStatus;  // SArray<STaskStatus>
3080
} SSchedulerHbRsp;
3081

3082
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3083
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3084
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3085

3086
typedef struct {
3087
  SMsgHead header;
3088
  uint64_t sId;
3089
  uint64_t queryId;
3090
  uint64_t clientId;
3091
  uint64_t taskId;
3092
  int64_t  refId;
3093
  int32_t  execId;
3094
} STaskCancelReq;
3095

3096
typedef struct {
3097
  int32_t code;
3098
} STaskCancelRsp;
3099

3100
typedef struct {
3101
  SMsgHead header;
3102
  uint64_t sId;
3103
  uint64_t queryId;
3104
  uint64_t clientId;
3105
  uint64_t taskId;
3106
  int64_t  refId;
3107
  int32_t  execId;
3108
} STaskDropReq;
3109

3110
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3111
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3112

3113
typedef enum {
3114
  TASK_NOTIFY_FINISHED = 1,
3115
} ETaskNotifyType;
3116

3117
typedef struct {
3118
  SMsgHead        header;
3119
  uint64_t        sId;
3120
  uint64_t        queryId;
3121
  uint64_t        clientId;
3122
  uint64_t        taskId;
3123
  int64_t         refId;
3124
  int32_t         execId;
3125
  ETaskNotifyType type;
3126
} STaskNotifyReq;
3127

3128
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3129
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3130

3131
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3132
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3133

3134
typedef struct {
3135
  int32_t code;
3136
} STaskDropRsp;
3137

3138
#define STREAM_TRIGGER_AT_ONCE                 1
3139
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3140
#define STREAM_TRIGGER_MAX_DELAY               3
3141
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3142
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3143

3144
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3145
#define STREAM_FILL_HISTORY_ON        1
3146
#define STREAM_FILL_HISTORY_OFF       0
3147
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3148
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3149
#define STREAM_CREATE_STABLE_TRUE     1
3150
#define STREAM_CREATE_STABLE_FALSE    0
3151

3152
typedef struct SColLocation {
3153
  int16_t  slotId;
3154
  col_id_t colId;
3155
  int8_t   type;
3156
} SColLocation;
3157

3158
typedef struct SVgroupVer {
3159
  int32_t vgId;
3160
  int64_t ver;
3161
} SVgroupVer;
3162

3163
typedef struct {
3164
  char    name[TSDB_STREAM_FNAME_LEN];
3165
  char    sourceDB[TSDB_DB_FNAME_LEN];
3166
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
3167
  char*   sql;
3168
  char*   ast;
3169
  int8_t  igExists;
3170
  int8_t  triggerType;
3171
  int8_t  igExpired;
3172
  int8_t  fillHistory;  // process data inserted before creating stream
3173
  int64_t maxDelay;
3174
  int64_t watermark;
3175
  int32_t numOfTags;
3176
  SArray* pTags;  // array of SField
3177
  // 3.0.20
3178
  int64_t checkpointFreq;  // ms
3179
  // 3.0.2.3
3180
  int8_t   createStb;
3181
  uint64_t targetStbUid;
3182
  SArray*  fillNullCols;  // array of SColLocation
3183
  int64_t  deleteMark;
3184
  int8_t   igUpdate;
3185
  int64_t  lastTs;
3186
  SArray*  pVgroupVerList;
3187
  // 3.3.0.0
3188
  SArray* pCols;  // array of SField
3189
  int64_t smaId;
3190
  // 3.3.6.0
3191
  SArray* pNotifyAddrUrls;
3192
  int32_t notifyEventTypes;
3193
  int32_t notifyErrorHandle;
3194
  int8_t  notifyHistory;
3195
  int64_t recalculateInterval;
3196
  char    pWstartName[TSDB_COL_NAME_LEN];
3197
  char    pWendName[TSDB_COL_NAME_LEN];
3198
  char    pGroupIdName[TSDB_COL_NAME_LEN];
3199
  char    pIsWindowFilledName[TSDB_COL_NAME_LEN];
3200
  SArray* pVSubTables; // array of SVSubTablesRsp
3201
} SCMCreateStreamReq;
3202

3203
typedef struct STaskNotifyEventStat {
3204
  int64_t notifyEventAddTimes;     // call times of add function
3205
  int64_t notifyEventAddElems;     // elements added by add function
3206
  double  notifyEventAddCostSec;   // time cost of add function
3207
  int64_t notifyEventPushTimes;    // call times of push function
3208
  int64_t notifyEventPushElems;    // elements pushed by push function
3209
  double  notifyEventPushCostSec;  // time cost of push function
3210
  int64_t notifyEventPackTimes;    // call times of pack function
3211
  int64_t notifyEventPackElems;    // elements packed by pack function
3212
  double  notifyEventPackCostSec;  // time cost of pack function
3213
  int64_t notifyEventSendTimes;    // call times of send function
3214
  int64_t notifyEventSendElems;    // elements sent by send function
3215
  double  notifyEventSendCostSec;  // time cost of send function
3216
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3217
} STaskNotifyEventStat;
3218

3219
typedef struct {
3220
  int64_t streamId;
3221
} SCMCreateStreamRsp;
3222

3223
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3224
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3225
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3226

3227
enum {
3228
  TOPIC_SUB_TYPE__DB = 1,
3229
  TOPIC_SUB_TYPE__TABLE,
3230
  TOPIC_SUB_TYPE__COLUMN,
3231
};
3232

3233
#define DEFAULT_MAX_POLL_INTERVAL  300000
3234
#define DEFAULT_SESSION_TIMEOUT    12000
3235
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3236
#define DEFAULT_MIN_POLL_ROWS      4096
3237

3238
typedef struct {
3239
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3240
  int8_t igExists;
3241
  int8_t subType;
3242
  int8_t withMeta;
3243
  char*  sql;
3244
  char   subDbName[TSDB_DB_FNAME_LEN];
3245
  char*  ast;
3246
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3247
} SCMCreateTopicReq;
3248

3249
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3250
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3251
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3252

3253
typedef struct {
3254
  int64_t consumerId;
3255
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3256

3257
typedef struct {
3258
  int64_t consumerId;
3259
  char    cgroup[TSDB_CGROUP_LEN];
3260
  char    clientId[TSDB_CLIENT_ID_LEN];
3261
  char    user[TSDB_USER_LEN];
3262
  char    fqdn[TSDB_FQDN_LEN];
3263
  SArray* topicNames;  // SArray<char**>
3264

3265
  int8_t  withTbName;
3266
  int8_t  autoCommit;
3267
  int32_t autoCommitInterval;
3268
  int8_t  resetOffsetCfg;
3269
  int8_t  enableReplay;
3270
  int8_t  enableBatchMeta;
3271
  int32_t sessionTimeoutMs;
3272
  int32_t maxPollIntervalMs;
3273
} SCMSubscribeReq;
3274

3275
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3276
  int32_t tlen = 0;
2,482✔
3277
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,482!
3278
  tlen += taosEncodeString(buf, pReq->cgroup);
2,482✔
3279
  tlen += taosEncodeString(buf, pReq->clientId);
2,482✔
3280

3281
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,482!
3282
  tlen += taosEncodeFixedI32(buf, topicNum);
2,482✔
3283

3284
  for (int32_t i = 0; i < topicNum; i++) {
3,516✔
3285
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,068✔
3286
  }
3287

3288
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,482!
3289
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,482!
3290
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,482!
3291
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,482!
3292
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,482!
3293
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,482!
3294
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,482!
3295
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,482!
3296
  tlen += taosEncodeString(buf, pReq->user);
2,482✔
3297
  tlen += taosEncodeString(buf, pReq->fqdn);
2,482✔
3298

3299
  return tlen;
2,482✔
3300
}
3301

3302
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3303
  void* start = buf;
1,315✔
3304
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,315!
3305
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,315✔
3306
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,315✔
3307

3308
  int32_t topicNum = 0;
1,315!
3309
  buf = taosDecodeFixedI32(buf, &topicNum);
1,315✔
3310

3311
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,315✔
3312
  if (pReq->topicNames == NULL) {
1,315!
3313
    return terrno;
×
3314
  }
3315
  for (int32_t i = 0; i < topicNum; i++) {
1,922✔
3316
    char* name = NULL;
607✔
3317
    buf = taosDecodeString(buf, &name);
607✔
3318
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,214!
3319
      return terrno;
×
3320
    }
3321
  }
3322

3323
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,315✔
3324
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,315✔
3325
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,315!
3326
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,315✔
3327
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,315✔
3328
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,315✔
3329
  if ((char*)buf - (char*)start < len) {
1,315!
3330
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,315!
3331
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,315!
3332
    buf = taosDecodeStringTo(buf, pReq->user);
1,315✔
3333
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,630✔
3334
  } else {
3335
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3336
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3337
  }
3338

3339
  return 0;
1,315✔
3340
}
3341

3342
typedef struct {
3343
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3344
  SArray* removedConsumers;  // SArray<int64_t>
3345
  SArray* newConsumers;      // SArray<int64_t>
3346
} SMqRebInfo;
3347

3348
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3349
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,281!
3350
  if (pRebInfo == NULL) {
1,281!
3351
    return NULL;
×
3352
  }
3353
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,281✔
3354
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,281✔
3355
  if (pRebInfo->removedConsumers == NULL) {
1,281!
3356
    goto _err;
×
3357
  }
3358
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,281✔
3359
  if (pRebInfo->newConsumers == NULL) {
1,281!
3360
    goto _err;
×
3361
  }
3362
  return pRebInfo;
1,281✔
3363
_err:
×
3364
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3365
  taosArrayDestroy(pRebInfo->newConsumers);
×
3366
  taosMemoryFreeClear(pRebInfo);
×
3367
  return NULL;
×
3368
}
3369

3370
typedef struct {
3371
  int64_t streamId;
3372
  int64_t checkpointId;
3373
  char    streamName[TSDB_STREAM_FNAME_LEN];
3374
} SMStreamDoCheckpointMsg;
3375

3376
typedef struct {
3377
  int64_t status;
3378
} SMVSubscribeRsp;
3379

3380
typedef struct {
3381
  char    name[TSDB_TOPIC_FNAME_LEN];
3382
  int8_t  igNotExists;
3383
  int32_t sqlLen;
3384
  char*   sql;
3385
  int8_t  force;
3386
} SMDropTopicReq;
3387

3388
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3389
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3390
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3391

3392
typedef struct {
3393
  char   topic[TSDB_TOPIC_FNAME_LEN];
3394
  char   cgroup[TSDB_CGROUP_LEN];
3395
  int8_t igNotExists;
3396
  int8_t force;
3397
} SMDropCgroupReq;
3398

3399
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3400
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3401

3402
typedef struct {
3403
  int8_t reserved;
3404
} SMDropCgroupRsp;
3405

3406
typedef struct {
3407
  char    name[TSDB_TABLE_FNAME_LEN];
3408
  int8_t  alterType;
3409
  SSchema schema;
3410
} SAlterTopicReq;
3411

3412
typedef struct {
3413
  SMsgHead head;
3414
  char     name[TSDB_TABLE_FNAME_LEN];
3415
  int64_t  tuid;
3416
  int32_t  sverson;
3417
  int32_t  execLen;
3418
  char*    executor;
3419
  int32_t  sqlLen;
3420
  char*    sql;
3421
} SDCreateTopicReq;
3422

3423
typedef struct {
3424
  SMsgHead head;
3425
  char     name[TSDB_TABLE_FNAME_LEN];
3426
  int64_t  tuid;
3427
} SDDropTopicReq;
3428

3429
typedef struct {
3430
  int64_t maxdelay[2];
3431
  int64_t watermark[2];
3432
  int64_t deleteMark[2];
3433
  int32_t qmsgLen[2];
3434
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3435
} SRSmaParam;
3436

3437
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3438
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3439

3440
// TDMT_VND_CREATE_STB ==============
3441
typedef struct SVCreateStbReq {
3442
  char*           name;
3443
  tb_uid_t        suid;
3444
  int8_t          rollup;
3445
  SSchemaWrapper  schemaRow;
3446
  SSchemaWrapper  schemaTag;
3447
  SRSmaParam      rsmaParam;
3448
  int32_t         alterOriDataLen;
3449
  void*           alterOriData;
3450
  int8_t          source;
3451
  int8_t          colCmpred;
3452
  SColCmprWrapper colCmpr;
3453
  int64_t         keep;
3454
  SExtSchema*     pExtSchemas;
3455
  int8_t          virtualStb;
3456
} SVCreateStbReq;
3457

3458
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3459
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3460

3461
// TDMT_VND_DROP_STB ==============
3462
typedef struct SVDropStbReq {
3463
  char*    name;
3464
  tb_uid_t suid;
3465
} SVDropStbReq;
3466

3467
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3468
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3469

3470
// TDMT_VND_CREATE_TABLE ==============
3471
#define TD_CREATE_IF_NOT_EXISTS 0x1
3472
typedef struct SVCreateTbReq {
3473
  int32_t  flags;
3474
  char*    name;
3475
  tb_uid_t uid;
3476
  int64_t  btime;
3477
  int32_t  ttl;
3478
  int32_t  commentLen;
3479
  char*    comment;
3480
  int8_t   type;
3481
  union {
3482
    struct {
3483
      char*    stbName;  // super table name
3484
      uint8_t  tagNum;
3485
      tb_uid_t suid;
3486
      SArray*  tagName;
3487
      uint8_t* pTag;
3488
    } ctb;
3489
    struct {
3490
      SSchemaWrapper schemaRow;
3491
    } ntb;
3492
  };
3493
  int32_t         sqlLen;
3494
  char*           sql;
3495
  SColCmprWrapper colCmpr;
3496
  SExtSchema*     pExtSchemas;
3497
  SColRefWrapper  colRef; // col reference for virtual table
3498
} SVCreateTbReq;
3499

3500
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3501
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3502
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3503

3504
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
2,461✔
3505
  if (NULL == req) {
6,156,852!
3506
    return;
5,881,798✔
3507
  }
3508

3509
  taosMemoryFreeClear(req->sql);
275,054!
3510
  taosMemoryFreeClear(req->name);
275,054!
3511
  taosMemoryFreeClear(req->comment);
275,105!
3512
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
275,105!
3513
    taosMemoryFreeClear(req->ctb.pTag);
260,740!
3514
    taosMemoryFreeClear(req->ctb.stbName);
260,808!
3515
    taosArrayDestroy(req->ctb.tagName);
260,833✔
3516
    req->ctb.tagName = NULL;
260,805✔
3517
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,365!
3518
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
14,365!
3519
  }
3520
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
275,170!
3521
  taosMemoryFreeClear(req->pExtSchemas);
275,170!
3522
  taosMemoryFreeClear(req->colRef.pColRef);
275,170!
3523
}
3524

3525
typedef struct {
3526
  int32_t nReqs;
3527
  union {
3528
    SVCreateTbReq* pReqs;
3529
    SArray*        pArray;
3530
  };
3531
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3532
} SVCreateTbBatchReq;
3533

3534
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3535
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3536
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3537

3538
typedef struct {
3539
  int32_t        code;
3540
  STableMetaRsp* pMeta;
3541
} SVCreateTbRsp, SVUpdateTbRsp;
3542

3543
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3544
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3545
void tFreeSVCreateTbRsp(void* param);
3546

3547
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3548
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3549

3550
typedef struct {
3551
  int32_t nRsps;
3552
  union {
3553
    SVCreateTbRsp* pRsps;
3554
    SArray*        pArray;
3555
  };
3556
} SVCreateTbBatchRsp;
3557

3558
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3559
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3560

3561
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3562
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3563

3564
// TDMT_VND_DROP_TABLE =================
3565
typedef struct {
3566
  char*    name;
3567
  uint64_t suid;  // for tmq in wal format
3568
  int64_t  uid;
3569
  int8_t   igNotExists;
3570
  int8_t   isVirtual;
3571
} SVDropTbReq;
3572

3573
typedef struct {
3574
  int32_t code;
3575
} SVDropTbRsp;
3576

3577
typedef struct {
3578
  int32_t nReqs;
3579
  union {
3580
    SVDropTbReq* pReqs;
3581
    SArray*      pArray;
3582
  };
3583
} SVDropTbBatchReq;
3584

3585
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3586
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3587

3588
typedef struct {
3589
  int32_t nRsps;
3590
  union {
3591
    SVDropTbRsp* pRsps;
3592
    SArray*      pArray;
3593
  };
3594
} SVDropTbBatchRsp;
3595

3596
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3597
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3598

3599
// TDMT_VND_ALTER_TABLE =====================
3600
typedef struct SMultiTagUpateVal {
3601
  char*    tagName;
3602
  int32_t  colId;
3603
  int8_t   tagType;
3604
  int8_t   tagFree;
3605
  uint32_t nTagVal;
3606
  uint8_t* pTagVal;
3607
  int8_t   isNull;
3608
  SArray*  pTagArray;
3609
} SMultiTagUpateVal;
3610
typedef struct SVAlterTbReq{
3611
  char*   tbName;
3612
  int8_t  action;
3613
  char*   colName;
3614
  int32_t colId;
3615
  // TSDB_ALTER_TABLE_ADD_COLUMN
3616
  int8_t  type;
3617
  int8_t  flags;
3618
  int32_t bytes;
3619
  // TSDB_ALTER_TABLE_DROP_COLUMN
3620
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3621
  int8_t   colModType;
3622
  int32_t  colModBytes;
3623
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3624
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3625
  int8_t   isNull;
3626
  int8_t   tagType;
3627
  int8_t   tagFree;
3628
  uint32_t nTagVal;
3629
  uint8_t* pTagVal;
3630
  SArray*  pTagArray;
3631
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3632
  int8_t   updateTTL;
3633
  int32_t  newTTL;
3634
  int32_t  newCommentLen;
3635
  char*    newComment;
3636
  int64_t  ctimeMs;    // fill by vnode
3637
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3638
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3639
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3640
  // for Add column
3641
  STypeMod typeMod;
3642
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3643
  char*    refDbName;
3644
  char*    refTbName;
3645
  char*    refColName;
3646
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
3647
} SVAlterTbReq;
3648

3649
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3650
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3651
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3652
void    tfreeMultiTagUpateVal(void* pMultiTag);
3653

3654
typedef struct {
3655
  int32_t        code;
3656
  STableMetaRsp* pMeta;
3657
} SVAlterTbRsp;
3658

3659
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3660
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3661
// ======================
3662

3663
typedef struct {
3664
  SMsgHead head;
3665
  int64_t  uid;
3666
  int32_t  tid;
3667
  int16_t  tversion;
3668
  int16_t  colId;
3669
  int8_t   type;
3670
  int16_t  bytes;
3671
  int32_t  tagValLen;
3672
  int16_t  numOfTags;
3673
  int32_t  schemaLen;
3674
  char     data[];
3675
} SUpdateTagValReq;
3676

3677
typedef struct {
3678
  SMsgHead head;
3679
} SUpdateTagValRsp;
3680

3681
typedef struct {
3682
  SMsgHead head;
3683
} SVShowTablesReq;
3684

3685
typedef struct {
3686
  SMsgHead head;
3687
  int32_t  id;
3688
} SVShowTablesFetchReq;
3689

3690
typedef struct {
3691
  int64_t useconds;
3692
  int8_t  completed;  // all results are returned to client
3693
  int8_t  precision;
3694
  int8_t  compressed;
3695
  int32_t compLen;
3696
  int32_t numOfRows;
3697
  char    data[];
3698
} SVShowTablesFetchRsp;
3699

3700
typedef struct {
3701
  int64_t consumerId;
3702
  int32_t epoch;
3703
  char    cgroup[TSDB_CGROUP_LEN];
3704
} SMqAskEpReq;
3705

3706
typedef struct {
3707
  int32_t key;
3708
  int32_t valueLen;
3709
  void*   value;
3710
} SKv;
3711

3712
typedef struct {
3713
  int64_t tscRid;
3714
  int8_t  connType;
3715
} SClientHbKey;
3716

3717
typedef struct {
3718
  int64_t tid;
3719
  char    status[TSDB_JOB_STATUS_LEN];
3720
} SQuerySubDesc;
3721

3722
typedef struct {
3723
  char     sql[TSDB_SHOW_SQL_LEN];
3724
  uint64_t queryId;
3725
  int64_t  useconds;
3726
  int64_t  stime;  // timestamp precision ms
3727
  int64_t  reqRid;
3728
  bool     stableQuery;
3729
  bool     isSubQuery;
3730
  char     fqdn[TSDB_FQDN_LEN];
3731
  int32_t  subPlanNum;
3732
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3733
} SQueryDesc;
3734

3735
typedef struct {
3736
  uint32_t connId;
3737
  SArray*  queryDesc;  // SArray<SQueryDesc>
3738
} SQueryHbReqBasic;
3739

3740
typedef struct {
3741
  uint32_t connId;
3742
  uint64_t killRid;
3743
  int32_t  totalDnodes;
3744
  int32_t  onlineDnodes;
3745
  int8_t   killConnection;
3746
  int8_t   align[3];
3747
  SEpSet   epSet;
3748
  SArray*  pQnodeList;
3749
} SQueryHbRspBasic;
3750

3751
typedef struct SAppClusterSummary {
3752
  uint64_t numOfInsertsReq;
3753
  uint64_t numOfInsertRows;
3754
  uint64_t insertElapsedTime;
3755
  uint64_t insertBytes;  // submit to tsdb since launched.
3756

3757
  uint64_t fetchBytes;
3758
  uint64_t numOfQueryReq;
3759
  uint64_t queryElapsedTime;
3760
  uint64_t numOfSlowQueries;
3761
  uint64_t totalRequests;
3762
  uint64_t currentRequests;  // the number of SRequestObj
3763
} SAppClusterSummary;
3764

3765
typedef struct {
3766
  int64_t            appId;
3767
  int32_t            pid;
3768
  char               name[TSDB_APP_NAME_LEN];
3769
  int64_t            startTime;
3770
  SAppClusterSummary summary;
3771
} SAppHbReq;
3772

3773
typedef struct {
3774
  SClientHbKey      connKey;
3775
  int64_t           clusterId;
3776
  SAppHbReq         app;
3777
  SQueryHbReqBasic* query;
3778
  SHashObj*         info;  // hash<Skv.key, Skv>
3779
  char              userApp[TSDB_APP_NAME_LEN];
3780
  uint32_t          userIp;
3781
} SClientHbReq;
3782

3783
typedef struct {
3784
  int64_t reqId;
3785
  SArray* reqs;  // SArray<SClientHbReq>
3786
  int64_t ipWhiteList;
3787
} SClientHbBatchReq;
3788

3789
typedef struct {
3790
  SClientHbKey      connKey;
3791
  int32_t           status;
3792
  SQueryHbRspBasic* query;
3793
  SArray*           info;  // Array<Skv>
3794
} SClientHbRsp;
3795

3796
typedef struct {
3797
  int64_t       reqId;
3798
  int64_t       rspId;
3799
  int32_t       svrTimestamp;
3800
  SArray*       rsps;  // SArray<SClientHbRsp>
3801
  SMonitorParas monitorParas;
3802
  int8_t        enableAuditDelete;
3803
  int8_t        enableStrongPass;
3804
} SClientHbBatchRsp;
3805

3806
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
232,599✔
3807

3808
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3809
  void* pIter = taosHashIterate(info, NULL);
107,188✔
3810
  while (pIter != NULL) {
218,081!
3811
    SKv* kv = (SKv*)pIter;
110,894✔
3812
    taosMemoryFreeClear(kv->value);
110,894!
3813
    pIter = taosHashIterate(info, pIter);
110,894✔
3814
  }
3815
}
107,187✔
3816

3817
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
63,805✔
3818
  SQueryDesc* desc = (SQueryDesc*)pDesc;
63,805✔
3819
  if (desc->subDesc) {
63,805✔
3820
    taosArrayDestroy(desc->subDesc);
56,287✔
3821
    desc->subDesc = NULL;
56,287✔
3822
  }
3823
}
63,805✔
3824

3825
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
150,199✔
3826
  SClientHbReq* req = (SClientHbReq*)pReq;
178,396✔
3827
  if (req->query) {
178,396!
3828
    if (req->query->queryDesc) {
139,152!
3829
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
45,670✔
3830
    }
3831
    taosMemoryFreeClear(req->query);
139,152!
3832
  }
3833

3834
  if (req->info) {
178,396!
3835
    tFreeReqKvHash(req->info);
107,188✔
3836
    taosHashCleanup(req->info);
107,187✔
3837
    req->info = NULL;
107,188✔
3838
  }
3839
}
96,312✔
3840

3841
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3842
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3843

3844
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3845
  if (pReq == NULL) return;
49,601!
3846
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
49,601✔
3847
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
49,601✔
3848
  taosMemoryFree(pReq);
49,601!
3849
}
3850

3851
static FORCE_INLINE void tFreeClientKv(void* pKv) {
43,334✔
3852
  SKv* kv = (SKv*)pKv;
43,334✔
3853
  if (kv) {
43,334!
3854
    taosMemoryFreeClear(kv->value);
43,334!
3855
  }
3856
}
43,334✔
3857

3858
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
147,028✔
3859
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
147,028✔
3860
  if (rsp->query) {
147,028✔
3861
    taosArrayDestroy(rsp->query->pQnodeList);
136,036✔
3862
    taosMemoryFreeClear(rsp->query);
136,035!
3863
  }
3864
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
147,027!
3865
}
78,916✔
3866

3867
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3868
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
89,764✔
3869
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
89,764✔
3870
}
89,766✔
3871

3872
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3873
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3874
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3875

3876
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3877
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
322,802!
3878
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
322,802!
3879
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
322,802!
3880
  return 0;
161,401✔
3881
}
3882

3883
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3884
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
147,050!
3885
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
147,050!
3886
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
73,525!
3887
  if (pKv->value == NULL) {
73,526!
3888
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3889
  }
3890
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
73,526!
3891
  return 0;
73,526✔
3892
}
3893

3894
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3895
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
600,790!
3896
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
600,790!
3897
  return 0;
300,395✔
3898
}
3899

3900
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3901
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
294,055!
3902
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
294,060!
3903
  return 0;
147,030✔
3904
}
3905

3906
typedef struct {
3907
  int32_t vgId;
3908
  // TODO stas
3909
} SMqReportVgInfo;
3910

3911
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3912
  int32_t tlen = 0;
3913
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3914
  return tlen;
3915
}
3916

3917
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3918
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3919
  return buf;
3920
}
3921

3922
typedef struct {
3923
  int32_t epoch;
3924
  int64_t topicUid;
3925
  char    name[TSDB_TOPIC_FNAME_LEN];
3926
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3927
} SMqTopicInfo;
3928

3929
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3930
  int32_t tlen = 0;
3931
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3932
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3933
  tlen += taosEncodeString(buf, pTopicInfo->name);
3934
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3935
  tlen += taosEncodeFixedI32(buf, sz);
3936
  for (int32_t i = 0; i < sz; i++) {
3937
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3938
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3939
  }
3940
  return tlen;
3941
}
3942

3943
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3944
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3945
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3946
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3947
  int32_t sz;
3948
  buf = taosDecodeFixedI32(buf, &sz);
3949
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3950
    return NULL;
3951
  }
3952
  for (int32_t i = 0; i < sz; i++) {
3953
    SMqReportVgInfo vgInfo;
3954
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3955
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3956
      return NULL;
3957
    }
3958
  }
3959
  return buf;
3960
}
3961

3962
typedef struct {
3963
  int32_t status;  // ask hb endpoint
3964
  int32_t epoch;
3965
  int64_t consumerId;
3966
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3967
} SMqReportReq;
3968

3969
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3970
  int32_t tlen = 0;
3971
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3972
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3973
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3974
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3975
  tlen += taosEncodeFixedI32(buf, sz);
3976
  for (int32_t i = 0; i < sz; i++) {
3977
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3978
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3979
  }
3980
  return tlen;
3981
}
3982

3983
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3984
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3985
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3986
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3987
  int32_t sz;
3988
  buf = taosDecodeFixedI32(buf, &sz);
3989
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3990
    return NULL;
3991
  }
3992
  for (int32_t i = 0; i < sz; i++) {
3993
    SMqTopicInfo topicInfo;
3994
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3995
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3996
      return NULL;
3997
    }
3998
  }
3999
  return buf;
4000
}
4001

4002
typedef struct {
4003
  SMsgHead head;
4004
  int64_t  leftForVer;
4005
  int32_t  vgId;
4006
  int64_t  consumerId;
4007
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4008
} SMqVDeleteReq;
4009

4010
typedef struct {
4011
  int8_t reserved;
4012
} SMqVDeleteRsp;
4013

4014
typedef struct {
4015
  char    name[TSDB_STREAM_FNAME_LEN];
4016
  int8_t  igNotExists;
4017
  int32_t sqlLen;
4018
  char*   sql;
4019
} SMDropStreamReq;
4020

4021
typedef struct {
4022
  int8_t reserved;
4023
} SMDropStreamRsp;
4024

4025
typedef struct {
4026
  SMsgHead head;
4027
  int64_t  resetRelHalt;  // reset related stream task halt status
4028
  int64_t  streamId;
4029
  int32_t  taskId;
4030
} SVDropStreamTaskReq;
4031

4032
typedef struct {
4033
  int8_t reserved;
4034
} SVDropStreamTaskRsp;
4035

4036
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4037
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4038
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4039

4040
typedef struct SVUpdateCheckpointInfoReq {
4041
  SMsgHead head;
4042
  int64_t  streamId;
4043
  int32_t  taskId;
4044
  int64_t  checkpointId;
4045
  int64_t  checkpointVer;
4046
  int64_t  checkpointTs;
4047
  int32_t  transId;
4048
  int64_t  hStreamId;  // add encode/decode
4049
  int64_t  hTaskId;
4050
  int8_t   dropRelHTask;
4051
} SVUpdateCheckpointInfoReq;
4052

4053
typedef struct {
4054
  int64_t leftForVer;
4055
  int32_t vgId;
4056
  int64_t oldConsumerId;
4057
  int64_t newConsumerId;
4058
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4059
  int8_t  subType;
4060
  int8_t  withMeta;
4061
  char*   qmsg;  // SubPlanToString
4062
  int64_t suid;
4063
} SMqRebVgReq;
4064

4065
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4066
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4067

4068
typedef struct {
4069
  char    topic[TSDB_TOPIC_FNAME_LEN];
4070
  int64_t ntbUid;
4071
  SArray* colIdList;  // SArray<int16_t>
4072
} STqCheckInfo;
4073

4074
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4075
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4076
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4077

4078
// tqOffset
4079
enum {
4080
  TMQ_OFFSET__RESET_NONE = -3,
4081
  TMQ_OFFSET__RESET_EARLIEST = -2,
4082
  TMQ_OFFSET__RESET_LATEST = -1,
4083
  TMQ_OFFSET__LOG = 1,
4084
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4085
  TMQ_OFFSET__SNAPSHOT_META = 3,
4086
};
4087

4088
enum {
4089
  WITH_DATA = 0,
4090
  WITH_META = 1,
4091
  ONLY_META = 2,
4092
};
4093

4094
#define TQ_OFFSET_VERSION 1
4095

4096
typedef struct {
4097
  int8_t type;
4098
  union {
4099
    // snapshot
4100
    struct {
4101
      int64_t uid;
4102
      int64_t ts;
4103
      SValue  primaryKey;
4104
    };
4105
    // log
4106
    struct {
4107
      int64_t version;
4108
    };
4109
  };
4110
} STqOffsetVal;
4111

4112
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4113
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
242,820✔
4114
  pOffsetVal->uid = uid;
242,820✔
4115
  pOffsetVal->ts = ts;
242,820✔
4116
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
242,820!
UNCOV
4117
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4118
  }
4119
  pOffsetVal->primaryKey = primaryKey;
242,854✔
4120
}
242,854✔
4121

4122
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4123
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
148✔
4124
  pOffsetVal->uid = uid;
148✔
4125
}
148✔
4126

4127
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4128
  pOffsetVal->type = TMQ_OFFSET__LOG;
3,655,027✔
4129
  pOffsetVal->version = ver;
3,655,027✔
4130
}
3,655,027✔
4131

4132
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4133
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4134
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4135
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4136
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4137
void    tOffsetDestroy(void* pVal);
4138

4139
typedef struct {
4140
  STqOffsetVal val;
4141
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4142
} STqOffset;
4143

4144
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4145
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4146
void    tDeleteSTqOffset(void* val);
4147

4148
typedef struct SMqVgOffset {
4149
  int64_t   consumerId;
4150
  STqOffset offset;
4151
} SMqVgOffset;
4152

4153
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4154
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4155

4156
typedef struct {
4157
  SMsgHead head;
4158
  int64_t  streamId;
4159
  int32_t  taskId;
4160
} SVPauseStreamTaskReq;
4161

4162
typedef struct {
4163
  SMsgHead head;
4164
  int64_t  streamId;
4165
  int32_t  taskId;
4166
  int64_t  chkptId;
4167
} SVResetStreamTaskReq;
4168

4169
typedef struct {
4170
  char   name[TSDB_STREAM_FNAME_LEN];
4171
  int8_t igNotExists;
4172
} SMPauseStreamReq;
4173

4174
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4175
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4176

4177
typedef struct {
4178
  SMsgHead head;
4179
  int32_t  taskId;
4180
  int64_t  streamId;
4181
  int8_t   igUntreated;
4182
} SVResumeStreamTaskReq;
4183

4184
typedef struct {
4185
  int8_t reserved;
4186
} SVResumeStreamTaskRsp;
4187

4188
typedef struct {
4189
  char   name[TSDB_STREAM_FNAME_LEN];
4190
  int8_t igNotExists;
4191
  int8_t igUntreated;
4192
} SMResumeStreamReq;
4193

4194
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4195
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4196

4197
typedef struct {
4198
  char   name[TSDB_STREAM_FNAME_LEN];
4199
  int8_t igNotExists;
4200
  int8_t igUntreated;
4201
} SMResetStreamReq;
4202

4203
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
4204
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
4205

4206
typedef struct {
4207
  char    name[TSDB_TABLE_FNAME_LEN];
4208
  char    stb[TSDB_TABLE_FNAME_LEN];
4209
  int8_t  igExists;
4210
  int8_t  intervalUnit;
4211
  int8_t  slidingUnit;
4212
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4213
  int32_t dstVgId;   // for stream
4214
  int64_t interval;
4215
  int64_t offset;
4216
  int64_t sliding;
4217
  int64_t maxDelay;
4218
  int64_t watermark;
4219
  int32_t exprLen;        // strlen + 1
4220
  int32_t tagsFilterLen;  // strlen + 1
4221
  int32_t sqlLen;         // strlen + 1
4222
  int32_t astLen;         // strlen + 1
4223
  char*   expr;
4224
  char*   tagsFilter;
4225
  char*   sql;
4226
  char*   ast;
4227
  int64_t deleteMark;
4228
  int64_t lastTs;
4229
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4230
  SArray* pVgroupVerList;
4231
  int8_t  recursiveTsma;
4232
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4233
} SMCreateSmaReq;
4234

4235
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4236
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4237
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4238

4239
typedef struct {
4240
  char   name[TSDB_TABLE_FNAME_LEN];
4241
  int8_t igNotExists;
4242
} SMDropSmaReq;
4243

4244
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4245
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4246

4247
typedef struct {
4248
  char   dbFName[TSDB_DB_FNAME_LEN];
4249
  char   stbName[TSDB_TABLE_NAME_LEN];
4250
  char   colName[TSDB_COL_NAME_LEN];
4251
  char   idxName[TSDB_INDEX_FNAME_LEN];
4252
  int8_t idxType;
4253
} SCreateTagIndexReq;
4254

4255
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4256
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4257

4258
typedef SMDropSmaReq SDropTagIndexReq;
4259

4260
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4261
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4262

4263
typedef struct {
4264
  int8_t         version;       // for compatibility(default 0)
4265
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4266
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4267
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4268
  int32_t        dstVgId;
4269
  char           indexName[TSDB_INDEX_NAME_LEN];
4270
  int32_t        exprLen;
4271
  int32_t        tagsFilterLen;
4272
  int64_t        indexUid;
4273
  tb_uid_t       tableUid;  // super/child/common table uid
4274
  tb_uid_t       dstTbUid;  // for dstVgroup
4275
  int64_t        interval;
4276
  int64_t        offset;  // use unit by precision of DB
4277
  int64_t        sliding;
4278
  char*          dstTbName;  // for dstVgroup
4279
  char*          expr;       // sma expression
4280
  char*          tagsFilter;
4281
  SSchemaWrapper schemaRow;  // for dstVgroup
4282
  SSchemaWrapper schemaTag;  // for dstVgroup
4283
} STSma;                     // Time-range-wise SMA
4284

4285
typedef STSma SVCreateTSmaReq;
4286

4287
typedef struct {
4288
  int8_t  type;  // 0 status report, 1 update data
4289
  int64_t indexUid;
4290
  int64_t skey;  // start TS key of interval/sliding window
4291
} STSmaMsg;
4292

4293
typedef struct {
4294
  int64_t indexUid;
4295
  char    indexName[TSDB_INDEX_NAME_LEN];
4296
} SVDropTSmaReq;
4297

4298
typedef struct {
4299
  int tmp;  // TODO: to avoid compile error
4300
} SVCreateTSmaRsp, SVDropTSmaRsp;
4301

4302
#if 0
4303
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4304
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4305
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4306
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4307
#endif
4308

4309
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4310
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4311
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4312
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4313

4314
typedef struct {
4315
  int32_t number;
4316
  STSma*  tSma;
4317
} STSmaWrapper;
4318

4319
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4320
  if (pSma) {
×
4321
    taosMemoryFreeClear(pSma->dstTbName);
×
4322
    taosMemoryFreeClear(pSma->expr);
×
4323
    taosMemoryFreeClear(pSma->tagsFilter);
×
4324
  }
4325
}
×
4326

4327
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4328
  if (pSW) {
×
4329
    if (pSW->tSma) {
×
4330
      if (deepCopy) {
×
4331
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4332
          tDestroyTSma(pSW->tSma + i);
×
4333
        }
4334
      }
4335
      taosMemoryFreeClear(pSW->tSma);
×
4336
    }
4337
  }
4338
}
×
4339

4340
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4341
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4342
  taosMemoryFreeClear(pSW);
×
4343
  return NULL;
×
4344
}
4345

4346
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4347
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4348

4349
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4350
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4351

4352
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4353
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4354
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4355
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4356
  }
4357
  return 0;
×
4358
}
4359

4360
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4361
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4362
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4363
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4364
  }
4365
  return 0;
×
4366
}
4367

4368
typedef struct {
4369
  int idx;
4370
} SMCreateFullTextReq;
4371

4372
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4373
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4374
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4375

4376
typedef struct {
4377
  char   name[TSDB_TABLE_FNAME_LEN];
4378
  int8_t igNotExists;
4379
} SMDropFullTextReq;
4380

4381
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4382
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4383

4384
typedef struct {
4385
  char indexFName[TSDB_INDEX_FNAME_LEN];
4386
} SUserIndexReq;
4387

4388
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4389
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4390

4391
typedef struct {
4392
  char dbFName[TSDB_DB_FNAME_LEN];
4393
  char tblFName[TSDB_TABLE_FNAME_LEN];
4394
  char colName[TSDB_COL_NAME_LEN];
4395
  char indexType[TSDB_INDEX_TYPE_LEN];
4396
  char indexExts[TSDB_INDEX_EXTS_LEN];
4397
} SUserIndexRsp;
4398

4399
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4400
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4401

4402
typedef struct {
4403
  char tbFName[TSDB_TABLE_FNAME_LEN];
4404
} STableIndexReq;
4405

4406
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4407
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4408

4409
typedef struct {
4410
  int8_t  intervalUnit;
4411
  int8_t  slidingUnit;
4412
  int64_t interval;
4413
  int64_t offset;
4414
  int64_t sliding;
4415
  int64_t dstTbUid;
4416
  int32_t dstVgId;
4417
  SEpSet  epSet;
4418
  char*   expr;
4419
} STableIndexInfo;
4420

4421
typedef struct {
4422
  char     tbName[TSDB_TABLE_NAME_LEN];
4423
  char     dbFName[TSDB_DB_FNAME_LEN];
4424
  uint64_t suid;
4425
  int32_t  version;
4426
  int32_t  indexSize;
4427
  SArray*  pIndex;  // STableIndexInfo
4428
} STableIndexRsp;
4429

4430
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4431
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4432
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4433

4434
void tFreeSTableIndexInfo(void* pInfo);
4435

4436
typedef struct {
4437
  int8_t  mqMsgType;
4438
  int32_t code;
4439
  int32_t epoch;
4440
  int64_t consumerId;
4441
  int64_t walsver;
4442
  int64_t walever;
4443
} SMqRspHead;
4444

4445
typedef struct {
4446
  SMsgHead     head;
4447
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4448
  int8_t       withTbName;
4449
  int8_t       useSnapshot;
4450
  int32_t      epoch;
4451
  uint64_t     reqId;
4452
  int64_t      consumerId;
4453
  int64_t      timeout;
4454
  STqOffsetVal reqOffset;
4455
  int8_t       enableReplay;
4456
  int8_t       sourceExcluded;
4457
  int8_t       rawData;
4458
  int32_t      minPollRows;
4459
  int8_t       enableBatchMeta;
4460
  SHashObj     *uidHash;  // to find if uid is duplicated
4461
} SMqPollReq;
4462

4463
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4464
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4465
void    tDestroySMqPollReq(SMqPollReq* pReq);
4466

4467
typedef struct {
4468
  int32_t vgId;
4469
  int64_t offset;
4470
  SEpSet  epSet;
4471
} SMqSubVgEp;
4472

4473
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4474
  int32_t tlen = 0;
1,207,236✔
4475
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
1,207,236✔
4476
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
1,207,236✔
4477
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
1,207,236✔
4478
  return tlen;
1,207,237✔
4479
}
4480

4481
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4482
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
603,543!
4483
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
603,543!
4484
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
603,543✔
4485
  return buf;
603,543✔
4486
}
4487

4488
typedef struct {
4489
  char           topic[TSDB_TOPIC_FNAME_LEN];
4490
  char           db[TSDB_DB_FNAME_LEN];
4491
  SArray*        vgs;  // SArray<SMqSubVgEp>
4492
  SSchemaWrapper schema;
4493
} SMqSubTopicEp;
4494

4495
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4496
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4497
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4498

4499
typedef struct {
4500
  SMqRspHead   head;
4501
  STqOffsetVal rspOffset;
4502
  int16_t      resMsgType;
4503
  int32_t      metaRspLen;
4504
  void*        metaRsp;
4505
} SMqMetaRsp;
4506

4507
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4508
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4509
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4510

4511
#define MQ_DATA_RSP_VERSION 100
4512

4513
typedef struct {
4514
  SMqRspHead   head;
4515
  STqOffsetVal rspOffset;
4516
  STqOffsetVal reqOffset;
4517
  int32_t      blockNum;
4518
  int8_t       withTbName;
4519
  int8_t       withSchema;
4520
  SArray*      blockDataLen;
4521
  SArray*      blockData;
4522
  SArray*      blockTbName;
4523
  SArray*      blockSchema;
4524

4525
  union {
4526
    struct {
4527
      int64_t sleepTime;
4528
    };
4529
    struct {
4530
      int32_t createTableNum;
4531
      SArray* createTableLen;
4532
      SArray* createTableReq;
4533
    };
4534
    struct{
4535
      int32_t len;
4536
      void*   rawData;
4537
    };
4538
  };
4539
  void*   data;  //for free in client, only effected if type is data or metadata. raw data not effected
4540
  bool    blockDataElementFree;   // if true, free blockDataElement in blockData,(true in server, false in client)
4541
} SMqDataRsp;
4542

4543
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4544
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4545
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4546
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4547
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4548

4549
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4550
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4551
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4552

4553
typedef struct SMqBatchMetaRsp {
4554
  SMqRspHead   head;  // not serialize
4555
  STqOffsetVal rspOffset;
4556
  SArray*      batchMetaLen;
4557
  SArray*      batchMetaReq;
4558
  void*        pMetaBuff;    // not serialize
4559
  uint32_t     metaBuffLen;  // not serialize
4560
} SMqBatchMetaRsp;
4561

4562
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4563
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4564
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4565
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4566

4567
typedef struct {
4568
  SMqRspHead head;
4569
  char       cgroup[TSDB_CGROUP_LEN];
4570
  SArray*    topics;  // SArray<SMqSubTopicEp>
4571
} SMqAskEpRsp;
4572

4573
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4574
  int32_t tlen = 0;
1,215,772✔
4575
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4576
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,215,772!
4577
  tlen += taosEncodeFixedI32(buf, sz);
1,215,772✔
4578
  for (int32_t i = 0; i < sz; i++) {
2,421,284✔
4579
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,205,512✔
4580
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,205,512✔
4581
  }
4582
  return tlen;
1,215,772✔
4583
}
4584

4585
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4586
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4587
  int32_t sz;
4588
  buf = taosDecodeFixedI32(buf, &sz);
607,460✔
4589
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
607,460✔
4590
  if (pRsp->topics == NULL) {
607,459!
4591
    return NULL;
×
4592
  }
4593
  for (int32_t i = 0; i < sz; i++) {
1,210,128✔
4594
    SMqSubTopicEp topicEp;
4595
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
602,668✔
4596
    if (buf == NULL) {
602,669!
4597
      return NULL;
×
4598
    }
4599
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,205,338!
4600
      return NULL;
×
4601
    }
4602
  }
4603
  return buf;
607,460✔
4604
}
4605

4606
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4607
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
1,218,288✔
4608
}
1,218,288✔
4609

4610
typedef struct {
4611
  int32_t      vgId;
4612
  STqOffsetVal offset;
4613
  int64_t      rows;
4614
  int64_t      ever;
4615
} OffsetRows;
4616

4617
typedef struct {
4618
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4619
  SArray* offsetRows;
4620
} TopicOffsetRows;
4621

4622
typedef struct {
4623
  int64_t consumerId;
4624
  int32_t epoch;
4625
  SArray* topics;
4626
  int8_t  pollFlag;
4627
} SMqHbReq;
4628

4629
typedef struct {
4630
  char   topic[TSDB_TOPIC_FNAME_LEN];
4631
  int8_t noPrivilege;
4632
} STopicPrivilege;
4633

4634
typedef struct {
4635
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4636
  int32_t debugFlag;
4637
} SMqHbRsp;
4638

4639
typedef struct {
4640
  SMsgHead head;
4641
  int64_t  consumerId;
4642
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4643
} SMqSeekReq;
4644

4645
#define TD_AUTO_CREATE_TABLE 0x1
4646
typedef struct {
4647
  int64_t       suid;
4648
  int64_t       uid;
4649
  int32_t       sver;
4650
  uint32_t      nData;
4651
  uint8_t*      pData;
4652
  SVCreateTbReq cTbReq;
4653
} SVSubmitBlk;
4654

4655
typedef struct {
4656
  SMsgHead header;
4657
  uint64_t sId;
4658
  uint64_t queryId;
4659
  uint64_t clientId;
4660
  uint64_t taskId;
4661
  uint32_t sqlLen;
4662
  uint32_t phyLen;
4663
  char*    sql;
4664
  char*    msg;
4665
  int8_t   source;
4666
} SVDeleteReq;
4667

4668
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4669
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4670

4671
typedef struct {
4672
  int64_t affectedRows;
4673
} SVDeleteRsp;
4674

4675
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4676
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4677

4678
typedef struct SDeleteRes {
4679
  uint64_t suid;
4680
  SArray*  uidList;
4681
  int64_t  skey;
4682
  int64_t  ekey;
4683
  int64_t  affectedRows;
4684
  char     tableFName[TSDB_TABLE_NAME_LEN];
4685
  char     tsColName[TSDB_COL_NAME_LEN];
4686
  int64_t  ctimeMs;  // fill by vnode
4687
  int8_t   source;
4688
} SDeleteRes;
4689

4690
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4691
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4692

4693
typedef struct {
4694
  // int64_t uid;
4695
  char    tbname[TSDB_TABLE_NAME_LEN];
4696
  int64_t startTs;
4697
  int64_t endTs;
4698
} SSingleDeleteReq;
4699

4700
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4701
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4702

4703
typedef struct {
4704
  int64_t suid;
4705
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4706
  int64_t ctimeMs;     // fill by vnode
4707
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4708
} SBatchDeleteReq;
4709

4710
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4711
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4712
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4713

4714
typedef struct {
4715
  int32_t msgIdx;
4716
  int32_t msgType;
4717
  int32_t msgLen;
4718
  void*   msg;
4719
} SBatchMsg;
4720

4721
typedef struct {
4722
  SMsgHead header;
4723
  SArray*  pMsgs;  // SArray<SBatchMsg>
4724
} SBatchReq;
4725

4726
typedef struct {
4727
  int32_t reqType;
4728
  int32_t msgIdx;
4729
  int32_t msgLen;
4730
  int32_t rspCode;
4731
  void*   msg;
4732
} SBatchRspMsg;
4733

4734
typedef struct {
4735
  SArray* pRsps;  // SArray<SBatchRspMsg>
4736
} SBatchRsp;
4737

4738
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4739
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4740
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
369,107✔
4741
  if (NULL == msg) {
369,107!
4742
    return;
×
4743
  }
4744
  SBatchMsg* pMsg = (SBatchMsg*)msg;
369,107✔
4745
  taosMemoryFree(pMsg->msg);
369,107!
4746
}
4747

4748
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4749
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4750

4751
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
502,454✔
4752
  if (NULL == p) {
502,454!
4753
    return;
×
4754
  }
4755

4756
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
502,454✔
4757
  taosMemoryFree(pRsp->msg);
502,454!
4758
}
4759

4760
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4761
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4762
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4763
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4764
void    tDestroySMqHbReq(SMqHbReq* pReq);
4765

4766
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4767
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4768
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4769

4770
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4771
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4772

4773
#define TD_REQ_FROM_APP               0x0
4774
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4775
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4776
#define SUBMIT_REQ_FROM_FILE          0x4
4777
#define TD_REQ_FROM_TAOX              0x8
4778
#define SUBMIT_REQUEST_VERSION        (1)
4779

4780
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4781

4782
typedef struct {
4783
  int32_t        flags;
4784
  SVCreateTbReq* pCreateTbReq;
4785
  int64_t        suid;
4786
  int64_t        uid;
4787
  int32_t        sver;
4788
  union {
4789
    SArray* aRowP;
4790
    SArray* aCol;
4791
  };
4792
  int64_t ctimeMs;
4793
} SSubmitTbData;
4794

4795
typedef struct {
4796
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4797
  bool    raw;
4798
} SSubmitReq2;
4799

4800
typedef struct {
4801
  SMsgHead header;
4802
  int64_t  version;
4803
  char     data[];  // SSubmitReq2
4804
} SSubmitReq2Msg;
4805

4806
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4807
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4808
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4809
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4810
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4811

4812
typedef struct {
4813
  int32_t affectedRows;
4814
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4815
} SSubmitRsp2;
4816

4817
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4818
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4819
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4820

4821
#define TSDB_MSG_FLG_ENCODE 0x1
4822
#define TSDB_MSG_FLG_DECODE 0x2
4823
#define TSDB_MSG_FLG_CMPT   0x3
4824

4825
typedef struct {
4826
  union {
4827
    struct {
4828
      void*   msgStr;
4829
      int32_t msgLen;
4830
      int64_t ver;
4831
    };
4832
    void* pDataBlock;
4833
  };
4834
} SPackedData;
4835

4836
typedef struct {
4837
  char     fullname[TSDB_VIEW_FNAME_LEN];
4838
  char     name[TSDB_VIEW_NAME_LEN];
4839
  char     dbFName[TSDB_DB_FNAME_LEN];
4840
  char*    querySql;
4841
  char*    sql;
4842
  int8_t   orReplace;
4843
  int8_t   precision;
4844
  int32_t  numOfCols;
4845
  SSchema* pSchema;
4846
} SCMCreateViewReq;
4847

4848
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4849
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4850
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4851

4852
typedef struct {
4853
  char   fullname[TSDB_VIEW_FNAME_LEN];
4854
  char   name[TSDB_VIEW_NAME_LEN];
4855
  char   dbFName[TSDB_DB_FNAME_LEN];
4856
  char*  sql;
4857
  int8_t igNotExists;
4858
} SCMDropViewReq;
4859

4860
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4861
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4862
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4863

4864
typedef struct {
4865
  char fullname[TSDB_VIEW_FNAME_LEN];
4866
} SViewMetaReq;
4867
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4868
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4869

4870
typedef struct {
4871
  char     name[TSDB_VIEW_NAME_LEN];
4872
  char     dbFName[TSDB_DB_FNAME_LEN];
4873
  char*    user;
4874
  uint64_t dbId;
4875
  uint64_t viewId;
4876
  char*    querySql;
4877
  int8_t   precision;
4878
  int8_t   type;
4879
  int32_t  version;
4880
  int32_t  numOfCols;
4881
  SSchema* pSchema;
4882
} SViewMetaRsp;
4883
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4884
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4885
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4886
typedef struct {
4887
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4888
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4889
} STableTSMAInfoReq;
4890

4891
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4892
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4893

4894
typedef struct {
4895
  int32_t  funcId;
4896
  col_id_t colId;
4897
} STableTSMAFuncInfo;
4898

4899
typedef struct {
4900
  char     name[TSDB_TABLE_NAME_LEN];
4901
  uint64_t tsmaId;
4902
  char     targetTb[TSDB_TABLE_NAME_LEN];
4903
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4904
  char     tb[TSDB_TABLE_NAME_LEN];
4905
  char     dbFName[TSDB_DB_FNAME_LEN];
4906
  uint64_t suid;
4907
  uint64_t destTbUid;
4908
  uint64_t dbId;
4909
  int32_t  version;
4910
  int64_t  interval;
4911
  int8_t   unit;
4912
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4913
  SArray*  pTags;      // SArray<SSchema>
4914
  SArray*  pUsedCols;  // SArray<SSchema>
4915
  char*    ast;
4916

4917
  int64_t streamUid;
4918
  int64_t reqTs;
4919
  int64_t rspTs;
4920
  int64_t delayDuration;  // ms
4921
  bool    fillHistoryFinished;
4922
} STableTSMAInfo;
4923

4924
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4925
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4926
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4927
void    tFreeTableTSMAInfo(void* p);
4928
void    tFreeAndClearTableTSMAInfo(void* p);
4929
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4930

4931
#define STSMAHbRsp            STableTSMAInfoRsp
4932
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4933
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4934
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4935

4936
typedef struct SStreamProgressReq {
4937
  int64_t streamId;
4938
  int32_t vgId;
4939
  int32_t fetchIdx;
4940
  int32_t subFetchIdx;
4941
} SStreamProgressReq;
4942

4943
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4944
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4945

4946
typedef struct SStreamProgressRsp {
4947
  int64_t streamId;
4948
  int32_t vgId;
4949
  bool    fillHisFinished;
4950
  int64_t progressDelay;
4951
  int32_t fetchIdx;
4952
  int32_t subFetchIdx;
4953
} SStreamProgressRsp;
4954

4955
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4956
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4957

4958
typedef struct SDropCtbWithTsmaSingleVgReq {
4959
  SVgroupInfo vgInfo;
4960
  SArray*     pTbs;  // SVDropTbReq
4961
} SMDropTbReqsOnSingleVg;
4962

4963
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4964
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4965
void    tFreeSMDropTbReqOnSingleVg(void* p);
4966

4967
typedef struct SDropTbsReq {
4968
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4969
} SMDropTbsReq;
4970

4971
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4972
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4973
void    tFreeSMDropTbsReq(void*);
4974

4975
typedef struct SVFetchTtlExpiredTbsRsp {
4976
  SArray* pExpiredTbs;  // SVDropTbReq
4977
  int32_t vgId;
4978
} SVFetchTtlExpiredTbsRsp;
4979

4980
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4981
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4982

4983
void tFreeFetchTtlExpiredTbsRsp(void* p);
4984

4985
void setDefaultOptionsForField(SFieldWithOptions* field);
4986
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4987

4988
#pragma pack(pop)
4989

4990
#ifdef __cplusplus
4991
}
4992
#endif
4993

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