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

taosdata / TDengine / #3796

31 Mar 2025 10:39AM UTC coverage: 30.372% (-7.1%) from 37.443%
#3796

push

travis-ci

happyguoxy
test:add test cases

69287 of 309062 branches covered (22.42%)

Branch coverage included in aggregate %.

118044 of 307720 relevant lines covered (38.36%)

278592.15 hits per line

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

27.95
/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) {
300,052✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
300,052✔
74
  int    segIdx = TMSG_SEG_CODE(type);
300,052✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
300,052!
76
    return type < tMsgRangeDict[segIdx];
300,072✔
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) {
50✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
49!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
99!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
984✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
984!
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) {
274!
801
    return TSDB_CODE_INVALID_PARA;
×
802
  }
803
  pRef->pColRef = (SColRef*)taosMemoryCalloc(nCols, sizeof(SColRef));
274!
804
  if (pRef->pColRef == NULL) {
274!
805
    return terrno;
×
806
  }
807
  pRef->nCols = nCols;
274✔
808
  for (int32_t i = 0; i < nCols; i++) {
4,125✔
809
    pRef->pColRef[i].hasRef = false;
3,851✔
810
    pRef->pColRef[i].id = (col_id_t)(i + 1);
3,851✔
811
  }
812
  return 0;
274✔
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)) {
611!
841
    return TSDB_CODE_INVALID_PARA;
×
842
  }
843
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
611!
844
  if (pCmpr->pColCmpr == NULL) {
611!
845
    return terrno;
×
846
  }
847
  pCmpr->nCols = nCols;
611✔
848
  return 0;
611✔
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;
92!
877

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

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

894
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
6✔
895
  if (pSchemaWrapper) {
194!
896
    taosMemoryFree(pSchemaWrapper->pSchema);
95!
897
    taosMemoryFree(pSchemaWrapper);
95!
898
  }
899
}
194✔
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;
×
910
  tlen += taosEncodeFixedI8(buf, pSchema->type);
×
911
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
×
912
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
×
913
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
×
914
  tlen += taosEncodeString(buf, pSchema->name);
×
915
  return tlen;
×
916
}
917

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

927
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
928
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
16,990!
929
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
32,804!
930
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
32,804!
931
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
32,804!
932
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
32,804!
933
  return 0;
16,402✔
934
}
935

936
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
937
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
40,710!
938
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
41,834!
939
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
41,834!
940
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
41,834!
941
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
20,917!
942
  return 0;
20,917✔
943
}
944

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

952
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
953
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
26,352!
954
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
26,352!
955
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pSchemaExt->typeMod));
26,352!
956
  return 0;
13,176✔
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));
14,486!
972
  TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pColRef->id));
14,486!
973
  if (pColRef->hasRef) {
7,243✔
974
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refDbName));
4,031!
975
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refTableName));
4,031!
976
    TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pColRef->refColName));
4,031!
977
  }
978

979
  return 0;
7,243✔
980
}
981

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

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

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

1010
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
1011
  if (pSW == NULL) {return TSDB_CODE_INVALID_PARA;}
1,864!
1012
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
3,728!
1013
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
3,728!
1014
  for (int32_t i = 0; i < pSW->nCols; i++) {
17,678!
1015
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
31,628!
1016
  }
1017
  return 0;
1,864✔
1018
}
1019

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

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

1033
  return 0;
6✔
1034
}
1035

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

1040
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
336!
1041
  if (pSW->pSchema == NULL) {
336!
1042
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
1043
  }
1044
  for (int32_t i = 0; i < pSW->nCols; i++) {
1,436!
1045
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
2,200!
1046
  }
1047

1048
  return 0;
336✔
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

1472
typedef struct {
1473
  char    db[TSDB_DB_FNAME_LEN];
1474
  int32_t numOfVgroups;
1475
  int32_t numOfStables;  // single_stable
1476
  int32_t buffer;        // MB
1477
  int32_t pageSize;
1478
  int32_t pages;
1479
  int32_t cacheLastSize;
1480
  int32_t daysPerFile;
1481
  int32_t daysToKeep0;
1482
  int32_t daysToKeep1;
1483
  int32_t daysToKeep2;
1484
  int32_t keepTimeOffset;
1485
  int32_t minRows;
1486
  int32_t maxRows;
1487
  int32_t walFsyncPeriod;
1488
  int8_t  walLevel;
1489
  int8_t  precision;  // time resolution
1490
  int8_t  compression;
1491
  int8_t  replications;
1492
  int8_t  strict;
1493
  int8_t  cacheLast;
1494
  int8_t  schemaless;
1495
  int8_t  ignoreExist;
1496
  int32_t numOfRetensions;
1497
  SArray* pRetensions;  // SRetention
1498
  int32_t walRetentionPeriod;
1499
  int64_t walRetentionSize;
1500
  int32_t walRollPeriod;
1501
  int64_t walSegmentSize;
1502
  int32_t sstTrigger;
1503
  int16_t hashPrefix;
1504
  int16_t hashSuffix;
1505
  int32_t s3ChunkSize;
1506
  int32_t s3KeepLocal;
1507
  int8_t  s3Compact;
1508
  int32_t tsdbPageSize;
1509
  int32_t sqlLen;
1510
  char*   sql;
1511
  int8_t  withArbitrator;
1512
  int8_t  encryptAlgorithm;
1513
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1514
  // 1. add auto-compact parameters
1515
  int32_t compactInterval;    // minutes
1516
  int32_t compactStartTime;   // minutes
1517
  int32_t compactEndTime;     // minutes
1518
  int8_t  compactTimeOffset;  // hour
1519
} SCreateDbReq;
1520

1521
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1522
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1523
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1524

1525
typedef struct {
1526
  char    db[TSDB_DB_FNAME_LEN];
1527
  int32_t buffer;
1528
  int32_t pageSize;
1529
  int32_t pages;
1530
  int32_t cacheLastSize;
1531
  int32_t daysPerFile;
1532
  int32_t daysToKeep0;
1533
  int32_t daysToKeep1;
1534
  int32_t daysToKeep2;
1535
  int32_t keepTimeOffset;
1536
  int32_t walFsyncPeriod;
1537
  int8_t  walLevel;
1538
  int8_t  strict;
1539
  int8_t  cacheLast;
1540
  int8_t  replications;
1541
  int32_t sstTrigger;
1542
  int32_t minRows;
1543
  int32_t walRetentionPeriod;
1544
  int32_t walRetentionSize;
1545
  int32_t s3KeepLocal;
1546
  int8_t  s3Compact;
1547
  int32_t sqlLen;
1548
  char*   sql;
1549
  int8_t  withArbitrator;
1550
  // 1. add auto-compact parameters
1551
  int32_t compactInterval;
1552
  int32_t compactStartTime;
1553
  int32_t compactEndTime;
1554
  int8_t  compactTimeOffset;
1555
} SAlterDbReq;
1556

1557
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1558
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1559
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1560

1561
typedef struct {
1562
  char    db[TSDB_DB_FNAME_LEN];
1563
  int8_t  ignoreNotExists;
1564
  int32_t sqlLen;
1565
  char*   sql;
1566
} SDropDbReq;
1567

1568
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1569
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1570
void    tFreeSDropDbReq(SDropDbReq* pReq);
1571

1572
typedef struct {
1573
  char    db[TSDB_DB_FNAME_LEN];
1574
  int64_t uid;
1575
} SDropDbRsp;
1576

1577
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1578
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1579

1580
typedef struct {
1581
  char    db[TSDB_DB_FNAME_LEN];
1582
  int64_t dbId;
1583
  int32_t vgVersion;
1584
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1585
  int64_t stateTs;     // ms
1586
} SUseDbReq;
1587

1588
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1589
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1590

1591
typedef struct {
1592
  char    db[TSDB_DB_FNAME_LEN];
1593
  int64_t uid;
1594
  int32_t vgVersion;
1595
  int32_t vgNum;
1596
  int16_t hashPrefix;
1597
  int16_t hashSuffix;
1598
  int8_t  hashMethod;
1599
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1600
  int32_t errCode;
1601
  int64_t stateTs;  // ms
1602
} SUseDbRsp;
1603

1604
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1605
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1606
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1607
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1608
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1609

1610
typedef struct {
1611
  char db[TSDB_DB_FNAME_LEN];
1612
} SDbCfgReq;
1613

1614
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1615
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1616

1617
typedef struct {
1618
  char    db[TSDB_DB_FNAME_LEN];
1619
  int32_t maxSpeed;
1620
} STrimDbReq;
1621

1622
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1623
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1624

1625
typedef struct {
1626
  int32_t timestamp;
1627
} SVTrimDbReq;
1628

1629
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1630
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1631

1632
typedef struct {
1633
  char db[TSDB_DB_FNAME_LEN];
1634
} SS3MigrateDbReq;
1635

1636
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1637
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1638

1639
typedef struct {
1640
  int32_t timestamp;
1641
} SVS3MigrateDbReq;
1642

1643
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1644
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1645

1646
typedef struct {
1647
  int32_t timestampSec;
1648
  int32_t ttlDropMaxCount;
1649
  int32_t nUids;
1650
  SArray* pTbUids;
1651
} SVDropTtlTableReq;
1652

1653
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1654
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1655

1656
typedef struct {
1657
  char    db[TSDB_DB_FNAME_LEN];
1658
  int64_t dbId;
1659
  int32_t cfgVersion;
1660
  int32_t numOfVgroups;
1661
  int32_t numOfStables;
1662
  int32_t buffer;
1663
  int32_t cacheSize;
1664
  int32_t pageSize;
1665
  int32_t pages;
1666
  int32_t daysPerFile;
1667
  int32_t daysToKeep0;
1668
  int32_t daysToKeep1;
1669
  int32_t daysToKeep2;
1670
  int32_t keepTimeOffset;
1671
  int32_t minRows;
1672
  int32_t maxRows;
1673
  int32_t walFsyncPeriod;
1674
  int16_t hashPrefix;
1675
  int16_t hashSuffix;
1676
  int8_t  hashMethod;
1677
  int8_t  walLevel;
1678
  int8_t  precision;
1679
  int8_t  compression;
1680
  int8_t  replications;
1681
  int8_t  strict;
1682
  int8_t  cacheLast;
1683
  int8_t  encryptAlgorithm;
1684
  int32_t s3ChunkSize;
1685
  int32_t s3KeepLocal;
1686
  int8_t  s3Compact;
1687
  int8_t  compactTimeOffset;
1688
  int32_t compactInterval;
1689
  int32_t compactStartTime;
1690
  int32_t compactEndTime;
1691
  int32_t tsdbPageSize;
1692
  int32_t walRetentionPeriod;
1693
  int32_t walRollPeriod;
1694
  int64_t walRetentionSize;
1695
  int64_t walSegmentSize;
1696
  int32_t numOfRetensions;
1697
  SArray* pRetensions;
1698
  int8_t  schemaless;
1699
  int16_t sstTrigger;
1700
  int8_t  withArbitrator;
1701
} SDbCfgRsp;
1702

1703
typedef SDbCfgRsp SDbCfgInfo;
1704

1705
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1706
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1707
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1708
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1709
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1710

1711
typedef struct {
1712
  int32_t rowNum;
1713
} SQnodeListReq;
1714

1715
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1716
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1717

1718
typedef struct {
1719
  int32_t rowNum;
1720
} SDnodeListReq;
1721

1722
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1723

1724
typedef struct {
1725
  int32_t useless;  // useless
1726
} SServerVerReq;
1727

1728
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1729
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1730

1731
typedef struct {
1732
  char ver[TSDB_VERSION_LEN];
1733
} SServerVerRsp;
1734

1735
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1736
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1737

1738
typedef struct SQueryNodeAddr {
1739
  int32_t nodeId;  // vgId or qnodeId
1740
  SEpSet  epSet;
1741
} SQueryNodeAddr;
1742

1743
typedef struct {
1744
  SQueryNodeAddr addr;
1745
  uint64_t       load;
1746
} SQueryNodeLoad;
1747

1748
typedef struct {
1749
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1750
} SQnodeListRsp;
1751

1752
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1753
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1754
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1755

1756
typedef struct {
1757
  SArray* dnodeList;  // SArray<SEpSet>
1758
} SDnodeListRsp;
1759

1760
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1761
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1762
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1763

1764
typedef struct {
1765
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1766
} STableTSMAInfoRsp;
1767

1768
typedef struct {
1769
  SUseDbRsp*         useDbRsp;
1770
  SDbCfgRsp*         cfgRsp;
1771
  STableTSMAInfoRsp* pTsmaRsp;
1772
  int32_t            dbTsmaVersion;
1773
  char               db[TSDB_DB_FNAME_LEN];
1774
  int64_t            dbId;
1775
} SDbHbRsp;
1776

1777
typedef struct {
1778
  SArray* pArray;  // Array of SDbHbRsp
1779
} SDbHbBatchRsp;
1780

1781
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1782
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1783
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1784

1785
typedef struct {
1786
  SArray* pArray;  // Array of SGetUserAuthRsp
1787
} SUserAuthBatchRsp;
1788

1789
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1790
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1791
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1792

1793
typedef struct {
1794
  char        db[TSDB_DB_FNAME_LEN];
1795
  STimeWindow timeRange;
1796
  int32_t     sqlLen;
1797
  char*       sql;
1798
  SArray*     vgroupIds;
1799
  int8_t      metaOnly;
1800
} SCompactDbReq;
1801

