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

taosdata / TDengine / #4271

10 Jun 2025 09:45AM UTC coverage: 62.985% (+0.002%) from 62.983%
#4271

push

travis-ci

web-flow
Merge pull request #31337 from taosdata/newtest_3.0

fix TD-35057 and TD-35346

158179 of 319671 branches covered (49.48%)

Branch coverage included in aggregate %.

243860 of 318637 relevant lines covered (76.53%)

18624660.26 hits per line

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

40.76
/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) {
70,941,672✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
70,941,672✔
74
  int    segIdx = TMSG_SEG_CODE(type);
70,941,672✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
70,941,672!
76
    return type < tMsgRangeDict[segIdx];
70,950,026✔
77
  }
78
  return false;
2✔
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
7,519,754✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
7,475,861!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
14,995,615!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
38,770,580✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
38,770,580✔
91
}
92

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

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

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

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

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

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

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

209
#define TSDB_KILL_MSG_LEN 30
210

211
#define TSDB_TABLE_NUM_UNIT 100000
212

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

669
//
670

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

780
bool hasExtSchema(const SExtSchema* pExtSchema);
781

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

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

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

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

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

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

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

836
  return pDstWrapper;
837
}
838

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

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

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

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

878
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
12,130,647!
879
  if (pSW == NULL) {
12,129,976!
880
    return NULL;
×
881
  }
882
  pSW->nCols = pSchemaWrapper->nCols;
12,129,976✔
883
  pSW->version = pSchemaWrapper->version;
12,129,976✔
884
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
12,129,976!
885
  if (pSW->pSchema == NULL) {
12,129,934!
886
    taosMemoryFree(pSW);
×
887
    return NULL;
×
888
  }
889

890
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
12,129,934✔
891
  return pSW;
12,129,934✔
892
}
893

894
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
593,605✔
895
  if (pSchemaWrapper) {
28,726,933!
896
    taosMemoryFree(pSchemaWrapper->pSchema);
11,041,403!
897
    taosMemoryFree(pSchemaWrapper);
11,041,598!
898
  }
899
}
28,607,352✔
900

901
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,485,398✔
902
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,485,398!
903
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,485,565✔
904
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,485,690!
905
  }
906
}
1,485,266✔
907

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

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

927
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
928
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
611,939,019!
929
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
635,377,836!
930
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
635,377,836!
931
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
635,377,836!
932
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
635,377,836!
933
  return 0;
317,688,918✔
934
}
935

936
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
937
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
796,640,483!
938
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,565,036,897!
939
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,556,367,781!
940
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,572,284,372!
941
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
788,808,183!
942
  return 0;
833,621,567✔
943
}
944

945
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
946
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
364,402,368!
947
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
364,402,368!
948
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
364,402,368!
949
  return 0;
182,201,184✔
950
}
951

952
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
953
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
7,239,322!
954
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
7,239,317!
955
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
7,239,308!
956
  return 0;
3,619,652✔
957
}
958

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

970
static FORCE_INLINE int32_t tDecodeSColRef(SDecoder* pDecoder, SColRef* pColRef) {
971
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, (int8_t*)&pColRef->hasRef));
36,072!
972
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
36,072!
973
  if (pColRef->hasRef) {
18,036✔
974
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
10,582!
975
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
10,582!
976
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
10,582!
977
  }
978

979
  return 0;
18,036✔
980
}
981

982
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
983
  int32_t tlen = 0;
8,494✔
984
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,494✔
985
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,494✔
986
  for (int32_t i = 0; i < pSW->nCols; i++) {
60,570✔
987
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
104,152!
988
  }
989
  return tlen;
8,494✔
990
}
991

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

1001
    for (int32_t i = 0; i < pSW->nCols; i++) {
27,097✔
1002
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
48,740✔
1003
    }
1004
  } else {
1005
    pSW->pSchema = NULL;
1,232✔
1006
  }
1007
  return (void*)buf;
3,959✔
1008
}
1009

1010
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1011
  if (pSW == NULL) {
798,993!
1012
    return TSDB_CODE_INVALID_PARA;
×
1013
  }
1014
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,597,986!
1015
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,597,986!
1016
  for (int32_t i = 0; i < pSW->nCols; i++) {
24,237,810!
1017
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
46,877,634!
1018
  }
1019
  return 0;
798,993✔
1020
}
1021

1022
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1023
  if (pSW == NULL) {
1,527,699!
1024
    return TSDB_CODE_INVALID_PARA;
×
1025
  }
1026
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
3,055,407!
1027
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
3,055,353!
1028

1029
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,527,645!
1030
  if (pSW->pSchema == NULL) {
1,527,787!
1031
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1032
  }
1033
  for (int32_t i = 0; i < pSW->nCols; i++) {
18,085,510!
1034
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
33,116,323!
1035
  }
1036

1037
  return 0;
1,526,910✔
1038
}
1039

1040
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1041
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
90,253,732!
1042
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
92,817,629!
1043

1044
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
46,406,239!
1045
  if (pSW->pSchema == NULL) {
46,641,582!
1046
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1047
  }
1048
  for (int32_t i = 0; i < pSW->nCols; i++) {
859,210,250!
1049
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,627,986,884!
1050
  }
1051

1052
  return 0;
43,792,034✔
1053
}
1054

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

1088
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1089
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1090
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1091

1092
typedef struct {
1093
  STableMetaRsp* pMeta;
1094
} SMCreateStbRsp;
1095

1096
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1097
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1098
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1099

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

1110
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1111
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1112
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1113

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

1128
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1129
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1130
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1131

1132
typedef struct SEpSet {
1133
  int8_t inUse;
1134
  int8_t numOfEps;
1135
  SEp    eps[TSDB_MAX_REPLICA];
1136
} SEpSet;
1137

1138
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1139
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1140
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1141
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1142

1143
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1144
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1145

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

1157
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1158
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1159

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

1179
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1180
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1181

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

1193
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1194
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1195

1196
typedef struct {
1197
  char    user[TSDB_USER_LEN];
1198
  int32_t sqlLen;
1199
  char*   sql;
1200
} SDropUserReq, SDropAcctReq;
1201

1202
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1203
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1204
void    tFreeSDropUserReq(SDropUserReq* pReq);
1205

1206
typedef struct SIpV4Range {
1207
  uint32_t ip;
1208
  uint32_t mask;
1209
} SIpV4Range;
1210

1211
typedef struct SIpv6Range {
1212
  uint64_t addr[2];
1213
  uint32_t mask;
1214
} SIpV6Range;
1215

1216
typedef struct {
1217
  int8_t type;
1218
  union {
1219
    SIpV4Range ipV4;
1220
    SIpV6Range ipV6;
1221
  };
1222
} SIpRange;
1223

1224
typedef struct {
1225
  int32_t    num;
1226
  SIpV4Range pIpRange[];
1227
} SIpWhiteList;
1228

1229
typedef struct {
1230
  int32_t  num;
1231
  SIpRange pIpRanges[];
1232
} SIpWhiteListDual;
1233

1234
SIpWhiteListDual* cloneIpWhiteList(SIpWhiteListDual* pIpWhiteList);
1235
int32_t           cvtIpWhiteListToDual(SIpWhiteList* pWhiteList, SIpWhiteListDual** pWhiteListDual);
1236
int32_t           cvtIpWhiteListDualToV4(SIpWhiteListDual* pWhiteListDual, SIpWhiteList** pWhiteList);
1237
int32_t           createDefaultIp6Range(SIpRange* pRange);
1238
int32_t           createDefaultIp4Range(SIpRange* pRange);
1239

1240
typedef struct {
1241
  int8_t  createType;
1242
  int8_t  superUser;  // denote if it is a super user or not
1243
  int8_t  sysInfo;
1244
  int8_t  enable;
1245
  char    user[TSDB_USER_LEN];
1246
  char    pass[TSDB_USET_PASSWORD_LEN];
1247
  int32_t numIpRanges;
1248

1249
  SIpV4Range* pIpRanges;
1250
  int32_t     sqlLen;
1251
  char*       sql;
1252
  int8_t      isImport;
1253
  int8_t      createDb;
1254
  int8_t      passIsMd5;
1255
  SIpRange*   pIpDualRanges;
1256
} SCreateUserReq;
1257

1258
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1259
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1260
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1261

1262
typedef struct {
1263
  int32_t dnodeId;
1264
  int64_t analVer;
1265
} SRetrieveAnalyticsAlgoReq;
1266

1267
typedef struct {
1268
  int64_t   ver;
1269
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1270
} SRetrieveAnalyticAlgoRsp;
1271

1272
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1273
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1274
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1275
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1276
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1277

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

1306
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1307
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1308
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1309

1310
typedef struct {
1311
  char user[TSDB_USER_LEN];
1312
} SGetUserAuthReq;
1313

1314
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1315
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1316

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

1338
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1339
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1340
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1341

1342
int32_t tSerializeIpRange(SEncoder* encoder, SIpRange* pRange);
1343
int32_t tDeserializeIpRange(SDecoder* decoder, SIpRange* pRange);
1344
typedef struct {
1345
  int64_t ver;
1346
  char    user[TSDB_USER_LEN];
1347
  int32_t numOfRange;
1348
  union {
1349
    SIpV4Range* pIpRanges;
1350
    SIpRange*   pIpDualRanges;
1351
  };
1352
} SUpdateUserIpWhite;
1353

1354
typedef struct {
1355
  int64_t             ver;
1356
  int                 numOfUser;
1357
  SUpdateUserIpWhite* pUserIpWhite;
1358
} SUpdateIpWhite;
1359

1360
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1361
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1362
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1363
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1364

