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

taosdata / TDengine / #3818

01 Apr 2025 07:46AM UTC coverage: 34.065% (-0.02%) from 34.08%
#3818

push

travis-ci

happyguoxy
test:alter gcda dir

148531 of 599532 branches covered (24.77%)

Branch coverage included in aggregate %.

222425 of 489446 relevant lines covered (45.44%)

762721.74 hits per line

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

33.56
/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) {
1,117,534✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
1,117,534✔
74
  int    segIdx = TMSG_SEG_CODE(type);
1,117,534✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
1,117,534✔
76
    return type < tMsgRangeDict[segIdx];
1,117,666✔
77
  }
78
  return false;
×
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
257,174✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
255,722!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
512,896✔
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
322,607✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
322,607✔
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
  uint64_t    suid;
692
  uint64_t    tuid;
693
  int32_t     vgId;
694
  int8_t      sysInfo;
695
  SSchema*    pSchemas;
696
  SSchemaExt* pSchemaExt;
697
  int8_t      virtualStb;
698
  int32_t     numOfColRefs;
699
  SColRef*    pColRefs;
700
} STableMetaRsp;
701

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

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

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

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

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

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

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

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

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

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

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

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

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

779
bool hasExtSchema(const SExtSchema* pExtSchema);
780

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

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

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

798

799
static FORCE_INLINE int32_t tInitDefaultSColRefWrapperByCols(SColRefWrapper* pRef, int32_t nCols) {
800
  if (pRef->pColRef) {
×
801
    return TSDB_CODE_INVALID_PARA;
×
802
  }
803
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
×
804
  if (pRef->pColRef == NULL) {
×
805
    return terrno;
×
806
  }
807
  pRef->nCols = nCols;
×
808
  for (int32_t i = 0; i < nCols; i++) {
×
809
    pRef->pColRef[i].hasRef = false;
×
810
    pRef->pColRef[i].id = (col_id_t)(i + 1);
×
811
  }
812
  return 0;
×
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)) {
83!
841
    return TSDB_CODE_INVALID_PARA;
×
842
  }
843
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
83!
844
  if (pCmpr->pColCmpr == NULL) {
83!
845
    return terrno;
×
846
  }
847
  pCmpr->nCols = nCols;
83✔
848
  return 0;
83✔
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;
45,749!
877

878
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
45,749!
879
  if (pSW == NULL) {
45,750!
880
    return NULL;
×
881
  }
882
  pSW->nCols = pSchemaWrapper->nCols;
45,750✔
883
  pSW->version = pSchemaWrapper->version;
45,750✔
884
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
45,750!
885
  if (pSW->pSchema == NULL) {
45,747!
886
    taosMemoryFree(pSW);
×
887
    return NULL;
×
888
  }
889

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

894
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
42,302✔
895
  if (pSchemaWrapper) {
50,670!
896
    taosMemoryFree(pSchemaWrapper->pSchema);
45,741!
897
    taosMemoryFree(pSchemaWrapper);
45,742!
898
  }
899
}
50,667✔
900

901
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
×
902
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
×
903
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
×
904
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
×
905
  }
906
}
×
907

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

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

927
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
928
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
140,291!
929
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
194,026!
930
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
194,026!
931
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
194,026!
932
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
194,026!
933
  return 0;
97,013✔
934
}
935

936
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
937
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
462,645!
938
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
837,726!
939
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
837,811!
940
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
838,422!
941
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
419,211!
942
  return 0;
419,299✔
943
}
944

945
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
946
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
75,356!
947
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
75,356!
948
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pSchemaExt->typeMod));
75,356!
949
  return 0;
37,678✔
950
}
951

952
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
953
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
55,652!
954
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
55,652!
955
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
55,652!
956
  return 0;
27,826✔
957
}
958

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

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

979
  return 0;
×
980
}
981

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

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

1001
    for (int32_t i = 0; i < pSW->nCols; i++) {
448✔
1002
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
712✔
1003
    }
1004
  } else {
1005
    pSW->pSchema = NULL;
1✔
1006
  }
1007
  return (void*)buf;
93✔
1008
}
1009

1010
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1011
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
4,231!
1012
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
8,462!
1013
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
8,462!
1014
  for (int32_t i = 0; i < pSW->nCols; i++) {
57,966!
1015
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
107,470!
1016
  }
1017
  return 0;
4,231✔
1018
}
1019

1020
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1021
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
2,144!
1022
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
4,287!
1023
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
4,286!
1024

1025
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
2,143!
1026
  if (pSW->pSchema == NULL) {
2,145!
1027
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1028
  }
1029
  for (int32_t i = 0; i < pSW->nCols; i++) {
51,655!
1030
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
99,021!
1031
  }
1032

1033
  return 0;
2,144✔
1034
}
1035

1036
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
1037
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
50,413!
1038
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
50,476!
1039

1040
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
25,236!
1041
  if (pSW->pSchema == NULL) {
25,244!
1042
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1043
  }
1044
  for (int32_t i = 0; i < pSW->nCols; i++) {
351,514!
1045
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
652,605!
1046
  }
1047

1048
  return 0;
25,179✔
1049
}
1050

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

1084
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1085
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
1086
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
1087

1088
typedef struct {
1089
  STableMetaRsp* pMeta;
1090
} SMCreateStbRsp;
1091

1092
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
1093
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
1094
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
1095

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

1106
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1107
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
1108
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
1109

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

1124
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1125
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
1126
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
1127

1128
typedef struct SEpSet {
1129
  int8_t inUse;
1130
  int8_t numOfEps;
1131
  SEp    eps[TSDB_MAX_REPLICA];
1132
} SEpSet;
1133

1134
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
1135
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
1136
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
1137
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1138

1139
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1140
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1141

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

1153
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1154
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1155

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

1175
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1176
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1177

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

1189
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1190
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1191

1192
typedef struct {
1193
  char    user[TSDB_USER_LEN];
1194
  int32_t sqlLen;
1195
  char*   sql;
1196
} SDropUserReq, SDropAcctReq;
1197

1198
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1199
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1200
void    tFreeSDropUserReq(SDropUserReq* pReq);
1201

1202
typedef struct SIpV4Range {
1203
  uint32_t ip;
1204
  uint32_t mask;
1205
} SIpV4Range;
1206

1207
typedef struct {
1208
  int32_t    num;
1209
  SIpV4Range pIpRange[];
1210
} SIpWhiteList;
1211

1212
SIpWhiteList* cloneIpWhiteList(SIpWhiteList* pIpWhiteList);
1213
typedef struct {
1214
  int8_t      createType;
1215
  int8_t      superUser;  // denote if it is a super user or not
1216
  int8_t      sysInfo;
1217
  int8_t      enable;
1218
  char        user[TSDB_USER_LEN];
1219
  char        pass[TSDB_USET_PASSWORD_LEN];
1220
  int32_t     numIpRanges;
1221
  SIpV4Range* pIpRanges;
1222
  int32_t     sqlLen;
1223
  char*       sql;
1224
  int8_t      isImport;
1225
  int8_t      createDb;
1226
  int8_t      passIsMd5;
1227
} SCreateUserReq;
1228

1229
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1230
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1231
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1232

1233
typedef struct {
1234
  int64_t     ver;
1235
  char        user[TSDB_USER_LEN];
1236
  int32_t     numOfRange;
1237
  SIpV4Range* pIpRanges;
1238
} SUpdateUserIpWhite;
1239
typedef struct {
1240
  int64_t             ver;
1241
  int                 numOfUser;
1242
  SUpdateUserIpWhite* pUserIpWhite;
1243
} SUpdateIpWhite;
1244

1245
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1246
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1247
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1248
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1249

1250
typedef struct {
1251
  int64_t ipWhiteVer;
1252
} SRetrieveIpWhiteReq;
1253

1254
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1255
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1256

1257
typedef struct {
1258
  int32_t dnodeId;
1259
  int64_t analVer;
1260
} SRetrieveAnalyticsAlgoReq;
1261

1262
typedef struct {
1263
  int64_t   ver;
1264
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1265
} SRetrieveAnalyticAlgoRsp;
1266

1267
int32_t tSerializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1268
int32_t tDeserializeRetrieveAnalyticAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalyticsAlgoReq* pReq);
1269
int32_t tSerializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1270
int32_t tDeserializeRetrieveAnalyticAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalyticAlgoRsp* pRsp);
1271
void    tFreeRetrieveAnalyticAlgoRsp(SRetrieveAnalyticAlgoRsp* pRsp);
1272

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

1300
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1301
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1302
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1303

1304
typedef struct {
1305
  char user[TSDB_USER_LEN];
1306
} SGetUserAuthReq;
1307

1308
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1309
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1310

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

1332
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1333
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1334
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1335

1336
typedef struct {
1337
  char user[TSDB_USER_LEN];
1338
} SGetUserWhiteListReq;
1339

1340
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1341
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1342

1343
typedef struct {
1344
  char        user[TSDB_USER_LEN];
1345
  int32_t     numWhiteLists;
1346
  SIpV4Range* pWhiteLists;
1347
} SGetUserWhiteListRsp;
1348

1349
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1350
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1351
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1352

1353
/*
1354
 * for client side struct, only column id, type, bytes are necessary
1355
 * But for data in vnode side, we need all the following information.
1356
 */
1357
typedef struct {
1358
  union {
1359
    col_id_t colId;
1360
    int16_t  slotId;
1361
  };
1362

1363
  uint8_t precision;
1364
  uint8_t scale;
1365
  int32_t bytes;
1366
  int8_t  type;
1367
  uint8_t pk;
1368
  bool    noData;
1369
} SColumnInfo;
1370

1371
typedef struct STimeWindow {
1372
  TSKEY skey;
1373
  TSKEY ekey;
1374
} STimeWindow;
1375

1376
typedef struct SQueryHint {
1377
  bool batchScan;
1378
} SQueryHint;
1379

1380
typedef struct {
1381
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1382
  int32_t tsLen;          // total length of ts comp block
1383
  int32_t tsNumOfBlocks;  // ts comp block numbers
1384
  int32_t tsOrder;        // ts comp block order
1385
} STsBufInfo;
1386

1387
typedef struct {
1388
  void*       timezone;
1389
  char        intervalUnit;
1390
  char        slidingUnit;
1391
  char        offsetUnit;
1392
  int8_t      precision;
1393
  int64_t     interval;
1394
  int64_t     sliding;
1395
  int64_t     offset;
1396
  STimeWindow timeRange;
1397
} SInterval;
1398

1399
typedef struct STbVerInfo {
1400
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1401
  int32_t sversion;
1402
  int32_t tversion;
1403
} STbVerInfo;
1404

1405
typedef struct {
1406
  int32_t code;
1407
  int64_t affectedRows;
1408
  SArray* tbVerInfo;  // STbVerInfo
1409
} SQueryTableRsp;
1410

1411
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1412

1413
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1414

1415
typedef struct {
1416
  SMsgHead header;
1417
  char     dbFName[TSDB_DB_FNAME_LEN];
1418
  char     tbName[TSDB_TABLE_NAME_LEN];
1419
} STableCfgReq;
1420

1421
typedef struct {
1422
  char        tbName[TSDB_TABLE_NAME_LEN];
1423
  char        stbName[TSDB_TABLE_NAME_LEN];
1424
  char        dbFName[TSDB_DB_FNAME_LEN];
1425
  int32_t     numOfTags;
1426
  int32_t     numOfColumns;
1427
  int8_t      tableType;
1428
  int64_t     delay1;
1429
  int64_t     delay2;
1430
  int64_t     watermark1;
1431
  int64_t     watermark2;
1432
  int32_t     ttl;
1433
  int32_t     keep;
1434
  SArray*     pFuncs;
1435
  int32_t     commentLen;
1436
  char*       pComment;
1437
  SSchema*    pSchemas;
1438
  int32_t     tagsLen;
1439
  char*       pTags;
1440
  SSchemaExt* pSchemaExt;
1441
  int8_t      virtualStb;
1442
  SColRef*    pColRefs;
1443
} STableCfg;
1444

1445
typedef STableCfg STableCfgRsp;
1446

1447
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1448
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1449

1450
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1451
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1452
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1453

1454
typedef struct {
1455
  SMsgHead header;
1456
  tb_uid_t suid;
1457
} SVSubTablesReq;
1458

1459
int32_t tSerializeSVSubTablesReq(void *buf, int32_t bufLen, SVSubTablesReq *pReq);
1460
int32_t tDeserializeSVSubTablesReq(void *buf, int32_t bufLen, SVSubTablesReq *pReq);
1461

1462
typedef struct {
1463
  int32_t  vgId;
1464
  SArray*  pTables;   //SArray<SVCTableRefCols*>
1465
} SVSubTablesRsp;
1466

1467
int32_t tSerializeSVSubTablesRsp(void *buf, int32_t bufLen, SVSubTablesRsp *pRsp);
1468
int32_t tDeserializeSVSubTablesRsp(void *buf, int32_t bufLen, SVSubTablesRsp *pRsp);
1469
void tDestroySVSubTablesRsp(void* rsp);
1470

1471
typedef struct {
1472
  SMsgHead header;
1473
  tb_uid_t suid;
1474
} SVStbRefDbsReq;
1475

1476
int32_t tSerializeSVStbRefDbsReq(void *buf, int32_t bufLen, SVStbRefDbsReq *pReq);
1477
int32_t tDeserializeSVStbRefDbsReq(void *buf, int32_t bufLen, SVStbRefDbsReq *pReq);
1478

1479
typedef struct {
1480
  int32_t  vgId;
1481
  SArray*  pDbs;   // SArray<char* (db name)>
1482
} SVStbRefDbsRsp;
1483

1484
int32_t tSerializeSVStbRefDbsRsp(void *buf, int32_t bufLen, SVStbRefDbsRsp *pRsp);
1485
int32_t tDeserializeSVStbRefDbsRsp(void *buf, int32_t bufLen, SVStbRefDbsRsp *pRsp);
1486
void tDestroySVStbRefDbsRsp(void* rsp);
1487

