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

taosdata / TDengine / #3626

28 Feb 2025 03:34AM UTC coverage: 63.764% (+0.1%) from 63.633%
#3626

push

travis-ci

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

merge: from main to 3.0 branch

149233 of 299935 branches covered (49.76%)

Branch coverage included in aggregate %.

53 of 91 new or added lines in 8 files covered. (58.24%)

3267 existing lines in 138 files now uncovered.

233601 of 300457 relevant lines covered (77.75%)

17374158.38 hits per line

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

48.26
/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) {
69,019,436✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
69,019,436✔
74
  int    segIdx = TMSG_SEG_CODE(type);
69,019,436✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
69,019,436!
76
    return type < tMsgRangeDict[segIdx];
69,021,639✔
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,289,733✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
3,263,078✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
6,552,811!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
33,840,841✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
33,840,841✔
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
  QUERY_NODE_ASSIGN_LEADER_STMT,
363

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

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

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

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

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

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

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

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

528
#pragma pack(push, 1)
529

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

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

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

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

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

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

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

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

601
//
602

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

734
  return pDstWrapper;
735
}
736

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

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

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

770
  taosMemoryFreeClear(pWrapper->pColCmpr);
771
  taosMemoryFreeClear(pWrapper);
772
}
773
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
774
  if (pSchemaWrapper->pSchema == NULL) return NULL;
11,416,833!
775

776
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
11,416,833!
777
  if (pSW == NULL) {
11,416,065!
UNCOV
778
    return NULL;
×
779
  }
780
  pSW->nCols = pSchemaWrapper->nCols;
11,416,065✔
781
  pSW->version = pSchemaWrapper->version;
11,416,065✔
782
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
11,416,065!
783
  if (pSW->pSchema == NULL) {
11,412,335!
784
    taosMemoryFree(pSW);
×
UNCOV
785
    return NULL;
×
786
  }
787

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

792
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
582,969✔
793
  if (pSchemaWrapper) {
27,391,145!
794
    taosMemoryFree(pSchemaWrapper->pSchema);
10,491,929!
795
    taosMemoryFree(pSchemaWrapper);
10,492,170!
796
  }
797
}
27,390,715✔
798

799
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,385,417✔
800
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,385,417!
801
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,385,709!
802
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,386,130!
803
  }
804
}
1,385,427✔
805

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

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

825
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
826
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
354,040,403!
827
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
373,450,042!
828
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
373,450,042!
829
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
373,450,042!
830
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
373,450,042!
831
  return 0;
186,725,021✔
832
}
833

834
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
835
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
659,921,907!
836
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,287,317,735!
837
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,273,745,187!
838
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,295,999,876!
839
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
652,336,538!
840
  return 0;
715,028,832✔
841
}
842

843
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
844
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
207,734,890!
845
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
207,734,890!
846
  return 0;
103,867,445✔
847
}
848

849
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
850
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
4,194,175!
851
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
4,194,180!
852
  return 0;
2,097,091✔
853
}
854

855
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
856
  int32_t tlen = 0;
9,616✔
857
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
9,616✔
858
  tlen += taosEncodeVariantI32(buf, pSW->version);
9,616✔
859
  for (int32_t i = 0; i < pSW->nCols; i++) {
69,186✔
860
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
119,140!
861
  }
862
  return tlen;
9,616✔
863
}
864

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

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

883
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
884
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,498,604!
885
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,498,604!
886
  for (int32_t i = 0; i < pSW->nCols; i++) {
20,158,941✔
887
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
38,819,278!
888
  }
889
  return 0;
749,302✔
890
}
891

892
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
893
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,239,188!
894
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,239,118!
895

896
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
619,504!
897
  if (pSW->pSchema == NULL) {
619,596!
UNCOV
898
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
899
  }
900
  for (int32_t i = 0; i < pSW->nCols; i++) {
9,386,005!
901
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
17,534,036!
902
  }
903

904
  return 0;
618,378✔
905
}
906

907
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
908
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
82,972,504!
909
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
79,136,168!
910

911
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
39,542,583!
912
  if (pSW->pSchema == NULL) {
39,872,612!
UNCOV
913
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
914
  }
915
  for (int32_t i = 0; i < pSW->nCols; i++) {
743,449,020✔
916
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,403,925,669!
917
  }
918

919
  return 0;
43,099,759✔
920
}
921

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1307
typedef STableCfg STableCfgRsp;
1308

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1547
typedef SDbCfgRsp SDbCfgInfo;
1548

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2272
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2273

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2583
typedef struct {
2584
  char*   arbToken;
2585
  int64_t arbTerm;
2586
  char*   memberToken;
2587
  int8_t  force;
2588
} SVArbSetAssignedLeaderReq;
2589

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

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

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

2604
typedef struct {
2605
  int32_t dnodeId;
2606
  char*   token;
2607
} SMArbUpdateGroupMember;
2608

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

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

2627
typedef struct {
2628
  SArray* updateArray;  // SMArbUpdateGroup
2629
} SMArbUpdateGroupBatchReq;
2630

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

2635
typedef struct {
2636
  char queryStrId[TSDB_QUERY_ID_LEN];
2637
} SKillQueryReq;
2638

2639
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2640
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2641

2642
typedef struct {
2643
  uint32_t connId;
2644
} SKillConnReq;
2645

2646
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2647
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2648

2649
typedef struct {
2650
  int32_t transId;
2651
} SKillTransReq;
2652

2653
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2654
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2655

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

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

2666
typedef struct {
2667
  int32_t useless;  // useless
2668
  int32_t sqlLen;
2669
  char*   sql;
2670
} SAssignLeaderReq;
2671

2672
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2673
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2674
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
2675
typedef struct {
2676
  int32_t vgId1;
2677
  int32_t vgId2;
2678
} SMergeVgroupReq;
2679

2680
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2681
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2682

2683
typedef struct {
2684
  int32_t vgId;
2685
  int32_t dnodeId1;
2686
  int32_t dnodeId2;
2687
  int32_t dnodeId3;
2688
  int32_t sqlLen;
2689
  char*   sql;
2690
} SRedistributeVgroupReq;
2691

2692
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2693
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2694
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2695

2696
typedef struct {
2697
  int32_t reserved;
2698
  int32_t vgId;
2699
  int32_t sqlLen;
2700
  char*   sql;
2701
  char    db[TSDB_DB_FNAME_LEN];
2702
} SBalanceVgroupLeaderReq;
2703

2704
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2705
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2706
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2707

2708
typedef struct {
2709
  int32_t vgId;
2710
} SForceBecomeFollowerReq;
2711

2712
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2713
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2714

2715
typedef struct {
2716
  int32_t vgId;
2717
} SSplitVgroupReq;
2718

2719
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2720
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2721

2722
typedef struct {
2723
  char user[TSDB_USER_LEN];
2724
  char spi;
2725
  char encrypt;
2726
  char secret[TSDB_PASSWORD_LEN];
2727
  char ckey[TSDB_PASSWORD_LEN];
2728
} SAuthReq, SAuthRsp;
2729

2730
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2731
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2732

2733
typedef struct {
2734
  int32_t statusCode;
2735
  char    details[1024];
2736
} SServerStatusRsp;
2737

2738
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2739
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2740

2741
/**
2742
 * The layout of the query message payload is as following:
2743
 * +--------------------+---------------------------------+
2744
 * |Sql statement       | Physical plan                   |
2745
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2746
 * +--------------------+---------------------------------+
2747
 */
2748
typedef struct SSubQueryMsg {
2749
  SMsgHead header;
2750
  uint64_t sId;
2751
  uint64_t queryId;
2752
  uint64_t clientId;
2753
  uint64_t taskId;
2754
  int64_t  refId;
2755
  int32_t  execId;
2756
  int32_t  msgMask;
2757
  int8_t   taskType;
2758
  int8_t   explain;
2759
  int8_t   needFetch;
2760
  int8_t   compress;
2761
  uint32_t sqlLen;
2762
  char*    sql;
2763
  uint32_t msgLen;
2764
  char*    msg;
2765
} SSubQueryMsg;
2766

2767
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2768
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2769
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2770

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

