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

taosdata / TDengine / #4180

27 May 2025 10:49AM UTC coverage: 63.267% (+0.4%) from 62.885%
#4180

push

travis-ci

web-flow
TD-35056 (#31227)

158426 of 318644 branches covered (49.72%)

Branch coverage included in aggregate %.

243945 of 317346 relevant lines covered (76.87%)

18276423.81 hits per line

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

40.84
/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) {
71,402,938✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
71,402,938✔
74
  int    segIdx = TMSG_SEG_CODE(type);
71,402,938✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
71,402,938!
76
    return type < tMsgRangeDict[segIdx];
71,411,471✔
77
  }
78
  return false;
×
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
7,301,716✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
7,255,913✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
14,557,629!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
38,469,936✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
38,469,936✔
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,506!
842
    return TSDB_CODE_INVALID_PARA;
×
843
  }
844
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
14,506!
845
  if (pCmpr->pColCmpr == NULL) {
14,506!
846
    return terrno;
×
847
  }
848
  pCmpr->nCols = nCols;
14,506✔
849
  return 0;
14,506✔
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;
12,040,218!
878

879
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
12,040,218!
880
  if (pSW == NULL) {
12,043,199!
881
    return NULL;
×
882
  }
883
  pSW->nCols = pSchemaWrapper->nCols;
12,043,199✔
884
  pSW->version = pSchemaWrapper->version;
12,043,199✔
885
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
12,043,199!
886
  if (pSW->pSchema == NULL) {
12,042,997!
887
    taosMemoryFree(pSW);
×
888
    return NULL;
×
889
  }
890

891
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
12,042,997✔
892
  return pSW;
12,042,997✔
893
}
894

895
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
609,285✔
896
  if (pSchemaWrapper) {
28,411,457!
897
    taosMemoryFree(pSchemaWrapper->pSchema);
10,881,686!
898
    taosMemoryFree(pSchemaWrapper);
10,881,902!
899
  }
900
}
28,292,515✔
901

902
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,577,899✔
903
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,577,899!
904
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,578,180✔
905
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,578,306!
906
  }
907
}
1,577,487✔
908

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

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

928
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
929
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
596,475,418!
930
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
619,991,060!
931
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
619,991,060!
932
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
619,991,060!
933
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
619,991,060!
934
  return 0;
309,995,530✔
935
}
936

937
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
938
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
793,837,297!
939
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,556,511,575!
940
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,550,013,352!
941
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,573,377,317!
942
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
790,459,737!
943
  return 0;
828,586,286✔
944
}
945

946
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
947
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
355,461,052!
948
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
355,461,052!
949
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
355,461,052!
950
  return 0;
177,730,526✔
951
}
952

953
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
954
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
7,202,323!
955
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
7,202,320!
956
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
7,202,317!
957
  return 0;
3,601,158✔
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));
22,836!
973
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
22,836!
974
  if (pColRef->hasRef) {
11,418✔
975
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
7,071!
976
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
7,071!
977
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
7,071!
978
  }
979

980
  return 0;
11,418✔
981
}
982

983
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
984
  int32_t tlen = 0;
8,620✔
985
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,620✔
986
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,620✔
987
  for (int32_t i = 0; i < pSW->nCols; i++) {
63,594✔
988
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
109,948!
989
  }
990
  return tlen;
8,620✔
991
}
992

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

1002
    for (int32_t i = 0; i < pSW->nCols; i++) {
28,527✔
1003
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
51,336✔
1004
    }
1005
  } else {
1006
    pSW->pSchema = NULL;
1,155✔
1007
  }
1008
  return (void*)buf;
4,014✔
1009
}
1010

1011
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1012
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
813,608!
1013
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,627,216!
1014
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,627,216!
1015
  for (int32_t i = 0; i < pSW->nCols; i++) {
24,329,250!
1016
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
47,031,284!
1017
  }
1018
  return 0;
813,608✔
1019
}
1020