1802
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1803
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1804
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1805

1806
typedef struct {
1807
  int32_t compactId;
1808
  int8_t  bAccepted;
1809
} SCompactDbRsp;
1810

1811
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1812
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1813

1814
typedef struct {
1815
  int32_t compactId;
1816
  int32_t sqlLen;
1817
  char*   sql;
1818
} SKillCompactReq;
1819

1820
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1821
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1822
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1823

1824
typedef struct {
1825
  char    name[TSDB_FUNC_NAME_LEN];
1826
  int8_t  igExists;
1827
  int8_t  funcType;
1828
  int8_t  scriptType;
1829
  int8_t  outputType;
1830
  int32_t outputLen;
1831
  int32_t bufSize;
1832
  int32_t codeLen;
1833
  int64_t signature;
1834
  char*   pComment;
1835
  char*   pCode;
1836
  int8_t  orReplace;
1837
} SCreateFuncReq;
1838

1839
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1840
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1841
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1842

1843
typedef struct {
1844
  char   name[TSDB_FUNC_NAME_LEN];
1845
  int8_t igNotExists;
1846
} SDropFuncReq;
1847

1848
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1849
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1850

1851
typedef struct {
1852
  int32_t numOfFuncs;
1853
  bool    ignoreCodeComment;
1854
  SArray* pFuncNames;
1855
} SRetrieveFuncReq;
1856

1857
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1858
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1859
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1860

1861
typedef struct {
1862
  char    name[TSDB_FUNC_NAME_LEN];
1863
  int8_t  funcType;
1864
  int8_t  scriptType;
1865
  int8_t  outputType;
1866
  int32_t outputLen;
1867
  int32_t bufSize;
1868
  int64_t signature;
1869
  int32_t commentSize;
1870
  int32_t codeSize;
1871
  char*   pComment;
1872
  char*   pCode;
1873
} SFuncInfo;
1874

1875
typedef struct {
1876
  int32_t funcVersion;
1877
  int64_t funcCreatedTime;
1878
} SFuncExtraInfo;
1879

1880
typedef struct {
1881
  int32_t numOfFuncs;
1882
  SArray* pFuncInfos;
1883
  SArray* pFuncExtraInfos;
1884
} SRetrieveFuncRsp;
1885

1886
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1887
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1888
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1889
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1890

1891
typedef struct {
1892
  int32_t       statusInterval;
1893
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
1894
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
1895
  char          locale[TD_LOCALE_LEN];      // tsLocale
1896
  char          charset[TD_LOCALE_LEN];     // tsCharset
1897
  int8_t        ttlChangeOnWrite;
1898
  int8_t        enableWhiteList;
1899
  int8_t        encryptionKeyStat;
1900
  uint32_t      encryptionKeyChksum;
1901
  SMonitorParas monitorParas;
1902
} SClusterCfg;
1903

1904
typedef struct {
1905
  int32_t openVnodes;
1906
  int32_t dropVnodes;
1907
  int32_t totalVnodes;
1908
  int32_t masterNum;
1909
  int64_t numOfSelectReqs;
1910
  int64_t numOfInsertReqs;
1911
  int64_t numOfInsertSuccessReqs;
1912
  int64_t numOfBatchInsertReqs;
1913
  int64_t numOfBatchInsertSuccessReqs;
1914
  int64_t errors;
1915
} SVnodesStat;
1916

1917
typedef struct {
1918
  int32_t vgId;
1919
  int8_t  syncState;
1920
  int8_t  syncRestore;
1921
  int64_t syncTerm;
1922
  int64_t roleTimeMs;
1923
  int64_t startTimeMs;
1924
  int8_t  syncCanRead;
1925
  int64_t cacheUsage;
1926
  int64_t numOfTables;
1927
  int64_t numOfTimeSeries;
1928
  int64_t totalStorage;
1929
  int64_t compStorage;
1930
  int64_t pointsWritten;
1931
  int64_t numOfSelectReqs;
1932
  int64_t numOfInsertReqs;
1933
  int64_t numOfInsertSuccessReqs;
1934
  int64_t numOfBatchInsertReqs;
1935
  int64_t numOfBatchInsertSuccessReqs;
1936
  int32_t numOfCachedTables;
1937
  int32_t learnerProgress;  // use one reservered
1938
  int64_t syncAppliedIndex;
1939
  int64_t syncCommitIndex;
1940
} SVnodeLoad;
1941

1942
typedef struct {
1943
  int32_t     vgId;
1944
  int64_t     numOfTables;
1945
  int64_t     memSize;
1946
  int64_t     l1Size;
1947
  int64_t     l2Size;
1948
  int64_t     l3Size;
1949
  int64_t     cacheSize;
1950
  int64_t     walSize;
1951
  int64_t     metaSize;
1952
  int64_t     rawDataSize;
1953
  int64_t     s3Size;
1954
  const char* dbname;
1955
} SDbSizeStatisInfo;
1956

1957
typedef struct {
1958
  int32_t vgId;
1959
  int64_t nTimeSeries;
1960
} SVnodeLoadLite;
1961

1962
typedef struct {
1963
  int8_t  syncState;
1964
  int64_t syncTerm;
1965
  int8_t  syncRestore;
1966
  int64_t roleTimeMs;
1967
} SMnodeLoad;
1968

1969
typedef struct {
1970
  int32_t dnodeId;
1971
  int64_t numOfProcessedQuery;
1972
  int64_t numOfProcessedCQuery;
1973
  int64_t numOfProcessedFetch;
1974
  int64_t numOfProcessedDrop;
1975
  int64_t numOfProcessedNotify;
1976
  int64_t numOfProcessedHb;
1977
  int64_t numOfProcessedDelete;
1978
  int64_t cacheDataSize;
1979
  int64_t numOfQueryInQueue;
1980
  int64_t numOfFetchInQueue;
1981
  int64_t timeInQueryQueue;
1982
  int64_t timeInFetchQueue;
1983
} SQnodeLoad;
1984

1985
typedef struct {
1986
  int32_t     sver;      // software version
1987
  int64_t     dnodeVer;  // dnode table version in sdb
1988
  int32_t     dnodeId;
1989
  int64_t     clusterId;
1990
  int64_t     rebootTime;
1991
  int64_t     updateTime;
1992
  float       numOfCores;
1993
  int32_t     numOfSupportVnodes;
1994
  int32_t     numOfDiskCfg;
1995
  int64_t     memTotal;
1996
  int64_t     memAvail;
1997
  char        dnodeEp[TSDB_EP_LEN];
1998
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
1999
  SMnodeLoad  mload;
2000
  SQnodeLoad  qload;
2001
  SClusterCfg clusterCfg;
2002
  SArray*     pVloads;  // array of SVnodeLoad
2003
  int32_t     statusSeq;
2004
  int64_t     ipWhiteVer;
2005
  int64_t     analVer;
2006
  int64_t     timestamp;
2007
} SStatusReq;
2008

2009
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2010
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
2011
void    tFreeSStatusReq(SStatusReq* pReq);
2012

2013
typedef struct {
2014
  int32_t forceReadConfig;
2015
  int32_t cver;
2016
  SArray* array;
2017
} SConfigReq;
2018

2019
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2020
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
2021
void    tFreeSConfigReq(SConfigReq* pReq);
2022

2023
typedef struct {
2024
  int32_t dnodeId;
2025
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
2026
} SDnodeInfoReq;
2027

2028
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2029
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
2030

2031
typedef enum {
2032
  MONITOR_TYPE_COUNTER = 0,
2033
  MONITOR_TYPE_SLOW_LOG = 1,
2034
} MONITOR_TYPE;
2035

2036
typedef struct {
2037
  int32_t      contLen;
2038
  char*        pCont;
2039
  MONITOR_TYPE type;
2040
} SStatisReq;
2041

2042
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2043
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
2044
void    tFreeSStatisReq(SStatisReq* pReq);
2045

2046
typedef struct {
2047
  char    db[TSDB_DB_FNAME_LEN];
2048
  char    table[TSDB_TABLE_NAME_LEN];
2049
  char    operation[AUDIT_OPERATION_LEN];
2050
  int32_t sqlLen;
2051
  char*   pSql;
2052
} SAuditReq;
2053
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2054
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
2055
void    tFreeSAuditReq(SAuditReq* pReq);
2056

2057
typedef struct {
2058
  int32_t dnodeId;
2059
  int64_t clusterId;
2060
  SArray* pVloads;
2061
} SNotifyReq;
2062

2063
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2064
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
2065
void    tFreeSNotifyReq(SNotifyReq* pReq);
2066

2067
typedef struct {
2068
  int32_t dnodeId;
2069
  int64_t clusterId;
2070
} SDnodeCfg;
2071

2072
typedef struct {
2073
  int32_t id;
2074
  int8_t  isMnode;
2075
  SEp     ep;
2076
} SDnodeEp;
2077

2078
typedef struct {
2079
  int32_t id;
2080
  int8_t  isMnode;
2081
  int8_t  offlineReason;
2082
  SEp     ep;
2083
  char    active[TSDB_ACTIVE_KEY_LEN];
2084
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
2085
} SDnodeInfo;
2086

2087
typedef struct {
2088
  int64_t   dnodeVer;
2089
  SDnodeCfg dnodeCfg;
2090
  SArray*   pDnodeEps;  // Array of SDnodeEp
2091
  int32_t   statusSeq;
2092
  int64_t   ipWhiteVer;
2093
  int64_t   analVer;
2094
} SStatusRsp;
2095

2096
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2097
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
2098
void    tFreeSStatusRsp(SStatusRsp* pRsp);
2099

2100
typedef struct {
2101
  int32_t forceReadConfig;
2102
  int32_t isConifgVerified;
2103
  int32_t isVersionVerified;
2104
  int32_t cver;
2105
  SArray* array;
2106
} SConfigRsp;
2107

2108
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2109
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
2110
void    tFreeSConfigRsp(SConfigRsp* pRsp);
2111

2112
typedef struct {
2113
  int32_t reserved;
2114
} SMTimerReq;
2115

2116
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2117
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
2118

2119
typedef struct SOrphanTask {
2120
  int64_t streamId;
2121
  int32_t taskId;
2122
  int32_t nodeId;
2123
} SOrphanTask;
2124

2125
typedef struct SMStreamDropOrphanMsg {
2126
  SArray* pList;  // SArray<SOrphanTask>
2127
} SMStreamDropOrphanMsg;
2128

2129
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2130
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
2131
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
2132

2133
typedef struct {
2134
  int32_t  id;
2135
  uint16_t port;                 // node sync Port
2136
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
2137
} SReplica;
2138

2139
typedef struct {
2140
  int32_t  vgId;
2141
  char     db[TSDB_DB_FNAME_LEN];
2142
  int64_t  dbUid;
2143
  int32_t  vgVersion;
2144
  int32_t  numOfStables;
2145
  int32_t  buffer;
2146
  int32_t  pageSize;
2147
  int32_t  pages;
2148
  int32_t  cacheLastSize;
2149
  int32_t  daysPerFile;
2150
  int32_t  daysToKeep0;
2151
  int32_t  daysToKeep1;
2152
  int32_t  daysToKeep2;
2153
  int32_t  keepTimeOffset;
2154
  int32_t  minRows;
2155
  int32_t  maxRows;
2156
  int32_t  walFsyncPeriod;
2157
  uint32_t hashBegin;
2158
  uint32_t hashEnd;
2159
  int8_t   hashMethod;
2160
  int8_t   walLevel;
2161
  int8_t   precision;
2162
  int8_t   compression;
2163
  int8_t   strict;
2164
  int8_t   cacheLast;
2165
  int8_t   isTsma;
2166
  int8_t   replica;
2167
  int8_t   selfIndex;
2168
  SReplica replicas[TSDB_MAX_REPLICA];
2169
  int32_t  numOfRetensions;
2170
  SArray*  pRetensions;  // SRetention
2171
  void*    pTsma;
2172
  int32_t  walRetentionPeriod;
2173
  int64_t  walRetentionSize;
2174
  int32_t  walRollPeriod;
2175
  int64_t  walSegmentSize;
2176
  int16_t  sstTrigger;
2177
  int16_t  hashPrefix;
2178
  int16_t  hashSuffix;
2179
  int32_t  tsdbPageSize;
2180
  int32_t  s3ChunkSize;
2181
  int32_t  s3KeepLocal;
2182
  int8_t   s3Compact;
2183
  int64_t  reserved[6];
2184
  int8_t   learnerReplica;
2185
  int8_t   learnerSelfIndex;
2186
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2187
  int32_t  changeVersion;
2188
  int8_t   encryptAlgorithm;
2189
} SCreateVnodeReq;
2190

2191
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2192
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2193
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2194

2195
typedef struct {
2196
  int32_t compactId;
2197
  int32_t vgId;
2198
  int32_t dnodeId;
2199
} SQueryCompactProgressReq;
2200

2201
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2202
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2203

2204
typedef struct {
2205
  int32_t compactId;
2206
  int32_t vgId;
2207
  int32_t dnodeId;
2208
  int32_t numberFileset;
2209
  int32_t finished;
2210
  int32_t progress;
2211
  int64_t remainingTime;
2212
} SQueryCompactProgressRsp;
2213

