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

taosdata / TDengine / #3608

12 Feb 2025 05:57AM UTC coverage: 63.066% (+1.4%) from 61.715%
#3608

push

travis-ci

web-flow
Merge pull request #29746 from taosdata/merge/mainto3.02

merge: from main to 3.0 branch

140199 of 286257 branches covered (48.98%)

Branch coverage included in aggregate %.

89 of 161 new or added lines in 18 files covered. (55.28%)

3211 existing lines in 190 files now uncovered.

218998 of 283298 relevant lines covered (77.3%)

5949310.66 hits per line

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

48.52
/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) {
62,804,247✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
62,804,247✔
74
  int    segIdx = TMSG_SEG_CODE(type);
62,804,247✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
62,804,247✔
76
    return type < tMsgRangeDict[segIdx];
62,805,947✔
77
  }
78
  return false;
10✔
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
1,651,656✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
1,625,742!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
3,277,398!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
6,853,609✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
6,853,609✔
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

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

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

206
#define TSDB_KILL_MSG_LEN 30
207

208
#define TSDB_TABLE_NUM_UNIT 100000
209

210
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
211
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
212
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
213

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

220
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
221
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
222
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
223
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
224

225
#define TD_SUPER_TABLE  TSDB_SUPER_TABLE
226
#define TD_CHILD_TABLE  TSDB_CHILD_TABLE
227
#define TD_NORMAL_TABLE TSDB_NORMAL_TABLE
228

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

274
  // Statement nodes are used in parser and planner module.
275
  QUERY_NODE_SET_OPERATOR = 100,
276
  QUERY_NODE_SELECT_STMT,
277
  QUERY_NODE_VNODE_MODIFY_STMT,
278
  QUERY_NODE_CREATE_DATABASE_STMT,
279
  QUERY_NODE_DROP_DATABASE_STMT,
280
  QUERY_NODE_ALTER_DATABASE_STMT,
281
  QUERY_NODE_FLUSH_DATABASE_STMT,
282
  QUERY_NODE_TRIM_DATABASE_STMT,
283
  QUERY_NODE_CREATE_TABLE_STMT,
284
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
285
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
286
  QUERY_NODE_DROP_TABLE_CLAUSE,
287
  QUERY_NODE_DROP_TABLE_STMT,
288
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
289
  QUERY_NODE_ALTER_TABLE_STMT,
290
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
291
  QUERY_NODE_CREATE_USER_STMT,
292
  QUERY_NODE_ALTER_USER_STMT,
293
  QUERY_NODE_DROP_USER_STMT,
294
  QUERY_NODE_USE_DATABASE_STMT,
295
  QUERY_NODE_CREATE_DNODE_STMT,
296
  QUERY_NODE_DROP_DNODE_STMT,
297
  QUERY_NODE_ALTER_DNODE_STMT,
298
  QUERY_NODE_CREATE_INDEX_STMT,
299
  QUERY_NODE_DROP_INDEX_STMT,
300
  QUERY_NODE_CREATE_QNODE_STMT,
301
  QUERY_NODE_DROP_QNODE_STMT,
302
  QUERY_NODE_CREATE_BNODE_STMT,
303
  QUERY_NODE_DROP_BNODE_STMT,
304
  QUERY_NODE_CREATE_SNODE_STMT,
305
  QUERY_NODE_DROP_SNODE_STMT,
306
  QUERY_NODE_CREATE_MNODE_STMT,
307
  QUERY_NODE_DROP_MNODE_STMT,
308
  QUERY_NODE_CREATE_TOPIC_STMT,
309
  QUERY_NODE_DROP_TOPIC_STMT,
310
  QUERY_NODE_DROP_CGROUP_STMT,
311
  QUERY_NODE_ALTER_LOCAL_STMT,
312
  QUERY_NODE_EXPLAIN_STMT,
313
  QUERY_NODE_DESCRIBE_STMT,
314
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
315
  QUERY_NODE_COMPACT_DATABASE_STMT,
316
  QUERY_NODE_COMPACT_VGROUPS_STMT,
317
  QUERY_NODE_CREATE_FUNCTION_STMT,
318
  QUERY_NODE_DROP_FUNCTION_STMT,
319
  QUERY_NODE_CREATE_STREAM_STMT,
320
  QUERY_NODE_DROP_STREAM_STMT,
321
  QUERY_NODE_BALANCE_VGROUP_STMT,
322
  QUERY_NODE_MERGE_VGROUP_STMT,
323
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
324
  QUERY_NODE_SPLIT_VGROUP_STMT,
325
  QUERY_NODE_SYNCDB_STMT,
326
  QUERY_NODE_GRANT_STMT,
327
  QUERY_NODE_REVOKE_STMT,
328
  QUERY_NODE_ALTER_CLUSTER_STMT,
329
  QUERY_NODE_S3MIGRATE_DATABASE_STMT,
330
  // placeholder for [154, 180]
331
  QUERY_NODE_SHOW_CREATE_VIEW_STMT = 181,
332
  QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
333
  QUERY_NODE_SHOW_CREATE_TABLE_STMT,
334
  QUERY_NODE_SHOW_CREATE_STABLE_STMT,
335
  QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT,
336
  QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT,
337
  QUERY_NODE_SHOW_SCORES_STMT,
338
  QUERY_NODE_SHOW_TABLE_TAGS_STMT,
339
  QUERY_NODE_KILL_CONNECTION_STMT,
340
  QUERY_NODE_KILL_QUERY_STMT,
341
  QUERY_NODE_KILL_TRANSACTION_STMT,
342
  QUERY_NODE_KILL_COMPACT_STMT,
343
  QUERY_NODE_DELETE_STMT,
344
  QUERY_NODE_INSERT_STMT,
345
  QUERY_NODE_QUERY,
346
  QUERY_NODE_SHOW_DB_ALIVE_STMT,
347
  QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
348
  QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
349
  QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT,
350
  QUERY_NODE_RESTORE_DNODE_STMT,
351
  QUERY_NODE_RESTORE_QNODE_STMT,
352
  QUERY_NODE_RESTORE_MNODE_STMT,
353
  QUERY_NODE_RESTORE_VNODE_STMT,
354
  QUERY_NODE_PAUSE_STREAM_STMT,
355
  QUERY_NODE_RESUME_STREAM_STMT,
356
  QUERY_NODE_CREATE_VIEW_STMT,
357
  QUERY_NODE_DROP_VIEW_STMT,
358
  QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE,
359
  QUERY_NODE_CREATE_ANODE_STMT,
360
  QUERY_NODE_DROP_ANODE_STMT,
361
  QUERY_NODE_UPDATE_ANODE_STMT,
362

363
  // show statement nodes
364
  // see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
365
  QUERY_NODE_SHOW_DNODES_STMT = 400,
366
  QUERY_NODE_SHOW_MNODES_STMT,
367
  QUERY_NODE_SHOW_MODULES_STMT,
368
  QUERY_NODE_SHOW_QNODES_STMT,
369
  QUERY_NODE_SHOW_SNODES_STMT,
370
  QUERY_NODE_SHOW_BNODES_STMT,
371
  QUERY_NODE_SHOW_ARBGROUPS_STMT,
372
  QUERY_NODE_SHOW_CLUSTER_STMT,
373
  QUERY_NODE_SHOW_DATABASES_STMT,
374
  QUERY_NODE_SHOW_FUNCTIONS_STMT,
375
  QUERY_NODE_SHOW_INDEXES_STMT,
376
  QUERY_NODE_SHOW_STABLES_STMT,
377
  QUERY_NODE_SHOW_STREAMS_STMT,
378
  QUERY_NODE_SHOW_TABLES_STMT,
379
  QUERY_NODE_SHOW_TAGS_STMT,
380
  QUERY_NODE_SHOW_USERS_STMT,
381
  QUERY_NODE_SHOW_USERS_FULL_STMT,
382
  QUERY_NODE_SHOW_LICENCES_STMT,
383
  QUERY_NODE_SHOW_VGROUPS_STMT,
384
  QUERY_NODE_SHOW_TOPICS_STMT,
385
  QUERY_NODE_SHOW_CONSUMERS_STMT,
386
  QUERY_NODE_SHOW_CONNECTIONS_STMT,
387
  QUERY_NODE_SHOW_QUERIES_STMT,
388
  QUERY_NODE_SHOW_APPS_STMT,
389
  QUERY_NODE_SHOW_VARIABLES_STMT,
390
  QUERY_NODE_SHOW_DNODE_VARIABLES_STMT,
391
  QUERY_NODE_SHOW_TRANSACTIONS_STMT,
392
  QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
393
  QUERY_NODE_SHOW_VNODES_STMT,
394
  QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
395
  QUERY_NODE_SHOW_VIEWS_STMT,
396
  QUERY_NODE_SHOW_COMPACTS_STMT,
397
  QUERY_NODE_SHOW_COMPACT_DETAILS_STMT,
398
  QUERY_NODE_SHOW_GRANTS_FULL_STMT,
399
  QUERY_NODE_SHOW_GRANTS_LOGS_STMT,
400
  QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT,
401
  QUERY_NODE_SHOW_ENCRYPTIONS_STMT,
402
  QUERY_NODE_SHOW_TSMAS_STMT,
403
  QUERY_NODE_SHOW_ANODES_STMT,
404
  QUERY_NODE_SHOW_ANODES_FULL_STMT,
405
  QUERY_NODE_SHOW_USAGE_STMT,
406
  QUERY_NODE_CREATE_TSMA_STMT,
407
  QUERY_NODE_SHOW_CREATE_TSMA_STMT,
408
  QUERY_NODE_DROP_TSMA_STMT,
409
  QUERY_NODE_SHOW_FILESETS_STMT,
410
  QUERY_NODE_SHOW_TRANSACTION_DETAILS_STMT,
411

412
  // logic plan node
413
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
414
  QUERY_NODE_LOGIC_PLAN_JOIN,
415
  QUERY_NODE_LOGIC_PLAN_AGG,
416
  QUERY_NODE_LOGIC_PLAN_PROJECT,
417
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
418
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
419
  QUERY_NODE_LOGIC_PLAN_MERGE,
420
  QUERY_NODE_LOGIC_PLAN_WINDOW,
421
  QUERY_NODE_LOGIC_PLAN_FILL,
422
  QUERY_NODE_LOGIC_PLAN_SORT,
423
  QUERY_NODE_LOGIC_PLAN_PARTITION,
424
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
425
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
426
  QUERY_NODE_LOGIC_SUBPLAN,
427
  QUERY_NODE_LOGIC_PLAN,
428
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
429
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
430
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
431

432
  // physical plan node
433
  QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
434
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
435
  QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN,  // INACTIVE
436
  QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
437
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
438
  QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
439
  QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN,
440
  QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN,
441
  QUERY_NODE_PHYSICAL_PLAN_PROJECT,
442
  QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
443
  QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
444
  QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
445
  QUERY_NODE_PHYSICAL_PLAN_MERGE,
446
  QUERY_NODE_PHYSICAL_PLAN_SORT,
447
  QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
448
  QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
449
  QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,  // INACTIVE
450
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
451
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL,
452
  QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL,
453
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL,
454
  QUERY_NODE_PHYSICAL_PLAN_FILL,
455
  QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL,
456
  QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
457
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION,
458
  QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION,
459
  QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION,
460
  QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
461
  QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE,
462
  QUERY_NODE_PHYSICAL_PLAN_PARTITION,
463
  QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION,
464
  QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
465
  QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC,
466
  QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
467
  QUERY_NODE_PHYSICAL_PLAN_INSERT,
468
  QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT,
469
  QUERY_NODE_PHYSICAL_PLAN_DELETE,
470
  QUERY_NODE_PHYSICAL_SUBPLAN,
471
  QUERY_NODE_PHYSICAL_PLAN,
472
  QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN,
473
  QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT,
474
  QUERY_NODE_PHYSICAL_PLAN_STREAM_EVENT,
475
  QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN,
476
  QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE,
477
  QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL,
478
  QUERY_NODE_PHYSICAL_PLAN_MERGE_COUNT,
479
  QUERY_NODE_PHYSICAL_PLAN_STREAM_COUNT,
480
  QUERY_NODE_PHYSICAL_PLAN_STREAM_MID_INTERVAL,
481
  QUERY_NODE_PHYSICAL_PLAN_STREAM_CONTINUE_INTERVAL,
482
  QUERY_NODE_PHYSICAL_PLAN_MERGE_ANOMALY,
483
  QUERY_NODE_PHYSICAL_PLAN_STREAM_ANOMALY,
484
  QUERY_NODE_PHYSICAL_PLAN_FORECAST_FUNC,
485
  QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERP_FUNC,
486
  QUERY_NODE_RESET_STREAM_STMT,
487
} ENodeType;
488

489
typedef struct {
490
  int32_t     vgId;
491
  uint8_t     option;  // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
492
  const char* dbFName;
493
  const char* tbName;
494
} SBuildTableInput;
495

496
typedef struct {
497
  char    db[TSDB_DB_FNAME_LEN];
498
  int64_t dbId;
499
  int32_t vgVersion;
500
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
501
  int64_t stateTs;
502
} SBuildUseDBInput;
503

504
typedef struct SField {
505
  char    name[TSDB_COL_NAME_LEN];
506
  uint8_t type;
507
  int8_t  flags;
508
  int32_t bytes;
509
} SField;
510
typedef struct SFieldWithOptions {
511
  char     name[TSDB_COL_NAME_LEN];
512
  uint8_t  type;
513
  int8_t   flags;
514
  int32_t  bytes;
515
  uint32_t compress;
516
} SFieldWithOptions;
517

518
typedef struct SRetention {
519
  int64_t freq;
520
  int64_t keep;
521
  int8_t  freqUnit;
522
  int8_t  keepUnit;
523
} SRetention;
524

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

527
#pragma pack(push, 1)
528

529
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
530
typedef struct SEp {
531
  char     fqdn[TSDB_FQDN_LEN];
532
  uint16_t port;
533
} SEp;
534

535
typedef struct {
536
  int32_t contLen;
537
  int32_t vgId;
538
} SMsgHead;
539

540
// Submit message for one table
541
typedef struct SSubmitBlk {
542
  int64_t uid;        // table unique id
543
  int64_t suid;       // stable id
544
  int32_t sversion;   // data schema version
545
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
546
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
547
  int32_t numOfRows;  // total number of rows in current submit block
548
  char    data[];
549
} SSubmitBlk;
550

551
// Submit message for this TSDB
552
typedef struct {
553
  SMsgHead header;
554
  int64_t  version;
555
  int32_t  length;
556
  int32_t  numOfBlocks;
557
  char     blocks[];
558
} SSubmitReq;
559

560
typedef struct {
561
  int32_t totalLen;
562
  int32_t len;
563
  STSRow* row;
564
} SSubmitBlkIter;
565

566
typedef struct {
567
  int32_t totalLen;
568
  int32_t len;
569
  // head of SSubmitBlk
570
  int64_t uid;        // table unique id
571
  int64_t suid;       // stable id
572
  int32_t sversion;   // data schema version
573
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
574
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
575
  int32_t numOfRows;  // total number of rows in current submit block
576
  // head of SSubmitBlk
577
  int32_t     numOfBlocks;
578
  const void* pMsg;
579
} SSubmitMsgIter;
580

581
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
582
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
583
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
584
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
585
// for debug
586
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
587

588
struct SSchema {
589
  int8_t   type;
590
  int8_t   flags;
591
  col_id_t colId;
592
  int32_t  bytes;
593
  char     name[TSDB_COL_NAME_LEN];
594
};
595
struct SSchemaExt {
596
  col_id_t colId;
597
  uint32_t compress;
598
};
599

600
//
601

602
struct SSchema2 {
603
  int8_t   type;
604
  int8_t   flags;
605
  col_id_t colId;
606
  int32_t  bytes;
607
  char     name[TSDB_COL_NAME_LEN];
608
  uint32_t compress;
609
};
610

611
typedef struct {
612
  char        tbName[TSDB_TABLE_NAME_LEN];
613
  char        stbName[TSDB_TABLE_NAME_LEN];
614
  char        dbFName[TSDB_DB_FNAME_LEN];
615
  int64_t     dbId;
616
  int32_t     numOfTags;
617
  int32_t     numOfColumns;
618
  int8_t      precision;
619
  int8_t      tableType;
620
  int32_t     sversion;
621
  int32_t     tversion;
622
  uint64_t    suid;
623
  uint64_t    tuid;
624
  int32_t     vgId;
625
  int8_t      sysInfo;
626
  SSchema*    pSchemas;
627
  SSchemaExt* pSchemaExt;
628
} STableMetaRsp;
629

630
typedef struct {
631
  int32_t        code;
632
  int64_t        uid;
633
  char*          tblFName;
634
  int32_t        numOfRows;
635
  int32_t        affectedRows;
636
  int64_t        sver;
637
  STableMetaRsp* pMeta;
638
} SSubmitBlkRsp;
639

