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

taosdata / TDengine / #3845

11 Apr 2025 06:14AM UTC coverage: 62.585% (+18.7%) from 43.852%
#3845

push

travis-ci

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

merge: from main to 3.0 branch

154461 of 315259 branches covered (48.99%)

Branch coverage included in aggregate %.

63 of 80 new or added lines in 9 files covered. (78.75%)

3223 existing lines in 85 files now uncovered.

240073 of 315138 relevant lines covered (76.18%)

18471065.7 hits per line

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

40.71
/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) {
79,809,786✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
79,809,786✔
74
  int    segIdx = TMSG_SEG_CODE(type);
79,809,786✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
79,809,786✔
76
    return type < tMsgRangeDict[segIdx];
79,820,458✔
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) {
3,994,374✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
3,949,713✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
7,944,087!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

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

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

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

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

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

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

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

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

209
#define TSDB_KILL_MSG_LEN 30
210

211
#define TSDB_TABLE_NUM_UNIT 100000
212

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

669
//
670

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

779
bool hasExtSchema(const SExtSchema* pExtSchema);
780

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

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

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

798

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

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

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

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

836
  return pDstWrapper;
837
}
838

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

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

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

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

878
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
11,440,973!
879
  if (pSW == NULL) {
11,435,943!
880
    return NULL;
×
881
  }
882
  pSW->nCols = pSchemaWrapper->nCols;
11,435,943✔
883
  pSW->version = pSchemaWrapper->version;
11,435,943✔
884
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
11,435,943!
885
  if (pSW->pSchema == NULL) {
11,431,913!
886
    taosMemoryFree(pSW);
×
887
    return NULL;
×
888
  }
889

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

894
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
592,802✔
895
  if (pSchemaWrapper) {
27,152,854!
896
    taosMemoryFree(pSchemaWrapper->pSchema);
10,353,258!
897
    taosMemoryFree(pSchemaWrapper);
10,353,339!
898
  }
899
}
27,032,512✔
900

901
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,470,075✔
902
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,470,075!
903
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,470,306!
904
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,470,593!
905
  }
906
}
1,469,942✔
907

908
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
909
  int32_t tlen = 0;
10,255,288✔
910
  tlen += taosEncodeFixedI8(buf, pSchema->type);
20,510,576✔
911
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
10,255,288!
912
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
10,255,288!
913
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
10,255,288!
914
  tlen += taosEncodeString(buf, pSchema->name);
10,255,288✔
915
  return tlen;
10,255,288✔
916
}
917

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

927
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
928
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
577,366,644!
929
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
596,553,894!
930
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
596,553,894!
931
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
596,553,894!
932
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
596,553,894!
933
  return 0;
298,276,947✔
934
}
935

936
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
937
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
745,453,743!
938
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,459,063,714!
939
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,445,982,227!
940
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,461,618,523!
941
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
732,605,338!
942
  return 0;
789,079,768✔
943
}
944

945
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
946
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
344,604,194!
947
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
344,604,194!
948
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
344,604,194!
949
  return 0;
172,302,097✔
950
}
951

952
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
953
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
5,369,713!
954
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
5,369,709!
955
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
5,369,700!
956
  return 0;
2,684,847✔
957
}
958

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

970
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
971
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
17,286!
972
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
17,286!
973
  if (pColRef->hasRef) {
8,643✔
974
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
4,997!
975
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
4,997!
976
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
4,997!
977
  }
978

979
  return 0;
8,643✔
980
}
981

982
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
983
  int32_t tlen = 0;
1,360,536✔
984
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
1,360,536✔
985
  tlen += taosEncodeVariantI32(buf, pSW->version);
1,360,536✔
986
  for (int32_t i = 0; i < pSW->nCols; i++) {
11,615,824✔
987
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
20,510,576!
988
  }
989
  return tlen;
1,360,536✔
990
}
991

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