2214
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2215
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2216

2217
typedef struct {
2218
  int32_t vgId;
2219
  int32_t dnodeId;
2220
  int64_t dbUid;
2221
  char    db[TSDB_DB_FNAME_LEN];
2222
  int64_t reserved[8];
2223
} SDropVnodeReq;
2224

2225
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2226
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2227

2228
typedef struct {
2229
  char    colName[TSDB_COL_NAME_LEN];
2230
  char    stb[TSDB_TABLE_FNAME_LEN];
2231
  int64_t stbUid;
2232
  int64_t dbUid;
2233
  int64_t reserved[8];
2234
} SDropIndexReq;
2235

2236
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2237
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2238

2239
typedef struct {
2240
  int64_t     dbUid;
2241
  char        db[TSDB_DB_FNAME_LEN];
2242
  int64_t     compactStartTime;
2243
  STimeWindow tw;
2244
  int32_t     compactId;
2245
  int8_t      metaOnly;
2246
} SCompactVnodeReq;
2247

2248
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2249
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2250

2251
typedef struct {
2252
  int32_t compactId;
2253
  int32_t vgId;
2254
  int32_t dnodeId;
2255
} SVKillCompactReq;
2256

2257
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2258
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2259

2260
typedef struct {
2261
  int32_t vgVersion;
2262
  int32_t buffer;
2263
  int32_t pageSize;
2264
  int32_t pages;
2265
  int32_t cacheLastSize;
2266
  int32_t daysPerFile;
2267
  int32_t daysToKeep0;
2268
  int32_t daysToKeep1;
2269
  int32_t daysToKeep2;
2270
  int32_t keepTimeOffset;
2271
  int32_t walFsyncPeriod;
2272
  int8_t  walLevel;
2273
  int8_t  strict;
2274
  int8_t  cacheLast;
2275
  int64_t reserved[7];
2276
  // 1st modification
2277
  int16_t sttTrigger;
2278
  int32_t minRows;
2279
  // 2nd modification
2280
  int32_t walRetentionPeriod;
2281
  int32_t walRetentionSize;
2282
  int32_t s3KeepLocal;
2283
  int8_t  s3Compact;
2284
} SAlterVnodeConfigReq;
2285

2286
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2287
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2288