1488
typedef struct {
1489
  char    db[TSDB_DB_FNAME_LEN];
1490
  int32_t numOfVgroups;
1491
  int32_t numOfStables;  // single_stable
1492
  int32_t buffer;        // MB
1493
  int32_t pageSize;
1494
  int32_t pages;
1495
  int32_t cacheLastSize;
1496
  int32_t daysPerFile;
1497
  int32_t daysToKeep0;
1498
  int32_t daysToKeep1;
1499
  int32_t daysToKeep2;
1500
  int32_t keepTimeOffset;
1501
  int32_t minRows;
1502
  int32_t maxRows;
1503
  int32_t walFsyncPeriod;
1504
  int8_t  walLevel;
1505
  int8_t  precision;  // time resolution
1506
  int8_t  compression;
1507
  int8_t  replications;
1508
  int8_t  strict;
1509
  int8_t  cacheLast;
1510
  int8_t  schemaless;
1511
  int8_t  ignoreExist;
1512
  int32_t numOfRetensions;
1513
  SArray* pRetensions;  // SRetention
1514
  int32_t walRetentionPeriod;
1515
  int64_t walRetentionSize;
1516
  int32_t walRollPeriod;
1517
  int64_t walSegmentSize;
1518
  int32_t sstTrigger;
1519
  int16_t hashPrefix;
1520
  int16_t hashSuffix;
1521
  int32_t s3ChunkSize;
1522
  int32_t s3KeepLocal;
1523
  int8_t  s3Compact;
1524
  int32_t tsdbPageSize;
1525
  int32_t sqlLen;
1526
  char*   sql;
1527
  int8_t  withArbitrator;
1528
  int8_t  encryptAlgorithm;
1529
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1530
  // 1. add auto-compact parameters
1531
  int32_t compactInterval;    // minutes
1532
  int32_t compactStartTime;   // minutes
1533
  int32_t compactEndTime;     // minutes
1534
  int8_t  compactTimeOffset;  // hour
1535
} SCreateDbReq;
1536

1537
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1538
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1539
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1540

1541
typedef struct {
1542
  char    db[TSDB_DB_FNAME_LEN];
1543
  int32_t buffer;
1544
  int32_t pageSize;
1545
  int32_t pages;
1546
  int32_t cacheLastSize;
1547
  int32_t daysPerFile;
1548
  int32_t daysToKeep0;
1549
  int32_t daysToKeep1;
1550
  int32_t daysToKeep2;
1551
  int32_t keepTimeOffset;
1552
  int32_t walFsyncPeriod;
1553
  int8_t  walLevel;
1554
  int8_t  strict;
1555
  int8_t  cacheLast;
1556
  int8_t  replications;
1557
  int32_t sstTrigger;
1558
  int32_t minRows;
1559
  int32_t walRetentionPeriod;
1560
  int32_t walRetentionSize;
1561
  int32_t s3KeepLocal;
1562
  int8_t  s3Compact;
1563
  int32_t sqlLen;
1564
  char*   sql;
1565
  int8_t  withArbitrator;
1566
  // 1. add auto-compact parameters
1567
  int32_t compactInterval;
1568
  int32_t compactStartTime;
1569
  int32_t compactEndTime;
1570
  int8_t  compactTimeOffset;
1571
} SAlterDbReq;
1572

1573
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1574
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1575
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1576

1577
typedef struct {
1578
  char    db[TSDB_DB_FNAME_LEN];
1579
  int8_t  ignoreNotExists;
1580
  int32_t sqlLen;
1581
  char*   sql;
1582
} SDropDbReq;
1583

1584
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1585
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1586
void    tFreeSDropDbReq(SDropDbReq* pReq);
1587

1588
typedef struct {
1589
  char    db[TSDB_DB_FNAME_LEN];
1590
  int64_t uid;
1591
} SDropDbRsp;
1592

1593
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1594
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1595

1596
typedef struct {
1597
  char    db[TSDB_DB_FNAME_LEN];
1598
  int64_t dbId;
1599
  int32_t vgVersion;
1600
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1601
  int64_t stateTs;     // ms
1602
} SUseDbReq;
1603

1604
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1605
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1606

1607
typedef struct {
1608
  char    db[TSDB_DB_FNAME_LEN];
1609
  int64_t uid;
1610
  int32_t vgVersion;
1611
  int32_t vgNum;
1612
  int16_t hashPrefix;
1613
  int16_t hashSuffix;
1614
  int8_t  hashMethod;
1615
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1616
  int32_t errCode;
1617
  int64_t stateTs;  // ms
1618
} SUseDbRsp;
1619

1620
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1621
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1622
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1623
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1624
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1625

1626
typedef struct {
1627
  char db[TSDB_DB_FNAME_LEN];
1628
} SDbCfgReq;
1629

1630
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1631
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1632

1633
typedef struct {
1634
  char    db[TSDB_DB_FNAME_LEN];
1635
  int32_t maxSpeed;
1636
} STrimDbReq;
1637

1638
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1639
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1640

1641
typedef struct {
1642
  int32_t timestamp;
1643
} SVTrimDbReq;
1644

1645
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1646
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1647

1648
typedef struct {
1649
  char db[TSDB_DB_FNAME_LEN];
1650
} SS3MigrateDbReq;
1651

1652
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1653
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1654

1655
typedef struct {
1656
  int32_t timestamp;
1657
} SVS3MigrateDbReq;
1658

1659
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1660
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1661

1662
typedef struct {
1663
  int32_t timestampSec;
1664
  int32_t ttlDropMaxCount;
1665
  int32_t nUids;
1666
  SArray* pTbUids;
1667
} SVDropTtlTableReq;
1668

1669
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1670
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1671

1672
typedef struct {
1673
  char    db[TSDB_DB_FNAME_LEN];
1674
  int64_t dbId;
1675
  int32_t cfgVersion;
1676
  int32_t numOfVgroups;
1677
  int32_t numOfStables;
1678
  int32_t buffer;
1679
  int32_t cacheSize;
1680
  int32_t pageSize;
1681
  int32_t pages;
1682
  int32_t daysPerFile;
1683
  int32_t daysToKeep0;
1684
  int32_t daysToKeep1;
1685
  int32_t daysToKeep2;
1686
  int32_t keepTimeOffset;
1687
  int32_t minRows;
1688
  int32_t maxRows;
1689
  int32_t walFsyncPeriod;
1690
  int16_t hashPrefix;
1691
  int16_t hashSuffix;
1692
  int8_t  hashMethod;
1693
  int8_t  walLevel;
1694
  int8_t  precision;
1695
  int8_t  compression;
1696
  int8_t  replications;
1697
  int8_t  strict;
1698
  int8_t  cacheLast;
1699
  int8_t  encryptAlgorithm;
1700
  int32_t s3ChunkSize;
1701
  int32_t s3KeepLocal;
1702
  int8_t  s3Compact;
1703
  int8_t  compactTimeOffset;
1704
  int32_t compactInterval;
1705
  int32_t compactStartTime;
1706
  int32_t compactEndTime;
1707
  int32_t tsdbPageSize;
1708
  int32_t walRetentionPeriod;
1709
  int32_t walRollPeriod;
1710
  int64_t walRetentionSize;
1711
  int64_t walSegmentSize;
1712
  int32_t numOfRetensions;
1713
  SArray* pRetensions;
1714
  int8_t  schemaless;
1715
  int16_t sstTrigger;
1716
  int8_t  withArbitrator;
1717
} SDbCfgRsp;
1718

1719
typedef SDbCfgRsp SDbCfgInfo;
1720

1721
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1722
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1723
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1724
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1725
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1726

1727
typedef struct {
1728
  int32_t rowNum;
1729
} SQnodeListReq;
1730

1731
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1732
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1733

1734
typedef struct {
1735
  int32_t rowNum;
1736
} SDnodeListReq;
1737

1738
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1739

1740
typedef struct {
1741
  int32_t useless;  // useless
1742
} SServerVerReq;
1743

1744
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1745
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1746

1747
typedef struct {
1748
  char ver[TSDB_VERSION_LEN];
1749
} SServerVerRsp;
1750

1751
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1752
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1753

1754
typedef struct SQueryNodeAddr {
1755
  int32_t nodeId;  // vgId or qnodeId
1756
  SEpSet  epSet;
1757
} SQueryNodeAddr;
1758

1759
typedef struct {
1760
  SQueryNodeAddr addr;
1761
  uint64_t       load;
1762
} SQueryNodeLoad;
1763

1764
typedef struct {
1765
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1766
} SQnodeListRsp;
1767

1768
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1769
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1770
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1771

1772
typedef struct {
1773
  SArray* dnodeList;  // SArray<SEpSet>
1774
} SDnodeListRsp;
1775

1776
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1777
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1778
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1779

1780
typedef struct {
1781
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1782
} STableTSMAInfoRsp;
1783

1784
typedef struct {
1785
  SUseDbRsp*         useDbRsp;
1786
  SDbCfgRsp*         cfgRsp;
1787
  STableTSMAInfoRsp* pTsmaRsp;
1788
  int32_t            dbTsmaVersion;
1789
  char               db[TSDB_DB_FNAME_LEN];
1790
  int64_t            dbId;
1791
} SDbHbRsp;
1792

1793
typedef struct {
1794
  SArray* pArray;  // Array of SDbHbRsp
1795
} SDbHbBatchRsp;
1796

1797
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1798
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1799
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1800

1801
typedef struct {
1802
  SArray* pArray;  // Array of SGetUserAuthRsp
1803
} SUserAuthBatchRsp;
1804

1805
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1806
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1807
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1808

1809
typedef struct {
1810
  char        db[TSDB_DB_FNAME_LEN];
1811
  STimeWindow timeRange;
1812
  int32_t     sqlLen;
1813
  char*       sql;
1814
  SArray*     vgroupIds;
1815
  int8_t      metaOnly;
1816
} SCompactDbReq;
1817

1818
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1819
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1820
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1821

1822
typedef struct {
1823
  int32_t compactId;
1824
  int8_t  bAccepted;
1825
} SCompactDbRsp;
1826

1827
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1828
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1829

1830
typedef struct {
1831
  int32_t compactId;
1832
  int32_t sqlLen;
1833
  char*   sql;
1834
} SKillCompactReq;
1835

1836
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1837
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1838
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1839

1840
typedef struct {
1841
  char    name[TSDB_FUNC_NAME_LEN];
1842
  int8_t  igExists;
1843
  int8_t  funcType;
1844
  int8_t  scriptType;
1845
  int8_t  outputType;
1846
  int32_t outputLen;
1847
  int32_t bufSize;
1848
  int32_t codeLen;
1849
  int64_t signature;
1850
  char*   pComment;
1851
  char*   pCode;
1852
  int8_t  orReplace;
1853
} SCreateFuncReq;
1854

1855
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1856
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1857
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1858

1859
typedef struct {
1860
  char   name[TSDB_FUNC_NAME_LEN];
1861
  int8_t igNotExists;
1862
} SDropFuncReq;
1863

1864
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1865
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1866

1867
typedef struct {
1868
  int32_t numOfFuncs;
1869
  bool    ignoreCodeComment;
1870
  SArray* pFuncNames;
1871
} SRetrieveFuncReq;
1872

1873
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1874
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1875
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1876

1877
typedef struct {
1878
  char    name[TSDB_FUNC_NAME_LEN];
1879
  int8_t  funcType;
1880
  int8_t  scriptType;
1881
  int8_t  outputType;
1882
  int32_t outputLen;
1883
  int32_t bufSize;
1884
  int64_t signature;
1885
  int32_t commentSize;
1886
  int32_t codeSize;
1887
  char*   pComment;
1888
  char*   pCode;
1889
} SFuncInfo;
1890

1891
typedef struct {
1892
  int32_t funcVersion;
1893
  int64_t funcCreatedTime;
1894
} SFuncExtraInfo;
1895

1896
typedef struct {
1897
  int32_t numOfFuncs;
1898
  SArray* pFuncInfos;
1899
  SArray* pFuncExtraInfos;
1900
} SRetrieveFuncRsp;
1901

1902
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1903
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1904
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1905
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1906

1907
typedef struct {
1908
  int32_t       statusInterval;
1909
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
1910
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
1911
  char          locale[TD_LOCALE_LEN];      // tsLocale
1912
  char          charset[TD_LOCALE_LEN];     // tsCharset
1913
  int8_t        ttlChangeOnWrite;
1914
  int8_t        enableWhiteList;
1915
  int8_t        encryptionKeyStat;
1916
  uint32_t      encryptionKeyChksum;
1917
  SMonitorParas monitorParas;
1918
} SClusterCfg;
1919

1920
typedef struct {
1921
  int32_t openVnodes;
1922
  int32_t dropVnodes;
1923
  int32_t totalVnodes;
1924
  int32_t masterNum;
1925
  int64_t numOfSelectReqs;
1926
  int64_t numOfInsertReqs;
1927
  int64_t numOfInsertSuccessReqs;
1928
  int64_t numOfBatchInsertReqs;
1929
  int64_t numOfBatchInsertSuccessReqs;
1930
  int64_t errors;
1931
} SVnodesStat;
1932

1933
typedef struct {
1934
  int32_t vgId;
1935
  int8_t  syncState;
1936
  int8_t  syncRestore;
1937
  int64_t syncTerm;
1938
  int64_t roleTimeMs;
1939
  int64_t startTimeMs;
1940
  int8_t  syncCanRead;
1941
  int64_t cacheUsage;
1942
  int64_t numOfTables;
1943
  int64_t numOfTimeSeries;
1944
  int64_t totalStorage;
1945
  int64_t compStorage;
1946
  int64_t pointsWritten;
1947
  int64_t numOfSelectReqs;
1948
  int64_t numOfInsertReqs;
1949
  int64_t numOfInsertSuccessReqs;
1950
  int64_t numOfBatchInsertReqs;
1951
  int64_t numOfBatchInsertSuccessReqs;
1952
  int32_t numOfCachedTables;
1953
  int32_t learnerProgress;  // use one reservered
1954
  int64_t syncAppliedIndex;
1955
  int64_t syncCommitIndex;
1956
} SVnodeLoad;
1957

1958
typedef struct {
1959
  int32_t     vgId;
1960
  int64_t     numOfTables;
1961
  int64_t     memSize;
1962
  int64_t     l1Size;
1963
  int64_t     l2Size;
1964
  int64_t     l3Size;
1965
  int64_t     cacheSize;
1966
  int64_t     walSize;
1967
  int64_t     metaSize;
1968
  int64_t     rawDataSize;
1969
  int64_t     s3Size;
1970
  const char* dbname;
1971
} SDbSizeStatisInfo;
1972

1973
typedef struct {
1974
  int32_t vgId;
1975
  int64_t nTimeSeries;
1976
} SVnodeLoadLite;
1977

1978
typedef struct {
1979
  int8_t  syncState;
1980
  int64_t syncTerm;
1981
  int8_t  syncRestore;
1982
  int64_t roleTimeMs;
1983
} SMnodeLoad;
1984

