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

taosdata / TDengine / #3587

23 Jan 2025 02:42AM UTC coverage: 63.549% (-0.09%) from 63.643%
#3587

push

travis-ci

web-flow
Merge pull request #29637 from taosdata/docs/TS-5944

docs/TS-5944 Correct typos in the descriptions of maximum and minimum values for taosBenchmark

141306 of 285630 branches covered (49.47%)

Branch coverage included in aggregate %.

219951 of 282844 relevant lines covered (77.76%)

19107446.53 hits per line

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

48.47
/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) {
61,109,794✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
61,109,794✔
74
  int    segIdx = TMSG_SEG_CODE(type);
61,109,794✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
61,109,794!
76
    return type < tMsgRangeDict[segIdx];
61,112,022✔
77
  }
78
  return false;
×
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
6,832,936✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
6,805,757✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
13,638,693!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
37,335,339✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
37,335,339✔
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,571!
738
    return TSDB_CODE_INVALID_PARA;
×
739
  }
740
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
15,571!
741
  if (pCmpr->pColCmpr == NULL) {
15,571!
742
    return terrno;
×
743
  }
744
  pCmpr->nCols = nCols;
15,571✔
745
  return 0;
15,571✔
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;
11,209,449!
774

775
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
11,209,449!
776
  if (pSW == NULL) {
11,207,210!
777
    return NULL;
×
778
  }
779
  pSW->nCols = pSchemaWrapper->nCols;
11,207,210✔
780
  pSW->version = pSchemaWrapper->version;
11,207,210✔
781
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
11,207,210!
782
  if (pSW->pSchema == NULL) {
11,204,789!
783
    taosMemoryFree(pSW);
×
784
    return NULL;
×
785
  }
786

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

791
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
466,708✔
792
  if (pSchemaWrapper) {
26,767,770!
793
    taosMemoryFree(pSchemaWrapper->pSchema);
10,269,814!
794
    taosMemoryFree(pSchemaWrapper);
10,270,009!
795
  }
796
}
26,766,949✔
797

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

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

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

824
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
825
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
375,805,601!
826
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
395,136,336!
827
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
395,136,336!
828
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
395,136,336!
829
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
395,136,336!
830
  return 0;
197,568,168✔
831
}
832

833
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
834
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
661,014,365!
835
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,290,274,713!
836
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,274,127,385!
837
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,294,133,568!
838
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
651,770,987!
839
  return 0;
710,130,533✔
840
}
841

842
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
843
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
221,461,182!
844
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
221,461,182!
845
  return 0;
110,730,591✔
846
}
847

848
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
849
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,951,088!
850
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,951,086!
851
  return 0;
1,975,542✔
852
}
853

854
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
855
  int32_t tlen = 0;
9,054✔
856
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
9,054✔
857
  tlen += taosEncodeVariantI32(buf, pSW->version);
9,054✔
858
  for (int32_t i = 0; i < pSW->nCols; i++) {
68,442✔
859
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
118,776!
860
  }
861
  return tlen;
9,054✔
862
}
863

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

873
    for (int32_t i = 0; i < pSW->nCols; i++) {
30,694✔
874
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
55,392✔
875
    }
876
  } else {
877
    pSW->pSchema = NULL;
1,237✔
878
  }
879
  return (void*)buf;
4,235✔
880
}
881

882
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
883
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,462,180!
884
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,462,180!
885
  for (int32_t i = 0; i < pSW->nCols; i++) {
20,061,825✔
886
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
38,661,470!
887
  }
888
  return 0;
731,090✔
889
}
890

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

895
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
599,442!
896
  if (pSW->pSchema == NULL) {
599,579!
897
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
898
  }
899
  for (int32_t i = 0; i < pSW->nCols; i++) {
9,030,415!
900
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
16,863,244!
901
  }
902

903
  return 0;
598,007✔
904
}
905

906
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
907
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
81,242,884!
908
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
78,338,849!
909

910
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
39,136,106!
911
  if (pSW->pSchema == NULL) {
39,447,548!
912
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
913
  }
914
  for (int32_t i = 0; i < pSW->nCols; i++) {
738,642,792✔
915
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,396,202,440!
916
  }
917

918
  return 0;
41,635,596✔
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
} SMArbUpdateGroup;
2616

2617
typedef struct {
2618
  SArray* updateArray;  // SMArbUpdateGroup
2619
} SMArbUpdateGroupBatchReq;
2620

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

2625
typedef struct {
2626
  char queryStrId[TSDB_QUERY_ID_LEN];
2627
} SKillQueryReq;
2628

2629
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2630
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2631

2632
typedef struct {
2633
  uint32_t connId;
2634
} SKillConnReq;
2635

2636
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2637
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2638