1001
    for (int32_t i = 0; i < pSW->nCols; i++) {
5,553,907✔
1002
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
10,252,110✔
1003
    }
1004
  } else {
1005
    pSW->pSchema = NULL;
252,150✔
1006
  }
1007
  return (void*)buf;
680,002✔
1008
}
1009

1010
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1011
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
735,494!
1012
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,470,988!
1013
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,470,988!
1014
  for (int32_t i = 0; i < pSW->nCols; i++) {
19,922,744!
1015
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
38,374,500!
1016
  }
1017
  return 0;
735,494✔
1018
}
1019

1020
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1021
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
1,539,189!
1022
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
3,078,358!
1023
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
3,078,347!
1024

1025
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,539,178!
1026
  if (pSW->pSchema == NULL) {
1,539,342!
1027
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1028
  }
1029
  for (int32_t i = 0; i < pSW->nCols; i++) {
18,239,035!
1030
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
33,399,696!
1031
  }
1032

1033
  return 0;
1,539,032✔
1034
}
1035

1036
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1037
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
87,151,883!
1038
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
88,519,242!
1039

1040
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
44,234,530!
1041
  if (pSW->pSchema == NULL) {
44,512,736!
1042
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1043
  }
1044
  for (int32_t i = 0; i < pSW->nCols; i++) {
813,533,754!
1045
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,538,811,150!
1046
  }
1047

1048
  return 0;
43,743,622✔
1049
}
1050

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1445
typedef STableCfg STableCfgRsp;
1446

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

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

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

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

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

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

1471
typedef struct {
1472
  SMsgHead header;
1473
  tb_uid_t suid;
1474
} SVStbRefDbsReq;
1475

1476
int32_t tSerializeSVStbRefDbsReq(void *buf, int32_t bufLen, SVStbRefDbsReq *pReq);
1477
int32_t tDeserializeSVStbRefDbsReq(void *buf, int32_t bufLen, SVStbRefDbsReq *pReq);
1478

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

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

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

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

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

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

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

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

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

1593
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1594
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1595

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

1604
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1605
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1606

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

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

1626
typedef struct {
1627
  char db[TSDB_DB_FNAME_LEN];
1628
} SDbCfgReq;
1629

1630
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1631
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1632

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

1638
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1639
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1640

1641
typedef struct {
1642
  int32_t timestamp;
1643
} SVTrimDbReq;
1644

1645
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1646
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1647

1648
typedef struct {
1649
  char db[TSDB_DB_FNAME_LEN];
1650
} SS3MigrateDbReq;
1651

1652
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1653
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1654

1655
typedef struct {
1656
  int32_t timestamp;
1657
} SVS3MigrateDbReq;
1658

1659
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1660
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1661

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

1669
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1670
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1671

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

1719
typedef SDbCfgRsp SDbCfgInfo;
1720

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

1727
typedef struct {
1728
  int32_t rowNum;
1729
} SQnodeListReq;
1730

1731
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1732
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1733

1734
typedef struct {
1735
  int32_t rowNum;
1736
} SDnodeListReq;
1737

1738
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1739

1740
typedef struct {
1741
  int32_t useless;  // useless
1742
} SServerVerReq;
1743

1744
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1745
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1746

1747
typedef struct {
1748
  char ver[TSDB_VERSION_LEN];
1749
} SServerVerRsp;
1750

1751
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1752
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1753

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

1759
typedef struct {
1760
  SQueryNodeAddr addr;
1761
  uint64_t       load;
1762
} SQueryNodeLoad;
1763

1764
typedef struct {
1765
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1766
} SQnodeListRsp;
1767

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

1772
typedef struct SDNodeAddr {
1773
  int32_t nodeId;  // dnodeId
1774
  SEpSet  epSet;
1775
} SDNodeAddr;
1776

1777
typedef struct {
1778
  SArray* dnodeList;  // SArray<SDNodeAddr>
1779
} SDnodeListRsp;
1780

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