1985
typedef struct {
1986
  int32_t dnodeId;
1987
  int64_t numOfProcessedQuery;
1988
  int64_t numOfProcessedCQuery;
1989
  int64_t numOfProcessedFetch;
1990
  int64_t numOfProcessedDrop;
1991
  int64_t numOfProcessedNotify;
1992
  int64_t numOfProcessedHb;
1993
  int64_t numOfProcessedDelete;
1994
  int64_t cacheDataSize;
1995
  int64_t numOfQueryInQueue;
1996
  int64_t numOfFetchInQueue;
1997
  int64_t timeInQueryQueue;
1998
  int64_t timeInFetchQueue;
1999
} SQnodeLoad;
2000

2001
typedef struct {
2002
  int32_t     sver;      // software version
2003
  int64_t     dnodeVer;  // dnode table version in sdb
2004
  int32_t     dnodeId;
2005
  int64_t     clusterId;
2006
  int64_t     rebootTime;
2007
  int64_t     updateTime;
2008
  float       numOfCores;
2009
  int32_t     numOfSupportVnodes;
2010
  int32_t     numOfDiskCfg;
2011
  int64_t     memTotal;
2012
  int64_t     memAvail;
2013
  char        dnodeEp[TSDB_EP_LEN];
2014
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
2015
  SMnodeLoad  mload;
2016
  SQnodeLoad  qload;
2017
  SClusterCfg clusterCfg;
2018
  SArray*     pVloads;  // array of SVnodeLoad
2019
  int32_t     statusSeq;
2020
  int64_t     ipWhiteVer;
2021
  int64_t     analVer;
2022
  int64_t     timestamp;
2023
} SStatusReq;
2024

2025
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2026
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2027
void    tFreeSStatusReq(SStatusReq* pReq);
2028

2029
typedef struct {
2030
  int32_t forceReadConfig;
2031
  int32_t cver;
2032
  SArray* array;
2033
} SConfigReq;
2034

2035
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2036
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2037
void    tFreeSConfigReq(SConfigReq* pReq);
2038

2039
typedef struct {
2040
  int32_t dnodeId;
2041
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2042
} SDnodeInfoReq;
2043

2044
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2045
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2046

2047
typedef enum {
2048
  MONITOR_TYPE_COUNTER = 0,
2049
  MONITOR_TYPE_SLOW_LOG = 1,
2050
} MONITOR_TYPE;
2051

2052
typedef struct {
2053
  int32_t      contLen;
2054
  char*        pCont;
2055
  MONITOR_TYPE type;
2056
} SStatisReq;
2057

2058
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2059
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2060
void    tFreeSStatisReq(SStatisReq* pReq);
2061

2062
typedef struct {
2063
  char    db[TSDB_DB_FNAME_LEN];
2064
  char    table[TSDB_TABLE_NAME_LEN];
2065
  char    operation[AUDIT_OPERATION_LEN];
2066
  int32_t sqlLen;
2067
  char*   pSql;
2068
} SAuditReq;
2069
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2070
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2071
void    tFreeSAuditReq(SAuditReq* pReq);
2072

2073
typedef struct {
2074
  int32_t dnodeId;
2075
  int64_t clusterId;
2076
  SArray* pVloads;
2077
} SNotifyReq;
2078

2079
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2080
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2081
void    tFreeSNotifyReq(SNotifyReq* pReq);
2082

2083
typedef struct {
2084
  int32_t dnodeId;
2085
  int64_t clusterId;
2086
} SDnodeCfg;
2087

2088
typedef struct {
2089
  int32_t id;
2090
  int8_t  isMnode;
2091
  SEp     ep;
2092
} SDnodeEp;
2093

2094
typedef struct {
2095
  int32_t id;
2096
  int8_t  isMnode;
2097
  int8_t  offlineReason;
2098
  SEp     ep;
2099
  char    active[TSDB_ACTIVE_KEY_LEN];
2100
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2101
} SDnodeInfo;
2102

2103
typedef struct {
2104
  int64_t   dnodeVer;
2105
  SDnodeCfg dnodeCfg;
2106
  SArray*   pDnodeEps;  // Array of SDnodeEp
2107
  int32_t   statusSeq;
2108
  int64_t   ipWhiteVer;
2109
  int64_t   analVer;
2110
} SStatusRsp;
2111

2112
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2113
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2114
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2115

2116
typedef struct {
2117
  int32_t forceReadConfig;
2118
  int32_t isConifgVerified;
2119
  int32_t isVersionVerified;
2120
  int32_t cver;
2121
  SArray* array;
2122
} SConfigRsp;
2123

2124
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2125
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2126
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2127

2128
typedef struct {
2129
  int32_t reserved;
2130
} SMTimerReq;
2131

2132
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2133
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2134

2135
typedef struct SOrphanTask {
2136
  int64_t streamId;
2137
  int32_t taskId;
2138
  int32_t nodeId;
2139
} SOrphanTask;
2140

2141
typedef struct SMStreamDropOrphanMsg {
2142
  SArray* pList;  // SArray<SOrphanTask>
2143
} SMStreamDropOrphanMsg;
2144

2145
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2146
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2147
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2148

2149
typedef struct {
2150
  int32_t  id;
2151
  uint16_t port;                 // node sync Port
2152
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2153
} SReplica;
2154

2155
typedef struct {
2156
  int32_t  vgId;
2157
  char     db[TSDB_DB_FNAME_LEN];
2158
  int64_t  dbUid;
2159
  int32_t  vgVersion;
2160
  int32_t  numOfStables;
2161
  int32_t  buffer;
2162
  int32_t  pageSize;
2163
  int32_t  pages;
2164
  int32_t  cacheLastSize;
2165
  int32_t  daysPerFile;
2166
  int32_t  daysToKeep0;
2167
  int32_t  daysToKeep1;
2168
  int32_t  daysToKeep2;
2169
  int32_t  keepTimeOffset;
2170
  int32_t  minRows;
2171
  int32_t  maxRows;
2172
  int32_t  walFsyncPeriod;
2173
  uint32_t hashBegin;
2174
  uint32_t hashEnd;
2175
  int8_t   hashMethod;
2176
  int8_t   walLevel;
2177
  int8_t   precision;
2178
  int8_t   compression;
2179
  int8_t   strict;
2180
  int8_t   cacheLast;
2181
  int8_t   isTsma;
2182
  int8_t   replica;
2183
  int8_t   selfIndex;
2184
  SReplica replicas[TSDB_MAX_REPLICA];
2185
  int32_t  numOfRetensions;
2186
  SArray*  pRetensions;  // SRetention
2187
  void*    pTsma;
2188
  int32_t  walRetentionPeriod;
2189
  int64_t  walRetentionSize;
2190
  int32_t  walRollPeriod;
2191
  int64_t  walSegmentSize;
2192
  int16_t  sstTrigger;
2193
  int16_t  hashPrefix;
2194
  int16_t  hashSuffix;
2195
  int32_t  tsdbPageSize;
2196
  int32_t  s3ChunkSize;
2197
  int32_t  s3KeepLocal;
2198
  int8_t   s3Compact;
2199
  int64_t  reserved[6];
2200
  int8_t   learnerReplica;
2201
  int8_t   learnerSelfIndex;
2202
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2203
  int32_t  changeVersion;
2204
  int8_t   encryptAlgorithm;
2205
} SCreateVnodeReq;
2206

2207
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2208
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2209
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2210

2211
typedef struct {
2212
  int32_t compactId;
2213
  int32_t vgId;
2214
  int32_t dnodeId;
2215
} SQueryCompactProgressReq;
2216

2217
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2218
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2219

2220
typedef struct {
2221
  int32_t compactId;
2222
  int32_t vgId;
2223
  int32_t dnodeId;
2224
  int32_t numberFileset;
2225
  int32_t finished;
2226
  int32_t progress;
2227
  int64_t remainingTime;
2228
} SQueryCompactProgressRsp;
2229

2230
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2231
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2232

2233
typedef struct {
2234
  int32_t vgId;
2235
  int32_t dnodeId;
2236
  int64_t dbUid;
2237
  char    db[TSDB_DB_FNAME_LEN];
2238
  int64_t reserved[8];
2239
} SDropVnodeReq;
2240

2241
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2242
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2243

2244
typedef struct {
2245
  char    colName[TSDB_COL_NAME_LEN];
2246
  char    stb[TSDB_TABLE_FNAME_LEN];
2247
  int64_t stbUid;
2248
  int64_t dbUid;
2249
  int64_t reserved[8];
2250
} SDropIndexReq;
2251

2252
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2253
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2254

2255
typedef struct {
2256
  int64_t     dbUid;
2257
  char        db[TSDB_DB_FNAME_LEN];
2258
  int64_t     compactStartTime;
2259
  STimeWindow tw;
2260
  int32_t     compactId;
2261
  int8_t      metaOnly;
2262
} SCompactVnodeReq;
2263

2264
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2265
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2266

2267
typedef struct {
2268
  int32_t compactId;
2269
  int32_t vgId;
2270
  int32_t dnodeId;
2271
} SVKillCompactReq;
2272

2273
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2274
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2275

2276
typedef struct {
2277
  int32_t vgVersion;
2278
  int32_t buffer;
2279
  int32_t pageSize;
2280
  int32_t pages;
2281
  int32_t cacheLastSize;
2282
  int32_t daysPerFile;
2283
  int32_t daysToKeep0;
2284
  int32_t daysToKeep1;
2285
  int32_t daysToKeep2;
2286
  int32_t keepTimeOffset;
2287
  int32_t walFsyncPeriod;
2288
  int8_t  walLevel;
2289
  int8_t  strict;
2290
  int8_t  cacheLast;
2291
  int64_t reserved[7];
2292
  // 1st modification
2293
  int16_t sttTrigger;
2294
  int32_t minRows;
2295
  // 2nd modification
2296
  int32_t walRetentionPeriod;
2297
  int32_t walRetentionSize;
2298
  int32_t s3KeepLocal;
2299
  int8_t  s3Compact;
2300
} SAlterVnodeConfigReq;
2301

2302
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2303
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2304