2639
typedef struct {
2640
  int32_t transId;
2641
} SKillTransReq;
2642

2643
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2644
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2645

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

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

2656
typedef struct {
2657
  int32_t vgId1;
2658
  int32_t vgId2;
2659
} SMergeVgroupReq;
2660

2661
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2662
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2663

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

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

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

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

2689
typedef struct {
2690
  int32_t vgId;
2691
} SForceBecomeFollowerReq;
2692

2693
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2694
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2695

2696
typedef struct {
2697
  int32_t vgId;
2698
} SSplitVgroupReq;
2699

2700
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2701
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2702

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

2711
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2712
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2713

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

2719
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2720
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2721

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

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

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

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

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

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

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

2789
typedef struct STableScanOperatorParam {
2790
  bool    tableSeq;
2791
  SArray* pUidList;
2792
} STableScanOperatorParam;
2793

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

2804
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2805
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2806

2807
typedef struct {
2808
  SMsgHead header;
2809
  uint64_t clientId;
2810
} SSchTasksStatusReq;
2811

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

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

2826
typedef struct {
2827
  uint64_t queryId;
2828
  uint64_t taskId;
2829
  int8_t   action;
2830
} STaskAction;
2831

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

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

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

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

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

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

2867
typedef struct {
2868
  int32_t code;
2869
} STaskCancelRsp;
2870

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

2881
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2882
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2883

2884
typedef enum {
2885
  TASK_NOTIFY_FINISHED = 1,
2886
} ETaskNotifyType;
2887

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

2899
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2900
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2901

2902
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2903
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2904

2905
typedef struct {
2906
  int32_t code;
2907
} STaskDropRsp;
2908

2909
#define STREAM_TRIGGER_AT_ONCE            1
2910
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2911
#define STREAM_TRIGGER_MAX_DELAY          3
2912
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2913

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

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

2928
typedef struct SVgroupVer {
2929
  int32_t vgId;
2930
  int64_t ver;
2931
} SVgroupVer;
2932

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

2967
typedef struct {
2968
  int64_t streamId;
2969
} SCMCreateStreamRsp;
2970

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

2975
enum {
2976
  TOPIC_SUB_TYPE__DB = 1,
2977
  TOPIC_SUB_TYPE__TABLE,
2978
  TOPIC_SUB_TYPE__COLUMN,
2979
};
2980

2981
#define DEFAULT_MAX_POLL_INTERVAL 300000
2982
#define DEFAULT_SESSION_TIMEOUT   12000
2983

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

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

2999
typedef struct {
3000
  int64_t consumerId;
3001
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3002

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

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

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

3027
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,438!
3028
  tlen += taosEncodeFixedI32(buf, topicNum);
2,438✔
3029

3030
  for (int32_t i = 0; i < topicNum; i++) {
3,446✔
3031
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,016✔
3032
  }
3033

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

3045
  return tlen;
2,438✔
3046
}
3047

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

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

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

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

3085
  return 0;
1,316✔
3086
}
3087

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

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

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

3122
typedef struct {
3123
  int64_t status;
3124
} SMVSubscribeRsp;
3125

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

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

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

3143
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3144
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3145

3146
typedef struct {
3147
  int8_t reserved;
3148
} SMDropCgroupRsp;
3149

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

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

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

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

3181
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3182
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3183

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

3199
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3200
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3201

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

3208
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3209
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3210

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

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

3243
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,813✔
3244
  if (NULL == req) {
19,652,903!
3245
    return;
19,369,830✔
3246
  }
3247

3248
  taosMemoryFreeClear(req->sql);
283,073!
3249
  taosMemoryFreeClear(req->name);
283,073!
3250
  taosMemoryFreeClear(req->comment);
283,095!
3251
  if (req->type == TSDB_CHILD_TABLE) {
283,095!
3252
    taosMemoryFreeClear(req->ctb.pTag);
267,498!
3253
    taosMemoryFreeClear(req->ctb.stbName);
267,493!
3254
    taosArrayDestroy(req->ctb.tagName);
267,508✔
3255
    req->ctb.tagName = NULL;
267,510✔
3256
  } else if (req->type == TSDB_NORMAL_TABLE) {
15,597!
3257
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
15,571!
3258
  }
3259
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
283,107!
3260
}
3261

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

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

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

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

3284
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3285
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3286

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

3295
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3296
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3297

3298
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3299
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3300

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

3309
typedef struct {
3310
  int32_t code;
3311
} SVDropTbRsp;
3312

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

3321
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3322
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3323

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

3332
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3333
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3334

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

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

3383
typedef struct {
3384
  int32_t        code;
3385
  STableMetaRsp* pMeta;
3386
} SVAlterTbRsp;
3387

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

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

3406
typedef struct {
3407
  SMsgHead head;
3408
} SUpdateTagValRsp;
3409