640
typedef struct {
641
  int32_t numOfRows;
642
  int32_t affectedRows;
643
  int32_t nBlocks;
644
  union {
645
    SArray*        pArray;
646
    SSubmitBlkRsp* pBlocks;
647
  };
648
} SSubmitRsp;
649

650
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
651
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
652
// void    tFreeSSubmitBlkRsp(void* param);
653
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
654

655
#define COL_SMA_ON     ((int8_t)0x1)
656
#define COL_IDX_ON     ((int8_t)0x2)
657
#define COL_IS_KEY     ((int8_t)0x4)
658
#define COL_SET_NULL   ((int8_t)0x10)
659
#define COL_SET_VAL    ((int8_t)0x20)
660
#define COL_IS_SYSINFO ((int8_t)0x40)
661

662
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
663
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
664

665
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
666
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
667
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
668

669
#define SSCHMEA_SET_IDX_ON(s) \
670
  do {                        \
671
    (s)->flags |= COL_IDX_ON; \
672
  } while (0)
673

674
#define SSCHMEA_SET_IDX_OFF(s)   \
675
  do {                           \
676
    (s)->flags &= (~COL_IDX_ON); \
677
  } while (0)
678

679
#define SSCHMEA_TYPE(s)  ((s)->type)
680
#define SSCHMEA_FLAGS(s) ((s)->flags)
681
#define SSCHMEA_COLID(s) ((s)->colId)
682
#define SSCHMEA_BYTES(s) ((s)->bytes)
683
#define SSCHMEA_NAME(s)  ((s)->name)
684

685
typedef struct {
686
  bool    tsEnableMonitor;
687
  int32_t tsMonitorInterval;
688
  int32_t tsSlowLogThreshold;
689
  int32_t tsSlowLogMaxLen;
690
  int32_t tsSlowLogScope;
691
  int32_t tsSlowLogThresholdTest;  // Obsolete
692
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
693
} SMonitorParas;
694

695
typedef struct {
696
  int32_t  nCols;
697
  int32_t  version;
698
  SSchema* pSchema;
699
} SSchemaWrapper;
700

701
typedef struct {
702
  col_id_t id;
703
  uint32_t alg;
704
} SColCmpr;
705

706
typedef struct {
707
  int32_t   nCols;
708
  int32_t   version;
709
  SColCmpr* pColCmpr;
710
} SColCmprWrapper;
711

712
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
713
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
714
    terrno = TSDB_CODE_INVALID_PARA;
715
    return NULL;
716
  }
717

718
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
719
  if (pDstWrapper == NULL) {
720
    return NULL;
721
  }
722
  pDstWrapper->nCols = pSrcWrapper->nCols;
723
  pDstWrapper->version = pSrcWrapper->version;
724

725
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
726
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
727
  if (pDstWrapper->pColCmpr == NULL) {
728
    taosMemoryFree(pDstWrapper);
729
    return NULL;
730
  }
731
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
732

733
  return pDstWrapper;
734
}
735

736
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
737
  if (!(!pCmpr->pColCmpr)) {
15,674!
738
    return TSDB_CODE_INVALID_PARA;
×
739
  }
740
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
15,674!
741
  if (pCmpr->pColCmpr == NULL) {
15,674!
742
    return terrno;
×
743
  }
744
  pCmpr->nCols = nCols;
15,674✔
745
  return 0;
15,674✔
746
}
747

748
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
749
  pCmpr->nCols = pSchema->nCols;
750
  if (!(!pCmpr->pColCmpr)) {
751
    return TSDB_CODE_INVALID_PARA;
752
  }
753
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
754
  if (pCmpr->pColCmpr == NULL) {
755
    return terrno;
756
  }
757
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
758
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
759
    SSchema*  pColSchema = &pSchema->pSchema[i];
760
    pColCmpr->id = pColSchema->colId;
761
    pColCmpr->alg = 0;
762
  }
763
  return 0;
764
}
765

766
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
767
  if (pWrapper == NULL) return;
768

769
  taosMemoryFreeClear(pWrapper->pColCmpr);
770
  taosMemoryFreeClear(pWrapper);
771
}
772
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
773
  if (pSchemaWrapper->pSchema == NULL) return NULL;
2,577,096!
774

775
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
2,577,096!
776
  if (pSW == NULL) {
2,576,820!
777
    return NULL;
×
778
  }
779
  pSW->nCols = pSchemaWrapper->nCols;
2,576,820✔
780
  pSW->version = pSchemaWrapper->version;
2,576,820✔
781
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
2,576,820!
782
  if (pSW->pSchema == NULL) {
2,575,890!
783
    taosMemoryFree(pSW);
×
784
    return NULL;
×
785
  }
786

787
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
2,575,890✔
788
  return pSW;
2,575,890✔
789
}
790

791
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
468,535✔
792
  if (pSchemaWrapper) {
6,388,973!
793
    taosMemoryFree(pSchemaWrapper->pSchema);
2,847,428!
794
    taosMemoryFree(pSchemaWrapper);
2,847,443!
795
  }
796
}
6,388,943✔
797

798
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,008✔
799
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,008!
800
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,008!
801
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,008!
802
  }
803
}
1,008✔
804

805
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
806
  int32_t tlen = 0;
52,042✔
807
  tlen += taosEncodeFixedI8(buf, pSchema->type);
104,084✔
808
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
52,042!
809
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
52,042!
810
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
52,042!
811
  tlen += taosEncodeString(buf, pSchema->name);
52,042✔
812
  return tlen;
52,042✔
813
}
814

815
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
816
  buf = taosDecodeFixedI8(buf, &pSchema->type);
48,052✔
817
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
24,026✔
818
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
24,026!
819
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
24,026!
820
  buf = taosDecodeStringTo(buf, pSchema->name);
24,026✔
821
  return (void*)buf;
24,026✔
822
}
823

824
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
825
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
27,785,898!
826
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
45,557,168!
827
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
45,557,168!
828
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
45,557,168!
829
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
45,557,168!
830
  return 0;
22,778,584✔
831
}
832

833
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
834
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
102,424,609!
835
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
199,810,436!
836
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
199,504,865!
837
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
199,531,407!
838
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
99,877,754!
839
  return 0;
100,012,359✔
840
}
841

842
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
843
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
7,469,744!
844
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
7,469,744!
845
  return 0;
3,734,872✔
846
}
847

848
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
849
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,803,365!
850
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,803,365!
851
  return 0;
1,901,682✔
852
}
853

854
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
855
  int32_t tlen = 0;
8,562✔
856
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,562✔
857
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,562✔
858
  for (int32_t i = 0; i < pSW->nCols; i++) {
60,604✔
859
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
104,084!
860
  }
861
  return tlen;
8,562✔
862
}
863

864
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
865
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
3,990✔
866
  buf = taosDecodeVariantI32(buf, &pSW->version);
3,990✔
867
  if (pSW->nCols > 0) {
3,990✔
868
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
2,689!
869
    if (pSW->pSchema == NULL) {
2,689!
870
      return NULL;
×
871
    }
872

873
    for (int32_t i = 0; i < pSW->nCols; i++) {
26,715✔
874
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
48,052✔
875
    }
876
  } else {
877
    pSW->pSchema = NULL;
1,301✔
878
  }
879
  return (void*)buf;
3,990✔
880
}
881

882
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
883
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,227,588!
884
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,227,588!
885
  for (int32_t i = 0; i < pSW->nCols; i++) {
18,385,064✔
886
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
35,542,540!
887
  }
888
  return 0;
613,794✔
889
}
890

891
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
892
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,035,218!
893
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,035,046!
894

895
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
517,467!
896
  if (pSW->pSchema == NULL) {
517,726!
897
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
898
  }
899
  for (int32_t i = 0; i < pSW->nCols; i++) {
8,140,215!
900
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
15,247,101!
901
  }
902

903
  return 0;
515,603✔
904
}
905

906
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
907
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
11,915,313!
908
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
11,915,943!
909

910
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
5,957,088!
911
  if (pSW->pSchema == NULL) {
5,959,389!
912
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
913
  }
914
  for (int32_t i = 0; i < pSW->nCols; i++) {
95,883,884✔
915
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
179,856,932!
916
  }
917

918
  return 0;
5,951,447✔
919
}
920

921
typedef struct {
922
  char     name[TSDB_TABLE_FNAME_LEN];
923
  int8_t   igExists;
924
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
925
  int8_t   reserved[6];
926
  tb_uid_t suid;
927
  int64_t  delay1;
928
  int64_t  delay2;
929
  int64_t  watermark1;
930
  int64_t  watermark2;
931
  int32_t  ttl;
932
  int32_t  colVer;
933
  int32_t  tagVer;
934
  int32_t  numOfColumns;
935
  int32_t  numOfTags;
936
  int32_t  numOfFuncs;
937
  int32_t  commentLen;
938
  int32_t  ast1Len;
939
  int32_t  ast2Len;
940
  SArray*  pColumns;  // array of SFieldWithOptions
941
  SArray*  pTags;     // array of SField
942
  SArray*  pFuncs;
943
  char*    pComment;
944
  char*    pAst1;
945
  char*    pAst2;
946
  int64_t  deleteMark1;
947
  int64_t  deleteMark2;
948
  int32_t  sqlLen;
949
  char*    sql;
950
} SMCreateStbReq;
951

952
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
953
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
954
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
955

956
typedef struct {
957
  STableMetaRsp* pMeta;
958
} SMCreateStbRsp;
959

960
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
961
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
962
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
963

964
typedef struct {
965
  char     name[TSDB_TABLE_FNAME_LEN];
966
  int8_t   igNotExists;
967
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
968
  int8_t   reserved[6];
969
  tb_uid_t suid;
970
  int32_t  sqlLen;
971
  char*    sql;
972
} SMDropStbReq;
973

974
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
975
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
976
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
977

978
typedef struct {
979
  char    name[TSDB_TABLE_FNAME_LEN];
980
  int8_t  alterType;
981
  int32_t numOfFields;
982
  SArray* pFields;
983
  int32_t ttl;
984
  int32_t commentLen;
985
  char*   comment;
986
  int32_t sqlLen;
987
  char*   sql;
988
} SMAlterStbReq;
989

990
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
991
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
992
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
993

994
typedef struct SEpSet {
995
  int8_t inUse;
996
  int8_t numOfEps;
997
  SEp    eps[TSDB_MAX_REPLICA];
998
} SEpSet;
999

1000
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1001
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1002
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1003
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1004

1005
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1006
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1007

1008
typedef struct {
1009
  int8_t  connType;
1010
  int32_t pid;
1011
  char    app[TSDB_APP_NAME_LEN];
1012
  char    db[TSDB_DB_NAME_LEN];
1013
  char    user[TSDB_USER_LEN];
1014
  char    passwd[TSDB_PASSWORD_LEN];
1015
  int64_t startTime;
1016
  char    sVer[TSDB_VERSION_LEN];
1017
} SConnectReq;
1018

1019
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1020
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1021

1022
typedef struct {
1023
  int32_t       acctId;
1024
  int64_t       clusterId;
1025
  uint32_t      connId;
1026
  int32_t       dnodeNum;
1027
  int8_t        superUser;
1028
  int8_t        sysInfo;
1029
  int8_t        connType;
1030
  SEpSet        epSet;
1031
  int32_t       svrTimestamp;
1032
  int32_t       passVer;
1033
  int32_t       authVer;
1034
  char          sVer[TSDB_VERSION_LEN];
1035
  char          sDetailVer[128];
1036
  int64_t       whiteListVer;
1037
  SMonitorParas monitorParas;
1038
  int8_t        enableAuditDelete;
1039
} SConnectRsp;
1040

1041
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1042
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1043

1044
typedef struct {
1045
  char    user[TSDB_USER_LEN];
1046
  char    pass[TSDB_PASSWORD_LEN];
1047
  int32_t maxUsers;
1048
  int32_t maxDbs;
1049
  int32_t maxTimeSeries;
1050
  int32_t maxStreams;
1051
  int32_t accessState;  // Configured only by command
1052
  int64_t maxStorage;
1053
} SCreateAcctReq, SAlterAcctReq;
1054

1055
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1056
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1057

1058
typedef struct {
1059
  char    user[TSDB_USER_LEN];
1060
  int32_t sqlLen;
1061
  char*   sql;
1062
} SDropUserReq, SDropAcctReq;
1063

1064
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1065
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1066
void    tFreeSDropUserReq(SDropUserReq* pReq);
1067

1068
typedef struct SIpV4Range {
1069
  uint32_t ip;
1070
  uint32_t mask;
1071
} SIpV4Range;
1072

1073
typedef struct {
1074
  int32_t    num;
1075
  SIpV4Range pIpRange[];
1076
} SIpWhiteList;
1077

1078
SIpWhiteList* cloneIpWhiteList(SIpWhiteList* pIpWhiteList);
1079
typedef struct {
1080
  int8_t      createType;
1081
  int8_t      superUser;  // denote if it is a super user or not
1082
  int8_t      sysInfo;
1083
  int8_t      enable;
1084
  char        user[TSDB_USER_LEN];
1085
  char        pass[TSDB_USET_PASSWORD_LEN];
1086
  int32_t     numIpRanges;
1087
  SIpV4Range* pIpRanges;
1088
  int32_t     sqlLen;
1089
  char*       sql;
1090
  int8_t      isImport;
1091
  int8_t      createDb;
1092
} SCreateUserReq;
1093

1094
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1095
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1096
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1097

1098
typedef struct {
1099
  int64_t     ver;
1100
  char        user[TSDB_USER_LEN];
1101
  int32_t     numOfRange;
1102
  SIpV4Range* pIpRanges;
1103
} SUpdateUserIpWhite;
1104
typedef struct {
1105
  int64_t             ver;
1106
  int                 numOfUser;
1107
  SUpdateUserIpWhite* pUserIpWhite;
1108
} SUpdateIpWhite;
1109

1110
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1111
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1112
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1113
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1114

1115
typedef struct {
1116
  int64_t ipWhiteVer;
1117
} SRetrieveIpWhiteReq;
1118

1119
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1120
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1121

1122
typedef struct {
1123
  int32_t dnodeId;
1124
  int64_t analVer;
1125
} SRetrieveAnalAlgoReq;
1126

1127
typedef struct {
1128
  int64_t   ver;
1129
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1130
} SRetrieveAnalAlgoRsp;
1131

1132
int32_t tSerializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1133
int32_t tDeserializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1134
int32_t tSerializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1135
int32_t tDeserializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1136
void    tFreeRetrieveAnalAlgoRsp(SRetrieveAnalAlgoRsp* pRsp);
1137

1138
typedef struct {
1139
  int8_t alterType;
1140
  int8_t superUser;
1141
  int8_t sysInfo;
1142
  int8_t enable;
1143
  int8_t isView;
1144
  union {
1145
    uint8_t flag;
1146
    struct {
1147
      uint8_t createdb : 1;
1148
      uint8_t reserve : 7;
1149
    };
1150
  };
1151
  char        user[TSDB_USER_LEN];
1152
  char        pass[TSDB_USET_PASSWORD_LEN];
1153
  char        objname[TSDB_DB_FNAME_LEN];  // db or topic
1154
  char        tabName[TSDB_TABLE_NAME_LEN];
1155
  char*       tagCond;
1156
  int32_t     tagCondLen;
1157
  int32_t     numIpRanges;
1158
  SIpV4Range* pIpRanges;
1159
  int64_t     privileges;
1160
  int32_t     sqlLen;
1161
  char*       sql;
1162
} SAlterUserReq;
1163

1164
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1165
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1166
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1167

1168
typedef struct {
1169
  char user[TSDB_USER_LEN];
1170
} SGetUserAuthReq;
1171

1172
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1173
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1174

1175
typedef struct {
1176
  char      user[TSDB_USER_LEN];
1177
  int32_t   version;
1178
  int32_t   passVer;
1179
  int8_t    superAuth;
1180
  int8_t    sysInfo;
1181
  int8_t    enable;
1182
  int8_t    dropped;
1183
  SHashObj* createdDbs;
1184
  SHashObj* readDbs;
1185
  SHashObj* writeDbs;
1186
  SHashObj* readTbs;
1187
  SHashObj* writeTbs;
1188
  SHashObj* alterTbs;
1189
  SHashObj* readViews;
1190
  SHashObj* writeViews;
1191
  SHashObj* alterViews;
1192
  SHashObj* useDbs;
1193
  int64_t   whiteListVer;
1194
} SGetUserAuthRsp;
1195

1196
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1197
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1198
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1199

1200
typedef struct {
1201
  char user[TSDB_USER_LEN];
1202
} SGetUserWhiteListReq;
1203

1204
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1205
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1206

1207
typedef struct {
1208
  char        user[TSDB_USER_LEN];
1209
  int32_t     numWhiteLists;
1210
  SIpV4Range* pWhiteLists;
1211
} SGetUserWhiteListRsp;
1212

1213
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1214
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1215
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1216

1217
/*
1218
 * for client side struct, only column id, type, bytes are necessary
1219
 * But for data in vnode side, we need all the following information.
1220
 */