2305
typedef struct {
2306
  int32_t  vgId;
2307
  int8_t   strict;
2308
  int8_t   selfIndex;
2309
  int8_t   replica;
2310
  SReplica replicas[TSDB_MAX_REPLICA];
2311
  int64_t  reserved[8];
2312
  int8_t   learnerSelfIndex;
2313
  int8_t   learnerReplica;
2314
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2315
  int32_t  changeVersion;
2316
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2317

2318
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2319
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2320

2321
typedef struct {
2322
  int32_t vgId;
2323
  int8_t  disable;
2324
} SDisableVnodeWriteReq;
2325

2326
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2327
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2328

2329
typedef struct {
2330
  int32_t  srcVgId;
2331
  int32_t  dstVgId;
2332
  uint32_t hashBegin;
2333
  uint32_t hashEnd;
2334
  int32_t  changeVersion;
2335
  int32_t  reserved;
2336
} SAlterVnodeHashRangeReq;
2337

2338
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2339
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2340

2341
#define REQ_OPT_TBNAME 0x0
2342
#define REQ_OPT_TBUID  0x01
2343
typedef struct {
2344
  SMsgHead header;
2345
  char     dbFName[TSDB_DB_FNAME_LEN];
2346
  char     tbName[TSDB_TABLE_NAME_LEN];
2347
  uint8_t  option;
2348
  uint8_t  autoCreateCtb;
2349
} STableInfoReq;
2350

2351
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2352
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2353

2354
typedef struct {
2355
  int8_t  metaClone;  // create local clone of the cached table meta
2356
  int32_t numOfVgroups;
2357
  int32_t numOfTables;
2358
  int32_t numOfUdfs;
2359
  char    tableNames[];
2360
} SMultiTableInfoReq;
2361

2362
// todo refactor
2363
typedef struct SVgroupInfo {
2364
  int32_t  vgId;
2365
  uint32_t hashBegin;
2366
  uint32_t hashEnd;
2367
  SEpSet   epSet;
2368
  union {
2369
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2370
    int32_t taskId;      // used in stream
2371
  };
2372
} SVgroupInfo;
2373

2374
typedef struct {
2375
  int32_t     numOfVgroups;
2376
  SVgroupInfo vgroups[];
2377
} SVgroupsInfo;
2378

2379
typedef struct {
2380
  STableMetaRsp* pMeta;
2381
} SMAlterStbRsp;
2382

2383
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2384
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2385
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2386

2387
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2388
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2389
void    tFreeSTableMetaRsp(void* pRsp);
2390
void    tFreeSTableIndexRsp(void* info);
2391

2392
typedef struct {
2393
  SArray* pMetaRsp;   // Array of STableMetaRsp
2394
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2395
} SSTbHbRsp;
2396

2397
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2398
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2399
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2400

2401
typedef struct {
2402
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2403
} SViewHbRsp;
2404

2405
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2406
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2407
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2408

2409
typedef struct {
2410
  int32_t numOfTables;
2411
  int32_t numOfVgroup;
2412
  int32_t numOfUdf;
2413
  int32_t contLen;
2414
  int8_t  compressed;  // denote if compressed or not
2415
  int32_t rawLen;      // size before compress
2416
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2417
  char    meta[];
2418
} SMultiTableMeta;
2419

2420
typedef struct {
2421
  int32_t dataLen;
2422
  char    name[TSDB_TABLE_FNAME_LEN];
2423
  char*   data;
2424
} STagData;
2425

2426
typedef struct {
2427
  int32_t  opType;
2428
  uint32_t valLen;
2429
  char*    val;
2430
} SShowVariablesReq;
2431

2432
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2433
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2434
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2435

2436
typedef struct {
2437
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2438
  char value[TSDB_CONFIG_PATH_LEN + 1];
2439
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2440
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2441
  char info[TSDB_CONFIG_INFO_LEN + 1];
2442
} SVariablesInfo;
2443

2444
typedef struct {
2445
  SArray* variables;  // SArray<SVariablesInfo>
2446
} SShowVariablesRsp;
2447

2448
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2449
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2450

2451
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2452

2453
/*
2454
 * sql: show tables like '%a_%'
2455
 * payload is the query condition, e.g., '%a_%'
2456
 * payloadLen is the length of payload
2457
 */
2458
typedef struct {
2459
  int32_t type;
2460
  char    db[TSDB_DB_FNAME_LEN];
2461
  int32_t payloadLen;
2462
  char*   payload;
2463
} SShowReq;
2464

2465
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2466
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2467
void tFreeSShowReq(SShowReq* pReq);
2468

2469
typedef struct {
2470
  int64_t       showId;
2471
  STableMetaRsp tableMeta;
2472
} SShowRsp, SVShowTablesRsp;
2473

2474
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2475
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2476
// void    tFreeSShowRsp(SShowRsp* pRsp);
2477

2478
typedef struct {
2479
  char    db[TSDB_DB_FNAME_LEN];
2480
  char    tb[TSDB_TABLE_NAME_LEN];
2481
  char    user[TSDB_USER_LEN];
2482
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2483
  int64_t showId;
2484
  int64_t compactId;  // for compact
2485
  bool    withFull;   // for show users full
2486
} SRetrieveTableReq;
2487

2488
typedef struct SSysTableSchema {
2489
  int8_t   type;
2490
  col_id_t colId;
2491
  int32_t  bytes;
2492
} SSysTableSchema;
2493

2494
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2495
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2496

2497
#define RETRIEVE_TABLE_RSP_VERSION          0
2498
#define RETRIEVE_TABLE_RSP_TMQ_VERSION      1
2499
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION  2
2500

2501
typedef struct {
2502
  int64_t useconds;
2503
  int8_t  completed;  // all results are returned to client
2504
  int8_t  precision;
2505
  int8_t  compressed;
2506
  int8_t  streamBlockType;
2507
  int32_t payloadLen;
2508
  int32_t compLen;
2509
  int32_t numOfBlocks;
2510
  int64_t numOfRows;  // from int32_t change to int64_t
2511
  int64_t numOfCols;
2512
  int64_t skey;
2513
  int64_t ekey;
2514
  int64_t version;                         // for stream
2515
  TSKEY   watermark;                       // for stream
2516
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2517
  char    data[];
2518
} SRetrieveTableRsp;
2519

2520
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2521

2522
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2523
  do {                                          \
2524
    ((int32_t*)(_p))[0] = (_compLen);           \
2525
    ((int32_t*)(_p))[1] = (_fullLen);           \
2526
  } while (0);
2527

2528
typedef struct {
2529
  int64_t version;
2530
  int64_t numOfRows;
2531
  int8_t  compressed;
2532
  int8_t  precision;
2533
  char    data[];
2534
} SRetrieveTableRspForTmq;
2535

2536
typedef struct {
2537
  int64_t handle;
2538
  int64_t useconds;
2539
  int8_t  completed;  // all results are returned to client
2540
  int8_t  precision;
2541
  int8_t  compressed;
2542
  int32_t compLen;
2543
  int32_t numOfRows;
2544
  int32_t fullLen;
2545
  char    data[];
2546
} SRetrieveMetaTableRsp;
2547

2548
typedef struct SExplainExecInfo {
2549
  double   startupCost;
2550
  double   totalCost;
2551
  uint64_t numOfRows;
2552
  uint32_t verboseLen;
2553
  void*    verboseInfo;
2554
} SExplainExecInfo;
2555

2556
typedef struct {
2557
  int32_t           numOfPlans;
2558
  SExplainExecInfo* subplanInfo;
2559
} SExplainRsp;
2560

2561
typedef struct {
2562
  SExplainRsp rsp;
2563
  uint64_t    qId;
2564
  uint64_t    cId;
2565
  uint64_t    tId;
2566
  int64_t     rId;
2567
  int32_t     eId;
2568
} SExplainLocalRsp;
2569

2570
typedef struct STableScanAnalyzeInfo {
2571
  uint64_t totalRows;
2572
  uint64_t totalCheckedRows;
2573
  uint32_t totalBlocks;
2574
  uint32_t loadBlocks;
2575
  uint32_t loadBlockStatis;
2576
  uint32_t skipBlocks;
2577
  uint32_t filterOutBlocks;
2578
  double   elapsedTime;
2579
  double   filterTime;
2580
} STableScanAnalyzeInfo;
2581

2582
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2583
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2584
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2585

2586
typedef struct {
2587
  char    config[TSDB_DNODE_CONFIG_LEN];
2588
  char    value[TSDB_CLUSTER_VALUE_LEN];
2589
  int32_t sqlLen;
2590
  char*   sql;
2591
} SMCfgClusterReq;
2592

2593
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2594
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2595
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2596

2597
typedef struct {
2598
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2599
  int32_t port;
2600
  int32_t sqlLen;
2601
  char*   sql;
2602
} SCreateDnodeReq;
2603

2604
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2605
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2606
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2607

2608
typedef struct {
2609
  int32_t dnodeId;
2610
  char    fqdn[TSDB_FQDN_LEN];
2611
  int32_t port;
2612
  int8_t  force;
2613
  int8_t  unsafe;
2614
  int32_t sqlLen;
2615
  char*   sql;
2616
} SDropDnodeReq;
2617

2618
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2619
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2620
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2621

2622
enum {
2623
  RESTORE_TYPE__ALL = 1,
2624
  RESTORE_TYPE__MNODE,
2625
  RESTORE_TYPE__VNODE,
2626
  RESTORE_TYPE__QNODE,
2627
};
2628

2629
typedef struct {
2630
  int32_t dnodeId;
2631
  int8_t  restoreType;
2632
  int32_t sqlLen;
2633
  char*   sql;
2634
} SRestoreDnodeReq;
2635

2636
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2637
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2638
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2639

2640
typedef struct {
2641
  int32_t dnodeId;
2642
  char    config[TSDB_DNODE_CONFIG_LEN];
2643
  char    value[TSDB_DNODE_VALUE_LEN];
2644
  int32_t sqlLen;
2645
  char*   sql;
2646
} SMCfgDnodeReq;
2647

2648
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2649
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2650
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2651

2652
typedef struct {
2653
  char    config[TSDB_DNODE_CONFIG_LEN];
2654
  char    value[TSDB_DNODE_VALUE_LEN];
2655
  int32_t version;
2656
} SDCfgDnodeReq;
2657

2658
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2659
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2660

2661
typedef struct {
2662
  int32_t dnodeId;
2663
  int32_t sqlLen;
2664
  char*   sql;
2665
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2666
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2667

2668
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2669
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2670
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2671
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2672
typedef struct {
2673
  int8_t   replica;
2674
  SReplica replicas[TSDB_MAX_REPLICA];
2675
  int8_t   learnerReplica;
2676
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2677
  int64_t  lastIndex;
2678
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2679

2680
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2681
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2682

2683
typedef struct {
2684
  int32_t urlLen;
2685
  int32_t sqlLen;
2686
  char*   url;
2687
  char*   sql;
2688
} SMCreateAnodeReq;
2689

2690
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2691
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2692
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2693

2694
typedef struct {
2695
  int32_t anodeId;
2696
  int32_t sqlLen;
2697
  char*   sql;
2698
} SMDropAnodeReq, SMUpdateAnodeReq;
2699

2700
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2701
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2702
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2703
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2704
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2705
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2706

2707
typedef struct {
2708
  int32_t vgId;
2709
  int32_t hbSeq;
2710
} SVArbHbReqMember;
2711

2712
typedef struct {
2713
  int32_t dnodeId;
2714
  char*   arbToken;
2715
  int64_t arbTerm;
2716
  SArray* hbMembers;  // SVArbHbReqMember
2717
} SVArbHeartBeatReq;
2718

2719
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2720
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2721
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2722

2723
typedef struct {
2724
  int32_t vgId;
2725
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2726
  int32_t hbSeq;
2727
} SVArbHbRspMember;
2728

2729
typedef struct {
2730
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2731
  int32_t dnodeId;
2732
  SArray* hbMembers;  // SVArbHbRspMember
2733
} SVArbHeartBeatRsp;
2734

2735
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2736
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2737
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2738

2739
typedef struct {
2740
  char*   arbToken;
2741
  int64_t arbTerm;
2742
  char*   member0Token;
2743
  char*   member1Token;
2744
} SVArbCheckSyncReq;
2745

2746
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2747
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2748
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2749

2750
typedef struct {
2751
  char*   arbToken;
2752
  char*   member0Token;
2753
  char*   member1Token;
2754
  int32_t vgId;
2755
  int32_t errCode;
2756
} SVArbCheckSyncRsp;
2757

2758
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2759
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2760
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2761

2762
typedef struct {
2763
  char*   arbToken;
2764
  int64_t arbTerm;
2765
  char*   memberToken;
2766
  int8_t  force;
2767
} SVArbSetAssignedLeaderReq;
2768

2769
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2770
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2771
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2772

2773
typedef struct {
2774
  char*   arbToken;
2775
  char*   memberToken;
2776
  int32_t vgId;
2777
} SVArbSetAssignedLeaderRsp;
2778

2779
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2780
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2781
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2782

2783
typedef struct {
2784
  int32_t dnodeId;
2785
  char*   token;
2786
} SMArbUpdateGroupMember;
2787

2788
typedef struct {
2789
  int32_t dnodeId;
2790
  char*   token;
2791
  int8_t  acked;
2792
} SMArbUpdateGroupAssigned;
2793

2794
typedef struct {
2795
  int32_t                  vgId;
2796
  int64_t                  dbUid;
2797
  SMArbUpdateGroupMember   members[2];
2798
  int8_t                   isSync;
2799
  int8_t                   assignedAcked;
2800
  SMArbUpdateGroupAssigned assignedLeader;
2801
  int64_t                  version;
2802
  int32_t                  code;
2803
  int64_t                  updateTimeMs;
2804
} SMArbUpdateGroup;
2805

2806
typedef struct {
2807
  SArray* updateArray;  // SMArbUpdateGroup
2808
} SMArbUpdateGroupBatchReq;
2809

2810
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2811
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2812
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2813

2814
typedef struct {
2815
  char queryStrId[TSDB_QUERY_ID_LEN];
2816
} SKillQueryReq;
2817

2818
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2819
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2820

2821
typedef struct {
2822
  uint32_t connId;
2823
} SKillConnReq;
2824

2825
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2826
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2827

2828
typedef struct {
2829
  int32_t transId;
2830
} SKillTransReq;
2831

2832
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2833
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2834

2835
typedef struct {
2836
  int32_t useless;  // useless
2837
  int32_t sqlLen;
2838
  char*   sql;
2839
} SBalanceVgroupReq;
2840

2841
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2842
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2843
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2844

2845
typedef struct {
2846
  int32_t useless;  // useless
2847
  int32_t sqlLen;
2848
  char*   sql;
2849
} SAssignLeaderReq;
2850

2851
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2852
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2853
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
2854
typedef struct {
2855
  int32_t vgId1;
2856
  int32_t vgId2;
2857
} SMergeVgroupReq;
2858

2859
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2860
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2861

2862
typedef struct {
2863
  int32_t vgId;
2864
  int32_t dnodeId1;
2865
  int32_t dnodeId2;
2866
  int32_t dnodeId3;
2867
  int32_t sqlLen;
2868
  char*   sql;
2869
} SRedistributeVgroupReq;
2870

2871
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2872
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2873
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2874

2875
typedef struct {
2876
  int32_t reserved;
2877
  int32_t vgId;
2878
  int32_t sqlLen;
2879
  char*   sql;
2880
  char    db[TSDB_DB_FNAME_LEN];
2881
} SBalanceVgroupLeaderReq;
2882

2883
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2884
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2885
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2886

2887
typedef struct {
2888
  int32_t vgId;
2889
} SForceBecomeFollowerReq;
2890

2891
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2892
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2893

2894
typedef struct {
2895
  int32_t vgId;
2896
} SSplitVgroupReq;
2897

2898
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2899
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2900

2901
typedef struct {
2902
  char user[TSDB_USER_LEN];
2903
  char spi;
2904
  char encrypt;
2905
  char secret[TSDB_PASSWORD_LEN];
2906
  char ckey[TSDB_PASSWORD_LEN];
2907
} SAuthReq, SAuthRsp;
2908

2909
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2910
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2911

2912
typedef struct {
2913
  int32_t statusCode;
2914
  char    details[1024];
2915
} SServerStatusRsp;
2916

2917
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2918
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2919

2920
/**
2921
 * The layout of the query message payload is as following:
2922
 * +--------------------+---------------------------------+
2923
 * |Sql statement       | Physical plan                   |
2924
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2925
 * +--------------------+---------------------------------+
2926
 */
2927
typedef struct SSubQueryMsg {
2928
  SMsgHead header;
2929
  uint64_t sId;
2930
  uint64_t queryId;
2931
  uint64_t clientId;
2932
  uint64_t taskId;
2933
  int64_t  refId;
2934
  int32_t  execId;
2935
  int32_t  msgMask;
2936
  int8_t   taskType;
2937
  int8_t   explain;
2938
  int8_t   needFetch;
2939
  int8_t   compress;
2940
  uint32_t sqlLen;
2941
  char*    sql;
2942
  uint32_t msgLen;
2943
  char*    msg;
2944
} SSubQueryMsg;
2945

2946
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2947
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2948
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2949

2950
typedef struct {
2951
  SMsgHead header;
2952
  uint64_t sId;
2953
  uint64_t queryId;
2954
  uint64_t taskId;
2955
} SSinkDataReq;
2956

2957
typedef struct {
2958
  SMsgHead header;
2959
  uint64_t sId;
2960
  uint64_t queryId;
2961
  uint64_t clientId;
2962
  uint64_t taskId;
2963
  int32_t  execId;
2964
} SQueryContinueReq;
2965

2966
typedef struct {
2967
  SMsgHead header;
2968
  uint64_t sId;
2969
  uint64_t queryId;
2970
  uint64_t taskId;
2971
} SResReadyReq;
2972

2973
typedef struct {
2974
  int32_t code;
2975
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2976
  int32_t sversion;
2977
  int32_t tversion;
2978
} SResReadyRsp;
2979

2980
typedef struct SOperatorParam {
2981
  int32_t opType;
2982
  int32_t downstreamIdx;
2983
  void*   value;
2984
  SArray* pChildren;  // SArray<SOperatorParam*>
2985
  bool    reUse;
2986
} SOperatorParam;
2987

2988
typedef struct SColIdNameKV {
2989
  col_id_t colId;
2990
  char     colName[TSDB_COL_NAME_LEN];
2991
} SColIdNameKV;
2992

2993
typedef struct SColIdPair {
2994
  col_id_t vtbColId;
2995
  col_id_t orgColId;
2996
} SColIdPair;
2997

2998
typedef struct SOrgTbInfo {
2999
  int32_t   vgId;
3000
  char      tbName[TSDB_TABLE_FNAME_LEN];
3001
  SArray*   colMap;  // SArray<SColIdNameKV>
3002
} SOrgTbInfo;
3003

3004
typedef struct STableScanOperatorParam {
3005
  bool           tableSeq;
3006
  SArray*        pUidList;
3007
  SOrgTbInfo*    pOrgTbInfo;
3008
  STimeWindow    window;
3009
} STableScanOperatorParam;
3010

3011
typedef struct SVTableScanOperatorParam {
3012
  uint64_t       uid;
3013
  SArray*        pOpParamArray;  // SArray<SOperatorParam>
3014
} SVTableScanOperatorParam;
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
  SOperatorParam* pOpParam;
3024
} SResFetchReq;
3025

3026
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3027
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3028

3029
typedef struct {
3030
  SMsgHead header;
3031
  uint64_t clientId;
3032
} SSchTasksStatusReq;
3033

3034
typedef struct {
3035
  uint64_t queryId;
3036
  uint64_t clientId;
3037
  uint64_t taskId;
3038
  int64_t  refId;
3039
  int32_t  execId;
3040
  int8_t   status;
3041
} STaskStatus;
3042

3043
typedef struct {
3044
  int64_t refId;
3045
  SArray* taskStatus;  // SArray<STaskStatus>
3046
} SSchedulerStatusRsp;
3047

3048
typedef struct {
3049
  uint64_t queryId;
3050
  uint64_t taskId;
3051
  int8_t   action;
3052
} STaskAction;
3053

3054
typedef struct SQueryNodeEpId {
3055
  int32_t nodeId;  // vgId or qnodeId
3056
  SEp     ep;
3057
} SQueryNodeEpId;
3058

3059
typedef struct {
3060
  SMsgHead       header;
3061
  uint64_t       clientId;
3062
  SQueryNodeEpId epId;
3063
  SArray*        taskAction;  // SArray<STaskAction>
3064
} SSchedulerHbReq;
3065

3066
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3067
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3068
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3069

3070
typedef struct {
3071
  SQueryNodeEpId epId;
3072
  SArray*        taskStatus;  // SArray<STaskStatus>
3073
} SSchedulerHbRsp;
3074

3075
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3076
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3077
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3078

3079
typedef struct {
3080
  SMsgHead header;
3081
  uint64_t sId;
3082
  uint64_t queryId;
3083
  uint64_t clientId;
3084
  uint64_t taskId;
3085
  int64_t  refId;
3086
  int32_t  execId;
3087
} STaskCancelReq;
3088

3089
typedef struct {
3090
  int32_t code;
3091
} STaskCancelRsp;
3092

3093
typedef struct {
3094
  SMsgHead header;
3095
  uint64_t sId;
3096
  uint64_t queryId;
3097
  uint64_t clientId;
3098
  uint64_t taskId;
3099
  int64_t  refId;
3100
  int32_t  execId;
3101
} STaskDropReq;
3102

3103
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3104
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3105

3106
typedef enum {
3107
  TASK_NOTIFY_FINISHED = 1,
3108
} ETaskNotifyType;
3109

3110
typedef struct {
3111
  SMsgHead        header;
3112
  uint64_t        sId;
3113
  uint64_t        queryId;
3114
  uint64_t        clientId;
3115
  uint64_t        taskId;
3116
  int64_t         refId;
3117
  int32_t         execId;
3118
  ETaskNotifyType type;
3119
} STaskNotifyReq;
3120

3121
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3122
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3123

3124
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3125
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3126

3127
typedef struct {
3128
  int32_t code;
3129
} STaskDropRsp;
3130

3131
#define STREAM_TRIGGER_AT_ONCE                 1
3132
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3133
#define STREAM_TRIGGER_MAX_DELAY               3
3134
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3135
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3136

3137
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3138
#define STREAM_FILL_HISTORY_ON        1
3139
#define STREAM_FILL_HISTORY_OFF       0
3140
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3141
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3142
#define STREAM_CREATE_STABLE_TRUE     1
3143
#define STREAM_CREATE_STABLE_FALSE    0
3144

3145
typedef struct SColLocation {
3146
  int16_t  slotId;
3147
  col_id_t colId;
3148
  int8_t   type;
3149
} SColLocation;
3150

3151
typedef struct SVgroupVer {
3152
  int32_t vgId;
3153
  int64_t ver;
3154
} SVgroupVer;
3155

3156
typedef struct {
3157
  char    name[TSDB_STREAM_FNAME_LEN];
3158
  char    sourceDB[TSDB_DB_FNAME_LEN];
3159
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
3160
  char*   sql;
3161
  char*   ast;
3162
  int8_t  igExists;
3163
  int8_t  triggerType;
3164
  int8_t  igExpired;
3165
  int8_t  fillHistory;  // process data inserted before creating stream
3166
  int64_t maxDelay;
3167
  int64_t watermark;
3168
  int32_t numOfTags;
3169
  SArray* pTags;  // array of SField
3170
  // 3.0.20
3171
  int64_t checkpointFreq;  // ms
3172
  // 3.0.2.3
3173
  int8_t   createStb;
3174
  uint64_t targetStbUid;
3175
  SArray*  fillNullCols;  // array of SColLocation
3176
  int64_t  deleteMark;
3177
  int8_t   igUpdate;
3178
  int64_t  lastTs;
3179
  SArray*  pVgroupVerList;
3180
  // 3.3.0.0
3181
  SArray* pCols;  // array of SField
3182
  int64_t smaId;
3183
  // 3.3.6.0
3184
  SArray* pNotifyAddrUrls;
3185
  int32_t notifyEventTypes;
3186
  int32_t notifyErrorHandle;
3187
  int8_t  notifyHistory;
3188
  int64_t recalculateInterval;
3189
  char    pWstartName[TSDB_COL_NAME_LEN];
3190
  char    pWendName[TSDB_COL_NAME_LEN];
3191
  char    pGroupIdName[TSDB_COL_NAME_LEN];
3192
  char    pIsWindowFilledName[TSDB_COL_NAME_LEN];
3193
  SArray* pVSubTables; // array of SVSubTablesRsp
3194
} SCMCreateStreamReq;
3195

3196
typedef struct STaskNotifyEventStat {
3197
  int64_t notifyEventAddTimes;     // call times of add function
3198
  int64_t notifyEventAddElems;     // elements added by add function
3199
  double  notifyEventAddCostSec;   // time cost of add function
3200
  int64_t notifyEventPushTimes;    // call times of push function
3201
  int64_t notifyEventPushElems;    // elements pushed by push function
3202
  double  notifyEventPushCostSec;  // time cost of push function
3203
  int64_t notifyEventPackTimes;    // call times of pack function
3204
  int64_t notifyEventPackElems;    // elements packed by pack function
3205
  double  notifyEventPackCostSec;  // time cost of pack function
3206
  int64_t notifyEventSendTimes;    // call times of send function
3207
  int64_t notifyEventSendElems;    // elements sent by send function
3208
  double  notifyEventSendCostSec;  // time cost of send function
3209
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3210
} STaskNotifyEventStat;
3211

3212
typedef struct {
3213
  int64_t streamId;
3214
} SCMCreateStreamRsp;
3215

3216
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3217
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3218
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3219

3220
enum {
3221
  TOPIC_SUB_TYPE__DB = 1,
3222
  TOPIC_SUB_TYPE__TABLE,
3223
  TOPIC_SUB_TYPE__COLUMN,
3224
};
3225

3226
#define DEFAULT_MAX_POLL_INTERVAL  300000
3227
#define DEFAULT_SESSION_TIMEOUT    12000
3228
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3229
#define DEFAULT_MIN_POLL_ROWS      4096
3230

3231
typedef struct {
3232
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3233
  int8_t igExists;
3234
  int8_t subType;
3235
  int8_t withMeta;
3236
  char*  sql;
3237
  char   subDbName[TSDB_DB_FNAME_LEN];
3238
  char*  ast;
3239
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3240
} SCMCreateTopicReq;
3241

3242
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3243
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3244
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3245

3246
typedef struct {
3247
  int64_t consumerId;
3248
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3249

3250
typedef struct {
3251
  int64_t consumerId;
3252
  char    cgroup[TSDB_CGROUP_LEN];
3253
  char    clientId[TSDB_CLIENT_ID_LEN];
3254
  char    user[TSDB_USER_LEN];
3255
  char    fqdn[TSDB_FQDN_LEN];
3256
  SArray* topicNames;  // SArray<char**>
3257

3258
  int8_t  withTbName;
3259
  int8_t  autoCommit;
3260
  int32_t autoCommitInterval;
3261
  int8_t  resetOffsetCfg;
3262
  int8_t  enableReplay;
3263
  int8_t  enableBatchMeta;
3264
  int32_t sessionTimeoutMs;
3265
  int32_t maxPollIntervalMs;
3266
} SCMSubscribeReq;
3267

3268
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3269
  int32_t tlen = 0;
318✔
3270
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
318!
3271
  tlen += taosEncodeString(buf, pReq->cgroup);
318✔
3272
  tlen += taosEncodeString(buf, pReq->clientId);
318✔
3273

3274
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
318!
3275
  tlen += taosEncodeFixedI32(buf, topicNum);
318✔
3276

3277
  for (int32_t i = 0; i < topicNum; i++) {
444✔
3278
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
252✔
3279
  }
3280

3281
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
318!
3282
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
318!
3283
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
318!
3284
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
318!
3285
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
318!
3286
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
318!
3287
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
318!
3288
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
318!
3289
  tlen += taosEncodeString(buf, pReq->user);
318✔
3290
  tlen += taosEncodeString(buf, pReq->fqdn);
318✔
3291

3292
  return tlen;
318✔
3293
}
3294

3295
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3296
  void* start = buf;
128✔
3297
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
128!
3298
  buf = taosDecodeStringTo(buf, pReq->cgroup);
128✔
3299
  buf = taosDecodeStringTo(buf, pReq->clientId);
128✔
3300

3301
  int32_t topicNum = 0;
128!
3302
  buf = taosDecodeFixedI32(buf, &topicNum);
128✔
3303

3304
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
128✔
3305
  if (pReq->topicNames == NULL) {
128!
3306
    return terrno;
×
3307
  }
3308
  for (int32_t i = 0; i < topicNum; i++) {
180✔
3309
    char* name = NULL;
52✔
3310
    buf = taosDecodeString(buf, &name);
52✔
3311
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
104!
3312
      return terrno;
×
3313
    }
3314
  }
3315

3316
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
128✔
3317
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
128✔
3318
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
128!
3319
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
128✔
3320
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
128✔
3321
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
128✔
3322
  if ((char*)buf - (char*)start < len) {
128!
3323
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
128!
3324
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
128!
3325
    buf = taosDecodeStringTo(buf, pReq->user);
128✔
3326
    buf = taosDecodeStringTo(buf, pReq->fqdn);
256✔
3327
  } else {
3328
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3329
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3330
  }
3331

3332
  return 0;
128✔
3333
}
3334