2289
typedef struct {
2290
  int32_t  vgId;
2291
  int8_t   strict;
2292
  int8_t   selfIndex;
2293
  int8_t   replica;
2294
  SReplica replicas[TSDB_MAX_REPLICA];
2295
  int64_t  reserved[8];
2296
  int8_t   learnerSelfIndex;
2297
  int8_t   learnerReplica;
2298
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2299
  int32_t  changeVersion;
2300
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2301

2302
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2303
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2304

2305
typedef struct {
2306
  int32_t vgId;
2307
  int8_t  disable;
2308
} SDisableVnodeWriteReq;
2309

2310
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2311
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2312

2313
typedef struct {
2314
  int32_t  srcVgId;
2315
  int32_t  dstVgId;
2316
  uint32_t hashBegin;
2317
  uint32_t hashEnd;
2318
  int32_t  changeVersion;
2319
  int32_t  reserved;
2320
} SAlterVnodeHashRangeReq;
2321

2322
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2323
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2324

2325
#define REQ_OPT_TBNAME 0x0
2326
#define REQ_OPT_TBUID  0x01
2327
typedef struct {
2328
  SMsgHead header;
2329
  char     dbFName[TSDB_DB_FNAME_LEN];
2330
  char     tbName[TSDB_TABLE_NAME_LEN];
2331
  uint8_t  option;
2332
  uint8_t  autoCreateCtb;
2333
} STableInfoReq;
2334

2335
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2336
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2337

2338
typedef struct {
2339
  int8_t  metaClone;  // create local clone of the cached table meta
2340
  int32_t numOfVgroups;
2341
  int32_t numOfTables;
2342
  int32_t numOfUdfs;
2343
  char    tableNames[];
2344
} SMultiTableInfoReq;
2345

2346
// todo refactor
2347
typedef struct SVgroupInfo {
2348
  int32_t  vgId;
2349
  uint32_t hashBegin;
2350
  uint32_t hashEnd;
2351
  SEpSet   epSet;
2352
  union {
2353
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2354
    int32_t taskId;      // used in stream
2355
  };
2356
} SVgroupInfo;
2357

2358
typedef struct {
2359
  int32_t     numOfVgroups;
2360
  SVgroupInfo vgroups[];
2361
} SVgroupsInfo;
2362

2363
typedef struct {
2364
  STableMetaRsp* pMeta;
2365
} SMAlterStbRsp;
2366

2367
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2368
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2369
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2370

2371
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2372
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2373
void    tFreeSTableMetaRsp(void* pRsp);
2374
void    tFreeSTableIndexRsp(void* info);
2375

2376
typedef struct {
2377
  SArray* pMetaRsp;   // Array of STableMetaRsp
2378
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2379
} SSTbHbRsp;
2380

2381
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2382
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2383
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2384

2385
typedef struct {
2386
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2387
} SViewHbRsp;
2388

2389
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2390
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2391
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2392

2393
typedef struct {
2394
  int32_t numOfTables;
2395
  int32_t numOfVgroup;
2396
  int32_t numOfUdf;
2397
  int32_t contLen;
2398
  int8_t  compressed;  // denote if compressed or not
2399
  int32_t rawLen;      // size before compress
2400
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2401
  char    meta[];
2402
} SMultiTableMeta;
2403

2404
typedef struct {
2405
  int32_t dataLen;
2406
  char    name[TSDB_TABLE_FNAME_LEN];
2407
  char*   data;
2408
} STagData;
2409

2410
typedef struct {
2411
  int32_t  opType;
2412
  uint32_t valLen;
2413
  char*    val;
2414
} SShowVariablesReq;
2415

2416
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2417
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2418
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2419

2420
typedef struct {
2421
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2422
  char value[TSDB_CONFIG_PATH_LEN + 1];
2423
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2424
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2425
  char info[TSDB_CONFIG_INFO_LEN + 1];
2426
} SVariablesInfo;
2427

2428
typedef struct {
2429
  SArray* variables;  // SArray<SVariablesInfo>
2430
} SShowVariablesRsp;
2431

2432
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2433
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2434

2435
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2436

2437
/*
2438
 * sql: show tables like '%a_%'
2439
 * payload is the query condition, e.g., '%a_%'
2440
 * payloadLen is the length of payload
2441
 */
2442
typedef struct {
2443
  int32_t type;
2444
  char    db[TSDB_DB_FNAME_LEN];
2445
  int32_t payloadLen;
2446
  char*   payload;
2447
} SShowReq;
2448

2449
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2450
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2451
void tFreeSShowReq(SShowReq* pReq);
2452

2453
typedef struct {
2454
  int64_t       showId;
2455
  STableMetaRsp tableMeta;
2456
} SShowRsp, SVShowTablesRsp;
2457

2458
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2459
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2460
// void    tFreeSShowRsp(SShowRsp* pRsp);
2461

2462
typedef struct {
2463
  char    db[TSDB_DB_FNAME_LEN];
2464
  char    tb[TSDB_TABLE_NAME_LEN];
2465
  char    user[TSDB_USER_LEN];
2466
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2467
  int64_t showId;
2468
  int64_t compactId;  // for compact
2469
  bool    withFull;   // for show users full
2470
} SRetrieveTableReq;
2471

2472
typedef struct SSysTableSchema {
2473
  int8_t   type;
2474
  col_id_t colId;
2475
  int32_t  bytes;
2476
} SSysTableSchema;
2477

2478
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2479
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2480

2481
#define RETRIEVE_TABLE_RSP_VERSION          0
2482
#define RETRIEVE_TABLE_RSP_TMQ_VERSION      1
2483
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION  2
2484

2485
typedef struct {
2486
  int64_t useconds;
2487
  int8_t  completed;  // all results are returned to client
2488
  int8_t  precision;
2489
  int8_t  compressed;
2490
  int8_t  streamBlockType;
2491
  int32_t payloadLen;
2492
  int32_t compLen;
2493
  int32_t numOfBlocks;
2494
  int64_t numOfRows;  // from int32_t change to int64_t
2495
  int64_t numOfCols;
2496
  int64_t skey;
2497
  int64_t ekey;
2498
  int64_t version;                         // for stream
2499
  TSKEY   watermark;                       // for stream
2500
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2501
  char    data[];
2502
} SRetrieveTableRsp;
2503

2504
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2505

2506
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2507
  do {                                          \
2508
    ((int32_t*)(_p))[0] = (_compLen);           \
2509
    ((int32_t*)(_p))[1] = (_fullLen);           \
2510
  } while (0);
2511

2512
typedef struct {
2513
  int64_t version;
2514
  int64_t numOfRows;
2515
  int8_t  compressed;
2516
  int8_t  precision;
2517
  char    data[];
2518
} SRetrieveTableRspForTmq;
2519

2520
typedef struct {
2521
  int64_t handle;
2522
  int64_t useconds;
2523
  int8_t  completed;  // all results are returned to client
2524
  int8_t  precision;
2525
  int8_t  compressed;
2526
  int32_t compLen;
2527
  int32_t numOfRows;
2528
  int32_t fullLen;
2529
  char    data[];
2530
} SRetrieveMetaTableRsp;
2531

2532
typedef struct SExplainExecInfo {
2533
  double   startupCost;
2534
  double   totalCost;
2535
  uint64_t numOfRows;
2536
  uint32_t verboseLen;
2537
  void*    verboseInfo;
2538
} SExplainExecInfo;
2539

2540
typedef struct {
2541
  int32_t           numOfPlans;
2542
  SExplainExecInfo* subplanInfo;
2543
} SExplainRsp;
2544

2545
typedef struct {
2546
  SExplainRsp rsp;
2547
  uint64_t    qId;
2548
  uint64_t    cId;
2549
  uint64_t    tId;
2550
  int64_t     rId;
2551
  int32_t     eId;
2552
} SExplainLocalRsp;
2553

2554
typedef struct STableScanAnalyzeInfo {
2555
  uint64_t totalRows;
2556
  uint64_t totalCheckedRows;
2557
  uint32_t totalBlocks;
2558
  uint32_t loadBlocks;
2559
  uint32_t loadBlockStatis;
2560
  uint32_t skipBlocks;
2561
  uint32_t filterOutBlocks;
2562
  double   elapsedTime;
2563
  double   filterTime;
2564
} STableScanAnalyzeInfo;
2565

2566
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2567
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2568
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2569

2570
typedef struct {
2571
  char    config[TSDB_DNODE_CONFIG_LEN];
2572
  char    value[TSDB_CLUSTER_VALUE_LEN];
2573
  int32_t sqlLen;
2574
  char*   sql;
2575
} SMCfgClusterReq;
2576

2577
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2578
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2579
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2580

2581
typedef struct {
2582
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2583
  int32_t port;
2584
  int32_t sqlLen;
2585
  char*   sql;
2586
} SCreateDnodeReq;
2587

2588
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2589
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2590
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2591

2592
typedef struct {
2593
  int32_t dnodeId;
2594
  char    fqdn[TSDB_FQDN_LEN];
2595
  int32_t port;
2596
  int8_t  force;
2597
  int8_t  unsafe;
2598
  int32_t sqlLen;
2599
  char*   sql;
2600
} SDropDnodeReq;
2601

2602
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2603
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2604
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2605

2606
enum {
2607
  RESTORE_TYPE__ALL = 1,
2608
  RESTORE_TYPE__MNODE,
2609
  RESTORE_TYPE__VNODE,
2610
  RESTORE_TYPE__QNODE,
2611
};
2612

2613
typedef struct {
2614
  int32_t dnodeId;
2615
  int8_t  restoreType;
2616
  int32_t sqlLen;
2617
  char*   sql;
2618
} SRestoreDnodeReq;
2619

2620
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2621
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2622
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2623

2624
typedef struct {
2625
  int32_t dnodeId;
2626
  char    config[TSDB_DNODE_CONFIG_LEN];
2627
  char    value[TSDB_DNODE_VALUE_LEN];
2628
  int32_t sqlLen;
2629
  char*   sql;
2630
} SMCfgDnodeReq;
2631

2632
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2633
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2634
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2635

2636
typedef struct {
2637
  char    config[TSDB_DNODE_CONFIG_LEN];
2638
  char    value[TSDB_DNODE_VALUE_LEN];
2639
  int32_t version;
2640
} SDCfgDnodeReq;
2641

2642
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2643
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2644

2645
typedef struct {
2646
  int32_t dnodeId;
2647
  int32_t sqlLen;
2648
  char*   sql;
2649
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2650
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2651

2652
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2653
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2654
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2655
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2656
typedef struct {
2657
  int8_t   replica;
2658
  SReplica replicas[TSDB_MAX_REPLICA];
2659
  int8_t   learnerReplica;
2660
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2661
  int64_t  lastIndex;
2662
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2663

2664
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2665
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2666

2667
typedef struct {
2668
  int32_t urlLen;
2669
  int32_t sqlLen;
2670
  char*   url;
2671
  char*   sql;
2672
} SMCreateAnodeReq;
2673

2674
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2675
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2676
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2677

2678
typedef struct {
2679
  int32_t anodeId;
2680
  int32_t sqlLen;
2681
  char*   sql;
2682
} SMDropAnodeReq, SMUpdateAnodeReq;
2683

2684
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2685
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2686
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2687
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2688
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2689
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2690

2691
typedef struct {
2692
  int32_t vgId;
2693
  int32_t hbSeq;
2694
} SVArbHbReqMember;
2695

2696
typedef struct {
2697
  int32_t dnodeId;
2698
  char*   arbToken;
2699
  int64_t arbTerm;
2700
  SArray* hbMembers;  // SVArbHbReqMember
2701
} SVArbHeartBeatReq;
2702

2703
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2704
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2705
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2706

2707
typedef struct {
2708
  int32_t vgId;
2709
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2710
  int32_t hbSeq;
2711
} SVArbHbRspMember;
2712

2713
typedef struct {
2714
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2715
  int32_t dnodeId;
2716
  SArray* hbMembers;  // SVArbHbRspMember
2717
} SVArbHeartBeatRsp;
2718

2719
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2720
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2721
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2722

2723
typedef struct {
2724
  char*   arbToken;
2725
  int64_t arbTerm;
2726
  char*   member0Token;
2727
  char*   member1Token;
2728
} SVArbCheckSyncReq;
2729

2730
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2731
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2732
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2733

2734
typedef struct {
2735
  char*   arbToken;
2736
  char*   member0Token;
2737
  char*   member1Token;
2738
  int32_t vgId;
2739
  int32_t errCode;
2740
} SVArbCheckSyncRsp;
2741

2742
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2743
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2744
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2745

2746
typedef struct {
2747
  char*   arbToken;
2748
  int64_t arbTerm;
2749
  char*   memberToken;
2750
  int8_t  force;
2751
} SVArbSetAssignedLeaderReq;
2752

2753
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2754
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2755
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2756

2757
typedef struct {
2758
  char*   arbToken;
2759
  char*   memberToken;
2760
  int32_t vgId;
2761
} SVArbSetAssignedLeaderRsp;
2762

2763
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2764
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2765
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2766

2767
typedef struct {
2768
  int32_t dnodeId;
2769
  char*   token;
2770
} SMArbUpdateGroupMember;
2771

2772
typedef struct {
2773
  int32_t dnodeId;
2774
  char*   token;
2775
  int8_t  acked;
2776
} SMArbUpdateGroupAssigned;
2777

2778
typedef struct {
2779
  int32_t                  vgId;
2780
  int64_t                  dbUid;
2781
  SMArbUpdateGroupMember   members[2];
2782
  int8_t                   isSync;
2783
  int8_t                   assignedAcked;
2784
  SMArbUpdateGroupAssigned assignedLeader;
2785
  int64_t                  version;
2786
  int32_t                  code;
2787
  int64_t                  updateTimeMs;
2788
} SMArbUpdateGroup;
2789

2790
typedef struct {
2791
  SArray* updateArray;  // SMArbUpdateGroup
2792
} SMArbUpdateGroupBatchReq;
2793

2794
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2795
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2796
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2797

2798
typedef struct {
2799
  char queryStrId[TSDB_QUERY_ID_LEN];
2800
} SKillQueryReq;
2801

2802
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2803
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2804

2805
typedef struct {
2806
  uint32_t connId;
2807
} SKillConnReq;
2808

2809
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2810
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2811

2812
typedef struct {
2813
  int32_t transId;
2814
} SKillTransReq;
2815

2816
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2817
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2818

2819
typedef struct {
2820
  int32_t useless;  // useless
2821
  int32_t sqlLen;
2822
  char*   sql;
2823
} SBalanceVgroupReq;
2824

2825
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2826
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2827
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2828

2829
typedef struct {
2830
  int32_t useless;  // useless
2831
  int32_t sqlLen;
2832
  char*   sql;
2833
} SAssignLeaderReq;
2834

2835
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2836
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2837
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
2838
typedef struct {
2839
  int32_t vgId1;
2840
  int32_t vgId2;
2841
} SMergeVgroupReq;
2842

2843
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2844
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2845

2846
typedef struct {
2847
  int32_t vgId;
2848
  int32_t dnodeId1;
2849
  int32_t dnodeId2;
2850
  int32_t dnodeId3;
2851
  int32_t sqlLen;
2852
  char*   sql;
2853
} SRedistributeVgroupReq;
2854

2855
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2856
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2857
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2858

2859
typedef struct {
2860
  int32_t reserved;
2861
  int32_t vgId;
2862
  int32_t sqlLen;
2863
  char*   sql;
2864
  char    db[TSDB_DB_FNAME_LEN];
2865
} SBalanceVgroupLeaderReq;
2866

2867
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2868
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2869
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2870

2871
typedef struct {
2872
  int32_t vgId;
2873
} SForceBecomeFollowerReq;
2874

2875
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2876
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2877

2878
typedef struct {
2879
  int32_t vgId;
2880
} SSplitVgroupReq;
2881

2882
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2883
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2884

2885
typedef struct {
2886
  char user[TSDB_USER_LEN];
2887
  char spi;
2888
  char encrypt;
2889
  char secret[TSDB_PASSWORD_LEN];
2890
  char ckey[TSDB_PASSWORD_LEN];
2891
} SAuthReq, SAuthRsp;
2892

2893
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2894
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2895

2896
typedef struct {
2897
  int32_t statusCode;
2898
  char    details[1024];
2899
} SServerStatusRsp;
2900

2901
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2902
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2903

2904
/**
2905
 * The layout of the query message payload is as following:
2906
 * +--------------------+---------------------------------+
2907
 * |Sql statement       | Physical plan                   |
2908
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2909
 * +--------------------+---------------------------------+
2910
 */
2911
typedef struct SSubQueryMsg {
2912
  SMsgHead header;
2913
  uint64_t sId;
2914
  uint64_t queryId;
2915
  uint64_t clientId;
2916
  uint64_t taskId;
2917
  int64_t  refId;
2918
  int32_t  execId;
2919
  int32_t  msgMask;
2920
  int8_t   taskType;
2921
  int8_t   explain;
2922
  int8_t   needFetch;
2923
  int8_t   compress;
2924
  uint32_t sqlLen;
2925
  char*    sql;
2926
  uint32_t msgLen;
2927
  char*    msg;
2928
} SSubQueryMsg;
2929

2930
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2931
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2932
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2933

2934
typedef struct {
2935
  SMsgHead header;
2936
  uint64_t sId;
2937
  uint64_t queryId;
2938
  uint64_t taskId;
2939
} SSinkDataReq;
2940

2941
typedef struct {
2942
  SMsgHead header;
2943
  uint64_t sId;
2944
  uint64_t queryId;
2945
  uint64_t clientId;
2946
  uint64_t taskId;
2947
  int32_t  execId;
2948
} SQueryContinueReq;
2949

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

2957
typedef struct {
2958
  int32_t code;
2959
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2960
  int32_t sversion;
2961
  int32_t tversion;
2962
} SResReadyRsp;
2963

2964
typedef struct SOperatorParam {
2965
  int32_t opType;
2966
  int32_t downstreamIdx;
2967
  void*   value;
2968
  SArray* pChildren;  // SArray<SOperatorParam*>
2969
  bool    reUse;
2970
} SOperatorParam;
2971

2972
typedef struct SColIdNameKV {
2973
  col_id_t colId;
2974
  char     colName[TSDB_COL_NAME_LEN];
2975
} SColIdNameKV;
2976

2977
typedef struct SColIdPair {
2978
  col_id_t vtbColId;
2979
  col_id_t orgColId;
2980
} SColIdPair;
2981

2982
typedef struct SOrgTbInfo {
2983
  int32_t   vgId;
2984
  char      tbName[TSDB_TABLE_FNAME_LEN];
2985
  SArray*   colMap;  // SArray<SColIdNameKV>
2986
} SOrgTbInfo;
2987

2988
typedef struct STableScanOperatorParam {
2989
  bool           tableSeq;
2990
  SArray*        pUidList;
2991
  SOrgTbInfo*    pOrgTbInfo;
2992
  STimeWindow    window;
2993
} STableScanOperatorParam;
2994

2995
typedef struct SVTableScanOperatorParam {
2996
  uint64_t       uid;
2997
  SArray*        pOpParamArray;  // SArray<SOperatorParam>
2998
} SVTableScanOperatorParam;
2999

3000
typedef struct {
3001
  SMsgHead        header;
3002
  uint64_t        sId;
3003
  uint64_t        queryId;
3004
  uint64_t        clientId;
3005
  uint64_t        taskId;
3006
  int32_t         execId;
3007
  SOperatorParam* pOpParam;
3008
} SResFetchReq;
3009

3010
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3011
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
3012

3013
typedef struct {
3014
  SMsgHead header;
3015
  uint64_t clientId;
3016
} SSchTasksStatusReq;
3017

3018
typedef struct {
3019
  uint64_t queryId;
3020
  uint64_t clientId;
3021
  uint64_t taskId;
3022
  int64_t  refId;
3023
  int32_t  execId;
3024
  int8_t   status;
3025
} STaskStatus;
3026

3027
typedef struct {
3028
  int64_t refId;
3029
  SArray* taskStatus;  // SArray<STaskStatus>
3030
} SSchedulerStatusRsp;
3031

3032
typedef struct {
3033
  uint64_t queryId;
3034
  uint64_t taskId;
3035
  int8_t   action;
3036
} STaskAction;
3037

3038
typedef struct SQueryNodeEpId {
3039
  int32_t nodeId;  // vgId or qnodeId
3040
  SEp     ep;
3041
} SQueryNodeEpId;
3042

3043
typedef struct {
3044
  SMsgHead       header;
3045
  uint64_t       clientId;
3046
  SQueryNodeEpId epId;
3047
  SArray*        taskAction;  // SArray<STaskAction>
3048
} SSchedulerHbReq;
3049

3050
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3051
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
3052
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
3053

3054
typedef struct {
3055
  SQueryNodeEpId epId;
3056
  SArray*        taskStatus;  // SArray<STaskStatus>
3057
} SSchedulerHbRsp;
3058

3059
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3060
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
3061
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
3062

3063
typedef struct {
3064
  SMsgHead header;
3065
  uint64_t sId;
3066
  uint64_t queryId;
3067
  uint64_t clientId;
3068
  uint64_t taskId;
3069
  int64_t  refId;
3070
  int32_t  execId;
3071
} STaskCancelReq;
3072

3073
typedef struct {
3074
  int32_t code;
3075
} STaskCancelRsp;
3076

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

3087
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3088
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
3089

3090
typedef enum {
3091
  TASK_NOTIFY_FINISHED = 1,
3092
} ETaskNotifyType;
3093

3094
typedef struct {
3095
  SMsgHead        header;
3096
  uint64_t        sId;
3097
  uint64_t        queryId;
3098
  uint64_t        clientId;
3099
  uint64_t        taskId;
3100
  int64_t         refId;
3101
  int32_t         execId;
3102
  ETaskNotifyType type;
3103
} STaskNotifyReq;
3104

3105
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3106
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
3107

3108
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3109
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
3110

3111
typedef struct {
3112
  int32_t code;
3113
} STaskDropRsp;
3114

3115
#define STREAM_TRIGGER_AT_ONCE                 1
3116
#define STREAM_TRIGGER_WINDOW_CLOSE            2
3117
#define STREAM_TRIGGER_MAX_DELAY               3
3118
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE      4
3119
#define STREAM_TRIGGER_CONTINUOUS_WINDOW_CLOSE 5
3120

3121
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
3122
#define STREAM_FILL_HISTORY_ON        1
3123
#define STREAM_FILL_HISTORY_OFF       0
3124
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
3125
#define STREAM_DEFAULT_IGNORE_UPDATE  1
3126
#define STREAM_CREATE_STABLE_TRUE     1
3127
#define STREAM_CREATE_STABLE_FALSE    0
3128

3129
typedef struct SColLocation {
3130
  int16_t  slotId;
3131
  col_id_t colId;
3132
  int8_t   type;
3133
} SColLocation;
3134

3135
typedef struct SVgroupVer {
3136
  int32_t vgId;
3137
  int64_t ver;
3138
} SVgroupVer;
3139

3140
typedef struct {
3141
  char    name[TSDB_STREAM_FNAME_LEN];
3142
  char    sourceDB[TSDB_DB_FNAME_LEN];
3143
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
3144
  char*   sql;
3145
  char*   ast;
3146
  int8_t  igExists;
3147
  int8_t  triggerType;
3148
  int8_t  igExpired;
3149
  int8_t  fillHistory;  // process data inserted before creating stream
3150
  int64_t maxDelay;
3151
  int64_t watermark;
3152
  int32_t numOfTags;
3153
  SArray* pTags;  // array of SField
3154
  // 3.0.20
3155
  int64_t checkpointFreq;  // ms
3156
  // 3.0.2.3
3157
  int8_t   createStb;
3158
  uint64_t targetStbUid;
3159
  SArray*  fillNullCols;  // array of SColLocation
3160
  int64_t  deleteMark;
3161
  int8_t   igUpdate;
3162
  int64_t  lastTs;
3163
  SArray*  pVgroupVerList;
3164
  // 3.3.0.0
3165
  SArray* pCols;  // array of SField
3166
  int64_t smaId;
3167
  // 3.3.6.0
3168
  SArray* pNotifyAddrUrls;
3169
  int32_t notifyEventTypes;
3170
  int32_t notifyErrorHandle;
3171
  int8_t  notifyHistory;
3172
  int64_t recalculateInterval;
3173
  char    pWstartName[TSDB_COL_NAME_LEN];
3174
  char    pWendName[TSDB_COL_NAME_LEN];
3175
  char    pGroupIdName[TSDB_COL_NAME_LEN];
3176
  char    pIsWindowFilledName[TSDB_COL_NAME_LEN];
3177
  SArray* pVSubTables; // array of SVSubTablesRsp
3178
} SCMCreateStreamReq;
3179

3180
typedef struct STaskNotifyEventStat {
3181
  int64_t notifyEventAddTimes;     // call times of add function
3182
  int64_t notifyEventAddElems;     // elements added by add function
3183
  double  notifyEventAddCostSec;   // time cost of add function
3184
  int64_t notifyEventPushTimes;    // call times of push function
3185
  int64_t notifyEventPushElems;    // elements pushed by push function
3186
  double  notifyEventPushCostSec;  // time cost of push function
3187
  int64_t notifyEventPackTimes;    // call times of pack function
3188
  int64_t notifyEventPackElems;    // elements packed by pack function
3189
  double  notifyEventPackCostSec;  // time cost of pack function
3190
  int64_t notifyEventSendTimes;    // call times of send function
3191
  int64_t notifyEventSendElems;    // elements sent by send function
3192
  double  notifyEventSendCostSec;  // time cost of send function
3193
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3194
} STaskNotifyEventStat;
3195

3196
typedef struct {
3197
  int64_t streamId;
3198
} SCMCreateStreamRsp;
3199

3200
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3201
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3202
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3203

3204
enum {
3205
  TOPIC_SUB_TYPE__DB = 1,
3206
  TOPIC_SUB_TYPE__TABLE,
3207
  TOPIC_SUB_TYPE__COLUMN,
3208
};
3209

3210
#define DEFAULT_MAX_POLL_INTERVAL  300000
3211
#define DEFAULT_SESSION_TIMEOUT    12000
3212
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3213
#define DEFAULT_MIN_POLL_ROWS      4096
3214

3215
typedef struct {
3216
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3217
  int8_t igExists;
3218
  int8_t subType;
3219
  int8_t withMeta;
3220
  char*  sql;
3221
  char   subDbName[TSDB_DB_FNAME_LEN];
3222
  char*  ast;
3223
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3224
} SCMCreateTopicReq;
3225

3226
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3227
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3228
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3229

3230
typedef struct {
3231
  int64_t consumerId;
3232
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3233

3234
typedef struct {
3235
  int64_t consumerId;
3236
  char    cgroup[TSDB_CGROUP_LEN];
3237
  char    clientId[TSDB_CLIENT_ID_LEN];
3238
  char    user[TSDB_USER_LEN];
3239
  char    fqdn[TSDB_FQDN_LEN];
3240
  SArray* topicNames;  // SArray<char**>
3241

3242
  int8_t  withTbName;
3243
  int8_t  autoCommit;
3244
  int32_t autoCommitInterval;
3245
  int8_t  resetOffsetCfg;
3246
  int8_t  enableReplay;
3247
  int8_t  enableBatchMeta;
3248
  int32_t sessionTimeoutMs;
3249
  int32_t maxPollIntervalMs;
3250
} SCMSubscribeReq;
3251

3252
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3253
  int32_t tlen = 0;
14✔
3254
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
14!
3255
  tlen += taosEncodeString(buf, pReq->cgroup);
14✔
3256
  tlen += taosEncodeString(buf, pReq->clientId);
14✔
3257

3258
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
14!
3259
  tlen += taosEncodeFixedI32(buf, topicNum);
14✔
3260

3261
  for (int32_t i = 0; i < topicNum; i++) {
26✔
3262
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
24✔
3263
  }
3264

3265
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
14!
3266
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
14!
3267
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
14!
3268
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
14!
3269
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
14!
3270
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
14!
3271
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
14!
3272
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
14!
3273
  tlen += taosEncodeString(buf, pReq->user);
14✔
3274
  tlen += taosEncodeString(buf, pReq->fqdn);
14✔
3275

3276
  return tlen;
14✔
3277
}
3278

3279
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3280
  void* start = buf;
×
3281
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
×
3282
  buf = taosDecodeStringTo(buf, pReq->cgroup);
×
3283
  buf = taosDecodeStringTo(buf, pReq->clientId);
×
3284

3285
  int32_t topicNum = 0;
×
3286
  buf = taosDecodeFixedI32(buf, &topicNum);
×
3287

3288
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
×
3289
  if (pReq->topicNames == NULL) {
×
3290
    return terrno;
×
3291
  }
3292
  for (int32_t i = 0; i < topicNum; i++) {
×
3293
    char* name = NULL;
×
3294
    buf = taosDecodeString(buf, &name);
×
3295
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
×
3296
      return terrno;
×
3297
    }
3298
  }
3299

3300
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
×
3301
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
×
3302
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
×
3303
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
×
3304
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
×
3305
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
×
3306
  if ((char*)buf - (char*)start < len) {
×
3307
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
×
3308
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
×
3309
    buf = taosDecodeStringTo(buf, pReq->user);
×
3310
    buf = taosDecodeStringTo(buf, pReq->fqdn);
×
3311
  } else {
3312
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3313
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3314
  }
3315

3316
  return 0;
×
3317
}
3318

3319
typedef struct {
3320
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3321
  SArray* removedConsumers;  // SArray<int64_t>
3322
  SArray* newConsumers;      // SArray<int64_t>
3323
} SMqRebInfo;
3324

3325
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3326
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
×
3327
  if (pRebInfo == NULL) {
×
3328
    return NULL;
×
3329
  }
3330
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
×
3331
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
×
3332
  if (pRebInfo->removedConsumers == NULL) {
×
3333
    goto _err;
×
3334
  }
3335
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
×
3336
  if (pRebInfo->newConsumers == NULL) {
×
3337
    goto _err;
×
3338
  }
3339
  return pRebInfo;
×
3340
_err:
×
3341
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3342
  taosArrayDestroy(pRebInfo->newConsumers);
×
3343
  taosMemoryFreeClear(pRebInfo);
×
3344
  return NULL;
×
3345
}
3346