1221
typedef struct {
1222
  union {
1223
    col_id_t colId;
1224
    int16_t  slotId;
1225
  };
1226

1227
  uint8_t precision;
1228
  uint8_t scale;
1229
  int32_t bytes;
1230
  int8_t  type;
1231
  uint8_t pk;
1232
  bool    noData;
1233
} SColumnInfo;
1234

1235
typedef struct STimeWindow {
1236
  TSKEY skey;
1237
  TSKEY ekey;
1238
} STimeWindow;
1239

1240
typedef struct SQueryHint {
1241
  bool batchScan;
1242
} SQueryHint;
1243

1244
typedef struct {
1245
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1246
  int32_t tsLen;          // total length of ts comp block
1247
  int32_t tsNumOfBlocks;  // ts comp block numbers
1248
  int32_t tsOrder;        // ts comp block order
1249
} STsBufInfo;
1250

1251
typedef struct {
1252
  void*       timezone;
1253
  char        intervalUnit;
1254
  char        slidingUnit;
1255
  char        offsetUnit;
1256
  int8_t      precision;
1257
  int64_t     interval;
1258
  int64_t     sliding;
1259
  int64_t     offset;
1260
  STimeWindow timeRange;
1261
} SInterval;
1262

1263
typedef struct STbVerInfo {
1264
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1265
  int32_t sversion;
1266
  int32_t tversion;
1267
} STbVerInfo;
1268

1269
typedef struct {
1270
  int32_t code;
1271
  int64_t affectedRows;
1272
  SArray* tbVerInfo;  // STbVerInfo
1273
} SQueryTableRsp;
1274

1275
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1276

1277
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1278

1279
typedef struct {
1280
  SMsgHead header;
1281
  char     dbFName[TSDB_DB_FNAME_LEN];
1282
  char     tbName[TSDB_TABLE_NAME_LEN];
1283
} STableCfgReq;
1284

1285
typedef struct {
1286
  char        tbName[TSDB_TABLE_NAME_LEN];
1287
  char        stbName[TSDB_TABLE_NAME_LEN];
1288
  char        dbFName[TSDB_DB_FNAME_LEN];
1289
  int32_t     numOfTags;
1290
  int32_t     numOfColumns;
1291
  int8_t      tableType;
1292
  int64_t     delay1;
1293
  int64_t     delay2;
1294
  int64_t     watermark1;
1295
  int64_t     watermark2;
1296
  int32_t     ttl;
1297
  SArray*     pFuncs;
1298
  int32_t     commentLen;
1299
  char*       pComment;
1300
  SSchema*    pSchemas;
1301
  int32_t     tagsLen;
1302
  char*       pTags;
1303
  SSchemaExt* pSchemaExt;
1304
} STableCfg;
1305

1306
typedef STableCfg STableCfgRsp;
1307

1308
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1309
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1310

1311
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1312
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1313
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1314

1315
typedef struct {
1316
  char    db[TSDB_DB_FNAME_LEN];
1317
  int32_t numOfVgroups;
1318
  int32_t numOfStables;  // single_stable
1319
  int32_t buffer;        // MB
1320
  int32_t pageSize;
1321
  int32_t pages;
1322
  int32_t cacheLastSize;
1323
  int32_t daysPerFile;
1324
  int32_t daysToKeep0;
1325
  int32_t daysToKeep1;
1326
  int32_t daysToKeep2;
1327
  int32_t keepTimeOffset;
1328
  int32_t minRows;
1329
  int32_t maxRows;
1330
  int32_t walFsyncPeriod;
1331
  int8_t  walLevel;
1332
  int8_t  precision;  // time resolution
1333
  int8_t  compression;
1334
  int8_t  replications;
1335
  int8_t  strict;
1336
  int8_t  cacheLast;
1337
  int8_t  schemaless;
1338
  int8_t  ignoreExist;
1339
  int32_t numOfRetensions;
1340
  SArray* pRetensions;  // SRetention
1341
  int32_t walRetentionPeriod;
1342
  int64_t walRetentionSize;
1343
  int32_t walRollPeriod;
1344
  int64_t walSegmentSize;
1345
  int32_t sstTrigger;
1346
  int16_t hashPrefix;
1347
  int16_t hashSuffix;
1348
  int32_t s3ChunkSize;
1349
  int32_t s3KeepLocal;
1350
  int8_t  s3Compact;
1351
  int32_t tsdbPageSize;
1352
  int32_t sqlLen;
1353
  char*   sql;
1354
  int8_t  withArbitrator;
1355
  int8_t  encryptAlgorithm;
1356
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1357
  // 1. add auto-compact parameters
1358
  int32_t compactInterval;  // minutes
1359
  int32_t compactStartTime; // minutes
1360
  int32_t compactEndTime;   // minutes
1361
  int8_t compactTimeOffset; // hour
1362
} SCreateDbReq;
1363

1364
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1365
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1366
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1367

1368
typedef struct {
1369
  char    db[TSDB_DB_FNAME_LEN];
1370
  int32_t buffer;
1371
  int32_t pageSize;
1372
  int32_t pages;
1373
  int32_t cacheLastSize;
1374
  int32_t daysPerFile;
1375
  int32_t daysToKeep0;
1376
  int32_t daysToKeep1;
1377
  int32_t daysToKeep2;
1378
  int32_t keepTimeOffset;
1379
  int32_t walFsyncPeriod;
1380
  int8_t  walLevel;
1381
  int8_t  strict;
1382
  int8_t  cacheLast;
1383
  int8_t  replications;
1384
  int32_t sstTrigger;
1385
  int32_t minRows;
1386
  int32_t walRetentionPeriod;
1387
  int32_t walRetentionSize;
1388
  int32_t s3KeepLocal;
1389
  int8_t  s3Compact;
1390
  int32_t sqlLen;
1391
  char*   sql;
1392
  int8_t  withArbitrator;
1393
  // 1. add auto-compact parameters
1394
  int32_t compactInterval;
1395
  int32_t compactStartTime;
1396
  int32_t compactEndTime;
1397
  int8_t  compactTimeOffset;
1398
} SAlterDbReq;
1399

1400
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1401
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1402
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1403

1404
typedef struct {
1405
  char    db[TSDB_DB_FNAME_LEN];
1406
  int8_t  ignoreNotExists;
1407
  int32_t sqlLen;
1408
  char*   sql;
1409
} SDropDbReq;
1410

1411
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1412
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1413
void    tFreeSDropDbReq(SDropDbReq* pReq);
1414

1415
typedef struct {
1416
  char    db[TSDB_DB_FNAME_LEN];
1417
  int64_t uid;
1418
} SDropDbRsp;
1419

1420
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1421
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1422

1423
typedef struct {
1424
  char    db[TSDB_DB_FNAME_LEN];
1425
  int64_t dbId;
1426
  int32_t vgVersion;
1427
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1428
  int64_t stateTs;     // ms
1429
} SUseDbReq;
1430

1431
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1432
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1433

1434
typedef struct {
1435
  char    db[TSDB_DB_FNAME_LEN];
1436
  int64_t uid;
1437
  int32_t vgVersion;
1438
  int32_t vgNum;
1439
  int16_t hashPrefix;
1440
  int16_t hashSuffix;
1441
  int8_t  hashMethod;
1442
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1443
  int32_t errCode;
1444
  int64_t stateTs;  // ms
1445
} SUseDbRsp;
1446

1447
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1448
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1449
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1450
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1451
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1452

1453
typedef struct {
1454
  char db[TSDB_DB_FNAME_LEN];
1455
} SDbCfgReq;
1456

1457
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1458
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1459

1460
typedef struct {
1461
  char    db[TSDB_DB_FNAME_LEN];
1462
  int32_t maxSpeed;
1463
} STrimDbReq;
1464

1465
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1466
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1467

1468
typedef struct {
1469
  int32_t timestamp;
1470
} SVTrimDbReq;
1471

1472
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1473
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1474

1475
typedef struct {
1476
  char db[TSDB_DB_FNAME_LEN];
1477
} SS3MigrateDbReq;
1478

1479
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1480
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1481

1482
typedef struct {
1483
  int32_t timestamp;
1484
} SVS3MigrateDbReq;
1485

1486
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1487
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1488

1489
typedef struct {
1490
  int32_t timestampSec;
1491
  int32_t ttlDropMaxCount;
1492
  int32_t nUids;
1493
  SArray* pTbUids;
1494
} SVDropTtlTableReq;
1495

1496
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1497
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1498

1499
typedef struct {
1500
  char    db[TSDB_DB_FNAME_LEN];
1501
  int64_t dbId;
1502
  int32_t cfgVersion;
1503
  int32_t numOfVgroups;
1504
  int32_t numOfStables;
1505
  int32_t buffer;
1506
  int32_t cacheSize;
1507
  int32_t pageSize;
1508
  int32_t pages;
1509
  int32_t daysPerFile;
1510
  int32_t daysToKeep0;
1511
  int32_t daysToKeep1;
1512
  int32_t daysToKeep2;
1513
  int32_t keepTimeOffset;
1514
  int32_t minRows;
1515
  int32_t maxRows;
1516
  int32_t walFsyncPeriod;
1517
  int16_t hashPrefix;
1518
  int16_t hashSuffix;
1519
  int8_t  hashMethod;
1520
  int8_t  walLevel;
1521
  int8_t  precision;
1522
  int8_t  compression;
1523
  int8_t  replications;
1524
  int8_t  strict;
1525
  int8_t  cacheLast;
1526
  int8_t  encryptAlgorithm;
1527
  int32_t s3ChunkSize;
1528
  int32_t s3KeepLocal;
1529
  int8_t  s3Compact;
1530
  int8_t  compactTimeOffset;
1531
  int32_t compactInterval;
1532
  int32_t compactStartTime;
1533
  int32_t compactEndTime;
1534
  int32_t tsdbPageSize;
1535
  int32_t walRetentionPeriod;
1536
  int32_t walRollPeriod;
1537
  int64_t walRetentionSize;
1538
  int64_t walSegmentSize;
1539
  int32_t numOfRetensions;
1540
  SArray* pRetensions;
1541
  int8_t  schemaless;
1542
  int16_t sstTrigger;
1543
  int8_t  withArbitrator;
1544
} SDbCfgRsp;
1545

1546
typedef SDbCfgRsp SDbCfgInfo;
1547

1548
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1549
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1550
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1551
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1552
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1553

1554
typedef struct {
1555
  int32_t rowNum;
1556
} SQnodeListReq;
1557

1558
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1559
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1560

1561
typedef struct {
1562
  int32_t rowNum;
1563
} SDnodeListReq;
1564

1565
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1566

1567
typedef struct {
1568
  int32_t useless;  // useless
1569
} SServerVerReq;
1570

1571
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1572
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1573

1574
typedef struct {
1575
  char ver[TSDB_VERSION_LEN];
1576
} SServerVerRsp;
1577

1578
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1579
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1580

1581
typedef struct SQueryNodeAddr {
1582
  int32_t nodeId;  // vgId or qnodeId
1583
  SEpSet  epSet;
1584
} SQueryNodeAddr;
1585

1586
typedef struct {
1587
  SQueryNodeAddr addr;
1588
  uint64_t       load;
1589
} SQueryNodeLoad;
1590

1591
typedef struct {
1592
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1593
} SQnodeListRsp;
1594

1595
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1596
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1597
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1598

1599
typedef struct {
1600
  SArray* dnodeList;  // SArray<SEpSet>
1601
} SDnodeListRsp;
1602

1603
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1604
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1605
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1606

1607
typedef struct {
1608
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1609
} STableTSMAInfoRsp;
1610

1611
typedef struct {
1612
  SUseDbRsp*         useDbRsp;
1613
  SDbCfgRsp*         cfgRsp;
1614
  STableTSMAInfoRsp* pTsmaRsp;
1615
  int32_t            dbTsmaVersion;
1616
  char               db[TSDB_DB_FNAME_LEN];
1617
  int64_t            dbId;
1618
} SDbHbRsp;
1619

1620
typedef struct {
1621
  SArray* pArray;  // Array of SDbHbRsp
1622
} SDbHbBatchRsp;
1623

1624
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1625
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1626
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1627

1628
typedef struct {
1629
  SArray* pArray;  // Array of SGetUserAuthRsp
1630
} SUserAuthBatchRsp;
1631

1632
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1633
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1634
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1635

1636
typedef struct {
1637
  char        db[TSDB_DB_FNAME_LEN];
1638
  STimeWindow timeRange;
1639
  int32_t     sqlLen;
1640
  char*       sql;
1641
  SArray*     vgroupIds;
1642
} SCompactDbReq;
1643

1644
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1645
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1646
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1647

1648
typedef struct {
1649
  int32_t compactId;
1650
  int8_t  bAccepted;
1651
} SCompactDbRsp;
1652

1653
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1654
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1655

1656
typedef struct {
1657
  int32_t compactId;
1658
  int32_t sqlLen;
1659
  char*   sql;
1660
} SKillCompactReq;
1661

1662
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1663
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1664
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1665

1666
typedef struct {
1667
  char    name[TSDB_FUNC_NAME_LEN];
1668
  int8_t  igExists;
1669
  int8_t  funcType;
1670
  int8_t  scriptType;
1671
  int8_t  outputType;
1672
  int32_t outputLen;
1673
  int32_t bufSize;
1674
  int32_t codeLen;
1675
  int64_t signature;
1676
  char*   pComment;
1677
  char*   pCode;
1678
  int8_t  orReplace;
1679
} SCreateFuncReq;
1680

1681
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1682
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1683
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1684

1685
typedef struct {
1686
  char   name[TSDB_FUNC_NAME_LEN];
1687
  int8_t igNotExists;
1688
} SDropFuncReq;
1689

1690
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1691
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1692

1693
typedef struct {
1694
  int32_t numOfFuncs;
1695
  bool    ignoreCodeComment;
1696
  SArray* pFuncNames;
1697
} SRetrieveFuncReq;
1698

1699
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1700
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1701
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1702

1703
typedef struct {
1704
  char    name[TSDB_FUNC_NAME_LEN];
1705
  int8_t  funcType;
1706
  int8_t  scriptType;
1707
  int8_t  outputType;
1708
  int32_t outputLen;
1709
  int32_t bufSize;
1710
  int64_t signature;
1711
  int32_t commentSize;
1712
  int32_t codeSize;
1713
  char*   pComment;
1714
  char*   pCode;
1715
} SFuncInfo;
1716

1717
typedef struct {
1718
  int32_t funcVersion;
1719
  int64_t funcCreatedTime;
1720
} SFuncExtraInfo;
1721

1722
typedef struct {
1723
  int32_t numOfFuncs;
1724
  SArray* pFuncInfos;
1725
  SArray* pFuncExtraInfos;
1726
} SRetrieveFuncRsp;
1727

1728
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1729
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1730
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1731
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1732

1733
typedef struct {
1734
  int32_t       statusInterval;
1735
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
1736
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
1737
  char          locale[TD_LOCALE_LEN];      // tsLocale
1738
  char          charset[TD_LOCALE_LEN];     // tsCharset
1739
  int8_t        ttlChangeOnWrite;
1740
  int8_t        enableWhiteList;
1741
  int8_t        encryptionKeyStat;
1742
  uint32_t      encryptionKeyChksum;
1743
  SMonitorParas monitorParas;
1744
} SClusterCfg;
1745

1746
typedef struct {
1747
  int32_t openVnodes;
1748
  int32_t dropVnodes;
1749
  int32_t totalVnodes;
1750
  int32_t masterNum;
1751
  int64_t numOfSelectReqs;
1752
  int64_t numOfInsertReqs;
1753
  int64_t numOfInsertSuccessReqs;
1754
  int64_t numOfBatchInsertReqs;
1755
  int64_t numOfBatchInsertSuccessReqs;
1756
  int64_t errors;
1757
} SVnodesStat;
1758

1759
typedef struct {
1760
  int32_t vgId;
1761
  int8_t  syncState;
1762
  int8_t  syncRestore;
1763
  int64_t syncTerm;
1764
  int64_t roleTimeMs;
1765
  int64_t startTimeMs;
1766
  int8_t  syncCanRead;
1767
  int64_t cacheUsage;
1768
  int64_t numOfTables;
1769
  int64_t numOfTimeSeries;
1770
  int64_t totalStorage;
1771
  int64_t compStorage;
1772
  int64_t pointsWritten;
1773
  int64_t numOfSelectReqs;
1774
  int64_t numOfInsertReqs;
1775
  int64_t numOfInsertSuccessReqs;
1776
  int64_t numOfBatchInsertReqs;
1777
  int64_t numOfBatchInsertSuccessReqs;
1778
  int32_t numOfCachedTables;
1779
  int32_t learnerProgress;  // use one reservered
1780
} SVnodeLoad;
1781