1021
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1022
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
1,542,267!
1023
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
3,084,599!
1024
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
3,084,500!
1025

1026
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,542,168!
1027
  if (pSW->pSchema == NULL) {
1,542,238!
1028
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1029
  }
1030
  for (int32_t i = 0; i < pSW->nCols; i++) {
18,199,423!
1031
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
33,315,439!
1032
  }
1033

1034
  return 0;
1,541,169✔
1035
}
1036

1037
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1038
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
91,867,427!
1039
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
93,082,754!
1040

1041
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
46,519,459!
1042
  if (pSW->pSchema == NULL) {
46,792,052!
1043
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1044
  }
1045
  for (int32_t i = 0; i < pSW->nCols; i++) {
854,299,663!
1046
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,617,016,873!
1047
  }
1048

1049
  return 0;
44,790,401✔
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
  int64_t bufferSegmentUsed;
1964
  int64_t bufferSegmentSize;
1965
} SVnodeLoad;
1966

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

1982
typedef struct {
1983
  int32_t vgId;
1984
  int64_t nTimeSeries;
1985
} SVnodeLoadLite;
1986

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

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

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

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

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

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

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

2053
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2054
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2055

2056
typedef enum {
2057
  MONITOR_TYPE_COUNTER = 0,
2058
  MONITOR_TYPE_SLOW_LOG = 1,
2059
} MONITOR_TYPE;
2060

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

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

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

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

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

2092
typedef struct {
2093
  int32_t dnodeId;
2094
  int64_t clusterId;
2095
} SDnodeCfg;
2096

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

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

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

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

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

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

2137
typedef struct {
2138
  int32_t reserved;
2139
} SMTimerReq;
2140

2141
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2142
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2143

2144
typedef struct SOrphanTask {
2145
  int64_t streamId;
2146
  int32_t taskId;
2147
  int32_t nodeId;
2148
} SOrphanTask;
2149

2150
typedef struct SMStreamDropOrphanMsg {
2151
  SArray* pList;  // SArray<SOrphanTask>
2152
} SMStreamDropOrphanMsg;
2153

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

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

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

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

2220
typedef struct {
2221
  int32_t compactId;
2222
  int32_t vgId;
2223
  int32_t dnodeId;
2224
} SQueryCompactProgressReq;
2225

2226
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2227
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2228

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

2239
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2240
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2241

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

2250
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2251
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2252

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

2261
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2262
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2263

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

2273
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2274
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2275

2276
typedef struct {
2277
  int32_t compactId;
2278
  int32_t vgId;
2279
  int32_t dnodeId;
2280
} SVKillCompactReq;
2281

2282
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2283
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2284

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

2311
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2312
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2313

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

2327
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2328
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2329

2330
typedef struct {
2331
  int32_t vgId;
2332
  int8_t  disable;
2333
} SDisableVnodeWriteReq;
2334

2335
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2336
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2337

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

2347
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2348
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2349

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

2360
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2361
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2362

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

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

2383
typedef struct {
2384
  int32_t     numOfVgroups;
2385
  SVgroupInfo vgroups[];
2386
} SVgroupsInfo;
2387

2388
typedef struct {
2389
  STableMetaRsp* pMeta;
2390
} SMAlterStbRsp;
2391

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

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

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

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

2410
typedef struct {
2411
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2412
} SViewHbRsp;
2413

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

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

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

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

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

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

2453
typedef struct {
2454
  SArray* variables;  // SArray<SVariablesInfo>
2455
} SShowVariablesRsp;
2456

2457
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2458
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2459

2460
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2461

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

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

2478
typedef struct {
2479
  int64_t       showId;
2480
  STableMetaRsp tableMeta;
2481
} SShowRsp, SVShowTablesRsp;
2482

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

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

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

2503
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2504
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2505

2506
#define RETRIEVE_TABLE_RSP_VERSION          0
2507
#define RETRIEVE_TABLE_RSP_TMQ_VERSION      1
2508
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION  2
2509

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

2529
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2530

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

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

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

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