1365
int32_t tSerializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1366
int32_t tDeserializeSUpdateIpWhiteDual(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1367
void    tFreeSUpdateIpWhiteDualReq(SUpdateIpWhite* pReq);
1368

1369
typedef struct {
1370
  int64_t ipWhiteVer;
1371
} SRetrieveIpWhiteReq;
1372

1373
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1374
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1375
typedef struct {
1376
  char user[TSDB_USER_LEN];
1377
} SGetUserWhiteListReq;
1378

1379
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1380
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1381

1382
typedef struct {
1383
  char    user[TSDB_USER_LEN];
1384
  int32_t numWhiteLists;
1385
  union {
1386
    SIpV4Range* pWhiteLists;
1387
    SIpRange*   pWhiteListsDual;
1388
  };
1389
} SGetUserWhiteListRsp;
1390

1391
int32_t tIpStrToUint(const SIpAddr* addr, SIpRange* range);
1392
int32_t tIpUintToStr(const SIpRange* range, SIpAddr* addr);
1393
int32_t tIpRangeSetMask(SIpRange* range, int32_t mask);
1394
void    tIpRangeSetDefaultMask(SIpRange* range);
1395

1396
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1397
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1398
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1399

1400
int32_t tSerializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1401
int32_t tDeserializeSGetUserWhiteListDualRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1402
void    tFreeSGetUserWhiteListDualRsp(SGetUserWhiteListRsp* pRsp);
1403

1404
/*
1405
 * for client side struct, only column id, type, bytes are necessary
1406
 * But for data in vnode side, we need all the following information.
1407
 */
1408
typedef struct {
1409
  union {
1410
    col_id_t colId;
1411
    int16_t  slotId;
1412
  };
1413

1414
  uint8_t precision;
1415
  uint8_t scale;
1416
  int32_t bytes;
1417
  int8_t  type;
1418
  uint8_t pk;
1419
  bool    noData;
1420
} SColumnInfo;
1421

1422
typedef struct STimeWindow {
1423
  TSKEY skey;
1424
  TSKEY ekey;
1425
} STimeWindow;
1426

1427
typedef struct SQueryHint {
1428
  bool batchScan;
1429
} SQueryHint;
1430

1431
typedef struct {
1432
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1433
  int32_t tsLen;          // total length of ts comp block
1434
  int32_t tsNumOfBlocks;  // ts comp block numbers
1435
  int32_t tsOrder;        // ts comp block order
1436
} STsBufInfo;
1437

1438
typedef struct {
1439
  void*       timezone;
1440
  char        intervalUnit;
1441
  char        slidingUnit;
1442
  char        offsetUnit;
1443
  int8_t      precision;
1444
  int64_t     interval;
1445
  int64_t     sliding;
1446
  int64_t     offset;
1447
  STimeWindow timeRange;
1448
} SInterval;
1449

1450
typedef struct STbVerInfo {
1451
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1452
  int32_t sversion;
1453
  int32_t tversion;
1454
  int32_t rversion;  // virtual table's column ref's version
1455
} STbVerInfo;
1456

1457
typedef struct {
1458
  int32_t code;
1459
  int64_t affectedRows;
1460
  SArray* tbVerInfo;  // STbVerInfo
1461
} SQueryTableRsp;
1462

1463
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1464

1465
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1466

1467
typedef struct {
1468
  SMsgHead header;
1469
  char     dbFName[TSDB_DB_FNAME_LEN];
1470
  char     tbName[TSDB_TABLE_NAME_LEN];
1471
} STableCfgReq;
1472

1473
typedef struct {
1474
  char        tbName[TSDB_TABLE_NAME_LEN];
1475
  char        stbName[TSDB_TABLE_NAME_LEN];
1476
  char        dbFName[TSDB_DB_FNAME_LEN];
1477
  int32_t     numOfTags;
1478
  int32_t     numOfColumns;
1479
  int8_t      tableType;
1480
  int64_t     delay1;
1481
  int64_t     delay2;
1482
  int64_t     watermark1;
1483
  int64_t     watermark2;
1484
  int32_t     ttl;
1485
  int32_t     keep;
1486
  SArray*     pFuncs;
1487
  int32_t     commentLen;
1488
  char*       pComment;
1489
  SSchema*    pSchemas;
1490
  int32_t     tagsLen;
1491
  char*       pTags;
1492
  SSchemaExt* pSchemaExt;
1493
  int8_t      virtualStb;
1494
  SColRef*    pColRefs;
1495
} STableCfg;
1496

1497
typedef STableCfg STableCfgRsp;
1498

1499
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1500
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1501

1502
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1503
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1504
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1505

1506
typedef struct {
1507
  SMsgHead header;
1508
  tb_uid_t suid;
1509
} SVSubTablesReq;
1510

1511
int32_t tSerializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1512
int32_t tDeserializeSVSubTablesReq(void* buf, int32_t bufLen, SVSubTablesReq* pReq);
1513

1514
typedef struct {
1515
  int32_t vgId;
1516
  SArray* pTables;  // SArray<SVCTableRefCols*>
1517
} SVSubTablesRsp;
1518

1519
int32_t tSerializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1520
int32_t tDeserializeSVSubTablesRsp(void* buf, int32_t bufLen, SVSubTablesRsp* pRsp);
1521
void    tDestroySVSubTablesRsp(void* rsp);
1522

1523
typedef struct {
1524
  SMsgHead header;
1525
  tb_uid_t suid;
1526
} SVStbRefDbsReq;
1527

1528
int32_t tSerializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1529
int32_t tDeserializeSVStbRefDbsReq(void* buf, int32_t bufLen, SVStbRefDbsReq* pReq);
1530

1531
typedef struct {
1532
  int32_t vgId;
1533
  SArray* pDbs;  // SArray<char* (db name)>
1534
} SVStbRefDbsRsp;
1535

1536
int32_t tSerializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1537
int32_t tDeserializeSVStbRefDbsRsp(void* buf, int32_t bufLen, SVStbRefDbsRsp* pRsp);
1538
void    tDestroySVStbRefDbsRsp(void* rsp);
1539

1540
typedef struct {
1541
  char    db[TSDB_DB_FNAME_LEN];
1542
  int32_t numOfVgroups;
1543
  int32_t numOfStables;  // single_stable
1544
  int32_t buffer;        // MB
1545
  int32_t pageSize;
1546
  int32_t pages;
1547
  int32_t cacheLastSize;
1548
  int32_t daysPerFile;
1549
  int32_t daysToKeep0;
1550
  int32_t daysToKeep1;
1551
  int32_t daysToKeep2;
1552
  int32_t keepTimeOffset;
1553
  int32_t minRows;
1554
  int32_t maxRows;
1555
  int32_t walFsyncPeriod;
1556
  int8_t  walLevel;
1557
  int8_t  precision;  // time resolution
1558
  int8_t  compression;
1559
  int8_t  replications;
1560
  int8_t  strict;
1561
  int8_t  cacheLast;
1562
  int8_t  schemaless;
1563
  int8_t  ignoreExist;
1564
  int32_t numOfRetensions;
1565
  SArray* pRetensions;  // SRetention
1566
  int32_t walRetentionPeriod;
1567
  int64_t walRetentionSize;
1568
  int32_t walRollPeriod;
1569
  int64_t walSegmentSize;
1570
  int32_t sstTrigger;
1571
  int16_t hashPrefix;
1572
  int16_t hashSuffix;
1573
  int32_t s3ChunkSize;
1574
  int32_t s3KeepLocal;
1575
  int8_t  s3Compact;
1576
  int32_t tsdbPageSize;
1577
  int32_t sqlLen;
1578
  char*   sql;
1579
  int8_t  withArbitrator;
1580
  int8_t  encryptAlgorithm;
1581
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1582
  // 1. add auto-compact parameters
1583
  int32_t compactInterval;    // minutes
1584
  int32_t compactStartTime;   // minutes
1585
  int32_t compactEndTime;     // minutes
1586
  int8_t  compactTimeOffset;  // hour
1587
} SCreateDbReq;
1588

1589
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1590
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1591
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1592

1593
typedef struct {
1594
  char    db[TSDB_DB_FNAME_LEN];
1595
  int32_t buffer;
1596
  int32_t pageSize;
1597
  int32_t pages;
1598
  int32_t cacheLastSize;
1599
  int32_t daysPerFile;
1600
  int32_t daysToKeep0;
1601
  int32_t daysToKeep1;
1602
  int32_t daysToKeep2;
1603
  int32_t keepTimeOffset;
1604
  int32_t walFsyncPeriod;
1605
  int8_t  walLevel;
1606
  int8_t  strict;
1607
  int8_t  cacheLast;
1608
  int8_t  replications;
1609
  int32_t sstTrigger;
1610
  int32_t minRows;
1611
  int32_t walRetentionPeriod;
1612
  int32_t walRetentionSize;
1613
  int32_t s3KeepLocal;
1614
  int8_t  s3Compact;
1615
  int32_t sqlLen;
1616
  char*   sql;
1617
  int8_t  withArbitrator;
1618
  // 1. add auto-compact parameters
1619
  int32_t compactInterval;
1620
  int32_t compactStartTime;
1621
  int32_t compactEndTime;
1622
  int8_t  compactTimeOffset;
1623
} SAlterDbReq;
1624

1625
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1626
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1627
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1628

1629
typedef struct {
1630
  char    db[TSDB_DB_FNAME_LEN];
1631
  int8_t  ignoreNotExists;
1632
  int32_t sqlLen;
1633
  char*   sql;
1634
} SDropDbReq;
1635

1636
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1637
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1638
void    tFreeSDropDbReq(SDropDbReq* pReq);
1639

1640
typedef struct {
1641
  char    db[TSDB_DB_FNAME_LEN];
1642
  int64_t uid;
1643
} SDropDbRsp;
1644

1645
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1646
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1647

1648
typedef struct {
1649
  char    db[TSDB_DB_FNAME_LEN];
1650
  int64_t dbId;
1651
  int32_t vgVersion;
1652
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1653
  int64_t stateTs;     // ms
1654
} SUseDbReq;
1655

1656
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1657
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1658

1659
typedef struct {
1660
  char    db[TSDB_DB_FNAME_LEN];
1661
  int64_t uid;
1662
  int32_t vgVersion;
1663
  int32_t vgNum;
1664
  int16_t hashPrefix;
1665
  int16_t hashSuffix;
1666
  int8_t  hashMethod;
1667
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1668
  int32_t errCode;
1669
  int64_t stateTs;  // ms
1670
} SUseDbRsp;
1671

1672
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1673
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1674
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1675
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1676
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1677

1678
typedef struct {
1679
  char db[TSDB_DB_FNAME_LEN];
1680
} SDbCfgReq;
1681

1682
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1683
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1684

1685
typedef struct {
1686
  char    db[TSDB_DB_FNAME_LEN];
1687
  int32_t maxSpeed;
1688
} STrimDbReq;
1689

1690
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1691
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1692

1693
typedef struct {
1694
  int32_t timestamp;
1695
} SVTrimDbReq;
1696

1697
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1698
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1699

1700
typedef struct {
1701
  char db[TSDB_DB_FNAME_LEN];
1702
} SS3MigrateDbReq;
1703

1704
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1705
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1706

1707
typedef struct {
1708
  int32_t timestamp;
1709
} SVS3MigrateDbReq;
1710

1711
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1712
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1713

1714
typedef struct {
1715
  int32_t timestampSec;
1716
  int32_t ttlDropMaxCount;
1717
  int32_t nUids;
1718
  SArray* pTbUids;
1719
} SVDropTtlTableReq;
1720

1721
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1722
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1723

1724
typedef struct {
1725
  char    db[TSDB_DB_FNAME_LEN];
1726
  int64_t dbId;
1727
  int32_t cfgVersion;
1728
  int32_t numOfVgroups;
1729
  int32_t numOfStables;
1730
  int32_t buffer;
1731
  int32_t cacheSize;
1732
  int32_t pageSize;
1733
  int32_t pages;
1734
  int32_t daysPerFile;
1735
  int32_t daysToKeep0;
1736
  int32_t daysToKeep1;
1737
  int32_t daysToKeep2;
1738
  int32_t keepTimeOffset;
1739
  int32_t minRows;
1740
  int32_t maxRows;
1741
  int32_t walFsyncPeriod;
1742
  int16_t hashPrefix;
1743
  int16_t hashSuffix;
1744
  int8_t  hashMethod;
1745
  int8_t  walLevel;
1746
  int8_t  precision;
1747
  int8_t  compression;
1748
  int8_t  replications;
1749
  int8_t  strict;
1750
  int8_t  cacheLast;
1751
  int8_t  encryptAlgorithm;
1752
  int32_t s3ChunkSize;
1753
  int32_t s3KeepLocal;
1754
  int8_t  s3Compact;
1755
  int8_t  compactTimeOffset;
1756
  int32_t compactInterval;
1757
  int32_t compactStartTime;
1758
  int32_t compactEndTime;
1759
  int32_t tsdbPageSize;
1760
  int32_t walRetentionPeriod;
1761
  int32_t walRollPeriod;
1762
  int64_t walRetentionSize;
1763
  int64_t walSegmentSize;
1764
  int32_t numOfRetensions;
1765
  SArray* pRetensions;
1766
  int8_t  schemaless;
1767
  int16_t sstTrigger;
1768
  int8_t  withArbitrator;
1769
} SDbCfgRsp;
1770

1771
typedef SDbCfgRsp SDbCfgInfo;
1772

1773
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1774
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1775
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1776
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1777
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1778

1779
typedef struct {
1780
  int32_t rowNum;
1781
} SQnodeListReq;
1782

1783
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1784
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1785

1786
typedef struct {
1787
  int32_t rowNum;
1788
} SDnodeListReq;
1789

1790
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1791

1792
typedef struct {
1793
  int32_t useless;  // useless
1794
} SServerVerReq;
1795

1796
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1797
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1798

1799
typedef struct {
1800
  char ver[TSDB_VERSION_LEN];
1801
} SServerVerRsp;
1802

1803
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1804
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1805

1806
typedef struct SQueryNodeAddr {
1807
  int32_t nodeId;  // vgId or qnodeId
1808
  SEpSet  epSet;
1809
} SQueryNodeAddr;
1810

1811
typedef struct {
1812
  SQueryNodeAddr addr;
1813
  uint64_t       load;
1814
} SQueryNodeLoad;
1815

1816
typedef struct {
1817
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1818
} SQnodeListRsp;
1819

1820
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1821
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1822
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1823

1824
typedef struct SDNodeAddr {
1825
  int32_t nodeId;  // dnodeId
1826
  SEpSet  epSet;
1827
} SDNodeAddr;
1828

1829
typedef struct {
1830
  SArray* dnodeList;  // SArray<SDNodeAddr>
1831
} SDnodeListRsp;
1832

1833
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1834
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1835
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1836

1837
typedef struct {
1838
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1839
} STableTSMAInfoRsp;
1840

1841
typedef struct {
1842
  SUseDbRsp*         useDbRsp;
1843
  SDbCfgRsp*         cfgRsp;
1844
  STableTSMAInfoRsp* pTsmaRsp;
1845
  int32_t            dbTsmaVersion;
1846
  char               db[TSDB_DB_FNAME_LEN];
1847
  int64_t            dbId;
1848
} SDbHbRsp;
1849

1850
typedef struct {
1851
  SArray* pArray;  // Array of SDbHbRsp
1852
} SDbHbBatchRsp;
1853

1854
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1855
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1856
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1857

1858
typedef struct {
1859
  SArray* pArray;  // Array of SGetUserAuthRsp
1860
} SUserAuthBatchRsp;
1861

1862
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1863
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1864
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1865

1866
typedef struct {
1867
  char        db[TSDB_DB_FNAME_LEN];
1868
  STimeWindow timeRange;
1869
  int32_t     sqlLen;
1870
  char*       sql;
1871
  SArray*     vgroupIds;
1872
  int8_t      metaOnly;
1873
} SCompactDbReq;
1874

1875
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1876
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1877
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1878

1879
typedef struct {
1880
  int32_t compactId;
1881
  int8_t  bAccepted;
1882
} SCompactDbRsp;
1883

1884
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1885
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1886

1887
typedef struct {
1888
  int32_t compactId;
1889
  int32_t sqlLen;
1890
  char*   sql;
1891
} SKillCompactReq;
1892

1893
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1894
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1895
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1896

1897
typedef struct {
1898
  char    name[TSDB_FUNC_NAME_LEN];
1899
  int8_t  igExists;
1900
  int8_t  funcType;
1901
  int8_t  scriptType;
1902
  int8_t  outputType;
1903
  int32_t outputLen;
1904
  int32_t bufSize;
1905
  int32_t codeLen;
1906
  int64_t signature;
1907
  char*   pComment;
1908
  char*   pCode;
1909
  int8_t  orReplace;
1910
} SCreateFuncReq;
1911

1912
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1913
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1914
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1915

1916
typedef struct {
1917
  char   name[TSDB_FUNC_NAME_LEN];
1918
  int8_t igNotExists;
1919
} SDropFuncReq;
1920

1921
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1922
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1923

1924
typedef struct {
1925
  int32_t numOfFuncs;
1926
  bool    ignoreCodeComment;
1927
  SArray* pFuncNames;
1928
} SRetrieveFuncReq;
1929

1930
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1931
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1932
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1933

1934
typedef struct {
1935
  char    name[TSDB_FUNC_NAME_LEN];
1936
  int8_t  funcType;
1937
  int8_t  scriptType;
1938
  int8_t  outputType;
1939
  int32_t outputLen;
1940
  int32_t bufSize;
1941
  int64_t signature;
1942
  int32_t commentSize;
1943
  int32_t codeSize;
1944
  char*   pComment;
1945
  char*   pCode;
1946
} SFuncInfo;
1947

1948
typedef struct {
1949
  int32_t funcVersion;
1950
  int64_t funcCreatedTime;
1951
} SFuncExtraInfo;
1952

1953
typedef struct {
1954
  int32_t numOfFuncs;
1955
  SArray* pFuncInfos;
1956
  SArray* pFuncExtraInfos;
1957
} SRetrieveFuncRsp;
1958

1959
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1960
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1961
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1962
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1963

1964
typedef struct {
1965
  int32_t       statusInterval;
1966
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
1967
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
1968
  char          locale[TD_LOCALE_LEN];      // tsLocale
1969
  char          charset[TD_LOCALE_LEN];     // tsCharset
1970
  int8_t        ttlChangeOnWrite;
1971
  int8_t        enableWhiteList;
1972
  int8_t        encryptionKeyStat;
1973
  uint32_t      encryptionKeyChksum;
1974
  SMonitorParas monitorParas;
1975
} SClusterCfg;
1976

1977
typedef struct {
1978
  int32_t openVnodes;
1979
  int32_t dropVnodes;
1980
  int32_t totalVnodes;
1981
  int32_t masterNum;
1982
  int64_t numOfSelectReqs;
1983
  int64_t numOfInsertReqs;
1984
  int64_t numOfInsertSuccessReqs;
1985
  int64_t numOfBatchInsertReqs;
1986
  int64_t numOfBatchInsertSuccessReqs;
1987
  int64_t errors;
1988
} SVnodesStat;
1989

1990
typedef struct {
1991
  int32_t vgId;
1992
  int8_t  syncState;
1993
  int8_t  syncRestore;
1994
  int64_t syncTerm;
1995
  int64_t roleTimeMs;
1996
  int64_t startTimeMs;
1997
  int8_t  syncCanRead;
1998
  int64_t cacheUsage;
1999
  int64_t numOfTables;
2000
  int64_t numOfTimeSeries;
2001
  int64_t totalStorage;
2002
  int64_t compStorage;
2003
  int64_t pointsWritten;
2004
  int64_t numOfSelectReqs;
2005
  int64_t numOfInsertReqs;
2006
  int64_t numOfInsertSuccessReqs;
2007
  int64_t numOfBatchInsertReqs;
2008
  int64_t numOfBatchInsertSuccessReqs;
2009
  int32_t numOfCachedTables;
2010
  int32_t learnerProgress;  // use one reservered
2011
  int64_t syncAppliedIndex;
2012
  int64_t syncCommitIndex;
2013
  int64_t bufferSegmentUsed;
2014
  int64_t bufferSegmentSize;
2015
} SVnodeLoad;
2016

2017
typedef struct {
2018
  int32_t     vgId;
2019
  int64_t     numOfTables;
2020
  int64_t     memSize;
2021
  int64_t     l1Size;
2022
  int64_t     l2Size;
2023
  int64_t     l3Size;
2024
  int64_t     cacheSize;
2025
  int64_t     walSize;
2026
  int64_t     metaSize;
2027
  int64_t     rawDataSize;
2028
  int64_t     s3Size;
2029
  const char* dbname;
2030
} SDbSizeStatisInfo;
2031

2032
typedef struct {
2033
  int32_t vgId;
2034
  int64_t nTimeSeries;
2035
} SVnodeLoadLite;
2036

2037
typedef struct {
2038
  int8_t  syncState;
2039
  int64_t syncTerm;
2040
  int8_t  syncRestore;
2041
  int64_t roleTimeMs;
2042
} SMnodeLoad;
2043

2044
typedef struct {
2045
  int32_t dnodeId;
2046
  int64_t numOfProcessedQuery;
2047
  int64_t numOfProcessedCQuery;
2048
  int64_t numOfProcessedFetch;
2049
  int64_t numOfProcessedDrop;
2050
  int64_t numOfProcessedNotify;
2051
  int64_t numOfProcessedHb;
2052
  int64_t numOfProcessedDelete;
2053
  int64_t cacheDataSize;
2054
  int64_t numOfQueryInQueue;
2055
  int64_t numOfFetchInQueue;
2056
  int64_t timeInQueryQueue;
2057
  int64_t timeInFetchQueue;
2058
} SQnodeLoad;
2059

2060
typedef struct {
2061
  int32_t     sver;      // software version
2062
  int64_t     dnodeVer;  // dnode table version in sdb
2063
  int32_t     dnodeId;
2064
  int64_t     clusterId;
2065
  int64_t     rebootTime;
2066
  int64_t     updateTime;
2067
  float       numOfCores;
2068
  int32_t     numOfSupportVnodes;
2069
  int32_t     numOfDiskCfg;
2070
  int64_t     memTotal;
2071
  int64_t     memAvail;
2072
  char        dnodeEp[TSDB_EP_LEN];
2073
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2074
  SMnodeLoad  mload;
2075
  SQnodeLoad  qload;
2076
  SClusterCfg clusterCfg;
2077
  SArray*     pVloads;  // array of SVnodeLoad
2078
  int32_t     statusSeq;
2079
  int64_t     ipWhiteVer;
2080
  int64_t     analVer;
2081
  int64_t     timestamp;
2082
} SStatusReq;
2083

2084
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2085
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2086
void    tFreeSStatusReq(SStatusReq* pReq);
2087

2088
typedef struct {
2089
  int32_t forceReadConfig;
2090
  int32_t cver;
2091
  SArray* array;
2092
} SConfigReq;
2093

2094
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2095
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2096
void    tFreeSConfigReq(SConfigReq* pReq);
2097

2098
typedef struct {
2099
  int32_t dnodeId;
2100
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2101
} SDnodeInfoReq;
2102

2103
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2104
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2105

2106
typedef enum {
2107
  MONITOR_TYPE_COUNTER = 0,
2108
  MONITOR_TYPE_SLOW_LOG = 1,
2109
} MONITOR_TYPE;
2110

2111
typedef struct {
2112
  int32_t      contLen;
2113
  char*        pCont;
2114
  MONITOR_TYPE type;
2115
} SStatisReq;
2116

2117
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2118
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2119
void    tFreeSStatisReq(SStatisReq* pReq);
2120

2121
typedef struct {
2122
  char    db[TSDB_DB_FNAME_LEN];
2123
  char    table[TSDB_TABLE_NAME_LEN];
2124
  char    operation[AUDIT_OPERATION_LEN];
2125
  int32_t sqlLen;
2126
  char*   pSql;
2127
} SAuditReq;
2128
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2129
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2130
void    tFreeSAuditReq(SAuditReq* pReq);
2131

2132
typedef struct {
2133
  int32_t dnodeId;
2134
  int64_t clusterId;
2135
  SArray* pVloads;
2136
} SNotifyReq;
2137

2138
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2139
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2140
void    tFreeSNotifyReq(SNotifyReq* pReq);
2141

2142
typedef struct {
2143
  int32_t dnodeId;
2144
  int64_t clusterId;
2145
} SDnodeCfg;
2146

2147
typedef struct {
2148
  int32_t id;
2149
  int8_t  isMnode;
2150
  SEp     ep;
2151
} SDnodeEp;
2152

2153
typedef struct {
2154
  int32_t id;
2155
  int8_t  isMnode;
2156
  int8_t  offlineReason;
2157
  SEp     ep;
2158
  char    active[TSDB_ACTIVE_KEY_LEN];
2159
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2160
} SDnodeInfo;
2161

2162
typedef struct {
2163
  int64_t   dnodeVer;
2164
  SDnodeCfg dnodeCfg;
2165
  SArray*   pDnodeEps;  // Array of SDnodeEp
2166
  int32_t   statusSeq;
2167
  int64_t   ipWhiteVer;
2168
  int64_t   analVer;
2169
} SStatusRsp;
2170

2171
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2172
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2173
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2174

2175
typedef struct {
2176
  int32_t forceReadConfig;
2177
  int32_t isConifgVerified;
2178
  int32_t isVersionVerified;
2179
  int32_t cver;
2180
  SArray* array;
2181
} SConfigRsp;
2182

2183
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2184
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2185
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2186

2187
typedef struct {
2188
  int32_t reserved;
2189
} SMTimerReq;
2190

2191
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2192
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2193

2194
typedef struct SOrphanTask {
2195
  int64_t streamId;
2196
  int32_t taskId;
2197
  int32_t nodeId;
2198
} SOrphanTask;
2199

2200
typedef struct SMStreamDropOrphanMsg {
2201
  SArray* pList;  // SArray<SOrphanTask>
2202
} SMStreamDropOrphanMsg;
2203

2204
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2205
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2206
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2207

2208
typedef struct {
2209
  int32_t  id;
2210
  uint16_t port;                 // node sync Port
2211
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2212
} SReplica;
2213

2214
typedef struct {
2215
  int32_t  vgId;
2216
  char     db[TSDB_DB_FNAME_LEN];
2217
  int64_t  dbUid;
2218
  int32_t  vgVersion;
2219
  int32_t  numOfStables;
2220
  int32_t  buffer;
2221
  int32_t  pageSize;
2222
  int32_t  pages;
2223
  int32_t  cacheLastSize;
2224
  int32_t  daysPerFile;
2225
  int32_t  daysToKeep0;
2226
  int32_t  daysToKeep1;
2227
  int32_t  daysToKeep2;
2228
  int32_t  keepTimeOffset;
2229
  int32_t  minRows;
2230
  int32_t  maxRows;
2231
  int32_t  walFsyncPeriod;
2232
  uint32_t hashBegin;
2233
  uint32_t hashEnd;
2234
  int8_t   hashMethod;
2235
  int8_t   walLevel;
2236
  int8_t   precision;
2237
  int8_t   compression;
2238
  int8_t   strict;
2239
  int8_t   cacheLast;
2240
  int8_t   isTsma;
2241
  int8_t   replica;
2242
  int8_t   selfIndex;
2243
  SReplica replicas[TSDB_MAX_REPLICA];
2244
  int32_t  numOfRetensions;
2245
  SArray*  pRetensions;  // SRetention
2246
  void*    pTsma;
2247
  int32_t  walRetentionPeriod;
2248
  int64_t  walRetentionSize;
2249
  int32_t  walRollPeriod;
2250
  int64_t  walSegmentSize;
2251
  int16_t  sstTrigger;
2252
  int16_t  hashPrefix;
2253
  int16_t  hashSuffix;
2254
  int32_t  tsdbPageSize;
2255
  int32_t  s3ChunkSize;
2256
  int32_t  s3KeepLocal;
2257
  int8_t   s3Compact;
2258
  int64_t  reserved[6];
2259
  int8_t   learnerReplica;
2260
  int8_t   learnerSelfIndex;
2261
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2262
  int32_t  changeVersion;
2263
  int8_t   encryptAlgorithm;
2264
} SCreateVnodeReq;
2265

2266
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2267
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2268
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2269

2270
typedef struct {
2271
  int32_t compactId;
2272
  int32_t vgId;
2273
  int32_t dnodeId;
2274
} SQueryCompactProgressReq;
2275

2276
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2277
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2278

2279
typedef struct {
2280
  int32_t compactId;
2281
  int32_t vgId;
2282
  int32_t dnodeId;
2283
  int32_t numberFileset;
2284
  int32_t finished;
2285
  int32_t progress;
2286
  int64_t remainingTime;
2287
} SQueryCompactProgressRsp;
2288

2289
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2290
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2291

2292
typedef struct {
2293
  int32_t vgId;
2294
  int32_t dnodeId;
2295
  int64_t dbUid;
2296
  char    db[TSDB_DB_FNAME_LEN];
2297
  int64_t reserved[8];
2298
} SDropVnodeReq;
2299

2300
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2301
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2302

2303
typedef struct {
2304
  char    colName[TSDB_COL_NAME_LEN];
2305
  char    stb[TSDB_TABLE_FNAME_LEN];
2306
  int64_t stbUid;
2307
  int64_t dbUid;
2308
  int64_t reserved[8];
2309
} SDropIndexReq;
2310

2311
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2312
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2313

2314
typedef struct {
2315
  int64_t     dbUid;
2316
  char        db[TSDB_DB_FNAME_LEN];
2317
  int64_t     compactStartTime;
2318
  STimeWindow tw;
2319
  int32_t     compactId;
2320
  int8_t      metaOnly;
2321
} SCompactVnodeReq;
2322

2323
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2324
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2325

2326
typedef struct {
2327
  int32_t compactId;
2328
  int32_t vgId;
2329
  int32_t dnodeId;
2330
} SVKillCompactReq;
2331

2332
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2333
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2334

2335
typedef struct {
2336
  int32_t vgVersion;
2337
  int32_t buffer;
2338
  int32_t pageSize;
2339
  int32_t pages;
2340
  int32_t cacheLastSize;
2341
  int32_t daysPerFile;
2342
  int32_t daysToKeep0;
2343
  int32_t daysToKeep1;
2344
  int32_t daysToKeep2;
2345
  int32_t keepTimeOffset;
2346
  int32_t walFsyncPeriod;
2347
  int8_t  walLevel;
2348
  int8_t  strict;
2349
  int8_t  cacheLast;
2350
  int64_t reserved[7];
2351
  // 1st modification
2352
  int16_t sttTrigger;
2353
  int32_t minRows;
2354
  // 2nd modification
2355
  int32_t walRetentionPeriod;
2356
  int32_t walRetentionSize;
2357
  int32_t s3KeepLocal;
2358
  int8_t  s3Compact;
2359
} SAlterVnodeConfigReq;
2360

2361
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2362
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2363

2364
typedef struct {
2365
  int32_t  vgId;
2366
  int8_t   strict;
2367
  int8_t   selfIndex;
2368
  int8_t   replica;
2369
  SReplica replicas[TSDB_MAX_REPLICA];
2370
  int64_t  reserved[8];
2371
  int8_t   learnerSelfIndex;
2372
  int8_t   learnerReplica;
2373
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2374
  int32_t  changeVersion;
2375
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2376

2377
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2378
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2379

2380
typedef struct {
2381
  int32_t vgId;
2382
  int8_t  disable;
2383
} SDisableVnodeWriteReq;
2384

2385
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2386
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2387

2388
typedef struct {
2389
  int32_t  srcVgId;
2390
  int32_t  dstVgId;
2391
  uint32_t hashBegin;
2392
  uint32_t hashEnd;
2393
  int32_t  changeVersion;
2394
  int32_t  reserved;
2395
} SAlterVnodeHashRangeReq;
2396

2397
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2398
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2399

2400
#define REQ_OPT_TBNAME 0x0
2401
#define REQ_OPT_TBUID  0x01
2402
typedef struct {
2403
  SMsgHead header;
2404
  char     dbFName[TSDB_DB_FNAME_LEN];
2405
  char     tbName[TSDB_TABLE_NAME_LEN];
2406
  uint8_t  option;
2407
  uint8_t  autoCreateCtb;
2408
} STableInfoReq;
2409

2410
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2411
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2412

2413
typedef struct {
2414
  int8_t  metaClone;  // create local clone of the cached table meta
2415
  int32_t numOfVgroups;
2416
  int32_t numOfTables;
2417
  int32_t numOfUdfs;
2418
  char    tableNames[];
2419
} SMultiTableInfoReq;
2420

2421
// todo refactor
2422
typedef struct SVgroupInfo {
2423
  int32_t  vgId;
2424
  uint32_t hashBegin;
2425
  uint32_t hashEnd;
2426
  SEpSet   epSet;
2427
  union {
2428
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2429
    int32_t taskId;      // used in stream
2430
  };
2431
} SVgroupInfo;
2432

2433
typedef struct {
2434
  int32_t     numOfVgroups;
2435
  SVgroupInfo vgroups[];
2436
} SVgroupsInfo;
2437

2438
typedef struct {
2439
  STableMetaRsp* pMeta;
2440
} SMAlterStbRsp;
2441

2442
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2443
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2444
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2445

2446
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2447
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2448
void    tFreeSTableMetaRsp(void* pRsp);
2449
void    tFreeSTableIndexRsp(void* info);
2450

2451
typedef struct {
2452
  SArray* pMetaRsp;   // Array of STableMetaRsp
2453
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2454
} SSTbHbRsp;
2455

2456
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2457
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2458
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2459

2460
typedef struct {
2461
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2462
} SViewHbRsp;
2463

2464
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2465
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2466
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2467

2468
typedef struct {
2469
  int32_t numOfTables;
2470
  int32_t numOfVgroup;
2471
  int32_t numOfUdf;
2472
  int32_t contLen;
2473
  int8_t  compressed;  // denote if compressed or not
2474
  int32_t rawLen;      // size before compress
2475
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2476
  char    meta[];
2477
} SMultiTableMeta;
2478

2479
typedef struct {
2480
  int32_t dataLen;
2481
  char    name[TSDB_TABLE_FNAME_LEN];
2482
  char*   data;
2483
} STagData;
2484

2485
typedef struct {
2486
  int32_t  opType;
2487
  uint32_t valLen;
2488
  char*    val;
2489
} SShowVariablesReq;
2490

2491
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2492
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2493
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2494

2495
typedef struct {
2496
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2497
  char value[TSDB_CONFIG_PATH_LEN + 1];
2498
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2499
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2500
  char info[TSDB_CONFIG_INFO_LEN + 1];
2501
} SVariablesInfo;
2502

2503
typedef struct {
2504
  SArray* variables;  // SArray<SVariablesInfo>
2505
} SShowVariablesRsp;
2506

2507
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2508
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2509

2510
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2511

2512
/*
2513
 * sql: show tables like '%a_%'
2514
 * payload is the query condition, e.g., '%a_%'
2515
 * payloadLen is the length of payload
2516
 */
2517
typedef struct {
2518
  int32_t type;
2519
  char    db[TSDB_DB_FNAME_LEN];
2520
  int32_t payloadLen;
2521
  char*   payload;
2522
} SShowReq;
2523

2524
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2525
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2526
void tFreeSShowReq(SShowReq* pReq);
2527

2528
typedef struct {
2529
  int64_t       showId;
2530
  STableMetaRsp tableMeta;
2531
} SShowRsp, SVShowTablesRsp;
2532

2533
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2534
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2535
// void    tFreeSShowRsp(SShowRsp* pRsp);
2536

2537
typedef struct {
2538
  char    db[TSDB_DB_FNAME_LEN];
2539
  char    tb[TSDB_TABLE_NAME_LEN];
2540
  char    user[TSDB_USER_LEN];
2541
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2542
  int64_t showId;
2543
  int64_t compactId;  // for compact
2544
  bool    withFull;   // for show users full
2545
} SRetrieveTableReq;
2546

2547
typedef struct SSysTableSchema {
2548
  int8_t   type;
2549
  col_id_t colId;
2550
  int32_t  bytes;
2551
} SSysTableSchema;
2552

2553
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2554
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2555

2556
#define RETRIEVE_TABLE_RSP_VERSION         0
2557
#define RETRIEVE_TABLE_RSP_TMQ_VERSION     1
2558
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION 2
2559

2560
typedef struct {
2561
  int64_t useconds;
2562
  int8_t  completed;  // all results are returned to client
2563
  int8_t  precision;
2564
  int8_t  compressed;
2565
  int8_t  streamBlockType;
2566
  int32_t payloadLen;
2567
  int32_t compLen;
2568
  int32_t numOfBlocks;
2569
  int64_t numOfRows;  // from int32_t change to int64_t
2570
  int64_t numOfCols;
2571
  int64_t skey;
2572
  int64_t ekey;
2573
  int64_t version;                         // for stream
2574
  TSKEY   watermark;                       // for stream
2575
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2576
  char    data[];
2577
} SRetrieveTableRsp;
2578

2579
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2580

2581
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2582
  do {                                          \
2583
    ((int32_t*)(_p))[0] = (_compLen);           \
2584
    ((int32_t*)(_p))[1] = (_fullLen);           \
2585
  } while (0);
2586

2587
typedef struct {
2588
  int64_t version;
2589
  int64_t numOfRows;
2590
  int8_t  compressed;
2591
  int8_t  precision;
2592
  char    data[];
2593
} SRetrieveTableRspForTmq;
2594

2595
typedef struct {
2596
  int64_t handle;
2597
  int64_t useconds;
2598
  int8_t  completed;  // all results are returned to client
2599
  int8_t  precision;
2600
  int8_t  compressed;
2601
  int32_t compLen;
2602
  int32_t numOfRows;
2603
  int32_t fullLen;
2604
  char    data[];
2605
} SRetrieveMetaTableRsp;
2606

2607
typedef struct SExplainExecInfo {
2608
  double   startupCost;
2609
  double   totalCost;
2610
  uint64_t numOfRows;
2611
  uint32_t verboseLen;
2612
  void*    verboseInfo;
2613
} SExplainExecInfo;
2614

2615
typedef struct {
2616
  int32_t           numOfPlans;
2617
  SExplainExecInfo* subplanInfo;
2618
} SExplainRsp;
2619

2620
typedef struct {
2621
  SExplainRsp rsp;
2622
  uint64_t    qId;
2623
  uint64_t    cId;
2624
  uint64_t    tId;
2625
  int64_t     rId;
2626
  int32_t     eId;
2627
} SExplainLocalRsp;
2628

2629
typedef struct STableScanAnalyzeInfo {
2630
  uint64_t totalRows;
2631
  uint64_t totalCheckedRows;
2632
  uint32_t totalBlocks;
2633
  uint32_t loadBlocks;
2634
  uint32_t loadBlockStatis;
2635
  uint32_t skipBlocks;
2636
  uint32_t filterOutBlocks;
2637
  double   elapsedTime;
2638
  double   filterTime;
2639
} STableScanAnalyzeInfo;
2640

2641
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2642
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2643
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2644

2645
typedef struct {
2646
  char    config[TSDB_DNODE_CONFIG_LEN];
2647
  char    value[TSDB_CLUSTER_VALUE_LEN];
2648
  int32_t sqlLen;
2649
  char*   sql;
2650
} SMCfgClusterReq;
2651

2652
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2653
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2654
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2655

2656
typedef struct {
2657
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2658
  int32_t port;
2659
  int32_t sqlLen;
2660
  char*   sql;
2661
} SCreateDnodeReq;
2662

2663
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2664
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2665
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2666

2667
typedef struct {
2668
  int32_t dnodeId;
2669
  char    fqdn[TSDB_FQDN_LEN];
2670
  int32_t port;
2671
  int8_t  force;
2672
  int8_t  unsafe;
2673
  int32_t sqlLen;
2674
  char*   sql;
2675
} SDropDnodeReq;
2676

2677
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2678
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2679
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2680

2681
enum {
2682
  RESTORE_TYPE__ALL = 1,
2683
  RESTORE_TYPE__MNODE,
2684
  RESTORE_TYPE__VNODE,
2685
  RESTORE_TYPE__QNODE,
2686
};
2687

2688
typedef struct {
2689
  int32_t dnodeId;
2690
  int8_t  restoreType;
2691
  int32_t sqlLen;
2692
  char*   sql;
2693
} SRestoreDnodeReq;
2694

2695
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2696
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2697
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2698

2699
typedef struct {
2700
  int32_t dnodeId;
2701
  char    config[TSDB_DNODE_CONFIG_LEN];
2702
  char    value[TSDB_DNODE_VALUE_LEN];
2703
  int32_t sqlLen;
2704
  char*   sql;
2705
} SMCfgDnodeReq;
2706

2707
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2708
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2709
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2710

2711
typedef struct {
2712
  char    config[TSDB_DNODE_CONFIG_LEN];
2713
  char    value[TSDB_DNODE_VALUE_LEN];
2714
  int32_t version;
2715
} SDCfgDnodeReq;
2716

2717
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2718
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2719

2720
typedef struct {
2721
  int32_t dnodeId;
2722
  int32_t sqlLen;
2723
  char*   sql;
2724
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2725
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2726

2727
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2728
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2729
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2730
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2731
typedef struct {
2732
  int8_t   replica;
2733
  SReplica replicas[TSDB_MAX_REPLICA];
2734
  int8_t   learnerReplica;
2735
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2736
  int64_t  lastIndex;
2737
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2738

2739
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2740
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2741

2742
typedef struct {
2743
  int32_t urlLen;
2744
  int32_t sqlLen;
2745
  char*   url;
2746
  char*   sql;
2747
} SMCreateAnodeReq;
2748

2749
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2750
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2751
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2752

2753
typedef struct {
2754
  int32_t anodeId;
2755
  int32_t sqlLen;
2756
  char*   sql;
2757
} SMDropAnodeReq, SMUpdateAnodeReq;
2758

2759
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2760
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2761
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2762
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2763
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2764
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2765

2766
typedef struct {
2767
  int32_t vgId;
2768
  int32_t hbSeq;
2769
} SVArbHbReqMember;
2770

2771
typedef struct {
2772
  int32_t dnodeId;
2773
  char*   arbToken;
2774
  int64_t arbTerm;
2775
  SArray* hbMembers;  // SVArbHbReqMember
2776
} SVArbHeartBeatReq;
2777

2778
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2779
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2780
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2781

2782
typedef struct {
2783
  int32_t vgId;
2784
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2785
  int32_t hbSeq;
2786
} SVArbHbRspMember;
2787

2788
typedef struct {
2789
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2790
  int32_t dnodeId;
2791
  SArray* hbMembers;  // SVArbHbRspMember
2792
} SVArbHeartBeatRsp;
2793

2794
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2795
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2796
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2797

2798
typedef struct {
2799
  char*   arbToken;
2800
  int64_t arbTerm;
2801
  char*   member0Token;
2802
  char*   member1Token;
2803
} SVArbCheckSyncReq;
2804

2805
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2806
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2807
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2808

2809
typedef struct {
2810
  char*   arbToken;
2811
  char*   member0Token;
2812
  char*   member1Token;
2813
  int32_t vgId;
2814
  int32_t errCode;
2815
} SVArbCheckSyncRsp;
2816

2817
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2818
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2819
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2820

2821
typedef struct {
2822
  char*   arbToken;
2823
  int64_t arbTerm;
2824
  char*   memberToken;
2825
  int8_t  force;
2826
} SVArbSetAssignedLeaderReq;
2827

2828
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2829
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2830
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2831

2832
typedef struct {
2833
  char*   arbToken;
2834
  char*   memberToken;
2835
  int32_t vgId;
2836
} SVArbSetAssignedLeaderRsp;
2837

2838
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2839
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2840
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2841

2842
typedef struct {
2843
  int32_t dnodeId;
2844
  char*   token;
2845
} SMArbUpdateGroupMember;
2846

2847
typedef struct {
2848
  int32_t dnodeId;
2849
  char*   token;
2850
  int8_t  acked;
2851
} SMArbUpdateGroupAssigned;
2852

2853
typedef struct {
2854
  int32_t                  vgId;
2855
  int64_t                  dbUid;
2856
  SMArbUpdateGroupMember   members[2];
2857
  int8_t                   isSync;
2858
  int8_t                   assignedAcked;
2859
  SMArbUpdateGroupAssigned assignedLeader;
2860
  int64_t                  version;
2861
  int32_t                  code;
2862
  int64_t                  updateTimeMs;
2863
} SMArbUpdateGroup;
2864

2865
typedef struct {
2866
  SArray* updateArray;  // SMArbUpdateGroup
2867
} SMArbUpdateGroupBatchReq;
2868

2869
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2870
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2871
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2872

2873
typedef struct {
2874
  char queryStrId[TSDB_QUERY_ID_LEN];
2875
} SKillQueryReq;
2876

2877
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2878
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2879

2880
typedef struct {
2881
  uint32_t connId;
2882
} SKillConnReq;
2883

2884
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2885
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2886

2887
typedef struct {
2888
  int32_t transId;
2889
} SKillTransReq;
2890

2891
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2892
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2893

2894
typedef struct {
2895
  int32_t useless;  // useless
2896
  int32_t sqlLen;
2897
  char*   sql;
2898
} SBalanceVgroupReq;
2899

2900
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2901
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2902
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2903

2904
typedef struct {
2905
  int32_t useless;  // useless
2906
  int32_t sqlLen;
2907
  char*   sql;
2908
} SAssignLeaderReq;
2909

2910
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2911
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2912
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
2913
typedef struct {
2914
  int32_t vgId1;
2915
  int32_t vgId2;
2916
} SMergeVgroupReq;
2917

2918
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2919
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2920

2921
typedef struct {
2922
  int32_t vgId;
2923
  int32_t dnodeId1;
2924
  int32_t dnodeId2;
2925
  int32_t dnodeId3;
2926
  int32_t sqlLen;
2927
  char*   sql;
2928
} SRedistributeVgroupReq;
2929

2930
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2931
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2932
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2933

2934
typedef struct {
2935
  int32_t reserved;
2936
  int32_t vgId;
2937
  int32_t sqlLen;
2938
  char*   sql;
2939
  char    db[TSDB_DB_FNAME_LEN];
2940
} SBalanceVgroupLeaderReq;
2941

2942
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2943
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2944
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2945

2946
typedef struct {
2947
  int32_t vgId;
2948
} SForceBecomeFollowerReq;
2949

2950
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2951
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2952

2953
typedef struct {
2954
  int32_t vgId;
2955
} SSplitVgroupReq;
2956

2957
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2958
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2959

2960
typedef struct {
2961
  char user[TSDB_USER_LEN];
2962
  char spi;
2963
  char encrypt;
2964
  char secret[TSDB_PASSWORD_LEN];
2965
  char ckey[TSDB_PASSWORD_LEN];
2966
} SAuthReq, SAuthRsp;
2967

2968
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2969
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2970

2971
typedef struct {
2972
  int32_t statusCode;
2973
  char    details[1024];
2974
} SServerStatusRsp;
2975

2976
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2977
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2978

2979
/**
2980
 * The layout of the query message payload is as following:
2981
 * +--------------------+---------------------------------+
2982
 * |Sql statement       | Physical plan                   |
2983
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2984
 * +--------------------+---------------------------------+
2985
 */
2986
typedef struct SSubQueryMsg {
2987
  SMsgHead header;
2988
  uint64_t sId;
2989
  uint64_t queryId;
2990
  uint64_t clientId;
2991
  uint64_t taskId;
2992
  int64_t  refId;
2993
  int32_t  execId;
2994
  int32_t  msgMask;
2995
  int8_t   taskType;
2996
  int8_t   explain;
2997
  int8_t   needFetch;
2998
  int8_t   compress;
2999
  uint32_t sqlLen;
3000
  char*    sql;
3001
  uint32_t msgLen;
3002
  char*    msg;
3003
} SSubQueryMsg;
3004

3005
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3006
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
3007
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
3008

3009
typedef struct {
3010
  SMsgHead header;
3011
  uint64_t sId;
3012
  uint64_t queryId;
3013
  uint64_t taskId;
3014
} SSinkDataReq;
3015

3016
typedef struct {
3017
  SMsgHead header;
3018
  uint64_t sId;
3019
  uint64_t queryId;
3020
  uint64_t clientId;
3021
  uint64_t taskId;
3022
  int32_t  execId;
3023
} SQueryContinueReq;
3024

3025
typedef struct {
3026
  SMsgHead header;
3027
  uint64_t sId;
3028
  uint64_t queryId;
3029
  uint64_t taskId;
3030
} SResReadyReq;
3031

3032
typedef struct {
3033
  int32_t code;
3034
  char    tbFName[TSDB_TABLE_FNAME_LEN];
3035
  int32_t sversion;
3036
  int32_t tversion;
3037
} SResReadyRsp;
3038

3039
typedef struct SOperatorParam {
3040
  int32_t opType;
3041
  int32_t downstreamIdx;
3042
  void*   value;
3043
  SArray* pChildren;  // SArray<SOperatorParam*>
3044
  bool    reUse;
3045
} SOperatorParam;
3046

3047
typedef struct SColIdNameKV {
3048
  col_id_t colId;
3049
  char     colName[TSDB_COL_NAME_LEN];
3050
} SColIdNameKV;
3051

3052
typedef struct SColIdPair {
3053
  col_id_t vtbColId;
3054
  col_id_t orgColId;
3055
} SColIdPair;
3056

3057
typedef struct SOrgTbInfo {
3058
  int32_t vgId;
3059
  char    tbName[TSDB_TABLE_FNAME_LEN];
3060
  SArray* colMap;  // SArray<SColIdNameKV>
3061
} SOrgTbInfo;
3062

3063
typedef struct STableScanOperatorParam {
3064
  bool        tableSeq;
3065
  SArray*     pUidList;
3066
  SOrgTbInfo* pOrgTbInfo;
3067
  STimeWindow window;
3068
} STableScanOperatorParam;
3069

3070
typedef struct SVTableScanOperatorParam {
3071
  uint64_t uid;
3072
  SArray*  pOpParamArray;  // SArray<SOperatorParam>
3073
} SVTableScanOperatorParam;
3074

3075
typedef struct {
3076
  SMsgHead        header;
3077
  uint64_t        sId;
3078
  uint64_t        queryId;
3079
  uint64_t        clientId;
3080
  uint64_t        taskId;
3081
  int32_t         execId;
3082
  SOperatorParam* pOpParam;
3083
} SResFetchReq;
3084

3085
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3086
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3087

3088
typedef struct {
3089
  SMsgHead header;
3090
  uint64_t clientId;
3091
} SSchTasksStatusReq;
3092

3093
typedef struct {
3094
  uint64_t queryId;
3095
  uint64_t clientId;
3096
  uint64_t taskId;
3097
  int64_t  refId;
3098
  int32_t  execId;
3099
  int8_t   status;
3100
} STaskStatus;
3101

3102
typedef struct {
3103
  int64_t refId;
3104
  SArray* taskStatus;  // SArray<STaskStatus>
3105
} SSchedulerStatusRsp;
3106

3107
typedef struct {
3108
  uint64_t queryId;
3109
  uint64_t taskId;
3110
  int8_t   action;
3111
} STaskAction;
3112

3113
typedef struct SQueryNodeEpId {
3114
  int32_t nodeId;  // vgId or qnodeId
3115
  SEp     ep;
3116
} SQueryNodeEpId;
3117

3118
typedef struct {
3119
  SMsgHead       header;
3120
  uint64_t       clientId;
3121
  SQueryNodeEpId epId;
3122
  SArray*        taskAction;  // SArray<STaskAction>
3123
} SSchedulerHbReq;
3124

3125
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3126
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3127
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3128

3129
typedef struct {
3130
  SQueryNodeEpId epId;
3131
  SArray*        taskStatus;  // SArray<STaskStatus>
3132
} SSchedulerHbRsp;
3133

3134
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3135
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3136
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3137

3138
typedef struct {
3139
  SMsgHead header;
3140
  uint64_t sId;
3141
  uint64_t queryId;
3142
  uint64_t clientId;
3143
  uint64_t taskId;
3144
  int64_t  refId;
3145
  int32_t  execId;
3146
} STaskCancelReq;
3147

3148
typedef struct {
3149
  int32_t code;
3150
} STaskCancelRsp;
3151

3152
typedef struct {
3153
  SMsgHead header;
3154
  uint64_t sId;
3155
  uint64_t queryId;
3156
  uint64_t clientId;
3157
  uint64_t taskId;
3158
  int64_t  refId;
3159
  int32_t  execId;
3160
} STaskDropReq;
3161

3162
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3163
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3164

3165
typedef enum {
3166
  TASK_NOTIFY_FINISHED = 1,
3167
} ETaskNotifyType;
3168

3169
typedef struct {
3170
  SMsgHead        header;
3171
  uint64_t        sId;
3172
  uint64_t        queryId;
3173
  uint64_t        clientId;
3174
  uint64_t        taskId;
3175
  int64_t         refId;
3176
  int32_t         execId;
3177
  ETaskNotifyType type;
3178
} STaskNotifyReq;
3179

3180
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3181
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3182

3183
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3184
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3185

3186
typedef struct {
3187
  int32_t code;
3188
} STaskDropRsp;
3189

3190
#define STREAM_TRIGGER_AT_ONCE                 1
3191
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3192
#define STREAM_TRIGGER_MAX_DELAY               3
3193
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3194
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3195

3196
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3197
#define STREAM_FILL_HISTORY_ON        1
3198
#define STREAM_FILL_HISTORY_OFF       0
3199
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3200
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3201
#define STREAM_CREATE_STABLE_TRUE     1
3202
#define STREAM_CREATE_STABLE_FALSE    0
3203

3204
typedef struct SColLocation {
3205
  int16_t  slotId;
3206
  col_id_t colId;
3207
  int8_t   type;
3208
} SColLocation;
3209

3210
typedef struct SVgroupVer {
3211
  int32_t vgId;
3212
  int64_t ver;
3213
} SVgroupVer;
3214

3215
typedef struct {
3216
  char    name[TSDB_STREAM_FNAME_LEN];
3217
  char    sourceDB[TSDB_DB_FNAME_LEN];
3218
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
3219
  char*   sql;
3220
  char*   ast;
3221
  int8_t  igExists;
3222
  int8_t  triggerType;
3223
  int8_t  igExpired;
3224
  int8_t  fillHistory;  // process data inserted before creating stream
3225
  int64_t maxDelay;
3226
  int64_t watermark;
3227
  int32_t numOfTags;
3228
  SArray* pTags;  // array of SField
3229
  // 3.0.20
3230
  int64_t checkpointFreq;  // ms
3231
  // 3.0.2.3
3232
  int8_t   createStb;
3233
  uint64_t targetStbUid;
3234
  SArray*  fillNullCols;  // array of SColLocation
3235
  int64_t  deleteMark;
3236
  int8_t   igUpdate;
3237
  int64_t  lastTs;
3238
  SArray*  pVgroupVerList;
3239
  // 3.3.0.0
3240
  SArray* pCols;  // array of SField
3241
  int64_t smaId;
3242
  // 3.3.6.0
3243
  SArray* pNotifyAddrUrls;
3244
  int32_t notifyEventTypes;
3245
  int32_t notifyErrorHandle;
3246
  int8_t  notifyHistory;
3247
  int64_t recalculateInterval;
3248
  char    pWstartName[TSDB_COL_NAME_LEN];
3249
  char    pWendName[TSDB_COL_NAME_LEN];
3250
  char    pGroupIdName[TSDB_COL_NAME_LEN];
3251
  char    pIsWindowFilledName[TSDB_COL_NAME_LEN];
3252
  SArray* pVSubTables;  // array of SVSubTablesRsp
3253
} SCMCreateStreamReq;
3254

3255
typedef struct STaskNotifyEventStat {
3256
  int64_t notifyEventAddTimes;     // call times of add function
3257
  int64_t notifyEventAddElems;     // elements added by add function
3258
  double  notifyEventAddCostSec;   // time cost of add function
3259
  int64_t notifyEventPushTimes;    // call times of push function
3260
  int64_t notifyEventPushElems;    // elements pushed by push function
3261
  double  notifyEventPushCostSec;  // time cost of push function
3262
  int64_t notifyEventPackTimes;    // call times of pack function
3263
  int64_t notifyEventPackElems;    // elements packed by pack function
3264
  double  notifyEventPackCostSec;  // time cost of pack function
3265
  int64_t notifyEventSendTimes;    // call times of send function
3266
  int64_t notifyEventSendElems;    // elements sent by send function
3267
  double  notifyEventSendCostSec;  // time cost of send function
3268
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3269
} STaskNotifyEventStat;
3270

3271
typedef struct {
3272
  int64_t streamId;
3273
} SCMCreateStreamRsp;
3274

3275
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3276
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3277
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3278

3279
enum {
3280
  TOPIC_SUB_TYPE__DB = 1,
3281
  TOPIC_SUB_TYPE__TABLE,
3282
  TOPIC_SUB_TYPE__COLUMN,
3283
};
3284

3285
#define DEFAULT_MAX_POLL_INTERVAL  300000
3286
#define DEFAULT_SESSION_TIMEOUT    12000
3287
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3288
#define DEFAULT_MIN_POLL_ROWS      4096
3289

3290
typedef struct {
3291
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3292
  int8_t igExists;
3293
  int8_t subType;
3294
  int8_t withMeta;
3295
  char*  sql;
3296
  char   subDbName[TSDB_DB_FNAME_LEN];
3297
  char*  ast;
3298
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3299
} SCMCreateTopicReq;
3300

3301
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3302
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3303
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3304

3305
typedef struct {
3306
  int64_t consumerId;
3307
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3308

3309
typedef struct {
3310
  int64_t consumerId;
3311
  char    cgroup[TSDB_CGROUP_LEN];
3312
  char    clientId[TSDB_CLIENT_ID_LEN];
3313
  char    user[TSDB_USER_LEN];
3314
  char    fqdn[TSDB_FQDN_LEN];
3315
  SArray* topicNames;  // SArray<char**>
3316

3317
  int8_t  withTbName;
3318
  int8_t  autoCommit;
3319
  int32_t autoCommitInterval;
3320
  int8_t  resetOffsetCfg;
3321
  int8_t  enableReplay;
3322
  int8_t  enableBatchMeta;
3323
  int32_t sessionTimeoutMs;
3324
  int32_t maxPollIntervalMs;
3325
} SCMSubscribeReq;
3326

3327
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3328
  int32_t tlen = 0;
2,488✔
3329
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,488!
3330
  tlen += taosEncodeString(buf, pReq->cgroup);
2,488✔
3331
  tlen += taosEncodeString(buf, pReq->clientId);
2,488✔
3332

3333
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,488!
3334
  tlen += taosEncodeFixedI32(buf, topicNum);
2,488✔
3335

3336
  for (int32_t i = 0; i < topicNum; i++) {
3,516✔
3337
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,056✔
3338
  }
3339

3340
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,488!
3341
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,488!
3342
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,488!
3343
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,488!
3344
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,488!
3345
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,488!
3346
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,488!
3347
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,488!
3348
  tlen += taosEncodeString(buf, pReq->user);
2,488✔
3349
  tlen += taosEncodeString(buf, pReq->fqdn);
2,488✔
3350

3351
  return tlen;
2,488✔
3352
}
3353

3354
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3355
  void* start = buf;
1,320✔
3356
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,320!
3357
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,320✔
3358
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,320✔
3359

3360
  int32_t topicNum = 0;
1,320!
3361
  buf = taosDecodeFixedI32(buf, &topicNum);
1,320✔
3362

3363
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,320✔
3364
  if (pReq->topicNames == NULL) {
1,320!
3365
    return terrno;
×
3366
  }
3367
  for (int32_t i = 0; i < topicNum; i++) {
1,925✔
3368
    char* name = NULL;
605✔
3369
    buf = taosDecodeString(buf, &name);
605✔
3370
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,210!
3371
      return terrno;
×
3372
    }
3373
  }
3374

3375
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,320✔
3376
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,320✔
3377
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,320!
3378
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,320✔
3379
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,320✔
3380
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,320✔
3381
  if ((char*)buf - (char*)start < len) {
1,320!
3382
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,320!
3383
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,320!
3384
    buf = taosDecodeStringTo(buf, pReq->user);
1,320✔
3385
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,640✔
3386
  } else {
3387
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3388
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3389
  }
3390

3391
  return 0;
1,320✔
3392
}
3393

3394
typedef struct {
3395
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3396
  SArray* removedConsumers;  // SArray<int64_t>
3397
  SArray* newConsumers;      // SArray<int64_t>
3398
} SMqRebInfo;
3399

3400
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3401
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,304!
3402
  if (pRebInfo == NULL) {
1,304!
3403
    return NULL;
×
3404
  }
3405
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,304✔
3406
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,304✔
3407
  if (pRebInfo->removedConsumers == NULL) {
1,304!
3408
    goto _err;
×
3409
  }
3410
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,304✔
3411
  if (pRebInfo->newConsumers == NULL) {
1,304!
3412
    goto _err;
×
3413
  }
3414
  return pRebInfo;
1,304✔
3415
_err:
×
3416
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3417
  taosArrayDestroy(pRebInfo->newConsumers);
×
3418
  taosMemoryFreeClear(pRebInfo);
×
3419
  return NULL;
×
3420
}
3421

3422
typedef struct {
3423
  int64_t streamId;
3424
  int64_t checkpointId;
3425
  char    streamName[TSDB_STREAM_FNAME_LEN];
3426
} SMStreamDoCheckpointMsg;
3427

3428
typedef struct {
3429
  int64_t status;
3430
} SMVSubscribeRsp;
3431

3432
typedef struct {
3433
  char    name[TSDB_TOPIC_FNAME_LEN];
3434
  int8_t  igNotExists;
3435
  int32_t sqlLen;
3436
  char*   sql;
3437
  int8_t  force;
3438
} SMDropTopicReq;
3439

3440
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3441
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3442
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3443

3444
typedef struct {
3445
  char   topic[TSDB_TOPIC_FNAME_LEN];
3446
  char   cgroup[TSDB_CGROUP_LEN];
3447
  int8_t igNotExists;
3448
  int8_t force;
3449
} SMDropCgroupReq;
3450

3451
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3452
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3453

3454
typedef struct {
3455
  int8_t reserved;
3456
} SMDropCgroupRsp;
3457

3458
typedef struct {
3459
  char    name[TSDB_TABLE_FNAME_LEN];
3460
  int8_t  alterType;
3461
  SSchema schema;
3462
} SAlterTopicReq;
3463

3464
typedef struct {
3465
  SMsgHead head;
3466
  char     name[TSDB_TABLE_FNAME_LEN];
3467
  int64_t  tuid;
3468
  int32_t  sverson;
3469
  int32_t  execLen;
3470
  char*    executor;
3471
  int32_t  sqlLen;
3472
  char*    sql;
3473
} SDCreateTopicReq;
3474

3475
typedef struct {
3476
  SMsgHead head;
3477
  char     name[TSDB_TABLE_FNAME_LEN];
3478
  int64_t  tuid;
3479
} SDDropTopicReq;
3480

3481
typedef struct {
3482
  int64_t maxdelay[2];
3483
  int64_t watermark[2];
3484
  int64_t deleteMark[2];
3485
  int32_t qmsgLen[2];
3486
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3487
} SRSmaParam;
3488

3489
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3490
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3491

3492
// TDMT_VND_CREATE_STB ==============
3493
typedef struct SVCreateStbReq {
3494
  char*           name;
3495
  tb_uid_t        suid;
3496
  int8_t          rollup;
3497
  SSchemaWrapper  schemaRow;
3498
  SSchemaWrapper  schemaTag;
3499
  SRSmaParam      rsmaParam;
3500
  int32_t         alterOriDataLen;
3501
  void*           alterOriData;
3502
  int8_t          source;
3503
  int8_t          colCmpred;
3504
  SColCmprWrapper colCmpr;
3505
  int64_t         keep;
3506
  SExtSchema*     pExtSchemas;
3507
  int8_t          virtualStb;
3508
} SVCreateStbReq;
3509

3510
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3511
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3512

3513
// TDMT_VND_DROP_STB ==============
3514
typedef struct SVDropStbReq {
3515
  char*    name;
3516
  tb_uid_t suid;
3517
} SVDropStbReq;
3518

3519
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3520
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3521

3522
// TDMT_VND_CREATE_TABLE ==============
3523
#define TD_CREATE_IF_NOT_EXISTS 0x1
3524
typedef struct SVCreateTbReq {
3525
  int32_t  flags;
3526
  char*    name;
3527
  tb_uid_t uid;
3528
  int64_t  btime;
3529
  int32_t  ttl;
3530
  int32_t  commentLen;
3531
  char*    comment;
3532
  int8_t   type;
3533
  union {
3534
    struct {
3535
      char*    stbName;  // super table name
3536
      uint8_t  tagNum;
3537
      tb_uid_t suid;
3538
      SArray*  tagName;
3539
      uint8_t* pTag;
3540
    } ctb;
3541
    struct {
3542
      SSchemaWrapper schemaRow;
3543
    } ntb;
3544
  };
3545
  int32_t         sqlLen;
3546
  char*           sql;
3547
  SColCmprWrapper colCmpr;
3548
  SExtSchema*     pExtSchemas;
3549
  SColRefWrapper  colRef;  // col reference for virtual table
3550
} SVCreateTbReq;
3551

3552
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3553
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3554
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3555

3556
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,156✔
3557
  if (NULL == req) {
23,136,802!
3558
    return;
22,792,069✔
3559
  }
3560

3561
  taosMemoryFreeClear(req->sql);
344,733!
3562
  taosMemoryFreeClear(req->name);
344,733!
3563
  taosMemoryFreeClear(req->comment);
344,873!
3564
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
344,873!
3565
    taosMemoryFreeClear(req->ctb.pTag);
328,305!
3566
    taosMemoryFreeClear(req->ctb.stbName);
328,389!
3567
    taosArrayDestroy(req->ctb.tagName);
328,384✔
3568
    req->ctb.tagName = NULL;
328,307✔
3569
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
16,568!
3570
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
16,568!
3571
  }