2778
typedef struct {
2779
  SMsgHead header;
2780
  uint64_t sId;
2781
  uint64_t queryId;
2782
  uint64_t clientId;
2783
  uint64_t taskId;
2784
  int32_t  execId;
2785
} SQueryContinueReq;
2786

2787
typedef struct {
2788
  SMsgHead header;
2789
  uint64_t sId;
2790
  uint64_t queryId;
2791
  uint64_t taskId;
2792
} SResReadyReq;
2793

2794
typedef struct {
2795
  int32_t code;
2796
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2797
  int32_t sversion;
2798
  int32_t tversion;
2799
} SResReadyRsp;
2800

2801
typedef struct SOperatorParam {
2802
  int32_t opType;
2803
  int32_t downstreamIdx;
2804
  void*   value;
2805
  SArray* pChildren;  // SArray<SOperatorParam*>
2806
} SOperatorParam;
2807

2808
typedef struct STableScanOperatorParam {
2809
  bool    tableSeq;
2810
  SArray* pUidList;
2811
} STableScanOperatorParam;
2812

2813
typedef struct {
2814
  SMsgHead        header;
2815
  uint64_t        sId;
2816
  uint64_t        queryId;
2817
  uint64_t        clientId;
2818
  uint64_t        taskId;
2819
  int32_t         execId;
2820
  SOperatorParam* pOpParam;
2821
} SResFetchReq;
2822

2823
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2824
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2825

2826
typedef struct {
2827
  SMsgHead header;
2828
  uint64_t clientId;
2829
} SSchTasksStatusReq;
2830

2831
typedef struct {
2832
  uint64_t queryId;
2833
  uint64_t clientId;
2834
  uint64_t taskId;
2835
  int64_t  refId;
2836
  int32_t  execId;
2837
  int8_t   status;
2838
} STaskStatus;
2839

2840
typedef struct {
2841
  int64_t refId;
2842
  SArray* taskStatus;  // SArray<STaskStatus>
2843
} SSchedulerStatusRsp;
2844

2845
typedef struct {
2846
  uint64_t queryId;
2847
  uint64_t taskId;
2848
  int8_t   action;
2849
} STaskAction;
2850

2851
typedef struct SQueryNodeEpId {
2852
  int32_t nodeId;  // vgId or qnodeId
2853
  SEp     ep;
2854
} SQueryNodeEpId;
2855

2856
typedef struct {
2857
  SMsgHead       header;
2858
  uint64_t       clientId;
2859
  SQueryNodeEpId epId;
2860
  SArray*        taskAction;  // SArray<STaskAction>
2861
} SSchedulerHbReq;
2862

2863
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2864
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2865
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2866

2867
typedef struct {
2868
  SQueryNodeEpId epId;
2869
  SArray*        taskStatus;  // SArray<STaskStatus>
2870
} SSchedulerHbRsp;
2871

2872
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2873
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2874
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2875

2876
typedef struct {
2877
  SMsgHead header;
2878
  uint64_t sId;
2879
  uint64_t queryId;
2880
  uint64_t clientId;
2881
  uint64_t taskId;
2882
  int64_t  refId;
2883
  int32_t  execId;
2884
} STaskCancelReq;
2885

2886
typedef struct {
2887
  int32_t code;
2888
} STaskCancelRsp;
2889

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

2900
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2901
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2902

2903
typedef enum {
2904
  TASK_NOTIFY_FINISHED = 1,
2905
} ETaskNotifyType;
2906

2907
typedef struct {
2908
  SMsgHead        header;
2909
  uint64_t        sId;
2910
  uint64_t        queryId;
2911
  uint64_t        clientId;
2912
  uint64_t        taskId;
2913
  int64_t         refId;
2914
  int32_t         execId;
2915
  ETaskNotifyType type;
2916
} STaskNotifyReq;
2917

2918
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2919
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2920

2921
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2922
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2923

2924
typedef struct {
2925
  int32_t code;
2926
} STaskDropRsp;
2927

2928
#define STREAM_TRIGGER_AT_ONCE            1
2929
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2930
#define STREAM_TRIGGER_MAX_DELAY          3
2931
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2932

2933
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2934
#define STREAM_FILL_HISTORY_ON        1
2935
#define STREAM_FILL_HISTORY_OFF       0
2936
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2937
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2938
#define STREAM_CREATE_STABLE_TRUE     1
2939
#define STREAM_CREATE_STABLE_FALSE    0
2940

2941
typedef struct SColLocation {
2942
  int16_t  slotId;
2943
  col_id_t colId;
2944
  int8_t   type;
2945
} SColLocation;
2946

2947
typedef struct SVgroupVer {
2948
  int32_t vgId;
2949
  int64_t ver;
2950
} SVgroupVer;
2951

2952
typedef struct {
2953
  char    name[TSDB_STREAM_FNAME_LEN];
2954
  char    sourceDB[TSDB_DB_FNAME_LEN];
2955
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
2956
  char*   sql;
2957
  char*   ast;
2958
  int8_t  igExists;
2959
  int8_t  triggerType;
2960
  int8_t  igExpired;
2961
  int8_t  fillHistory;  // process data inserted before creating stream
2962
  int64_t maxDelay;
2963
  int64_t watermark;
2964
  int32_t numOfTags;
2965
  SArray* pTags;  // array of SField
2966
  // 3.0.20
2967
  int64_t checkpointFreq;  // ms
2968
  // 3.0.2.3
2969
  int8_t   createStb;
2970
  uint64_t targetStbUid;
2971
  SArray*  fillNullCols;  // array of SColLocation
2972
  int64_t  deleteMark;
2973
  int8_t   igUpdate;
2974
  int64_t  lastTs;
2975
  SArray*  pVgroupVerList;
2976
  // 3.3.0.0
2977
  SArray* pCols;  // array of SField
2978
  int64_t smaId;
2979
  // 3.3.6.0
2980
  SArray* pNotifyAddrUrls;
2981
  int32_t notifyEventTypes;
2982
  int32_t notifyErrorHandle;
2983
  int8_t  notifyHistory;
2984
} SCMCreateStreamReq;
2985

2986
typedef struct STaskNotifyEventStat {
2987
  int64_t notifyEventAddTimes;     // call times of add function
2988
  int64_t notifyEventAddElems;     // elements added by add function
2989
  double  notifyEventAddCostSec;   // time cost of add function
2990
  int64_t notifyEventPushTimes;    // call times of push function
2991
  int64_t notifyEventPushElems;    // elements pushed by push function
2992
  double  notifyEventPushCostSec;  // time cost of push function
2993
  int64_t notifyEventPackTimes;    // call times of pack function
2994
  int64_t notifyEventPackElems;    // elements packed by pack function
2995
  double  notifyEventPackCostSec;  // time cost of pack function
2996
  int64_t notifyEventSendTimes;    // call times of send function
2997
  int64_t notifyEventSendElems;    // elements sent by send function
2998
  double  notifyEventSendCostSec;  // time cost of send function
2999
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3000
} STaskNotifyEventStat;
3001

3002
typedef struct {
3003
  int64_t streamId;
3004
} SCMCreateStreamRsp;
3005

3006
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3007
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3008
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3009

3010
enum {
3011
  TOPIC_SUB_TYPE__DB = 1,
3012
  TOPIC_SUB_TYPE__TABLE,
3013
  TOPIC_SUB_TYPE__COLUMN,
3014
};
3015

3016
#define DEFAULT_MAX_POLL_INTERVAL  300000
3017
#define DEFAULT_SESSION_TIMEOUT    12000
3018
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3019
#define DEFAULT_MIN_POLL_ROWS      4096
3020

3021
typedef struct {
3022
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3023
  int8_t igExists;
3024
  int8_t subType;
3025
  int8_t withMeta;
3026
  char*  sql;
3027
  char   subDbName[TSDB_DB_FNAME_LEN];
3028
  char*  ast;
3029
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3030
} SCMCreateTopicReq;
3031

3032
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3033
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3034
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3035