2565
typedef struct {
2566
  int32_t           numOfPlans;
2567
  SExplainExecInfo* subplanInfo;
2568
} SExplainRsp;
2569

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2667
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2668
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2669

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

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

2689
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2690
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2691

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

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

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

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

2716
typedef struct {
2717
  int32_t vgId;
2718
  int32_t hbSeq;
2719
} SVArbHbReqMember;
2720

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

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

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

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

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

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

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

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

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

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

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

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

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

2792
typedef struct {
2793
  int32_t dnodeId;
2794
  char*   token;
2795
} SMArbUpdateGroupMember;
2796

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

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

2815
typedef struct {
2816
  SArray* updateArray;  // SMArbUpdateGroup
2817
} SMArbUpdateGroupBatchReq;
2818

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

2823
typedef struct {
2824
  char queryStrId[TSDB_QUERY_ID_LEN];
2825
} SKillQueryReq;
2826

2827
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2828
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2829

2830
typedef struct {
2831
  uint32_t connId;
2832
} SKillConnReq;
2833

2834
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2835
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2836

2837
typedef struct {
2838
  int32_t transId;
2839
} SKillTransReq;
2840

2841
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2842
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2843

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

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

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

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

2868
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2869
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2870

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

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

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

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

2896
typedef struct {
2897
  int32_t vgId;
2898
} SForceBecomeFollowerReq;
2899

2900
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2901
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2902

2903
typedef struct {
2904
  int32_t vgId;
2905
} SSplitVgroupReq;
2906

2907
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2908
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2909

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

2918
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2919
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2920

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

2926
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2927
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2928

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

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

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

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

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

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

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

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

3002
typedef struct SColIdPair {
3003
  col_id_t vtbColId;
3004
  col_id_t orgColId;
3005
} SColIdPair;
3006

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

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

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

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

3035
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3036
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3037

3038
typedef struct {
3039
  SMsgHead header;
3040
  uint64_t clientId;
3041
} SSchTasksStatusReq;
3042

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

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

3057
typedef struct {
3058
  uint64_t queryId;
3059
  uint64_t taskId;
3060
  int8_t   action;
3061
} STaskAction;
3062

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

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

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

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

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

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

3098
typedef struct {
3099
  int32_t code;
3100
} STaskCancelRsp;
3101

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

3112
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3113
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3114

3115
typedef enum {
3116
  TASK_NOTIFY_FINISHED = 1,
3117
} ETaskNotifyType;
3118

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

3130
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3131
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3132

3133
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3134
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3135

3136
typedef struct {
3137
  int32_t code;
3138
} STaskDropRsp;
3139

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

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

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

3160
typedef struct SVgroupVer {
3161
  int32_t vgId;
3162
  int64_t ver;
3163
} SVgroupVer;
3164

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

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

3221
typedef struct {
3222
  int64_t streamId;
3223
} SCMCreateStreamRsp;
3224

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

3229
enum {
3230
  TOPIC_SUB_TYPE__DB = 1,
3231
  TOPIC_SUB_TYPE__TABLE,
3232
  TOPIC_SUB_TYPE__COLUMN,
3233
};
3234

3235
#define DEFAULT_MAX_POLL_INTERVAL  300000
3236
#define DEFAULT_SESSION_TIMEOUT    12000
3237
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3238
#define DEFAULT_MIN_POLL_ROWS      4096
3239

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

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

3255
typedef struct {
3256
  int64_t consumerId;
3257
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3258

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

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

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

3283
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,696!
3284
  tlen += taosEncodeFixedI32(buf, topicNum);
2,696✔
3285

3286
  for (int32_t i = 0; i < topicNum; i++) {
3,820✔
3287
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,248✔
3288
  }
3289

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

3301
  return tlen;
2,696✔
3302
}
3303

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

3310
  int32_t topicNum = 0;
1,424!
3311
  buf = taosDecodeFixedI32(buf, &topicNum);
1,424✔
3312