3335
typedef struct {
3336
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3337
  SArray* removedConsumers;  // SArray<int64_t>
3338
  SArray* newConsumers;      // SArray<int64_t>
3339
} SMqRebInfo;
3340

3341
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3342
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
103!
3343
  if (pRebInfo == NULL) {
103!
3344
    return NULL;
×
3345
  }
3346
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
103✔
3347
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
103✔
3348
  if (pRebInfo->removedConsumers == NULL) {
103!
3349
    goto _err;
×
3350
  }
3351
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
103✔
3352
  if (pRebInfo->newConsumers == NULL) {
103!
3353
    goto _err;
×
3354
  }
3355
  return pRebInfo;
103✔
3356
_err:
×
3357
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3358
  taosArrayDestroy(pRebInfo->newConsumers);
×
3359
  taosMemoryFreeClear(pRebInfo);
×
3360
  return NULL;
×
3361
}
3362

3363
typedef struct {
3364
  int64_t streamId;
3365
  int64_t checkpointId;
3366
  char    streamName[TSDB_STREAM_FNAME_LEN];
3367
} SMStreamDoCheckpointMsg;
3368

3369
typedef struct {
3370
  int64_t status;
3371
} SMVSubscribeRsp;
3372

3373
typedef struct {
3374
  char    name[TSDB_TOPIC_FNAME_LEN];
3375
  int8_t  igNotExists;
3376
  int32_t sqlLen;
3377
  char*   sql;
3378
  int8_t  force;
3379
} SMDropTopicReq;
3380

3381
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3382
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3383
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3384

3385
typedef struct {
3386
  char   topic[TSDB_TOPIC_FNAME_LEN];
3387
  char   cgroup[TSDB_CGROUP_LEN];
3388
  int8_t igNotExists;
3389
  int8_t force;
3390
} SMDropCgroupReq;
3391

3392
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3393
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3394

3395
typedef struct {
3396
  int8_t reserved;
3397
} SMDropCgroupRsp;
3398

3399
typedef struct {
3400
  char    name[TSDB_TABLE_FNAME_LEN];
3401
  int8_t  alterType;
3402
  SSchema schema;
3403
} SAlterTopicReq;
3404

3405
typedef struct {
3406
  SMsgHead head;
3407
  char     name[TSDB_TABLE_FNAME_LEN];
3408
  int64_t  tuid;
3409
  int32_t  sverson;
3410
  int32_t  execLen;
3411
  char*    executor;
3412
  int32_t  sqlLen;
3413
  char*    sql;
3414
} SDCreateTopicReq;
3415

3416
typedef struct {
3417
  SMsgHead head;
3418
  char     name[TSDB_TABLE_FNAME_LEN];
3419
  int64_t  tuid;
3420
} SDDropTopicReq;
3421

3422
typedef struct {
3423
  int64_t maxdelay[2];
3424
  int64_t watermark[2];
3425
  int64_t deleteMark[2];
3426
  int32_t qmsgLen[2];
3427
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3428
} SRSmaParam;
3429

3430
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3431
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3432

3433
// TDMT_VND_CREATE_STB ==============
3434
typedef struct SVCreateStbReq {
3435
  char*           name;
3436
  tb_uid_t        suid;
3437
  int8_t          rollup;
3438
  SSchemaWrapper  schemaRow;
3439
  SSchemaWrapper  schemaTag;
3440
  SRSmaParam      rsmaParam;
3441
  int32_t         alterOriDataLen;
3442
  void*           alterOriData;
3443
  int8_t          source;
3444
  int8_t          colCmpred;
3445
  SColCmprWrapper colCmpr;
3446
  int64_t         keep;
3447
  SExtSchema*     pExtSchemas;
3448
  int8_t          virtualStb;
3449
} SVCreateStbReq;
3450

3451
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3452
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3453

3454
// TDMT_VND_DROP_STB ==============
3455
typedef struct SVDropStbReq {
3456
  char*    name;
3457
  tb_uid_t suid;
3458
} SVDropStbReq;
3459

3460
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3461
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3462

