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

taosdata / TDengine / #3616

19 Feb 2025 11:22AM UTC coverage: 63.315% (+0.4%) from 62.953%
#3616

push

travis-ci

web-flow
Merge pull request #29823 from taosdata/feat/TS-5928

fix:[TS-5928]add consumer parameters

148228 of 300186 branches covered (49.38%)

Branch coverage included in aggregate %.

232358 of 300909 relevant lines covered (77.22%)

17990742.15 hits per line

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

48.52
/include/common/tmsg.h
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#ifndef _TD_COMMON_TAOS_MSG_H_
17
#define _TD_COMMON_TAOS_MSG_H_
18

19
#include "taosdef.h"
20
#include "taoserror.h"
21
#include "tarray.h"
22
#include "tcoding.h"
23
#include "tcol.h"
24
#include "tencode.h"
25
#include "thash.h"
26
#include "tlist.h"
27
#include "tname.h"
28
#include "trow.h"
29
#include "tuuid.h"
30

31
#ifdef __cplusplus
32
extern "C" {
33
#endif
34

35
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
36

37
#define TD_MSG_NUMBER_
38
#undef TD_MSG_DICT_
39
#undef TD_MSG_INFO_
40
#undef TD_MSG_TYPE_INFO_
41
#undef TD_MSG_RANGE_CODE_
42
#undef TD_MSG_SEG_CODE_
43
#include "tmsgdef.h"
44

45
#undef TD_MSG_NUMBER_
46
#undef TD_MSG_DICT_
47
#undef TD_MSG_INFO_
48
#undef TD_MSG_TYPE_INFO_
49
#undef TD_MSG_RANGE_CODE_
50
#define TD_MSG_SEG_CODE_
51
#include "tmsgdef.h"
52

53
#undef TD_MSG_NUMBER_
54
#undef TD_MSG_DICT_
55
#undef TD_MSG_INFO_
56
#undef TD_MSG_TYPE_INFO_
57
#undef TD_MSG_SEG_CODE_
58
#undef TD_MSG_RANGE_CODE_
59
#include "tmsgdef.h"
60

61
extern char*   tMsgInfo[];
62
extern int32_t tMsgDict[];
63
extern int32_t tMsgRangeDict[];
64

65
typedef uint16_t tmsg_t;
66

67
#define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8)
68
#define TMSG_SEG_SEQ(TYPE)  ((TYPE)&0xff)
69
#define TMSG_INDEX(TYPE)    (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE))
70

71
static inline bool tmsgIsValid(tmsg_t type) {
61,781,658✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
61,781,658✔
74
  int    segIdx = TMSG_SEG_CODE(type);
61,781,658✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
61,781,658!
76
    return type < tMsgRangeDict[segIdx];
61,783,828✔
77
  }
78
  return false;
×
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
3,360,892✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
3,335,654✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
6,696,546!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

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

775
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
11,459,384!
776
  if (pSW == NULL) {
11,454,944!
777
    return NULL;
×
778
  }
779
  pSW->nCols = pSchemaWrapper->nCols;
11,454,944✔
780
  pSW->version = pSchemaWrapper->version;
11,454,944✔
781
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
11,454,944!
782
  if (pSW->pSchema == NULL) {
11,453,060!
783
    taosMemoryFree(pSW);
×
784
    return NULL;
×
785
  }
786

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

791
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
590,578✔
792
  if (pSchemaWrapper) {
27,506,066!
793
    taosMemoryFree(pSchemaWrapper->pSchema);
10,548,448!
794
    taosMemoryFree(pSchemaWrapper);
10,548,808!
795
  }
796
}
27,504,873✔
797

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

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

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

824
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
825
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
374,905,802!
826
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
393,984,064!
827
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
393,984,064!
828
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
393,984,064!
829
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
393,984,064!
830
  return 0;
196,992,032✔
831
}
832

833
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
834
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
700,742,177!
835
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,374,731,338!
836
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,365,914,624!
837
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,385,248,985!
838
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
695,920,180!
839
  return 0;
745,380,365✔
840
}
841

842
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
843
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
220,947,876!
844
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
220,947,876!
845
  return 0;
110,473,938✔
846
}
847

848
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
849
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
4,071,414!
850
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
4,071,412!
851
  return 0;
2,035,707✔
852
}
853

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

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

873
    for (int32_t i = 0; i < pSW->nCols; i++) {
29,101✔
874
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
52,450✔
875
    }
876
  } else {
877
    pSW->pSchema = NULL;
1,139✔
878
  }
879
  return (void*)buf;
4,015✔
880
}
881

882
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
883
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,473,288!
884
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,473,288!
885
  for (int32_t i = 0; i < pSW->nCols; i++) {
19,814,906✔
886
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
38,156,524!
887
  }
888
  return 0;
736,644✔
889
}
890

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

895
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
605,077!
896
  if (pSW->pSchema == NULL) {
605,138!
897
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
898
  }
899
  for (int32_t i = 0; i < pSW->nCols; i++) {
9,006,183!
900
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
16,803,693!
901
  }
902

903
  return 0;
603,535✔
904
}
905

906
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
907
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
84,774,856!
908
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
82,392,554!
909

910
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
41,182,546!
911
  if (pSW->pSchema == NULL) {
41,449,367!
912
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
913
  }
914
  for (int32_t i = 0; i < pSW->nCols; i++) {
775,832,028✔
915
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,466,662,953!
916
  }
917

918
  return 0;
43,551,736✔
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
  int64_t syncAppliedIndex;
1781
  int64_t syncCommitIndex;
1782
} SVnodeLoad;
1783

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

1799
typedef struct {
1800
  int32_t vgId;
1801
  int64_t nTimeSeries;
1802
} SVnodeLoadLite;
1803

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

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

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

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

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

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

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

1869
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1870
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1871

1872
typedef enum {
1873
  MONITOR_TYPE_COUNTER = 0,
1874
  MONITOR_TYPE_SLOW_LOG = 1,
1875
} MONITOR_TYPE;
1876

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

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

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

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

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

1908
typedef struct {
1909
  int32_t dnodeId;
1910
  int64_t clusterId;
1911
} SDnodeCfg;
1912

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

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

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

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

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

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

1953
typedef struct {
1954
  int32_t reserved;
1955
} SMTimerReq;
1956

1957
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1958
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1959

1960
typedef struct SOrphanTask {
1961
  int64_t streamId;
1962
  int32_t taskId;
1963
  int32_t nodeId;
1964
} SOrphanTask;
1965

1966
typedef struct SMStreamDropOrphanMsg {
1967
  SArray* pList;  // SArray<SOrphanTask>
1968
} SMStreamDropOrphanMsg;
1969

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

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

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

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

2036
typedef struct {
2037
  int32_t compactId;
2038
  int32_t vgId;
2039
  int32_t dnodeId;
2040
} SQueryCompactProgressReq;
2041

2042
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2043
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2044

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

2055
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2056
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2057

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

2066
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2067
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2068

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

2077
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2078
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2079

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

2088
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2089
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2090

2091
typedef struct {
2092
  int32_t compactId;
2093
  int32_t vgId;
2094
  int32_t dnodeId;
2095
} SVKillCompactReq;
2096

2097
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2098
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2099

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

2126
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2127
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2128

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

2142
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2143
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2144

2145
typedef struct {
2146
  int32_t vgId;
2147
  int8_t  disable;
2148
} SDisableVnodeWriteReq;
2149

2150
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2151
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2152

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

2162
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2163
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2164

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

2174
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2175
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2176

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

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

2197
typedef struct {
2198
  int32_t     numOfVgroups;
2199
  SVgroupInfo vgroups[];
2200
} SVgroupsInfo;
2201

2202
typedef struct {
2203
  STableMetaRsp* pMeta;
2204
} SMAlterStbRsp;
2205

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

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

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

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

2224
typedef struct {
2225
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2226
} SViewHbRsp;
2227

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

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

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

2249
typedef struct {
2250
  int32_t useless;  // useless
2251
} SShowVariablesReq;
2252

2253
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2254
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2255

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

2264
typedef struct {
2265
  SArray* variables;  // SArray<SVariablesInfo>
2266
} SShowVariablesRsp;
2267

2268
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2269
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2270

2271
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2272

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

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

2289
typedef struct {
2290
  int64_t       showId;
2291
  STableMetaRsp tableMeta;
2292
} SShowRsp, SVShowTablesRsp;
2293

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

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

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

2314
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2315
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2316

2317
#define RETRIEVE_TABLE_RSP_VERSION          0
2318
#define RETRIEVE_TABLE_RSP_TMQ_VERSION      1
2319
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION  2
2320

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

2340
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2341

2342
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2343
  do {                                          \
2344
    ((int32_t*)(_p))[0] = (_compLen);           \
2345
    ((int32_t*)(_p))[1] = (_fullLen);           \
2346
  } while (0);
2347

2348
typedef struct {
2349
  int64_t version;
2350
  int64_t numOfRows;
2351
  int8_t  compressed;
2352
  int8_t  precision;
2353
  char    data[];
2354
} SRetrieveTableRspForTmq;
2355

2356
typedef struct {
2357
  int64_t handle;
2358
  int64_t useconds;
2359
  int8_t  completed;  // all results are returned to client
2360
  int8_t  precision;
2361
  int8_t  compressed;
2362
  int32_t compLen;
2363
  int32_t numOfRows;
2364
  int32_t fullLen;
2365
  char    data[];
2366
} SRetrieveMetaTableRsp;
2367