1782
typedef struct {
1783
  int32_t     vgId;
1784
  int64_t     numOfTables;
1785
  int64_t     memSize;
1786
  int64_t     l1Size;
1787
  int64_t     l2Size;
1788
  int64_t     l3Size;
1789
  int64_t     cacheSize;
1790
  int64_t     walSize;
1791
  int64_t     metaSize;
1792
  int64_t     rawDataSize;
1793
  int64_t     s3Size;
1794
  const char* dbname;
1795
} SDbSizeStatisInfo;
1796

1797
typedef struct {
1798
  int32_t vgId;
1799
  int64_t nTimeSeries;
1800
} SVnodeLoadLite;
1801

1802
typedef struct {
1803
  int8_t  syncState;
1804
  int64_t syncTerm;
1805
  int8_t  syncRestore;
1806
  int64_t roleTimeMs;
1807
} SMnodeLoad;
1808

1809
typedef struct {
1810
  int32_t dnodeId;
1811
  int64_t numOfProcessedQuery;
1812
  int64_t numOfProcessedCQuery;
1813
  int64_t numOfProcessedFetch;
1814
  int64_t numOfProcessedDrop;
1815
  int64_t numOfProcessedNotify;
1816
  int64_t numOfProcessedHb;
1817
  int64_t numOfProcessedDelete;
1818
  int64_t cacheDataSize;
1819
  int64_t numOfQueryInQueue;
1820
  int64_t numOfFetchInQueue;
1821
  int64_t timeInQueryQueue;
1822
  int64_t timeInFetchQueue;
1823
} SQnodeLoad;
1824

1825
typedef struct {
1826
  int32_t     sver;      // software version
1827
  int64_t     dnodeVer;  // dnode table version in sdb
1828
  int32_t     dnodeId;
1829
  int64_t     clusterId;
1830
  int64_t     rebootTime;
1831
  int64_t     updateTime;
1832
  float       numOfCores;
1833
  int32_t     numOfSupportVnodes;
1834
  int32_t     numOfDiskCfg;
1835
  int64_t     memTotal;
1836
  int64_t     memAvail;
1837
  char        dnodeEp[TSDB_EP_LEN];
1838
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
1839
  SMnodeLoad  mload;
1840
  SQnodeLoad  qload;
1841
  SClusterCfg clusterCfg;
1842
  SArray*     pVloads;  // array of SVnodeLoad
1843
  int32_t     statusSeq;
1844
  int64_t     ipWhiteVer;
1845
  int64_t     analVer;
1846
} SStatusReq;
1847

1848
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1849
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1850
void    tFreeSStatusReq(SStatusReq* pReq);
1851

1852
typedef struct {
1853
  int32_t forceReadConfig;
1854
  int32_t cver;
1855
  SArray* array;
1856
} SConfigReq;
1857

1858
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
1859
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
1860
void    tFreeSConfigReq(SConfigReq* pReq);
1861

1862
typedef struct {
1863
  int32_t dnodeId;
1864
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
1865
} SDnodeInfoReq;
1866

1867
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1868
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1869

1870
typedef enum {
1871
  MONITOR_TYPE_COUNTER = 0,
1872
  MONITOR_TYPE_SLOW_LOG = 1,
1873
} MONITOR_TYPE;
1874

1875
typedef struct {
1876
  int32_t      contLen;
1877
  char*        pCont;
1878
  MONITOR_TYPE type;
1879
} SStatisReq;
1880

1881
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1882
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1883
void    tFreeSStatisReq(SStatisReq* pReq);
1884

1885
typedef struct {
1886
  char    db[TSDB_DB_FNAME_LEN];
1887
  char    table[TSDB_TABLE_NAME_LEN];
1888
  char    operation[AUDIT_OPERATION_LEN];
1889
  int32_t sqlLen;
1890
  char*   pSql;
1891
} SAuditReq;
1892
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
1893
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
1894
void    tFreeSAuditReq(SAuditReq* pReq);
1895

1896
typedef struct {
1897
  int32_t dnodeId;
1898
  int64_t clusterId;
1899
  SArray* pVloads;
1900
} SNotifyReq;
1901

1902
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1903
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1904
void    tFreeSNotifyReq(SNotifyReq* pReq);
1905

1906
typedef struct {
1907
  int32_t dnodeId;
1908
  int64_t clusterId;
1909
} SDnodeCfg;
1910

1911
typedef struct {
1912
  int32_t id;
1913
  int8_t  isMnode;
1914
  SEp     ep;
1915
} SDnodeEp;
1916

1917
typedef struct {
1918
  int32_t id;
1919
  int8_t  isMnode;
1920
  int8_t  offlineReason;
1921
  SEp     ep;
1922
  char    active[TSDB_ACTIVE_KEY_LEN];
1923
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
1924
} SDnodeInfo;
1925

1926
typedef struct {
1927
  int64_t   dnodeVer;
1928
  SDnodeCfg dnodeCfg;
1929
  SArray*   pDnodeEps;  // Array of SDnodeEp
1930
  int32_t   statusSeq;
1931
  int64_t   ipWhiteVer;
1932
  int64_t   analVer;
1933
} SStatusRsp;
1934

1935
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1936
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1937
void    tFreeSStatusRsp(SStatusRsp* pRsp);
1938

1939
typedef struct {
1940
  int32_t forceReadConfig;
1941
  int32_t isConifgVerified;
1942
  int32_t isVersionVerified;
1943
  int32_t cver;
1944
  SArray* array;
1945
} SConfigRsp;
1946

1947
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
1948
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
1949
void    tFreeSConfigRsp(SConfigRsp* pRsp);
1950

1951
typedef struct {
1952
  int32_t reserved;
1953
} SMTimerReq;
1954

1955
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1956
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1957

1958
typedef struct SOrphanTask {
1959
  int64_t streamId;
1960
  int32_t taskId;
1961
  int32_t nodeId;
1962
} SOrphanTask;
1963

1964
typedef struct SMStreamDropOrphanMsg {
1965
  SArray* pList;  // SArray<SOrphanTask>
1966
} SMStreamDropOrphanMsg;
1967

1968
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1969
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1970
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
1971

1972
typedef struct {
1973
  int32_t  id;
1974
  uint16_t port;                 // node sync Port
1975
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
1976
} SReplica;
1977

1978
typedef struct {
1979
  int32_t  vgId;
1980
  char     db[TSDB_DB_FNAME_LEN];
1981
  int64_t  dbUid;
1982
  int32_t  vgVersion;
1983
  int32_t  numOfStables;
1984
  int32_t  buffer;
1985
  int32_t  pageSize;
1986
  int32_t  pages;
1987
  int32_t  cacheLastSize;
1988
  int32_t  daysPerFile;
1989
  int32_t  daysToKeep0;
1990
  int32_t  daysToKeep1;
1991
  int32_t  daysToKeep2;
1992
  int32_t  keepTimeOffset;
1993
  int32_t  minRows;
1994
  int32_t  maxRows;
1995
  int32_t  walFsyncPeriod;
1996
  uint32_t hashBegin;
1997
  uint32_t hashEnd;
1998
  int8_t   hashMethod;
1999
  int8_t   walLevel;
2000
  int8_t   precision;
2001
  int8_t   compression;
2002
  int8_t   strict;
2003
  int8_t   cacheLast;
2004
  int8_t   isTsma;
2005
  int8_t   replica;
2006
  int8_t   selfIndex;
2007
  SReplica replicas[TSDB_MAX_REPLICA];
2008
  int32_t  numOfRetensions;
2009
  SArray*  pRetensions;  // SRetention
2010
  void*    pTsma;
2011
  int32_t  walRetentionPeriod;
2012
  int64_t  walRetentionSize;
2013
  int32_t  walRollPeriod;
2014
  int64_t  walSegmentSize;
2015
  int16_t  sstTrigger;
2016
  int16_t  hashPrefix;
2017
  int16_t  hashSuffix;
2018
  int32_t  tsdbPageSize;
2019
  int32_t  s3ChunkSize;
2020
  int32_t  s3KeepLocal;
2021
  int8_t   s3Compact;
2022
  int64_t  reserved[6];
2023
  int8_t   learnerReplica;
2024
  int8_t   learnerSelfIndex;
2025
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2026
  int32_t  changeVersion;
2027
  int8_t   encryptAlgorithm;
2028
} SCreateVnodeReq;
2029

2030
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2031
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2032
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2033

2034
typedef struct {
2035
  int32_t compactId;
2036
  int32_t vgId;
2037
  int32_t dnodeId;
2038
} SQueryCompactProgressReq;
2039

2040
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2041
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2042

2043
typedef struct {
2044
  int32_t compactId;
2045
  int32_t vgId;
2046
  int32_t dnodeId;
2047
  int32_t numberFileset;
2048
  int32_t finished;
2049
  int32_t progress;
2050
  int64_t remainingTime;
2051
} SQueryCompactProgressRsp;
2052

2053
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2054
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2055

2056
typedef struct {
2057
  int32_t vgId;
2058
  int32_t dnodeId;
2059
  int64_t dbUid;
2060
  char    db[TSDB_DB_FNAME_LEN];
2061
  int64_t reserved[8];
2062
} SDropVnodeReq;
2063

2064
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2065
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2066

2067
typedef struct {
2068
  char    colName[TSDB_COL_NAME_LEN];
2069
  char    stb[TSDB_TABLE_FNAME_LEN];
2070
  int64_t stbUid;
2071
  int64_t dbUid;
2072
  int64_t reserved[8];
2073
} SDropIndexReq;
2074

2075
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2076
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2077

2078
typedef struct {
2079
  int64_t     dbUid;
2080
  char        db[TSDB_DB_FNAME_LEN];
2081
  int64_t     compactStartTime;
2082
  STimeWindow tw;
2083
  int32_t     compactId;
2084
} SCompactVnodeReq;
2085

2086
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2087
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2088

2089
typedef struct {
2090
  int32_t compactId;
2091
  int32_t vgId;
2092
  int32_t dnodeId;
2093
} SVKillCompactReq;
2094

2095
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2096
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2097

2098
typedef struct {
2099
  int32_t vgVersion;
2100
  int32_t buffer;
2101
  int32_t pageSize;
2102
  int32_t pages;
2103
  int32_t cacheLastSize;
2104
  int32_t daysPerFile;
2105
  int32_t daysToKeep0;
2106
  int32_t daysToKeep1;
2107
  int32_t daysToKeep2;
2108
  int32_t keepTimeOffset;
2109
  int32_t walFsyncPeriod;
2110
  int8_t  walLevel;
2111
  int8_t  strict;
2112
  int8_t  cacheLast;
2113
  int64_t reserved[7];
2114
  // 1st modification
2115
  int16_t sttTrigger;
2116
  int32_t minRows;
2117
  // 2nd modification
2118
  int32_t walRetentionPeriod;
2119
  int32_t walRetentionSize;
2120
  int32_t s3KeepLocal;
2121
  int8_t  s3Compact;
2122
} SAlterVnodeConfigReq;
2123

2124
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2125
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2126