3410
typedef struct {
3411
  SMsgHead head;
3412
} SVShowTablesReq;
3413

3414
typedef struct {
3415
  SMsgHead head;
3416
  int32_t  id;
3417
} SVShowTablesFetchReq;
3418

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

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

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

3441
typedef struct {
3442
  int64_t tscRid;
3443
  int8_t  connType;
3444
} SClientHbKey;
3445

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

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

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

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

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

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

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

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

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

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

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

3534
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
225,292✔
3535

3536
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3537
  void* pIter = taosHashIterate(info, NULL);
549,891✔
3538
  while (pIter != NULL) {
930,917!
3539
    SKv* kv = (SKv*)pIter;
380,937✔
3540
    taosMemoryFreeClear(kv->value);
380,937!
3541
    pIter = taosHashIterate(info, pIter);
380,938✔
3542
  }
3543
}
549,980✔
3544

3545
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
352,065✔
3546
  SQueryDesc* desc = (SQueryDesc*)pDesc;
352,065✔
3547
  if (desc->subDesc) {
352,065✔
3548
    taosArrayDestroy(desc->subDesc);
345,350✔
3549
    desc->subDesc = NULL;
345,353✔
3550
  }
3551
}
352,068✔
3552

3553
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
652,681✔
3554
  SClientHbReq* req = (SClientHbReq*)pReq;
663,759✔
3555
  if (req->query) {
663,759!
3556
    if (req->query->queryDesc) {
643,131!
3557
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
47,421✔
3558
    }
3559
    taosMemoryFreeClear(req->query);
643,131!
3560
  }
3561

3562
  if (req->info) {
663,761!
3563
    tFreeReqKvHash(req->info);
549,891✔
3564
    taosHashCleanup(req->info);
549,980✔
3565
    req->info = NULL;
549,955✔
3566
  }
3567
}
527,891✔
3568

3569
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3570
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3571

3572
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3573
  if (pReq == NULL) return;
41,123!
3574
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
41,123✔
3575
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
41,123✔
3576
  taosMemoryFree(pReq);
41,123!
3577
}
3578

3579
static FORCE_INLINE void tFreeClientKv(void* pKv) {
139,098✔
3580
  SKv* kv = (SKv*)pKv;
139,098✔
3581
  if (kv) {
139,098!
3582
    taosMemoryFreeClear(kv->value);
139,098!
3583
  }
3584
}
139,098✔
3585

3586
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
650,303✔
3587
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
650,303✔
3588
  if (rsp->query) {
650,303✔
3589
    taosArrayDestroy(rsp->query->pQnodeList);
640,893✔
3590
    taosMemoryFreeClear(rsp->query);
640,966!
3591
  }
3592
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
650,452!
3593
}
133,772✔
3594

3595
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3596
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
431,685✔
3597
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
431,685✔
3598
}
431,888✔
3599

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

3604
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3605
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
682,666!
3606
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
682,666!
3607
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
682,666!
3608
  return 0;
341,333✔
3609
}
3610

3611
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3612
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
698,689!
3613
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
698,694!
3614
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
349,350!
3615
  if (pKv->value == NULL) {
349,350!
3616
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3617
  }
3618
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
349,350!
3619
  return 0;
349,350✔
3620
}
3621

3622
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3623
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,609,656!
3624
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,609,656!
3625
  return 0;
1,304,828✔
3626
}
3627

3628
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3629
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,301,032!
3630
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,301,109!
3631
  return 0;
650,588✔
3632
}
3633

3634
typedef struct {
3635
  int32_t vgId;
3636
  // TODO stas
3637
} SMqReportVgInfo;
3638

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

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

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

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

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

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

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

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

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

3738
typedef struct {
3739
  int8_t reserved;
3740
} SMqVDeleteRsp;
3741

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

3749
typedef struct {
3750
  int8_t reserved;
3751
} SMDropStreamRsp;
3752

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

3760
typedef struct {
3761
  int8_t reserved;
3762
} SVDropStreamTaskRsp;
3763

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

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

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

3793
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3794
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3795

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

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

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

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

3822
#define TQ_OFFSET_VERSION 1
3823

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

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

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

3855
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3856
  pOffsetVal->type = TMQ_OFFSET__LOG;
577,390✔
3857
  pOffsetVal->version = ver;
577,390✔
3858
}
577,390✔
3859

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

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

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

3876
typedef struct SMqVgOffset {
3877
  int64_t   consumerId;
3878
  STqOffset offset;
3879
} SMqVgOffset;
3880

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

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

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

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

3902
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3903
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3904

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

3912
typedef struct {
3913
  int8_t reserved;
3914
} SVResumeStreamTaskRsp;
3915

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

3922
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3923
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3924

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