2368
typedef struct SExplainExecInfo {
2369
  double   startupCost;
2370
  double   totalCost;
2371
  uint64_t numOfRows;
2372
  uint32_t verboseLen;
2373
  void*    verboseInfo;
2374
} SExplainExecInfo;
2375

2376
typedef struct {
2377
  int32_t           numOfPlans;
2378
  SExplainExecInfo* subplanInfo;
2379
} SExplainRsp;
2380

2381
typedef struct {
2382
  SExplainRsp rsp;
2383
  uint64_t    qId;
2384
  uint64_t    cId;
2385
  uint64_t    tId;
2386
  int64_t     rId;
2387
  int32_t     eId;
2388
} SExplainLocalRsp;
2389

2390
typedef struct STableScanAnalyzeInfo {
2391
  uint64_t totalRows;
2392
  uint64_t totalCheckedRows;
2393
  uint32_t totalBlocks;
2394
  uint32_t loadBlocks;
2395
  uint32_t loadBlockStatis;
2396
  uint32_t skipBlocks;
2397
  uint32_t filterOutBlocks;
2398
  double   elapsedTime;
2399
  double   filterTime;
2400
} STableScanAnalyzeInfo;
2401

2402
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2403
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2404
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2405

2406
typedef struct {
2407
  char    config[TSDB_DNODE_CONFIG_LEN];
2408
  char    value[TSDB_CLUSTER_VALUE_LEN];
2409
  int32_t sqlLen;
2410
  char*   sql;
2411
} SMCfgClusterReq;
2412

2413
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2414
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2415
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2416

2417
typedef struct {
2418
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2419
  int32_t port;
2420
  int32_t sqlLen;
2421
  char*   sql;
2422
} SCreateDnodeReq;
2423

2424
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2425
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2426
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2427

2428
typedef struct {
2429
  int32_t dnodeId;
2430
  char    fqdn[TSDB_FQDN_LEN];
2431
  int32_t port;
2432
  int8_t  force;
2433
  int8_t  unsafe;
2434
  int32_t sqlLen;
2435
  char*   sql;
2436
} SDropDnodeReq;
2437

2438
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2439
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2440
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2441

2442
enum {
2443
  RESTORE_TYPE__ALL = 1,
2444
  RESTORE_TYPE__MNODE,
2445
  RESTORE_TYPE__VNODE,
2446
  RESTORE_TYPE__QNODE,
2447
};
2448

2449
typedef struct {
2450
  int32_t dnodeId;
2451
  int8_t  restoreType;
2452
  int32_t sqlLen;
2453
  char*   sql;
2454
} SRestoreDnodeReq;
2455

2456
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2457
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2458
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2459

2460
typedef struct {
2461
  int32_t dnodeId;
2462
  char    config[TSDB_DNODE_CONFIG_LEN];
2463
  char    value[TSDB_DNODE_VALUE_LEN];
2464
  int32_t sqlLen;
2465
  char*   sql;
2466
} SMCfgDnodeReq;
2467

2468
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2469
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2470
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2471

2472
typedef struct {
2473
  char    config[TSDB_DNODE_CONFIG_LEN];
2474
  char    value[TSDB_DNODE_VALUE_LEN];
2475
  int32_t version;
2476
} SDCfgDnodeReq;
2477

2478
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2479
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2480