1785
typedef struct {
1786
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1787
} STableTSMAInfoRsp;
1788

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

1798
typedef struct {
1799
  SArray* pArray;  // Array of SDbHbRsp
1800
} SDbHbBatchRsp;
1801

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

1806
typedef struct {
1807
  SArray* pArray;  // Array of SGetUserAuthRsp
1808
} SUserAuthBatchRsp;
1809

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

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

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

1827
typedef struct {
1828
  int32_t compactId;
1829
  int8_t  bAccepted;
1830
} SCompactDbRsp;
1831

1832
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1833
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1834

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

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

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

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

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

1869
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1870
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1871

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

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

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

1896
typedef struct {
1897
  int32_t funcVersion;
1898
  int64_t funcCreatedTime;
1899
} SFuncExtraInfo;
1900

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

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

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

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

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

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

1978
typedef struct {
1979
  int32_t vgId;
1980
  int64_t nTimeSeries;
1981
} SVnodeLoadLite;
1982

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

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

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

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

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

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

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

2049
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2050
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2051

2052
typedef enum {
2053
  MONITOR_TYPE_COUNTER = 0,
2054
  MONITOR_TYPE_SLOW_LOG = 1,
2055
} MONITOR_TYPE;
2056

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

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

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

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

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

2088
typedef struct {
2089
  int32_t dnodeId;
2090
  int64_t clusterId;
2091
} SDnodeCfg;
2092

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

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

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

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

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

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

2133
typedef struct {
2134
  int32_t reserved;
2135
} SMTimerReq;
2136

2137
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2138
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2139

2140
typedef struct SOrphanTask {
2141
  int64_t streamId;
2142
  int32_t taskId;
2143
  int32_t nodeId;
2144
} SOrphanTask;
2145

2146
typedef struct SMStreamDropOrphanMsg {
2147
  SArray* pList;  // SArray<SOrphanTask>
2148
} SMStreamDropOrphanMsg;
2149

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

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

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

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

2216
typedef struct {
2217
  int32_t compactId;
2218
  int32_t vgId;
2219
  int32_t dnodeId;
2220
} SQueryCompactProgressReq;
2221

2222
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2223
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2224

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

2235
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2236
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2237

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

2246
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2247
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2248

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

2257
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2258
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2259

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

2269
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2270
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2271

2272
typedef struct {
2273
  int32_t compactId;
2274
  int32_t vgId;
2275
  int32_t dnodeId;
2276
} SVKillCompactReq;
2277

2278
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2279
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2280

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

2307
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2308
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2309

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

2323
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2324
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2325

2326
typedef struct {
2327
  int32_t vgId;
2328
  int8_t  disable;
2329
} SDisableVnodeWriteReq;
2330

2331
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2332
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2333

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

2343
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2344
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2345

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

2356
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2357
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2358

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

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

2379
typedef struct {
2380
  int32_t     numOfVgroups;
2381
  SVgroupInfo vgroups[];
2382
} SVgroupsInfo;
2383

2384
typedef struct {
2385
  STableMetaRsp* pMeta;
2386
} SMAlterStbRsp;
2387

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

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

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

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

2406
typedef struct {
2407
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2408
} SViewHbRsp;
2409

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

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

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

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

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

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

2449
typedef struct {
2450
  SArray* variables;  // SArray<SVariablesInfo>
2451
} SShowVariablesRsp;
2452

2453
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2454
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2455

2456
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2457

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

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

2474
typedef struct {
2475
  int64_t       showId;
2476
  STableMetaRsp tableMeta;
2477
} SShowRsp, SVShowTablesRsp;
2478

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

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

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

2499
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2500
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2501

2502
#define RETRIEVE_TABLE_RSP_VERSION          0
2503
#define RETRIEVE_TABLE_RSP_TMQ_VERSION      1
2504
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION  2
2505

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

2525
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2526

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

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

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

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