3463
// TDMT_VND_CREATE_TABLE ==============
3464
#define TD_CREATE_IF_NOT_EXISTS 0x1
3465
typedef struct SVCreateTbReq {
3466
  int32_t  flags;
3467
  char*    name;
3468
  tb_uid_t uid;
3469
  int64_t  btime;
3470
  int32_t  ttl;
3471
  int32_t  commentLen;
3472
  char*    comment;
3473
  int8_t   type;
3474
  union {
3475
    struct {
3476
      char*    stbName;  // super table name
3477
      uint8_t  tagNum;
3478
      tb_uid_t suid;
3479
      SArray*  tagName;
3480
      uint8_t* pTag;
3481
    } ctb;
3482
    struct {
3483
      SSchemaWrapper schemaRow;
3484
    } ntb;
3485
  };
3486
  int32_t         sqlLen;
3487
  char*           sql;
3488
  SColCmprWrapper colCmpr;
3489
  SExtSchema*     pExtSchemas;
3490
  SColRefWrapper  colRef; // col reference for virtual table
3491
} SVCreateTbReq;
3492

3493
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3494
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3495
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3496

3497
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
10✔
3498
  if (NULL == req) {
236,431!
3499
    return;
229,383✔
3500
  }
3501

3502
  taosMemoryFreeClear(req->sql);
7,048!
3503
  taosMemoryFreeClear(req->name);
7,048!
3504
  taosMemoryFreeClear(req->comment);
7,049!
3505
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
7,049!
3506
    taosMemoryFreeClear(req->ctb.pTag);
6,966!
3507
    taosMemoryFreeClear(req->ctb.stbName);
6,968!
3508
    taosArrayDestroy(req->ctb.tagName);
6,969✔
3509
    req->ctb.tagName = NULL;
6,965✔
3510
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
83!
3511
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
83!
3512
  }
3513
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
7,048!
3514
  taosMemoryFreeClear(req->pExtSchemas);
7,048!
3515
  taosMemoryFreeClear(req->colRef.pColRef);
7,048!
3516
}
3517

3518
typedef struct {
3519
  int32_t nReqs;
3520
  union {
3521
    SVCreateTbReq* pReqs;
3522
    SArray*        pArray;
3523
  };
3524
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3525
} SVCreateTbBatchReq;
3526

3527
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3528
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3529
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3530

3531
typedef struct {
3532
  int32_t        code;
3533
  STableMetaRsp* pMeta;
3534
} SVCreateTbRsp, SVUpdateTbRsp;
3535

3536
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3537
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3538
void tFreeSVCreateTbRsp(void* param);
3539

3540
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3541
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3542

3543
typedef struct {
3544
  int32_t nRsps;
3545
  union {
3546
    SVCreateTbRsp* pRsps;
3547
    SArray*        pArray;
3548
  };
3549
} SVCreateTbBatchRsp;
3550

3551
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3552
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3553

3554
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3555
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3556

3557
// TDMT_VND_DROP_TABLE =================
3558
typedef struct {
3559
  char*    name;
3560
  uint64_t suid;  // for tmq in wal format
3561
  int64_t  uid;
3562
  int8_t   igNotExists;
3563
  int8_t   isVirtual;
3564
} SVDropTbReq;
3565

3566
typedef struct {
3567
  int32_t code;
3568
} SVDropTbRsp;
3569

3570
typedef struct {
3571
  int32_t nReqs;
3572
  union {
3573
    SVDropTbReq* pReqs;
3574
    SArray*      pArray;
3575
  };
3576
} SVDropTbBatchReq;
3577

3578
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3579
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3580

3581
typedef struct {
3582
  int32_t nRsps;
3583
  union {
3584
    SVDropTbRsp* pRsps;
3585
    SArray*      pArray;
3586
  };
3587
} SVDropTbBatchRsp;
3588

3589
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3590
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3591

3592
// TDMT_VND_ALTER_TABLE =====================
3593
typedef struct SMultiTagUpateVal {
3594
  char*    tagName;
3595
  int32_t  colId;
3596
  int8_t   tagType;
3597
  int8_t   tagFree;
3598
  uint32_t nTagVal;
3599
  uint8_t* pTagVal;
3600
  int8_t   isNull;
3601
  SArray*  pTagArray;
3602
} SMultiTagUpateVal;
3603
typedef struct SVAlterTbReq{
3604
  char*   tbName;
3605
  int8_t  action;
3606
  char*   colName;
3607
  int32_t colId;
3608
  // TSDB_ALTER_TABLE_ADD_COLUMN
3609
  int8_t  type;
3610
  int8_t  flags;
3611
  int32_t bytes;
3612
  // TSDB_ALTER_TABLE_DROP_COLUMN
3613
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3614
  int8_t   colModType;
3615
  int32_t  colModBytes;
3616
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3617
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3618
  int8_t   isNull;
3619
  int8_t   tagType;
3620
  int8_t   tagFree;
3621
  uint32_t nTagVal;
3622
  uint8_t* pTagVal;
3623
  SArray*  pTagArray;
3624
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3625
  int8_t   updateTTL;
3626
  int32_t  newTTL;
3627
  int32_t  newCommentLen;
3628
  char*    newComment;
3629
  int64_t  ctimeMs;    // fill by vnode
3630
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3631
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3632
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3633
  // for Add column
3634
  STypeMod typeMod;
3635
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3636
  char*    refDbName;
3637
  char*    refTbName;
3638
  char*    refColName;
3639
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
3640
} SVAlterTbReq;
3641

3642
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3643
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3644
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3645
void    tfreeMultiTagUpateVal(void* pMultiTag);
3646

3647
typedef struct {
3648
  int32_t        code;
3649
  STableMetaRsp* pMeta;
3650
} SVAlterTbRsp;
3651

3652
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3653
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3654
// ======================
3655

3656
typedef struct {
3657
  SMsgHead head;
3658
  int64_t  uid;
3659
  int32_t  tid;
3660
  int16_t  tversion;
3661
  int16_t  colId;
3662
  int8_t   type;
3663
  int16_t  bytes;
3664
  int32_t  tagValLen;
3665
  int16_t  numOfTags;
3666
  int32_t  schemaLen;
3667
  char     data[];
3668
} SUpdateTagValReq;
3669

3670
typedef struct {
3671
  SMsgHead head;
3672
} SUpdateTagValRsp;
3673

3674
typedef struct {
3675
  SMsgHead head;
3676
} SVShowTablesReq;
3677

3678
typedef struct {
3679
  SMsgHead head;
3680
  int32_t  id;
3681
} SVShowTablesFetchReq;
3682

3683
typedef struct {
3684
  int64_t useconds;
3685
  int8_t  completed;  // all results are returned to client
3686
  int8_t  precision;
3687
  int8_t  compressed;
3688
  int32_t compLen;
3689
  int32_t numOfRows;
3690
  char    data[];
3691
} SVShowTablesFetchRsp;
3692

3693
typedef struct {
3694
  int64_t consumerId;
3695
  int32_t epoch;
3696
  char    cgroup[TSDB_CGROUP_LEN];
3697
} SMqAskEpReq;
3698

3699
typedef struct {
3700
  int32_t key;
3701
  int32_t valueLen;
3702
  void*   value;
3703
} SKv;
3704

3705
typedef struct {
3706
  int64_t tscRid;
3707
  int8_t  connType;
3708
} SClientHbKey;
3709

3710
typedef struct {
3711
  int64_t tid;
3712
  char    status[TSDB_JOB_STATUS_LEN];
3713
} SQuerySubDesc;
3714

3715
typedef struct {
3716
  char     sql[TSDB_SHOW_SQL_LEN];
3717
  uint64_t queryId;
3718
  int64_t  useconds;
3719
  int64_t  stime;  // timestamp precision ms
3720
  int64_t  reqRid;
3721
  bool     stableQuery;
3722
  bool     isSubQuery;
3723
  char     fqdn[TSDB_FQDN_LEN];
3724
  int32_t  subPlanNum;
3725
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3726
} SQueryDesc;
3727

3728
typedef struct {
3729
  uint32_t connId;
3730
  SArray*  queryDesc;  // SArray<SQueryDesc>
3731
} SQueryHbReqBasic;
3732

3733
typedef struct {
3734
  uint32_t connId;
3735
  uint64_t killRid;
3736
  int32_t  totalDnodes;
3737
  int32_t  onlineDnodes;
3738
  int8_t   killConnection;
3739
  int8_t   align[3];
3740
  SEpSet   epSet;
3741
  SArray*  pQnodeList;
3742
} SQueryHbRspBasic;
3743

3744
typedef struct SAppClusterSummary {
3745
  uint64_t numOfInsertsReq;
3746
  uint64_t numOfInsertRows;
3747
  uint64_t insertElapsedTime;
3748
  uint64_t insertBytes;  // submit to tsdb since launched.
3749

3750
  uint64_t fetchBytes;
3751
  uint64_t numOfQueryReq;
3752
  uint64_t queryElapsedTime;
3753
  uint64_t numOfSlowQueries;
3754
  uint64_t totalRequests;
3755
  uint64_t currentRequests;  // the number of SRequestObj
3756
} SAppClusterSummary;
3757

3758
typedef struct {
3759
  int64_t            appId;
3760
  int32_t            pid;
3761
  char               name[TSDB_APP_NAME_LEN];
3762
  int64_t            startTime;
3763
  SAppClusterSummary summary;
3764
} SAppHbReq;
3765

3766
typedef struct {
3767
  SClientHbKey      connKey;
3768
  int64_t           clusterId;
3769
  SAppHbReq         app;
3770
  SQueryHbReqBasic* query;
3771
  SHashObj*         info;  // hash<Skv.key, Skv>
3772
  char              userApp[TSDB_APP_NAME_LEN];
3773
  uint32_t          userIp;
3774
} SClientHbReq;
3775

3776
typedef struct {
3777
  int64_t reqId;
3778
  SArray* reqs;  // SArray<SClientHbReq>
3779
  int64_t ipWhiteList;
3780
} SClientHbBatchReq;
3781

3782
typedef struct {
3783
  SClientHbKey      connKey;
3784
  int32_t           status;
3785
  SQueryHbRspBasic* query;
3786
  SArray*           info;  // Array<Skv>
3787
} SClientHbRsp;
3788

3789
typedef struct {
3790
  int64_t       reqId;
3791
  int64_t       rspId;
3792
  int32_t       svrTimestamp;
3793
  SArray*       rsps;  // SArray<SClientHbRsp>
3794
  SMonitorParas monitorParas;
3795
  int8_t        enableAuditDelete;
3796
  int8_t        enableStrongPass;
3797
} SClientHbBatchRsp;
3798

3799
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
19,050✔
3800

3801
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3802
  void* pIter = taosHashIterate(info, NULL);
6,016✔
3803
  while (pIter != NULL) {
12,122!
3804
    SKv* kv = (SKv*)pIter;
6,106✔
3805
    taosMemoryFreeClear(kv->value);
6,106!
3806
    pIter = taosHashIterate(info, pIter);
6,106✔
3807
  }
3808
}
6,016✔
3809

3810
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
1,848✔
3811
  SQueryDesc* desc = (SQueryDesc*)pDesc;
1,848✔
3812
  if (desc->subDesc) {
1,848✔
3813
    taosArrayDestroy(desc->subDesc);
1,331✔
3814
    desc->subDesc = NULL;
1,331✔
3815
  }
3816
}
1,848✔
3817

3818
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
8,263✔
3819
  SClientHbReq* req = (SClientHbReq*)pReq;
10,961✔
3820
  if (req->query) {
10,961!
3821
    if (req->query->queryDesc) {
7,413!
3822
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
2,247✔
3823
    }
3824
    taosMemoryFreeClear(req->query);
7,413!
3825
  }
3826

3827
  if (req->info) {
10,961!
3828
    tFreeReqKvHash(req->info);
6,016✔
3829
    taosHashCleanup(req->info);
6,016✔
3830
    req->info = NULL;
6,016✔
3831
  }
3832
}
5,542✔
3833

3834
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3835
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3836

3837
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3838
  if (pReq == NULL) return;
3,921!
3839
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
3,921✔
3840
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
3,921✔
3841
  taosMemoryFree(pReq);
3,921!
3842
}
3843

3844
static FORCE_INLINE void tFreeClientKv(void* pKv) {
1,716✔
3845
  SKv* kv = (SKv*)pKv;
1,716✔
3846
  if (kv) {
1,716!
3847
    taosMemoryFreeClear(kv->value);
1,716!
3848
  }
3849
}
1,716✔
3850

3851
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
7,830✔
3852
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
7,830✔
3853
  if (rsp->query) {
7,830✔
3854
    taosArrayDestroy(rsp->query->pQnodeList);
6,991✔
3855
    taosMemoryFreeClear(rsp->query);
6,991!
3856
  }
3857
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
7,830!
3858
}
4,988✔
3859

3860
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3861
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
5,688✔
3862
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
5,688✔
3863
}
5,689✔
3864

3865
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3866
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3867
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3868

3869
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3870
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
19,148!
3871
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
19,148!
3872
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
19,148!
3873
  return 0;
9,574✔
3874
}
3875

3876
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3877
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
6,072!
3878
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
6,072!
3879
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
3,036!
3880
  if (pKv->value == NULL) {
3,036!
3881
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3882
  }
3883
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
3,036!
3884
  return 0;
3,036✔
3885
}
3886

3887
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3888
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
33,052!
3889
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
33,052!
3890
  return 0;
16,526✔
3891
}
3892

3893
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3894
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
15,664!
3895
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
15,664!
3896
  return 0;
7,832✔
3897
}
3898

3899
typedef struct {
3900
  int32_t vgId;
3901
  // TODO stas
3902
} SMqReportVgInfo;
3903

3904
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3905
  int32_t tlen = 0;
3906
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3907
  return tlen;
3908
}
3909

3910
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3911
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3912
  return buf;
3913
}
3914

3915
typedef struct {
3916
  int32_t epoch;
3917
  int64_t topicUid;
3918
  char    name[TSDB_TOPIC_FNAME_LEN];
3919
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3920
} SMqTopicInfo;
3921

3922
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3923
  int32_t tlen = 0;
3924
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3925
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3926
  tlen += taosEncodeString(buf, pTopicInfo->name);
3927
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3928
  tlen += taosEncodeFixedI32(buf, sz);
3929
  for (int32_t i = 0; i < sz; i++) {
3930
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3931
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3932
  }
3933
  return tlen;
3934
}
3935

3936
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3937
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3938
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3939
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3940
  int32_t sz;
3941
  buf = taosDecodeFixedI32(buf, &sz);
3942
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3943
    return NULL;
3944
  }
3945
  for (int32_t i = 0; i < sz; i++) {
3946
    SMqReportVgInfo vgInfo;
3947
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3948
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3949
      return NULL;
3950
    }