3572
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
344,875!
3573
  taosMemoryFreeClear(req->pExtSchemas);
344,875!
3574
  taosMemoryFreeClear(req->colRef.pColRef);
344,875!
3575
}
3576

3577
typedef struct {
3578
  int32_t nReqs;
3579
  union {
3580
    SVCreateTbReq* pReqs;
3581
    SArray*        pArray;
3582
  };
3583
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3584
} SVCreateTbBatchReq;
3585

3586
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3587
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3588
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3589

3590
typedef struct {
3591
  int32_t        code;
3592
  STableMetaRsp* pMeta;
3593
} SVCreateTbRsp, SVUpdateTbRsp;
3594

3595
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3596
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3597
void tFreeSVCreateTbRsp(void* param);
3598

3599
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3600
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3601

3602
typedef struct {
3603
  int32_t nRsps;
3604
  union {
3605
    SVCreateTbRsp* pRsps;
3606
    SArray*        pArray;
3607
  };
3608
} SVCreateTbBatchRsp;
3609

3610
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3611
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3612

3613
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3614
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3615

3616
// TDMT_VND_DROP_TABLE =================
3617
typedef struct {
3618
  char*    name;
3619
  uint64_t suid;  // for tmq in wal format
3620
  int64_t  uid;
3621
  int8_t   igNotExists;
3622
  int8_t   isVirtual;
3623
} SVDropTbReq;
3624