2481
typedef struct {
2482
  int32_t dnodeId;
2483
  int32_t sqlLen;
2484
  char*   sql;
2485
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2486
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2487

2488
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2489
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2490
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2491
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2492
typedef struct {
2493
  int8_t   replica;
2494
  SReplica replicas[TSDB_MAX_REPLICA];
2495
  int8_t   learnerReplica;
2496
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2497
  int64_t  lastIndex;
2498
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2499

2500
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2501
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2502

2503
typedef struct {
2504
  int32_t urlLen;
2505
  int32_t sqlLen;
2506
  char*   url;
2507
  char*   sql;
2508
} SMCreateAnodeReq;
2509

2510
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2511
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2512
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2513

2514
typedef struct {
2515
  int32_t anodeId;
2516
  int32_t sqlLen;
2517
  char*   sql;
2518
} SMDropAnodeReq, SMUpdateAnodeReq;
2519

2520
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2521
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2522
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2523
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2524
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2525
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2526

2527
typedef struct {
2528
  int32_t vgId;
2529
  int32_t hbSeq;
2530
} SVArbHbReqMember;
2531

2532
typedef struct {
2533
  int32_t dnodeId;
2534
  char*   arbToken;
2535
  int64_t arbTerm;
2536
  SArray* hbMembers;  // SVArbHbReqMember
2537
} SVArbHeartBeatReq;
2538

2539
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2540
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2541
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2542

2543
typedef struct {
2544
  int32_t vgId;
2545
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2546
  int32_t hbSeq;
2547
} SVArbHbRspMember;
2548

2549
typedef struct {
2550
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2551
  int32_t dnodeId;
2552
  SArray* hbMembers;  // SVArbHbRspMember
2553
} SVArbHeartBeatRsp;
2554

2555
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2556
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2557
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2558

2559
typedef struct {
2560
  char*   arbToken;
2561
  int64_t arbTerm;
2562
  char*   member0Token;
2563
  char*   member1Token;
2564
} SVArbCheckSyncReq;
2565

2566
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2567
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2568
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2569

2570
typedef struct {
2571
  char*   arbToken;
2572
  char*   member0Token;
2573
  char*   member1Token;
2574
  int32_t vgId;
2575
  int32_t errCode;
2576
} SVArbCheckSyncRsp;
2577

2578
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2579
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2580
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2581

2582
typedef struct {
2583
  char*   arbToken;
2584
  int64_t arbTerm;
2585
  char*   memberToken;
2586
} SVArbSetAssignedLeaderReq;
2587

2588
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2589
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2590
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2591

2592
typedef struct {
2593
  char*   arbToken;
2594
  char*   memberToken;
2595
  int32_t vgId;
2596
} SVArbSetAssignedLeaderRsp;
2597

2598
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2599
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2600
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2601

2602
typedef struct {
2603
  int32_t dnodeId;
2604
  char*   token;
2605
} SMArbUpdateGroupMember;
2606

2607
typedef struct {
2608
  int32_t dnodeId;
2609
  char*   token;
2610
  int8_t  acked;
2611
} SMArbUpdateGroupAssigned;
2612

2613
typedef struct {
2614
  int32_t                  vgId;
2615
  int64_t                  dbUid;
2616
  SMArbUpdateGroupMember   members[2];
2617
  int8_t                   isSync;
2618
  int8_t                   assignedAcked;
2619
  SMArbUpdateGroupAssigned assignedLeader;
2620
  int64_t                  version;
2621
  int32_t                  code;
2622
  int64_t                  updateTimeMs;
2623
} SMArbUpdateGroup;
2624

2625
typedef struct {
2626
  SArray* updateArray;  // SMArbUpdateGroup
2627
} SMArbUpdateGroupBatchReq;
2628

2629
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2630
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2631
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2632

2633
typedef struct {
2634
  char queryStrId[TSDB_QUERY_ID_LEN];
2635
} SKillQueryReq;
2636

2637
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2638
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2639

2640
typedef struct {
2641
  uint32_t connId;
2642
} SKillConnReq;
2643

2644
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2645
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2646

2647
typedef struct {
2648
  int32_t transId;
2649
} SKillTransReq;
2650

2651
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2652
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2653

2654
typedef struct {
2655
  int32_t useless;  // useless
2656
  int32_t sqlLen;
2657
  char*   sql;
2658
} SBalanceVgroupReq;
2659

2660
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2661
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2662
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2663

2664
typedef struct {
2665
  int32_t vgId1;
2666
  int32_t vgId2;
2667
} SMergeVgroupReq;
2668

2669
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2670
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2671

2672
typedef struct {
2673
  int32_t vgId;
2674
  int32_t dnodeId1;
2675
  int32_t dnodeId2;
2676
  int32_t dnodeId3;
2677
  int32_t sqlLen;
2678
  char*   sql;
2679
} SRedistributeVgroupReq;
2680

2681
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2682
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2683
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2684

2685
typedef struct {
2686
  int32_t reserved;
2687
  int32_t vgId;
2688
  int32_t sqlLen;
2689
  char*   sql;
2690
  char    db[TSDB_DB_FNAME_LEN];
2691
} SBalanceVgroupLeaderReq;
2692

2693
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2694
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2695
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2696

2697
typedef struct {
2698
  int32_t vgId;
2699
} SForceBecomeFollowerReq;
2700

2701
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2702
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2703

2704
typedef struct {
2705
  int32_t vgId;
2706
} SSplitVgroupReq;
2707

2708
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2709
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2710

2711
typedef struct {
2712
  char user[TSDB_USER_LEN];
2713
  char spi;
2714
  char encrypt;
2715
  char secret[TSDB_PASSWORD_LEN];
2716
  char ckey[TSDB_PASSWORD_LEN];
2717
} SAuthReq, SAuthRsp;
2718

2719
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2720
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2721

2722
typedef struct {
2723
  int32_t statusCode;
2724
  char    details[1024];
2725
} SServerStatusRsp;
2726

2727
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2728
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2729

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

2756
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2757
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2758
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2759

2760
typedef struct {
2761
  SMsgHead header;
2762
  uint64_t sId;
2763
  uint64_t queryId;
2764
  uint64_t taskId;
2765
} SSinkDataReq;
2766

2767
typedef struct {
2768
  SMsgHead header;
2769
  uint64_t sId;
2770
  uint64_t queryId;
2771
  uint64_t clientId;
2772
  uint64_t taskId;
2773
  int32_t  execId;
2774
} SQueryContinueReq;
2775

2776
typedef struct {
2777
  SMsgHead header;
2778
  uint64_t sId;
2779
  uint64_t queryId;
2780
  uint64_t taskId;
2781
} SResReadyReq;
2782

2783
typedef struct {
2784
  int32_t code;
2785
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2786
  int32_t sversion;
2787
  int32_t tversion;
2788
} SResReadyRsp;
2789

2790
typedef struct SOperatorParam {
2791
  int32_t opType;
2792
  int32_t downstreamIdx;
2793
  void*   value;
2794
  SArray* pChildren;  // SArray<SOperatorParam*>
2795
} SOperatorParam;
2796

2797
typedef struct STableScanOperatorParam {
2798
  bool    tableSeq;
2799
  SArray* pUidList;
2800
} STableScanOperatorParam;
2801

2802
typedef struct {
2803
  SMsgHead        header;
2804
  uint64_t        sId;
2805
  uint64_t        queryId;
2806
  uint64_t        clientId;
2807
  uint64_t        taskId;
2808
  int32_t         execId;
2809
  SOperatorParam* pOpParam;
2810
} SResFetchReq;
2811

2812
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2813
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2814

2815
typedef struct {
2816
  SMsgHead header;
2817
  uint64_t clientId;
2818
} SSchTasksStatusReq;
2819

2820
typedef struct {
2821
  uint64_t queryId;
2822
  uint64_t clientId;
2823
  uint64_t taskId;
2824
  int64_t  refId;
2825
  int32_t  execId;
2826
  int8_t   status;
2827
} STaskStatus;
2828

2829
typedef struct {
2830
  int64_t refId;
2831
  SArray* taskStatus;  // SArray<STaskStatus>
2832
} SSchedulerStatusRsp;
2833

2834
typedef struct {
2835
  uint64_t queryId;
2836
  uint64_t taskId;
2837
  int8_t   action;
2838
} STaskAction;
2839

2840
typedef struct SQueryNodeEpId {
2841
  int32_t nodeId;  // vgId or qnodeId
2842
  SEp     ep;
2843
} SQueryNodeEpId;
2844

2845
typedef struct {
2846
  SMsgHead       header;
2847
  uint64_t       clientId;
2848
  SQueryNodeEpId epId;
2849
  SArray*        taskAction;  // SArray<STaskAction>
2850
} SSchedulerHbReq;
2851

2852
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2853
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2854
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2855

2856
typedef struct {
2857
  SQueryNodeEpId epId;
2858
  SArray*        taskStatus;  // SArray<STaskStatus>
2859
} SSchedulerHbRsp;
2860

2861
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2862
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2863
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2864

2865
typedef struct {
2866
  SMsgHead header;
2867
  uint64_t sId;
2868
  uint64_t queryId;
2869
  uint64_t clientId;
2870
  uint64_t taskId;
2871
  int64_t  refId;
2872
  int32_t  execId;
2873
} STaskCancelReq;
2874

2875
typedef struct {
2876
  int32_t code;
2877
} STaskCancelRsp;
2878

2879
typedef struct {
2880
  SMsgHead header;
2881
  uint64_t sId;
2882
  uint64_t queryId;
2883
  uint64_t clientId;
2884
  uint64_t taskId;
2885
  int64_t  refId;
2886
  int32_t  execId;
2887
} STaskDropReq;
2888

2889
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2890
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2891

2892
typedef enum {
2893
  TASK_NOTIFY_FINISHED = 1,
2894
} ETaskNotifyType;
2895

2896
typedef struct {
2897
  SMsgHead        header;
2898
  uint64_t        sId;
2899
  uint64_t        queryId;
2900
  uint64_t        clientId;
2901
  uint64_t        taskId;
2902
  int64_t         refId;
2903
  int32_t         execId;
2904
  ETaskNotifyType type;
2905
} STaskNotifyReq;
2906

2907
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2908
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2909

2910
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2911
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2912

2913
typedef struct {
2914
  int32_t code;
2915
} STaskDropRsp;
2916

2917
#define STREAM_TRIGGER_AT_ONCE            1
2918
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2919
#define STREAM_TRIGGER_MAX_DELAY          3
2920
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2921

2922
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2923
#define STREAM_FILL_HISTORY_ON        1
2924
#define STREAM_FILL_HISTORY_OFF       0
2925
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2926
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2927
#define STREAM_CREATE_STABLE_TRUE     1
2928
#define STREAM_CREATE_STABLE_FALSE    0
2929

2930
typedef struct SColLocation {
2931
  int16_t  slotId;
2932
  col_id_t colId;
2933
  int8_t   type;
2934
} SColLocation;
2935

2936
typedef struct SVgroupVer {
2937
  int32_t vgId;
2938
  int64_t ver;
2939
} SVgroupVer;
2940

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

2975
typedef struct STaskNotifyEventStat {
2976
  int64_t notifyEventAddTimes;     // call times of add function
2977
  int64_t notifyEventAddElems;     // elements added by add function
2978
  double  notifyEventAddCostSec;   // time cost of add function
2979
  int64_t notifyEventPushTimes;    // call times of push function
2980
  int64_t notifyEventPushElems;    // elements pushed by push function
2981
  double  notifyEventPushCostSec;  // time cost of push function
2982
  int64_t notifyEventPackTimes;    // call times of pack function
2983
  int64_t notifyEventPackElems;    // elements packed by pack function
2984
  double  notifyEventPackCostSec;  // time cost of pack function
2985
  int64_t notifyEventSendTimes;    // call times of send function
2986
  int64_t notifyEventSendElems;    // elements sent by send function
2987
  double  notifyEventSendCostSec;  // time cost of send function
2988
  int64_t notifyEventHoldElems;    // elements hold due to watermark
2989
} STaskNotifyEventStat;
2990

2991
typedef struct {
2992
  int64_t streamId;
2993
} SCMCreateStreamRsp;
2994

2995
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
2996
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
2997
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
2998

2999
enum {
3000
  TOPIC_SUB_TYPE__DB = 1,
3001
  TOPIC_SUB_TYPE__TABLE,
3002
  TOPIC_SUB_TYPE__COLUMN,
3003
};
3004

3005
#define DEFAULT_MAX_POLL_INTERVAL  300000
3006
#define DEFAULT_SESSION_TIMEOUT    12000
3007
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3008
#define DEFAULT_MIN_POLL_ROWS      4096
3009

3010
typedef struct {
3011
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3012
  int8_t igExists;
3013
  int8_t subType;
3014
  int8_t withMeta;
3015
  char*  sql;
3016
  char   subDbName[TSDB_DB_FNAME_LEN];
3017
  char*  ast;
3018
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3019
} SCMCreateTopicReq;
3020

3021
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3022
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3023
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3024

3025
typedef struct {
3026
  int64_t consumerId;
3027
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3028

3029
typedef struct {
3030
  int64_t consumerId;
3031
  char    cgroup[TSDB_CGROUP_LEN];
3032
  char    clientId[TSDB_CLIENT_ID_LEN];
3033
  char    user[TSDB_USER_LEN];
3034
  char    fqdn[TSDB_FQDN_LEN];
3035
  SArray* topicNames;  // SArray<char**>
3036

3037
  int8_t  withTbName;
3038
  int8_t  autoCommit;
3039
  int32_t autoCommitInterval;
3040
  int8_t  resetOffsetCfg;
3041
  int8_t  enableReplay;
3042
  int8_t  enableBatchMeta;
3043
  int32_t sessionTimeoutMs;
3044
  int32_t maxPollIntervalMs;
3045
} SCMSubscribeReq;
3046

3047
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3048
  int32_t tlen = 0;
2,448✔
3049
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,448!
3050
  tlen += taosEncodeString(buf, pReq->cgroup);
2,448✔
3051
  tlen += taosEncodeString(buf, pReq->clientId);
2,448✔
3052

3053
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,448!
3054
  tlen += taosEncodeFixedI32(buf, topicNum);
2,448✔
3055

3056
  for (int32_t i = 0; i < topicNum; i++) {
3,476✔
3057
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,056✔
3058
  }
3059

3060
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,448!
3061
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,448!
3062
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,448!
3063
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,448!
3064
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,448!
3065
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,448!
3066
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,448!
3067
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,448!
3068
  tlen += taosEncodeString(buf, pReq->user);
2,448✔
3069
  tlen += taosEncodeString(buf, pReq->fqdn);
2,448✔
3070

3071
  return tlen;
2,448✔
3072
}
3073

3074
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3075
  void* start = buf;
1,323✔
3076
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,323!
3077
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,323✔
3078
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,323✔
3079

3080
  int32_t topicNum = 0;
1,323!
3081
  buf = taosDecodeFixedI32(buf, &topicNum);
1,323✔
3082

3083
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,323✔
3084
  if (pReq->topicNames == NULL) {
1,323!
3085
    return terrno;
×
3086
  }
3087
  for (int32_t i = 0; i < topicNum; i++) {
1,940✔
3088
    char* name = NULL;
617✔
3089
    buf = taosDecodeString(buf, &name);
617✔
3090
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,234!
3091
      return terrno;
×
3092
    }
3093
  }
3094

3095
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,323✔
3096
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,323✔
3097
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,323!
3098
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,323✔
3099
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,323✔
3100
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,323✔
3101
  if ((char*)buf - (char*)start < len) {
1,323!
3102
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,323!
3103
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,323!
3104
    buf = taosDecodeStringTo(buf, pReq->user);
1,323✔
3105
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,646✔
3106
  } else {
3107
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3108
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3109
  }
3110

3111
  return 0;
1,323✔
3112
}
3113