3036
typedef struct {
3037
  int64_t consumerId;
3038
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3039

3040
typedef struct {
3041
  int64_t consumerId;
3042
  char    cgroup[TSDB_CGROUP_LEN];
3043
  char    clientId[TSDB_CLIENT_ID_LEN];
3044
  char    user[TSDB_USER_LEN];
3045
  char    fqdn[TSDB_FQDN_LEN];
3046
  SArray* topicNames;  // SArray<char**>
3047

3048
  int8_t  withTbName;
3049
  int8_t  autoCommit;
3050
  int32_t autoCommitInterval;
3051
  int8_t  resetOffsetCfg;
3052
  int8_t  enableReplay;
3053
  int8_t  enableBatchMeta;
3054
  int32_t sessionTimeoutMs;
3055
  int32_t maxPollIntervalMs;
3056
} SCMSubscribeReq;
3057

3058
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3059
  int32_t tlen = 0;
2,386✔
3060
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,386!
3061
  tlen += taosEncodeString(buf, pReq->cgroup);
2,386✔
3062
  tlen += taosEncodeString(buf, pReq->clientId);
2,386✔
3063

3064
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,386!
3065
  tlen += taosEncodeFixedI32(buf, topicNum);
2,386✔
3066

3067
  for (int32_t i = 0; i < topicNum; i++) {
3,362✔
3068
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
1,952✔
3069
  }
3070

3071
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,386!
3072
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,386!
3073
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,386!
3074
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,386!
3075
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,386!
3076
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,386!
3077
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,386!
3078
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,386!
3079
  tlen += taosEncodeString(buf, pReq->user);
2,386✔
3080
  tlen += taosEncodeString(buf, pReq->fqdn);
2,386✔
3081

3082
  return tlen;
2,386✔
3083
}
3084

3085
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3086
  void* start = buf;
1,290✔
3087
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,290!
3088
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,290✔
3089
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,290✔
3090

3091
  int32_t topicNum = 0;
1,290!
3092
  buf = taosDecodeFixedI32(buf, &topicNum);
1,290✔
3093

3094
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,290✔
3095
  if (pReq->topicNames == NULL) {
1,290!
UNCOV
3096
    return terrno;
×
3097
  }
3098
  for (int32_t i = 0; i < topicNum; i++) {
1,880✔
3099
    char* name = NULL;
590✔
3100
    buf = taosDecodeString(buf, &name);
590✔
3101
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,180!
UNCOV
3102
      return terrno;
×
3103
    }
3104
  }
3105

3106
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,290✔
3107
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,290✔
3108
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,290!
3109
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,290✔
3110
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,290✔
3111
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,290✔
3112
  if ((char*)buf - (char*)start < len) {
1,290!
3113
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,290!
3114
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,290!
3115
    buf = taosDecodeStringTo(buf, pReq->user);
1,290✔
3116
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,580✔
3117
  } else {
UNCOV
3118
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
UNCOV
3119
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3120
  }
3121

3122
  return 0;
1,290✔
3123
}
3124

3125
typedef struct {
3126
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3127
  SArray* removedConsumers;  // SArray<int64_t>
3128
  SArray* newConsumers;      // SArray<int64_t>
3129
} SMqRebInfo;
3130

3131
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3132
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,320!
3133
  if (pRebInfo == NULL) {
1,320!
UNCOV
3134
    return NULL;
×
3135
  }
3136
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,320✔
3137
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,320✔
3138
  if (pRebInfo->removedConsumers == NULL) {
1,320!
3139
    goto _err;
×
3140
  }
3141
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,320✔
3142
  if (pRebInfo->newConsumers == NULL) {
1,320!
UNCOV
3143
    goto _err;
×
3144
  }
3145
  return pRebInfo;
1,320✔
UNCOV
3146
_err:
×
UNCOV
3147
  taosArrayDestroy(pRebInfo->removedConsumers);
×
UNCOV
3148
  taosArrayDestroy(pRebInfo->newConsumers);
×
UNCOV
3149
  taosMemoryFreeClear(pRebInfo);
×
UNCOV
3150
  return NULL;
×
3151
}
3152

3153
typedef struct {
3154
  int64_t streamId;
3155
  int64_t checkpointId;
3156
  char    streamName[TSDB_STREAM_FNAME_LEN];
3157
} SMStreamDoCheckpointMsg;
3158

3159
typedef struct {
3160
  int64_t status;
3161
} SMVSubscribeRsp;
3162

3163
typedef struct {
3164
  char    name[TSDB_TOPIC_FNAME_LEN];
3165
  int8_t  igNotExists;
3166
  int32_t sqlLen;
3167
  char*   sql;
3168
} SMDropTopicReq;
3169

3170
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3171
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3172
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3173

3174
typedef struct {
3175
  char   topic[TSDB_TOPIC_FNAME_LEN];
3176
  char   cgroup[TSDB_CGROUP_LEN];
3177
  int8_t igNotExists;
3178
} SMDropCgroupReq;
3179

3180
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3181
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3182

3183
typedef struct {
3184
  int8_t reserved;
3185
} SMDropCgroupRsp;
3186

3187
typedef struct {
3188
  char    name[TSDB_TABLE_FNAME_LEN];
3189
  int8_t  alterType;
3190
  SSchema schema;
3191
} SAlterTopicReq;
3192

3193
typedef struct {
3194
  SMsgHead head;
3195
  char     name[TSDB_TABLE_FNAME_LEN];
3196
  int64_t  tuid;
3197
  int32_t  sverson;
3198
  int32_t  execLen;
3199
  char*    executor;
3200
  int32_t  sqlLen;
3201
  char*    sql;
3202
} SDCreateTopicReq;
3203

3204
typedef struct {
3205
  SMsgHead head;
3206
  char     name[TSDB_TABLE_FNAME_LEN];
3207
  int64_t  tuid;
3208
} SDDropTopicReq;
3209

3210
typedef struct {
3211
  int64_t maxdelay[2];
3212
  int64_t watermark[2];
3213
  int64_t deleteMark[2];
3214
  int32_t qmsgLen[2];
3215
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3216
} SRSmaParam;
3217

3218
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3219
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3220

3221
// TDMT_VND_CREATE_STB ==============
3222
typedef struct SVCreateStbReq {
3223
  char*           name;
3224
  tb_uid_t        suid;
3225
  int8_t          rollup;
3226
  SSchemaWrapper  schemaRow;
3227
  SSchemaWrapper  schemaTag;
3228
  SRSmaParam      rsmaParam;
3229
  int32_t         alterOriDataLen;
3230
  void*           alterOriData;
3231
  int8_t          source;
3232
  int8_t          colCmpred;
3233
  SColCmprWrapper colCmpr;
3234
} SVCreateStbReq;
3235

3236
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3237
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3238

3239
// TDMT_VND_DROP_STB ==============
3240
typedef struct SVDropStbReq {
3241
  char*    name;
3242
  tb_uid_t suid;
3243
} SVDropStbReq;
3244

3245
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3246
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3247

3248
// TDMT_VND_CREATE_TABLE ==============
3249
#define TD_CREATE_IF_NOT_EXISTS 0x1
3250
typedef struct SVCreateTbReq {
3251
  int32_t  flags;
3252
  char*    name;
3253
  tb_uid_t uid;
3254
  int64_t  btime;
3255
  int32_t  ttl;
3256
  int32_t  commentLen;
3257
  char*    comment;
3258
  int8_t   type;
3259
  union {
3260
    struct {
3261
      char*    stbName;  // super table name
3262
      uint8_t  tagNum;
3263
      tb_uid_t suid;
3264
      SArray*  tagName;
3265
      uint8_t* pTag;
3266
    } ctb;
3267
    struct {
3268
      SSchemaWrapper schemaRow;
3269
    } ntb;
3270
  };
3271
  int32_t         sqlLen;
3272
  char*           sql;
3273
  SColCmprWrapper colCmpr;
3274
} SVCreateTbReq;
3275

3276
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3277
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3278
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3279

3280
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,776✔
3281
  if (NULL == req) {
19,637,544!
3282
    return;
19,344,241✔
3283
  }
3284

3285
  taosMemoryFreeClear(req->sql);
293,303!
3286
  taosMemoryFreeClear(req->name);
293,303!
3287
  taosMemoryFreeClear(req->comment);
293,332!
3288
  if (req->type == TSDB_CHILD_TABLE) {
293,332!
3289
    taosMemoryFreeClear(req->ctb.pTag);
277,396!
3290
    taosMemoryFreeClear(req->ctb.stbName);
277,414!
3291
    taosArrayDestroy(req->ctb.tagName);
277,421✔
3292
    req->ctb.tagName = NULL;
277,421✔
3293
  } else if (req->type == TSDB_NORMAL_TABLE) {
15,936!
3294
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
15,910!
3295
  }