2561
typedef struct {
2562
  int32_t           numOfPlans;
2563
  SExplainExecInfo* subplanInfo;
2564
} SExplainRsp;
2565

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2663
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2664
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2665

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

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

2685
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2686
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2687

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

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

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

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

2712
typedef struct {
2713
  int32_t vgId;
2714
  int32_t hbSeq;
2715
} SVArbHbReqMember;
2716

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

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

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

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

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

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

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

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

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

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

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

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

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

2788
typedef struct {
2789
  int32_t dnodeId;
2790
  char*   token;
2791
} SMArbUpdateGroupMember;
2792

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

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

2811
typedef struct {
2812
  SArray* updateArray;  // SMArbUpdateGroup
2813
} SMArbUpdateGroupBatchReq;
2814

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

2819
typedef struct {
2820
  char queryStrId[TSDB_QUERY_ID_LEN];
2821
} SKillQueryReq;
2822

2823
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2824
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2825

2826
typedef struct {
2827
  uint32_t connId;
2828
} SKillConnReq;
2829

2830
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2831
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2832

2833
typedef struct {
2834
  int32_t transId;
2835
} SKillTransReq;
2836

2837
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2838
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2839

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

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

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

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

2864
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2865
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2866

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

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

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

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

2892
typedef struct {
2893
  int32_t vgId;
2894
} SForceBecomeFollowerReq;
2895

2896
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2897
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2898

2899
typedef struct {
2900
  int32_t vgId;
2901
} SSplitVgroupReq;
2902

2903
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2904
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2905

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

2914
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2915
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2916

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

2922
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2923
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2924

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

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

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

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

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

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

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

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

2998
typedef struct SColIdPair {
2999
  col_id_t vtbColId;
3000
  col_id_t orgColId;
3001
} SColIdPair;
3002

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

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

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

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

3031
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3032
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3033

3034
typedef struct {
3035
  SMsgHead header;
3036
  uint64_t clientId;
3037
} SSchTasksStatusReq;
3038

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

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

3053
typedef struct {
3054
  uint64_t queryId;
3055
  uint64_t taskId;
3056
  int8_t   action;
3057
} STaskAction;
3058

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

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

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

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

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

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

3094
typedef struct {
3095
  int32_t code;
3096
} STaskCancelRsp;
3097

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

3108
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3109
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3110

3111
typedef enum {
3112
  TASK_NOTIFY_FINISHED = 1,
3113
} ETaskNotifyType;
3114

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

3126
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3127
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3128

3129
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3130
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3131

3132
typedef struct {
3133
  int32_t code;
3134
} STaskDropRsp;
3135

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

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

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

3156
typedef struct SVgroupVer {
3157
  int32_t vgId;
3158
  int64_t ver;
3159
} SVgroupVer;
3160

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

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

3217
typedef struct {
3218
  int64_t streamId;
3219
} SCMCreateStreamRsp;
3220

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

3225
enum {
3226
  TOPIC_SUB_TYPE__DB = 1,
3227
  TOPIC_SUB_TYPE__TABLE,
3228
  TOPIC_SUB_TYPE__COLUMN,
3229
};
3230

3231
#define DEFAULT_MAX_POLL_INTERVAL  300000
3232
#define DEFAULT_SESSION_TIMEOUT    12000
3233
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3234
#define DEFAULT_MIN_POLL_ROWS      4096
3235

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

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

3251
typedef struct {
3252
  int64_t consumerId;
3253
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3254

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

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

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

3279
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,451!
3280
  tlen += taosEncodeFixedI32(buf, topicNum);
2,451✔
3281

3282
  for (int32_t i = 0; i < topicNum; i++) {
3,468✔
3283
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,034✔
3284
  }
3285

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

3297
  return tlen;
2,451✔
3298
}
3299

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

3306
  int32_t topicNum = 0;
1,295!
3307
  buf = taosDecodeFixedI32(buf, &topicNum);
1,295✔
3308