3625
typedef struct {
3626
  int32_t code;
3627
} SVDropTbRsp;
3628

3629
typedef struct {
3630
  int32_t nReqs;
3631
  union {
3632
    SVDropTbReq* pReqs;
3633
    SArray*      pArray;
3634
  };
3635
} SVDropTbBatchReq;
3636

3637
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3638
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3639

3640
typedef struct {
3641
  int32_t nRsps;
3642
  union {
3643
    SVDropTbRsp* pRsps;
3644
    SArray*      pArray;
3645
  };
3646
} SVDropTbBatchRsp;
3647

3648
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3649
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3650

3651
// TDMT_VND_ALTER_TABLE =====================
3652
typedef struct SMultiTagUpateVal {
3653
  char*    tagName;
3654
  int32_t  colId;
3655
  int8_t   tagType;
3656
  int8_t   tagFree;
3657
  uint32_t nTagVal;
3658
  uint8_t* pTagVal;
3659
  int8_t   isNull;
3660
  SArray*  pTagArray;
3661
} SMultiTagUpateVal;
3662
typedef struct SVAlterTbReq {
3663
  char*   tbName;
3664
  int8_t  action;
3665
  char*   colName;
3666
  int32_t colId;
3667
  // TSDB_ALTER_TABLE_ADD_COLUMN
3668
  int8_t  type;
3669
  int8_t  flags;
3670
  int32_t bytes;
3671
  // TSDB_ALTER_TABLE_DROP_COLUMN
3672
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3673
  int8_t   colModType;
3674
  int32_t  colModBytes;
3675
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3676
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3677
  int8_t   isNull;
3678
  int8_t   tagType;
3679
  int8_t   tagFree;
3680
  uint32_t nTagVal;
3681
  uint8_t* pTagVal;
3682
  SArray*  pTagArray;
3683
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3684
  int8_t   updateTTL;
3685
  int32_t  newTTL;
3686
  int32_t  newCommentLen;
3687
  char*    newComment;
3688
  int64_t  ctimeMs;    // fill by vnode
3689
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3690
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3691
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3692
  // for Add column
3693
  STypeMod typeMod;
3694
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3695
  char* refDbName;
3696
  char* refTbName;
3697
  char* refColName;
3698
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
3699
} SVAlterTbReq;
3700