3347
typedef struct {
3348
  int64_t streamId;
3349
  int64_t checkpointId;
3350
  char    streamName[TSDB_STREAM_FNAME_LEN];
3351
} SMStreamDoCheckpointMsg;
3352

3353
typedef struct {
3354
  int64_t status;
3355
} SMVSubscribeRsp;
3356

3357
typedef struct {
3358
  char    name[TSDB_TOPIC_FNAME_LEN];
3359
  int8_t  igNotExists;
3360
  int32_t sqlLen;
3361
  char*   sql;
3362
  int8_t  force;
3363
} SMDropTopicReq;
3364

3365
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3366
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3367
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3368

3369
typedef struct {
3370
  char   topic[TSDB_TOPIC_FNAME_LEN];
3371
  char   cgroup[TSDB_CGROUP_LEN];
3372
  int8_t igNotExists;
3373
  int8_t force;
3374
} SMDropCgroupReq;
3375

3376
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3377
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3378

3379
typedef struct {
3380
  int8_t reserved;
3381
} SMDropCgroupRsp;
3382

3383
typedef struct {
3384
  char    name[TSDB_TABLE_FNAME_LEN];
3385
  int8_t  alterType;
3386
  SSchema schema;
3387
} SAlterTopicReq;
3388

3389
typedef struct {
3390
  SMsgHead head;
3391
  char     name[TSDB_TABLE_FNAME_LEN];
3392
  int64_t  tuid;
3393
  int32_t  sverson;
3394
  int32_t  execLen;
3395
  char*    executor;
3396
  int32_t  sqlLen;
3397
  char*    sql;
3398
} SDCreateTopicReq;
3399

3400
typedef struct {
3401
  SMsgHead head;
3402
  char     name[TSDB_TABLE_FNAME_LEN];
3403
  int64_t  tuid;
3404
} SDDropTopicReq;
3405

3406
typedef struct {
3407
  int64_t maxdelay[2];
3408
  int64_t watermark[2];
3409
  int64_t deleteMark[2];
3410
  int32_t qmsgLen[2];
3411
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3412
} SRSmaParam;
3413

3414
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3415
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3416

3417
// TDMT_VND_CREATE_STB ==============
3418
typedef struct SVCreateStbReq {
3419
  char*           name;
3420
  tb_uid_t        suid;
3421
  int8_t          rollup;
3422
  SSchemaWrapper  schemaRow;
3423
  SSchemaWrapper  schemaTag;
3424
  SRSmaParam      rsmaParam;
3425
  int32_t         alterOriDataLen;
3426
  void*           alterOriData;
3427
  int8_t          source;
3428
  int8_t          colCmpred;
3429
  SColCmprWrapper colCmpr;
3430
  int64_t         keep;
3431
  SExtSchema*     pExtSchemas;
3432
  int8_t          virtualStb;
3433
} SVCreateStbReq;
3434

3435
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3436
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3437

3438
// TDMT_VND_DROP_STB ==============
3439
typedef struct SVDropStbReq {
3440
  char*    name;
3441
  tb_uid_t suid;
3442
} SVDropStbReq;
3443

3444
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3445
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3446

3447
// TDMT_VND_CREATE_TABLE ==============
3448
#define TD_CREATE_IF_NOT_EXISTS 0x1
3449
typedef struct SVCreateTbReq {
3450
  int32_t  flags;
3451
  char*    name;
3452
  tb_uid_t uid;
3453
  int64_t  btime;
3454
  int32_t  ttl;
3455
  int32_t  commentLen;
3456
  char*    comment;
3457
  int8_t   type;
3458
  union {
3459
    struct {
3460
      char*    stbName;  // super table name
3461
      uint8_t  tagNum;
3462
      tb_uid_t suid;
3463
      SArray*  tagName;
3464
      uint8_t* pTag;
3465
    } ctb;
3466
    struct {
3467
      SSchemaWrapper schemaRow;
3468
    } ntb;
3469
  };
3470
  int32_t         sqlLen;
3471
  char*           sql;
3472
  SColCmprWrapper colCmpr;
3473
  SExtSchema*     pExtSchemas;
3474
  SColRefWrapper  colRef; // col reference for virtual table
3475
} SVCreateTbReq;
3476

3477
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3478
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3479
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3480

3481
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
×
3482
  if (NULL == req) {
10,097!
3483
    return;
8,103✔
3484
  }
3485

3486
  taosMemoryFreeClear(req->sql);
1,994!
3487
  taosMemoryFreeClear(req->name);
1,994!
3488
  taosMemoryFreeClear(req->comment);
1,994!
3489
  if (req->type == TSDB_CHILD_TABLE || req->type == TSDB_VIRTUAL_CHILD_TABLE) {
1,994!
3490
    taosMemoryFreeClear(req->ctb.pTag);
1,230!
3491
    taosMemoryFreeClear(req->ctb.stbName);
1,230!
3492
    taosArrayDestroy(req->ctb.tagName);
1,230✔
3493
    req->ctb.tagName = NULL;
1,230✔
3494
  } else if (req->type == TSDB_NORMAL_TABLE || req->type == TSDB_VIRTUAL_NORMAL_TABLE) {
764!
3495
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
764!
3496
  }
3497
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
1,994!
3498
  taosMemoryFreeClear(req->pExtSchemas);
1,994!
3499
  taosMemoryFreeClear(req->colRef.pColRef);
1,994!
3500
}
3501

3502
typedef struct {
3503
  int32_t nReqs;
3504
  union {
3505
    SVCreateTbReq* pReqs;
3506
    SArray*        pArray;
3507
  };
3508
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3509
} SVCreateTbBatchReq;
3510

3511
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3512
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3513
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3514

3515
typedef struct {
3516
  int32_t        code;
3517
  STableMetaRsp* pMeta;
3518
} SVCreateTbRsp, SVUpdateTbRsp;
3519

3520
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3521
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3522
void tFreeSVCreateTbRsp(void* param);
3523

3524
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3525
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3526

3527
typedef struct {
3528
  int32_t nRsps;
3529
  union {
3530
    SVCreateTbRsp* pRsps;
3531
    SArray*        pArray;
3532
  };
3533
} SVCreateTbBatchRsp;
3534

3535
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3536
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3537

3538
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3539
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3540

3541
// TDMT_VND_DROP_TABLE =================
3542
typedef struct {
3543
  char*    name;
3544
  uint64_t suid;  // for tmq in wal format
3545
  int64_t  uid;
3546
  int8_t   igNotExists;
3547
  int8_t   isVirtual;
3548
} SVDropTbReq;
3549

3550
typedef struct {
3551
  int32_t code;
3552
} SVDropTbRsp;
3553

3554
typedef struct {
3555
  int32_t nReqs;
3556
  union {
3557
    SVDropTbReq* pReqs;
3558
    SArray*      pArray;
3559
  };
3560
} SVDropTbBatchReq;
3561

3562
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3563
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3564

3565
typedef struct {
3566
  int32_t nRsps;
3567
  union {
3568
    SVDropTbRsp* pRsps;
3569
    SArray*      pArray;
3570
  };
3571
} SVDropTbBatchRsp;
3572

3573
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3574
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3575