3931
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
3932
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
3933

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

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

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

3972
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3973
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3974

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

3983
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3984
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3985

3986
typedef SMDropSmaReq SDropTagIndexReq;
3987

3988
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3989
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3990

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

4013
typedef STSma SVCreateTSmaReq;
4014

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

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

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

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

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

4042
typedef struct {
4043
  int32_t number;
4044
  STSma*  tSma;
4045
} STSmaWrapper;
4046

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

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

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

4074
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4075
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4076

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

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

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

4096
typedef struct {
4097
  int idx;
4098
} SMCreateFullTextReq;
4099

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

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

4109
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4110
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4111

4112
typedef struct {
4113
  char indexFName[TSDB_INDEX_FNAME_LEN];
4114
} SUserIndexReq;
4115

4116
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4117
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4118

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

4127
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4128
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4129

4130
typedef struct {
4131
  char tbFName[TSDB_TABLE_FNAME_LEN];
4132
} STableIndexReq;
4133

4134
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4135
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4136

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

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

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

4162
void tFreeSTableIndexInfo(void* pInfo);
4163

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

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

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

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

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

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

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

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

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

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

4236
#define MQ_DATA_RSP_VERSION 100
4237

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

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

4261
} SMqDataRsp;
4262

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

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

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

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

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

4291
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4292
  int32_t tlen = 0;
19,650✔
4293
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4294
  int32_t sz = taosArrayGetSize(pRsp->topics);
19,650!
4295
  tlen += taosEncodeFixedI32(buf, sz);
19,649✔
4296
  for (int32_t i = 0; i < sz; i++) {
26,929✔
4297
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
7,280✔
4298
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
7,280✔
4299
  }
4300
  return tlen;
19,649✔
4301
}
4302

4303
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4304
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4305
  int32_t sz;
4306
  buf = taosDecodeFixedI32(buf, &sz);
8,717✔
4307
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,717✔
4308
  if (pRsp->topics == NULL) {
8,717!
4309
    return NULL;
×
4310
  }
4311
  for (int32_t i = 0; i < sz; i++) {
12,250✔
4312
    SMqSubTopicEp topicEp;
4313
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,533✔
4314
    if (buf == NULL) {
3,533!
4315
      return NULL;
×
4316
    }
4317
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
7,066!
4318
      return NULL;
×
4319
    }
4320
  }
4321
  return buf;
8,717✔
4322
}
4323

4324
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4325
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
21,696✔
4326
}
21,696✔
4327

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

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

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

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

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

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

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

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

4386
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4387
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4388

4389
typedef struct {
4390
  int64_t affectedRows;
4391
} SVDeleteRsp;
4392

4393
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4394
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4395

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

4408
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4409
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4410

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

4418
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4419
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4420

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

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

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

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

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

4452
typedef struct {
4453
  SArray* pRsps;  // SArray<SBatchRspMsg>
4454
} SBatchRsp;
4455

4456
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4457
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4458
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
7,213,950✔
4459
  if (NULL == msg) {
7,213,950!
4460
    return;
×
4461
  }
4462
  SBatchMsg* pMsg = (SBatchMsg*)msg;
7,213,950✔
4463
  taosMemoryFree(pMsg->msg);
7,213,950!
4464
}
4465

4466
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4467
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4468

4469
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,507,744✔
4470
  if (NULL == p) {
1,507,744!
4471
    return;
×
4472
  }
4473

4474
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,507,744✔
4475
  taosMemoryFree(pRsp->msg);
1,507,744!
4476
}
4477

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

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

4488
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4489
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4490

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

4498
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4499

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

4513
typedef struct {
4514
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4515
} SSubmitReq2;
4516

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

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

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

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

4537
#define TSDB_MSG_FLG_ENCODE 0x1
4538
#define TSDB_MSG_FLG_DECODE 0x2
4539
#define TSDB_MSG_FLG_CMPT   0x3
4540

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

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

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

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

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

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

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

4607
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4608
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4609

4610
typedef struct {
4611
  int32_t  funcId;
4612
  col_id_t colId;
4613
} STableTSMAFuncInfo;
4614

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

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

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

4647
#define STSMAHbRsp            STableTSMAInfoRsp
4648
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4649
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4650
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4651

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

4659
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4660
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4661

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

4671
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4672
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4673

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

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

4683
typedef struct SDropTbsReq {
4684
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4685
} SMDropTbsReq;
4686

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

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

4696
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4697
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4698

4699
void tFreeFetchTtlExpiredTbsRsp(void* p);
4700

4701
void setDefaultOptionsForField(SFieldWithOptions* field);
4702
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4703

4704
#pragma pack(pop)
4705

4706
#ifdef __cplusplus
4707
}
4708
#endif
4709

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