3114
typedef struct {
3115
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3116
  SArray* removedConsumers;  // SArray<int64_t>
3117
  SArray* newConsumers;      // SArray<int64_t>
3118
} SMqRebInfo;
3119

3120
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3121
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,312!
3122
  if (pRebInfo == NULL) {
1,312!
3123
    return NULL;
×
3124
  }
3125
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,312✔
3126
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,312✔
3127
  if (pRebInfo->removedConsumers == NULL) {
1,312!
3128
    goto _err;
×
3129
  }
3130
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,312✔
3131
  if (pRebInfo->newConsumers == NULL) {
1,312!
3132
    goto _err;
×
3133
  }
3134
  return pRebInfo;
1,312✔
3135
_err:
×
3136
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3137
  taosArrayDestroy(pRebInfo->newConsumers);
×
3138
  taosMemoryFreeClear(pRebInfo);
×
3139
  return NULL;
×
3140
}
3141

3142
typedef struct {
3143
  int64_t streamId;
3144
  int64_t checkpointId;
3145
  char    streamName[TSDB_STREAM_FNAME_LEN];
3146
} SMStreamDoCheckpointMsg;
3147

3148
typedef struct {
3149
  int64_t status;
3150
} SMVSubscribeRsp;
3151

3152
typedef struct {
3153
  char    name[TSDB_TOPIC_FNAME_LEN];
3154
  int8_t  igNotExists;
3155
  int32_t sqlLen;
3156
  char*   sql;
3157
} SMDropTopicReq;
3158

3159
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3160
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3161
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3162

3163
typedef struct {
3164
  char   topic[TSDB_TOPIC_FNAME_LEN];
3165
  char   cgroup[TSDB_CGROUP_LEN];
3166
  int8_t igNotExists;
3167
} SMDropCgroupReq;
3168

3169
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3170
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3171

3172
typedef struct {
3173
  int8_t reserved;
3174
} SMDropCgroupRsp;
3175

3176
typedef struct {
3177
  char    name[TSDB_TABLE_FNAME_LEN];
3178
  int8_t  alterType;
3179
  SSchema schema;
3180
} SAlterTopicReq;
3181

3182
typedef struct {
3183
  SMsgHead head;
3184
  char     name[TSDB_TABLE_FNAME_LEN];
3185
  int64_t  tuid;
3186
  int32_t  sverson;
3187
  int32_t  execLen;
3188
  char*    executor;
3189
  int32_t  sqlLen;
3190
  char*    sql;
3191
} SDCreateTopicReq;
3192

3193
typedef struct {
3194
  SMsgHead head;
3195
  char     name[TSDB_TABLE_FNAME_LEN];
3196
  int64_t  tuid;
3197
} SDDropTopicReq;
3198

3199
typedef struct {
3200
  int64_t maxdelay[2];
3201
  int64_t watermark[2];
3202
  int64_t deleteMark[2];
3203
  int32_t qmsgLen[2];
3204
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3205
} SRSmaParam;
3206

3207
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3208
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3209

3210
// TDMT_VND_CREATE_STB ==============
3211
typedef struct SVCreateStbReq {
3212
  char*           name;
3213
  tb_uid_t        suid;
3214
  int8_t          rollup;
3215
  SSchemaWrapper  schemaRow;
3216
  SSchemaWrapper  schemaTag;
3217
  SRSmaParam      rsmaParam;
3218
  int32_t         alterOriDataLen;
3219
  void*           alterOriData;
3220
  int8_t          source;
3221
  int8_t          colCmpred;
3222
  SColCmprWrapper colCmpr;
3223
} SVCreateStbReq;
3224

3225
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3226
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3227

3228
// TDMT_VND_DROP_STB ==============
3229
typedef struct SVDropStbReq {
3230
  char*    name;
3231
  tb_uid_t suid;
3232
} SVDropStbReq;
3233

3234
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3235
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3236

3237
// TDMT_VND_CREATE_TABLE ==============
3238
#define TD_CREATE_IF_NOT_EXISTS 0x1
3239
typedef struct SVCreateTbReq {
3240
  int32_t  flags;
3241
  char*    name;
3242
  tb_uid_t uid;
3243
  int64_t  btime;
3244
  int32_t  ttl;
3245
  int32_t  commentLen;
3246
  char*    comment;
3247
  int8_t   type;
3248
  union {
3249
    struct {
3250
      char*    stbName;  // super table name
3251
      uint8_t  tagNum;
3252
      tb_uid_t suid;
3253
      SArray*  tagName;
3254
      uint8_t* pTag;
3255
    } ctb;
3256
    struct {
3257
      SSchemaWrapper schemaRow;
3258
    } ntb;
3259
  };
3260
  int32_t         sqlLen;
3261
  char*           sql;
3262
  SColCmprWrapper colCmpr;
3263
} SVCreateTbReq;
3264

3265
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3266
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3267
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3268

3269
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,789✔
3270
  if (NULL == req) {
19,558,691!
3271
    return;
19,261,239✔
3272
  }
3273

3274
  taosMemoryFreeClear(req->sql);
297,452!
3275
  taosMemoryFreeClear(req->name);
297,452!
3276
  taosMemoryFreeClear(req->comment);
297,479!
3277
  if (req->type == TSDB_CHILD_TABLE) {
297,479!
3278
    taosMemoryFreeClear(req->ctb.pTag);
281,523!
3279
    taosMemoryFreeClear(req->ctb.stbName);
281,532!
3280
    taosArrayDestroy(req->ctb.tagName);
281,530✔
3281
    req->ctb.tagName = NULL;
281,540✔
3282
  } else if (req->type == TSDB_NORMAL_TABLE) {
15,958!
3283
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
15,930!
3284
  }
3285
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
297,496!
3286
}
3287

3288
typedef struct {
3289
  int32_t nReqs;
3290
  union {
3291
    SVCreateTbReq* pReqs;
3292
    SArray*        pArray;
3293
  };
3294
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3295
} SVCreateTbBatchReq;
3296

3297
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3298
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3299
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3300

3301
typedef struct {
3302
  int32_t        code;
3303
  STableMetaRsp* pMeta;
3304
} SVCreateTbRsp, SVUpdateTbRsp;
3305

3306
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3307
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3308
void tFreeSVCreateTbRsp(void* param);
3309

3310
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3311
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3312

3313
typedef struct {
3314
  int32_t nRsps;
3315
  union {
3316
    SVCreateTbRsp* pRsps;
3317
    SArray*        pArray;
3318
  };
3319
} SVCreateTbBatchRsp;
3320

3321
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3322
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3323

3324
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3325
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3326

3327
// TDMT_VND_DROP_TABLE =================
3328
typedef struct {
3329
  char*    name;
3330
  uint64_t suid;  // for tmq in wal format
3331
  int64_t  uid;
3332
  int8_t   igNotExists;
3333
} SVDropTbReq;
3334

3335
typedef struct {
3336
  int32_t code;
3337
} SVDropTbRsp;
3338

3339
typedef struct {
3340
  int32_t nReqs;
3341
  union {
3342
    SVDropTbReq* pReqs;
3343
    SArray*      pArray;
3344
  };
3345
} SVDropTbBatchReq;
3346

3347
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3348
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3349

3350
typedef struct {
3351
  int32_t nRsps;
3352
  union {
3353
    SVDropTbRsp* pRsps;
3354
    SArray*      pArray;
3355
  };
3356
} SVDropTbBatchRsp;
3357

3358
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3359
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3360

3361
// TDMT_VND_ALTER_TABLE =====================
3362
typedef struct SMultiTagUpateVal {
3363
  char*    tagName;
3364
  int32_t  colId;
3365
  int8_t   tagType;
3366
  int8_t   tagFree;
3367
  uint32_t nTagVal;
3368
  uint8_t* pTagVal;
3369
  int8_t   isNull;
3370
  SArray*  pTagArray;
3371
} SMultiTagUpateVal;
3372
typedef struct {
3373
  char*   tbName;
3374
  int8_t  action;
3375
  char*   colName;
3376
  int32_t colId;
3377
  // TSDB_ALTER_TABLE_ADD_COLUMN
3378
  int8_t  type;
3379
  int8_t  flags;
3380
  int32_t bytes;
3381
  // TSDB_ALTER_TABLE_DROP_COLUMN
3382
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3383
  int8_t   colModType;
3384
  int32_t  colModBytes;
3385
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3386
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3387
  int8_t   isNull;
3388
  int8_t   tagType;
3389
  int8_t   tagFree;
3390
  uint32_t nTagVal;
3391
  uint8_t* pTagVal;
3392
  SArray*  pTagArray;
3393
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3394
  int8_t   updateTTL;
3395
  int32_t  newTTL;
3396
  int32_t  newCommentLen;
3397
  char*    newComment;
3398
  int64_t  ctimeMs;    // fill by vnode
3399
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3400
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3401
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3402
} SVAlterTbReq;
3403

3404
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3405
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3406
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3407
void    tfreeMultiTagUpateVal(void* pMultiTag);
3408

3409
typedef struct {
3410
  int32_t        code;
3411
  STableMetaRsp* pMeta;
3412
} SVAlterTbRsp;
3413

3414
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3415
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3416
// ======================
3417

3418
typedef struct {
3419
  SMsgHead head;
3420
  int64_t  uid;
3421
  int32_t  tid;
3422
  int16_t  tversion;
3423
  int16_t  colId;
3424
  int8_t   type;
3425
  int16_t  bytes;
3426
  int32_t  tagValLen;
3427
  int16_t  numOfTags;
3428
  int32_t  schemaLen;
3429
  char     data[];
3430
} SUpdateTagValReq;
3431