3309
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,295✔
3310
  if (pReq->topicNames == NULL) {
1,295!
3311
    return terrno;
×
3312
  }
3313
  for (int32_t i = 0; i < topicNum; i++) {
1,891✔
3314
    char* name = NULL;
596✔
3315
    buf = taosDecodeString(buf, &name);
596✔
3316
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,192!
3317
      return terrno;
×
3318
    }
3319
  }
3320

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

3337
  return 0;
1,295✔
3338
}
3339

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

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

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

3374
typedef struct {
3375
  int64_t status;
3376
} SMVSubscribeRsp;
3377

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

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

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

3397
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3398
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3399

3400
typedef struct {
3401
  int8_t reserved;
3402
} SMDropCgroupRsp;
3403

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

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

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

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

3435
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3436
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3437

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

3456
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3457
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3458

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

3465
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3466
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3467

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

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

3502
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
7,240✔
3503
  if (NULL == req) {
19,774,414!
3504
    return;
19,493,446✔
3505
  }
3506

3507
  taosMemoryFreeClear(req->sql);
280,968!
3508
  taosMemoryFreeClear(req->name);
280,968!
3509
  taosMemoryFreeClear(req->comment);
281,050!
3510
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
281,050!
3511
    taosMemoryFreeClear(req->ctb.pTag);
267,418!
3512
    taosMemoryFreeClear(req->ctb.stbName);
267,512!
3513
    taosArrayDestroy(req->ctb.tagName);
267,513✔
3514
    req->ctb.tagName = NULL;
267,436✔
3515
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
13,632!
3516
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
13,632!
3517
  }
3518
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
281,068!
3519
  taosMemoryFreeClear(req->pExtSchemas);
281,068!
3520
  taosMemoryFreeClear(req->colRef.pColRef);
281,068!
3521
}
3522

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

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

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

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

3545
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3546
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3547

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

3556
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3557
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3558

3559
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3560
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3561

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

3571
typedef struct {
3572
  int32_t code;
3573
} SVDropTbRsp;
3574

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

3583
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3584
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3585

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

3594
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3595
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3596

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

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

3652
typedef struct {
3653
  int32_t        code;
3654
  STableMetaRsp* pMeta;
3655
} SVAlterTbRsp;
3656

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

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

3675
typedef struct {
3676
  SMsgHead head;
3677
} SUpdateTagValRsp;
3678

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

3683
typedef struct {
3684
  SMsgHead head;
3685
  int32_t  id;
3686
} SVShowTablesFetchReq;
3687

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

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

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

3710
typedef struct {
3711
  int64_t tscRid;
3712
  int8_t  connType;
3713
} SClientHbKey;
3714

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

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

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

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

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

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

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

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

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

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

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

3804
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
308,856✔
3805

3806
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3807
  void* pIter = taosHashIterate(info, NULL);
558,015✔
3808
  while (pIter != NULL) {
973,005!
3809
    SKv* kv = (SKv*)pIter;
414,945✔
3810
    taosMemoryFreeClear(kv->value);
414,945!
3811
    pIter = taosHashIterate(info, pIter);
414,945✔
3812
  }
3813
}
558,060✔
3814

3815
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
365,156✔
3816
  SQueryDesc* desc = (SQueryDesc*)pDesc;
365,156✔
3817
  if (desc->subDesc) {
365,156✔
3818
    taosArrayDestroy(desc->subDesc);
357,179✔
3819
    desc->subDesc = NULL;
357,179✔
3820
  }
3821
}
365,156✔
3822

3823
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
666,829✔
3824
  SClientHbReq* req = (SClientHbReq*)pReq;
697,543✔
3825
  if (req->query) {
697,543!
3826
    if (req->query->queryDesc) {
654,949!
3827
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
51,672✔
3828
    }
3829
    taosMemoryFreeClear(req->query);
654,949!
3830
  }
3831