3951
  }
3952
  return buf;
3953
}
3954

3955
typedef struct {
3956
  int32_t status;  // ask hb endpoint
3957
  int32_t epoch;
3958
  int64_t consumerId;
3959
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3960
} SMqReportReq;
3961

3962
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3963
  int32_t tlen = 0;
3964
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3965
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3966
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3967
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3968
  tlen += taosEncodeFixedI32(buf, sz);
3969
  for (int32_t i = 0; i < sz; i++) {
3970
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3971
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3972
  }
3973
  return tlen;
3974
}
3975

3976
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3977
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3978
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3979
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3980
  int32_t sz;
3981
  buf = taosDecodeFixedI32(buf, &sz);
3982
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3983
    return NULL;
3984
  }
3985
  for (int32_t i = 0; i < sz; i++) {
3986
    SMqTopicInfo topicInfo;
3987
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3988
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3989
      return NULL;
3990
    }
3991
  }
3992
  return buf;
3993
}
3994

3995
typedef struct {
3996
  SMsgHead head;
3997
  int64_t  leftForVer;
3998
  int32_t  vgId;
3999
  int64_t  consumerId;
4000
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4001
} SMqVDeleteReq;
4002

4003
typedef struct {
4004
  int8_t reserved;
4005
} SMqVDeleteRsp;
4006

4007
typedef struct {
4008
  char    name[TSDB_STREAM_FNAME_LEN];
4009
  int8_t  igNotExists;
4010
  int32_t sqlLen;
4011
  char*   sql;
4012
} SMDropStreamReq;
4013

4014
typedef struct {
4015
  int8_t reserved;
4016
} SMDropStreamRsp;
4017

4018
typedef struct {
4019
  SMsgHead head;
4020
  int64_t  resetRelHalt;  // reset related stream task halt status
4021
  int64_t  streamId;
4022
  int32_t  taskId;
4023
} SVDropStreamTaskReq;
4024

4025
typedef struct {
4026
  int8_t reserved;
4027
} SVDropStreamTaskRsp;
4028

4029
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4030
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4031
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4032

4033
typedef struct SVUpdateCheckpointInfoReq {
4034
  SMsgHead head;
4035
  int64_t  streamId;
4036
  int32_t  taskId;
4037
  int64_t  checkpointId;
4038
  int64_t  checkpointVer;
4039
  int64_t  checkpointTs;
4040
  int32_t  transId;
4041
  int64_t  hStreamId;  // add encode/decode
4042
  int64_t  hTaskId;
4043
  int8_t   dropRelHTask;
4044
} SVUpdateCheckpointInfoReq;
4045

4046
typedef struct {
4047
  int64_t leftForVer;
4048
  int32_t vgId;
4049
  int64_t oldConsumerId;
4050
  int64_t newConsumerId;
4051
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4052
  int8_t  subType;
4053
  int8_t  withMeta;
4054
  char*   qmsg;  // SubPlanToString
4055
  int64_t suid;
4056
} SMqRebVgReq;
4057

4058
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4059
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4060

4061
typedef struct {
4062
  char    topic[TSDB_TOPIC_FNAME_LEN];
4063
  int64_t ntbUid;
4064
  SArray* colIdList;  // SArray<int16_t>
4065
} STqCheckInfo;
4066

4067
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4068
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4069
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4070

4071
// tqOffset
4072
enum {
4073
  TMQ_OFFSET__RESET_NONE = -3,
4074
  TMQ_OFFSET__RESET_EARLIEST = -2,
4075
  TMQ_OFFSET__RESET_LATEST = -1,
4076
  TMQ_OFFSET__LOG = 1,
4077
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4078
  TMQ_OFFSET__SNAPSHOT_META = 3,
4079
};
4080

4081
enum {
4082
  WITH_DATA = 0,
4083
  WITH_META = 1,
4084
  ONLY_META = 2,
4085
};
4086

4087
#define TQ_OFFSET_VERSION 1
4088

4089
typedef struct {
4090
  int8_t type;
4091
  union {
4092
    // snapshot
4093
    struct {
4094
      int64_t uid;
4095
      int64_t ts;
4096
      SValue  primaryKey;
4097
    };
4098
    // log
4099
    struct {
4100
      int64_t version;
4101
    };
4102
  };
4103
} STqOffsetVal;
4104

4105
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4106
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
×
4107
  pOffsetVal->uid = uid;
×
4108
  pOffsetVal->ts = ts;
×
4109
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
×
4110
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4111
  }
4112
  pOffsetVal->primaryKey = primaryKey;
×
4113
}
×
4114

4115
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4116
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
×
4117
  pOffsetVal->uid = uid;
×
4118
}
×
4119

4120
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4121
  pOffsetVal->type = TMQ_OFFSET__LOG;
263,935✔
4122
  pOffsetVal->version = ver;
263,935✔
4123
}
263,935✔
4124

4125
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4126
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4127
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4128
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4129
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4130
void    tOffsetDestroy(void* pVal);
4131

4132
typedef struct {
4133
  STqOffsetVal val;
4134
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4135
} STqOffset;
4136

4137
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4138
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4139
void    tDeleteSTqOffset(void* val);
4140

4141
typedef struct SMqVgOffset {
4142
  int64_t   consumerId;
4143
  STqOffset offset;
4144
} SMqVgOffset;
4145

4146
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4147
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4148

4149
typedef struct {
4150
  SMsgHead head;
4151
  int64_t  streamId;
4152
  int32_t  taskId;
4153
} SVPauseStreamTaskReq;
4154

4155
typedef struct {
4156
  SMsgHead head;
4157
  int64_t  streamId;
4158
  int32_t  taskId;
4159
  int64_t  chkptId;
4160
} SVResetStreamTaskReq;
4161

4162
typedef struct {
4163
  char   name[TSDB_STREAM_FNAME_LEN];
4164
  int8_t igNotExists;
4165
} SMPauseStreamReq;
4166

4167
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4168
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4169

4170
typedef struct {
4171
  SMsgHead head;
4172
  int32_t  taskId;
4173
  int64_t  streamId;
4174
  int8_t   igUntreated;
4175
} SVResumeStreamTaskReq;
4176

4177
typedef struct {
4178
  int8_t reserved;
4179
} SVResumeStreamTaskRsp;
4180

4181
typedef struct {
4182
  char   name[TSDB_STREAM_FNAME_LEN];
4183
  int8_t igNotExists;
4184
  int8_t igUntreated;
4185
} SMResumeStreamReq;
4186

4187
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4188
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4189

4190
typedef struct {
4191
  char   name[TSDB_STREAM_FNAME_LEN];
4192
  int8_t igNotExists;
4193
  int8_t igUntreated;
4194
} SMResetStreamReq;
4195

4196
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
4197
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
4198

4199
typedef struct {
4200
  char    name[TSDB_TABLE_FNAME_LEN];
4201
  char    stb[TSDB_TABLE_FNAME_LEN];
4202
  int8_t  igExists;
4203
  int8_t  intervalUnit;
4204
  int8_t  slidingUnit;
4205
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4206
  int32_t dstVgId;   // for stream
4207
  int64_t interval;
4208
  int64_t offset;
4209
  int64_t sliding;
4210
  int64_t maxDelay;
4211
  int64_t watermark;
4212
  int32_t exprLen;        // strlen + 1
4213
  int32_t tagsFilterLen;  // strlen + 1
4214
  int32_t sqlLen;         // strlen + 1
4215
  int32_t astLen;         // strlen + 1
4216
  char*   expr;
4217
  char*   tagsFilter;
4218
  char*   sql;
4219
  char*   ast;
4220
  int64_t deleteMark;
4221
  int64_t lastTs;
4222
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4223
  SArray* pVgroupVerList;
4224
  int8_t  recursiveTsma;
4225
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4226
} SMCreateSmaReq;
4227

4228
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4229
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4230
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4231

4232
typedef struct {
4233
  char   name[TSDB_TABLE_FNAME_LEN];
4234
  int8_t igNotExists;
4235
} SMDropSmaReq;
4236

4237
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4238
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4239

4240
typedef struct {
4241
  char   dbFName[TSDB_DB_FNAME_LEN];
4242
  char   stbName[TSDB_TABLE_NAME_LEN];
4243
  char   colName[TSDB_COL_NAME_LEN];
4244
  char   idxName[TSDB_INDEX_FNAME_LEN];
4245
  int8_t idxType;
4246
} SCreateTagIndexReq;
4247

4248
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4249
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4250

4251
typedef SMDropSmaReq SDropTagIndexReq;
4252

4253
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4254
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4255

4256
typedef struct {
4257
  int8_t         version;       // for compatibility(default 0)
4258
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4259
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4260
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4261
  int32_t        dstVgId;
4262
  char           indexName[TSDB_INDEX_NAME_LEN];
4263
  int32_t        exprLen;
4264
  int32_t        tagsFilterLen;
4265
  int64_t        indexUid;
4266
  tb_uid_t       tableUid;  // super/child/common table uid
4267
  tb_uid_t       dstTbUid;  // for dstVgroup
4268
  int64_t        interval;
4269
  int64_t        offset;  // use unit by precision of DB
4270
  int64_t        sliding;
4271
  char*          dstTbName;  // for dstVgroup
4272
  char*          expr;       // sma expression
4273
  char*          tagsFilter;
4274
  SSchemaWrapper schemaRow;  // for dstVgroup
4275
  SSchemaWrapper schemaTag;  // for dstVgroup
4276
} STSma;                     // Time-range-wise SMA
4277

4278
typedef STSma SVCreateTSmaReq;
4279

4280
typedef struct {
4281
  int8_t  type;  // 0 status report, 1 update data
4282
  int64_t indexUid;
4283
  int64_t skey;  // start TS key of interval/sliding window
4284
} STSmaMsg;
4285

4286
typedef struct {
4287
  int64_t indexUid;
4288
  char    indexName[TSDB_INDEX_NAME_LEN];
4289
} SVDropTSmaReq;
4290

4291
typedef struct {
4292
  int tmp;  // TODO: to avoid compile error
4293
} SVCreateTSmaRsp, SVDropTSmaRsp;
4294

4295
#if 0
4296
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4297
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4298
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4299
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4300
#endif
4301

4302
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4303
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4304
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4305
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4306

4307
typedef struct {
4308
  int32_t number;
4309
  STSma*  tSma;
4310
} STSmaWrapper;
4311

4312
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4313
  if (pSma) {
×
4314
    taosMemoryFreeClear(pSma->dstTbName);
×
4315
    taosMemoryFreeClear(pSma->expr);
×
4316
    taosMemoryFreeClear(pSma->tagsFilter);
×
4317
  }
4318
}
×
4319

4320
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4321
  if (pSW) {
×
4322
    if (pSW->tSma) {
×
4323
      if (deepCopy) {
×
4324
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4325
          tDestroyTSma(pSW->tSma + i);
×
4326
        }
4327
      }
4328
      taosMemoryFreeClear(pSW->tSma);
×
4329
    }
4330
  }
4331
}
×
4332

4333
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4334
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4335
  taosMemoryFreeClear(pSW);
×
4336
  return NULL;
×
4337
}
4338

4339
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4340
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4341

4342
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4343
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4344

4345
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4346
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4347
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4348
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4349
  }
4350
  return 0;
×
4351
}
4352

4353
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4354
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4355
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4356
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4357
  }
4358
  return 0;
×
4359
}
4360

4361
typedef struct {
4362
  int idx;
4363
} SMCreateFullTextReq;
4364

4365
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4366
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4367
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4368

4369
typedef struct {
4370
  char   name[TSDB_TABLE_FNAME_LEN];
4371
  int8_t igNotExists;
4372
} SMDropFullTextReq;
4373

4374
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4375
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4376

4377
typedef struct {
4378
  char indexFName[TSDB_INDEX_FNAME_LEN];
4379
} SUserIndexReq;
4380

4381
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4382
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4383

4384
typedef struct {
4385
  char dbFName[TSDB_DB_FNAME_LEN];
4386
  char tblFName[TSDB_TABLE_FNAME_LEN];
4387
  char colName[TSDB_COL_NAME_LEN];
4388
  char indexType[TSDB_INDEX_TYPE_LEN];
4389
  char indexExts[TSDB_INDEX_EXTS_LEN];
4390
} SUserIndexRsp;
4391

4392
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4393
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4394

4395
typedef struct {
4396
  char tbFName[TSDB_TABLE_FNAME_LEN];
4397
} STableIndexReq;
4398

4399
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4400
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4401

4402
typedef struct {
4403
  int8_t  intervalUnit;
4404
  int8_t  slidingUnit;
4405
  int64_t interval;
4406
  int64_t offset;
4407
  int64_t sliding;
4408
  int64_t dstTbUid;
4409
  int32_t dstVgId;
4410
  SEpSet  epSet;
4411
  char*   expr;
4412
} STableIndexInfo;
4413

4414
typedef struct {
4415
  char     tbName[TSDB_TABLE_NAME_LEN];
4416
  char     dbFName[TSDB_DB_FNAME_LEN];
4417
  uint64_t suid;
4418
  int32_t  version;
4419
  int32_t  indexSize;
4420
  SArray*  pIndex;  // STableIndexInfo
4421
} STableIndexRsp;
4422

4423
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4424
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4425
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4426

4427
void tFreeSTableIndexInfo(void* pInfo);
4428

4429
typedef struct {
4430
  int8_t  mqMsgType;
4431
  int32_t code;
4432
  int32_t epoch;
4433
  int64_t consumerId;
4434
  int64_t walsver;
4435
  int64_t walever;
4436
} SMqRspHead;
4437

4438
typedef struct {
4439
  SMsgHead     head;
4440
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4441
  int8_t       withTbName;
4442
  int8_t       useSnapshot;
4443
  int32_t      epoch;
4444
  uint64_t     reqId;
4445
  int64_t      consumerId;
4446
  int64_t      timeout;
4447
  STqOffsetVal reqOffset;
4448
  int8_t       enableReplay;
4449
  int8_t       sourceExcluded;
4450
  int8_t       rawData;
4451
  int32_t      minPollRows;
4452
  int8_t       enableBatchMeta;
4453
  SHashObj     *uidHash;  // to find if uid is duplicated
4454
} SMqPollReq;
4455

4456
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4457
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4458
void    tDestroySMqPollReq(SMqPollReq* pReq);
4459

4460
typedef struct {
4461
  int32_t vgId;
4462
  int64_t offset;
4463
  SEpSet  epSet;
4464
} SMqSubVgEp;
4465

4466
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4467
  int32_t tlen = 0;