3576
// TDMT_VND_ALTER_TABLE =====================
3577
typedef struct SMultiTagUpateVal {
3578
  char*    tagName;
3579
  int32_t  colId;
3580
  int8_t   tagType;
3581
  int8_t   tagFree;
3582
  uint32_t nTagVal;
3583
  uint8_t* pTagVal;
3584
  int8_t   isNull;
3585
  SArray*  pTagArray;
3586
} SMultiTagUpateVal;
3587
typedef struct SVAlterTbReq{
3588
  char*   tbName;
3589
  int8_t  action;
3590
  char*   colName;
3591
  int32_t colId;
3592
  // TSDB_ALTER_TABLE_ADD_COLUMN
3593
  int8_t  type;
3594
  int8_t  flags;
3595
  int32_t bytes;
3596
  // TSDB_ALTER_TABLE_DROP_COLUMN
3597
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3598
  int8_t   colModType;
3599
  int32_t  colModBytes;
3600
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3601
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3602
  int8_t   isNull;
3603
  int8_t   tagType;
3604
  int8_t   tagFree;
3605
  uint32_t nTagVal;
3606
  uint8_t* pTagVal;
3607
  SArray*  pTagArray;
3608
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3609
  int8_t   updateTTL;
3610
  int32_t  newTTL;
3611
  int32_t  newCommentLen;
3612
  char*    newComment;
3613
  int64_t  ctimeMs;    // fill by vnode
3614
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3615
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3616
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3617
  // for Add column
3618
  STypeMod typeMod;
3619
  // TSDB_ALTER_TABLE_ALTER_COLUMN_REF
3620
  char*    refDbName;
3621
  char*    refTbName;
3622
  char*    refColName;
3623
  // TSDB_ALTER_TABLE_REMOVE_COLUMN_REF
3624
} SVAlterTbReq;
3625

3626
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3627
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3628
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3629
void    tfreeMultiTagUpateVal(void* pMultiTag);
3630

3631
typedef struct {
3632
  int32_t        code;
3633
  STableMetaRsp* pMeta;
3634
} SVAlterTbRsp;
3635

3636
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3637
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3638
// ======================
3639

3640
typedef struct {
3641
  SMsgHead head;
3642
  int64_t  uid;
3643
  int32_t  tid;
3644
  int16_t  tversion;
3645
  int16_t  colId;
3646
  int8_t   type;
3647
  int16_t  bytes;
3648
  int32_t  tagValLen;
3649
  int16_t  numOfTags;
3650
  int32_t  schemaLen;
3651
  char     data[];
3652
} SUpdateTagValReq;
3653

3654
typedef struct {
3655
  SMsgHead head;
3656
} SUpdateTagValRsp;
3657

3658
typedef struct {
3659
  SMsgHead head;
3660
} SVShowTablesReq;
3661

3662
typedef struct {
3663
  SMsgHead head;
3664
  int32_t  id;
3665
} SVShowTablesFetchReq;
3666

3667
typedef struct {
3668
  int64_t useconds;
3669
  int8_t  completed;  // all results are returned to client
3670
  int8_t  precision;
3671
  int8_t  compressed;
3672
  int32_t compLen;
3673
  int32_t numOfRows;
3674
  char    data[];
3675
} SVShowTablesFetchRsp;
3676

3677
typedef struct {
3678
  int64_t consumerId;
3679
  int32_t epoch;
3680
  char    cgroup[TSDB_CGROUP_LEN];
3681
} SMqAskEpReq;
3682

3683
typedef struct {
3684
  int32_t key;
3685
  int32_t valueLen;
3686
  void*   value;
3687
} SKv;
3688

3689
typedef struct {
3690
  int64_t tscRid;
3691
  int8_t  connType;
3692
} SClientHbKey;
3693

3694
typedef struct {
3695
  int64_t tid;
3696
  char    status[TSDB_JOB_STATUS_LEN];
3697
} SQuerySubDesc;
3698

3699
typedef struct {
3700
  char     sql[TSDB_SHOW_SQL_LEN];
3701
  uint64_t queryId;
3702
  int64_t  useconds;
3703
  int64_t  stime;  // timestamp precision ms
3704
  int64_t  reqRid;
3705
  bool     stableQuery;
3706
  bool     isSubQuery;
3707
  char     fqdn[TSDB_FQDN_LEN];
3708
  int32_t  subPlanNum;
3709
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3710
} SQueryDesc;
3711

3712
typedef struct {
3713
  uint32_t connId;
3714
  SArray*  queryDesc;  // SArray<SQueryDesc>
3715
} SQueryHbReqBasic;
3716

3717
typedef struct {
3718
  uint32_t connId;
3719
  uint64_t killRid;
3720
  int32_t  totalDnodes;
3721
  int32_t  onlineDnodes;
3722
  int8_t   killConnection;
3723
  int8_t   align[3];
3724
  SEpSet   epSet;
3725
  SArray*  pQnodeList;
3726
} SQueryHbRspBasic;
3727

3728
typedef struct SAppClusterSummary {
3729
  uint64_t numOfInsertsReq;
3730
  uint64_t numOfInsertRows;
3731
  uint64_t insertElapsedTime;
3732
  uint64_t insertBytes;  // submit to tsdb since launched.
3733

3734
  uint64_t fetchBytes;
3735
  uint64_t numOfQueryReq;
3736
  uint64_t queryElapsedTime;
3737
  uint64_t numOfSlowQueries;
3738
  uint64_t totalRequests;
3739
  uint64_t currentRequests;  // the number of SRequestObj
3740
} SAppClusterSummary;
3741

3742
typedef struct {
3743
  int64_t            appId;
3744
  int32_t            pid;
3745
  char               name[TSDB_APP_NAME_LEN];
3746
  int64_t            startTime;
3747
  SAppClusterSummary summary;
3748
} SAppHbReq;
3749

3750
typedef struct {
3751
  SClientHbKey      connKey;
3752
  int64_t           clusterId;
3753
  SAppHbReq         app;
3754
  SQueryHbReqBasic* query;
3755
  SHashObj*         info;  // hash<Skv.key, Skv>
3756
  char              userApp[TSDB_APP_NAME_LEN];
3757
  uint32_t          userIp;
3758
} SClientHbReq;
3759

3760
typedef struct {
3761
  int64_t reqId;
3762
  SArray* reqs;  // SArray<SClientHbReq>
3763
  int64_t ipWhiteList;
3764
} SClientHbBatchReq;
3765

3766
typedef struct {
3767
  SClientHbKey      connKey;
3768
  int32_t           status;
3769
  SQueryHbRspBasic* query;
3770
  SArray*           info;  // Array<Skv>
3771
} SClientHbRsp;
3772

3773
typedef struct {
3774
  int64_t       reqId;
3775
  int64_t       rspId;
3776
  int32_t       svrTimestamp;
3777
  SArray*       rsps;  // SArray<SClientHbRsp>
3778
  SMonitorParas monitorParas;
3779
  int8_t        enableAuditDelete;
3780
  int8_t        enableStrongPass;
3781
} SClientHbBatchRsp;
3782

3783
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
3,839✔
3784

3785
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3786
  void* pIter = taosHashIterate(info, NULL);
870✔
3787
  while (pIter != NULL) {
2,052!
3788
    SKv* kv = (SKv*)pIter;
1,182✔
3789
    taosMemoryFreeClear(kv->value);
1,182!
3790
    pIter = taosHashIterate(info, pIter);
1,182✔
3791
  }
3792
}
870✔
3793

3794
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
894✔
3795
  SQueryDesc* desc = (SQueryDesc*)pDesc;
894✔
3796
  if (desc->subDesc) {
894✔
3797
    taosArrayDestroy(desc->subDesc);
482✔
3798
    desc->subDesc = NULL;
482✔
3799
  }
3800
}
894✔
3801

3802
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
1,682✔
3803
  SClientHbReq* req = (SClientHbReq*)pReq;
1,970✔
3804
  if (req->query) {
1,970!
3805
    if (req->query->queryDesc) {
1,269!
3806
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
831✔
3807
    }
3808
    taosMemoryFreeClear(req->query);
1,269!
3809
  }
3810

3811
  if (req->info) {
1,970!
3812
    tFreeReqKvHash(req->info);
870✔
3813
    taosHashCleanup(req->info);
870✔
3814
    req->info = NULL;
870✔
3815
  }
3816
}
291✔
3817

3818
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3819
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3820

3821
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3822
  if (pReq == NULL) return;
1,466!
3823
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
1,466✔
3824
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
1,466✔
3825
  taosMemoryFree(pReq);
1,466!
3826
}
3827

3828
static FORCE_INLINE void tFreeClientKv(void* pKv) {
654✔
3829
  SKv* kv = (SKv*)pKv;
654✔
3830
  if (kv) {
654!
3831
    taosMemoryFreeClear(kv->value);
654!
3832
  }
3833
}
654✔
3834

3835
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
1,671✔
3836
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
1,671✔
3837
  if (rsp->query) {
1,671!
3838
    taosArrayDestroy(rsp->query->pQnodeList);
1,259✔
3839
    taosMemoryFreeClear(rsp->query);
1,259!
3840
  }
3841
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
1,671!
3842
}
1,669✔
3843

3844
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3845
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
1,460✔
3846
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
1,460✔
3847
}
1,460✔
3848

3849
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3850
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3851
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3852

3853
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3854
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
4,724!
3855
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
4,724!
3856
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
4,724!
3857
  return 0;
2,362✔
3858
}
3859

3860
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3861
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
1,312!
3862
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
1,312!
3863
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
656!
3864
  if (pKv->value == NULL) {
656!
3865
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3866
  }
3867
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
656!
3868
  return 0;
656✔
3869
}
3870

3871
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3872
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
6,728!
3873
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
6,728!
3874
  return 0;
3,364✔
3875
}
3876

3877
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3878
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
3,344!
3879
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
3,344!
3880
  return 0;
1,672✔
3881
}
3882

3883
typedef struct {
3884
  int32_t vgId;
3885
  // TODO stas
3886
} SMqReportVgInfo;
3887

3888
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3889
  int32_t tlen = 0;
3890
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3891
  return tlen;
3892
}
3893

3894
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3895
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3896
  return buf;
3897
}
3898

3899
typedef struct {
3900
  int32_t epoch;
3901
  int64_t topicUid;
3902
  char    name[TSDB_TOPIC_FNAME_LEN];
3903
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3904
} SMqTopicInfo;
3905

3906
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3907
  int32_t tlen = 0;
3908
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3909
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3910
  tlen += taosEncodeString(buf, pTopicInfo->name);
3911
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3912
  tlen += taosEncodeFixedI32(buf, sz);
3913
  for (int32_t i = 0; i < sz; i++) {
3914
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3915
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3916
  }
3917
  return tlen;
3918
}
3919

3920
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3921
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3922
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3923
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3924
  int32_t sz;
3925
  buf = taosDecodeFixedI32(buf, &sz);
3926
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3927
    return NULL;
3928
  }
3929
  for (int32_t i = 0; i < sz; i++) {
3930
    SMqReportVgInfo vgInfo;
3931
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3932
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3933
      return NULL;
3934
    }
3935
  }
3936
  return buf;
3937
}
3938

3939
typedef struct {
3940
  int32_t status;  // ask hb endpoint
3941
  int32_t epoch;
3942
  int64_t consumerId;
3943
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3944
} SMqReportReq;
3945

3946
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3947
  int32_t tlen = 0;
3948
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3949
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3950
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3951
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3952
  tlen += taosEncodeFixedI32(buf, sz);
3953
  for (int32_t i = 0; i < sz; i++) {
3954
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3955
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3956
  }
3957
  return tlen;
3958
}
3959

3960
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3961
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3962
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3963
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3964
  int32_t sz;
3965
  buf = taosDecodeFixedI32(buf, &sz);
3966
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3967
    return NULL;
3968
  }
3969
  for (int32_t i = 0; i < sz; i++) {
3970
    SMqTopicInfo topicInfo;
3971
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3972
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3973
      return NULL;
3974
    }
3975
  }
3976
  return buf;
3977
}
3978

3979
typedef struct {
3980
  SMsgHead head;
3981
  int64_t  leftForVer;
3982
  int32_t  vgId;
3983
  int64_t  consumerId;
3984
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3985
} SMqVDeleteReq;
3986

3987
typedef struct {
3988
  int8_t reserved;
3989
} SMqVDeleteRsp;
3990

3991
typedef struct {
3992
  char    name[TSDB_STREAM_FNAME_LEN];
3993
  int8_t  igNotExists;
3994
  int32_t sqlLen;
3995
  char*   sql;
3996
} SMDropStreamReq;
3997

3998
typedef struct {
3999
  int8_t reserved;
4000
} SMDropStreamRsp;
4001

4002
typedef struct {
4003
  SMsgHead head;
4004
  int64_t  resetRelHalt;  // reset related stream task halt status
4005
  int64_t  streamId;
4006
  int32_t  taskId;
4007
} SVDropStreamTaskReq;
4008

4009
typedef struct {
4010
  int8_t reserved;
4011
} SVDropStreamTaskRsp;
4012

4013
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
4014
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
4015
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
4016