2127
typedef struct {
2128
  int32_t  vgId;
2129
  int8_t   strict;
2130
  int8_t   selfIndex;
2131
  int8_t   replica;
2132
  SReplica replicas[TSDB_MAX_REPLICA];
2133
  int64_t  reserved[8];
2134
  int8_t   learnerSelfIndex;
2135
  int8_t   learnerReplica;
2136
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2137
  int32_t  changeVersion;
2138
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2139

2140
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2141
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2142

2143
typedef struct {
2144
  int32_t vgId;
2145
  int8_t  disable;
2146
} SDisableVnodeWriteReq;
2147

2148
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2149
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2150

2151
typedef struct {
2152
  int32_t  srcVgId;
2153
  int32_t  dstVgId;
2154
  uint32_t hashBegin;
2155
  uint32_t hashEnd;
2156
  int32_t  changeVersion;
2157
  int32_t  reserved;
2158
} SAlterVnodeHashRangeReq;
2159

2160
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2161
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2162

2163
#define REQ_OPT_TBNAME 0x0
2164
#define REQ_OPT_TBUID  0x01
2165
typedef struct {
2166
  SMsgHead header;
2167
  char     dbFName[TSDB_DB_FNAME_LEN];
2168
  char     tbName[TSDB_TABLE_NAME_LEN];
2169
  uint8_t  option;
2170
} STableInfoReq;
2171

2172
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2173
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2174

2175
typedef struct {
2176
  int8_t  metaClone;  // create local clone of the cached table meta
2177
  int32_t numOfVgroups;
2178
  int32_t numOfTables;
2179
  int32_t numOfUdfs;
2180
  char    tableNames[];
2181
} SMultiTableInfoReq;
2182

2183
// todo refactor
2184
typedef struct SVgroupInfo {
2185
  int32_t  vgId;
2186
  uint32_t hashBegin;
2187
  uint32_t hashEnd;
2188
  SEpSet   epSet;
2189
  union {
2190
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2191
    int32_t taskId;      // used in stream
2192
  };
2193
} SVgroupInfo;
2194

2195
typedef struct {
2196
  int32_t     numOfVgroups;
2197
  SVgroupInfo vgroups[];
2198
} SVgroupsInfo;
2199

2200
typedef struct {
2201
  STableMetaRsp* pMeta;
2202
} SMAlterStbRsp;
2203

2204
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2205
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2206
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2207

2208
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2209
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2210
void    tFreeSTableMetaRsp(void* pRsp);
2211
void    tFreeSTableIndexRsp(void* info);
2212

2213
typedef struct {
2214
  SArray* pMetaRsp;   // Array of STableMetaRsp
2215
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2216
} SSTbHbRsp;
2217

2218
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2219
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2220
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2221

2222
typedef struct {
2223
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2224
} SViewHbRsp;
2225

2226
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2227
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2228
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2229

2230
typedef struct {
2231
  int32_t numOfTables;
2232
  int32_t numOfVgroup;
2233
  int32_t numOfUdf;
2234
  int32_t contLen;
2235
  int8_t  compressed;  // denote if compressed or not
2236
  int32_t rawLen;      // size before compress
2237
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2238
  char    meta[];
2239
} SMultiTableMeta;
2240

2241
typedef struct {
2242
  int32_t dataLen;
2243
  char    name[TSDB_TABLE_FNAME_LEN];
2244
  char*   data;
2245
} STagData;
2246

2247
typedef struct {
2248
  int32_t useless;  // useless
2249
} SShowVariablesReq;
2250

2251
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2252
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2253

2254
typedef struct {
2255
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2256
  char value[TSDB_CONFIG_PATH_LEN + 1];
2257
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2258
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2259
  char info[TSDB_CONFIG_INFO_LEN + 1];
2260
} SVariablesInfo;
2261

2262
typedef struct {
2263
  SArray* variables;  // SArray<SVariablesInfo>
2264
} SShowVariablesRsp;
2265

2266
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2267
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2268

2269
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2270

2271
/*
2272
 * sql: show tables like '%a_%'
2273
 * payload is the query condition, e.g., '%a_%'
2274
 * payloadLen is the length of payload
2275
 */
2276
typedef struct {
2277
  int32_t type;
2278
  char    db[TSDB_DB_FNAME_LEN];
2279
  int32_t payloadLen;
2280
  char*   payload;
2281
} SShowReq;
2282

2283
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2284
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2285
void tFreeSShowReq(SShowReq* pReq);
2286

2287
typedef struct {
2288
  int64_t       showId;
2289
  STableMetaRsp tableMeta;
2290
} SShowRsp, SVShowTablesRsp;
2291

2292
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2293
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2294
// void    tFreeSShowRsp(SShowRsp* pRsp);
2295

2296
typedef struct {
2297
  char    db[TSDB_DB_FNAME_LEN];
2298
  char    tb[TSDB_TABLE_NAME_LEN];
2299
  char    user[TSDB_USER_LEN];
2300
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2301
  int64_t showId;
2302
  int64_t compactId;  // for compact
2303
  bool    withFull;   // for show users full
2304
} SRetrieveTableReq;
2305

2306
typedef struct SSysTableSchema {
2307
  int8_t   type;
2308
  col_id_t colId;
2309
  int32_t  bytes;
2310
} SSysTableSchema;
2311

2312
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2313
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2314

2315
typedef struct {
2316
  int64_t useconds;
2317
  int8_t  completed;  // all results are returned to client
2318
  int8_t  precision;
2319
  int8_t  compressed;
2320
  int8_t  streamBlockType;
2321
  int32_t payloadLen;
2322
  int32_t compLen;
2323
  int32_t numOfBlocks;
2324
  int64_t numOfRows;  // from int32_t change to int64_t
2325
  int64_t numOfCols;
2326
  int64_t skey;
2327
  int64_t ekey;
2328
  int64_t version;                         // for stream
2329
  TSKEY   watermark;                       // for stream
2330
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2331
  char    data[];
2332
} SRetrieveTableRsp;
2333

2334
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2335

2336
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2337
  do {                                          \
2338
    ((int32_t*)(_p))[0] = (_compLen);           \
2339
    ((int32_t*)(_p))[1] = (_fullLen);           \
2340
  } while (0);
2341

2342
typedef struct {
2343
  int64_t version;
2344
  int64_t numOfRows;
2345
  int8_t  compressed;
2346
  int8_t  precision;
2347
  char    data[];
2348
} SRetrieveTableRspForTmq;
2349

2350
typedef struct {
2351
  int64_t handle;
2352
  int64_t useconds;
2353
  int8_t  completed;  // all results are returned to client
2354
  int8_t  precision;
2355
  int8_t  compressed;
2356
  int32_t compLen;
2357
  int32_t numOfRows;
2358
  int32_t fullLen;
2359
  char    data[];
2360
} SRetrieveMetaTableRsp;
2361

2362
typedef struct SExplainExecInfo {
2363
  double   startupCost;
2364
  double   totalCost;
2365
  uint64_t numOfRows;
2366
  uint32_t verboseLen;
2367
  void*    verboseInfo;
2368
} SExplainExecInfo;
2369

2370
typedef struct {
2371
  int32_t           numOfPlans;
2372
  SExplainExecInfo* subplanInfo;
2373
} SExplainRsp;
2374

2375
typedef struct {
2376
  SExplainRsp rsp;
2377
  uint64_t    qId;
2378
  uint64_t    cId;
2379
  uint64_t    tId;
2380
  int64_t     rId;
2381
  int32_t     eId;
2382
} SExplainLocalRsp;
2383

2384
typedef struct STableScanAnalyzeInfo {
2385
  uint64_t totalRows;
2386
  uint64_t totalCheckedRows;
2387
  uint32_t totalBlocks;
2388
  uint32_t loadBlocks;
2389
  uint32_t loadBlockStatis;
2390
  uint32_t skipBlocks;
2391
  uint32_t filterOutBlocks;
2392
  double   elapsedTime;
2393
  double   filterTime;
2394
} STableScanAnalyzeInfo;
2395

2396
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2397
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2398
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2399

2400
typedef struct {
2401
  char    config[TSDB_DNODE_CONFIG_LEN];
2402
  char    value[TSDB_CLUSTER_VALUE_LEN];
2403
  int32_t sqlLen;
2404
  char*   sql;
2405
} SMCfgClusterReq;
2406

2407
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2408
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2409
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2410

2411
typedef struct {
2412
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2413
  int32_t port;
2414
  int32_t sqlLen;
2415
  char*   sql;
2416
} SCreateDnodeReq;
2417

2418
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2419
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2420
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2421

2422
typedef struct {
2423
  int32_t dnodeId;
2424
  char    fqdn[TSDB_FQDN_LEN];
2425
  int32_t port;
2426
  int8_t  force;
2427
  int8_t  unsafe;
2428
  int32_t sqlLen;
2429
  char*   sql;
2430
} SDropDnodeReq;
2431

2432
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2433
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2434
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2435

2436
enum {
2437
  RESTORE_TYPE__ALL = 1,
2438
  RESTORE_TYPE__MNODE,
2439
  RESTORE_TYPE__VNODE,
2440
  RESTORE_TYPE__QNODE,
2441
};
2442

2443
typedef struct {
2444
  int32_t dnodeId;
2445
  int8_t  restoreType;
2446
  int32_t sqlLen;
2447
  char*   sql;
2448
} SRestoreDnodeReq;
2449

2450
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2451
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2452
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2453

2454
typedef struct {
2455
  int32_t dnodeId;
2456
  char    config[TSDB_DNODE_CONFIG_LEN];
2457
  char    value[TSDB_DNODE_VALUE_LEN];
2458
  int32_t sqlLen;
2459
  char*   sql;
2460
} SMCfgDnodeReq;
2461

2462
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2463
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2464
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2465

2466
typedef struct {
2467
  char    config[TSDB_DNODE_CONFIG_LEN];
2468
  char    value[TSDB_DNODE_VALUE_LEN];
2469
  int32_t version;
2470
} SDCfgDnodeReq;
2471

2472
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2473
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2474

2475
typedef struct {
2476
  int32_t dnodeId;
2477
  int32_t sqlLen;
2478
  char*   sql;
2479
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2480
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2481

2482
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2483
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2484
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2485
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2486
typedef struct {
2487
  int8_t   replica;
2488
  SReplica replicas[TSDB_MAX_REPLICA];
2489
  int8_t   learnerReplica;
2490
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2491
  int64_t  lastIndex;
2492
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2493

2494
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2495
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2496

2497
typedef struct {
2498
  int32_t urlLen;
2499
  int32_t sqlLen;
2500
  char*   url;
2501
  char*   sql;
2502
} SMCreateAnodeReq;
2503

2504
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2505
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2506
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2507

2508
typedef struct {
2509
  int32_t anodeId;
2510
  int32_t sqlLen;
2511
  char*   sql;
2512
} SMDropAnodeReq, SMUpdateAnodeReq;
2513

2514
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2515
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2516
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2517
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2518
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2519
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2520

2521
typedef struct {
2522
  int32_t vgId;
2523
  int32_t hbSeq;
2524
} SVArbHbReqMember;
2525

2526
typedef struct {
2527
  int32_t dnodeId;
2528
  char*   arbToken;
2529
  int64_t arbTerm;
2530
  SArray* hbMembers;  // SVArbHbReqMember
2531
} SVArbHeartBeatReq;
2532

2533
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2534
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2535
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2536

2537
typedef struct {
2538
  int32_t vgId;
2539
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2540
  int32_t hbSeq;
2541
} SVArbHbRspMember;
2542

2543
typedef struct {
2544
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2545
  int32_t dnodeId;
2546
  SArray* hbMembers;  // SVArbHbRspMember
2547
} SVArbHeartBeatRsp;
2548

2549
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2550
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2551
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2552

2553
typedef struct {
2554
  char*   arbToken;
2555
  int64_t arbTerm;
2556
  char*   member0Token;
2557
  char*   member1Token;
2558
} SVArbCheckSyncReq;
2559

2560
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2561
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2562
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2563

2564
typedef struct {
2565
  char*   arbToken;
2566
  char*   member0Token;
2567
  char*   member1Token;
2568
  int32_t vgId;
2569
  int32_t errCode;
2570
} SVArbCheckSyncRsp;
2571

2572
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2573
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2574
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2575

2576
typedef struct {
2577
  char*   arbToken;
2578
  int64_t arbTerm;
2579
  char*   memberToken;
2580
} SVArbSetAssignedLeaderReq;
2581

2582
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2583
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2584
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2585

2586
typedef struct {
2587
  char*   arbToken;
2588
  char*   memberToken;
2589
  int32_t vgId;
2590
} SVArbSetAssignedLeaderRsp;
2591

2592
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2593
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2594
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2595

2596
typedef struct {
2597
  int32_t dnodeId;
2598
  char*   token;
2599
} SMArbUpdateGroupMember;
2600

2601
typedef struct {
2602
  int32_t dnodeId;
2603
  char*   token;
2604
  int8_t  acked;
2605
} SMArbUpdateGroupAssigned;
2606

2607
typedef struct {
2608
  int32_t                  vgId;
2609
  int64_t                  dbUid;
2610
  SMArbUpdateGroupMember   members[2];
2611
  int8_t                   isSync;
2612
  int8_t                   assignedAcked;
2613
  SMArbUpdateGroupAssigned assignedLeader;
2614
  int64_t                  version;
2615
  int32_t                  code;
2616
  int64_t                  updateTimeMs;
2617
} SMArbUpdateGroup;
2618

2619
typedef struct {
2620
  SArray* updateArray;  // SMArbUpdateGroup
2621
} SMArbUpdateGroupBatchReq;
2622

2623
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2624
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2625
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2626

2627
typedef struct {
2628
  char queryStrId[TSDB_QUERY_ID_LEN];
2629
} SKillQueryReq;
2630

2631
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2632
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2633

2634
typedef struct {
2635
  uint32_t connId;
2636
} SKillConnReq;
2637

2638
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2639
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2640

2641
typedef struct {
2642
  int32_t transId;
2643
} SKillTransReq;
2644

2645
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2646
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2647

2648
typedef struct {
2649
  int32_t useless;  // useless
2650
  int32_t sqlLen;
2651
  char*   sql;
2652
} SBalanceVgroupReq;
2653

2654
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2655
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2656
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2657

2658
typedef struct {
2659
  int32_t vgId1;
2660
  int32_t vgId2;
2661
} SMergeVgroupReq;
2662

2663
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2664
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2665

2666
typedef struct {
2667
  int32_t vgId;
2668
  int32_t dnodeId1;
2669
  int32_t dnodeId2;
2670
  int32_t dnodeId3;
2671
  int32_t sqlLen;
2672
  char*   sql;
2673
} SRedistributeVgroupReq;
2674

2675
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2676
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2677
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2678

2679
typedef struct {
2680
  int32_t reserved;
2681
  int32_t vgId;
2682
  int32_t sqlLen;
2683
  char*   sql;
2684
  char    db[TSDB_DB_FNAME_LEN];
2685
} SBalanceVgroupLeaderReq;
2686

2687
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2688
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2689
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2690

2691
typedef struct {
2692
  int32_t vgId;
2693
} SForceBecomeFollowerReq;
2694

2695
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2696
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2697

2698
typedef struct {
2699
  int32_t vgId;
2700
} SSplitVgroupReq;
2701

2702
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2703
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2704

2705
typedef struct {
2706
  char user[TSDB_USER_LEN];
2707
  char spi;
2708
  char encrypt;
2709
  char secret[TSDB_PASSWORD_LEN];
2710
  char ckey[TSDB_PASSWORD_LEN];
2711
} SAuthReq, SAuthRsp;
2712

2713
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2714
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2715

2716
typedef struct {
2717
  int32_t statusCode;
2718
  char    details[1024];
2719
} SServerStatusRsp;
2720

2721
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2722
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2723

2724
/**
2725
 * The layout of the query message payload is as following:
2726
 * +--------------------+---------------------------------+
2727
 * |Sql statement       | Physical plan                   |
2728
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2729
 * +--------------------+---------------------------------+
2730
 */
2731
typedef struct SSubQueryMsg {
2732
  SMsgHead header;
2733
  uint64_t sId;
2734
  uint64_t queryId;
2735
  uint64_t clientId;
2736
  uint64_t taskId;
2737
  int64_t  refId;
2738
  int32_t  execId;
2739
  int32_t  msgMask;
2740
  int8_t   taskType;
2741
  int8_t   explain;
2742
  int8_t   needFetch;
2743
  int8_t   compress;
2744
  uint32_t sqlLen;
2745
  char*    sql;
2746
  uint32_t msgLen;
2747
  char*    msg;
2748
} SSubQueryMsg;
2749

2750
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2751
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2752
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2753

2754
typedef struct {
2755
  SMsgHead header;
2756
  uint64_t sId;
2757
  uint64_t queryId;
2758
  uint64_t taskId;
2759
} SSinkDataReq;
2760

2761
typedef struct {
2762
  SMsgHead header;
2763
  uint64_t sId;
2764
  uint64_t queryId;
2765
  uint64_t clientId;
2766
  uint64_t taskId;
2767
  int32_t  execId;
2768
} SQueryContinueReq;
2769

2770
typedef struct {
2771
  SMsgHead header;
2772
  uint64_t sId;
2773
  uint64_t queryId;
2774
  uint64_t taskId;
2775
} SResReadyReq;
2776

2777
typedef struct {
2778
  int32_t code;
2779
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2780
  int32_t sversion;
2781
  int32_t tversion;
2782
} SResReadyRsp;
2783

2784
typedef struct SOperatorParam {
2785
  int32_t opType;
2786
  int32_t downstreamIdx;
2787
  void*   value;
2788
  SArray* pChildren;  // SArray<SOperatorParam*>
2789
} SOperatorParam;
2790

2791
typedef struct STableScanOperatorParam {
2792
  bool    tableSeq;
2793
  SArray* pUidList;
2794
} STableScanOperatorParam;
2795

2796
typedef struct {
2797
  SMsgHead        header;
2798
  uint64_t        sId;
2799
  uint64_t        queryId;
2800
  uint64_t        clientId;
2801
  uint64_t        taskId;
2802
  int32_t         execId;
2803
  SOperatorParam* pOpParam;
2804
} SResFetchReq;
2805

2806
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2807
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2808

2809
typedef struct {
2810
  SMsgHead header;
2811
  uint64_t clientId;
2812
} SSchTasksStatusReq;
2813

2814
typedef struct {
2815
  uint64_t queryId;
2816
  uint64_t clientId;
2817
  uint64_t taskId;
2818
  int64_t  refId;
2819
  int32_t  execId;
2820
  int8_t   status;
2821
} STaskStatus;
2822

2823
typedef struct {
2824
  int64_t refId;
2825
  SArray* taskStatus;  // SArray<STaskStatus>
2826
} SSchedulerStatusRsp;
2827

2828
typedef struct {
2829
  uint64_t queryId;
2830
  uint64_t taskId;
2831
  int8_t   action;
2832
} STaskAction;
2833

2834
typedef struct SQueryNodeEpId {
2835
  int32_t nodeId;  // vgId or qnodeId
2836
  SEp     ep;
2837
} SQueryNodeEpId;
2838

2839
typedef struct {
2840
  SMsgHead       header;
2841
  uint64_t       clientId;
2842
  SQueryNodeEpId epId;
2843
  SArray*        taskAction;  // SArray<STaskAction>
2844
} SSchedulerHbReq;
2845

2846
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2847
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2848
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2849

2850
typedef struct {
2851
  SQueryNodeEpId epId;
2852
  SArray*        taskStatus;  // SArray<STaskStatus>
2853
} SSchedulerHbRsp;
2854

2855
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2856
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2857
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2858

2859
typedef struct {
2860
  SMsgHead header;
2861
  uint64_t sId;
2862
  uint64_t queryId;
2863
  uint64_t clientId;
2864
  uint64_t taskId;
2865
  int64_t  refId;
2866
  int32_t  execId;
2867
} STaskCancelReq;
2868

2869
typedef struct {
2870
  int32_t code;
2871
} STaskCancelRsp;
2872

2873
typedef struct {
2874
  SMsgHead header;
2875
  uint64_t sId;
2876
  uint64_t queryId;
2877
  uint64_t clientId;
2878
  uint64_t taskId;
2879
  int64_t  refId;
2880
  int32_t  execId;
2881
} STaskDropReq;
2882

2883
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2884
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2885

2886
typedef enum {
2887
  TASK_NOTIFY_FINISHED = 1,
2888
} ETaskNotifyType;
2889

2890
typedef struct {
2891
  SMsgHead        header;
2892
  uint64_t        sId;
2893
  uint64_t        queryId;
2894
  uint64_t        clientId;
2895
  uint64_t        taskId;
2896
  int64_t         refId;
2897
  int32_t         execId;
2898
  ETaskNotifyType type;
2899
} STaskNotifyReq;
2900

2901
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2902
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2903

2904
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2905
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2906

2907
typedef struct {
2908
  int32_t code;
2909
} STaskDropRsp;
2910

2911
#define STREAM_TRIGGER_AT_ONCE            1
2912
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2913
#define STREAM_TRIGGER_MAX_DELAY          3
2914
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2915

2916
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2917
#define STREAM_FILL_HISTORY_ON        1
2918
#define STREAM_FILL_HISTORY_OFF       0
2919
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2920
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2921
#define STREAM_CREATE_STABLE_TRUE     1
2922
#define STREAM_CREATE_STABLE_FALSE    0
2923

2924
typedef struct SColLocation {
2925
  int16_t  slotId;
2926
  col_id_t colId;
2927
  int8_t   type;
2928
} SColLocation;
2929

2930
typedef struct SVgroupVer {
2931
  int32_t vgId;
2932
  int64_t ver;
2933
} SVgroupVer;
2934

2935
typedef struct {
2936
  char    name[TSDB_STREAM_FNAME_LEN];
2937
  char    sourceDB[TSDB_DB_FNAME_LEN];
2938
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
2939
  char*   sql;
2940
  char*   ast;
2941
  int8_t  igExists;
2942
  int8_t  triggerType;
2943
  int8_t  igExpired;
2944
  int8_t  fillHistory;  // process data inserted before creating stream
2945
  int64_t maxDelay;
2946
  int64_t watermark;
2947
  int32_t numOfTags;
2948
  SArray* pTags;  // array of SField
2949
  // 3.0.20
2950
  int64_t checkpointFreq;  // ms
2951
  // 3.0.2.3
2952
  int8_t   createStb;
2953
  uint64_t targetStbUid;
2954
  SArray*  fillNullCols;  // array of SColLocation
2955
  int64_t  deleteMark;
2956
  int8_t   igUpdate;
2957
  int64_t  lastTs;
2958
  SArray*  pVgroupVerList;
2959
  // 3.3.0.0
2960
  SArray* pCols;  // array of SField
2961
  int64_t smaId;
2962
  // 3.3.6.0
2963
  SArray* pNotifyAddrUrls;
2964
  int32_t notifyEventTypes;
2965
  int32_t notifyErrorHandle;
2966
  int8_t  notifyHistory;
2967
} SCMCreateStreamReq;
2968

2969
typedef struct {
2970
  int64_t streamId;
2971
} SCMCreateStreamRsp;
2972

2973
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
2974
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
2975
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
2976

2977
enum {
2978
  TOPIC_SUB_TYPE__DB = 1,
2979
  TOPIC_SUB_TYPE__TABLE,
2980
  TOPIC_SUB_TYPE__COLUMN,
2981
};
2982

2983
#define DEFAULT_MAX_POLL_INTERVAL 300000
2984
#define DEFAULT_SESSION_TIMEOUT   12000
2985

2986
typedef struct {
2987
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
2988
  int8_t igExists;
2989
  int8_t subType;
2990
  int8_t withMeta;
2991
  char*  sql;
2992
  char   subDbName[TSDB_DB_FNAME_LEN];
2993
  char*  ast;
2994
  char   subStbName[TSDB_TABLE_FNAME_LEN];
2995
} SCMCreateTopicReq;
2996

2997
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
2998
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
2999
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3000

3001
typedef struct {
3002
  int64_t consumerId;
3003
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3004

3005
typedef struct {
3006
  int64_t consumerId;
3007
  char    cgroup[TSDB_CGROUP_LEN];
3008
  char    clientId[TSDB_CLIENT_ID_LEN];
3009
  char    user[TSDB_USER_LEN];
3010
  char    fqdn[TSDB_FQDN_LEN];
3011
  SArray* topicNames;  // SArray<char**>
3012

3013
  int8_t  withTbName;
3014
  int8_t  autoCommit;
3015
  int32_t autoCommitInterval;
3016
  int8_t  resetOffsetCfg;
3017
  int8_t  enableReplay;
3018
  int8_t  enableBatchMeta;
3019
  int32_t sessionTimeoutMs;
3020
  int32_t maxPollIntervalMs;
3021
} SCMSubscribeReq;
3022

3023
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3024
  int32_t tlen = 0;
2,432✔
3025
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,432!
3026
  tlen += taosEncodeString(buf, pReq->cgroup);
2,432✔
3027
  tlen += taosEncodeString(buf, pReq->clientId);
2,432✔
3028

3029
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,432!
3030
  tlen += taosEncodeFixedI32(buf, topicNum);
2,432✔
3031

3032
  for (int32_t i = 0; i < topicNum; i++) {
3,462✔
3033
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,060✔
3034
  }
3035

3036
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,432!
3037
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,432!
3038
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,432!
3039
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,432!
3040
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,432!
3041
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,432!
3042
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,432!
3043
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,432!
3044
  tlen += taosEncodeString(buf, pReq->user);
2,432✔
3045
  tlen += taosEncodeString(buf, pReq->fqdn);
2,432✔
3046

3047
  return tlen;
2,432✔
3048
}
3049

3050
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3051
  void* start = buf;
1,316✔
3052
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,316!
3053
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,316✔
3054
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,316✔
3055

3056
  int32_t topicNum = 0;
1,316!
3057
  buf = taosDecodeFixedI32(buf, &topicNum);
1,316✔
3058

3059
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,316✔
3060
  if (pReq->topicNames == NULL) {
1,316!
UNCOV
3061
    return terrno;
×
3062
  }
3063
  for (int32_t i = 0; i < topicNum; i++) {
1,934✔
3064
    char* name = NULL;
618✔
3065
    buf = taosDecodeString(buf, &name);
618✔
3066
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,236!
UNCOV
3067
      return terrno;
×
3068
    }
3069
  }
3070

3071
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,316✔
3072
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,316✔
3073
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,316!
3074
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,316✔
3075
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,316✔
3076
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,316✔
3077
  if ((char*)buf - (char*)start < len) {
1,316!
3078
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,316!
3079
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,316!
3080
    buf = taosDecodeStringTo(buf, pReq->user);
1,316✔
3081
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,632✔
3082
  } else {
UNCOV
3083
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
3084
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3085
  }
3086

3087
  return 0;
1,316✔
3088
}
3089

3090
typedef struct {
3091
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3092
  SArray* removedConsumers;  // SArray<int64_t>
3093
  SArray* newConsumers;      // SArray<int64_t>
3094
} SMqRebInfo;
3095

3096
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3097
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,281!
3098
  if (pRebInfo == NULL) {
1,281!
UNCOV
3099
    return NULL;
×
3100
  }
3101
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,281✔
3102
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,281✔
3103
  if (pRebInfo->removedConsumers == NULL) {
1,281!
UNCOV
3104
    goto _err;
×
3105
  }
3106
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,281✔
3107
  if (pRebInfo->newConsumers == NULL) {
1,281!
UNCOV
3108
    goto _err;
×
3109
  }
3110
  return pRebInfo;
1,281✔
3111
_err:
×
3112
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3113
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
3114
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
3115
  return NULL;
×
3116
}
3117