3432
typedef struct {
3433
  SMsgHead head;
3434
} SUpdateTagValRsp;
3435

3436
typedef struct {
3437
  SMsgHead head;
3438
} SVShowTablesReq;
3439

3440
typedef struct {
3441
  SMsgHead head;
3442
  int32_t  id;
3443
} SVShowTablesFetchReq;
3444

3445
typedef struct {
3446
  int64_t useconds;
3447
  int8_t  completed;  // all results are returned to client
3448
  int8_t  precision;
3449
  int8_t  compressed;
3450
  int32_t compLen;
3451
  int32_t numOfRows;
3452
  char    data[];
3453
} SVShowTablesFetchRsp;
3454

3455
typedef struct {
3456
  int64_t consumerId;
3457
  int32_t epoch;
3458
  char    cgroup[TSDB_CGROUP_LEN];
3459
} SMqAskEpReq;
3460

3461
typedef struct {
3462
  int32_t key;
3463
  int32_t valueLen;
3464
  void*   value;
3465
} SKv;
3466

3467
typedef struct {
3468
  int64_t tscRid;
3469
  int8_t  connType;
3470
} SClientHbKey;
3471

3472
typedef struct {
3473
  int64_t tid;
3474
  char    status[TSDB_JOB_STATUS_LEN];
3475
} SQuerySubDesc;
3476

3477
typedef struct {
3478
  char     sql[TSDB_SHOW_SQL_LEN];
3479
  uint64_t queryId;
3480
  int64_t  useconds;
3481
  int64_t  stime;  // timestamp precision ms
3482
  int64_t  reqRid;
3483
  bool     stableQuery;
3484
  bool     isSubQuery;
3485
  char     fqdn[TSDB_FQDN_LEN];
3486
  int32_t  subPlanNum;
3487
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3488
} SQueryDesc;
3489

3490
typedef struct {
3491
  uint32_t connId;
3492
  SArray*  queryDesc;  // SArray<SQueryDesc>
3493
} SQueryHbReqBasic;
3494

3495
typedef struct {
3496
  uint32_t connId;
3497
  uint64_t killRid;
3498
  int32_t  totalDnodes;
3499
  int32_t  onlineDnodes;
3500
  int8_t   killConnection;
3501
  int8_t   align[3];
3502
  SEpSet   epSet;
3503
  SArray*  pQnodeList;
3504
} SQueryHbRspBasic;
3505

3506
typedef struct SAppClusterSummary {
3507
  uint64_t numOfInsertsReq;
3508
  uint64_t numOfInsertRows;
3509
  uint64_t insertElapsedTime;
3510
  uint64_t insertBytes;  // submit to tsdb since launched.
3511

3512
  uint64_t fetchBytes;
3513
  uint64_t numOfQueryReq;
3514
  uint64_t queryElapsedTime;
3515
  uint64_t numOfSlowQueries;
3516
  uint64_t totalRequests;
3517
  uint64_t currentRequests;  // the number of SRequestObj
3518
} SAppClusterSummary;
3519

3520
typedef struct {
3521
  int64_t            appId;
3522
  int32_t            pid;
3523
  char               name[TSDB_APP_NAME_LEN];
3524
  int64_t            startTime;
3525
  SAppClusterSummary summary;
3526
} SAppHbReq;
3527

3528
typedef struct {
3529
  SClientHbKey      connKey;
3530
  int64_t           clusterId;
3531
  SAppHbReq         app;
3532
  SQueryHbReqBasic* query;
3533
  SHashObj*         info;  // hash<Skv.key, Skv>
3534
  char              userApp[TSDB_APP_NAME_LEN];
3535
  uint32_t          userIp;
3536
} SClientHbReq;
3537

3538
typedef struct {
3539
  int64_t reqId;
3540
  SArray* reqs;  // SArray<SClientHbReq>
3541
  int64_t ipWhiteList;
3542
} SClientHbBatchReq;
3543

3544
typedef struct {
3545
  SClientHbKey      connKey;
3546
  int32_t           status;
3547
  SQueryHbRspBasic* query;
3548
  SArray*           info;  // Array<Skv>
3549
} SClientHbRsp;
3550

3551
typedef struct {
3552
  int64_t       reqId;
3553
  int64_t       rspId;
3554
  int32_t       svrTimestamp;
3555
  SArray*       rsps;  // SArray<SClientHbRsp>
3556
  SMonitorParas monitorParas;
3557
  int8_t        enableAuditDelete;
3558
} SClientHbBatchRsp;
3559

3560
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
247,587✔
3561

3562
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3563
  void* pIter = taosHashIterate(info, NULL);
535,428✔
3564
  while (pIter != NULL) {
941,400!
3565
    SKv* kv = (SKv*)pIter;
405,934✔
3566
    taosMemoryFreeClear(kv->value);
405,934!
3567
    pIter = taosHashIterate(info, pIter);
405,935✔
3568
  }
3569
}
535,466✔
3570

3571
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
361,628✔
3572
  SQueryDesc* desc = (SQueryDesc*)pDesc;
361,628✔
3573
  if (desc->subDesc) {
361,628✔
3574
    taosArrayDestroy(desc->subDesc);
349,316✔
3575
    desc->subDesc = NULL;
349,318✔
3576
  }
3577
}
361,630✔
3578

3579
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
627,618✔
3580
  SClientHbReq* req = (SClientHbReq*)pReq;
642,478✔
3581
  if (req->query) {
642,478!
3582
    if (req->query->queryDesc) {
612,428!
3583
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
52,222✔
3584
    }
3585
    taosMemoryFreeClear(req->query);
612,428!
3586
  }
3587

3588
  if (req->info) {
642,490!
3589
    tFreeReqKvHash(req->info);
535,428✔
3590
    taosHashCleanup(req->info);
535,466✔
3591
    req->info = NULL;
535,444✔
3592
  }
3593
}
507,996✔
3594

3595
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3596
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3597

3598
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3599
  if (pReq == NULL) return;
56,057!
3600
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
56,057✔
3601
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
56,057✔
3602
  taosMemoryFree(pReq);
56,057!
3603
}
3604

3605
static FORCE_INLINE void tFreeClientKv(void* pKv) {
155,335✔
3606
  SKv* kv = (SKv*)pKv;
155,335✔
3607
  if (kv) {
155,335!
3608
    taosMemoryFreeClear(kv->value);
155,335!
3609
  }
3610
}
155,335✔
3611

3612
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
624,697✔
3613
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
624,697✔
3614
  if (rsp->query) {
624,697✔
3615
    taosArrayDestroy(rsp->query->pQnodeList);
609,661✔
3616
    taosMemoryFreeClear(rsp->query);
609,768!
3617
  }
3618
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
624,871!
3619
}
131,946✔
3620

3621
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3622
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
445,788✔
3623
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
445,788✔
3624
}
445,992✔
3625

3626
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3627
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3628
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3629

3630
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3631
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
783,860!
3632
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
783,860!
3633
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
783,860!
3634
  return 0;
391,930✔
3635
}
3636

3637
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3638
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
730,548!
3639
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
730,562!
3640
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
365,288!
3641
  if (pKv->value == NULL) {
365,286!
3642
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3643
  }
3644
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
365,286!
3645
  return 0;
365,287✔
3646
}
3647

3648
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3649
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,508,634!
3650
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,508,634!
3651
  return 0;
1,254,317✔
3652
}
3653

3654
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3655
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,249,981!
3656
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,250,101!
3657
  return 0;
625,058✔
3658
}
3659

3660
typedef struct {
3661
  int32_t vgId;
3662
  // TODO stas
3663
} SMqReportVgInfo;
3664

3665
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3666
  int32_t tlen = 0;
3667
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3668
  return tlen;
3669
}
3670

3671
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3672
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3673
  return buf;
3674
}
3675

3676
typedef struct {
3677
  int32_t epoch;
3678
  int64_t topicUid;
3679
  char    name[TSDB_TOPIC_FNAME_LEN];
3680
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3681
} SMqTopicInfo;
3682

3683
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3684
  int32_t tlen = 0;
3685
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3686
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3687
  tlen += taosEncodeString(buf, pTopicInfo->name);
3688
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3689
  tlen += taosEncodeFixedI32(buf, sz);
3690
  for (int32_t i = 0; i < sz; i++) {
3691
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3692
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3693
  }
3694
  return tlen;
3695
}
3696

3697
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3698
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3699
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3700
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3701
  int32_t sz;
3702
  buf = taosDecodeFixedI32(buf, &sz);
3703
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3704
    return NULL;
3705
  }
3706
  for (int32_t i = 0; i < sz; i++) {
3707
    SMqReportVgInfo vgInfo;
3708
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3709
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3710
      return NULL;
3711
    }
3712
  }
3713
  return buf;
3714
}
3715

3716
typedef struct {
3717
  int32_t status;  // ask hb endpoint
3718
  int32_t epoch;
3719
  int64_t consumerId;
3720
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3721
} SMqReportReq;
3722

3723
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3724
  int32_t tlen = 0;
3725
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3726
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3727
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3728
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3729
  tlen += taosEncodeFixedI32(buf, sz);
3730
  for (int32_t i = 0; i < sz; i++) {
3731
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3732
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3733
  }
3734
  return tlen;
3735
}
3736

3737
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3738
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3739
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3740
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3741
  int32_t sz;
3742
  buf = taosDecodeFixedI32(buf, &sz);
3743
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3744
    return NULL;
3745
  }
3746
  for (int32_t i = 0; i < sz; i++) {
3747
    SMqTopicInfo topicInfo;
3748
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3749
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3750
      return NULL;
3751
    }