3701
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3702
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3703
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3704
void    tfreeMultiTagUpateVal(void* pMultiTag);
3705

3706
typedef struct {
3707
  int32_t        code;
3708
  STableMetaRsp* pMeta;
3709
} SVAlterTbRsp;
3710

3711
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3712
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3713
// ======================
3714

3715
typedef struct {
3716
  SMsgHead head;
3717
  int64_t  uid;
3718
  int32_t  tid;
3719
  int16_t  tversion;
3720
  int16_t  colId;
3721
  int8_t   type;
3722
  int16_t  bytes;
3723
  int32_t  tagValLen;
3724
  int16_t  numOfTags;
3725
  int32_t  schemaLen;
3726
  char     data[];
3727
} SUpdateTagValReq;
3728

3729
typedef struct {
3730
  SMsgHead head;
3731
} SUpdateTagValRsp;
3732

3733
typedef struct {
3734
  SMsgHead head;
3735
} SVShowTablesReq;
3736

3737
typedef struct {
3738
  SMsgHead head;
3739
  int32_t  id;
3740
} SVShowTablesFetchReq;
3741

3742
typedef struct {
3743
  int64_t useconds;
3744
  int8_t  completed;  // all results are returned to client
3745
  int8_t  precision;
3746
  int8_t  compressed;
3747
  int32_t compLen;
3748
  int32_t numOfRows;
3749
  char    data[];
3750
} SVShowTablesFetchRsp;
3751