3118
typedef struct {
3119
  int64_t streamId;
3120
  int64_t checkpointId;
3121
  char    streamName[TSDB_STREAM_FNAME_LEN];
3122
} SMStreamDoCheckpointMsg;
3123

3124
typedef struct {
3125
  int64_t status;
3126
} SMVSubscribeRsp;
3127

3128
typedef struct {
3129
  char    name[TSDB_TOPIC_FNAME_LEN];
3130
  int8_t  igNotExists;
3131
  int32_t sqlLen;
3132
  char*   sql;
3133
} SMDropTopicReq;
3134

3135
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3136
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3137
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3138

3139
typedef struct {
3140
  char   topic[TSDB_TOPIC_FNAME_LEN];
3141
  char   cgroup[TSDB_CGROUP_LEN];
3142
  int8_t igNotExists;
3143
} SMDropCgroupReq;
3144

3145
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3146
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3147

3148
typedef struct {
3149
  int8_t reserved;
3150
} SMDropCgroupRsp;
3151

3152
typedef struct {
3153
  char    name[TSDB_TABLE_FNAME_LEN];
3154
  int8_t  alterType;
3155
  SSchema schema;
3156
} SAlterTopicReq;
3157

3158
typedef struct {
3159
  SMsgHead head;
3160
  char     name[TSDB_TABLE_FNAME_LEN];
3161
  int64_t  tuid;
3162
  int32_t  sverson;
3163
  int32_t  execLen;
3164
  char*    executor;
3165
  int32_t  sqlLen;
3166
  char*    sql;
3167
} SDCreateTopicReq;
3168

3169
typedef struct {
3170
  SMsgHead head;
3171
  char     name[TSDB_TABLE_FNAME_LEN];
3172
  int64_t  tuid;
3173
} SDDropTopicReq;
3174

3175
typedef struct {
3176
  int64_t maxdelay[2];
3177
  int64_t watermark[2];
3178
  int64_t deleteMark[2];
3179
  int32_t qmsgLen[2];
3180
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3181
} SRSmaParam;
3182

3183
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3184
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3185

3186
// TDMT_VND_CREATE_STB ==============
3187
typedef struct SVCreateStbReq {
3188
  char*           name;
3189
  tb_uid_t        suid;
3190
  int8_t          rollup;
3191
  SSchemaWrapper  schemaRow;
3192
  SSchemaWrapper  schemaTag;
3193
  SRSmaParam      rsmaParam;
3194
  int32_t         alterOriDataLen;
3195
  void*           alterOriData;
3196
  int8_t          source;
3197
  int8_t          colCmpred;
3198
  SColCmprWrapper colCmpr;
3199
} SVCreateStbReq;
3200

3201
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3202
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3203

3204
// TDMT_VND_DROP_STB ==============
3205
typedef struct SVDropStbReq {
3206
  char*    name;
3207
  tb_uid_t suid;
3208
} SVDropStbReq;
3209

3210
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3211
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3212

3213
// TDMT_VND_CREATE_TABLE ==============
3214
#define TD_CREATE_IF_NOT_EXISTS 0x1
3215
typedef struct SVCreateTbReq {
3216
  int32_t  flags;
3217
  char*    name;
3218
  tb_uid_t uid;
3219
  int64_t  btime;
3220
  int32_t  ttl;
3221
  int32_t  commentLen;
3222
  char*    comment;
3223
  int8_t   type;
3224
  union {
3225
    struct {
3226
      char*    stbName;  // super table name
3227
      uint8_t  tagNum;
3228
      tb_uid_t suid;
3229
      SArray*  tagName;
3230
      uint8_t* pTag;
3231
    } ctb;
3232
    struct {
3233
      SSchemaWrapper schemaRow;
3234
    } ntb;
3235
  };
3236
  int32_t         sqlLen;
3237
  char*           sql;
3238
  SColCmprWrapper colCmpr;
3239
} SVCreateTbReq;
3240

3241
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3242
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3243
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3244

3245
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
3,583✔
3246
  if (NULL == req) {
3,870,686!
3247
    return;
3,611,251✔
3248
  }
3249

3250
  taosMemoryFreeClear(req->sql);
259,435!
3251
  taosMemoryFreeClear(req->name);
259,435!
3252
  taosMemoryFreeClear(req->comment);
259,455!
3253
  if (req->type == TSDB_CHILD_TABLE) {
259,455!
3254
    taosMemoryFreeClear(req->ctb.pTag);
243,733!
3255
    taosMemoryFreeClear(req->ctb.stbName);
243,749!
3256
    taosArrayDestroy(req->ctb.tagName);
243,751✔
3257
    req->ctb.tagName = NULL;
243,767✔
3258
  } else if (req->type == TSDB_NORMAL_TABLE) {
15,723!
3259
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
15,674!
3260
  }
3261
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
259,489!
3262
}
3263

3264
typedef struct {
3265
  int32_t nReqs;
3266
  union {
3267
    SVCreateTbReq* pReqs;
3268
    SArray*        pArray;
3269
  };
3270
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3271
} SVCreateTbBatchReq;
3272

3273
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3274
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3275
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3276

3277
typedef struct {
3278
  int32_t        code;
3279
  STableMetaRsp* pMeta;
3280
} SVCreateTbRsp, SVUpdateTbRsp;
3281

3282
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3283
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3284
void tFreeSVCreateTbRsp(void* param);
3285

3286
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3287
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3288

3289
typedef struct {
3290
  int32_t nRsps;
3291
  union {
3292
    SVCreateTbRsp* pRsps;
3293
    SArray*        pArray;
3294
  };
3295
} SVCreateTbBatchRsp;
3296

3297
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3298
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3299

3300
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3301
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3302

3303
// TDMT_VND_DROP_TABLE =================
3304
typedef struct {
3305
  char*    name;
3306
  uint64_t suid;  // for tmq in wal format
3307
  int64_t  uid;
3308
  int8_t   igNotExists;
3309
} SVDropTbReq;
3310

3311
typedef struct {
3312
  int32_t code;
3313
} SVDropTbRsp;
3314

3315
typedef struct {
3316
  int32_t nReqs;
3317
  union {
3318
    SVDropTbReq* pReqs;
3319
    SArray*      pArray;
3320
  };
3321
} SVDropTbBatchReq;
3322

3323
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3324
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3325

3326
typedef struct {
3327
  int32_t nRsps;
3328
  union {
3329
    SVDropTbRsp* pRsps;
3330
    SArray*      pArray;
3331
  };
3332
} SVDropTbBatchRsp;
3333

3334
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3335
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3336

3337
// TDMT_VND_ALTER_TABLE =====================
3338
typedef struct SMultiTagUpateVal {
3339
  char*    tagName;
3340
  int32_t  colId;
3341
  int8_t   tagType;
3342
  int8_t   tagFree;
3343
  uint32_t nTagVal;
3344
  uint8_t* pTagVal;
3345
  int8_t   isNull;
3346
  SArray*  pTagArray;
3347
} SMultiTagUpateVal;
3348
typedef struct {
3349
  char*   tbName;
3350
  int8_t  action;
3351
  char*   colName;
3352
  int32_t colId;
3353
  // TSDB_ALTER_TABLE_ADD_COLUMN
3354
  int8_t  type;
3355
  int8_t  flags;
3356
  int32_t bytes;
3357
  // TSDB_ALTER_TABLE_DROP_COLUMN
3358
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3359
  int8_t   colModType;
3360
  int32_t  colModBytes;
3361
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3362
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3363
  int8_t   isNull;
3364
  int8_t   tagType;
3365
  int8_t   tagFree;
3366
  uint32_t nTagVal;
3367
  uint8_t* pTagVal;
3368
  SArray*  pTagArray;
3369
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3370
  int8_t   updateTTL;
3371
  int32_t  newTTL;
3372
  int32_t  newCommentLen;
3373
  char*    newComment;
3374
  int64_t  ctimeMs;    // fill by vnode
3375
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3376
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3377
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3378
} SVAlterTbReq;
3379

3380
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3381
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3382
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3383
void    tfreeMultiTagUpateVal(void* pMultiTag);
3384

3385
typedef struct {
3386
  int32_t        code;
3387
  STableMetaRsp* pMeta;
3388
} SVAlterTbRsp;
3389

3390
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3391
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3392
// ======================
3393

3394
typedef struct {
3395
  SMsgHead head;
3396
  int64_t  uid;
3397
  int32_t  tid;
3398
  int16_t  tversion;
3399
  int16_t  colId;
3400
  int8_t   type;
3401
  int16_t  bytes;
3402
  int32_t  tagValLen;
3403
  int16_t  numOfTags;
3404
  int32_t  schemaLen;
3405
  char     data[];
3406
} SUpdateTagValReq;
3407

3408
typedef struct {
3409
  SMsgHead head;
3410
} SUpdateTagValRsp;
3411

3412
typedef struct {
3413
  SMsgHead head;
3414
} SVShowTablesReq;
3415

3416
typedef struct {
3417
  SMsgHead head;
3418
  int32_t  id;
3419
} SVShowTablesFetchReq;
3420

3421
typedef struct {
3422
  int64_t useconds;
3423
  int8_t  completed;  // all results are returned to client
3424
  int8_t  precision;
3425
  int8_t  compressed;
3426
  int32_t compLen;
3427
  int32_t numOfRows;
3428
  char    data[];
3429
} SVShowTablesFetchRsp;
3430

3431
typedef struct {
3432
  int64_t consumerId;
3433
  int32_t epoch;
3434
  char    cgroup[TSDB_CGROUP_LEN];
3435
} SMqAskEpReq;
3436

3437
typedef struct {
3438
  int32_t key;
3439
  int32_t valueLen;
3440
  void*   value;
3441
} SKv;
3442

3443
typedef struct {
3444
  int64_t tscRid;
3445
  int8_t  connType;
3446
} SClientHbKey;
3447

3448
typedef struct {
3449
  int64_t tid;
3450
  char    status[TSDB_JOB_STATUS_LEN];
3451
} SQuerySubDesc;
3452

3453
typedef struct {
3454
  char     sql[TSDB_SHOW_SQL_LEN];
3455
  uint64_t queryId;
3456
  int64_t  useconds;
3457
  int64_t  stime;  // timestamp precision ms
3458
  int64_t  reqRid;
3459
  bool     stableQuery;
3460
  bool     isSubQuery;
3461
  char     fqdn[TSDB_FQDN_LEN];
3462
  int32_t  subPlanNum;
3463
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3464
} SQueryDesc;
3465

3466
typedef struct {
3467
  uint32_t connId;
3468
  SArray*  queryDesc;  // SArray<SQueryDesc>
3469
} SQueryHbReqBasic;
3470

3471
typedef struct {
3472
  uint32_t connId;
3473
  uint64_t killRid;
3474
  int32_t  totalDnodes;
3475
  int32_t  onlineDnodes;
3476
  int8_t   killConnection;
3477
  int8_t   align[3];
3478
  SEpSet   epSet;
3479
  SArray*  pQnodeList;
3480
} SQueryHbRspBasic;
3481

3482
typedef struct SAppClusterSummary {
3483
  uint64_t numOfInsertsReq;
3484
  uint64_t numOfInsertRows;
3485
  uint64_t insertElapsedTime;
3486
  uint64_t insertBytes;  // submit to tsdb since launched.
3487

3488
  uint64_t fetchBytes;
3489
  uint64_t numOfQueryReq;
3490
  uint64_t queryElapsedTime;
3491
  uint64_t numOfSlowQueries;
3492
  uint64_t totalRequests;
3493
  uint64_t currentRequests;  // the number of SRequestObj
3494
} SAppClusterSummary;
3495

3496
typedef struct {
3497
  int64_t            appId;
3498
  int32_t            pid;
3499
  char               name[TSDB_APP_NAME_LEN];
3500
  int64_t            startTime;
3501
  SAppClusterSummary summary;
3502
} SAppHbReq;
3503

3504
typedef struct {
3505
  SClientHbKey      connKey;
3506
  int64_t           clusterId;
3507
  SAppHbReq         app;
3508
  SQueryHbReqBasic* query;
3509
  SHashObj*         info;  // hash<Skv.key, Skv>
3510
  char              userApp[TSDB_APP_NAME_LEN];
3511
  uint32_t          userIp;
3512
} SClientHbReq;
3513

3514
typedef struct {
3515
  int64_t reqId;
3516
  SArray* reqs;  // SArray<SClientHbReq>
3517
  int64_t ipWhiteList;
3518
} SClientHbBatchReq;
3519