3752
  }
3753
  return buf;
3754
}
3755

3756
typedef struct {
3757
  SMsgHead head;
3758
  int64_t  leftForVer;
3759
  int32_t  vgId;
3760
  int64_t  consumerId;
3761
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3762
} SMqVDeleteReq;
3763

3764
typedef struct {
3765
  int8_t reserved;
3766
} SMqVDeleteRsp;
3767

3768
typedef struct {
3769
  char    name[TSDB_STREAM_FNAME_LEN];
3770
  int8_t  igNotExists;
3771
  int32_t sqlLen;
3772
  char*   sql;
3773
} SMDropStreamReq;
3774

3775
typedef struct {
3776
  int8_t reserved;
3777
} SMDropStreamRsp;
3778

3779
typedef struct {
3780
  SMsgHead head;
3781
  int64_t  resetRelHalt;  // reset related stream task halt status
3782
  int64_t  streamId;
3783
  int32_t  taskId;
3784
} SVDropStreamTaskReq;
3785

3786
typedef struct {
3787
  int8_t reserved;
3788
} SVDropStreamTaskRsp;
3789

3790
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3791
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3792
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3793

3794
typedef struct SVUpdateCheckpointInfoReq {
3795
  SMsgHead head;
3796
  int64_t  streamId;
3797
  int32_t  taskId;
3798
  int64_t  checkpointId;
3799
  int64_t  checkpointVer;
3800
  int64_t  checkpointTs;
3801
  int32_t  transId;
3802
  int64_t  hStreamId;  // add encode/decode
3803
  int64_t  hTaskId;
3804
  int8_t   dropRelHTask;
3805
} SVUpdateCheckpointInfoReq;
3806

3807
typedef struct {
3808
  int64_t leftForVer;
3809
  int32_t vgId;
3810
  int64_t oldConsumerId;
3811
  int64_t newConsumerId;
3812
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3813
  int8_t  subType;
3814
  int8_t  withMeta;
3815
  char*   qmsg;  // SubPlanToString
3816
  int64_t suid;
3817
} SMqRebVgReq;
3818

3819
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3820
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3821

3822
typedef struct {
3823
  char    topic[TSDB_TOPIC_FNAME_LEN];
3824
  int64_t ntbUid;
3825
  SArray* colIdList;  // SArray<int16_t>
3826
} STqCheckInfo;
3827

3828
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3829
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3830
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3831

3832
// tqOffset
3833
enum {
3834
  TMQ_OFFSET__RESET_NONE = -3,
3835
  TMQ_OFFSET__RESET_EARLIEST = -2,
3836
  TMQ_OFFSET__RESET_LATEST = -1,
3837
  TMQ_OFFSET__LOG = 1,
3838
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3839
  TMQ_OFFSET__SNAPSHOT_META = 3,
3840
};
3841

3842
enum {
3843
  WITH_DATA = 0,
3844
  WITH_META = 1,
3845
  ONLY_META = 2,
3846
};
3847

3848
#define TQ_OFFSET_VERSION 1
3849

3850
typedef struct {
3851
  int8_t type;
3852
  union {
3853
    // snapshot
3854
    struct {
3855
      int64_t uid;
3856
      int64_t ts;
3857
      SValue  primaryKey;
3858
    };
3859
    // log
3860
    struct {
3861
      int64_t version;
3862
    };
3863
  };
3864
} STqOffsetVal;
3865

3866
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3867
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
26,052✔
3868
  pOffsetVal->uid = uid;
26,052✔
3869
  pOffsetVal->ts = ts;
26,052✔
3870
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
26,052!
3871
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3872
  }
3873
  pOffsetVal->primaryKey = primaryKey;
26,056✔
3874
}
26,056✔
3875

3876
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3877
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
145✔
3878
  pOffsetVal->uid = uid;
145✔
3879
}
145✔
3880

3881
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3882
  pOffsetVal->type = TMQ_OFFSET__LOG;
524,195✔
3883
  pOffsetVal->version = ver;
524,195✔
3884
}
524,195✔
3885

3886
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3887
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3888
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3889
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3890
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3891
void    tOffsetDestroy(void* pVal);
3892

3893
typedef struct {
3894
  STqOffsetVal val;
3895
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3896
} STqOffset;
3897

3898
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3899
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3900
void    tDeleteSTqOffset(void* val);
3901

3902
typedef struct SMqVgOffset {
3903
  int64_t   consumerId;
3904
  STqOffset offset;
3905
} SMqVgOffset;
3906

3907
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3908
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3909

3910
typedef struct {
3911
  SMsgHead head;
3912
  int64_t  streamId;
3913
  int32_t  taskId;
3914
} SVPauseStreamTaskReq;
3915

3916
typedef struct {
3917
  SMsgHead head;
3918
  int64_t  streamId;
3919
  int32_t  taskId;
3920
  int64_t  chkptId;
3921
} SVResetStreamTaskReq;
3922

3923
typedef struct {
3924
  char   name[TSDB_STREAM_FNAME_LEN];
3925
  int8_t igNotExists;
3926
} SMPauseStreamReq;
3927

3928
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3929
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3930

3931
typedef struct {
3932
  SMsgHead head;
3933
  int32_t  taskId;
3934
  int64_t  streamId;
3935
  int8_t   igUntreated;
3936
} SVResumeStreamTaskReq;
3937

3938
typedef struct {
3939
  int8_t reserved;
3940
} SVResumeStreamTaskRsp;
3941

3942
typedef struct {
3943
  char   name[TSDB_STREAM_FNAME_LEN];
3944
  int8_t igNotExists;
3945
  int8_t igUntreated;
3946
} SMResumeStreamReq;
3947

3948
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3949
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3950

3951
typedef struct {
3952
  char   name[TSDB_STREAM_FNAME_LEN];
3953
  int8_t igNotExists;
3954
  int8_t igUntreated;
3955
} SMResetStreamReq;
3956

3957
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
3958
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
3959

3960
typedef struct {
3961
  char    name[TSDB_TABLE_FNAME_LEN];
3962
  char    stb[TSDB_TABLE_FNAME_LEN];
3963
  int8_t  igExists;
3964
  int8_t  intervalUnit;
3965
  int8_t  slidingUnit;
3966
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
3967
  int32_t dstVgId;   // for stream
3968
  int64_t interval;
3969
  int64_t offset;
3970
  int64_t sliding;
3971
  int64_t maxDelay;
3972
  int64_t watermark;
3973
  int32_t exprLen;        // strlen + 1
3974
  int32_t tagsFilterLen;  // strlen + 1
3975
  int32_t sqlLen;         // strlen + 1
3976
  int32_t astLen;         // strlen + 1
3977
  char*   expr;
3978
  char*   tagsFilter;
3979
  char*   sql;
3980
  char*   ast;
3981
  int64_t deleteMark;
3982
  int64_t lastTs;
3983
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3984
  SArray* pVgroupVerList;
3985
  int8_t  recursiveTsma;
3986
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3987
} SMCreateSmaReq;
3988

3989
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3990
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3991
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3992

3993
typedef struct {
3994
  char   name[TSDB_TABLE_FNAME_LEN];
3995
  int8_t igNotExists;
3996
} SMDropSmaReq;
3997

3998
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3999
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4000

4001
typedef struct {
4002
  char   dbFName[TSDB_DB_FNAME_LEN];
4003
  char   stbName[TSDB_TABLE_NAME_LEN];
4004
  char   colName[TSDB_COL_NAME_LEN];
4005
  char   idxName[TSDB_INDEX_FNAME_LEN];
4006
  int8_t idxType;
4007
} SCreateTagIndexReq;
4008

4009
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4010
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4011

4012
typedef SMDropSmaReq SDropTagIndexReq;
4013

4014
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4015
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4016

4017
typedef struct {
4018
  int8_t         version;       // for compatibility(default 0)
4019
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4020
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4021
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4022
  int32_t        dstVgId;
4023
  char           indexName[TSDB_INDEX_NAME_LEN];
4024
  int32_t        exprLen;
4025
  int32_t        tagsFilterLen;
4026
  int64_t        indexUid;
4027
  tb_uid_t       tableUid;  // super/child/common table uid
4028
  tb_uid_t       dstTbUid;  // for dstVgroup
4029
  int64_t        interval;
4030
  int64_t        offset;  // use unit by precision of DB
4031
  int64_t        sliding;
4032
  char*          dstTbName;  // for dstVgroup
4033
  char*          expr;       // sma expression
4034
  char*          tagsFilter;
4035
  SSchemaWrapper schemaRow;  // for dstVgroup
4036
  SSchemaWrapper schemaTag;  // for dstVgroup
4037
} STSma;                     // Time-range-wise SMA
4038

4039
typedef STSma SVCreateTSmaReq;
4040

4041
typedef struct {
4042
  int8_t  type;  // 0 status report, 1 update data
4043
  int64_t indexUid;
4044
  int64_t skey;  // start TS key of interval/sliding window
4045
} STSmaMsg;
4046

4047
typedef struct {
4048
  int64_t indexUid;
4049
  char    indexName[TSDB_INDEX_NAME_LEN];
4050
} SVDropTSmaReq;
4051

4052
typedef struct {
4053
  int tmp;  // TODO: to avoid compile error
4054
} SVCreateTSmaRsp, SVDropTSmaRsp;
4055

4056
#if 0
4057
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4058
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4059
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4060
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4061
#endif
4062

4063
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4064
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4065
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4066
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4067

4068
typedef struct {
4069
  int32_t number;
4070
  STSma*  tSma;
4071
} STSmaWrapper;
4072