3296
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
293,357!
3297
}
3298

3299
typedef struct {
3300
  int32_t nReqs;
3301
  union {
3302
    SVCreateTbReq* pReqs;
3303
    SArray*        pArray;
3304
  };
3305
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3306
} SVCreateTbBatchReq;
3307

3308
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3309
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3310
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3311

3312
typedef struct {
3313
  int32_t        code;
3314
  STableMetaRsp* pMeta;
3315
} SVCreateTbRsp, SVUpdateTbRsp;
3316

3317
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3318
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3319
void tFreeSVCreateTbRsp(void* param);
3320

3321
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3322
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3323

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

3332
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3333
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3334

3335
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3336
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3337

3338
// TDMT_VND_DROP_TABLE =================
3339
typedef struct {
3340
  char*    name;
3341
  uint64_t suid;  // for tmq in wal format
3342
  int64_t  uid;
3343
  int8_t   igNotExists;
3344
} SVDropTbReq;
3345

3346
typedef struct {
3347
  int32_t code;
3348
} SVDropTbRsp;
3349

3350
typedef struct {
3351
  int32_t nReqs;
3352
  union {
3353
    SVDropTbReq* pReqs;
3354
    SArray*      pArray;
3355
  };
3356
} SVDropTbBatchReq;
3357

3358
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3359
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3360

3361
typedef struct {
3362
  int32_t nRsps;
3363
  union {
3364
    SVDropTbRsp* pRsps;
3365
    SArray*      pArray;
3366
  };
3367
} SVDropTbBatchRsp;
3368

3369
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3370
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3371

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

3415
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3416
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3417
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3418
void    tfreeMultiTagUpateVal(void* pMultiTag);
3419

3420
typedef struct {
3421
  int32_t        code;
3422
  STableMetaRsp* pMeta;
3423
} SVAlterTbRsp;
3424

3425
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3426
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3427
// ======================
3428

3429
typedef struct {
3430
  SMsgHead head;
3431
  int64_t  uid;
3432
  int32_t  tid;
3433
  int16_t  tversion;
3434
  int16_t  colId;
3435
  int8_t   type;
3436
  int16_t  bytes;
3437
  int32_t  tagValLen;
3438
  int16_t  numOfTags;
3439
  int32_t  schemaLen;
3440
  char     data[];
3441
} SUpdateTagValReq;
3442

3443
typedef struct {
3444
  SMsgHead head;
3445
} SUpdateTagValRsp;
3446

3447
typedef struct {
3448
  SMsgHead head;
3449
} SVShowTablesReq;
3450

3451
typedef struct {
3452
  SMsgHead head;
3453
  int32_t  id;
3454
} SVShowTablesFetchReq;
3455

3456
typedef struct {
3457
  int64_t useconds;
3458
  int8_t  completed;  // all results are returned to client
3459
  int8_t  precision;
3460
  int8_t  compressed;
3461
  int32_t compLen;
3462
  int32_t numOfRows;
3463
  char    data[];
3464
} SVShowTablesFetchRsp;
3465

3466
typedef struct {
3467
  int64_t consumerId;
3468
  int32_t epoch;
3469
  char    cgroup[TSDB_CGROUP_LEN];
3470
} SMqAskEpReq;
3471

3472
typedef struct {
3473
  int32_t key;
3474
  int32_t valueLen;
3475
  void*   value;
3476
} SKv;
3477

3478
typedef struct {
3479
  int64_t tscRid;
3480
  int8_t  connType;
3481
} SClientHbKey;
3482

3483
typedef struct {
3484
  int64_t tid;
3485
  char    status[TSDB_JOB_STATUS_LEN];
3486
} SQuerySubDesc;
3487

3488
typedef struct {
3489
  char     sql[TSDB_SHOW_SQL_LEN];
3490
  uint64_t queryId;
3491
  int64_t  useconds;
3492
  int64_t  stime;  // timestamp precision ms
3493
  int64_t  reqRid;
3494
  bool     stableQuery;
3495
  bool     isSubQuery;
3496
  char     fqdn[TSDB_FQDN_LEN];
3497
  int32_t  subPlanNum;
3498
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3499
} SQueryDesc;
3500

3501
typedef struct {
3502
  uint32_t connId;
3503
  SArray*  queryDesc;  // SArray<SQueryDesc>
3504
} SQueryHbReqBasic;
3505

3506
typedef struct {
3507
  uint32_t connId;
3508
  uint64_t killRid;
3509
  int32_t  totalDnodes;
3510
  int32_t  onlineDnodes;
3511
  int8_t   killConnection;
3512
  int8_t   align[3];
3513
  SEpSet   epSet;
3514
  SArray*  pQnodeList;
3515
} SQueryHbRspBasic;
3516

3517
typedef struct SAppClusterSummary {
3518
  uint64_t numOfInsertsReq;
3519
  uint64_t numOfInsertRows;
3520
  uint64_t insertElapsedTime;
3521
  uint64_t insertBytes;  // submit to tsdb since launched.
3522

3523
  uint64_t fetchBytes;
3524
  uint64_t numOfQueryReq;
3525
  uint64_t queryElapsedTime;
3526
  uint64_t numOfSlowQueries;
3527
  uint64_t totalRequests;
3528
  uint64_t currentRequests;  // the number of SRequestObj
3529
} SAppClusterSummary;
3530

3531
typedef struct {
3532
  int64_t            appId;
3533
  int32_t            pid;
3534
  char               name[TSDB_APP_NAME_LEN];
3535
  int64_t            startTime;
3536
  SAppClusterSummary summary;
3537
} SAppHbReq;
3538

3539
typedef struct {
3540
  SClientHbKey      connKey;
3541
  int64_t           clusterId;
3542
  SAppHbReq         app;
3543
  SQueryHbReqBasic* query;
3544
  SHashObj*         info;  // hash<Skv.key, Skv>
3545
  char              userApp[TSDB_APP_NAME_LEN];
3546
  uint32_t          userIp;
3547
} SClientHbReq;
3548

3549
typedef struct {
3550
  int64_t reqId;
3551
  SArray* reqs;  // SArray<SClientHbReq>
3552
  int64_t ipWhiteList;
3553
} SClientHbBatchReq;
3554

3555
typedef struct {
3556
  SClientHbKey      connKey;
3557
  int32_t           status;
3558
  SQueryHbRspBasic* query;
3559
  SArray*           info;  // Array<Skv>
3560
} SClientHbRsp;
3561

3562
typedef struct {
3563
  int64_t       reqId;
3564
  int64_t       rspId;
3565
  int32_t       svrTimestamp;
3566
  SArray*       rsps;  // SArray<SClientHbRsp>
3567
  SMonitorParas monitorParas;
3568
  int8_t        enableAuditDelete;
3569
} SClientHbBatchRsp;
3570

3571
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
244,127✔
3572

3573
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3574
  void* pIter = taosHashIterate(info, NULL);
527,524✔
3575
  while (pIter != NULL) {
910,111!
3576
    SKv* kv = (SKv*)pIter;
382,548✔
3577
    taosMemoryFreeClear(kv->value);
382,548!
3578
    pIter = taosHashIterate(info, pIter);
382,548✔
3579
  }
3580
}
527,563✔
3581

3582
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
340,928✔
3583
  SQueryDesc* desc = (SQueryDesc*)pDesc;
340,928✔
3584
  if (desc->subDesc) {
340,928✔
3585
    taosArrayDestroy(desc->subDesc);
334,017✔
3586
    desc->subDesc = NULL;
334,015✔
3587
  }
3588
}
340,926✔
3589

3590
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
626,706✔
3591
  SClientHbReq* req = (SClientHbReq*)pReq;
643,033✔
3592
  if (req->query) {
643,033!
3593
    if (req->query->queryDesc) {
616,944!
3594
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
50,260✔
3595
    }
3596
    taosMemoryFreeClear(req->query);
616,944!
3597
  }
3598