3520
typedef struct {
3521
  SClientHbKey      connKey;
3522
  int32_t           status;
3523
  SQueryHbRspBasic* query;
3524
  SArray*           info;  // Array<Skv>
3525
} SClientHbRsp;
3526

3527
typedef struct {
3528
  int64_t       reqId;
3529
  int64_t       rspId;
3530
  int32_t       svrTimestamp;
3531
  SArray*       rsps;  // SArray<SClientHbRsp>
3532
  SMonitorParas monitorParas;
3533
  int8_t        enableAuditDelete;
3534
} SClientHbBatchRsp;
3535

3536
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
152,642✔
3537

3538
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3539
  void* pIter = taosHashIterate(info, NULL);
90,449✔
3540
  while (pIter != NULL) {
181,352!
3541
    SKv* kv = (SKv*)pIter;
90,902✔
3542
    taosMemoryFreeClear(kv->value);
90,902!
3543
    pIter = taosHashIterate(info, pIter);
90,902✔
3544
  }
3545
}
90,450✔
3546

3547
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
50,793✔
3548
  SQueryDesc* desc = (SQueryDesc*)pDesc;
50,793✔
3549
  if (desc->subDesc) {
50,793✔
3550
    taosArrayDestroy(desc->subDesc);
44,642✔
3551
    desc->subDesc = NULL;
44,642✔
3552
  }
3553
}
50,793✔
3554

3555
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
126,868✔
3556
  SClientHbReq* req = (SClientHbReq*)pReq;
137,633✔
3557
  if (req->query) {
137,633!
3558
    if (req->query->queryDesc) {
118,370!
3559
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
36,199✔
3560
    }
3561
    taosMemoryFreeClear(req->query);
118,370!
3562
  }
3563

3564
  if (req->info) {
137,633!
3565
    tFreeReqKvHash(req->info);
90,449✔
3566
    taosHashCleanup(req->info);
90,450✔
3567
    req->info = NULL;
90,450✔
3568
  }
3569
}
69,837✔
3570

3571
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3572
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3573

3574
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3575
  if (pReq == NULL) return;
39,472!
3576
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
39,472✔
3577
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
39,472✔
3578
  taosMemoryFree(pReq);
39,472!
3579
}
3580

3581
static FORCE_INLINE void tFreeClientKv(void* pKv) {
35,875✔
3582
  SKv* kv = (SKv*)pKv;
35,875✔
3583
  if (kv) {
35,875!
3584
    taosMemoryFreeClear(kv->value);
35,875!
3585
  }
3586
}
35,875✔
3587

3588
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
124,298✔
3589
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
124,298✔
3590
  if (rsp->query) {
124,298✔
3591
    taosArrayDestroy(rsp->query->pQnodeList);
115,822✔
3592
    taosMemoryFreeClear(rsp->query);
115,822!
3593
  }
3594
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
124,298!
3595
}
65,227✔
3596

3597
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3598
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
72,959✔
3599
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
72,959✔
3600
}
72,959✔
3601

3602
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3603
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3604
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3605

3606
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3607
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
263,282!
3608
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
263,282!
3609
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
263,282!
3610
  return 0;
131,641✔
3611
}
3612

3613
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3614
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
121,912!
3615
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
121,912!
3616
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
60,956!
3617
  if (pKv->value == NULL) {
60,956!
UNCOV
3618
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3619
  }
3620
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
60,956!
3621
  return 0;
60,956✔
3622
}
3623

3624
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3625
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
507,474!
3626
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
507,474!
3627
  return 0;
253,737✔
3628
}
3629

3630
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3631
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
248,596!
3632
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
248,596!
3633
  return 0;
124,298✔
3634
}
3635

3636
typedef struct {
3637
  int32_t vgId;
3638
  // TODO stas
3639
} SMqReportVgInfo;
3640

3641
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3642
  int32_t tlen = 0;
3643
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3644
  return tlen;
3645
}
3646

3647
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3648
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3649
  return buf;
3650
}
3651

3652
typedef struct {
3653
  int32_t epoch;
3654
  int64_t topicUid;
3655
  char    name[TSDB_TOPIC_FNAME_LEN];
3656
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3657
} SMqTopicInfo;
3658

3659
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3660
  int32_t tlen = 0;
3661
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3662
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3663
  tlen += taosEncodeString(buf, pTopicInfo->name);
3664
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3665
  tlen += taosEncodeFixedI32(buf, sz);
3666
  for (int32_t i = 0; i < sz; i++) {
3667
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3668
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3669
  }
3670
  return tlen;
3671
}
3672

3673
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3674
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3675
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3676
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3677
  int32_t sz;
3678
  buf = taosDecodeFixedI32(buf, &sz);
3679
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3680
    return NULL;
3681
  }
3682
  for (int32_t i = 0; i < sz; i++) {
3683
    SMqReportVgInfo vgInfo;
3684
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3685
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3686
      return NULL;
3687
    }
3688
  }
3689
  return buf;
3690
}
3691

3692
typedef struct {
3693
  int32_t status;  // ask hb endpoint
3694
  int32_t epoch;
3695
  int64_t consumerId;
3696
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3697
} SMqReportReq;
3698

3699
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3700
  int32_t tlen = 0;
3701
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3702
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3703
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3704
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3705
  tlen += taosEncodeFixedI32(buf, sz);
3706
  for (int32_t i = 0; i < sz; i++) {
3707
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3708
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3709
  }
3710
  return tlen;
3711
}
3712

3713
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3714
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3715
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3716
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3717
  int32_t sz;
3718
  buf = taosDecodeFixedI32(buf, &sz);
3719
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3720
    return NULL;
3721
  }
3722
  for (int32_t i = 0; i < sz; i++) {
3723
    SMqTopicInfo topicInfo;
3724
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3725
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3726
      return NULL;
3727
    }
3728
  }
3729
  return buf;
3730
}
3731

3732
typedef struct {
3733
  SMsgHead head;
3734
  int64_t  leftForVer;
3735
  int32_t  vgId;
3736
  int64_t  consumerId;
3737
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3738
} SMqVDeleteReq;
3739

3740
typedef struct {
3741
  int8_t reserved;
3742
} SMqVDeleteRsp;
3743

3744
typedef struct {
3745
  char    name[TSDB_STREAM_FNAME_LEN];
3746
  int8_t  igNotExists;
3747
  int32_t sqlLen;
3748
  char*   sql;
3749
} SMDropStreamReq;
3750

3751
typedef struct {
3752
  int8_t reserved;
3753
} SMDropStreamRsp;
3754

3755
typedef struct {
3756
  SMsgHead head;
3757
  int64_t  resetRelHalt;  // reset related stream task halt status
3758
  int64_t  streamId;
3759
  int32_t  taskId;
3760
} SVDropStreamTaskReq;
3761

3762
typedef struct {
3763
  int8_t reserved;
3764
} SVDropStreamTaskRsp;
3765

3766
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3767
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3768
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3769

3770
typedef struct SVUpdateCheckpointInfoReq {
3771
  SMsgHead head;
3772
  int64_t  streamId;
3773
  int32_t  taskId;
3774
  int64_t  checkpointId;
3775
  int64_t  checkpointVer;
3776
  int64_t  checkpointTs;
3777
  int32_t  transId;
3778
  int64_t  hStreamId;  // add encode/decode
3779
  int64_t  hTaskId;
3780
  int8_t   dropRelHTask;
3781
} SVUpdateCheckpointInfoReq;
3782

3783
typedef struct {
3784
  int64_t leftForVer;
3785
  int32_t vgId;
3786
  int64_t oldConsumerId;
3787
  int64_t newConsumerId;
3788
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3789
  int8_t  subType;
3790
  int8_t  withMeta;
3791
  char*   qmsg;  // SubPlanToString
3792
  int64_t suid;
3793
} SMqRebVgReq;
3794

3795
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3796
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3797

3798
typedef struct {
3799
  char    topic[TSDB_TOPIC_FNAME_LEN];
3800
  int64_t ntbUid;
3801
  SArray* colIdList;  // SArray<int16_t>
3802
} STqCheckInfo;
3803

3804
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3805
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3806
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3807

3808
// tqOffset
3809
enum {
3810
  TMQ_OFFSET__RESET_NONE = -3,
3811
  TMQ_OFFSET__RESET_EARLIEST = -2,
3812
  TMQ_OFFSET__RESET_LATEST = -1,
3813
  TMQ_OFFSET__LOG = 1,
3814
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3815
  TMQ_OFFSET__SNAPSHOT_META = 3,
3816
};
3817

3818
enum {
3819
  WITH_DATA = 0,
3820
  WITH_META = 1,
3821
  ONLY_META = 2,
3822
};
3823

3824
#define TQ_OFFSET_VERSION 1
3825

3826
typedef struct {
3827
  int8_t type;
3828
  union {
3829
    // snapshot
3830
    struct {
3831
      int64_t uid;
3832
      int64_t ts;
3833
      SValue  primaryKey;
3834
    };
3835
    // log
3836
    struct {
3837
      int64_t version;
3838
    };
3839
  };
3840
} STqOffsetVal;
3841

3842
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3843
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
25,083✔
3844
  pOffsetVal->uid = uid;
25,083✔
3845
  pOffsetVal->ts = ts;
25,083✔
3846
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
25,083!
UNCOV
3847
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3848
  }
3849
  pOffsetVal->primaryKey = primaryKey;
25,117✔
3850
}
25,117✔
3851

3852
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3853
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
149✔
3854
  pOffsetVal->uid = uid;
149✔
3855
}
149✔
3856

3857
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3858
  pOffsetVal->type = TMQ_OFFSET__LOG;
561,309✔
3859
  pOffsetVal->version = ver;
561,309✔
3860
}
561,309✔
3861

3862
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3863
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3864
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3865
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3866
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3867
void    tOffsetDestroy(void* pVal);
3868

3869
typedef struct {
3870
  STqOffsetVal val;
3871
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3872
} STqOffset;
3873

3874
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3875
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3876
void    tDeleteSTqOffset(void* val);
3877

3878
typedef struct SMqVgOffset {
3879
  int64_t   consumerId;
3880
  STqOffset offset;
3881
} SMqVgOffset;
3882

3883
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3884
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3885

3886
typedef struct {
3887
  SMsgHead head;
3888
  int64_t  streamId;
3889
  int32_t  taskId;
3890
} SVPauseStreamTaskReq;
3891

3892
typedef struct {
3893
  SMsgHead head;
3894
  int64_t  streamId;
3895
  int32_t  taskId;
3896
  int64_t  chkptId;
3897
} SVResetStreamTaskReq;
3898

3899
typedef struct {
3900
  char   name[TSDB_STREAM_FNAME_LEN];
3901
  int8_t igNotExists;
3902
} SMPauseStreamReq;
3903

3904
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3905
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3906

3907
typedef struct {
3908
  SMsgHead head;
3909
  int32_t  taskId;
3910
  int64_t  streamId;
3911
  int8_t   igUntreated;
3912
} SVResumeStreamTaskReq;
3913

3914
typedef struct {
3915
  int8_t reserved;
3916
} SVResumeStreamTaskRsp;
3917

3918
typedef struct {
3919
  char   name[TSDB_STREAM_FNAME_LEN];
3920
  int8_t igNotExists;
3921
  int8_t igUntreated;
3922
} SMResumeStreamReq;
3923

3924
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3925
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3926

3927
typedef struct {
3928
  char   name[TSDB_STREAM_FNAME_LEN];
3929
  int8_t igNotExists;
3930
  int8_t igUntreated;
3931
} SMResetStreamReq;
3932

3933
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
3934
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
3935

3936
typedef struct {
3937
  char    name[TSDB_TABLE_FNAME_LEN];
3938
  char    stb[TSDB_TABLE_FNAME_LEN];
3939
  int8_t  igExists;
3940
  int8_t  intervalUnit;
3941
  int8_t  slidingUnit;
3942
  int8_t  timezone;    // int8_t is not enough, timezone is unit of second
3943
  int32_t dstVgId;  // for stream
3944
  int64_t interval;
3945
  int64_t offset;
3946
  int64_t sliding;
3947
  int64_t maxDelay;
3948
  int64_t watermark;
3949
  int32_t exprLen;        // strlen + 1
3950
  int32_t tagsFilterLen;  // strlen + 1
3951
  int32_t sqlLen;         // strlen + 1
3952
  int32_t astLen;         // strlen + 1
3953
  char*   expr;
3954
  char*   tagsFilter;
3955
  char*   sql;
3956
  char*   ast;
3957
  int64_t deleteMark;
3958
  int64_t lastTs;
3959
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3960
  SArray* pVgroupVerList;
3961
  int8_t  recursiveTsma;
3962
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3963
} SMCreateSmaReq;
3964

3965
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3966
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3967
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3968

3969
typedef struct {
3970
  char   name[TSDB_TABLE_FNAME_LEN];
3971
  int8_t igNotExists;
3972
} SMDropSmaReq;
3973

3974
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3975
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3976

3977
typedef struct {
3978
  char   dbFName[TSDB_DB_FNAME_LEN];
3979
  char   stbName[TSDB_TABLE_NAME_LEN];
3980
  char   colName[TSDB_COL_NAME_LEN];
3981
  char   idxName[TSDB_INDEX_FNAME_LEN];
3982
  int8_t idxType;
3983
} SCreateTagIndexReq;
3984

3985
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3986
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3987

3988
typedef SMDropSmaReq SDropTagIndexReq;
3989

3990
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3991
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3992

3993
typedef struct {
3994
  int8_t         version;       // for compatibility(default 0)
3995
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
3996
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
3997
  int8_t         timezoneInt;   // sma data expired if timezone changes.
3998
  int32_t        dstVgId;
3999
  char           indexName[TSDB_INDEX_NAME_LEN];
4000
  int32_t        exprLen;
4001
  int32_t        tagsFilterLen;
4002
  int64_t        indexUid;
4003
  tb_uid_t       tableUid;  // super/child/common table uid
4004
  tb_uid_t       dstTbUid;  // for dstVgroup
4005
  int64_t        interval;
4006
  int64_t        offset;  // use unit by precision of DB
4007
  int64_t        sliding;
4008
  char*          dstTbName;  // for dstVgroup
4009
  char*          expr;       // sma expression
4010
  char*          tagsFilter;
4011
  SSchemaWrapper schemaRow;  // for dstVgroup
4012
  SSchemaWrapper schemaTag;  // for dstVgroup
4013
} STSma;                     // Time-range-wise SMA
4014

4015
typedef STSma SVCreateTSmaReq;
4016

4017
typedef struct {
4018
  int8_t  type;  // 0 status report, 1 update data
4019
  int64_t indexUid;
4020
  int64_t skey;  // start TS key of interval/sliding window
4021
} STSmaMsg;
4022

4023
typedef struct {
4024
  int64_t indexUid;
4025
  char    indexName[TSDB_INDEX_NAME_LEN];
4026
} SVDropTSmaReq;
4027

4028
typedef struct {
4029
  int tmp;  // TODO: to avoid compile error
4030
} SVCreateTSmaRsp, SVDropTSmaRsp;
4031

4032
#if 0
4033
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4034
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4035
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4036
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4037
#endif
4038

4039
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4040
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4041
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4042
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4043

4044
typedef struct {
4045
  int32_t number;
4046
  STSma*  tSma;
4047
} STSmaWrapper;
4048

4049
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4050
  if (pSma) {
2!
4051
    taosMemoryFreeClear(pSma->dstTbName);
2!
4052
    taosMemoryFreeClear(pSma->expr);
2!
4053
    taosMemoryFreeClear(pSma->tagsFilter);
2!
4054
  }
4055
}
2✔
4056

4057
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4058
  if (pSW) {
×
4059
    if (pSW->tSma) {
×
4060
      if (deepCopy) {
×
UNCOV
4061
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
UNCOV
4062
          tDestroyTSma(pSW->tSma + i);
×
4063
        }
4064
      }
UNCOV
4065
      taosMemoryFreeClear(pSW->tSma);
×
4066
    }
4067
  }
UNCOV
4068
}
×
4069

4070
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4071
  tDestroyTSmaWrapper(pSW, deepCopy);
×
UNCOV
4072
  taosMemoryFreeClear(pSW);
×
UNCOV
4073
  return NULL;
×
4074
}
4075

4076
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4077
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4078

4079
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4080
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4081

4082
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4083
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
UNCOV
4084
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4085
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4086
  }
UNCOV
4087
  return 0;
×
4088
}
4089

4090
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4091
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
4092
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4093
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4094
  }
UNCOV
4095
  return 0;
×
4096
}
4097

4098
typedef struct {
4099
  int idx;
4100
} SMCreateFullTextReq;
4101

4102
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4103
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4104
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4105

4106
typedef struct {
4107
  char   name[TSDB_TABLE_FNAME_LEN];
4108
  int8_t igNotExists;
4109
} SMDropFullTextReq;
4110

4111
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4112
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4113

4114
typedef struct {
4115
  char indexFName[TSDB_INDEX_FNAME_LEN];
4116
} SUserIndexReq;
4117