3313
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,424✔
3314
  if (pReq->topicNames == NULL) {
1,424!
3315
    return terrno;
×
3316
  }
3317
  for (int32_t i = 0; i < topicNum; i++) {
2,077✔
3318
    char* name = NULL;
653✔
3319
    buf = taosDecodeString(buf, &name);
653✔
3320
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,306!
3321
      return terrno;
×
3322
    }
3323
  }
3324

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

3341
  return 0;
1,424✔
3342
}
3343

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

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

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

3378
typedef struct {
3379
  int64_t status;
3380
} SMVSubscribeRsp;
3381

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

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

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

3401
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3402
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3403

3404
typedef struct {
3405
  int8_t reserved;
3406
} SMDropCgroupRsp;
3407

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

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

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

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

3439
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3440
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3441

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

3460
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3461
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3462

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

3469
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3470
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3471

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

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

3506
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,168✔
3507
  if (NULL == req) {
22,200,213!
3508
    return;
21,881,333✔
3509
  }
3510

3511
  taosMemoryFreeClear(req->sql);
318,880!
3512
  taosMemoryFreeClear(req->name);
318,880!
3513
  taosMemoryFreeClear(req->comment);
318,932!
3514
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
318,932!
3515
    taosMemoryFreeClear(req->ctb.pTag);
304,267!
3516
    taosMemoryFreeClear(req->ctb.stbName);
304,384!
3517
    taosArrayDestroy(req->ctb.tagName);
304,388✔
3518
    req->ctb.tagName = NULL;
304,323✔
3519
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
14,665!
3520
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
14,665!
3521
  }
3522
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
318,988!
3523
  taosMemoryFreeClear(req->pExtSchemas);
318,988!
3524
  taosMemoryFreeClear(req->colRef.pColRef);
318,988!
3525
}
3526

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

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

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

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

3549
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3550
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3551

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

3560
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3561
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3562

3563
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3564
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3565

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

3575
typedef struct {
3576
  int32_t code;
3577
} SVDropTbRsp;
3578

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

3587
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3588
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3589

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

3598
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3599
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3600

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

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

3656
typedef struct {
3657
  int32_t        code;
3658
  STableMetaRsp* pMeta;
3659
} SVAlterTbRsp;
3660

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

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

3679
typedef struct {
3680
  SMsgHead head;
3681
} SUpdateTagValRsp;
3682

3683
typedef struct {
3684
  SMsgHead head;
3685
} SVShowTablesReq;
3686

3687
typedef struct {
3688
  SMsgHead head;
3689
  int32_t  id;
3690
} SVShowTablesFetchReq;
3691

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

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

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

3714
typedef struct {
3715
  int64_t tscRid;
3716
  int8_t  connType;
3717
} SClientHbKey;
3718

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

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

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

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

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

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

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

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

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

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

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

3808
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
344,332✔
3809

3810
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3811
  void* pIter = taosHashIterate(info, NULL);
404,189✔
3812
  while (pIter != NULL) {
665,620!
3813
    SKv* kv = (SKv*)pIter;
261,408✔
3814
    taosMemoryFreeClear(kv->value);
261,408!
3815
    pIter = taosHashIterate(info, pIter);
261,406✔
3816
  }
3817
}
404,212✔
3818

3819
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
290,239✔
3820
  SQueryDesc* desc = (SQueryDesc*)pDesc;
290,239✔
3821
  if (desc->subDesc) {
290,239✔
3822
    taosArrayDestroy(desc->subDesc);
282,063✔
3823
    desc->subDesc = NULL;
282,066✔
3824
  }
3825
}
290,242✔
3826

3827
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
525,698✔
3828
  SClientHbReq* req = (SClientHbReq*)pReq;
558,127✔
3829
  if (req->query) {
558,127!
3830
    if (req->query->queryDesc) {
513,126!
3831
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
54,315✔
3832
    }
3833
    taosMemoryFreeClear(req->query);
513,126!
3834
  }
3835