3599
  if (req->info) {
643,019!
3600
    tFreeReqKvHash(req->info);
527,524✔
3601
    taosHashCleanup(req->info);
527,563✔
3602
    req->info = NULL;
527,553✔
3603
  }
3604
}
508,914✔
3605

3606
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3607
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3608

3609
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3610
  if (pReq == NULL) return;
43,368!
3611
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
43,368✔
3612
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
43,368✔
3613
  taosMemoryFree(pReq);
43,368!
3614
}
3615

3616
static FORCE_INLINE void tFreeClientKv(void* pKv) {
146,152✔
3617
  SKv* kv = (SKv*)pKv;
146,152✔
3618
  if (kv) {
146,152!
3619
    taosMemoryFreeClear(kv->value);
146,153!
3620
  }
3621
}
146,150✔
3622

3623
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
623,869✔
3624
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
623,869✔
3625
  if (rsp->query) {
623,869✔
3626
    taosArrayDestroy(rsp->query->pQnodeList);
614,223✔
3627
    taosMemoryFreeClear(rsp->query);
614,321!
3628
  }
3629
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
623,995!
3630
}
131,566✔
3631

3632
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3633
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
418,877✔
3634
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
418,877✔
3635
}
418,998✔
3636

3637
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3638
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3639
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3640

3641
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3642
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
718,244!
3643
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
718,244!
3644
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
718,244!
3645
  return 0;
359,122✔
3646
}
3647

3648
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3649
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
698,180!
3650
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
698,188!
3651
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
349,100!
3652
  if (pKv->value == NULL) {
349,115!
UNCOV
3653
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3654
  }
3655
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
349,115!
3656
  return 0;
349,104✔
3657
}
3658

3659
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3660
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,505,228!
3661
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,505,228!
3662
  return 0;
1,252,614✔
3663
}
3664

3665
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3666
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,248,137!
3667
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,248,200!
3668
  return 0;
624,123✔
3669
}
3670

3671
typedef struct {
3672
  int32_t vgId;
3673
  // TODO stas
3674
} SMqReportVgInfo;
3675

3676
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3677
  int32_t tlen = 0;
3678
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3679
  return tlen;
3680
}
3681

3682
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3683
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3684
  return buf;
3685
}
3686

3687
typedef struct {
3688
  int32_t epoch;
3689
  int64_t topicUid;
3690
  char    name[TSDB_TOPIC_FNAME_LEN];
3691
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3692
} SMqTopicInfo;
3693

3694
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3695
  int32_t tlen = 0;
3696
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3697
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3698
  tlen += taosEncodeString(buf, pTopicInfo->name);
3699
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3700
  tlen += taosEncodeFixedI32(buf, sz);
3701
  for (int32_t i = 0; i < sz; i++) {
3702
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3703
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3704
  }
3705
  return tlen;
3706
}
3707

3708
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3709
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3710
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3711
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3712
  int32_t sz;
3713
  buf = taosDecodeFixedI32(buf, &sz);
3714
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3715
    return NULL;
3716
  }
3717
  for (int32_t i = 0; i < sz; i++) {
3718
    SMqReportVgInfo vgInfo;
3719
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3720
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3721
      return NULL;
3722
    }
3723
  }
3724
  return buf;
3725
}
3726

3727
typedef struct {
3728
  int32_t status;  // ask hb endpoint
3729
  int32_t epoch;
3730
  int64_t consumerId;
3731
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3732
} SMqReportReq;
3733

3734
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3735
  int32_t tlen = 0;
3736
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3737
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3738
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3739
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3740
  tlen += taosEncodeFixedI32(buf, sz);
3741
  for (int32_t i = 0; i < sz; i++) {
3742
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3743
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3744
  }
3745
  return tlen;
3746
}
3747

3748
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3749
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3750
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3751
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3752
  int32_t sz;
3753
  buf = taosDecodeFixedI32(buf, &sz);
3754
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3755
    return NULL;
3756
  }
3757
  for (int32_t i = 0; i < sz; i++) {
3758
    SMqTopicInfo topicInfo;
3759
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3760
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3761
      return NULL;
3762
    }
3763
  }
3764
  return buf;
3765
}
3766

3767
typedef struct {
3768
  SMsgHead head;
3769
  int64_t  leftForVer;
3770
  int32_t  vgId;
3771
  int64_t  consumerId;
3772
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3773
} SMqVDeleteReq;
3774

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

3779
typedef struct {
3780
  char    name[TSDB_STREAM_FNAME_LEN];
3781
  int8_t  igNotExists;
3782
  int32_t sqlLen;
3783
  char*   sql;
3784
} SMDropStreamReq;
3785

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

3790
typedef struct {
3791
  SMsgHead head;
3792
  int64_t  resetRelHalt;  // reset related stream task halt status
3793
  int64_t  streamId;
3794
  int32_t  taskId;
3795
} SVDropStreamTaskReq;
3796

3797
typedef struct {
3798
  int8_t reserved;
3799
} SVDropStreamTaskRsp;
3800

3801
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3802
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3803
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3804

3805
typedef struct SVUpdateCheckpointInfoReq {
3806
  SMsgHead head;
3807
  int64_t  streamId;
3808
  int32_t  taskId;
3809
  int64_t  checkpointId;
3810
  int64_t  checkpointVer;
3811
  int64_t  checkpointTs;
3812
  int32_t  transId;
3813
  int64_t  hStreamId;  // add encode/decode
3814
  int64_t  hTaskId;
3815
  int8_t   dropRelHTask;
3816
} SVUpdateCheckpointInfoReq;
3817

3818
typedef struct {
3819
  int64_t leftForVer;
3820
  int32_t vgId;
3821
  int64_t oldConsumerId;
3822
  int64_t newConsumerId;
3823
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3824
  int8_t  subType;
3825
  int8_t  withMeta;
3826
  char*   qmsg;  // SubPlanToString
3827
  int64_t suid;
3828
} SMqRebVgReq;
3829

3830
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3831
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3832

3833
typedef struct {
3834
  char    topic[TSDB_TOPIC_FNAME_LEN];
3835
  int64_t ntbUid;
3836
  SArray* colIdList;  // SArray<int16_t>
3837
} STqCheckInfo;
3838

3839
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3840
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3841
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3842

3843
// tqOffset
3844
enum {
3845
  TMQ_OFFSET__RESET_NONE = -3,
3846
  TMQ_OFFSET__RESET_EARLIEST = -2,
3847
  TMQ_OFFSET__RESET_LATEST = -1,
3848
  TMQ_OFFSET__LOG = 1,
3849
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3850
  TMQ_OFFSET__SNAPSHOT_META = 3,
3851
};
3852

3853
enum {
3854
  WITH_DATA = 0,
3855
  WITH_META = 1,
3856
  ONLY_META = 2,
3857
};
3858

3859
#define TQ_OFFSET_VERSION 1
3860

3861
typedef struct {
3862
  int8_t type;
3863
  union {
3864
    // snapshot
3865
    struct {
3866
      int64_t uid;
3867
      int64_t ts;
3868
      SValue  primaryKey;
3869
    };
3870
    // log
3871
    struct {
3872
      int64_t version;
3873
    };
3874
  };
3875
} STqOffsetVal;
3876

3877
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3878
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
25,005✔
3879
  pOffsetVal->uid = uid;
25,005✔
3880
  pOffsetVal->ts = ts;
25,005✔
3881
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
25,005!
UNCOV
3882
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3883
  }
3884
  pOffsetVal->primaryKey = primaryKey;
25,023✔
3885
}
25,023✔
3886

3887
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3888
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
143✔
3889
  pOffsetVal->uid = uid;
143✔
3890
}
143✔
3891

3892
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3893
  pOffsetVal->type = TMQ_OFFSET__LOG;
555,761✔
3894
  pOffsetVal->version = ver;
555,761✔
3895
}
555,761✔
3896

3897
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3898
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3899
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3900
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3901
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3902
void    tOffsetDestroy(void* pVal);
3903

3904
typedef struct {
3905
  STqOffsetVal val;
3906
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3907
} STqOffset;
3908

3909
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3910
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3911
void    tDeleteSTqOffset(void* val);
3912

3913
typedef struct SMqVgOffset {
3914
  int64_t   consumerId;
3915
  STqOffset offset;
3916
} SMqVgOffset;
3917