4118
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4119
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4120

4121
typedef struct {
4122
  char dbFName[TSDB_DB_FNAME_LEN];
4123
  char tblFName[TSDB_TABLE_FNAME_LEN];
4124
  char colName[TSDB_COL_NAME_LEN];
4125
  char indexType[TSDB_INDEX_TYPE_LEN];
4126
  char indexExts[TSDB_INDEX_EXTS_LEN];
4127
} SUserIndexRsp;
4128

4129
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4130
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4131

4132
typedef struct {
4133
  char tbFName[TSDB_TABLE_FNAME_LEN];
4134
} STableIndexReq;
4135

4136
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4137
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4138

4139
typedef struct {
4140
  int8_t  intervalUnit;
4141
  int8_t  slidingUnit;
4142
  int64_t interval;
4143
  int64_t offset;
4144
  int64_t sliding;
4145
  int64_t dstTbUid;
4146
  int32_t dstVgId;
4147
  SEpSet  epSet;
4148
  char*   expr;
4149
} STableIndexInfo;
4150

4151
typedef struct {
4152
  char     tbName[TSDB_TABLE_NAME_LEN];
4153
  char     dbFName[TSDB_DB_FNAME_LEN];
4154
  uint64_t suid;
4155
  int32_t  version;
4156
  int32_t  indexSize;
4157
  SArray*  pIndex;  // STableIndexInfo
4158
} STableIndexRsp;
4159

4160
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4161
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4162
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4163

4164
void tFreeSTableIndexInfo(void* pInfo);
4165

4166
typedef struct {
4167
  int8_t  mqMsgType;
4168
  int32_t code;
4169
  int32_t epoch;
4170
  int64_t consumerId;
4171
  int64_t walsver;
4172
  int64_t walever;
4173
} SMqRspHead;
4174

4175
typedef struct {
4176
  SMsgHead     head;
4177
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4178
  int8_t       withTbName;
4179
  int8_t       useSnapshot;
4180
  int32_t      epoch;
4181
  uint64_t     reqId;
4182
  int64_t      consumerId;
4183
  int64_t      timeout;
4184
  STqOffsetVal reqOffset;
4185
  int8_t       enableReplay;
4186
  int8_t       sourceExcluded;
4187
  int8_t       enableBatchMeta;
4188
} SMqPollReq;
4189

4190
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4191
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4192
void    tDestroySMqPollReq(SMqPollReq* pReq);
4193

4194
typedef struct {
4195
  int32_t vgId;
4196
  int64_t offset;
4197
  SEpSet  epSet;
4198
} SMqSubVgEp;
4199

4200
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4201
  int32_t tlen = 0;
8,448✔
4202
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,448✔
4203
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,448✔
4204
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,448✔
4205
  return tlen;
8,448✔
4206
}
4207

4208
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4209
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,105!
4210
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,105!
4211
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,105✔
4212
  return buf;
4,105✔
4213
}
4214

4215
typedef struct {
4216
  char           topic[TSDB_TOPIC_FNAME_LEN];
4217
  char           db[TSDB_DB_FNAME_LEN];
4218
  SArray*        vgs;  // SArray<SMqSubVgEp>
4219
  SSchemaWrapper schema;
4220
} SMqSubTopicEp;
4221

4222
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4223
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4224
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4225

4226
typedef struct {
4227
  SMqRspHead   head;
4228
  STqOffsetVal rspOffset;
4229
  int16_t      resMsgType;
4230
  int32_t      metaRspLen;
4231
  void*        metaRsp;
4232
} SMqMetaRsp;
4233

4234
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4235
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4236
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4237

4238
#define MQ_DATA_RSP_VERSION 100
4239

4240
typedef struct {
4241
  SMqRspHead   head;
4242
  STqOffsetVal rspOffset;
4243
  STqOffsetVal reqOffset;
4244
  int32_t      blockNum;
4245
  int8_t       withTbName;
4246
  int8_t       withSchema;
4247
  SArray*      blockDataLen;
4248
  SArray*      blockData;
4249
  SArray*      blockTbName;
4250
  SArray*      blockSchema;
4251

4252
  union {
4253
    struct {
4254
      int64_t sleepTime;
4255
    };
4256
    struct {
4257
      int32_t createTableNum;
4258
      SArray* createTableLen;
4259
      SArray* createTableReq;
4260
    };
4261
  };
4262

4263
} SMqDataRsp;
4264

4265
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4266
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4267
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4268

4269
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4270
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4271
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4272

4273
typedef struct SMqBatchMetaRsp {
4274
  SMqRspHead   head;  // not serialize
4275
  STqOffsetVal rspOffset;
4276
  SArray*      batchMetaLen;
4277
  SArray*      batchMetaReq;
4278
  void*        pMetaBuff;    // not serialize
4279
  uint32_t     metaBuffLen;  // not serialize
4280
} SMqBatchMetaRsp;
4281

4282
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4283
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4284
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4285
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4286

4287
typedef struct {
4288
  SMqRspHead head;
4289
  char       cgroup[TSDB_CGROUP_LEN];
4290
  SArray*    topics;  // SArray<SMqSubTopicEp>
4291
} SMqAskEpRsp;
4292

4293
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4294
  int32_t tlen = 0;
17,790✔
4295
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4296
  int32_t sz = taosArrayGetSize(pRsp->topics);
17,790!
4297
  tlen += taosEncodeFixedI32(buf, sz);
17,789✔
4298
  for (int32_t i = 0; i < sz; i++) {
24,579✔
4299
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,790✔
4300
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,790✔
4301
  }
4302
  return tlen;
17,789✔
4303
}
4304

4305
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4306
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4307
  int32_t sz;
4308
  buf = taosDecodeFixedI32(buf, &sz);
8,481✔
4309
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,481✔
4310
  if (pRsp->topics == NULL) {
8,481!
UNCOV
4311
    return NULL;
×
4312
  }
4313
  for (int32_t i = 0; i < sz; i++) {
11,768✔
4314
    SMqSubTopicEp topicEp;
4315
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,287✔
4316
    if (buf == NULL) {
3,287!
UNCOV
4317
      return NULL;
×
4318
    }
4319
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,574!
UNCOV
4320
      return NULL;
×
4321
    }
4322
  }
4323
  return buf;
8,481✔
4324
}
4325

4326
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4327
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
20,435✔
4328
}
20,435✔
4329

4330
typedef struct {
4331
  int32_t      vgId;
4332
  STqOffsetVal offset;
4333
  int64_t      rows;
4334
  int64_t      ever;
4335
} OffsetRows;
4336

4337
typedef struct {
4338
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4339
  SArray* offsetRows;
4340
} TopicOffsetRows;
4341

4342
typedef struct {
4343
  int64_t consumerId;
4344
  int32_t epoch;
4345
  SArray* topics;
4346
  int8_t  pollFlag;
4347
} SMqHbReq;
4348

4349
typedef struct {
4350
  char   topic[TSDB_TOPIC_FNAME_LEN];
4351
  int8_t noPrivilege;
4352
} STopicPrivilege;
4353

4354
typedef struct {
4355
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4356
  int32_t debugFlag;
4357
} SMqHbRsp;
4358

4359
typedef struct {
4360
  SMsgHead head;
4361
  int64_t  consumerId;
4362
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4363
} SMqSeekReq;
4364

4365
#define TD_AUTO_CREATE_TABLE 0x1
4366
typedef struct {
4367
  int64_t       suid;
4368
  int64_t       uid;
4369
  int32_t       sver;
4370
  uint32_t      nData;
4371
  uint8_t*      pData;
4372
  SVCreateTbReq cTbReq;
4373
} SVSubmitBlk;
4374

4375
typedef struct {
4376
  SMsgHead header;
4377
  uint64_t sId;
4378
  uint64_t queryId;
4379
  uint64_t clientId;
4380
  uint64_t taskId;
4381
  uint32_t sqlLen;
4382
  uint32_t phyLen;
4383
  char*    sql;
4384
  char*    msg;
4385
  int8_t   source;
4386
} SVDeleteReq;
4387

4388
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4389
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4390

4391
typedef struct {
4392
  int64_t affectedRows;
4393
} SVDeleteRsp;
4394

4395
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4396
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4397

4398
typedef struct SDeleteRes {
4399
  uint64_t suid;
4400
  SArray*  uidList;
4401
  int64_t  skey;
4402
  int64_t  ekey;
4403
  int64_t  affectedRows;
4404
  char     tableFName[TSDB_TABLE_NAME_LEN];
4405
  char     tsColName[TSDB_COL_NAME_LEN];
4406
  int64_t  ctimeMs;  // fill by vnode
4407
  int8_t   source;
4408
} SDeleteRes;
4409

4410
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4411
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4412

4413
typedef struct {
4414
  // int64_t uid;
4415
  char    tbname[TSDB_TABLE_NAME_LEN];
4416
  int64_t startTs;
4417
  int64_t endTs;
4418
} SSingleDeleteReq;
4419

4420
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4421
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4422

4423
typedef struct {
4424
  int64_t suid;
4425
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4426
  int64_t ctimeMs;     // fill by vnode
4427
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4428
} SBatchDeleteReq;
4429

4430
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4431
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4432
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4433

4434
typedef struct {
4435
  int32_t msgIdx;
4436
  int32_t msgType;
4437
  int32_t msgLen;
4438
  void*   msg;
4439
} SBatchMsg;
4440

4441
typedef struct {
4442
  SMsgHead header;
4443
  SArray*  pMsgs;  // SArray<SBatchMsg>
4444
} SBatchReq;
4445

4446
typedef struct {
4447
  int32_t reqType;
4448
  int32_t msgIdx;
4449
  int32_t msgLen;
4450
  int32_t rspCode;
4451
  void*   msg;
4452
} SBatchRspMsg;
4453

4454
typedef struct {
4455
  SArray* pRsps;  // SArray<SBatchRspMsg>
4456
} SBatchRsp;
4457

4458
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4459
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4460
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
156,361✔
4461
  if (NULL == msg) {
156,361!
UNCOV
4462
    return;
×
4463
  }
4464
  SBatchMsg* pMsg = (SBatchMsg*)msg;
156,361✔
4465
  taosMemoryFree(pMsg->msg);
156,361!
4466
}
4467

4468
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4469
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4470

4471
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
188,207✔
4472
  if (NULL == p) {
188,207!
UNCOV
4473
    return;
×
4474
  }
4475

4476
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
188,207✔
4477
  taosMemoryFree(pRsp->msg);
188,207!
4478
}
4479

4480
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4481
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4482
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4483
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4484
void    tDestroySMqHbReq(SMqHbReq* pReq);
4485

4486
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4487
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4488
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4489

4490
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4491
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4492

4493
#define TD_REQ_FROM_APP               0x0
4494
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4495
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4496
#define SUBMIT_REQ_FROM_FILE          0x4
4497
#define TD_REQ_FROM_TAOX              0x8
4498
#define SUBMIT_REQUEST_VERSION        (1)
4499

4500
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4501

4502
typedef struct {
4503
  int32_t        flags;
4504
  SVCreateTbReq* pCreateTbReq;
4505
  int64_t        suid;
4506
  int64_t        uid;
4507
  int32_t        sver;
4508
  union {
4509
    SArray* aRowP;
4510
    SArray* aCol;
4511
  };
4512
  int64_t ctimeMs;
4513
} SSubmitTbData;
4514

4515
typedef struct {
4516
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4517
} SSubmitReq2;
4518

4519
typedef struct {
4520
  SMsgHead header;
4521
  int64_t  version;
4522
  char     data[];  // SSubmitReq2
4523
} SSubmitReq2Msg;
4524

4525
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4526
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
4527
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4528
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4529

4530
typedef struct {
4531
  int32_t affectedRows;
4532
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4533
} SSubmitRsp2;
4534

4535
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4536
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4537
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4538

4539
#define TSDB_MSG_FLG_ENCODE 0x1
4540
#define TSDB_MSG_FLG_DECODE 0x2
4541
#define TSDB_MSG_FLG_CMPT   0x3
4542

4543
typedef struct {
4544
  union {
4545
    struct {
4546
      void*   msgStr;
4547
      int32_t msgLen;
4548
      int64_t ver;
4549
    };
4550
    void* pDataBlock;
4551
  };
4552
} SPackedData;
4553

4554
typedef struct {
4555
  char     fullname[TSDB_VIEW_FNAME_LEN];
4556
  char     name[TSDB_VIEW_NAME_LEN];
4557
  char     dbFName[TSDB_DB_FNAME_LEN];
4558
  char*    querySql;
4559
  char*    sql;
4560
  int8_t   orReplace;
4561
  int8_t   precision;
4562
  int32_t  numOfCols;
4563
  SSchema* pSchema;
4564
} SCMCreateViewReq;
4565

4566
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4567
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4568
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4569

4570
typedef struct {
4571
  char   fullname[TSDB_VIEW_FNAME_LEN];
4572
  char   name[TSDB_VIEW_NAME_LEN];
4573
  char   dbFName[TSDB_DB_FNAME_LEN];
4574
  char*  sql;
4575
  int8_t igNotExists;
4576
} SCMDropViewReq;
4577

4578
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4579
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4580
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4581

4582
typedef struct {
4583
  char fullname[TSDB_VIEW_FNAME_LEN];
4584
} SViewMetaReq;
4585
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4586
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4587

4588
typedef struct {
4589
  char     name[TSDB_VIEW_NAME_LEN];
4590
  char     dbFName[TSDB_DB_FNAME_LEN];
4591
  char*    user;
4592
  uint64_t dbId;
4593
  uint64_t viewId;
4594
  char*    querySql;
4595
  int8_t   precision;
4596
  int8_t   type;
4597
  int32_t  version;
4598
  int32_t  numOfCols;
4599
  SSchema* pSchema;
4600
} SViewMetaRsp;
4601
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4602
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4603
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4604
typedef struct {
4605
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4606
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4607
} STableTSMAInfoReq;
4608

4609
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4610
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4611

4612
typedef struct {
4613
  int32_t  funcId;
4614
  col_id_t colId;
4615
} STableTSMAFuncInfo;
4616

4617
typedef struct {
4618
  char     name[TSDB_TABLE_NAME_LEN];
4619
  uint64_t tsmaId;
4620
  char     targetTb[TSDB_TABLE_NAME_LEN];
4621
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4622
  char     tb[TSDB_TABLE_NAME_LEN];
4623
  char     dbFName[TSDB_DB_FNAME_LEN];
4624
  uint64_t suid;
4625
  uint64_t destTbUid;
4626
  uint64_t dbId;
4627
  int32_t  version;
4628
  int64_t  interval;
4629
  int8_t   unit;
4630
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4631
  SArray*  pTags;      // SArray<SSchema>
4632
  SArray*  pUsedCols;  // SArray<SSchema>
4633
  char*    ast;
4634

4635
  int64_t streamUid;
4636
  int64_t reqTs;
4637
  int64_t rspTs;
4638
  int64_t delayDuration;  // ms
4639
  bool    fillHistoryFinished;
4640
} STableTSMAInfo;
4641

4642
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4643
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4644
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4645
void    tFreeTableTSMAInfo(void* p);
4646
void    tFreeAndClearTableTSMAInfo(void* p);
4647
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4648

4649
#define STSMAHbRsp            STableTSMAInfoRsp
4650
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4651
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4652
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4653

4654
typedef struct SStreamProgressReq {
4655
  int64_t streamId;
4656
  int32_t vgId;
4657
  int32_t fetchIdx;
4658
  int32_t subFetchIdx;
4659
} SStreamProgressReq;
4660

4661
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4662
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4663

4664
typedef struct SStreamProgressRsp {
4665
  int64_t streamId;
4666
  int32_t vgId;
4667
  bool    fillHisFinished;
4668
  int64_t progressDelay;
4669
  int32_t fetchIdx;
4670
  int32_t subFetchIdx;
4671
} SStreamProgressRsp;
4672

4673
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4674
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4675

4676
typedef struct SDropCtbWithTsmaSingleVgReq {
4677
  SVgroupInfo vgInfo;
4678
  SArray*     pTbs;  // SVDropTbReq
4679
} SMDropTbReqsOnSingleVg;
4680

4681
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4682
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4683
void    tFreeSMDropTbReqOnSingleVg(void* p);
4684

4685
typedef struct SDropTbsReq {
4686
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4687
} SMDropTbsReq;
4688

4689
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4690
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4691
void    tFreeSMDropTbsReq(void*);
4692

4693
typedef struct SVFetchTtlExpiredTbsRsp {
4694
  SArray* pExpiredTbs;  // SVDropTbReq
4695
  int32_t vgId;
4696
} SVFetchTtlExpiredTbsRsp;
4697

4698
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4699
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4700

4701
void tFreeFetchTtlExpiredTbsRsp(void* p);
4702

4703
void setDefaultOptionsForField(SFieldWithOptions* field);
4704
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4705

4706
#pragma pack(pop)
4707

4708
#ifdef __cplusplus
4709
}
4710
#endif
4711

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