4073
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4074
  if (pSma) {
2!
4075
    taosMemoryFreeClear(pSma->dstTbName);
2!
4076
    taosMemoryFreeClear(pSma->expr);
2!
4077
    taosMemoryFreeClear(pSma->tagsFilter);
2!
4078
  }
4079
}
2✔
4080

4081
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4082
  if (pSW) {
×
4083
    if (pSW->tSma) {
×
4084
      if (deepCopy) {
×
4085
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4086
          tDestroyTSma(pSW->tSma + i);
×
4087
        }
4088
      }
4089
      taosMemoryFreeClear(pSW->tSma);
×
4090
    }
4091
  }
4092
}
×
4093

4094
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4095
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4096
  taosMemoryFreeClear(pSW);
×
4097
  return NULL;
×
4098
}
4099

4100
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4101
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4102

4103
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4104
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4105

4106
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4107
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4108
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4109
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4110
  }
4111
  return 0;
×
4112
}
4113

4114
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4115
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4116
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4117
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4118
  }
4119
  return 0;
×
4120
}
4121

4122
typedef struct {
4123
  int idx;
4124
} SMCreateFullTextReq;
4125

4126
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4127
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4128
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4129

4130
typedef struct {
4131
  char   name[TSDB_TABLE_FNAME_LEN];
4132
  int8_t igNotExists;
4133
} SMDropFullTextReq;
4134

4135
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4136
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4137

4138
typedef struct {
4139
  char indexFName[TSDB_INDEX_FNAME_LEN];
4140
} SUserIndexReq;
4141

4142
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4143
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4144

4145
typedef struct {
4146
  char dbFName[TSDB_DB_FNAME_LEN];
4147
  char tblFName[TSDB_TABLE_FNAME_LEN];
4148
  char colName[TSDB_COL_NAME_LEN];
4149
  char indexType[TSDB_INDEX_TYPE_LEN];
4150
  char indexExts[TSDB_INDEX_EXTS_LEN];
4151
} SUserIndexRsp;
4152

4153
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4154
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4155

4156
typedef struct {
4157
  char tbFName[TSDB_TABLE_FNAME_LEN];
4158
} STableIndexReq;
4159

4160
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4161
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4162

4163
typedef struct {
4164
  int8_t  intervalUnit;
4165
  int8_t  slidingUnit;
4166
  int64_t interval;
4167
  int64_t offset;
4168
  int64_t sliding;
4169
  int64_t dstTbUid;
4170
  int32_t dstVgId;
4171
  SEpSet  epSet;
4172
  char*   expr;
4173
} STableIndexInfo;
4174

4175
typedef struct {
4176
  char     tbName[TSDB_TABLE_NAME_LEN];
4177
  char     dbFName[TSDB_DB_FNAME_LEN];
4178
  uint64_t suid;
4179
  int32_t  version;
4180
  int32_t  indexSize;
4181
  SArray*  pIndex;  // STableIndexInfo
4182
} STableIndexRsp;
4183

4184
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4185
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4186
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4187

4188
void tFreeSTableIndexInfo(void* pInfo);
4189

4190
typedef struct {
4191
  int8_t  mqMsgType;
4192
  int32_t code;
4193
  int32_t epoch;
4194
  int64_t consumerId;
4195
  int64_t walsver;
4196
  int64_t walever;
4197
} SMqRspHead;
4198

4199
typedef struct {
4200
  SMsgHead     head;
4201
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4202
  int8_t       withTbName;
4203
  int8_t       useSnapshot;
4204
  int32_t      epoch;
4205
  uint64_t     reqId;
4206
  int64_t      consumerId;
4207
  int64_t      timeout;
4208
  STqOffsetVal reqOffset;
4209
  int8_t       enableReplay;
4210
  int8_t       sourceExcluded;
4211
  int8_t       rawData;
4212
  int32_t      minPollRows;
4213
  int8_t       enableBatchMeta;
4214
  SHashObj    *uidHash;  // to find if uid is duplicated
4215
} SMqPollReq;
4216

4217
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4218
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4219
void    tDestroySMqPollReq(SMqPollReq* pReq);
4220

4221
typedef struct {
4222
  int32_t vgId;
4223
  int64_t offset;
4224
  SEpSet  epSet;
4225
} SMqSubVgEp;
4226

4227
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4228
  int32_t tlen = 0;
8,594✔
4229
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,594✔
4230
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,594✔
4231
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,594✔
4232
  return tlen;
8,594✔
4233
}
4234

4235
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4236
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,175!
4237
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,175!
4238
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,175✔
4239
  return buf;
4,175✔
4240
}
4241

4242
typedef struct {
4243
  char           topic[TSDB_TOPIC_FNAME_LEN];
4244
  char           db[TSDB_DB_FNAME_LEN];
4245
  SArray*        vgs;  // SArray<SMqSubVgEp>
4246
  SSchemaWrapper schema;
4247
} SMqSubTopicEp;
4248

4249
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4250
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4251
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4252

4253
typedef struct {
4254
  SMqRspHead   head;
4255
  STqOffsetVal rspOffset;
4256
  int16_t      resMsgType;
4257
  int32_t      metaRspLen;
4258
  void*        metaRsp;
4259
} SMqMetaRsp;
4260

4261
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4262
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4263
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4264

4265
#define MQ_DATA_RSP_VERSION 100
4266

4267
typedef struct {
4268
  SMqRspHead   head;
4269
  STqOffsetVal rspOffset;
4270
  STqOffsetVal reqOffset;
4271
  int32_t      blockNum;
4272
  int8_t       withTbName;
4273
  int8_t       withSchema;
4274
  SArray*      blockDataLen;
4275
  SArray*      blockData;
4276
  SArray*      blockTbName;
4277
  SArray*      blockSchema;
4278

4279
  union {
4280
    struct {
4281
      int64_t sleepTime;
4282
    };
4283
    struct {
4284
      int32_t createTableNum;
4285
      SArray* createTableLen;
4286
      SArray* createTableReq;
4287
    };
4288
    struct{
4289
      int32_t len;
4290
      void*   rawData;
4291
    };
4292
  };
4293
  void*   data;  //for free in client, only effected if type is data or metadata. raw data not effected
4294
  bool    blockDataElementFree;   // if true, free blockDataElement in blockData,(true in server, false in client)
4295

4296
} SMqDataRsp;
4297

4298
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4299
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4300
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4301
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4302
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4303

4304
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4305
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4306
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4307

4308
typedef struct SMqBatchMetaRsp {
4309
  SMqRspHead   head;  // not serialize
4310
  STqOffsetVal rspOffset;
4311
  SArray*      batchMetaLen;
4312
  SArray*      batchMetaReq;
4313
  void*        pMetaBuff;    // not serialize
4314
  uint32_t     metaBuffLen;  // not serialize
4315
} SMqBatchMetaRsp;
4316

4317
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4318
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4319
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4320
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4321

4322
typedef struct {
4323
  SMqRspHead head;
4324
  char       cgroup[TSDB_CGROUP_LEN];
4325
  SArray*    topics;  // SArray<SMqSubTopicEp>
4326
} SMqAskEpRsp;
4327

4328
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4329
  int32_t tlen = 0;
17,794✔
4330
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4331
  int32_t sz = taosArrayGetSize(pRsp->topics);
17,794!
4332
  tlen += taosEncodeFixedI32(buf, sz);
17,794✔
4333
  for (int32_t i = 0; i < sz; i++) {
24,642✔
4334
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,848✔
4335
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,848✔
4336
  }
4337
  return tlen;
17,794✔
4338
}
4339

4340
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4341
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4342
  int32_t sz;
4343
  buf = taosDecodeFixedI32(buf, &sz);
8,488✔
4344
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,488✔
4345
  if (pRsp->topics == NULL) {
8,488!
4346
    return NULL;
×
4347
  }
4348
  for (int32_t i = 0; i < sz; i++) {
11,804✔
4349
    SMqSubTopicEp topicEp;
4350
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,316✔
4351
    if (buf == NULL) {
3,316!
4352
      return NULL;
×
4353
    }
4354
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,632!
4355
      return NULL;
×
4356
    }
4357
  }
4358
  return buf;
8,488✔
4359
}
4360

4361
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4362
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
20,549✔
4363
}
20,549✔
4364

4365
typedef struct {
4366
  int32_t      vgId;
4367
  STqOffsetVal offset;
4368
  int64_t      rows;
4369
  int64_t      ever;
4370
} OffsetRows;
4371

4372
typedef struct {
4373
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4374
  SArray* offsetRows;
4375
} TopicOffsetRows;
4376

4377
typedef struct {
4378
  int64_t consumerId;
4379
  int32_t epoch;
4380
  SArray* topics;
4381
  int8_t  pollFlag;
4382
} SMqHbReq;
4383

4384
typedef struct {
4385
  char   topic[TSDB_TOPIC_FNAME_LEN];
4386
  int8_t noPrivilege;
4387
} STopicPrivilege;
4388

4389
typedef struct {
4390
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4391
  int32_t debugFlag;
4392
} SMqHbRsp;
4393

4394
typedef struct {
4395
  SMsgHead head;
4396
  int64_t  consumerId;
4397
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4398
} SMqSeekReq;
4399

4400
#define TD_AUTO_CREATE_TABLE 0x1
4401
typedef struct {
4402
  int64_t       suid;
4403
  int64_t       uid;
4404
  int32_t       sver;
4405
  uint32_t      nData;
4406
  uint8_t*      pData;
4407
  SVCreateTbReq cTbReq;
4408
} SVSubmitBlk;
4409