3918
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3919
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3920

3921
typedef struct {
3922
  SMsgHead head;
3923
  int64_t  streamId;
3924
  int32_t  taskId;
3925
} SVPauseStreamTaskReq;
3926

3927
typedef struct {
3928
  SMsgHead head;
3929
  int64_t  streamId;
3930
  int32_t  taskId;
3931
  int64_t  chkptId;
3932
} SVResetStreamTaskReq;
3933

3934
typedef struct {
3935
  char   name[TSDB_STREAM_FNAME_LEN];
3936
  int8_t igNotExists;
3937
} SMPauseStreamReq;
3938

3939
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3940
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3941

3942
typedef struct {
3943
  SMsgHead head;
3944
  int32_t  taskId;
3945
  int64_t  streamId;
3946
  int8_t   igUntreated;
3947
} SVResumeStreamTaskReq;
3948

3949
typedef struct {
3950
  int8_t reserved;
3951
} SVResumeStreamTaskRsp;
3952

3953
typedef struct {
3954
  char   name[TSDB_STREAM_FNAME_LEN];
3955
  int8_t igNotExists;
3956
  int8_t igUntreated;
3957
} SMResumeStreamReq;
3958

3959
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3960
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3961

3962
typedef struct {
3963
  char   name[TSDB_STREAM_FNAME_LEN];
3964
  int8_t igNotExists;
3965
  int8_t igUntreated;
3966
} SMResetStreamReq;
3967

3968
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
3969
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
3970

3971
typedef struct {
3972
  char    name[TSDB_TABLE_FNAME_LEN];
3973
  char    stb[TSDB_TABLE_FNAME_LEN];
3974
  int8_t  igExists;
3975
  int8_t  intervalUnit;
3976
  int8_t  slidingUnit;
3977
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
3978
  int32_t dstVgId;   // for stream
3979
  int64_t interval;
3980
  int64_t offset;
3981
  int64_t sliding;
3982
  int64_t maxDelay;
3983
  int64_t watermark;
3984
  int32_t exprLen;        // strlen + 1
3985
  int32_t tagsFilterLen;  // strlen + 1
3986
  int32_t sqlLen;         // strlen + 1
3987
  int32_t astLen;         // strlen + 1
3988
  char*   expr;
3989
  char*   tagsFilter;
3990
  char*   sql;
3991
  char*   ast;
3992
  int64_t deleteMark;
3993
  int64_t lastTs;
3994
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3995
  SArray* pVgroupVerList;
3996
  int8_t  recursiveTsma;
3997
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3998
} SMCreateSmaReq;
3999

4000
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4001
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4002
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4003

4004
typedef struct {
4005
  char   name[TSDB_TABLE_FNAME_LEN];
4006
  int8_t igNotExists;
4007
} SMDropSmaReq;
4008

4009
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4010
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4011

4012
typedef struct {
4013
  char   dbFName[TSDB_DB_FNAME_LEN];
4014
  char   stbName[TSDB_TABLE_NAME_LEN];
4015
  char   colName[TSDB_COL_NAME_LEN];
4016
  char   idxName[TSDB_INDEX_FNAME_LEN];
4017
  int8_t idxType;
4018
} SCreateTagIndexReq;
4019

4020
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4021
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4022

4023
typedef SMDropSmaReq SDropTagIndexReq;
4024

4025
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4026
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4027

4028
typedef struct {
4029
  int8_t         version;       // for compatibility(default 0)
4030
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4031
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4032
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4033
  int32_t        dstVgId;
4034
  char           indexName[TSDB_INDEX_NAME_LEN];
4035
  int32_t        exprLen;
4036
  int32_t        tagsFilterLen;
4037
  int64_t        indexUid;
4038
  tb_uid_t       tableUid;  // super/child/common table uid
4039
  tb_uid_t       dstTbUid;  // for dstVgroup
4040
  int64_t        interval;
4041
  int64_t        offset;  // use unit by precision of DB
4042
  int64_t        sliding;
4043
  char*          dstTbName;  // for dstVgroup
4044
  char*          expr;       // sma expression
4045
  char*          tagsFilter;
4046
  SSchemaWrapper schemaRow;  // for dstVgroup
4047
  SSchemaWrapper schemaTag;  // for dstVgroup
4048
} STSma;                     // Time-range-wise SMA
4049

4050
typedef STSma SVCreateTSmaReq;
4051

4052
typedef struct {
4053
  int8_t  type;  // 0 status report, 1 update data
4054
  int64_t indexUid;
4055
  int64_t skey;  // start TS key of interval/sliding window
4056
} STSmaMsg;
4057

4058
typedef struct {
4059
  int64_t indexUid;
4060
  char    indexName[TSDB_INDEX_NAME_LEN];
4061
} SVDropTSmaReq;
4062

4063
typedef struct {
4064
  int tmp;  // TODO: to avoid compile error
4065
} SVCreateTSmaRsp, SVDropTSmaRsp;
4066

4067
#if 0
4068
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4069
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4070
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4071
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4072
#endif
4073

4074
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4075
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4076
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4077
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4078

4079
typedef struct {
4080
  int32_t number;
4081
  STSma*  tSma;
4082
} STSmaWrapper;
4083

4084
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4085
  if (pSma) {
3!
4086
    taosMemoryFreeClear(pSma->dstTbName);
3!
4087
    taosMemoryFreeClear(pSma->expr);
3!
4088
    taosMemoryFreeClear(pSma->tagsFilter);
3!
4089
  }
4090
}
3✔
4091

4092
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
UNCOV
4093
  if (pSW) {
×
UNCOV
4094
    if (pSW->tSma) {
×
4095
      if (deepCopy) {
×
4096
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4097
          tDestroyTSma(pSW->tSma + i);
×
4098
        }
4099
      }
UNCOV
4100
      taosMemoryFreeClear(pSW->tSma);
×
4101
    }
4102
  }
UNCOV
4103
}
×
4104

4105
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4106
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4107
  taosMemoryFreeClear(pSW);
×
4108
  return NULL;
×
4109
}
4110

4111
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4112
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4113

4114
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4115
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4116

4117
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
UNCOV
4118
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4119
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
4120
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4121
  }
UNCOV
4122
  return 0;
×
4123
}
4124

UNCOV
4125
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
UNCOV
4126
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
UNCOV
4127
  for (int32_t i = 0; i < pReq->number; ++i) {
×
UNCOV
4128
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4129
  }
UNCOV
4130
  return 0;
×
4131
}
4132

4133
typedef struct {
4134
  int idx;
4135
} SMCreateFullTextReq;
4136

4137
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4138
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4139
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4140

4141
typedef struct {
4142
  char   name[TSDB_TABLE_FNAME_LEN];
4143
  int8_t igNotExists;
4144
} SMDropFullTextReq;
4145

4146
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4147
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4148

4149
typedef struct {
4150
  char indexFName[TSDB_INDEX_FNAME_LEN];
4151
} SUserIndexReq;
4152

4153
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4154
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4155

4156
typedef struct {
4157
  char dbFName[TSDB_DB_FNAME_LEN];
4158
  char tblFName[TSDB_TABLE_FNAME_LEN];
4159
  char colName[TSDB_COL_NAME_LEN];
4160
  char indexType[TSDB_INDEX_TYPE_LEN];
4161
  char indexExts[TSDB_INDEX_EXTS_LEN];
4162
} SUserIndexRsp;
4163

4164
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4165
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4166

4167
typedef struct {
4168
  char tbFName[TSDB_TABLE_FNAME_LEN];
4169
} STableIndexReq;
4170

4171
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4172
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4173

4174
typedef struct {
4175
  int8_t  intervalUnit;
4176
  int8_t  slidingUnit;
4177
  int64_t interval;
4178
  int64_t offset;
4179
  int64_t sliding;
4180
  int64_t dstTbUid;
4181
  int32_t dstVgId;
4182
  SEpSet  epSet;
4183
  char*   expr;
4184
} STableIndexInfo;
4185

4186
typedef struct {
4187
  char     tbName[TSDB_TABLE_NAME_LEN];
4188
  char     dbFName[TSDB_DB_FNAME_LEN];
4189
  uint64_t suid;
4190
  int32_t  version;
4191
  int32_t  indexSize;
4192
  SArray*  pIndex;  // STableIndexInfo
4193
} STableIndexRsp;
4194