4017
typedef struct SVUpdateCheckpointInfoReq {
4018
  SMsgHead head;
4019
  int64_t  streamId;
4020
  int32_t  taskId;
4021
  int64_t  checkpointId;
4022
  int64_t  checkpointVer;
4023
  int64_t  checkpointTs;
4024
  int32_t  transId;
4025
  int64_t  hStreamId;  // add encode/decode
4026
  int64_t  hTaskId;
4027
  int8_t   dropRelHTask;
4028
} SVUpdateCheckpointInfoReq;
4029

4030
typedef struct {
4031
  int64_t leftForVer;
4032
  int32_t vgId;
4033
  int64_t oldConsumerId;
4034
  int64_t newConsumerId;
4035
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
4036
  int8_t  subType;
4037
  int8_t  withMeta;
4038
  char*   qmsg;  // SubPlanToString
4039
  int64_t suid;
4040
} SMqRebVgReq;
4041

4042
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
4043
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
4044

4045
typedef struct {
4046
  char    topic[TSDB_TOPIC_FNAME_LEN];
4047
  int64_t ntbUid;
4048
  SArray* colIdList;  // SArray<int16_t>
4049
} STqCheckInfo;
4050

4051
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
4052
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
4053
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
4054

4055
// tqOffset
4056
enum {
4057
  TMQ_OFFSET__RESET_NONE = -3,
4058
  TMQ_OFFSET__RESET_EARLIEST = -2,
4059
  TMQ_OFFSET__RESET_LATEST = -1,
4060
  TMQ_OFFSET__LOG = 1,
4061
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
4062
  TMQ_OFFSET__SNAPSHOT_META = 3,
4063
};
4064

4065
enum {
4066
  WITH_DATA = 0,
4067
  WITH_META = 1,
4068
  ONLY_META = 2,
4069
};
4070

4071
#define TQ_OFFSET_VERSION 1
4072

4073
typedef struct {
4074
  int8_t type;
4075
  union {
4076
    // snapshot
4077
    struct {
4078
      int64_t uid;
4079
      int64_t ts;
4080
      SValue  primaryKey;
4081
    };
4082
    // log
4083
    struct {
4084
      int64_t version;
4085
    };
4086
  };
4087
} STqOffsetVal;
4088

4089
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
4090
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
×
4091
  pOffsetVal->uid = uid;
×
4092
  pOffsetVal->ts = ts;
×
4093
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
×
4094
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
4095
  }
4096
  pOffsetVal->primaryKey = primaryKey;
×
4097
}
×
4098

4099
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
4100
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
×
4101
  pOffsetVal->uid = uid;
×
4102
}
×
4103

4104
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
4105
  pOffsetVal->type = TMQ_OFFSET__LOG;
×
4106
  pOffsetVal->version = ver;
×
4107
}
×
4108

4109
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
4110
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
4111
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
4112
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4113
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
4114
void    tOffsetDestroy(void* pVal);
4115

4116
typedef struct {
4117
  STqOffsetVal val;
4118
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4119
} STqOffset;
4120

4121
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
4122
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
4123
void    tDeleteSTqOffset(void* val);
4124

4125
typedef struct SMqVgOffset {
4126
  int64_t   consumerId;
4127
  STqOffset offset;
4128
} SMqVgOffset;
4129

4130
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
4131
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
4132

4133
typedef struct {
4134
  SMsgHead head;
4135
  int64_t  streamId;
4136
  int32_t  taskId;
4137
} SVPauseStreamTaskReq;
4138

4139
typedef struct {
4140
  SMsgHead head;
4141
  int64_t  streamId;
4142
  int32_t  taskId;
4143
  int64_t  chkptId;
4144
} SVResetStreamTaskReq;
4145

4146
typedef struct {
4147
  char   name[TSDB_STREAM_FNAME_LEN];
4148
  int8_t igNotExists;
4149
} SMPauseStreamReq;
4150

4151
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
4152
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
4153

4154
typedef struct {
4155
  SMsgHead head;
4156
  int32_t  taskId;
4157
  int64_t  streamId;
4158
  int8_t   igUntreated;
4159
} SVResumeStreamTaskReq;
4160

4161
typedef struct {
4162
  int8_t reserved;
4163
} SVResumeStreamTaskRsp;
4164

4165
typedef struct {
4166
  char   name[TSDB_STREAM_FNAME_LEN];
4167
  int8_t igNotExists;
4168
  int8_t igUntreated;
4169
} SMResumeStreamReq;
4170

4171
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
4172
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
4173

4174
typedef struct {
4175
  char   name[TSDB_STREAM_FNAME_LEN];
4176
  int8_t igNotExists;
4177
  int8_t igUntreated;
4178
} SMResetStreamReq;
4179

4180
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
4181
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
4182

4183
typedef struct {
4184
  char    name[TSDB_TABLE_FNAME_LEN];
4185
  char    stb[TSDB_TABLE_FNAME_LEN];
4186
  int8_t  igExists;
4187
  int8_t  intervalUnit;
4188
  int8_t  slidingUnit;
4189
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
4190
  int32_t dstVgId;   // for stream
4191
  int64_t interval;
4192
  int64_t offset;
4193
  int64_t sliding;
4194
  int64_t maxDelay;
4195
  int64_t watermark;
4196
  int32_t exprLen;        // strlen + 1
4197
  int32_t tagsFilterLen;  // strlen + 1
4198
  int32_t sqlLen;         // strlen + 1
4199
  int32_t astLen;         // strlen + 1
4200
  char*   expr;
4201
  char*   tagsFilter;
4202
  char*   sql;
4203
  char*   ast;
4204
  int64_t deleteMark;
4205
  int64_t lastTs;
4206
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4207
  SArray* pVgroupVerList;
4208
  int8_t  recursiveTsma;
4209
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4210
} SMCreateSmaReq;
4211

4212
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4213
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4214
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4215

4216
typedef struct {
4217
  char   name[TSDB_TABLE_FNAME_LEN];
4218
  int8_t igNotExists;
4219
} SMDropSmaReq;
4220

4221
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4222
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4223

4224
typedef struct {
4225
  char   dbFName[TSDB_DB_FNAME_LEN];
4226
  char   stbName[TSDB_TABLE_NAME_LEN];
4227
  char   colName[TSDB_COL_NAME_LEN];
4228
  char   idxName[TSDB_INDEX_FNAME_LEN];
4229
  int8_t idxType;
4230
} SCreateTagIndexReq;
4231

4232
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4233
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4234

4235
typedef SMDropSmaReq SDropTagIndexReq;
4236

4237
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4238
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4239

4240
typedef struct {
4241
  int8_t         version;       // for compatibility(default 0)
4242
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4243
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4244
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4245
  int32_t        dstVgId;
4246
  char           indexName[TSDB_INDEX_NAME_LEN];
4247
  int32_t        exprLen;
4248
  int32_t        tagsFilterLen;
4249
  int64_t        indexUid;
4250
  tb_uid_t       tableUid;  // super/child/common table uid
4251
  tb_uid_t       dstTbUid;  // for dstVgroup
4252
  int64_t        interval;
4253
  int64_t        offset;  // use unit by precision of DB
4254
  int64_t        sliding;
4255
  char*          dstTbName;  // for dstVgroup
4256
  char*          expr;       // sma expression
4257
  char*          tagsFilter;
4258
  SSchemaWrapper schemaRow;  // for dstVgroup
4259
  SSchemaWrapper schemaTag;  // for dstVgroup
4260
} STSma;                     // Time-range-wise SMA
4261

4262
typedef STSma SVCreateTSmaReq;
4263

4264
typedef struct {
4265
  int8_t  type;  // 0 status report, 1 update data
4266
  int64_t indexUid;
4267
  int64_t skey;  // start TS key of interval/sliding window
4268
} STSmaMsg;
4269

4270
typedef struct {
4271
  int64_t indexUid;
4272
  char    indexName[TSDB_INDEX_NAME_LEN];
4273
} SVDropTSmaReq;
4274

4275
typedef struct {
4276
  int tmp;  // TODO: to avoid compile error
4277
} SVCreateTSmaRsp, SVDropTSmaRsp;
4278

4279
#if 0
4280
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4281
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4282
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4283
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4284
#endif
4285

4286
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4287
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4288
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4289
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4290

4291
typedef struct {
4292
  int32_t number;
4293
  STSma*  tSma;
4294
} STSmaWrapper;
4295

4296
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4297
  if (pSma) {
×
4298
    taosMemoryFreeClear(pSma->dstTbName);
×
4299
    taosMemoryFreeClear(pSma->expr);
×
4300
    taosMemoryFreeClear(pSma->tagsFilter);
×
4301
  }
4302
}
×
4303

4304
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4305
  if (pSW) {
×
4306
    if (pSW->tSma) {
×
4307
      if (deepCopy) {
×
4308
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4309
          tDestroyTSma(pSW->tSma + i);
×
4310
        }
4311
      }
4312
      taosMemoryFreeClear(pSW->tSma);
×
4313
    }
4314
  }
4315
}
×
4316

4317
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4318
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4319
  taosMemoryFreeClear(pSW);
×
4320
  return NULL;
×
4321
}
4322

4323
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4324
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4325

4326
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4327
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4328

4329
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4330
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4331
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4332
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4333
  }
4334
  return 0;
×
4335
}
4336

4337
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4338
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4339
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4340
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4341
  }
4342
  return 0;
×
4343
}
4344

4345
typedef struct {
4346
  int idx;
4347
} SMCreateFullTextReq;
4348

4349
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4350
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4351
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4352

4353
typedef struct {
4354
  char   name[TSDB_TABLE_FNAME_LEN];
4355
  int8_t igNotExists;
4356
} SMDropFullTextReq;
4357

4358
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4359
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4360

4361
typedef struct {
4362
  char indexFName[TSDB_INDEX_FNAME_LEN];
4363
} SUserIndexReq;
4364

4365
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4366
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4367

4368
typedef struct {
4369
  char dbFName[TSDB_DB_FNAME_LEN];
4370
  char tblFName[TSDB_TABLE_FNAME_LEN];
4371
  char colName[TSDB_COL_NAME_LEN];
4372
  char indexType[TSDB_INDEX_TYPE_LEN];
4373
  char indexExts[TSDB_INDEX_EXTS_LEN];
4374
} SUserIndexRsp;
4375

4376
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4377
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4378

4379
typedef struct {
4380
  char tbFName[TSDB_TABLE_FNAME_LEN];
4381
} STableIndexReq;
4382

4383
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4384
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4385

4386
typedef struct {
4387
  int8_t  intervalUnit;
4388
  int8_t  slidingUnit;
4389
  int64_t interval;
4390
  int64_t offset;
4391
  int64_t sliding;
4392
  int64_t dstTbUid;
4393
  int32_t dstVgId;
4394
  SEpSet  epSet;
4395
  char*   expr;
4396
} STableIndexInfo;
4397

4398
typedef struct {
4399
  char     tbName[TSDB_TABLE_NAME_LEN];
4400
  char     dbFName[TSDB_DB_FNAME_LEN];
4401
  uint64_t suid;
4402
  int32_t  version;
4403
  int32_t  indexSize;
4404
  SArray*  pIndex;  // STableIndexInfo
4405
} STableIndexRsp;
4406

4407
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4408
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4409
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4410

4411
void tFreeSTableIndexInfo(void* pInfo);
4412

4413
typedef struct {
4414
  int8_t  mqMsgType;
4415
  int32_t code;
4416
  int32_t epoch;
4417
  int64_t consumerId;
4418
  int64_t walsver;
4419
  int64_t walever;
4420
} SMqRspHead;
4421

4422
typedef struct {
4423
  SMsgHead     head;
4424
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4425
  int8_t       withTbName;
4426
  int8_t       useSnapshot;
4427
  int32_t      epoch;
4428
  uint64_t     reqId;
4429
  int64_t      consumerId;
4430
  int64_t      timeout;
4431
  STqOffsetVal reqOffset;
4432
  int8_t       enableReplay;
4433
  int8_t       sourceExcluded;
4434
  int8_t       rawData;
4435
  int32_t      minPollRows;
4436
  int8_t       enableBatchMeta;
4437
  SHashObj     *uidHash;  // to find if uid is duplicated
4438
} SMqPollReq;
4439

4440
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4441
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4442
void    tDestroySMqPollReq(SMqPollReq* pReq);
4443

4444
typedef struct {
4445
  int32_t vgId;
4446
  int64_t offset;
4447
  SEpSet  epSet;
4448
} SMqSubVgEp;
4449

4450
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4451
  int32_t tlen = 0;
×
4452
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
×
4453
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
×
4454
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
×
4455
  return tlen;
×
4456
}
4457

4458
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4459
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
2!
4460
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
2!
4461
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
2✔
4462
  return buf;
2✔
4463
}
4464

4465
typedef struct {
4466
  char           topic[TSDB_TOPIC_FNAME_LEN];
4467
  char           db[TSDB_DB_FNAME_LEN];
4468
  SArray*        vgs;  // SArray<SMqSubVgEp>
4469
  SSchemaWrapper schema;
4470
} SMqSubTopicEp;
4471

4472
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4473
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4474
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4475

4476
typedef struct {
4477
  SMqRspHead   head;
4478
  STqOffsetVal rspOffset;
4479
  int16_t      resMsgType;
4480
  int32_t      metaRspLen;
4481
  void*        metaRsp;
4482
} SMqMetaRsp;
4483

4484
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4485
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4486
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4487

4488
#define MQ_DATA_RSP_VERSION 100
4489