3752
typedef struct {
3753
  int64_t consumerId;
3754
  int32_t epoch;
3755
  char    cgroup[TSDB_CGROUP_LEN];
3756
} SMqAskEpReq;
3757

3758
typedef struct {
3759
  int32_t key;
3760
  int32_t valueLen;
3761
  void*   value;
3762
} SKv;
3763

3764
typedef struct {
3765
  int64_t tscRid;
3766
  int8_t  connType;
3767
} SClientHbKey;
3768

3769
typedef struct {
3770
  int64_t tid;
3771
  char    status[TSDB_JOB_STATUS_LEN];
3772
} SQuerySubDesc;
3773

3774
typedef struct {
3775
  char     sql[TSDB_SHOW_SQL_LEN];
3776
  uint64_t queryId;
3777
  int64_t  useconds;
3778
  int64_t  stime;  // timestamp precision ms
3779
  int64_t  reqRid;
3780
  bool     stableQuery;
3781
  bool     isSubQuery;
3782
  char     fqdn[TSDB_FQDN_LEN];
3783
  int32_t  subPlanNum;
3784
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3785
} SQueryDesc;
3786

3787
typedef struct {
3788
  uint32_t connId;
3789
  SArray*  queryDesc;  // SArray<SQueryDesc>
3790
} SQueryHbReqBasic;
3791

3792
typedef struct {
3793
  uint32_t connId;
3794
  uint64_t killRid;
3795
  int32_t  totalDnodes;
3796
  int32_t  onlineDnodes;
3797
  int8_t   killConnection;
3798
  int8_t   align[3];
3799
  SEpSet   epSet;
3800
  SArray*  pQnodeList;
3801
} SQueryHbRspBasic;
3802

3803
typedef struct SAppClusterSummary {
3804
  uint64_t numOfInsertsReq;
3805
  uint64_t numOfInsertRows;
3806
  uint64_t insertElapsedTime;
3807
  uint64_t insertBytes;  // submit to tsdb since launched.
3808

3809
  uint64_t fetchBytes;
3810
  uint64_t numOfQueryReq;
3811
  uint64_t queryElapsedTime;
3812
  uint64_t numOfSlowQueries;
3813
  uint64_t totalRequests;
3814
  uint64_t currentRequests;  // the number of SRequestObj
3815
} SAppClusterSummary;
3816

3817
typedef struct {
3818
  int64_t            appId;
3819
  int32_t            pid;
3820
  char               name[TSDB_APP_NAME_LEN];
3821
  int64_t            startTime;
3822
  SAppClusterSummary summary;
3823
} SAppHbReq;
3824

3825
typedef struct {
3826
  SClientHbKey      connKey;
3827
  int64_t           clusterId;
3828
  SAppHbReq         app;
3829
  SQueryHbReqBasic* query;
3830
  SHashObj*         info;  // hash<Skv.key, Skv>
3831
  char              userApp[TSDB_APP_NAME_LEN];
3832
  uint32_t          userIp;
3833
  SIpRange          userDualIp;
3834
} SClientHbReq;
3835

3836
typedef struct {
3837
  int64_t reqId;
3838
  SArray* reqs;  // SArray<SClientHbReq>
3839
  int64_t ipWhiteListVer;
3840
} SClientHbBatchReq;
3841

3842
typedef struct {
3843
  SClientHbKey      connKey;
3844
  int32_t           status;
3845
  SQueryHbRspBasic* query;
3846
  SArray*           info;  // Array<Skv>
3847
} SClientHbRsp;
3848

3849
typedef struct {
3850
  int64_t       reqId;
3851
  int64_t       rspId;
3852
  int32_t       svrTimestamp;
3853
  SArray*       rsps;  // SArray<SClientHbRsp>
3854
  SMonitorParas monitorParas;
3855
  int8_t        enableAuditDelete;
3856
  int8_t        enableStrongPass;
3857
} SClientHbBatchRsp;
3858

3859
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
337,422✔
3860

3861
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3862
  void* pIter = taosHashIterate(info, NULL);
413,153✔
3863
  while (pIter != NULL) {
700,572!
3864
    SKv* kv = (SKv*)pIter;
287,394✔
3865
    taosMemoryFreeClear(kv->value);
287,394!
3866
    pIter = taosHashIterate(info, pIter);
287,394✔
3867
  }
3868
}
413,178✔
3869

3870
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
313,645✔
3871
  SQueryDesc* desc = (SQueryDesc*)pDesc;
313,645✔
3872
  if (desc->subDesc) {
313,645✔
3873
    taosArrayDestroy(desc->subDesc);
303,848✔
3874
    desc->subDesc = NULL;
303,849✔
3875
  }
3876
}
313,646✔
3877

3878
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
518,261✔
3879
  SClientHbReq* req = (SClientHbReq*)pReq;
551,093✔
3880
  if (req->query) {
551,093!
3881
    if (req->query->queryDesc) {
504,131!
3882
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
57,784✔
3883
    }
3884
    taosMemoryFreeClear(req->query);
504,131!
3885
  }
3886

3887
  if (req->info) {
551,108!
3888
    tFreeReqKvHash(req->info);
413,153✔
3889
    taosHashCleanup(req->info);
413,178✔
3890
    req->info = NULL;
413,178✔
3891
  }
3892
}
396,416✔
3893

3894
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3895
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3896

3897
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3898
  if (pReq == NULL) return;
61,822!
3899
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
61,822✔
3900
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
61,822✔
3901
  taosMemoryFree(pReq);
61,822!
3902
}
3903

3904
static FORCE_INLINE void tFreeClientKv(void* pKv) {
105,886✔
3905
  SKv* kv = (SKv*)pKv;
105,886✔
3906
  if (kv) {
105,886!
3907
    taosMemoryFreeClear(kv->value);
105,887!
3908
  }
3909
}
105,886✔
3910

3911
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
514,658✔
3912
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
514,658✔
3913
  if (rsp->query) {
514,658✔
3914
    taosArrayDestroy(rsp->query->pQnodeList);
500,601✔
3915
    taosMemoryFreeClear(rsp->query);
500,642!
3916
  }
3917
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
514,721!
3918
}
151,148✔
3919

3920
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3921
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
292,936✔
3922
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
292,936✔
3923
}
292,964✔
3924

3925
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3926
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3927
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3928

3929
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3930
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
613,640!
3931
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
613,640!
3932
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
613,640!
3933
  return 0;
306,820✔
3934
}
3935

3936
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3937
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
479,711!
3938
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
479,712!
3939
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
239,856!
3940
  if (pKv->value == NULL) {
239,859!
3941
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3942
  }
3943
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
239,859!
3944
  return 0;
239,859✔
3945
}
3946

3947
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3948
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,071,246!
3949
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,071,246!
3950
  return 0;
1,035,623✔
3951
}
3952

3953
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3954
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,029,442!
3955
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,029,467!
3956
  return 0;
514,730✔
3957
}
3958

3959
typedef struct {
3960
  int32_t vgId;
3961
  // TODO stas
3962
} SMqReportVgInfo;
3963

3964
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3965
  int32_t tlen = 0;
3966
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3967
  return tlen;
3968
}
3969

3970
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3971
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3972
  return buf;
3973
}
3974

3975
typedef struct {
3976
  int32_t epoch;
3977
  int64_t topicUid;
3978
  char    name[TSDB_TOPIC_FNAME_LEN];
3979
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3980
} SMqTopicInfo;
3981

3982
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3983
  int32_t tlen = 0;
3984
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3985
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3986
  tlen += taosEncodeString(buf, pTopicInfo->name);
3987
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3988
  tlen += taosEncodeFixedI32(buf, sz);
3989
  for (int32_t i = 0; i < sz; i++) {
3990
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3991
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3992
  }
3993
  return tlen;
3994
}
3995

3996
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3997
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3998
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3999
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
4000
  int32_t sz;