552✔
4468
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
552✔
4469
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
552✔
4470
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
552✔
4471
  return tlen;
552✔
4472
}
4473

4474
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4475
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
300!
4476
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
300!
4477
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
300✔
4478
  return buf;
300✔
4479
}
4480

4481
typedef struct {
4482
  char           topic[TSDB_TOPIC_FNAME_LEN];
4483
  char           db[TSDB_DB_FNAME_LEN];
4484
  SArray*        vgs;  // SArray<SMqSubVgEp>
4485
  SSchemaWrapper schema;
4486
} SMqSubTopicEp;
4487

4488
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4489
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4490
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4491

4492
typedef struct {
4493
  SMqRspHead   head;
4494
  STqOffsetVal rspOffset;
4495
  int16_t      resMsgType;
4496
  int32_t      metaRspLen;
4497
  void*        metaRsp;
4498
} SMqMetaRsp;
4499

4500
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4501
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4502
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4503

4504
#define MQ_DATA_RSP_VERSION 100
4505

4506
typedef struct {
4507
  SMqRspHead   head;
4508
  STqOffsetVal rspOffset;
4509
  STqOffsetVal reqOffset;
4510
  int32_t      blockNum;
4511
  int8_t       withTbName;
4512
  int8_t       withSchema;
4513
  SArray*      blockDataLen;
4514
  SArray*      blockData;
4515
  SArray*      blockTbName;
4516
  SArray*      blockSchema;
4517

4518
  union {
4519
    struct {
4520
      int64_t sleepTime;
4521
    };
4522
    struct {
4523
      int32_t createTableNum;
4524
      SArray* createTableLen;
4525
      SArray* createTableReq;
4526
    };
4527
    struct{
4528
      int32_t len;
4529
      void*   rawData;
4530
    };
4531
  };
4532
  void*   data;  //for free in client, only effected if type is data or metadata. raw data not effected
4533
  bool    blockDataElementFree;   // if true, free blockDataElement in blockData,(true in server, false in client)
4534
} SMqDataRsp;
4535

4536
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4537
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4538
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4539
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4540
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4541

4542
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4543
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4544
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4545

4546
typedef struct SMqBatchMetaRsp {
4547
  SMqRspHead   head;  // not serialize
4548
  STqOffsetVal rspOffset;
4549
  SArray*      batchMetaLen;
4550
  SArray*      batchMetaReq;
4551
  void*        pMetaBuff;    // not serialize
4552
  uint32_t     metaBuffLen;  // not serialize
4553
} SMqBatchMetaRsp;
4554

4555
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4556
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4557
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4558
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4559

4560
typedef struct {
4561
  SMqRspHead head;
4562
  char       cgroup[TSDB_CGROUP_LEN];
4563
  SArray*    topics;  // SArray<SMqSubTopicEp>
4564
} SMqAskEpRsp;
4565

4566
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4567
  int32_t tlen = 0;
568✔
4568
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4569
  int32_t sz = taosArrayGetSize(pRsp->topics);
568!
4570
  tlen += taosEncodeFixedI32(buf, sz);
568✔
4571
  for (int32_t i = 0; i < sz; i++) {
688✔
4572
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
120✔
4573
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
120✔
4574
  }
4575
  return tlen;
568✔
4576
}
4577

4578
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4579
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4580
  int32_t sz;
4581
  buf = taosDecodeFixedI32(buf, &sz);
685✔
4582
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
685✔
4583
  if (pRsp->topics == NULL) {
685!
4584
    return NULL;
×
4585
  }
4586
  for (int32_t i = 0; i < sz; i++) {
755✔
4587
    SMqSubTopicEp topicEp;
4588
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
70✔
4589
    if (buf == NULL) {
70!
4590
      return NULL;
×
4591
    }
4592
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
140!
4593
      return NULL;
×
4594
    }
4595
  }
4596
  return buf;
685✔
4597
}
4598

4599
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4600
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
1,206✔
4601
}
1,206✔
4602

4603
typedef struct {
4604
  int32_t      vgId;
4605
  STqOffsetVal offset;
4606
  int64_t      rows;
4607
  int64_t      ever;
4608
} OffsetRows;
4609

4610
typedef struct {
4611
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4612
  SArray* offsetRows;
4613
} TopicOffsetRows;
4614

4615
typedef struct {
4616
  int64_t consumerId;
4617
  int32_t epoch;
4618
  SArray* topics;
4619
  int8_t  pollFlag;
4620
} SMqHbReq;
4621

4622
typedef struct {
4623
  char   topic[TSDB_TOPIC_FNAME_LEN];
4624
  int8_t noPrivilege;
4625
} STopicPrivilege;
4626

4627
typedef struct {
4628
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4629
  int32_t debugFlag;
4630
} SMqHbRsp;
4631

4632
typedef struct {
4633
  SMsgHead head;
4634
  int64_t  consumerId;
4635
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4636
} SMqSeekReq;
4637

4638
#define TD_AUTO_CREATE_TABLE 0x1
4639
typedef struct {
4640
  int64_t       suid;
4641
  int64_t       uid;
4642
  int32_t       sver;
4643
  uint32_t      nData;
4644
  uint8_t*      pData;
4645
  SVCreateTbReq cTbReq;
4646
} SVSubmitBlk;
4647

4648
typedef struct {
4649
  SMsgHead header;
4650
  uint64_t sId;
4651
  uint64_t queryId;
4652
  uint64_t clientId;
4653
  uint64_t taskId;
4654
  uint32_t sqlLen;
4655
  uint32_t phyLen;
4656
  char*    sql;
4657
  char*    msg;
4658
  int8_t   source;
4659
} SVDeleteReq;
4660

4661
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4662
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4663

4664
typedef struct {
4665
  int64_t affectedRows;
4666
} SVDeleteRsp;
4667

4668
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4669
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4670

4671
typedef struct SDeleteRes {
4672
  uint64_t suid;
4673
  SArray*  uidList;
4674
  int64_t  skey;
4675
  int64_t  ekey;
4676
  int64_t  affectedRows;
4677
  char     tableFName[TSDB_TABLE_NAME_LEN];
4678
  char     tsColName[TSDB_COL_NAME_LEN];
4679
  int64_t  ctimeMs;  // fill by vnode
4680
  int8_t   source;
4681
} SDeleteRes;
4682

4683
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4684
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4685

4686
typedef struct {
4687
  // int64_t uid;
4688
  char    tbname[TSDB_TABLE_NAME_LEN];
4689
  int64_t startTs;
4690
  int64_t endTs;
4691
} SSingleDeleteReq;
4692

4693
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4694
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4695

4696
typedef struct {
4697
  int64_t suid;
4698
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4699
  int64_t ctimeMs;     // fill by vnode
4700
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4701
} SBatchDeleteReq;
4702

4703
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4704
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4705
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4706

4707
typedef struct {
4708
  int32_t msgIdx;
4709
  int32_t msgType;
4710
  int32_t msgLen;
4711
  void*   msg;
4712
} SBatchMsg;
4713

4714
typedef struct {
4715
  SMsgHead header;
4716
  SArray*  pMsgs;  // SArray<SBatchMsg>
4717
} SBatchReq;
4718

4719
typedef struct {
4720
  int32_t reqType;
4721
  int32_t msgIdx;
4722
  int32_t msgLen;
4723
  int32_t rspCode;
4724
  void*   msg;
4725
} SBatchRspMsg;
4726

4727
typedef struct {
4728
  SArray* pRsps;  // SArray<SBatchRspMsg>
4729
} SBatchRsp;
4730

4731
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4732
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4733
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
1,649✔
4734
  if (NULL == msg) {
1,649!
4735
    return;
×
4736
  }
4737
  SBatchMsg* pMsg = (SBatchMsg*)msg;
1,649✔
4738
  taosMemoryFree(pMsg->msg);
1,649!
4739
}
4740

4741
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4742
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4743

4744
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
5,387✔
4745
  if (NULL == p) {
5,387!
4746
    return;
×
4747
  }
4748

4749
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
5,387✔
4750
  taosMemoryFree(pRsp->msg);
5,387!
4751
}
4752

4753
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4754
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4755
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4756
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4757
void    tDestroySMqHbReq(SMqHbReq* pReq);
4758

4759
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4760
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4761
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4762

4763
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4764
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4765

4766
#define TD_REQ_FROM_APP               0x0
4767
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4768
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4769
#define SUBMIT_REQ_FROM_FILE          0x4
4770
#define TD_REQ_FROM_TAOX              0x8
4771
#define SUBMIT_REQUEST_VERSION        (1)
4772

4773
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4774

4775
typedef struct {
4776
  int32_t        flags;
4777
  SVCreateTbReq* pCreateTbReq;
4778
  int64_t        suid;
4779
  int64_t        uid;
4780
  int32_t        sver;
4781
  union {
4782
    SArray* aRowP;
4783
    SArray* aCol;
4784
  };
4785
  int64_t ctimeMs;
4786
} SSubmitTbData;
4787

4788
typedef struct {
4789
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4790
  bool    raw;
4791
} SSubmitReq2;
4792

4793
typedef struct {
4794
  SMsgHead header;
4795
  int64_t  version;
4796
  char     data[];  // SSubmitReq2
4797
} SSubmitReq2Msg;
4798

4799
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4800
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4801
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4802
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4803
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4804

4805
typedef struct {
4806
  int32_t affectedRows;
4807
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4808
} SSubmitRsp2;
4809

4810
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4811
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4812
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4813

4814
#define TSDB_MSG_FLG_ENCODE 0x1
4815
#define TSDB_MSG_FLG_DECODE 0x2
4816
#define TSDB_MSG_FLG_CMPT   0x3
4817

4818
typedef struct {
4819
  union {
4820
    struct {
4821
      void*   msgStr;
4822
      int32_t msgLen;
4823
      int64_t ver;
4824
    };
4825
    void* pDataBlock;
4826
  };
4827
} SPackedData;
4828

4829
typedef struct {
4830
  char     fullname[TSDB_VIEW_FNAME_LEN];
4831
  char     name[TSDB_VIEW_NAME_LEN];
4832
  char     dbFName[TSDB_DB_FNAME_LEN];
4833
  char*    querySql;
4834
  char*    sql;
4835
  int8_t   orReplace;
4836
  int8_t   precision;
4837
  int32_t  numOfCols;
4838
  SSchema* pSchema;
4839
} SCMCreateViewReq;
4840

4841
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4842
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4843
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4844

4845
typedef struct {
4846
  char   fullname[TSDB_VIEW_FNAME_LEN];
4847
  char   name[TSDB_VIEW_NAME_LEN];
4848
  char   dbFName[TSDB_DB_FNAME_LEN];
4849
  char*  sql;
4850
  int8_t igNotExists;
4851
} SCMDropViewReq;
4852

4853
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4854
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4855
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4856

4857
typedef struct {
4858
  char fullname[TSDB_VIEW_FNAME_LEN];
4859
} SViewMetaReq;
4860
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4861
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4862

4863
typedef struct {
4864
  char     name[TSDB_VIEW_NAME_LEN];
4865
  char     dbFName[TSDB_DB_FNAME_LEN];
4866
  char*    user;
4867
  uint64_t dbId;
4868
  uint64_t viewId;
4869
  char*    querySql;
4870
  int8_t   precision;
4871
  int8_t   type;
4872
  int32_t  version;
4873
  int32_t  numOfCols;
4874
  SSchema* pSchema;
4875
} SViewMetaRsp;
4876
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4877
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4878
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4879
typedef struct {
4880
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4881
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4882
} STableTSMAInfoReq;
4883

4884
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4885
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4886

4887
typedef struct {
4888
  int32_t  funcId;
4889
  col_id_t colId;
4890
} STableTSMAFuncInfo;
4891

4892
typedef struct {
4893
  char     name[TSDB_TABLE_NAME_LEN];
4894
  uint64_t tsmaId;
4895
  char     targetTb[TSDB_TABLE_NAME_LEN];
4896
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4897
  char     tb[TSDB_TABLE_NAME_LEN];
4898
  char     dbFName[TSDB_DB_FNAME_LEN];
4899
  uint64_t suid;
4900
  uint64_t destTbUid;
4901
  uint64_t dbId;
4902
  int32_t  version;
4903
  int64_t  interval;
4904
  int8_t   unit;
4905
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4906
  SArray*  pTags;      // SArray<SSchema>
4907
  SArray*  pUsedCols;  // SArray<SSchema>
4908
  char*    ast;
4909

4910
  int64_t streamUid;
4911
  int64_t reqTs;
4912
  int64_t rspTs;
4913
  int64_t delayDuration;  // ms
4914
  bool    fillHistoryFinished;
4915
} STableTSMAInfo;
4916

4917
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4918
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4919
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4920
void    tFreeTableTSMAInfo(void* p);
4921
void    tFreeAndClearTableTSMAInfo(void* p);
4922
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4923

4924
#define STSMAHbRsp            STableTSMAInfoRsp
4925
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4926
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4927
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4928

4929
typedef struct SStreamProgressReq {
4930
  int64_t streamId;
4931
  int32_t vgId;
4932
  int32_t fetchIdx;
4933
  int32_t subFetchIdx;
4934
} SStreamProgressReq;
4935

4936
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4937
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4938

4939
typedef struct SStreamProgressRsp {
4940
  int64_t streamId;
4941
  int32_t vgId;
4942
  bool    fillHisFinished;
4943
  int64_t progressDelay;
4944
  int32_t fetchIdx;
4945
  int32_t subFetchIdx;
4946
} SStreamProgressRsp;
4947

4948
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4949
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4950

4951
typedef struct SDropCtbWithTsmaSingleVgReq {
4952
  SVgroupInfo vgInfo;
4953
  SArray*     pTbs;  // SVDropTbReq
4954
} SMDropTbReqsOnSingleVg;
4955

4956
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4957
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4958
void    tFreeSMDropTbReqOnSingleVg(void* p);
4959

4960
typedef struct SDropTbsReq {
4961
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4962
} SMDropTbsReq;
4963

4964
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4965
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4966
void    tFreeSMDropTbsReq(void*);
4967

4968
typedef struct SVFetchTtlExpiredTbsRsp {
4969
  SArray* pExpiredTbs;  // SVDropTbReq
4970
  int32_t vgId;
4971
} SVFetchTtlExpiredTbsRsp;
4972

4973
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4974
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4975

4976
void tFreeFetchTtlExpiredTbsRsp(void* p);
4977

4978
void setDefaultOptionsForField(SFieldWithOptions* field);
4979
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4980

4981
#pragma pack(pop)
4982

4983
#ifdef __cplusplus
4984
}
4985
#endif
4986

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