3836
  if (req->info) {
558,119!
3837
    tFreeReqKvHash(req->info);
404,189✔
3838
    taosHashCleanup(req->info);
404,212✔
3839
    req->info = NULL;
404,202✔
3840
  }
3841
}
390,388✔
3842

3843
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3844
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3845

3846
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3847
  if (pReq == NULL) return;
57,094!
3848
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
57,094✔
3849
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
57,094✔
3850
  taosMemoryFree(pReq);
57,094!
3851
}
3852

3853
static FORCE_INLINE void tFreeClientKv(void* pKv) {
91,969✔
3854
  SKv* kv = (SKv*)pKv;
91,969✔
3855
  if (kv) {
91,969!
3856
    taosMemoryFreeClear(kv->value);
91,969!
3857
  }
3858
}
91,969✔
3859

3860
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
522,023✔
3861
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
522,023✔
3862
  if (rsp->query) {
522,023✔
3863
    taosArrayDestroy(rsp->query->pQnodeList);
509,574✔
3864
    taosMemoryFreeClear(rsp->query);
509,583!
3865
  }
3866
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
522,059!
3867
}
164,115✔
3868

3869
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3870
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
268,794✔
3871
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
268,794✔
3872
}
268,840✔
3873

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

3878
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3879
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
545,798!
3880
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
545,798!
3881
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
545,798!
3882
  return 0;
272,899✔
3883
}
3884

3885
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3886
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
433,839!
3887
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
433,838!
3888
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
216,919!
3889
  if (pKv->value == NULL) {
216,924!
3890
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3891
  }
3892
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
216,924!
3893
  return 0;
216,922✔
3894
}
3895

3896
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3897
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,101,514!
3898
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,101,514!
3899
  return 0;
1,050,757✔
3900
}
3901

3902
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3903
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,044,162!
3904
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,044,171!
3905
  return 0;
522,090✔
3906
}
3907

3908
typedef struct {
3909
  int32_t vgId;
3910
  // TODO stas
3911
} SMqReportVgInfo;
3912

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

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

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

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

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

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

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

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

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

4012
typedef struct {
4013
  int8_t reserved;
4014
} SMqVDeleteRsp;
4015

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

4023
typedef struct {
4024
  int8_t reserved;
4025
} SMDropStreamRsp;
4026

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

4034
typedef struct {
4035
  int8_t reserved;
4036
} SVDropStreamTaskRsp;
4037

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

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

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

4067
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4068
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4069

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

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

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

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

4096
#define TQ_OFFSET_VERSION 1
4097

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

4114
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4115
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
26,172✔
4116
  pOffsetVal->uid = uid;
26,172✔
4117
  pOffsetVal->ts = ts;
26,172✔
4118
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
26,172!
4119
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4120
  }
4121
  pOffsetVal->primaryKey = primaryKey;
26,185✔
4122
}
26,185✔
4123

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

4129
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4130
  pOffsetVal->type = TMQ_OFFSET__LOG;
603,416✔
4131
  pOffsetVal->version = ver;
603,416✔
4132
}
603,416✔
4133

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

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

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

4150
typedef struct SMqVgOffset {
4151
  int64_t   consumerId;
4152
  STqOffset offset;
4153
} SMqVgOffset;
4154

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

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

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

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

4176
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4177
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4178

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

4186
typedef struct {
4187
  int8_t reserved;
4188
} SVResumeStreamTaskRsp;
4189

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

4196
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4197
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4198

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

4205
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
4206
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
4207

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

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

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

4246
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4247
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4248

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

4257
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4258
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4259

4260
typedef SMDropSmaReq SDropTagIndexReq;
4261

4262
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4263
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4264

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

4287
typedef STSma SVCreateTSmaReq;
4288

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

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

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

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

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

4316
typedef struct {
4317
  int32_t number;
4318
  STSma*  tSma;
4319
} STSmaWrapper;
4320

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

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

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

4348
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4349
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4350

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

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

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