4001
  buf = taosDecodeFixedI32(buf, &sz);
4002
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
4003
    return NULL;
4004
  }
4005
  for (int32_t i = 0; i < sz; i++) {
4006
    SMqReportVgInfo vgInfo;
4007
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
4008
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
4009
      return NULL;
4010
    }
4011
  }
4012
  return buf;
4013
}
4014

4015
typedef struct {
4016
  int32_t status;  // ask hb endpoint
4017
  int32_t epoch;
4018
  int64_t consumerId;
4019
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
4020
} SMqReportReq;
4021

4022
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
4023
  int32_t tlen = 0;
4024
  tlen += taosEncodeFixedI32(buf, pMsg->status);
4025
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
4026
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
4027
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
4028
  tlen += taosEncodeFixedI32(buf, sz);
4029
  for (int32_t i = 0; i < sz; i++) {
4030
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
4031
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
4032
  }
4033
  return tlen;
4034
}
4035

4036
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
4037
  buf = taosDecodeFixedI32(buf, &pMsg->status);
4038
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
4039
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
4040
  int32_t sz;
4041
  buf = taosDecodeFixedI32(buf, &sz);
4042
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
4043
    return NULL;
4044
  }
4045
  for (int32_t i = 0; i < sz; i++) {
4046
    SMqTopicInfo topicInfo;
4047
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
4048
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
4049
      return NULL;
4050
    }
4051
  }
4052
  return buf;
4053
}
4054

4055
typedef struct {
4056
  SMsgHead head;
4057
  int64_t  leftForVer;
4058
  int32_t  vgId;
4059
  int64_t  consumerId;
4060
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4061
} SMqVDeleteReq;
4062

4063
typedef struct {
4064
  int8_t reserved;
4065
} SMqVDeleteRsp;
4066

4067
typedef struct {
4068
  char    name[TSDB_STREAM_FNAME_LEN];
4069
  int8_t  igNotExists;
4070
  int32_t sqlLen;
4071
  char*   sql;
4072
} SMDropStreamReq;
4073

4074
typedef struct {
4075
  int8_t reserved;
4076
} SMDropStreamRsp;
4077

4078
typedef struct {
4079
  SMsgHead head;
4080
  int64_t  resetRelHalt;  // reset related stream task halt status
4081
  int64_t  streamId;
4082
  int32_t  taskId;
4083
} SVDropStreamTaskReq;
4084

4085
typedef struct {
4086
  int8_t reserved;
4087
} SVDropStreamTaskRsp;
4088

4089
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4090
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4091
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4092

4093
typedef struct SVUpdateCheckpointInfoReq {
4094
  SMsgHead head;
4095
  int64_t  streamId;
4096
  int32_t  taskId;
4097
  int64_t  checkpointId;
4098
  int64_t  checkpointVer;
4099
  int64_t  checkpointTs;
4100
  int32_t  transId;
4101
  int64_t  hStreamId;  // add encode/decode
4102
  int64_t  hTaskId;
4103
  int8_t   dropRelHTask;
4104
} SVUpdateCheckpointInfoReq;
4105

4106
typedef struct {
4107
  int64_t leftForVer;
4108
  int32_t vgId;
4109
  int64_t oldConsumerId;
4110
  int64_t newConsumerId;
4111
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4112
  int8_t  subType;
4113
  int8_t  withMeta;
4114
  char*   qmsg;  // SubPlanToString
4115
  int64_t suid;
4116
} SMqRebVgReq;
4117

4118
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4119
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4120

4121
typedef struct {
4122
  char    topic[TSDB_TOPIC_FNAME_LEN];
4123
  int64_t ntbUid;
4124
  SArray* colIdList;  // SArray<int16_t>
4125
} STqCheckInfo;
4126

4127
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4128
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4129
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4130

4131
// tqOffset
4132
enum {
4133
  TMQ_OFFSET__RESET_NONE = -3,
4134
  TMQ_OFFSET__RESET_EARLIEST = -2,
4135
  TMQ_OFFSET__RESET_LATEST = -1,
4136
  TMQ_OFFSET__LOG = 1,
4137
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4138
  TMQ_OFFSET__SNAPSHOT_META = 3,
4139
};
4140

4141
enum {
4142
  WITH_DATA = 0,
4143
  WITH_META = 1,
4144
  ONLY_META = 2,
4145
};
4146

4147
#define TQ_OFFSET_VERSION 1
4148

4149
typedef struct {
4150
  int8_t type;
4151
  union {
4152
    // snapshot
4153
    struct {
4154
      int64_t uid;
4155
      int64_t ts;
4156
      SValue  primaryKey;
4157
    };
4158
    // log
4159
    struct {
4160
      int64_t version;
4161
    };
4162
  };
4163
} STqOffsetVal;
4164

4165
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4166
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
26,011✔
4167
  pOffsetVal->uid = uid;
26,011✔
4168
  pOffsetVal->ts = ts;
26,011✔
4169
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
26,011!
4170
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4171
  }
4172
  pOffsetVal->primaryKey = primaryKey;
26,022✔
4173
}
26,022✔
4174

4175
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4176
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
148✔
4177
  pOffsetVal->uid = uid;
148✔
4178
}
148✔
4179

4180
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4181
  pOffsetVal->type = TMQ_OFFSET__LOG;
558,452✔
4182
  pOffsetVal->version = ver;
558,452✔
4183
}
558,452✔
4184

4185
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4186
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4187
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4188
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4189
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4190
void    tOffsetDestroy(void* pVal);
4191

4192
typedef struct {
4193
  STqOffsetVal val;
4194
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4195
} STqOffset;
4196

4197
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4198
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4199
void    tDeleteSTqOffset(void* val);
4200

4201
typedef struct SMqVgOffset {
4202
  int64_t   consumerId;
4203
  STqOffset offset;
4204
} SMqVgOffset;
4205

4206
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4207
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4208

4209
typedef struct {
4210
  SMsgHead head;
4211
  int64_t  streamId;
4212
  int32_t  taskId;
4213
} SVPauseStreamTaskReq;
4214

4215
typedef struct {
4216
  SMsgHead head;
4217
  int64_t  streamId;
4218
  int32_t  taskId;
4219
  int64_t  chkptId;
4220
} SVResetStreamTaskReq;
4221

4222
typedef struct {
4223
  char   name[TSDB_STREAM_FNAME_LEN];
4224
  int8_t igNotExists;
4225
} SMPauseStreamReq;
4226

4227
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4228
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4229

4230
typedef struct {
4231
  SMsgHead head;
4232
  int32_t  taskId;
4233
  int64_t  streamId;
4234
  int8_t   igUntreated;
4235
} SVResumeStreamTaskReq;
4236

4237
typedef struct {
4238
  int8_t reserved;
4239
} SVResumeStreamTaskRsp;
4240

4241
typedef struct {
4242
  char   name[TSDB_STREAM_FNAME_LEN];
4243
  int8_t igNotExists;
4244
  int8_t igUntreated;
4245
} SMResumeStreamReq;
4246

4247
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4248
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4249

4250
typedef struct {
4251
  char   name[TSDB_STREAM_FNAME_LEN];
4252
  int8_t igNotExists;
4253
  int8_t igUntreated;
4254
} SMResetStreamReq;
4255

4256
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
4257
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
4258

4259
typedef struct {
4260
  char    name[TSDB_TABLE_FNAME_LEN];
4261
  char    stb[TSDB_TABLE_FNAME_LEN];
4262
  int8_t  igExists;
4263
  int8_t  intervalUnit;
4264
  int8_t  slidingUnit;
4265
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4266
  int32_t dstVgId;   // for stream
4267
  int64_t interval;
4268
  int64_t offset;
4269
  int64_t sliding;
4270
  int64_t maxDelay;
4271
  int64_t watermark;
4272
  int32_t exprLen;        // strlen + 1
4273
  int32_t tagsFilterLen;  // strlen + 1
4274
  int32_t sqlLen;         // strlen + 1
4275
  int32_t astLen;         // strlen + 1
4276
  char*   expr;
4277
  char*   tagsFilter;
4278
  char*   sql;
4279
  char*   ast;
4280
  int64_t deleteMark;
4281
  int64_t lastTs;
4282
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4283
  SArray* pVgroupVerList;
4284
  int8_t  recursiveTsma;
4285
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4286
} SMCreateSmaReq;
4287

4288
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4289
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4290
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4291

4292
typedef struct {
4293
  char   name[TSDB_TABLE_FNAME_LEN];
4294
  int8_t igNotExists;
4295
} SMDropSmaReq;
4296

4297
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4298
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4299

4300
typedef struct {
4301
  char   dbFName[TSDB_DB_FNAME_LEN];
4302
  char   stbName[TSDB_TABLE_NAME_LEN];
4303
  char   colName[TSDB_COL_NAME_LEN];
4304
  char   idxName[TSDB_INDEX_FNAME_LEN];
4305
  int8_t idxType;
4306
} SCreateTagIndexReq;
4307

4308
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4309
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4310

4311
typedef SMDropSmaReq SDropTagIndexReq;
4312

4313
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4314
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4315

4316
typedef struct {
4317
  int8_t         version;       // for compatibility(default 0)
4318
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4319
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4320
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4321
  int32_t        dstVgId;
4322
  char           indexName[TSDB_INDEX_NAME_LEN];
4323
  int32_t        exprLen;
4324
  int32_t        tagsFilterLen;
4325
  int64_t        indexUid;
4326
  tb_uid_t       tableUid;  // super/child/common table uid
4327
  tb_uid_t       dstTbUid;  // for dstVgroup
4328
  int64_t        interval;
4329
  int64_t        offset;  // use unit by precision of DB
4330
  int64_t        sliding;
4331
  char*          dstTbName;  // for dstVgroup
4332
  char*          expr;       // sma expression
4333
  char*          tagsFilter;
4334
  SSchemaWrapper schemaRow;  // for dstVgroup
4335
  SSchemaWrapper schemaTag;  // for dstVgroup
4336
} STSma;                     // Time-range-wise SMA
4337

4338
typedef STSma SVCreateTSmaReq;
4339

4340
typedef struct {
4341
  int8_t  type;  // 0 status report, 1 update data
4342
  int64_t indexUid;
4343
  int64_t skey;  // start TS key of interval/sliding window
4344
} STSmaMsg;
4345

4346
typedef struct {
4347
  int64_t indexUid;
4348
  char    indexName[TSDB_INDEX_NAME_LEN];
4349
} SVDropTSmaReq;
4350

4351
typedef struct {
4352
  int tmp;  // TODO: to avoid compile error
4353
} SVCreateTSmaRsp, SVDropTSmaRsp;
4354

4355
#if 0
4356
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4357
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4358
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4359
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4360
#endif
4361

4362
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4363
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4364
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4365
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4366

4367
typedef struct {
4368
  int32_t number;
4369
  STSma*  tSma;
4370
} STSmaWrapper;
4371

4372
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4373
  if (pSma) {
×
4374
    taosMemoryFreeClear(pSma->dstTbName);
×
4375
    taosMemoryFreeClear(pSma->expr);
×
4376
    taosMemoryFreeClear(pSma->tagsFilter);
×
4377
  }
4378
}
×
4379

4380
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4381
  if (pSW) {
×
4382
    if (pSW->tSma) {
×
4383
      if (deepCopy) {
×
4384
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4385
          tDestroyTSma(pSW->tSma + i);
×
4386
        }
4387
      }
4388
      taosMemoryFreeClear(pSW->tSma);
×
4389
    }
4390
  }
4391
}
×
4392

4393
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4394
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4395
  taosMemoryFreeClear(pSW);
×
4396
  return NULL;
×
4397
}
4398

4399
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4400
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4401

4402
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4403
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4404

4405
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4406
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4407
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4408
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4409
  }
4410
  return 0;
×
4411
}
4412

4413
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4414
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4415
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4416
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4417
  }
4418
  return 0;
×
4419
}
4420

4421
typedef struct {
4422
  int idx;
4423
} SMCreateFullTextReq;
4424

4425
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4426
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4427
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4428

4429
typedef struct {
4430
  char   name[TSDB_TABLE_FNAME_LEN];
4431
  int8_t igNotExists;
4432
} SMDropFullTextReq;
4433

4434
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4435
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4436

4437
typedef struct {
4438
  char indexFName[TSDB_INDEX_FNAME_LEN];
4439
} SUserIndexReq;
4440

4441
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4442
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4443

4444
typedef struct {
4445
  char dbFName[TSDB_DB_FNAME_LEN];
4446
  char tblFName[TSDB_TABLE_FNAME_LEN];
4447
  char colName[TSDB_COL_NAME_LEN];
4448
  char indexType[TSDB_INDEX_TYPE_LEN];
4449
  char indexExts[TSDB_INDEX_EXTS_LEN];
4450
} SUserIndexRsp;
4451

4452
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4453
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4454

4455
typedef struct {
4456
  char tbFName[TSDB_TABLE_FNAME_LEN];
4457
} STableIndexReq;
4458

4459
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4460
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4461

4462
typedef struct {
4463
  int8_t  intervalUnit;
4464
  int8_t  slidingUnit;
4465
  int64_t interval;
4466
  int64_t offset;
4467
  int64_t sliding;
4468
  int64_t dstTbUid;
4469
  int32_t dstVgId;
4470
  SEpSet  epSet;
4471
  char*   expr;
4472
} STableIndexInfo;
4473

4474
typedef struct {
4475
  char     tbName[TSDB_TABLE_NAME_LEN];
4476
  char     dbFName[TSDB_DB_FNAME_LEN];
4477
  uint64_t suid;
4478
  int32_t  version;
4479
  int32_t  indexSize;
4480
  SArray*  pIndex;  // STableIndexInfo
4481
} STableIndexRsp;
4482

4483
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4484
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4485
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4486

4487
void tFreeSTableIndexInfo(void* pInfo);
4488

4489
typedef struct {
4490
  int8_t  mqMsgType;
4491
  int32_t code;
4492
  int32_t epoch;
4493
  int64_t consumerId;
4494
  int64_t walsver;
4495
  int64_t walever;
4496
} SMqRspHead;
4497

4498
typedef struct {
4499
  SMsgHead     head;
4500
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4501
  int8_t       withTbName;
4502
  int8_t       useSnapshot;
4503
  int32_t      epoch;
4504
  uint64_t     reqId;
4505
  int64_t      consumerId;
4506
  int64_t      timeout;
4507
  STqOffsetVal reqOffset;
4508
  int8_t       enableReplay;
4509
  int8_t       sourceExcluded;
4510
  int8_t       rawData;
4511
  int32_t      minPollRows;
4512
  int8_t       enableBatchMeta;
4513
  SHashObj*    uidHash;  // to find if uid is duplicated
4514
} SMqPollReq;
4515

4516
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4517
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4518
void    tDestroySMqPollReq(SMqPollReq* pReq);
4519