3832
  if (req->info) {
697,550!
3833
    tFreeReqKvHash(req->info);
558,015✔
3834
    taosHashCleanup(req->info);
558,060✔
3835
    req->info = NULL;
558,020✔
3836
  }
3837
}
549,846✔
3838

3839
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3840
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3841

3842
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3843
  if (pReq == NULL) return;
48,711!
3844
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
48,711✔
3845
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
48,711✔
3846
  taosMemoryFree(pReq);
48,711!
3847
}
3848

3849
static FORCE_INLINE void tFreeClientKv(void* pKv) {
159,960✔
3850
  SKv* kv = (SKv*)pKv;
159,960✔
3851
  if (kv) {
159,960!
3852
    taosMemoryFreeClear(kv->value);
159,960!
3853
  }
3854
}
159,960✔
3855

3856
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
663,629✔
3857
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
663,629✔
3858
  if (rsp->query) {
663,629✔
3859
    taosArrayDestroy(rsp->query->pQnodeList);
651,873✔
3860
    taosMemoryFreeClear(rsp->query);
652,005!
3861
  }
3862
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
663,807!
3863
}
144,837✔
3864

3865
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3866
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
445,003✔
3867
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
445,003✔
3868
}
445,158✔
3869

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

3874
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3875
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
788,804!
3876
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
788,804!
3877
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
788,804!
3878
  return 0;
394,402✔
3879
}
3880

3881
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3882
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
755,344!
3883
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
755,354!
3884
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
377,685!
3885
  if (pKv->value == NULL) {
377,685!
UNCOV
3886
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3887
  }
3888
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
377,685!
3889
  return 0;
377,669✔
3890
}
3891

3892
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3893
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,665,484!
3894
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,665,484!
3895
  return 0;
1,332,742✔
3896
}
3897

3898
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3899
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,327,769!
3900
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,327,784!
3901
  return 0;
663,905✔
3902
}
3903

3904
typedef struct {
3905
  int32_t vgId;
3906
  // TODO stas
3907
} SMqReportVgInfo;
3908

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

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

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

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

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

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

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

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

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

4008
typedef struct {
4009
  int8_t reserved;
4010
} SMqVDeleteRsp;
4011

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

4019
typedef struct {
4020
  int8_t reserved;
4021
} SMDropStreamRsp;
4022

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

4030
typedef struct {
4031
  int8_t reserved;
4032
} SVDropStreamTaskRsp;
4033

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

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

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

4063
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4064
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4065

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

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

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

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

4092
#define TQ_OFFSET_VERSION 1
4093

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

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

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

4125
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4126
  pOffsetVal->type = TMQ_OFFSET__LOG;
2,970,013✔
4127
  pOffsetVal->version = ver;
2,970,013✔
4128
}
2,970,013✔
4129

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

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

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

4146
typedef struct SMqVgOffset {
4147
  int64_t   consumerId;
4148
  STqOffset offset;
4149
} SMqVgOffset;
4150

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

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

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

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

4172
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4173
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4174

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

4182
typedef struct {
4183
  int8_t reserved;
4184
} SVResumeStreamTaskRsp;
4185

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

4192
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4193
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4194

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

4201
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
4202
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
4203

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

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

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

4242
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4243
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4244

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

4253
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4254
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4255

4256
typedef SMDropSmaReq SDropTagIndexReq;
4257

4258
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4259
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4260

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

4283
typedef STSma SVCreateTSmaReq;
4284

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

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

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

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

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

4312
typedef struct {
4313
  int32_t number;
4314
  STSma*  tSma;
4315
} STSmaWrapper;
4316

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

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

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

4344
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4345
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4346

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

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

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

4366
typedef struct {
4367
  int idx;
4368
} SMCreateFullTextReq;
4369

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

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

4379
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4380
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4381

4382
typedef struct {
4383
  char indexFName[TSDB_INDEX_FNAME_LEN];
4384
} SUserIndexReq;
4385