4490
typedef struct {
4491
  SMqRspHead   head;
4492
  STqOffsetVal rspOffset;
4493
  STqOffsetVal reqOffset;
4494
  int32_t      blockNum;
4495
  int8_t       withTbName;
4496
  int8_t       withSchema;
4497
  SArray*      blockDataLen;
4498
  SArray*      blockData;
4499
  SArray*      blockTbName;
4500
  SArray*      blockSchema;
4501

4502
  union {
4503
    struct {
4504
      int64_t sleepTime;
4505
    };
4506
    struct {
4507
      int32_t createTableNum;
4508
      SArray* createTableLen;
4509
      SArray* createTableReq;
4510
    };
4511
    struct{
4512
      int32_t len;
4513
      void*   rawData;
4514
    };
4515
  };
4516
  void*   data;  //for free in client, only effected if type is data or metadata. raw data not effected
4517
  bool    blockDataElementFree;   // if true, free blockDataElement in blockData,(true in server, false in client)
4518
} SMqDataRsp;
4519

4520
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4521
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4522
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4523
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4524
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4525

4526
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4527
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4528
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4529

4530
typedef struct SMqBatchMetaRsp {
4531
  SMqRspHead   head;  // not serialize
4532
  STqOffsetVal rspOffset;
4533
  SArray*      batchMetaLen;
4534
  SArray*      batchMetaReq;
4535
  void*        pMetaBuff;    // not serialize
4536
  uint32_t     metaBuffLen;  // not serialize
4537
} SMqBatchMetaRsp;
4538

4539
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4540
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4541
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4542
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4543

4544
typedef struct {
4545
  SMqRspHead head;
4546
  char       cgroup[TSDB_CGROUP_LEN];
4547
  SArray*    topics;  // SArray<SMqSubTopicEp>
4548
} SMqAskEpRsp;
4549

4550
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4551
  int32_t tlen = 0;
×
4552
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4553
  int32_t sz = taosArrayGetSize(pRsp->topics);
×
4554
  tlen += taosEncodeFixedI32(buf, sz);
×
4555
  for (int32_t i = 0; i < sz; i++) {
×
4556
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
×
4557
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
×
4558
  }
4559
  return tlen;
×
4560
}
4561

4562
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4563
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4564
  int32_t sz;
4565
  buf = taosDecodeFixedI32(buf, &sz);
11✔
4566
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
11✔
4567
  if (pRsp->topics == NULL) {
11!
4568
    return NULL;
×
4569
  }
4570
  for (int32_t i = 0; i < sz; i++) {
12!
4571
    SMqSubTopicEp topicEp;
4572
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
1✔
4573
    if (buf == NULL) {
1!
4574
      return NULL;
×
4575
    }
4576
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
2!
4577
      return NULL;
×
4578
    }
4579
  }
4580
  return buf;
11✔
4581
}
4582

4583
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4584
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
11✔
4585
}
11✔
4586

4587
typedef struct {
4588
  int32_t      vgId;
4589
  STqOffsetVal offset;
4590
  int64_t      rows;
4591
  int64_t      ever;
4592
} OffsetRows;
4593

4594
typedef struct {
4595
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4596
  SArray* offsetRows;
4597
} TopicOffsetRows;
4598

4599
typedef struct {
4600
  int64_t consumerId;
4601
  int32_t epoch;
4602
  SArray* topics;
4603
  int8_t  pollFlag;
4604
} SMqHbReq;
4605

4606
typedef struct {
4607
  char   topic[TSDB_TOPIC_FNAME_LEN];
4608
  int8_t noPrivilege;
4609
} STopicPrivilege;
4610

4611
typedef struct {
4612
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4613
  int32_t debugFlag;
4614
} SMqHbRsp;
4615

4616
typedef struct {
4617
  SMsgHead head;
4618
  int64_t  consumerId;
4619
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4620
} SMqSeekReq;
4621

4622
#define TD_AUTO_CREATE_TABLE 0x1
4623
typedef struct {
4624
  int64_t       suid;
4625
  int64_t       uid;
4626
  int32_t       sver;
4627
  uint32_t      nData;
4628
  uint8_t*      pData;
4629
  SVCreateTbReq cTbReq;
4630
} SVSubmitBlk;
4631

4632
typedef struct {
4633
  SMsgHead header;
4634
  uint64_t sId;
4635
  uint64_t queryId;
4636
  uint64_t clientId;
4637
  uint64_t taskId;
4638
  uint32_t sqlLen;
4639
  uint32_t phyLen;
4640
  char*    sql;
4641
  char*    msg;
4642
  int8_t   source;
4643
} SVDeleteReq;
4644

4645
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4646
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4647

4648
typedef struct {
4649
  int64_t affectedRows;
4650
} SVDeleteRsp;
4651

4652
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4653
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4654

4655
typedef struct SDeleteRes {
4656
  uint64_t suid;
4657
  SArray*  uidList;
4658
  int64_t  skey;
4659
  int64_t  ekey;
4660
  int64_t  affectedRows;
4661
  char     tableFName[TSDB_TABLE_NAME_LEN];
4662
  char     tsColName[TSDB_COL_NAME_LEN];
4663
  int64_t  ctimeMs;  // fill by vnode
4664
  int8_t   source;
4665
} SDeleteRes;
4666

4667
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4668
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4669

4670
typedef struct {
4671
  // int64_t uid;
4672
  char    tbname[TSDB_TABLE_NAME_LEN];
4673
  int64_t startTs;
4674
  int64_t endTs;
4675
} SSingleDeleteReq;
4676

4677
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4678
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4679

4680
typedef struct {
4681
  int64_t suid;
4682
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4683
  int64_t ctimeMs;     // fill by vnode
4684
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4685
} SBatchDeleteReq;
4686

4687
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4688
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4689
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4690

4691
typedef struct {
4692
  int32_t msgIdx;
4693
  int32_t msgType;
4694
  int32_t msgLen;
4695
  void*   msg;
4696
} SBatchMsg;
4697

4698
typedef struct {
4699
  SMsgHead header;
4700
  SArray*  pMsgs;  // SArray<SBatchMsg>
4701
} SBatchReq;
4702

4703
typedef struct {
4704
  int32_t reqType;
4705
  int32_t msgIdx;
4706
  int32_t msgLen;
4707
  int32_t rspCode;
4708
  void*   msg;
4709
} SBatchRspMsg;
4710

4711
typedef struct {
4712
  SArray* pRsps;  // SArray<SBatchRspMsg>
4713
} SBatchRsp;
4714

4715
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4716
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4717
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
10✔
4718
  if (NULL == msg) {
10!
4719
    return;
×
4720
  }
4721
  SBatchMsg* pMsg = (SBatchMsg*)msg;
10✔
4722
  taosMemoryFree(pMsg->msg);
10!
4723
}
4724

4725
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4726
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4727

4728
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,005✔
4729
  if (NULL == p) {
1,005!
4730
    return;
×
4731
  }
4732

4733
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,005✔
4734
  taosMemoryFree(pRsp->msg);
1,005!
4735
}
4736

4737
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4738
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4739
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4740
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4741
void    tDestroySMqHbReq(SMqHbReq* pReq);
4742

4743
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4744
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4745
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4746

4747
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4748
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4749

4750
#define TD_REQ_FROM_APP               0x0
4751
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4752
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4753
#define SUBMIT_REQ_FROM_FILE          0x4
4754
#define TD_REQ_FROM_TAOX              0x8
4755
#define SUBMIT_REQUEST_VERSION        (1)
4756

4757
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4758

4759
typedef struct {
4760
  int32_t        flags;
4761
  SVCreateTbReq* pCreateTbReq;
4762
  int64_t        suid;
4763
  int64_t        uid;
4764
  int32_t        sver;
4765
  union {
4766
    SArray* aRowP;
4767
    SArray* aCol;
4768
  };
4769
  int64_t ctimeMs;
4770
} SSubmitTbData;
4771

4772
typedef struct {
4773
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4774
  bool    raw;
4775
} SSubmitReq2;
4776

4777
typedef struct {
4778
  SMsgHead header;
4779
  int64_t  version;
4780
  char     data[];  // SSubmitReq2
4781
} SSubmitReq2Msg;
4782

4783
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4784
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4785
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4786
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4787
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4788

4789
typedef struct {
4790
  int32_t affectedRows;
4791
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4792
} SSubmitRsp2;
4793

4794
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4795
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4796
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4797

4798
#define TSDB_MSG_FLG_ENCODE 0x1
4799
#define TSDB_MSG_FLG_DECODE 0x2
4800
#define TSDB_MSG_FLG_CMPT   0x3
4801

4802
typedef struct {
4803
  union {
4804
    struct {
4805
      void*   msgStr;
4806
      int32_t msgLen;
4807
      int64_t ver;
4808
    };
4809
    void* pDataBlock;
4810
  };
4811
} SPackedData;
4812

4813
typedef struct {
4814
  char     fullname[TSDB_VIEW_FNAME_LEN];
4815
  char     name[TSDB_VIEW_NAME_LEN];
4816
  char     dbFName[TSDB_DB_FNAME_LEN];
4817
  char*    querySql;
4818
  char*    sql;
4819
  int8_t   orReplace;
4820
  int8_t   precision;
4821
  int32_t  numOfCols;
4822
  SSchema* pSchema;
4823
} SCMCreateViewReq;
4824

4825
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4826
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4827
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
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*  sql;
4834
  int8_t igNotExists;
4835
} SCMDropViewReq;
4836

4837
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4838
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4839
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4840

4841
typedef struct {
4842
  char fullname[TSDB_VIEW_FNAME_LEN];
4843
} SViewMetaReq;
4844
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4845
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4846

4847
typedef struct {
4848
  char     name[TSDB_VIEW_NAME_LEN];
4849
  char     dbFName[TSDB_DB_FNAME_LEN];
4850
  char*    user;
4851
  uint64_t dbId;
4852
  uint64_t viewId;
4853
  char*    querySql;
4854
  int8_t   precision;
4855
  int8_t   type;
4856
  int32_t  version;
4857
  int32_t  numOfCols;
4858
  SSchema* pSchema;
4859
} SViewMetaRsp;
4860
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4861
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4862
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4863
typedef struct {
4864
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4865
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4866
} STableTSMAInfoReq;
4867

4868
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4869
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4870

4871
typedef struct {
4872
  int32_t  funcId;
4873
  col_id_t colId;
4874
} STableTSMAFuncInfo;
4875

4876
typedef struct {
4877
  char     name[TSDB_TABLE_NAME_LEN];
4878
  uint64_t tsmaId;
4879
  char     targetTb[TSDB_TABLE_NAME_LEN];
4880
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4881
  char     tb[TSDB_TABLE_NAME_LEN];
4882
  char     dbFName[TSDB_DB_FNAME_LEN];
4883
  uint64_t suid;
4884
  uint64_t destTbUid;
4885
  uint64_t dbId;
4886
  int32_t  version;
4887
  int64_t  interval;
4888
  int8_t   unit;
4889
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4890
  SArray*  pTags;      // SArray<SSchema>
4891
  SArray*  pUsedCols;  // SArray<SSchema>
4892
  char*    ast;
4893

4894
  int64_t streamUid;
4895
  int64_t reqTs;
4896
  int64_t rspTs;
4897
  int64_t delayDuration;  // ms
4898
  bool    fillHistoryFinished;
4899
} STableTSMAInfo;
4900

4901
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4902
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4903
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4904
void    tFreeTableTSMAInfo(void* p);
4905
void    tFreeAndClearTableTSMAInfo(void* p);
4906
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4907

4908
#define STSMAHbRsp            STableTSMAInfoRsp
4909
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4910
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4911
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4912

4913
typedef struct SStreamProgressReq {
4914
  int64_t streamId;
4915
  int32_t vgId;
4916
  int32_t fetchIdx;
4917
  int32_t subFetchIdx;
4918
} SStreamProgressReq;
4919

4920
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4921
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4922

4923
typedef struct SStreamProgressRsp {
4924
  int64_t streamId;
4925
  int32_t vgId;
4926
  bool    fillHisFinished;
4927
  int64_t progressDelay;
4928
  int32_t fetchIdx;
4929
  int32_t subFetchIdx;
4930
} SStreamProgressRsp;
4931

4932
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4933
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4934

4935
typedef struct SDropCtbWithTsmaSingleVgReq {
4936
  SVgroupInfo vgInfo;
4937
  SArray*     pTbs;  // SVDropTbReq
4938
} SMDropTbReqsOnSingleVg;
4939

4940
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4941
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4942
void    tFreeSMDropTbReqOnSingleVg(void* p);
4943

4944
typedef struct SDropTbsReq {
4945
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4946
} SMDropTbsReq;
4947

4948
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4949
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4950
void    tFreeSMDropTbsReq(void*);
4951

4952
typedef struct SVFetchTtlExpiredTbsRsp {
4953
  SArray* pExpiredTbs;  // SVDropTbReq
4954
  int32_t vgId;
4955
} SVFetchTtlExpiredTbsRsp;
4956

4957
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4958
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4959

4960
void tFreeFetchTtlExpiredTbsRsp(void* p);
4961

4962
void setDefaultOptionsForField(SFieldWithOptions* field);
4963
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4964

4965
#pragma pack(pop)
4966

4967
#ifdef __cplusplus
4968
}
4969
#endif
4970

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