4520
typedef struct {
4521
  int32_t vgId;
4522
  int64_t offset;
4523
  SEpSet  epSet;
4524
} SMqSubVgEp;
4525

4526
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4527
  int32_t tlen = 0;
8,398✔
4528
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,398✔
4529
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,398✔
4530
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,398✔
4531
  return tlen;
8,398✔
4532
}
4533

4534
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4535
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,121!
4536
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,121!
4537
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,121✔
4538
  return buf;
4,121✔
4539
}
4540

4541
typedef struct {
4542
  char           topic[TSDB_TOPIC_FNAME_LEN];
4543
  char           db[TSDB_DB_FNAME_LEN];
4544
  SArray*        vgs;  // SArray<SMqSubVgEp>
4545
  SSchemaWrapper schema;
4546
} SMqSubTopicEp;
4547

4548
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4549
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4550
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4551

4552
typedef struct {
4553
  SMqRspHead   head;
4554
  STqOffsetVal rspOffset;
4555
  int16_t      resMsgType;
4556
  int32_t      metaRspLen;
4557
  void*        metaRsp;
4558
} SMqMetaRsp;
4559

4560
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4561
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4562
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4563

4564
#define MQ_DATA_RSP_VERSION 100
4565

4566
typedef struct {
4567
  SMqRspHead   head;
4568
  STqOffsetVal rspOffset;
4569
  STqOffsetVal reqOffset;
4570
  int32_t      blockNum;
4571
  int8_t       withTbName;
4572
  int8_t       withSchema;
4573
  SArray*      blockDataLen;
4574
  SArray*      blockData;
4575
  SArray*      blockTbName;
4576
  SArray*      blockSchema;
4577

4578
  union {
4579
    struct {
4580
      int64_t sleepTime;
4581
    };
4582
    struct {
4583
      int32_t createTableNum;
4584
      SArray* createTableLen;
4585
      SArray* createTableReq;
4586
    };
4587
    struct {
4588
      int32_t len;
4589
      void*   rawData;
4590
    };
4591
  };
4592
  void* data;                  // for free in client, only effected if type is data or metadata. raw data not effected
4593
  bool  blockDataElementFree;  // if true, free blockDataElement in blockData,(true in server, false in client)
4594
} SMqDataRsp;
4595

4596
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4597
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4598
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4599
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4600
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4601

4602
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4603
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4604
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4605

4606
typedef struct SMqBatchMetaRsp {
4607
  SMqRspHead   head;  // not serialize
4608
  STqOffsetVal rspOffset;
4609
  SArray*      batchMetaLen;
4610
  SArray*      batchMetaReq;
4611
  void*        pMetaBuff;    // not serialize
4612
  uint32_t     metaBuffLen;  // not serialize
4613
} SMqBatchMetaRsp;
4614

4615
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4616
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4617
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4618
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4619

4620
typedef struct {
4621
  SMqRspHead head;
4622
  char       cgroup[TSDB_CGROUP_LEN];
4623
  SArray*    topics;  // SArray<SMqSubTopicEp>
4624
} SMqAskEpRsp;
4625

4626
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4627
  int32_t tlen = 0;
16,830✔
4628
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4629
  int32_t sz = taosArrayGetSize(pRsp->topics);
16,830!
4630
  tlen += taosEncodeFixedI32(buf, sz);
16,830✔
4631
  for (int32_t i = 0; i < sz; i++) {
23,474✔
4632
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,644✔
4633
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,644✔
4634
  }
4635
  return tlen;
16,830✔
4636
}
4637

4638
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4639
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4640
  int32_t sz;
4641
  buf = taosDecodeFixedI32(buf, &sz);
8,119✔
4642
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,119✔
4643
  if (pRsp->topics == NULL) {
8,119!
4644
    return NULL;
×
4645
  }
4646
  for (int32_t i = 0; i < sz; i++) {
11,352✔
4647
    SMqSubTopicEp topicEp;
4648
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,233✔
4649
    if (buf == NULL) {
3,233!
4650
      return NULL;
×
4651
    }
4652
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,466!
4653
      return NULL;
×
4654
    }
4655
  }
4656
  return buf;
8,119✔
4657
}
4658

4659
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4660
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
19,537✔
4661
}
19,537✔
4662

4663
typedef struct {
4664
  int32_t      vgId;
4665
  STqOffsetVal offset;
4666
  int64_t      rows;
4667
  int64_t      ever;
4668
} OffsetRows;
4669

4670
typedef struct {
4671
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4672
  SArray* offsetRows;
4673
} TopicOffsetRows;
4674

4675
typedef struct {
4676
  int64_t consumerId;
4677
  int32_t epoch;
4678
  SArray* topics;
4679
  int8_t  pollFlag;
4680
} SMqHbReq;
4681

4682
typedef struct {
4683
  char   topic[TSDB_TOPIC_FNAME_LEN];
4684
  int8_t noPrivilege;
4685
} STopicPrivilege;
4686

4687
typedef struct {
4688
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4689
  int32_t debugFlag;
4690
} SMqHbRsp;
4691

4692
typedef struct {
4693
  SMsgHead head;
4694
  int64_t  consumerId;
4695
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4696
} SMqSeekReq;
4697

4698
#define TD_AUTO_CREATE_TABLE 0x1
4699
typedef struct {
4700
  int64_t       suid;
4701
  int64_t       uid;
4702
  int32_t       sver;
4703
  uint32_t      nData;
4704
  uint8_t*      pData;
4705
  SVCreateTbReq cTbReq;
4706
} SVSubmitBlk;
4707

4708
typedef struct {
4709
  SMsgHead header;
4710
  uint64_t sId;
4711
  uint64_t queryId;
4712
  uint64_t clientId;
4713
  uint64_t taskId;
4714
  uint32_t sqlLen;
4715
  uint32_t phyLen;
4716
  char*    sql;
4717
  char*    msg;
4718
  int8_t   source;
4719
} SVDeleteReq;
4720

4721
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4722
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4723

4724
typedef struct {
4725
  int64_t affectedRows;
4726
} SVDeleteRsp;
4727

4728
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4729
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4730

4731
typedef struct SDeleteRes {
4732
  uint64_t suid;
4733
  SArray*  uidList;
4734
  int64_t  skey;
4735
  int64_t  ekey;
4736
  int64_t  affectedRows;
4737
  char     tableFName[TSDB_TABLE_NAME_LEN];
4738
  char     tsColName[TSDB_COL_NAME_LEN];
4739
  int64_t  ctimeMs;  // fill by vnode
4740
  int8_t   source;
4741
} SDeleteRes;
4742

4743
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4744
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4745

4746
typedef struct {
4747
  // int64_t uid;
4748
  char    tbname[TSDB_TABLE_NAME_LEN];
4749
  int64_t startTs;
4750
  int64_t endTs;
4751
} SSingleDeleteReq;
4752

4753
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4754
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4755

4756
typedef struct {
4757
  int64_t suid;
4758
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4759
  int64_t ctimeMs;     // fill by vnode
4760
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4761
} SBatchDeleteReq;
4762

4763
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4764
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4765
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4766

4767
typedef struct {
4768
  int32_t msgIdx;
4769
  int32_t msgType;
4770
  int32_t msgLen;
4771
  void*   msg;
4772
} SBatchMsg;
4773

4774
typedef struct {
4775
  SMsgHead header;
4776
  SArray*  pMsgs;  // SArray<SBatchMsg>
4777
} SBatchReq;
4778

4779
typedef struct {
4780
  int32_t reqType;
4781
  int32_t msgIdx;
4782
  int32_t msgLen;
4783
  int32_t rspCode;
4784
  void*   msg;
4785
} SBatchRspMsg;
4786

4787
typedef struct {
4788
  SArray* pRsps;  // SArray<SBatchRspMsg>
4789
} SBatchRsp;
4790

4791
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4792
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4793
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
9,632,421✔
4794
  if (NULL == msg) {
9,632,421!
4795
    return;
×
4796
  }
4797
  SBatchMsg* pMsg = (SBatchMsg*)msg;
9,632,421✔
4798
  taosMemoryFree(pMsg->msg);
9,632,421!
4799
}
4800

4801
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4802
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4803

4804
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
2,596,267✔
4805
  if (NULL == p) {
2,596,267!
4806
    return;
×
4807
  }
4808

4809
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
2,596,267✔
4810
  taosMemoryFree(pRsp->msg);
2,596,267!
4811
}
4812

4813
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4814
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4815
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4816
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4817
void    tDestroySMqHbReq(SMqHbReq* pReq);
4818

4819
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4820
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4821
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4822

4823
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4824
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4825

4826
#define TD_REQ_FROM_APP               0x0
4827
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4828
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4829
#define SUBMIT_REQ_FROM_FILE          0x4
4830
#define TD_REQ_FROM_TAOX              0x8
4831
#define SUBMIT_REQUEST_VERSION        (1)
4832

4833
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4834

4835
typedef struct {
4836
  int32_t        flags;
4837
  SVCreateTbReq* pCreateTbReq;
4838
  int64_t        suid;
4839
  int64_t        uid;
4840
  int32_t        sver;
4841
  union {
4842
    SArray* aRowP;
4843
    SArray* aCol;
4844
  };
4845
  int64_t ctimeMs;
4846
} SSubmitTbData;
4847

4848
typedef struct {
4849
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4850
  bool    raw;
4851
} SSubmitReq2;
4852

4853
typedef struct {
4854
  SMsgHead header;
4855
  int64_t  version;
4856
  char     data[];  // SSubmitReq2
4857
} SSubmitReq2Msg;
4858

4859
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4860
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4861
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4862
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4863
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4864

4865
typedef struct {
4866
  int32_t affectedRows;
4867
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4868
} SSubmitRsp2;
4869

4870
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4871
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4872
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4873

4874
#define TSDB_MSG_FLG_ENCODE 0x1
4875
#define TSDB_MSG_FLG_DECODE 0x2
4876
#define TSDB_MSG_FLG_CMPT   0x3
4877

4878
typedef struct {
4879
  union {
4880
    struct {
4881
      void*   msgStr;
4882
      int32_t msgLen;
4883
      int64_t ver;
4884
    };
4885
    void* pDataBlock;
4886
  };
4887
} SPackedData;
4888

4889
typedef struct {
4890
  char     fullname[TSDB_VIEW_FNAME_LEN];
4891
  char     name[TSDB_VIEW_NAME_LEN];
4892
  char     dbFName[TSDB_DB_FNAME_LEN];
4893
  char*    querySql;
4894
  char*    sql;
4895
  int8_t   orReplace;
4896
  int8_t   precision;
4897
  int32_t  numOfCols;
4898
  SSchema* pSchema;
4899
} SCMCreateViewReq;
4900

4901
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4902
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4903
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4904

4905
typedef struct {
4906
  char   fullname[TSDB_VIEW_FNAME_LEN];
4907
  char   name[TSDB_VIEW_NAME_LEN];
4908
  char   dbFName[TSDB_DB_FNAME_LEN];
4909
  char*  sql;
4910
  int8_t igNotExists;
4911
} SCMDropViewReq;
4912

4913
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4914
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4915
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4916

4917
typedef struct {
4918
  char fullname[TSDB_VIEW_FNAME_LEN];
4919
} SViewMetaReq;
4920
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4921
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4922

4923
typedef struct {
4924
  char     name[TSDB_VIEW_NAME_LEN];
4925
  char     dbFName[TSDB_DB_FNAME_LEN];
4926
  char*    user;
4927
  uint64_t dbId;
4928
  uint64_t viewId;
4929
  char*    querySql;
4930
  int8_t   precision;
4931
  int8_t   type;
4932
  int32_t  version;
4933
  int32_t  numOfCols;
4934
  SSchema* pSchema;
4935
} SViewMetaRsp;
4936
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4937
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4938
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4939
typedef struct {
4940
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4941
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4942
} STableTSMAInfoReq;
4943

4944
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4945
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4946

4947
typedef struct {
4948
  int32_t  funcId;
4949
  col_id_t colId;
4950
} STableTSMAFuncInfo;
4951

4952
typedef struct {
4953
  char     name[TSDB_TABLE_NAME_LEN];
4954
  uint64_t tsmaId;
4955
  char     targetTb[TSDB_TABLE_NAME_LEN];
4956
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4957
  char     tb[TSDB_TABLE_NAME_LEN];
4958
  char     dbFName[TSDB_DB_FNAME_LEN];
4959
  uint64_t suid;
4960
  uint64_t destTbUid;
4961
  uint64_t dbId;
4962
  int32_t  version;
4963
  int64_t  interval;
4964
  int8_t   unit;
4965
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4966
  SArray*  pTags;      // SArray<SSchema>
4967
  SArray*  pUsedCols;  // SArray<SSchema>
4968
  char*    ast;
4969

4970
  int64_t streamUid;
4971
  int64_t reqTs;
4972
  int64_t rspTs;
4973
  int64_t delayDuration;  // ms
4974
  bool    fillHistoryFinished;
4975
} STableTSMAInfo;
4976

4977
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4978
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4979
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4980
void    tFreeTableTSMAInfo(void* p);
4981
void    tFreeAndClearTableTSMAInfo(void* p);
4982
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4983

4984
#define STSMAHbRsp            STableTSMAInfoRsp
4985
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4986
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4987
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4988

4989
typedef struct SStreamProgressReq {
4990
  int64_t streamId;
4991
  int32_t vgId;
4992
  int32_t fetchIdx;
4993
  int32_t subFetchIdx;
4994
} SStreamProgressReq;
4995

4996
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4997
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4998

4999
typedef struct SStreamProgressRsp {
5000
  int64_t streamId;
5001
  int32_t vgId;
5002
  bool    fillHisFinished;
5003
  int64_t progressDelay;
5004
  int32_t fetchIdx;
5005
  int32_t subFetchIdx;
5006
} SStreamProgressRsp;
5007

5008
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
5009
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
5010

5011
typedef struct SDropCtbWithTsmaSingleVgReq {
5012
  SVgroupInfo vgInfo;
5013
  SArray*     pTbs;  // SVDropTbReq
5014
} SMDropTbReqsOnSingleVg;
5015

5016
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
5017
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
5018
void    tFreeSMDropTbReqOnSingleVg(void* p);
5019

5020
typedef struct SDropTbsReq {
5021
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
5022
} SMDropTbsReq;
5023

5024
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
5025
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
5026
void    tFreeSMDropTbsReq(void*);
5027

5028
typedef struct SVFetchTtlExpiredTbsRsp {
5029
  SArray* pExpiredTbs;  // SVDropTbReq
5030
  int32_t vgId;
5031
} SVFetchTtlExpiredTbsRsp;
5032

5033
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
5034
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
5035

5036
void tFreeFetchTtlExpiredTbsRsp(void* p);
5037

5038
void setDefaultOptionsForField(SFieldWithOptions* field);
5039
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
5040

5041
#pragma pack(pop)
5042

5043
#ifdef __cplusplus
5044
}
5045
#endif
5046

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