4195
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4196
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4197
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4198

4199
void tFreeSTableIndexInfo(void* pInfo);
4200

4201
typedef struct {
4202
  int8_t  mqMsgType;
4203
  int32_t code;
4204
  int32_t epoch;
4205
  int64_t consumerId;
4206
  int64_t walsver;
4207
  int64_t walever;
4208
} SMqRspHead;
4209

4210
typedef struct {
4211
  SMsgHead     head;
4212
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4213
  int8_t       withTbName;
4214
  int8_t       useSnapshot;
4215
  int32_t      epoch;
4216
  uint64_t     reqId;
4217
  int64_t      consumerId;
4218
  int64_t      timeout;
4219
  STqOffsetVal reqOffset;
4220
  int8_t       enableReplay;
4221
  int8_t       sourceExcluded;
4222
  int8_t       rawData;
4223
  int32_t      minPollRows;
4224
  int8_t       enableBatchMeta;
4225
  SHashObj    *uidHash;  // to find if uid is duplicated
4226
} SMqPollReq;
4227

4228
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4229
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4230
void    tDestroySMqPollReq(SMqPollReq* pReq);
4231

4232
typedef struct {
4233
  int32_t vgId;
4234
  int64_t offset;
4235
  SEpSet  epSet;
4236
} SMqSubVgEp;
4237

4238
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4239
  int32_t tlen = 0;
9,554✔
4240
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
9,554✔
4241
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
9,554✔
4242
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
9,554✔
4243
  return tlen;
9,554✔
4244
}
4245

4246
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4247
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,662!
4248
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,662!
4249
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,662✔
4250
  return buf;
4,662✔
4251
}
4252

4253
typedef struct {
4254
  char           topic[TSDB_TOPIC_FNAME_LEN];
4255
  char           db[TSDB_DB_FNAME_LEN];
4256
  SArray*        vgs;  // SArray<SMqSubVgEp>
4257
  SSchemaWrapper schema;
4258
} SMqSubTopicEp;
4259

4260
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4261
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4262
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4263

4264
typedef struct {
4265
  SMqRspHead   head;
4266
  STqOffsetVal rspOffset;
4267
  int16_t      resMsgType;
4268
  int32_t      metaRspLen;
4269
  void*        metaRsp;
4270
} SMqMetaRsp;
4271

4272
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4273
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4274
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4275

4276
#define MQ_DATA_RSP_VERSION 100
4277

4278
typedef struct {
4279
  SMqRspHead   head;
4280
  STqOffsetVal rspOffset;
4281
  STqOffsetVal reqOffset;
4282
  int32_t      blockNum;
4283
  int8_t       withTbName;
4284
  int8_t       withSchema;
4285
  SArray*      blockDataLen;
4286
  SArray*      blockData;
4287
  SArray*      blockTbName;
4288
  SArray*      blockSchema;
4289

4290
  union {
4291
    struct {
4292
      int64_t sleepTime;
4293
    };
4294
    struct {
4295
      int32_t createTableNum;
4296
      SArray* createTableLen;
4297
      SArray* createTableReq;
4298
    };
4299
    struct{
4300
      int32_t len;
4301
      void*   rawData;
4302
    };
4303
  };
4304
  void*   data;  //for free in client, only effected if type is data or metadata. raw data not effected
4305
  bool    blockDataElementFree;   // if true, free blockDataElement in blockData,(true in server, false in client)
4306

4307
} SMqDataRsp;
4308

4309
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4310
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4311
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4312
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4313
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4314

4315
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4316
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4317
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4318

4319
typedef struct SMqBatchMetaRsp {
4320
  SMqRspHead   head;  // not serialize
4321
  STqOffsetVal rspOffset;
4322
  SArray*      batchMetaLen;
4323
  SArray*      batchMetaReq;
4324
  void*        pMetaBuff;    // not serialize
4325
  uint32_t     metaBuffLen;  // not serialize
4326
} SMqBatchMetaRsp;
4327

4328
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4329
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4330
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4331
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4332

4333
typedef struct {
4334
  SMqRspHead head;
4335
  char       cgroup[TSDB_CGROUP_LEN];
4336
  SArray*    topics;  // SArray<SMqSubTopicEp>
4337
} SMqAskEpRsp;
4338

4339
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4340
  int32_t tlen = 0;
18,760✔
4341
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4342
  int32_t sz = taosArrayGetSize(pRsp->topics);
18,760!
4343
  tlen += taosEncodeFixedI32(buf, sz);
18,760✔
4344
  for (int32_t i = 0; i < sz; i++) {
26,608✔
4345
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
7,848✔
4346
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
7,848✔
4347
  }
4348
  return tlen;
18,760✔
4349
}
4350

4351
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4352
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4353
  int32_t sz;
4354
  buf = taosDecodeFixedI32(buf, &sz);
8,977✔
4355
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,977✔
4356
  if (pRsp->topics == NULL) {
8,977!
UNCOV
4357
    return NULL;
×
4358
  }
4359
  for (int32_t i = 0; i < sz; i++) {
12,794✔
4360
    SMqSubTopicEp topicEp;
4361
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,817✔
4362
    if (buf == NULL) {
3,817!
UNCOV
4363
      return NULL;
×
4364
    }
4365
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
7,634!
UNCOV
4366
      return NULL;
×
4367
    }
4368
  }
4369
  return buf;
8,977✔
4370
}
4371

4372
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4373
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
21,463✔
4374
}
21,463✔
4375

4376
typedef struct {
4377
  int32_t      vgId;
4378
  STqOffsetVal offset;
4379
  int64_t      rows;
4380
  int64_t      ever;
4381
} OffsetRows;
4382

4383
typedef struct {
4384
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4385
  SArray* offsetRows;
4386
} TopicOffsetRows;
4387

4388
typedef struct {
4389
  int64_t consumerId;
4390
  int32_t epoch;
4391
  SArray* topics;
4392
  int8_t  pollFlag;
4393
} SMqHbReq;
4394

4395
typedef struct {
4396
  char   topic[TSDB_TOPIC_FNAME_LEN];
4397
  int8_t noPrivilege;
4398
} STopicPrivilege;
4399

4400
typedef struct {
4401
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4402
  int32_t debugFlag;
4403
} SMqHbRsp;
4404

4405
typedef struct {
4406
  SMsgHead head;
4407
  int64_t  consumerId;
4408
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4409
} SMqSeekReq;
4410

4411
#define TD_AUTO_CREATE_TABLE 0x1
4412
typedef struct {
4413
  int64_t       suid;
4414
  int64_t       uid;
4415
  int32_t       sver;
4416
  uint32_t      nData;
4417
  uint8_t*      pData;
4418
  SVCreateTbReq cTbReq;
4419
} SVSubmitBlk;
4420

4421
typedef struct {
4422
  SMsgHead header;
4423
  uint64_t sId;
4424
  uint64_t queryId;
4425
  uint64_t clientId;
4426
  uint64_t taskId;
4427
  uint32_t sqlLen;
4428
  uint32_t phyLen;
4429
  char*    sql;
4430
  char*    msg;
4431
  int8_t   source;
4432
} SVDeleteReq;
4433

4434
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4435
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4436

4437
typedef struct {
4438
  int64_t affectedRows;
4439
} SVDeleteRsp;
4440

4441
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4442
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4443

4444
typedef struct SDeleteRes {
4445
  uint64_t suid;
4446
  SArray*  uidList;
4447
  int64_t  skey;
4448
  int64_t  ekey;
4449
  int64_t  affectedRows;
4450
  char     tableFName[TSDB_TABLE_NAME_LEN];
4451
  char     tsColName[TSDB_COL_NAME_LEN];
4452
  int64_t  ctimeMs;  // fill by vnode
4453
  int8_t   source;
4454
} SDeleteRes;
4455

4456
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4457
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4458

4459
typedef struct {
4460
  // int64_t uid;
4461
  char    tbname[TSDB_TABLE_NAME_LEN];
4462
  int64_t startTs;
4463
  int64_t endTs;
4464
} SSingleDeleteReq;
4465

4466
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4467
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4468