4370
typedef struct {
4371
  int idx;
4372
} SMCreateFullTextReq;
4373

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

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

4383
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4384
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4385

4386
typedef struct {
4387
  char indexFName[TSDB_INDEX_FNAME_LEN];
4388
} SUserIndexReq;
4389

4390
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4391
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4392

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

4401
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4402
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4403

4404
typedef struct {
4405
  char tbFName[TSDB_TABLE_FNAME_LEN];
4406
} STableIndexReq;
4407

4408
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4409
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4410

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

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

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

4436
void tFreeSTableIndexInfo(void* pInfo);
4437

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

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

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

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

4475
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4476
  int32_t tlen = 0;
8,768✔
4477
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,768✔
4478
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,768✔
4479
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,768✔
4480
  return tlen;
8,768✔
4481
}
4482

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

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

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

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

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

4513
#define MQ_DATA_RSP_VERSION 100
4514

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

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

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

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

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

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

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

4575
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4576
  int32_t tlen = 0;
16,610✔
4577
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4578
  int32_t sz = taosArrayGetSize(pRsp->topics);
16,610!
4579
  tlen += taosEncodeFixedI32(buf, sz);
16,610✔
4580
  for (int32_t i = 0; i < sz; i++) {
23,312✔
4581
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,702✔
4582
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,702✔
4583
  }
4584
  return tlen;
16,610✔
4585
}
4586

4587
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4588
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4589
  int32_t sz;
4590
  buf = taosDecodeFixedI32(buf, &sz);
7,894✔
4591
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
7,894✔
4592
  if (pRsp->topics == NULL) {
7,894!
4593
    return NULL;
×
4594
  }
4595
  for (int32_t i = 0; i < sz; i++) {
11,155✔
4596
    SMqSubTopicEp topicEp;
4597
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,261✔
4598
    if (buf == NULL) {
3,261!
4599
      return NULL;
×
4600
    }
4601
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,522!
4602
      return NULL;
×
4603
    }
4604
  }
4605
  return buf;
7,894✔
4606
}
4607

4608
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4609
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
19,660✔
4610
}
19,660✔
4611

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

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

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

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

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

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

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

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

4670
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4671
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4672

4673
typedef struct {
4674
  int64_t affectedRows;
4675
} SVDeleteRsp;
4676

4677
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4678
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4679

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

4692
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4693
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4694

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

4702
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4703
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4704

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

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

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

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

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

4736
typedef struct {
4737
  SArray* pRsps;  // SArray<SBatchRspMsg>
4738
} SBatchRsp;
4739

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

4750
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4751
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4752

4753
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
2,492,825✔
4754
  if (NULL == p) {
2,492,825!
4755
    return;
×
4756
  }
4757

4758
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
2,492,825✔
4759
  taosMemoryFree(pRsp->msg);
2,492,825!
4760
}
4761

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

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

4772
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4773
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4774

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

4782
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4783

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

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

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

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

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

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

4823
#define TSDB_MSG_FLG_ENCODE 0x1
4824
#define TSDB_MSG_FLG_DECODE 0x2
4825
#define TSDB_MSG_FLG_CMPT   0x3
4826

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

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

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

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

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

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

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

4893
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4894
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4895

4896
typedef struct {
4897
  int32_t  funcId;
4898
  col_id_t colId;
4899
} STableTSMAFuncInfo;
4900

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

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

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

4933
#define STSMAHbRsp            STableTSMAInfoRsp
4934
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4935
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4936
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4937

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

4945
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4946
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4947

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

4957
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4958
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4959

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

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

4969
typedef struct SDropTbsReq {
4970
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4971
} SMDropTbsReq;
4972

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

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

4982
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4983
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4984

4985
void tFreeFetchTtlExpiredTbsRsp(void* p);
4986

4987
void setDefaultOptionsForField(SFieldWithOptions* field);
4988
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4989

4990
#pragma pack(pop)
4991

4992
#ifdef __cplusplus
4993
}
4994
#endif
4995

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