4410
typedef struct {
4411
  SMsgHead header;
4412
  uint64_t sId;
4413
  uint64_t queryId;
4414
  uint64_t clientId;
4415
  uint64_t taskId;
4416
  uint32_t sqlLen;
4417
  uint32_t phyLen;
4418
  char*    sql;
4419
  char*    msg;
4420
  int8_t   source;
4421
} SVDeleteReq;
4422

4423
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4424
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4425

4426
typedef struct {
4427
  int64_t affectedRows;
4428
} SVDeleteRsp;
4429

4430
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4431
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4432

4433
typedef struct SDeleteRes {
4434
  uint64_t suid;
4435
  SArray*  uidList;
4436
  int64_t  skey;
4437
  int64_t  ekey;
4438
  int64_t  affectedRows;
4439
  char     tableFName[TSDB_TABLE_NAME_LEN];
4440
  char     tsColName[TSDB_COL_NAME_LEN];
4441
  int64_t  ctimeMs;  // fill by vnode
4442
  int8_t   source;
4443
} SDeleteRes;
4444

4445
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4446
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4447

4448
typedef struct {
4449
  // int64_t uid;
4450
  char    tbname[TSDB_TABLE_NAME_LEN];
4451
  int64_t startTs;
4452
  int64_t endTs;
4453
} SSingleDeleteReq;
4454

4455
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4456
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4457

4458
typedef struct {
4459
  int64_t suid;
4460
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4461
  int64_t ctimeMs;     // fill by vnode
4462
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4463
} SBatchDeleteReq;
4464

4465
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4466
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4467
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4468

4469
typedef struct {
4470
  int32_t msgIdx;
4471
  int32_t msgType;
4472
  int32_t msgLen;
4473
  void*   msg;
4474
} SBatchMsg;
4475

4476
typedef struct {
4477
  SMsgHead header;
4478
  SArray*  pMsgs;  // SArray<SBatchMsg>
4479
} SBatchReq;
4480

4481
typedef struct {
4482
  int32_t reqType;
4483
  int32_t msgIdx;
4484
  int32_t msgLen;
4485
  int32_t rspCode;
4486
  void*   msg;
4487
} SBatchRspMsg;
4488

4489
typedef struct {
4490
  SArray* pRsps;  // SArray<SBatchRspMsg>
4491
} SBatchRsp;
4492

4493
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4494
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4495
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
7,241,995✔
4496
  if (NULL == msg) {
7,241,995!
4497
    return;
×
4498
  }
4499
  SBatchMsg* pMsg = (SBatchMsg*)msg;
7,241,995✔
4500
  taosMemoryFree(pMsg->msg);
7,241,995!
4501
}
4502

4503
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4504
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4505

4506
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,550,674✔
4507
  if (NULL == p) {
1,550,674!
4508
    return;
×
4509
  }
4510

4511
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,550,674✔
4512
  taosMemoryFree(pRsp->msg);
1,550,674!
4513
}
4514

4515
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4516
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4517
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4518
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4519
void    tDestroySMqHbReq(SMqHbReq* pReq);
4520

4521
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4522
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4523
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4524

4525
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4526
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4527

4528
#define TD_REQ_FROM_APP               0x0
4529
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4530
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4531
#define SUBMIT_REQ_FROM_FILE          0x4
4532
#define TD_REQ_FROM_TAOX              0x8
4533
#define SUBMIT_REQUEST_VERSION        (1)
4534

4535
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4536

4537
typedef struct {
4538
  int32_t        flags;
4539
  SVCreateTbReq* pCreateTbReq;
4540
  int64_t        suid;
4541
  int64_t        uid;
4542
  int32_t        sver;
4543
  union {
4544
    SArray* aRowP;
4545
    SArray* aCol;
4546
  };
4547
  int64_t ctimeMs;
4548
} SSubmitTbData;
4549

4550
typedef struct {
4551
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4552
  bool    raw;
4553
} SSubmitReq2;
4554

4555
typedef struct {
4556
  SMsgHead header;
4557
  int64_t  version;
4558
  char     data[];  // SSubmitReq2
4559
} SSubmitReq2Msg;
4560

4561
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4562
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4563
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4564
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4565
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4566

4567
typedef struct {
4568
  int32_t affectedRows;
4569
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4570
} SSubmitRsp2;
4571

4572
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4573
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4574
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4575

4576
#define TSDB_MSG_FLG_ENCODE 0x1
4577
#define TSDB_MSG_FLG_DECODE 0x2
4578
#define TSDB_MSG_FLG_CMPT   0x3
4579

4580
typedef struct {
4581
  union {
4582
    struct {
4583
      void*   msgStr;
4584
      int32_t msgLen;
4585
      int64_t ver;
4586
    };
4587
    void* pDataBlock;
4588
  };
4589
} SPackedData;
4590

4591
typedef struct {
4592
  char     fullname[TSDB_VIEW_FNAME_LEN];
4593
  char     name[TSDB_VIEW_NAME_LEN];
4594
  char     dbFName[TSDB_DB_FNAME_LEN];
4595
  char*    querySql;
4596
  char*    sql;
4597
  int8_t   orReplace;
4598
  int8_t   precision;
4599
  int32_t  numOfCols;
4600
  SSchema* pSchema;
4601
} SCMCreateViewReq;
4602

4603
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4604
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4605
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4606

4607
typedef struct {
4608
  char   fullname[TSDB_VIEW_FNAME_LEN];
4609
  char   name[TSDB_VIEW_NAME_LEN];
4610
  char   dbFName[TSDB_DB_FNAME_LEN];
4611
  char*  sql;
4612
  int8_t igNotExists;
4613
} SCMDropViewReq;
4614

4615
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4616
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4617
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4618

4619
typedef struct {
4620
  char fullname[TSDB_VIEW_FNAME_LEN];
4621
} SViewMetaReq;
4622
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4623
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4624

4625
typedef struct {
4626
  char     name[TSDB_VIEW_NAME_LEN];
4627
  char     dbFName[TSDB_DB_FNAME_LEN];
4628
  char*    user;
4629
  uint64_t dbId;
4630
  uint64_t viewId;
4631
  char*    querySql;
4632
  int8_t   precision;
4633
  int8_t   type;
4634
  int32_t  version;
4635
  int32_t  numOfCols;
4636
  SSchema* pSchema;
4637
} SViewMetaRsp;
4638
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4639
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4640
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4641
typedef struct {
4642
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4643
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4644
} STableTSMAInfoReq;
4645

4646
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4647
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4648

4649
typedef struct {
4650
  int32_t  funcId;
4651
  col_id_t colId;
4652
} STableTSMAFuncInfo;
4653

4654
typedef struct {
4655
  char     name[TSDB_TABLE_NAME_LEN];
4656
  uint64_t tsmaId;
4657
  char     targetTb[TSDB_TABLE_NAME_LEN];
4658
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4659
  char     tb[TSDB_TABLE_NAME_LEN];
4660
  char     dbFName[TSDB_DB_FNAME_LEN];
4661
  uint64_t suid;
4662
  uint64_t destTbUid;
4663
  uint64_t dbId;
4664
  int32_t  version;
4665
  int64_t  interval;
4666
  int8_t   unit;
4667
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4668
  SArray*  pTags;      // SArray<SSchema>
4669
  SArray*  pUsedCols;  // SArray<SSchema>
4670
  char*    ast;
4671

4672
  int64_t streamUid;
4673
  int64_t reqTs;
4674
  int64_t rspTs;
4675
  int64_t delayDuration;  // ms
4676
  bool    fillHistoryFinished;
4677
} STableTSMAInfo;
4678

4679
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4680
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4681
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4682
void    tFreeTableTSMAInfo(void* p);
4683
void    tFreeAndClearTableTSMAInfo(void* p);
4684
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4685

4686
#define STSMAHbRsp            STableTSMAInfoRsp
4687
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4688
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4689
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4690

4691
typedef struct SStreamProgressReq {
4692
  int64_t streamId;
4693
  int32_t vgId;
4694
  int32_t fetchIdx;
4695
  int32_t subFetchIdx;
4696
} SStreamProgressReq;
4697

4698
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4699
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4700

4701
typedef struct SStreamProgressRsp {
4702
  int64_t streamId;
4703
  int32_t vgId;
4704
  bool    fillHisFinished;
4705
  int64_t progressDelay;
4706
  int32_t fetchIdx;
4707
  int32_t subFetchIdx;
4708
} SStreamProgressRsp;
4709

4710
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4711
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4712

4713
typedef struct SDropCtbWithTsmaSingleVgReq {
4714
  SVgroupInfo vgInfo;
4715
  SArray*     pTbs;  // SVDropTbReq
4716
} SMDropTbReqsOnSingleVg;
4717

4718
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4719
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4720
void    tFreeSMDropTbReqOnSingleVg(void* p);
4721

4722
typedef struct SDropTbsReq {
4723
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4724
} SMDropTbsReq;
4725

4726
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4727
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4728
void    tFreeSMDropTbsReq(void*);
4729

4730
typedef struct SVFetchTtlExpiredTbsRsp {
4731
  SArray* pExpiredTbs;  // SVDropTbReq
4732
  int32_t vgId;
4733
} SVFetchTtlExpiredTbsRsp;
4734

4735
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4736
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4737

4738
void tFreeFetchTtlExpiredTbsRsp(void* p);
4739

4740
void setDefaultOptionsForField(SFieldWithOptions* field);
4741
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4742

4743
#pragma pack(pop)
4744

4745
#ifdef __cplusplus
4746
}
4747
#endif
4748

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