4469
typedef struct {
4470
  int64_t suid;
4471
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4472
  int64_t ctimeMs;     // fill by vnode
4473
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4474
} SBatchDeleteReq;
4475

4476
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4477
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4478
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4479

4480
typedef struct {
4481
  int32_t msgIdx;
4482
  int32_t msgType;
4483
  int32_t msgLen;
4484
  void*   msg;
4485
} SBatchMsg;
4486

4487
typedef struct {
4488
  SMsgHead header;
4489
  SArray*  pMsgs;  // SArray<SBatchMsg>
4490
} SBatchReq;
4491

4492
typedef struct {
4493
  int32_t reqType;
4494
  int32_t msgIdx;
4495
  int32_t msgLen;
4496
  int32_t rspCode;
4497
  void*   msg;
4498
} SBatchRspMsg;
4499

4500
typedef struct {
4501
  SArray* pRsps;  // SArray<SBatchRspMsg>
4502
} SBatchRsp;
4503

4504
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4505
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4506
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
6,853,561✔
4507
  if (NULL == msg) {
6,853,561!
4508
    return;
×
4509
  }
4510
  SBatchMsg* pMsg = (SBatchMsg*)msg;
6,853,561✔
4511
  taosMemoryFree(pMsg->msg);
6,853,561!
4512
}
4513

4514
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4515
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4516

4517
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,483,962✔
4518
  if (NULL == p) {
1,483,962!
UNCOV
4519
    return;
×
4520
  }
4521

4522
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,483,962✔
4523
  taosMemoryFree(pRsp->msg);
1,483,962!
4524
}
4525

4526
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4527
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4528
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4529
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4530
void    tDestroySMqHbReq(SMqHbReq* pReq);
4531

4532
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4533
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4534
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4535

4536
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4537
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4538

4539
#define TD_REQ_FROM_APP               0x0
4540
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4541
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4542
#define SUBMIT_REQ_FROM_FILE          0x4
4543
#define TD_REQ_FROM_TAOX              0x8
4544
#define SUBMIT_REQUEST_VERSION        (1)
4545

4546
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4547

4548
typedef struct {
4549
  int32_t        flags;
4550
  SVCreateTbReq* pCreateTbReq;
4551
  int64_t        suid;
4552
  int64_t        uid;
4553
  int32_t        sver;
4554
  union {
4555
    SArray* aRowP;
4556
    SArray* aCol;
4557
  };
4558
  int64_t ctimeMs;
4559
} SSubmitTbData;
4560

4561
typedef struct {
4562
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4563
  bool    raw;
4564
} SSubmitReq2;
4565

4566
typedef struct {
4567
  SMsgHead header;
4568
  int64_t  version;
4569
  char     data[];  // SSubmitReq2
4570
} SSubmitReq2Msg;
4571

4572
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4573
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4574
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4575
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4576
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4577

4578
typedef struct {
4579
  int32_t affectedRows;
4580
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4581
} SSubmitRsp2;
4582

4583
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4584
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4585
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4586

4587
#define TSDB_MSG_FLG_ENCODE 0x1
4588
#define TSDB_MSG_FLG_DECODE 0x2
4589
#define TSDB_MSG_FLG_CMPT   0x3
4590

4591
typedef struct {
4592
  union {
4593
    struct {
4594
      void*   msgStr;
4595
      int32_t msgLen;
4596
      int64_t ver;
4597
    };
4598
    void* pDataBlock;
4599
  };
4600
} SPackedData;
4601

4602
typedef struct {
4603
  char     fullname[TSDB_VIEW_FNAME_LEN];
4604
  char     name[TSDB_VIEW_NAME_LEN];
4605
  char     dbFName[TSDB_DB_FNAME_LEN];
4606
  char*    querySql;
4607
  char*    sql;
4608
  int8_t   orReplace;
4609
  int8_t   precision;
4610
  int32_t  numOfCols;
4611
  SSchema* pSchema;
4612
} SCMCreateViewReq;
4613

4614
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4615
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4616
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4617

4618
typedef struct {
4619
  char   fullname[TSDB_VIEW_FNAME_LEN];
4620
  char   name[TSDB_VIEW_NAME_LEN];
4621
  char   dbFName[TSDB_DB_FNAME_LEN];
4622
  char*  sql;
4623
  int8_t igNotExists;
4624
} SCMDropViewReq;
4625

4626
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4627
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4628
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4629

4630
typedef struct {
4631
  char fullname[TSDB_VIEW_FNAME_LEN];
4632
} SViewMetaReq;
4633
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4634
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4635

4636
typedef struct {
4637
  char     name[TSDB_VIEW_NAME_LEN];
4638
  char     dbFName[TSDB_DB_FNAME_LEN];
4639
  char*    user;
4640
  uint64_t dbId;
4641
  uint64_t viewId;
4642
  char*    querySql;
4643
  int8_t   precision;
4644
  int8_t   type;
4645
  int32_t  version;
4646
  int32_t  numOfCols;
4647
  SSchema* pSchema;
4648
} SViewMetaRsp;
4649
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4650
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4651
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4652
typedef struct {
4653
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4654
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4655
} STableTSMAInfoReq;
4656

4657
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4658
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4659

4660
typedef struct {
4661
  int32_t  funcId;
4662
  col_id_t colId;
4663
} STableTSMAFuncInfo;
4664

4665
typedef struct {
4666
  char     name[TSDB_TABLE_NAME_LEN];
4667
  uint64_t tsmaId;
4668
  char     targetTb[TSDB_TABLE_NAME_LEN];
4669
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4670
  char     tb[TSDB_TABLE_NAME_LEN];
4671
  char     dbFName[TSDB_DB_FNAME_LEN];
4672
  uint64_t suid;
4673
  uint64_t destTbUid;
4674
  uint64_t dbId;
4675
  int32_t  version;
4676
  int64_t  interval;
4677
  int8_t   unit;
4678
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4679
  SArray*  pTags;      // SArray<SSchema>
4680
  SArray*  pUsedCols;  // SArray<SSchema>
4681
  char*    ast;
4682

4683
  int64_t streamUid;
4684
  int64_t reqTs;
4685
  int64_t rspTs;
4686
  int64_t delayDuration;  // ms
4687
  bool    fillHistoryFinished;
4688
} STableTSMAInfo;
4689

4690
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4691
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4692
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4693
void    tFreeTableTSMAInfo(void* p);
4694
void    tFreeAndClearTableTSMAInfo(void* p);
4695
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4696

4697
#define STSMAHbRsp            STableTSMAInfoRsp
4698
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4699
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4700
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4701

4702
typedef struct SStreamProgressReq {
4703
  int64_t streamId;
4704
  int32_t vgId;
4705
  int32_t fetchIdx;
4706
  int32_t subFetchIdx;
4707
} SStreamProgressReq;
4708

4709
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4710
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4711

4712
typedef struct SStreamProgressRsp {
4713
  int64_t streamId;
4714
  int32_t vgId;
4715
  bool    fillHisFinished;
4716
  int64_t progressDelay;
4717
  int32_t fetchIdx;
4718
  int32_t subFetchIdx;
4719
} SStreamProgressRsp;
4720

4721
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4722
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4723

4724
typedef struct SDropCtbWithTsmaSingleVgReq {
4725
  SVgroupInfo vgInfo;
4726
  SArray*     pTbs;  // SVDropTbReq
4727
} SMDropTbReqsOnSingleVg;
4728

4729
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4730
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4731
void    tFreeSMDropTbReqOnSingleVg(void* p);
4732

4733
typedef struct SDropTbsReq {
4734
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4735
} SMDropTbsReq;
4736

4737
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4738
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4739
void    tFreeSMDropTbsReq(void*);
4740

4741
typedef struct SVFetchTtlExpiredTbsRsp {
4742
  SArray* pExpiredTbs;  // SVDropTbReq
4743
  int32_t vgId;
4744
} SVFetchTtlExpiredTbsRsp;
4745

4746
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4747
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4748

4749
void tFreeFetchTtlExpiredTbsRsp(void* p);
4750

4751
void setDefaultOptionsForField(SFieldWithOptions* field);
4752
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4753

4754
#pragma pack(pop)
4755

4756
#ifdef __cplusplus
4757
}
4758
#endif
4759

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