4386
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4387
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4388

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

4397
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4398
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4399

4400
typedef struct {
4401
  char tbFName[TSDB_TABLE_FNAME_LEN];
4402
} STableIndexReq;
4403

4404
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4405
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4406

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

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

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

4432
void tFreeSTableIndexInfo(void* pInfo);
4433

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

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

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

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

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

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

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

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

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

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

4509
#define MQ_DATA_RSP_VERSION 100
4510

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

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

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

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

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

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

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

4571
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4572
  int32_t tlen = 0;
1,368,945✔
4573
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4574
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,368,945!
4575
  tlen += taosEncodeFixedI32(buf, sz);
1,368,945✔
4576
  for (int32_t i = 0; i < sz; i++) {
2,727,720✔
4577
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,358,776✔
4578
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,358,776✔
4579
  }
4580
  return tlen;
1,368,944✔
4581
}
4582

4583
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4584
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4585
  int32_t sz;
4586
  buf = taosDecodeFixedI32(buf, &sz);
684,059✔
4587
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
684,059✔
4588
  if (pRsp->topics == NULL) {
684,059!
UNCOV
4589
    return NULL;
×
4590
  }
4591
  for (int32_t i = 0; i < sz; i++) {
1,363,365✔
4592
    SMqSubTopicEp topicEp;
4593
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
679,306✔
4594
    if (buf == NULL) {
679,306!
UNCOV
4595
      return NULL;
×
4596
    }
4597
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,358,612!
UNCOV
4598
      return NULL;
×
4599
    }
4600
  }
4601
  return buf;
684,059✔
4602
}
4603

4604
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4605
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
1,371,477✔
4606
}
1,371,478✔
4607

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

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

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

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

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

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

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

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

4666
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4667
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4668

4669
typedef struct {
4670
  int64_t affectedRows;
4671
} SVDeleteRsp;
4672

4673
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4674
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4675

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

4688
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4689
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4690

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

4698
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4699
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4700

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

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

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

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

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

4732
typedef struct {
4733
  SArray* pRsps;  // SArray<SBatchRspMsg>
4734
} SBatchRsp;
4735

4736
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4737
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4738
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
9,177,589✔
4739
  if (NULL == msg) {
9,177,589!
UNCOV
4740
    return;
×
4741
  }
4742
  SBatchMsg* pMsg = (SBatchMsg*)msg;
9,177,589✔
4743
  taosMemoryFree(pMsg->msg);
9,177,589!
4744
}
4745

4746
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4747
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4748

4749
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
2,424,034✔
4750
  if (NULL == p) {
2,424,034!
UNCOV
4751
    return;
×
4752
  }
4753

4754
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
2,424,034✔
4755
  taosMemoryFree(pRsp->msg);
2,424,034!
4756
}
4757

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

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

4768
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4769
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4770

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

4778
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4779

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

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

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

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

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

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

4819
#define TSDB_MSG_FLG_ENCODE 0x1
4820
#define TSDB_MSG_FLG_DECODE 0x2
4821
#define TSDB_MSG_FLG_CMPT   0x3
4822

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

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

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

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

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

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

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

4889
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4890
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4891

4892
typedef struct {
4893
  int32_t  funcId;
4894
  col_id_t colId;
4895
} STableTSMAFuncInfo;
4896

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

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

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

4929
#define STSMAHbRsp            STableTSMAInfoRsp
4930
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4931
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4932
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4933

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

4941
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4942
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4943

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

4953
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4954
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4955

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

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

4965
typedef struct SDropTbsReq {
4966
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4967
} SMDropTbsReq;
4968

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

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

4978
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4979
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4980

4981
void tFreeFetchTtlExpiredTbsRsp(void* p);
4982

4983
void setDefaultOptionsForField(SFieldWithOptions* field);
4984
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4985

4986
#pragma pack(pop)
4987

4988
#ifdef __cplusplus
4989
}
4990
#endif
4991

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