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

taosdata / TDengine / #3633

11 Mar 2025 12:59PM UTC coverage: 0.0% (-60.7%) from 60.719%
#3633

push

travis-ci

web-flow
Merge pull request #30118 from taosdata/wl30

udpate ci workflow

0 of 280412 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 275582 relevant lines covered (0.0%)

0.0 hits per line

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

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

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
×
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
×
91
}
92

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

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

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

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

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

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

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

206
#define TSDB_KILL_MSG_LEN 30
207

208
#define TSDB_TABLE_NUM_UNIT 100000
209

210
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
211
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
212
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
213

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

220
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
221
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
222
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
223
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
224

225
#define TD_SUPER_TABLE  TSDB_SUPER_TABLE
226
#define TD_CHILD_TABLE  TSDB_CHILD_TABLE
227
#define TD_NORMAL_TABLE TSDB_NORMAL_TABLE
228

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

274
  // Statement nodes are used in parser and planner module.
275
  QUERY_NODE_SET_OPERATOR = 100,
276
  QUERY_NODE_SELECT_STMT,
277
  QUERY_NODE_VNODE_MODIFY_STMT,
278
  QUERY_NODE_CREATE_DATABASE_STMT,
279
  QUERY_NODE_DROP_DATABASE_STMT,
280
  QUERY_NODE_ALTER_DATABASE_STMT,
281
  QUERY_NODE_FLUSH_DATABASE_STMT,
282
  QUERY_NODE_TRIM_DATABASE_STMT,
283
  QUERY_NODE_CREATE_TABLE_STMT,
284
  QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
285
  QUERY_NODE_CREATE_MULTI_TABLES_STMT,
286
  QUERY_NODE_DROP_TABLE_CLAUSE,
287
  QUERY_NODE_DROP_TABLE_STMT,
288
  QUERY_NODE_DROP_SUPER_TABLE_STMT,
289
  QUERY_NODE_ALTER_TABLE_STMT,
290
  QUERY_NODE_ALTER_SUPER_TABLE_STMT,
291
  QUERY_NODE_CREATE_USER_STMT,
292
  QUERY_NODE_ALTER_USER_STMT,
293
  QUERY_NODE_DROP_USER_STMT,
294
  QUERY_NODE_USE_DATABASE_STMT,
295
  QUERY_NODE_CREATE_DNODE_STMT,
296
  QUERY_NODE_DROP_DNODE_STMT,
297
  QUERY_NODE_ALTER_DNODE_STMT,
298
  QUERY_NODE_CREATE_INDEX_STMT,
299
  QUERY_NODE_DROP_INDEX_STMT,
300
  QUERY_NODE_CREATE_QNODE_STMT,
301
  QUERY_NODE_DROP_QNODE_STMT,
302
  QUERY_NODE_CREATE_BNODE_STMT,
303
  QUERY_NODE_DROP_BNODE_STMT,
304
  QUERY_NODE_CREATE_SNODE_STMT,
305
  QUERY_NODE_DROP_SNODE_STMT,
306
  QUERY_NODE_CREATE_MNODE_STMT,
307
  QUERY_NODE_DROP_MNODE_STMT,
308
  QUERY_NODE_CREATE_TOPIC_STMT,
309
  QUERY_NODE_DROP_TOPIC_STMT,
310
  QUERY_NODE_DROP_CGROUP_STMT,
311
  QUERY_NODE_ALTER_LOCAL_STMT,
312
  QUERY_NODE_EXPLAIN_STMT,
313
  QUERY_NODE_DESCRIBE_STMT,
314
  QUERY_NODE_RESET_QUERY_CACHE_STMT,
315
  QUERY_NODE_COMPACT_DATABASE_STMT,
316
  QUERY_NODE_COMPACT_VGROUPS_STMT,
317
  QUERY_NODE_CREATE_FUNCTION_STMT,
318
  QUERY_NODE_DROP_FUNCTION_STMT,
319
  QUERY_NODE_CREATE_STREAM_STMT,
320
  QUERY_NODE_DROP_STREAM_STMT,
321
  QUERY_NODE_BALANCE_VGROUP_STMT,
322
  QUERY_NODE_MERGE_VGROUP_STMT,
323
  QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
324
  QUERY_NODE_SPLIT_VGROUP_STMT,
325
  QUERY_NODE_SYNCDB_STMT,
326
  QUERY_NODE_GRANT_STMT,
327
  QUERY_NODE_REVOKE_STMT,
328
  QUERY_NODE_ALTER_CLUSTER_STMT,
329
  QUERY_NODE_S3MIGRATE_DATABASE_STMT,
330
  // placeholder for [154, 180]
331
  QUERY_NODE_SHOW_CREATE_VIEW_STMT = 181,
332
  QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
333
  QUERY_NODE_SHOW_CREATE_TABLE_STMT,
334
  QUERY_NODE_SHOW_CREATE_STABLE_STMT,
335
  QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT,
336
  QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT,
337
  QUERY_NODE_SHOW_SCORES_STMT,
338
  QUERY_NODE_SHOW_TABLE_TAGS_STMT,
339
  QUERY_NODE_KILL_CONNECTION_STMT,
340
  QUERY_NODE_KILL_QUERY_STMT,
341
  QUERY_NODE_KILL_TRANSACTION_STMT,
342
  QUERY_NODE_KILL_COMPACT_STMT,
343
  QUERY_NODE_DELETE_STMT,
344
  QUERY_NODE_INSERT_STMT,
345
  QUERY_NODE_QUERY,
346
  QUERY_NODE_SHOW_DB_ALIVE_STMT,
347
  QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
348
  QUERY_NODE_BALANCE_VGROUP_LEADER_STMT,
349
  QUERY_NODE_BALANCE_VGROUP_LEADER_DATABASE_STMT,
350
  QUERY_NODE_RESTORE_DNODE_STMT,
351
  QUERY_NODE_RESTORE_QNODE_STMT,
352
  QUERY_NODE_RESTORE_MNODE_STMT,
353
  QUERY_NODE_RESTORE_VNODE_STMT,
354
  QUERY_NODE_PAUSE_STREAM_STMT,
355
  QUERY_NODE_RESUME_STREAM_STMT,
356
  QUERY_NODE_CREATE_VIEW_STMT,
357
  QUERY_NODE_DROP_VIEW_STMT,
358
  QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE,
359
  QUERY_NODE_CREATE_ANODE_STMT,
360
  QUERY_NODE_DROP_ANODE_STMT,
361
  QUERY_NODE_UPDATE_ANODE_STMT,
362
  QUERY_NODE_ASSIGN_LEADER_STMT,
363

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

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

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

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

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

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

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

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

529
#pragma pack(push, 1)
530

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

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

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

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

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

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

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

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

602
//
603

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

735
  return pDstWrapper;
736
}
737

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

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

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

771
  taosMemoryFreeClear(pWrapper->pColCmpr);
772
  taosMemoryFreeClear(pWrapper);
773
}
774
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
775
  if (pSchemaWrapper->pSchema == NULL) return NULL;
×
776

777
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
×
778
  if (pSW == NULL) {
×
779
    return NULL;
×
780
  }
781
  pSW->nCols = pSchemaWrapper->nCols;
×
782
  pSW->version = pSchemaWrapper->version;
×
783
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
×
784
  if (pSW->pSchema == NULL) {
×
785
    taosMemoryFree(pSW);
×
786
    return NULL;
×
787
  }
788

789
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
×
790
  return pSW;
×
791
}
792

793
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
×
794
  if (pSchemaWrapper) {
×
795
    taosMemoryFree(pSchemaWrapper->pSchema);
×
796
    taosMemoryFree(pSchemaWrapper);
×
797
  }
798
}
×
799

800
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
×
801
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
×
802
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
×
803
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
×
804
  }
805
}
×
806

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

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

826
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
827
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
×
828
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
×
829
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
×
830
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
×
831
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
×
832
  return 0;
×
833
}
834

835
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
836
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
×
837
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
×
838
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
×
839
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
×
840
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
×
841
  return 0;
×
842
}
843

844
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
845
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
×
846
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
×
847
  return 0;
×
848
}
849

850
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
851
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
×
852
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
×
853
  return 0;
×
854
}
855

856
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
857
  int32_t tlen = 0;
×
858
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
×
859
  tlen += taosEncodeVariantI32(buf, pSW->version);
×
860
  for (int32_t i = 0; i < pSW->nCols; i++) {
×
861
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
×
862
  }
863
  return tlen;
×
864
}
865

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

875
    for (int32_t i = 0; i < pSW->nCols; i++) {
×
876
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
×
877
    }
878
  } else {
879
    pSW->pSchema = NULL;
×
880
  }
881
  return (void*)buf;
×
882
}
883

884
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
885
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
×
886
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
×
887
  for (int32_t i = 0; i < pSW->nCols; i++) {
×
888
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
×
889
  }
890
  return 0;
×
891
}
892

893
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
894
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
×
895
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
×
896

897
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
×
898
  if (pSW->pSchema == NULL) {
×
899
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
900
  }
901
  for (int32_t i = 0; i < pSW->nCols; i++) {
×
902
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
×
903
  }
904

905
  return 0;
×
906
}
907

908
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
909
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
×
910
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
×
911

912
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
×
913
  if (pSW->pSchema == NULL) {
×
914
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
915
  }
916
  for (int32_t i = 0; i < pSW->nCols; i++) {
×
917
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
×
918
  }
919

920
  return 0;
×
921
}
922

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1118
typedef struct {
1119
  int64_t ipWhiteVer;
1120
} SRetrieveIpWhiteReq;
1121

1122
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1123
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1124

1125
typedef struct {
1126
  int32_t dnodeId;
1127
  int64_t analVer;
1128
} SRetrieveAnalAlgoReq;
1129

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

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

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

1168
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1169
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1170
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1171

1172
typedef struct {
1173
  char user[TSDB_USER_LEN];
1174
} SGetUserAuthReq;
1175

1176
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1177
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1178

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

1200
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1201
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1202
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1203

1204
typedef struct {
1205
  char user[TSDB_USER_LEN];
1206
} SGetUserWhiteListReq;
1207

1208
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1209
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1210

1211
typedef struct {
1212
  char        user[TSDB_USER_LEN];
1213
  int32_t     numWhiteLists;
1214
  SIpV4Range* pWhiteLists;
1215
} SGetUserWhiteListRsp;
1216

1217
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1218
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1219
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1220

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

1231
  uint8_t precision;
1232
  uint8_t scale;
1233
  int32_t bytes;
1234
  int8_t  type;
1235
  uint8_t pk;
1236
  bool    noData;
1237
} SColumnInfo;
1238

1239
typedef struct STimeWindow {
1240
  TSKEY skey;
1241
  TSKEY ekey;
1242
} STimeWindow;
1243

1244
typedef struct SQueryHint {
1245
  bool batchScan;
1246
} SQueryHint;
1247

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

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

1267
typedef struct STbVerInfo {
1268
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1269
  int32_t sversion;
1270
  int32_t tversion;
1271
} STbVerInfo;
1272

1273
typedef struct {
1274
  int32_t code;
1275
  int64_t affectedRows;
1276
  SArray* tbVerInfo;  // STbVerInfo
1277
} SQueryTableRsp;
1278

1279
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1280

1281
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1282

1283
typedef struct {
1284
  SMsgHead header;
1285
  char     dbFName[TSDB_DB_FNAME_LEN];
1286
  char     tbName[TSDB_TABLE_NAME_LEN];
1287
} STableCfgReq;
1288

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

1310
typedef STableCfg STableCfgRsp;
1311

1312
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1313
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1314

1315
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1316
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1317
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1318

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

1368
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1369
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1370
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1371

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

1404
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1405
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1406
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1407

1408
typedef struct {
1409
  char    db[TSDB_DB_FNAME_LEN];
1410
  int8_t  ignoreNotExists;
1411
  int32_t sqlLen;
1412
  char*   sql;
1413
} SDropDbReq;
1414

1415
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1416
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1417
void    tFreeSDropDbReq(SDropDbReq* pReq);
1418

1419
typedef struct {
1420
  char    db[TSDB_DB_FNAME_LEN];
1421
  int64_t uid;
1422
} SDropDbRsp;
1423

1424
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1425
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1426

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

1435
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1436
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1437

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

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

1457
typedef struct {
1458
  char db[TSDB_DB_FNAME_LEN];
1459
} SDbCfgReq;
1460

1461
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1462
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1463

1464
typedef struct {
1465
  char    db[TSDB_DB_FNAME_LEN];
1466
  int32_t maxSpeed;
1467
} STrimDbReq;
1468

1469
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1470
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1471

1472
typedef struct {
1473
  int32_t timestamp;
1474
} SVTrimDbReq;
1475

1476
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1477
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1478

1479
typedef struct {
1480
  char db[TSDB_DB_FNAME_LEN];
1481
} SS3MigrateDbReq;
1482

1483
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1484
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1485

1486
typedef struct {
1487
  int32_t timestamp;
1488
} SVS3MigrateDbReq;
1489

1490
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1491
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1492

1493
typedef struct {
1494
  int32_t timestampSec;
1495
  int32_t ttlDropMaxCount;
1496
  int32_t nUids;
1497
  SArray* pTbUids;
1498
} SVDropTtlTableReq;
1499

1500
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1501
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1502

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

1550
typedef SDbCfgRsp SDbCfgInfo;
1551

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

1558
typedef struct {
1559
  int32_t rowNum;
1560
} SQnodeListReq;
1561

1562
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1563
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1564

1565
typedef struct {
1566
  int32_t rowNum;
1567
} SDnodeListReq;
1568

1569
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1570

1571
typedef struct {
1572
  int32_t useless;  // useless
1573
} SServerVerReq;
1574

1575
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1576
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1577

1578
typedef struct {
1579
  char ver[TSDB_VERSION_LEN];
1580
} SServerVerRsp;
1581

1582
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1583
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1584

1585
typedef struct SQueryNodeAddr {
1586
  int32_t nodeId;  // vgId or qnodeId
1587
  SEpSet  epSet;
1588
} SQueryNodeAddr;
1589

1590
typedef struct {
1591
  SQueryNodeAddr addr;
1592
  uint64_t       load;
1593
} SQueryNodeLoad;
1594

1595
typedef struct {
1596
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1597
} SQnodeListRsp;
1598

1599
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1600
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1601
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1602

1603
typedef struct {
1604
  SArray* dnodeList;  // SArray<SEpSet>
1605
} SDnodeListRsp;
1606

1607
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1608
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1609
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1610

1611
typedef struct {
1612
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1613
} STableTSMAInfoRsp;
1614

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

1624
typedef struct {
1625
  SArray* pArray;  // Array of SDbHbRsp
1626
} SDbHbBatchRsp;
1627

1628
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1629
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1630
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1631

1632
typedef struct {
1633
  SArray* pArray;  // Array of SGetUserAuthRsp
1634
} SUserAuthBatchRsp;
1635

1636
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1637
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1638
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1639

1640
typedef struct {
1641
  char        db[TSDB_DB_FNAME_LEN];
1642
  STimeWindow timeRange;
1643
  int32_t     sqlLen;
1644
  char*       sql;
1645
  SArray*     vgroupIds;
1646
  int8_t      metaOnly;
1647
} SCompactDbReq;
1648

1649
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1650
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1651
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1652

1653
typedef struct {
1654
  int32_t compactId;
1655
  int8_t  bAccepted;
1656
} SCompactDbRsp;
1657

1658
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1659
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1660

1661
typedef struct {
1662
  int32_t compactId;
1663
  int32_t sqlLen;
1664
  char*   sql;
1665
} SKillCompactReq;
1666

1667
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1668
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1669
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1670

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

1686
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1687
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1688
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1689

1690
typedef struct {
1691
  char   name[TSDB_FUNC_NAME_LEN];
1692
  int8_t igNotExists;
1693
} SDropFuncReq;
1694

1695
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1696
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1697

1698
typedef struct {
1699
  int32_t numOfFuncs;
1700
  bool    ignoreCodeComment;
1701
  SArray* pFuncNames;
1702
} SRetrieveFuncReq;
1703

1704
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1705
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1706
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1707

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

1722
typedef struct {
1723
  int32_t funcVersion;
1724
  int64_t funcCreatedTime;
1725
} SFuncExtraInfo;
1726

1727
typedef struct {
1728
  int32_t numOfFuncs;
1729
  SArray* pFuncInfos;
1730
  SArray* pFuncExtraInfos;
1731
} SRetrieveFuncRsp;
1732

1733
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1734
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1735
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1736
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1737

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

1751
typedef struct {
1752
  int32_t openVnodes;
1753
  int32_t dropVnodes;
1754
  int32_t totalVnodes;
1755
  int32_t masterNum;
1756
  int64_t numOfSelectReqs;
1757
  int64_t numOfInsertReqs;
1758
  int64_t numOfInsertSuccessReqs;
1759
  int64_t numOfBatchInsertReqs;
1760
  int64_t numOfBatchInsertSuccessReqs;
1761
  int64_t errors;
1762
} SVnodesStat;
1763

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

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

1804
typedef struct {
1805
  int32_t vgId;
1806
  int64_t nTimeSeries;
1807
} SVnodeLoadLite;
1808

1809
typedef struct {
1810
  int8_t  syncState;
1811
  int64_t syncTerm;
1812
  int8_t  syncRestore;
1813
  int64_t roleTimeMs;
1814
} SMnodeLoad;
1815

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

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

1856
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1857
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1858
void    tFreeSStatusReq(SStatusReq* pReq);
1859

1860
typedef struct {
1861
  int32_t forceReadConfig;
1862
  int32_t cver;
1863
  SArray* array;
1864
} SConfigReq;
1865

1866
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
1867
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
1868
void    tFreeSConfigReq(SConfigReq* pReq);
1869

1870
typedef struct {
1871
  int32_t dnodeId;
1872
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
1873
} SDnodeInfoReq;
1874

1875
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1876
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1877

1878
typedef enum {
1879
  MONITOR_TYPE_COUNTER = 0,
1880
  MONITOR_TYPE_SLOW_LOG = 1,
1881
} MONITOR_TYPE;
1882

1883
typedef struct {
1884
  int32_t      contLen;
1885
  char*        pCont;
1886
  MONITOR_TYPE type;
1887
} SStatisReq;
1888

1889
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1890
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1891
void    tFreeSStatisReq(SStatisReq* pReq);
1892

1893
typedef struct {
1894
  char    db[TSDB_DB_FNAME_LEN];
1895
  char    table[TSDB_TABLE_NAME_LEN];
1896
  char    operation[AUDIT_OPERATION_LEN];
1897
  int32_t sqlLen;
1898
  char*   pSql;
1899
} SAuditReq;
1900
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
1901
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
1902
void    tFreeSAuditReq(SAuditReq* pReq);
1903

1904
typedef struct {
1905
  int32_t dnodeId;
1906
  int64_t clusterId;
1907
  SArray* pVloads;
1908
} SNotifyReq;
1909

1910
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1911
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1912
void    tFreeSNotifyReq(SNotifyReq* pReq);
1913

1914
typedef struct {
1915
  int32_t dnodeId;
1916
  int64_t clusterId;
1917
} SDnodeCfg;
1918

1919
typedef struct {
1920
  int32_t id;
1921
  int8_t  isMnode;
1922
  SEp     ep;
1923
} SDnodeEp;
1924

1925
typedef struct {
1926
  int32_t id;
1927
  int8_t  isMnode;
1928
  int8_t  offlineReason;
1929
  SEp     ep;
1930
  char    active[TSDB_ACTIVE_KEY_LEN];
1931
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
1932
} SDnodeInfo;
1933

1934
typedef struct {
1935
  int64_t   dnodeVer;
1936
  SDnodeCfg dnodeCfg;
1937
  SArray*   pDnodeEps;  // Array of SDnodeEp
1938
  int32_t   statusSeq;
1939
  int64_t   ipWhiteVer;
1940
  int64_t   analVer;
1941
} SStatusRsp;
1942

1943
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1944
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1945
void    tFreeSStatusRsp(SStatusRsp* pRsp);
1946

1947
typedef struct {
1948
  int32_t forceReadConfig;
1949
  int32_t isConifgVerified;
1950
  int32_t isVersionVerified;
1951
  int32_t cver;
1952
  SArray* array;
1953
} SConfigRsp;
1954

1955
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
1956
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
1957
void    tFreeSConfigRsp(SConfigRsp* pRsp);
1958

1959
typedef struct {
1960
  int32_t reserved;
1961
} SMTimerReq;
1962

1963
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1964
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1965

1966
typedef struct SOrphanTask {
1967
  int64_t streamId;
1968
  int32_t taskId;
1969
  int32_t nodeId;
1970
} SOrphanTask;
1971

1972
typedef struct SMStreamDropOrphanMsg {
1973
  SArray* pList;  // SArray<SOrphanTask>
1974
} SMStreamDropOrphanMsg;
1975

1976
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1977
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1978
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
1979

1980
typedef struct {
1981
  int32_t  id;
1982
  uint16_t port;                 // node sync Port
1983
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
1984
} SReplica;
1985

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

2038
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2039
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2040
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2041

2042
typedef struct {
2043
  int32_t compactId;
2044
  int32_t vgId;
2045
  int32_t dnodeId;
2046
} SQueryCompactProgressReq;
2047

2048
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2049
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2050

2051
typedef struct {
2052
  int32_t compactId;
2053
  int32_t vgId;
2054
  int32_t dnodeId;
2055
  int32_t numberFileset;
2056
  int32_t finished;
2057
  int32_t progress;
2058
  int64_t remainingTime;
2059
} SQueryCompactProgressRsp;
2060

2061
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2062
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2063

2064
typedef struct {
2065
  int32_t vgId;
2066
  int32_t dnodeId;
2067
  int64_t dbUid;
2068
  char    db[TSDB_DB_FNAME_LEN];
2069
  int64_t reserved[8];
2070
} SDropVnodeReq;
2071

2072
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2073
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2074

2075
typedef struct {
2076
  char    colName[TSDB_COL_NAME_LEN];
2077
  char    stb[TSDB_TABLE_FNAME_LEN];
2078
  int64_t stbUid;
2079
  int64_t dbUid;
2080
  int64_t reserved[8];
2081
} SDropIndexReq;
2082

2083
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2084
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2085

2086
typedef struct {
2087
  int64_t     dbUid;
2088
  char        db[TSDB_DB_FNAME_LEN];
2089
  int64_t     compactStartTime;
2090
  STimeWindow tw;
2091
  int32_t     compactId;
2092
  int8_t      metaOnly;
2093
} SCompactVnodeReq;
2094

2095
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2096
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2097

2098
typedef struct {
2099
  int32_t compactId;
2100
  int32_t vgId;
2101
  int32_t dnodeId;
2102
} SVKillCompactReq;
2103

2104
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2105
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2106

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

2133
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2134
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2135

2136
typedef struct {
2137
  int32_t  vgId;
2138
  int8_t   strict;
2139
  int8_t   selfIndex;
2140
  int8_t   replica;
2141
  SReplica replicas[TSDB_MAX_REPLICA];
2142
  int64_t  reserved[8];
2143
  int8_t   learnerSelfIndex;
2144
  int8_t   learnerReplica;
2145
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2146
  int32_t  changeVersion;
2147
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2148

2149
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2150
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2151

2152
typedef struct {
2153
  int32_t vgId;
2154
  int8_t  disable;
2155
} SDisableVnodeWriteReq;
2156

2157
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2158
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2159

2160
typedef struct {
2161
  int32_t  srcVgId;
2162
  int32_t  dstVgId;
2163
  uint32_t hashBegin;
2164
  uint32_t hashEnd;
2165
  int32_t  changeVersion;
2166
  int32_t  reserved;
2167
} SAlterVnodeHashRangeReq;
2168

2169
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2170
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2171

2172
#define REQ_OPT_TBNAME 0x0
2173
#define REQ_OPT_TBUID  0x01
2174
typedef struct {
2175
  SMsgHead header;
2176
  char     dbFName[TSDB_DB_FNAME_LEN];
2177
  char     tbName[TSDB_TABLE_NAME_LEN];
2178
  uint8_t  option;
2179
  uint8_t  autoCreateCtb;
2180
} STableInfoReq;
2181

2182
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2183
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2184

2185
typedef struct {
2186
  int8_t  metaClone;  // create local clone of the cached table meta
2187
  int32_t numOfVgroups;
2188
  int32_t numOfTables;
2189
  int32_t numOfUdfs;
2190
  char    tableNames[];
2191
} SMultiTableInfoReq;
2192

2193
// todo refactor
2194
typedef struct SVgroupInfo {
2195
  int32_t  vgId;
2196
  uint32_t hashBegin;
2197
  uint32_t hashEnd;
2198
  SEpSet   epSet;
2199
  union {
2200
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2201
    int32_t taskId;      // used in stream
2202
  };
2203
} SVgroupInfo;
2204

2205
typedef struct {
2206
  int32_t     numOfVgroups;
2207
  SVgroupInfo vgroups[];
2208
} SVgroupsInfo;
2209

2210
typedef struct {
2211
  STableMetaRsp* pMeta;
2212
} SMAlterStbRsp;
2213

2214
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2215
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2216
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2217

2218
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2219
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2220
void    tFreeSTableMetaRsp(void* pRsp);
2221
void    tFreeSTableIndexRsp(void* info);
2222

2223
typedef struct {
2224
  SArray* pMetaRsp;   // Array of STableMetaRsp
2225
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2226
} SSTbHbRsp;
2227

2228
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2229
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2230
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2231

2232
typedef struct {
2233
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2234
} SViewHbRsp;
2235

2236
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2237
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2238
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2239

2240
typedef struct {
2241
  int32_t numOfTables;
2242
  int32_t numOfVgroup;
2243
  int32_t numOfUdf;
2244
  int32_t contLen;
2245
  int8_t  compressed;  // denote if compressed or not
2246
  int32_t rawLen;      // size before compress
2247
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2248
  char    meta[];
2249
} SMultiTableMeta;
2250

2251
typedef struct {
2252
  int32_t dataLen;
2253
  char    name[TSDB_TABLE_FNAME_LEN];
2254
  char*   data;
2255
} STagData;
2256

2257
typedef struct {
2258
  int32_t  opType;
2259
  uint32_t valLen;
2260
  char*    val;
2261
} SShowVariablesReq;
2262

2263
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2264
int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2265
void    tFreeSShowVariablesReq(SShowVariablesReq* pReq);
2266

2267
typedef struct {
2268
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2269
  char value[TSDB_CONFIG_PATH_LEN + 1];
2270
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2271
  char category[TSDB_CONFIG_CATEGORY_LEN + 1];
2272
  char info[TSDB_CONFIG_INFO_LEN + 1];
2273
} SVariablesInfo;
2274

2275
typedef struct {
2276
  SArray* variables;  // SArray<SVariablesInfo>
2277
} SShowVariablesRsp;
2278

2279
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2280
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2281

2282
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2283

2284
/*
2285
 * sql: show tables like '%a_%'
2286
 * payload is the query condition, e.g., '%a_%'
2287
 * payloadLen is the length of payload
2288
 */
2289
typedef struct {
2290
  int32_t type;
2291
  char    db[TSDB_DB_FNAME_LEN];
2292
  int32_t payloadLen;
2293
  char*   payload;
2294
} SShowReq;
2295

2296
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2297
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2298
void tFreeSShowReq(SShowReq* pReq);
2299

2300
typedef struct {
2301
  int64_t       showId;
2302
  STableMetaRsp tableMeta;
2303
} SShowRsp, SVShowTablesRsp;
2304

2305
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2306
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2307
// void    tFreeSShowRsp(SShowRsp* pRsp);
2308

2309
typedef struct {
2310
  char    db[TSDB_DB_FNAME_LEN];
2311
  char    tb[TSDB_TABLE_NAME_LEN];
2312
  char    user[TSDB_USER_LEN];
2313
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2314
  int64_t showId;
2315
  int64_t compactId;  // for compact
2316
  bool    withFull;   // for show users full
2317
} SRetrieveTableReq;
2318

2319
typedef struct SSysTableSchema {
2320
  int8_t   type;
2321
  col_id_t colId;
2322
  int32_t  bytes;
2323
} SSysTableSchema;
2324

2325
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2326
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2327

2328
#define RETRIEVE_TABLE_RSP_VERSION          0
2329
#define RETRIEVE_TABLE_RSP_TMQ_VERSION      1
2330
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION  2
2331

2332
typedef struct {
2333
  int64_t useconds;
2334
  int8_t  completed;  // all results are returned to client
2335
  int8_t  precision;
2336
  int8_t  compressed;
2337
  int8_t  streamBlockType;
2338
  int32_t payloadLen;
2339
  int32_t compLen;
2340
  int32_t numOfBlocks;
2341
  int64_t numOfRows;  // from int32_t change to int64_t
2342
  int64_t numOfCols;
2343
  int64_t skey;
2344
  int64_t ekey;
2345
  int64_t version;                         // for stream
2346
  TSKEY   watermark;                       // for stream
2347
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2348
  char    data[];
2349
} SRetrieveTableRsp;
2350

2351
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2352

2353
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2354
  do {                                          \
2355
    ((int32_t*)(_p))[0] = (_compLen);           \
2356
    ((int32_t*)(_p))[1] = (_fullLen);           \
2357
  } while (0);
2358

2359
typedef struct {
2360
  int64_t version;
2361
  int64_t numOfRows;
2362
  int8_t  compressed;
2363
  int8_t  precision;
2364
  char    data[];
2365
} SRetrieveTableRspForTmq;
2366

2367
typedef struct {
2368
  int64_t handle;
2369
  int64_t useconds;
2370
  int8_t  completed;  // all results are returned to client
2371
  int8_t  precision;
2372
  int8_t  compressed;
2373
  int32_t compLen;
2374
  int32_t numOfRows;
2375
  int32_t fullLen;
2376
  char    data[];
2377
} SRetrieveMetaTableRsp;
2378

2379
typedef struct SExplainExecInfo {
2380
  double   startupCost;
2381
  double   totalCost;
2382
  uint64_t numOfRows;
2383
  uint32_t verboseLen;
2384
  void*    verboseInfo;
2385
} SExplainExecInfo;
2386

2387
typedef struct {
2388
  int32_t           numOfPlans;
2389
  SExplainExecInfo* subplanInfo;
2390
} SExplainRsp;
2391

2392
typedef struct {
2393
  SExplainRsp rsp;
2394
  uint64_t    qId;
2395
  uint64_t    cId;
2396
  uint64_t    tId;
2397
  int64_t     rId;
2398
  int32_t     eId;
2399
} SExplainLocalRsp;
2400

2401
typedef struct STableScanAnalyzeInfo {
2402
  uint64_t totalRows;
2403
  uint64_t totalCheckedRows;
2404
  uint32_t totalBlocks;
2405
  uint32_t loadBlocks;
2406
  uint32_t loadBlockStatis;
2407
  uint32_t skipBlocks;
2408
  uint32_t filterOutBlocks;
2409
  double   elapsedTime;
2410
  double   filterTime;
2411
} STableScanAnalyzeInfo;
2412

2413
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2414
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2415
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2416

2417
typedef struct {
2418
  char    config[TSDB_DNODE_CONFIG_LEN];
2419
  char    value[TSDB_CLUSTER_VALUE_LEN];
2420
  int32_t sqlLen;
2421
  char*   sql;
2422
} SMCfgClusterReq;
2423

2424
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2425
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2426
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2427

2428
typedef struct {
2429
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2430
  int32_t port;
2431
  int32_t sqlLen;
2432
  char*   sql;
2433
} SCreateDnodeReq;
2434

2435
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2436
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2437
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2438

2439
typedef struct {
2440
  int32_t dnodeId;
2441
  char    fqdn[TSDB_FQDN_LEN];
2442
  int32_t port;
2443
  int8_t  force;
2444
  int8_t  unsafe;
2445
  int32_t sqlLen;
2446
  char*   sql;
2447
} SDropDnodeReq;
2448

2449
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2450
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2451
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2452

2453
enum {
2454
  RESTORE_TYPE__ALL = 1,
2455
  RESTORE_TYPE__MNODE,
2456
  RESTORE_TYPE__VNODE,
2457
  RESTORE_TYPE__QNODE,
2458
};
2459

2460
typedef struct {
2461
  int32_t dnodeId;
2462
  int8_t  restoreType;
2463
  int32_t sqlLen;
2464
  char*   sql;
2465
} SRestoreDnodeReq;
2466

2467
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2468
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2469
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2470

2471
typedef struct {
2472
  int32_t dnodeId;
2473
  char    config[TSDB_DNODE_CONFIG_LEN];
2474
  char    value[TSDB_DNODE_VALUE_LEN];
2475
  int32_t sqlLen;
2476
  char*   sql;
2477
} SMCfgDnodeReq;
2478

2479
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2480
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2481
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2482

2483
typedef struct {
2484
  char    config[TSDB_DNODE_CONFIG_LEN];
2485
  char    value[TSDB_DNODE_VALUE_LEN];
2486
  int32_t version;
2487
} SDCfgDnodeReq;
2488

2489
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2490
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2491

2492
typedef struct {
2493
  int32_t dnodeId;
2494
  int32_t sqlLen;
2495
  char*   sql;
2496
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2497
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2498

2499
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2500
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2501
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2502
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2503
typedef struct {
2504
  int8_t   replica;
2505
  SReplica replicas[TSDB_MAX_REPLICA];
2506
  int8_t   learnerReplica;
2507
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2508
  int64_t  lastIndex;
2509
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2510

2511
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2512
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2513

2514
typedef struct {
2515
  int32_t urlLen;
2516
  int32_t sqlLen;
2517
  char*   url;
2518
  char*   sql;
2519
} SMCreateAnodeReq;
2520

2521
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2522
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2523
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2524

2525
typedef struct {
2526
  int32_t anodeId;
2527
  int32_t sqlLen;
2528
  char*   sql;
2529
} SMDropAnodeReq, SMUpdateAnodeReq;
2530

2531
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2532
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2533
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2534
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2535
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2536
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2537

2538
typedef struct {
2539
  int32_t vgId;
2540
  int32_t hbSeq;
2541
} SVArbHbReqMember;
2542

2543
typedef struct {
2544
  int32_t dnodeId;
2545
  char*   arbToken;
2546
  int64_t arbTerm;
2547
  SArray* hbMembers;  // SVArbHbReqMember
2548
} SVArbHeartBeatReq;
2549

2550
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2551
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2552
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2553

2554
typedef struct {
2555
  int32_t vgId;
2556
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2557
  int32_t hbSeq;
2558
} SVArbHbRspMember;
2559

2560
typedef struct {
2561
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2562
  int32_t dnodeId;
2563
  SArray* hbMembers;  // SVArbHbRspMember
2564
} SVArbHeartBeatRsp;
2565

2566
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2567
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2568
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2569

2570
typedef struct {
2571
  char*   arbToken;
2572
  int64_t arbTerm;
2573
  char*   member0Token;
2574
  char*   member1Token;
2575
} SVArbCheckSyncReq;
2576

2577
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2578
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2579
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2580

2581
typedef struct {
2582
  char*   arbToken;
2583
  char*   member0Token;
2584
  char*   member1Token;
2585
  int32_t vgId;
2586
  int32_t errCode;
2587
} SVArbCheckSyncRsp;
2588

2589
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2590
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2591
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2592

2593
typedef struct {
2594
  char*   arbToken;
2595
  int64_t arbTerm;
2596
  char*   memberToken;
2597
  int8_t  force;
2598
} SVArbSetAssignedLeaderReq;
2599

2600
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2601
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2602
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2603

2604
typedef struct {
2605
  char*   arbToken;
2606
  char*   memberToken;
2607
  int32_t vgId;
2608
} SVArbSetAssignedLeaderRsp;
2609

2610
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2611
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2612
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2613

2614
typedef struct {
2615
  int32_t dnodeId;
2616
  char*   token;
2617
} SMArbUpdateGroupMember;
2618

2619
typedef struct {
2620
  int32_t dnodeId;
2621
  char*   token;
2622
  int8_t  acked;
2623
} SMArbUpdateGroupAssigned;
2624

2625
typedef struct {
2626
  int32_t                  vgId;
2627
  int64_t                  dbUid;
2628
  SMArbUpdateGroupMember   members[2];
2629
  int8_t                   isSync;
2630
  int8_t                   assignedAcked;
2631
  SMArbUpdateGroupAssigned assignedLeader;
2632
  int64_t                  version;
2633
  int32_t                  code;
2634
  int64_t                  updateTimeMs;
2635
} SMArbUpdateGroup;
2636

2637
typedef struct {
2638
  SArray* updateArray;  // SMArbUpdateGroup
2639
} SMArbUpdateGroupBatchReq;
2640

2641
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2642
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2643
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2644

2645
typedef struct {
2646
  char queryStrId[TSDB_QUERY_ID_LEN];
2647
} SKillQueryReq;
2648

2649
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2650
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2651

2652
typedef struct {
2653
  uint32_t connId;
2654
} SKillConnReq;
2655

2656
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2657
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2658

2659
typedef struct {
2660
  int32_t transId;
2661
} SKillTransReq;
2662

2663
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2664
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2665

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

2672
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2673
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2674
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2675

2676
typedef struct {
2677
  int32_t useless;  // useless
2678
  int32_t sqlLen;
2679
  char*   sql;
2680
} SAssignLeaderReq;
2681

2682
int32_t tSerializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2683
int32_t tDeserializeSAssignLeaderReq(void* buf, int32_t bufLen, SAssignLeaderReq* pReq);
2684
void    tFreeSAssignLeaderReq(SAssignLeaderReq* pReq);
2685
typedef struct {
2686
  int32_t vgId1;
2687
  int32_t vgId2;
2688
} SMergeVgroupReq;
2689

2690
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2691
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2692

2693
typedef struct {
2694
  int32_t vgId;
2695
  int32_t dnodeId1;
2696
  int32_t dnodeId2;
2697
  int32_t dnodeId3;
2698
  int32_t sqlLen;
2699
  char*   sql;
2700
} SRedistributeVgroupReq;
2701

2702
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2703
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2704
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2705

2706
typedef struct {
2707
  int32_t reserved;
2708
  int32_t vgId;
2709
  int32_t sqlLen;
2710
  char*   sql;
2711
  char    db[TSDB_DB_FNAME_LEN];
2712
} SBalanceVgroupLeaderReq;
2713

2714
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2715
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2716
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2717

2718
typedef struct {
2719
  int32_t vgId;
2720
} SForceBecomeFollowerReq;
2721

2722
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2723
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2724

2725
typedef struct {
2726
  int32_t vgId;
2727
} SSplitVgroupReq;
2728

2729
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2730
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2731

2732
typedef struct {
2733
  char user[TSDB_USER_LEN];
2734
  char spi;
2735
  char encrypt;
2736
  char secret[TSDB_PASSWORD_LEN];
2737
  char ckey[TSDB_PASSWORD_LEN];
2738
} SAuthReq, SAuthRsp;
2739

2740
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2741
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2742

2743
typedef struct {
2744
  int32_t statusCode;
2745
  char    details[1024];
2746
} SServerStatusRsp;
2747

2748
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2749
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2750

2751
/**
2752
 * The layout of the query message payload is as following:
2753
 * +--------------------+---------------------------------+
2754
 * |Sql statement       | Physical plan                   |
2755
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2756
 * +--------------------+---------------------------------+
2757
 */
2758
typedef struct SSubQueryMsg {
2759
  SMsgHead header;
2760
  uint64_t sId;
2761
  uint64_t queryId;
2762
  uint64_t clientId;
2763
  uint64_t taskId;
2764
  int64_t  refId;
2765
  int32_t  execId;
2766
  int32_t  msgMask;
2767
  int8_t   taskType;
2768
  int8_t   explain;
2769
  int8_t   needFetch;
2770
  int8_t   compress;
2771
  uint32_t sqlLen;
2772
  char*    sql;
2773
  uint32_t msgLen;
2774
  char*    msg;
2775
} SSubQueryMsg;
2776

2777
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2778
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2779
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2780

2781
typedef struct {
2782
  SMsgHead header;
2783
  uint64_t sId;
2784
  uint64_t queryId;
2785
  uint64_t taskId;
2786
} SSinkDataReq;
2787

2788
typedef struct {
2789
  SMsgHead header;
2790
  uint64_t sId;
2791
  uint64_t queryId;
2792
  uint64_t clientId;
2793
  uint64_t taskId;
2794
  int32_t  execId;
2795
} SQueryContinueReq;
2796

2797
typedef struct {
2798
  SMsgHead header;
2799
  uint64_t sId;
2800
  uint64_t queryId;
2801
  uint64_t taskId;
2802
} SResReadyReq;
2803

2804
typedef struct {
2805
  int32_t code;
2806
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2807
  int32_t sversion;
2808
  int32_t tversion;
2809
} SResReadyRsp;
2810

2811
typedef struct SOperatorParam {
2812
  int32_t opType;
2813
  int32_t downstreamIdx;
2814
  void*   value;
2815
  SArray* pChildren;  // SArray<SOperatorParam*>
2816
} SOperatorParam;
2817

2818
typedef struct STableScanOperatorParam {
2819
  bool    tableSeq;
2820
  SArray* pUidList;
2821
} STableScanOperatorParam;
2822

2823
typedef struct {
2824
  SMsgHead        header;
2825
  uint64_t        sId;
2826
  uint64_t        queryId;
2827
  uint64_t        clientId;
2828
  uint64_t        taskId;
2829
  int32_t         execId;
2830
  SOperatorParam* pOpParam;
2831
} SResFetchReq;
2832

2833
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2834
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2835

2836
typedef struct {
2837
  SMsgHead header;
2838
  uint64_t clientId;
2839
} SSchTasksStatusReq;
2840

2841
typedef struct {
2842
  uint64_t queryId;
2843
  uint64_t clientId;
2844
  uint64_t taskId;
2845
  int64_t  refId;
2846
  int32_t  execId;
2847
  int8_t   status;
2848
} STaskStatus;
2849

2850
typedef struct {
2851
  int64_t refId;
2852
  SArray* taskStatus;  // SArray<STaskStatus>
2853
} SSchedulerStatusRsp;
2854

2855
typedef struct {
2856
  uint64_t queryId;
2857
  uint64_t taskId;
2858
  int8_t   action;
2859
} STaskAction;
2860

2861
typedef struct SQueryNodeEpId {
2862
  int32_t nodeId;  // vgId or qnodeId
2863
  SEp     ep;
2864
} SQueryNodeEpId;
2865

2866
typedef struct {
2867
  SMsgHead       header;
2868
  uint64_t       clientId;
2869
  SQueryNodeEpId epId;
2870
  SArray*        taskAction;  // SArray<STaskAction>
2871
} SSchedulerHbReq;
2872

2873
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2874
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2875
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2876

2877
typedef struct {
2878
  SQueryNodeEpId epId;
2879
  SArray*        taskStatus;  // SArray<STaskStatus>
2880
} SSchedulerHbRsp;
2881

2882
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2883
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2884
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2885

2886
typedef struct {
2887
  SMsgHead header;
2888
  uint64_t sId;
2889
  uint64_t queryId;
2890
  uint64_t clientId;
2891
  uint64_t taskId;
2892
  int64_t  refId;
2893
  int32_t  execId;
2894
} STaskCancelReq;
2895

2896
typedef struct {
2897
  int32_t code;
2898
} STaskCancelRsp;
2899

2900
typedef struct {
2901
  SMsgHead header;
2902
  uint64_t sId;
2903
  uint64_t queryId;
2904
  uint64_t clientId;
2905
  uint64_t taskId;
2906
  int64_t  refId;
2907
  int32_t  execId;
2908
} STaskDropReq;
2909

2910
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2911
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2912

2913
typedef enum {
2914
  TASK_NOTIFY_FINISHED = 1,
2915
} ETaskNotifyType;
2916

2917
typedef struct {
2918
  SMsgHead        header;
2919
  uint64_t        sId;
2920
  uint64_t        queryId;
2921
  uint64_t        clientId;
2922
  uint64_t        taskId;
2923
  int64_t         refId;
2924
  int32_t         execId;
2925
  ETaskNotifyType type;
2926
} STaskNotifyReq;
2927

2928
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2929
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2930

2931
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2932
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2933

2934
typedef struct {
2935
  int32_t code;
2936
} STaskDropRsp;
2937

2938
#define STREAM_TRIGGER_AT_ONCE            1
2939
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2940
#define STREAM_TRIGGER_MAX_DELAY          3
2941
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2942

2943
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2944
#define STREAM_FILL_HISTORY_ON        1
2945
#define STREAM_FILL_HISTORY_OFF       0
2946
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2947
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2948
#define STREAM_CREATE_STABLE_TRUE     1
2949
#define STREAM_CREATE_STABLE_FALSE    0
2950

2951
typedef struct SColLocation {
2952
  int16_t  slotId;
2953
  col_id_t colId;
2954
  int8_t   type;
2955
} SColLocation;
2956

2957
typedef struct SVgroupVer {
2958
  int32_t vgId;
2959
  int64_t ver;
2960
} SVgroupVer;
2961

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

2996
typedef struct STaskNotifyEventStat {
2997
  int64_t notifyEventAddTimes;     // call times of add function
2998
  int64_t notifyEventAddElems;     // elements added by add function
2999
  double  notifyEventAddCostSec;   // time cost of add function
3000
  int64_t notifyEventPushTimes;    // call times of push function
3001
  int64_t notifyEventPushElems;    // elements pushed by push function
3002
  double  notifyEventPushCostSec;  // time cost of push function
3003
  int64_t notifyEventPackTimes;    // call times of pack function
3004
  int64_t notifyEventPackElems;    // elements packed by pack function
3005
  double  notifyEventPackCostSec;  // time cost of pack function
3006
  int64_t notifyEventSendTimes;    // call times of send function
3007
  int64_t notifyEventSendElems;    // elements sent by send function
3008
  double  notifyEventSendCostSec;  // time cost of send function
3009
  int64_t notifyEventHoldElems;    // elements hold due to watermark
3010
} STaskNotifyEventStat;
3011

3012
typedef struct {
3013
  int64_t streamId;
3014
} SCMCreateStreamRsp;
3015

3016
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3017
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3018
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3019

3020
enum {
3021
  TOPIC_SUB_TYPE__DB = 1,
3022
  TOPIC_SUB_TYPE__TABLE,
3023
  TOPIC_SUB_TYPE__COLUMN,
3024
};
3025

3026
#define DEFAULT_MAX_POLL_INTERVAL  300000
3027
#define DEFAULT_SESSION_TIMEOUT    12000
3028
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3029
#define DEFAULT_MIN_POLL_ROWS      4096
3030

3031
typedef struct {
3032
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3033
  int8_t igExists;
3034
  int8_t subType;
3035
  int8_t withMeta;
3036
  char*  sql;
3037
  char   subDbName[TSDB_DB_FNAME_LEN];
3038
  char*  ast;
3039
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3040
} SCMCreateTopicReq;
3041

3042
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3043
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3044
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3045

3046
typedef struct {
3047
  int64_t consumerId;
3048
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3049

3050
typedef struct {
3051
  int64_t consumerId;
3052
  char    cgroup[TSDB_CGROUP_LEN];
3053
  char    clientId[TSDB_CLIENT_ID_LEN];
3054
  char    user[TSDB_USER_LEN];
3055
  char    fqdn[TSDB_FQDN_LEN];
3056
  SArray* topicNames;  // SArray<char**>
3057

3058
  int8_t  withTbName;
3059
  int8_t  autoCommit;
3060
  int32_t autoCommitInterval;
3061
  int8_t  resetOffsetCfg;
3062
  int8_t  enableReplay;
3063
  int8_t  enableBatchMeta;
3064
  int32_t sessionTimeoutMs;
3065
  int32_t maxPollIntervalMs;
3066
} SCMSubscribeReq;
3067

3068
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3069
  int32_t tlen = 0;
×
3070
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
×
3071
  tlen += taosEncodeString(buf, pReq->cgroup);
×
3072
  tlen += taosEncodeString(buf, pReq->clientId);
×
3073

3074
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
×
3075
  tlen += taosEncodeFixedI32(buf, topicNum);
×
3076

3077
  for (int32_t i = 0; i < topicNum; i++) {
×
3078
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
×
3079
  }
3080

3081
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
×
3082
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
×
3083
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
×
3084
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
×
3085
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
×
3086
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
×
3087
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
×
3088
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
×
3089
  tlen += taosEncodeString(buf, pReq->user);
×
3090
  tlen += taosEncodeString(buf, pReq->fqdn);
×
3091

3092
  return tlen;
×
3093
}
3094

3095
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3096
  void* start = buf;
×
3097
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
×
3098
  buf = taosDecodeStringTo(buf, pReq->cgroup);
×
3099
  buf = taosDecodeStringTo(buf, pReq->clientId);
×
3100

3101
  int32_t topicNum = 0;
×
3102
  buf = taosDecodeFixedI32(buf, &topicNum);
×
3103

3104
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
×
3105
  if (pReq->topicNames == NULL) {
×
3106
    return terrno;
×
3107
  }
3108
  for (int32_t i = 0; i < topicNum; i++) {
×
3109
    char* name = NULL;
×
3110
    buf = taosDecodeString(buf, &name);
×
3111
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
×
3112
      return terrno;
×
3113
    }
3114
  }
3115

3116
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
×
3117
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
×
3118
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
×
3119
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
×
3120
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
×
3121
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
×
3122
  if ((char*)buf - (char*)start < len) {
×
3123
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
×
3124
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
×
3125
    buf = taosDecodeStringTo(buf, pReq->user);
×
3126
    buf = taosDecodeStringTo(buf, pReq->fqdn);
×
3127
  } else {
3128
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3129
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3130
  }
3131

3132
  return 0;
×
3133
}
3134

3135
typedef struct {
3136
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3137
  SArray* removedConsumers;  // SArray<int64_t>
3138
  SArray* newConsumers;      // SArray<int64_t>
3139
} SMqRebInfo;
3140

3141
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3142
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
×
3143
  if (pRebInfo == NULL) {
×
3144
    return NULL;
×
3145
  }
3146
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
×
3147
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
×
3148
  if (pRebInfo->removedConsumers == NULL) {
×
3149
    goto _err;
×
3150
  }
3151
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
×
3152
  if (pRebInfo->newConsumers == NULL) {
×
3153
    goto _err;
×
3154
  }
3155
  return pRebInfo;
×
3156
_err:
×
3157
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3158
  taosArrayDestroy(pRebInfo->newConsumers);
×
3159
  taosMemoryFreeClear(pRebInfo);
×
3160
  return NULL;
×
3161
}
3162

3163
typedef struct {
3164
  int64_t streamId;
3165
  int64_t checkpointId;
3166
  char    streamName[TSDB_STREAM_FNAME_LEN];
3167
} SMStreamDoCheckpointMsg;
3168

3169
typedef struct {
3170
  int64_t status;
3171
} SMVSubscribeRsp;
3172

3173
typedef struct {
3174
  char    name[TSDB_TOPIC_FNAME_LEN];
3175
  int8_t  igNotExists;
3176
  int32_t sqlLen;
3177
  char*   sql;
3178
} SMDropTopicReq;
3179

3180
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3181
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3182
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3183

3184
typedef struct {
3185
  char   topic[TSDB_TOPIC_FNAME_LEN];
3186
  char   cgroup[TSDB_CGROUP_LEN];
3187
  int8_t igNotExists;
3188
} SMDropCgroupReq;
3189

3190
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3191
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3192

3193
typedef struct {
3194
  int8_t reserved;
3195
} SMDropCgroupRsp;
3196

3197
typedef struct {
3198
  char    name[TSDB_TABLE_FNAME_LEN];
3199
  int8_t  alterType;
3200
  SSchema schema;
3201
} SAlterTopicReq;
3202

3203
typedef struct {
3204
  SMsgHead head;
3205
  char     name[TSDB_TABLE_FNAME_LEN];
3206
  int64_t  tuid;
3207
  int32_t  sverson;
3208
  int32_t  execLen;
3209
  char*    executor;
3210
  int32_t  sqlLen;
3211
  char*    sql;
3212
} SDCreateTopicReq;
3213

3214
typedef struct {
3215
  SMsgHead head;
3216
  char     name[TSDB_TABLE_FNAME_LEN];
3217
  int64_t  tuid;
3218
} SDDropTopicReq;
3219

3220
typedef struct {
3221
  int64_t maxdelay[2];
3222
  int64_t watermark[2];
3223
  int64_t deleteMark[2];
3224
  int32_t qmsgLen[2];
3225
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3226
} SRSmaParam;
3227

3228
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3229
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3230

3231
// TDMT_VND_CREATE_STB ==============
3232
typedef struct SVCreateStbReq {
3233
  char*           name;
3234
  tb_uid_t        suid;
3235
  int8_t          rollup;
3236
  SSchemaWrapper  schemaRow;
3237
  SSchemaWrapper  schemaTag;
3238
  SRSmaParam      rsmaParam;
3239
  int32_t         alterOriDataLen;
3240
  void*           alterOriData;
3241
  int8_t          source;
3242
  int8_t          colCmpred;
3243
  SColCmprWrapper colCmpr;
3244
} SVCreateStbReq;
3245

3246
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3247
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3248

3249
// TDMT_VND_DROP_STB ==============
3250
typedef struct SVDropStbReq {
3251
  char*    name;
3252
  tb_uid_t suid;
3253
} SVDropStbReq;
3254

3255
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3256
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3257

3258
// TDMT_VND_CREATE_TABLE ==============
3259
#define TD_CREATE_IF_NOT_EXISTS 0x1
3260
typedef struct SVCreateTbReq {
3261
  int32_t  flags;
3262
  char*    name;
3263
  tb_uid_t uid;
3264
  int64_t  btime;
3265
  int32_t  ttl;
3266
  int32_t  commentLen;
3267
  char*    comment;
3268
  int8_t   type;
3269
  union {
3270
    struct {
3271
      char*    stbName;  // super table name
3272
      uint8_t  tagNum;
3273
      tb_uid_t suid;
3274
      SArray*  tagName;
3275
      uint8_t* pTag;
3276
    } ctb;
3277
    struct {
3278
      SSchemaWrapper schemaRow;
3279
    } ntb;
3280
  };
3281
  int32_t         sqlLen;
3282
  char*           sql;
3283
  SColCmprWrapper colCmpr;
3284
} SVCreateTbReq;
3285

3286
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3287
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3288
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3289

3290
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
×
3291
  if (NULL == req) {
×
3292
    return;
×
3293
  }
3294

3295
  taosMemoryFreeClear(req->sql);
×
3296
  taosMemoryFreeClear(req->name);
×
3297
  taosMemoryFreeClear(req->comment);
×
3298
  if (req->type == TSDB_CHILD_TABLE) {
×
3299
    taosMemoryFreeClear(req->ctb.pTag);
×
3300
    taosMemoryFreeClear(req->ctb.stbName);
×
3301
    taosArrayDestroy(req->ctb.tagName);
×
3302
    req->ctb.tagName = NULL;
×
3303
  } else if (req->type == TSDB_NORMAL_TABLE) {
×
3304
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
×
3305
  }
3306
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
×
3307
}
3308

3309
typedef struct {
3310
  int32_t nReqs;
3311
  union {
3312
    SVCreateTbReq* pReqs;
3313
    SArray*        pArray;
3314
  };
3315
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3316
} SVCreateTbBatchReq;
3317

3318
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3319
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3320
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3321

3322
typedef struct {
3323
  int32_t        code;
3324
  STableMetaRsp* pMeta;
3325
} SVCreateTbRsp, SVUpdateTbRsp;
3326

3327
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3328
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3329
void tFreeSVCreateTbRsp(void* param);
3330

3331
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3332
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3333

3334
typedef struct {
3335
  int32_t nRsps;
3336
  union {
3337
    SVCreateTbRsp* pRsps;
3338
    SArray*        pArray;
3339
  };
3340
} SVCreateTbBatchRsp;
3341

3342
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3343
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3344

3345
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3346
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3347

3348
// TDMT_VND_DROP_TABLE =================
3349
typedef struct {
3350
  char*    name;
3351
  uint64_t suid;  // for tmq in wal format
3352
  int64_t  uid;
3353
  int8_t   igNotExists;
3354
} SVDropTbReq;
3355

3356
typedef struct {
3357
  int32_t code;
3358
} SVDropTbRsp;
3359

3360
typedef struct {
3361
  int32_t nReqs;
3362
  union {
3363
    SVDropTbReq* pReqs;
3364
    SArray*      pArray;
3365
  };
3366
} SVDropTbBatchReq;
3367

3368
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3369
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3370

3371
typedef struct {
3372
  int32_t nRsps;
3373
  union {
3374
    SVDropTbRsp* pRsps;
3375
    SArray*      pArray;
3376
  };
3377
} SVDropTbBatchRsp;
3378

3379
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3380
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3381

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

3425
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3426
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3427
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3428
void    tfreeMultiTagUpateVal(void* pMultiTag);
3429

3430
typedef struct {
3431
  int32_t        code;
3432
  STableMetaRsp* pMeta;
3433
} SVAlterTbRsp;
3434

3435
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3436
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3437
// ======================
3438

3439
typedef struct {
3440
  SMsgHead head;
3441
  int64_t  uid;
3442
  int32_t  tid;
3443
  int16_t  tversion;
3444
  int16_t  colId;
3445
  int8_t   type;
3446
  int16_t  bytes;
3447
  int32_t  tagValLen;
3448
  int16_t  numOfTags;
3449
  int32_t  schemaLen;
3450
  char     data[];
3451
} SUpdateTagValReq;
3452

3453
typedef struct {
3454
  SMsgHead head;
3455
} SUpdateTagValRsp;
3456

3457
typedef struct {
3458
  SMsgHead head;
3459
} SVShowTablesReq;
3460

3461
typedef struct {
3462
  SMsgHead head;
3463
  int32_t  id;
3464
} SVShowTablesFetchReq;
3465

3466
typedef struct {
3467
  int64_t useconds;
3468
  int8_t  completed;  // all results are returned to client
3469
  int8_t  precision;
3470
  int8_t  compressed;
3471
  int32_t compLen;
3472
  int32_t numOfRows;
3473
  char    data[];
3474
} SVShowTablesFetchRsp;
3475

3476
typedef struct {
3477
  int64_t consumerId;
3478
  int32_t epoch;
3479
  char    cgroup[TSDB_CGROUP_LEN];
3480
} SMqAskEpReq;
3481

3482
typedef struct {
3483
  int32_t key;
3484
  int32_t valueLen;
3485
  void*   value;
3486
} SKv;
3487

3488
typedef struct {
3489
  int64_t tscRid;
3490
  int8_t  connType;
3491
} SClientHbKey;
3492

3493
typedef struct {
3494
  int64_t tid;
3495
  char    status[TSDB_JOB_STATUS_LEN];
3496
} SQuerySubDesc;
3497

3498
typedef struct {
3499
  char     sql[TSDB_SHOW_SQL_LEN];
3500
  uint64_t queryId;
3501
  int64_t  useconds;
3502
  int64_t  stime;  // timestamp precision ms
3503
  int64_t  reqRid;
3504
  bool     stableQuery;
3505
  bool     isSubQuery;
3506
  char     fqdn[TSDB_FQDN_LEN];
3507
  int32_t  subPlanNum;
3508
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3509
} SQueryDesc;
3510

3511
typedef struct {
3512
  uint32_t connId;
3513
  SArray*  queryDesc;  // SArray<SQueryDesc>
3514
} SQueryHbReqBasic;
3515

3516
typedef struct {
3517
  uint32_t connId;
3518
  uint64_t killRid;
3519
  int32_t  totalDnodes;
3520
  int32_t  onlineDnodes;
3521
  int8_t   killConnection;
3522
  int8_t   align[3];
3523
  SEpSet   epSet;
3524
  SArray*  pQnodeList;
3525
} SQueryHbRspBasic;
3526

3527
typedef struct SAppClusterSummary {
3528
  uint64_t numOfInsertsReq;
3529
  uint64_t numOfInsertRows;
3530
  uint64_t insertElapsedTime;
3531
  uint64_t insertBytes;  // submit to tsdb since launched.
3532

3533
  uint64_t fetchBytes;
3534
  uint64_t numOfQueryReq;
3535
  uint64_t queryElapsedTime;
3536
  uint64_t numOfSlowQueries;
3537
  uint64_t totalRequests;
3538
  uint64_t currentRequests;  // the number of SRequestObj
3539
} SAppClusterSummary;
3540

3541
typedef struct {
3542
  int64_t            appId;
3543
  int32_t            pid;
3544
  char               name[TSDB_APP_NAME_LEN];
3545
  int64_t            startTime;
3546
  SAppClusterSummary summary;
3547
} SAppHbReq;
3548

3549
typedef struct {
3550
  SClientHbKey      connKey;
3551
  int64_t           clusterId;
3552
  SAppHbReq         app;
3553
  SQueryHbReqBasic* query;
3554
  SHashObj*         info;  // hash<Skv.key, Skv>
3555
  char              userApp[TSDB_APP_NAME_LEN];
3556
  uint32_t          userIp;
3557
} SClientHbReq;
3558

3559
typedef struct {
3560
  int64_t reqId;
3561
  SArray* reqs;  // SArray<SClientHbReq>
3562
  int64_t ipWhiteList;
3563
} SClientHbBatchReq;
3564

3565
typedef struct {
3566
  SClientHbKey      connKey;
3567
  int32_t           status;
3568
  SQueryHbRspBasic* query;
3569
  SArray*           info;  // Array<Skv>
3570
} SClientHbRsp;
3571

3572
typedef struct {
3573
  int64_t       reqId;
3574
  int64_t       rspId;
3575
  int32_t       svrTimestamp;
3576
  SArray*       rsps;  // SArray<SClientHbRsp>
3577
  SMonitorParas monitorParas;
3578
  int8_t        enableAuditDelete;
3579
  int8_t        enableStrongPass;
3580
} SClientHbBatchRsp;
3581

3582
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
×
3583

3584
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3585
  void* pIter = taosHashIterate(info, NULL);
×
3586
  while (pIter != NULL) {
×
3587
    SKv* kv = (SKv*)pIter;
×
3588
    taosMemoryFreeClear(kv->value);
×
3589
    pIter = taosHashIterate(info, pIter);
×
3590
  }
3591
}
×
3592

3593
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
×
3594
  SQueryDesc* desc = (SQueryDesc*)pDesc;
×
3595
  if (desc->subDesc) {
×
3596
    taosArrayDestroy(desc->subDesc);
×
3597
    desc->subDesc = NULL;
×
3598
  }
3599
}
×
3600

3601
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
×
3602
  SClientHbReq* req = (SClientHbReq*)pReq;
×
3603
  if (req->query) {
×
3604
    if (req->query->queryDesc) {
×
3605
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
×
3606
    }
3607
    taosMemoryFreeClear(req->query);
×
3608
  }
3609

3610
  if (req->info) {
×
3611
    tFreeReqKvHash(req->info);
×
3612
    taosHashCleanup(req->info);
×
3613
    req->info = NULL;
×
3614
  }
3615
}
×
3616

3617
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3618
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3619

3620
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3621
  if (pReq == NULL) return;
×
3622
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
×
3623
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
×
3624
  taosMemoryFree(pReq);
×
3625
}
3626

3627
static FORCE_INLINE void tFreeClientKv(void* pKv) {
×
3628
  SKv* kv = (SKv*)pKv;
×
3629
  if (kv) {
×
3630
    taosMemoryFreeClear(kv->value);
×
3631
  }
3632
}
×
3633

3634
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
×
3635
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
×
3636
  if (rsp->query) {
×
3637
    taosArrayDestroy(rsp->query->pQnodeList);
×
3638
    taosMemoryFreeClear(rsp->query);
×
3639
  }
3640
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
×
3641
}
×
3642

3643
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3644
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
×
3645
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
×
3646
}
×
3647

3648
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3649
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3650
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3651

3652
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3653
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
×
3654
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
×
3655
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
×
3656
  return 0;
×
3657
}
3658

3659
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3660
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
×
3661
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
×
3662
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
×
3663
  if (pKv->value == NULL) {
×
3664
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3665
  }
3666
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
×
3667
  return 0;
×
3668
}
3669

3670
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3671
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
×
3672
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
×
3673
  return 0;
×
3674
}
3675

3676
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3677
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
×
3678
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
×
3679
  return 0;
×
3680
}
3681

3682
typedef struct {
3683
  int32_t vgId;
3684
  // TODO stas
3685
} SMqReportVgInfo;
3686

3687
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3688
  int32_t tlen = 0;
3689
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3690
  return tlen;
3691
}
3692

3693
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3694
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3695
  return buf;
3696
}
3697

3698
typedef struct {
3699
  int32_t epoch;
3700
  int64_t topicUid;
3701
  char    name[TSDB_TOPIC_FNAME_LEN];
3702
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3703
} SMqTopicInfo;
3704

3705
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3706
  int32_t tlen = 0;
3707
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3708
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3709
  tlen += taosEncodeString(buf, pTopicInfo->name);
3710
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3711
  tlen += taosEncodeFixedI32(buf, sz);
3712
  for (int32_t i = 0; i < sz; i++) {
3713
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3714
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3715
  }
3716
  return tlen;
3717
}
3718

3719
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3720
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3721
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3722
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3723
  int32_t sz;
3724
  buf = taosDecodeFixedI32(buf, &sz);
3725
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3726
    return NULL;
3727
  }
3728
  for (int32_t i = 0; i < sz; i++) {
3729
    SMqReportVgInfo vgInfo;
3730
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3731
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3732
      return NULL;
3733
    }
3734
  }
3735
  return buf;
3736
}
3737

3738
typedef struct {
3739
  int32_t status;  // ask hb endpoint
3740
  int32_t epoch;
3741
  int64_t consumerId;
3742
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3743
} SMqReportReq;
3744

3745
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3746
  int32_t tlen = 0;
3747
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3748
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3749
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3750
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3751
  tlen += taosEncodeFixedI32(buf, sz);
3752
  for (int32_t i = 0; i < sz; i++) {
3753
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3754
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3755
  }
3756
  return tlen;
3757
}
3758

3759
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3760
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3761
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3762
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3763
  int32_t sz;
3764
  buf = taosDecodeFixedI32(buf, &sz);
3765
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3766
    return NULL;
3767
  }
3768
  for (int32_t i = 0; i < sz; i++) {
3769
    SMqTopicInfo topicInfo;
3770
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3771
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3772
      return NULL;
3773
    }
3774
  }
3775
  return buf;
3776
}
3777

3778
typedef struct {
3779
  SMsgHead head;
3780
  int64_t  leftForVer;
3781
  int32_t  vgId;
3782
  int64_t  consumerId;
3783
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3784
} SMqVDeleteReq;
3785

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

3790
typedef struct {
3791
  char    name[TSDB_STREAM_FNAME_LEN];
3792
  int8_t  igNotExists;
3793
  int32_t sqlLen;
3794
  char*   sql;
3795
} SMDropStreamReq;
3796

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

3801
typedef struct {
3802
  SMsgHead head;
3803
  int64_t  resetRelHalt;  // reset related stream task halt status
3804
  int64_t  streamId;
3805
  int32_t  taskId;
3806
} SVDropStreamTaskReq;
3807

3808
typedef struct {
3809
  int8_t reserved;
3810
} SVDropStreamTaskRsp;
3811

3812
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3813
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3814
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3815

3816
typedef struct SVUpdateCheckpointInfoReq {
3817
  SMsgHead head;
3818
  int64_t  streamId;
3819
  int32_t  taskId;
3820
  int64_t  checkpointId;
3821
  int64_t  checkpointVer;
3822
  int64_t  checkpointTs;
3823
  int32_t  transId;
3824
  int64_t  hStreamId;  // add encode/decode
3825
  int64_t  hTaskId;
3826
  int8_t   dropRelHTask;
3827
} SVUpdateCheckpointInfoReq;
3828

3829
typedef struct {
3830
  int64_t leftForVer;
3831
  int32_t vgId;
3832
  int64_t oldConsumerId;
3833
  int64_t newConsumerId;
3834
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3835
  int8_t  subType;
3836
  int8_t  withMeta;
3837
  char*   qmsg;  // SubPlanToString
3838
  int64_t suid;
3839
} SMqRebVgReq;
3840

3841
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3842
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3843

3844
typedef struct {
3845
  char    topic[TSDB_TOPIC_FNAME_LEN];
3846
  int64_t ntbUid;
3847
  SArray* colIdList;  // SArray<int16_t>
3848
} STqCheckInfo;
3849

3850
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3851
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3852
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3853

3854
// tqOffset
3855
enum {
3856
  TMQ_OFFSET__RESET_NONE = -3,
3857
  TMQ_OFFSET__RESET_EARLIEST = -2,
3858
  TMQ_OFFSET__RESET_LATEST = -1,
3859
  TMQ_OFFSET__LOG = 1,
3860
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3861
  TMQ_OFFSET__SNAPSHOT_META = 3,
3862
};
3863

3864
enum {
3865
  WITH_DATA = 0,
3866
  WITH_META = 1,
3867
  ONLY_META = 2,
3868
};
3869

3870
#define TQ_OFFSET_VERSION 1
3871

3872
typedef struct {
3873
  int8_t type;
3874
  union {
3875
    // snapshot
3876
    struct {
3877
      int64_t uid;
3878
      int64_t ts;
3879
      SValue  primaryKey;
3880
    };
3881
    // log
3882
    struct {
3883
      int64_t version;
3884
    };
3885
  };
3886
} STqOffsetVal;
3887

3888
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3889
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
×
3890
  pOffsetVal->uid = uid;
×
3891
  pOffsetVal->ts = ts;
×
3892
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
×
3893
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3894
  }
3895
  pOffsetVal->primaryKey = primaryKey;
×
3896
}
×
3897

3898
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3899
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
×
3900
  pOffsetVal->uid = uid;
×
3901
}
×
3902

3903
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3904
  pOffsetVal->type = TMQ_OFFSET__LOG;
×
3905
  pOffsetVal->version = ver;
×
3906
}
×
3907

3908
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3909
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3910
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3911
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3912
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3913
void    tOffsetDestroy(void* pVal);
3914

3915
typedef struct {
3916
  STqOffsetVal val;
3917
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3918
} STqOffset;
3919

3920
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3921
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3922
void    tDeleteSTqOffset(void* val);
3923

3924
typedef struct SMqVgOffset {
3925
  int64_t   consumerId;
3926
  STqOffset offset;
3927
} SMqVgOffset;
3928

3929
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3930
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3931

3932
typedef struct {
3933
  SMsgHead head;
3934
  int64_t  streamId;
3935
  int32_t  taskId;
3936
} SVPauseStreamTaskReq;
3937

3938
typedef struct {
3939
  SMsgHead head;
3940
  int64_t  streamId;
3941
  int32_t  taskId;
3942
  int64_t  chkptId;
3943
} SVResetStreamTaskReq;
3944

3945
typedef struct {
3946
  char   name[TSDB_STREAM_FNAME_LEN];
3947
  int8_t igNotExists;
3948
} SMPauseStreamReq;
3949

3950
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3951
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3952

3953
typedef struct {
3954
  SMsgHead head;
3955
  int32_t  taskId;
3956
  int64_t  streamId;
3957
  int8_t   igUntreated;
3958
} SVResumeStreamTaskReq;
3959

3960
typedef struct {
3961
  int8_t reserved;
3962
} SVResumeStreamTaskRsp;
3963

3964
typedef struct {
3965
  char   name[TSDB_STREAM_FNAME_LEN];
3966
  int8_t igNotExists;
3967
  int8_t igUntreated;
3968
} SMResumeStreamReq;
3969

3970
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3971
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3972

3973
typedef struct {
3974
  char   name[TSDB_STREAM_FNAME_LEN];
3975
  int8_t igNotExists;
3976
  int8_t igUntreated;
3977
} SMResetStreamReq;
3978

3979
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
3980
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
3981

3982
typedef struct {
3983
  char    name[TSDB_TABLE_FNAME_LEN];
3984
  char    stb[TSDB_TABLE_FNAME_LEN];
3985
  int8_t  igExists;
3986
  int8_t  intervalUnit;
3987
  int8_t  slidingUnit;
3988
  int8_t  timezone;  // int8_t is not enough, timezone is unit of second
3989
  int32_t dstVgId;   // for stream
3990
  int64_t interval;
3991
  int64_t offset;
3992
  int64_t sliding;
3993
  int64_t maxDelay;
3994
  int64_t watermark;
3995
  int32_t exprLen;        // strlen + 1
3996
  int32_t tagsFilterLen;  // strlen + 1
3997
  int32_t sqlLen;         // strlen + 1
3998
  int32_t astLen;         // strlen + 1
3999
  char*   expr;
4000
  char*   tagsFilter;
4001
  char*   sql;
4002
  char*   ast;
4003
  int64_t deleteMark;
4004
  int64_t lastTs;
4005
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
4006
  SArray* pVgroupVerList;
4007
  int8_t  recursiveTsma;
4008
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
4009
} SMCreateSmaReq;
4010

4011
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4012
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4013
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4014

4015
typedef struct {
4016
  char   name[TSDB_TABLE_FNAME_LEN];
4017
  int8_t igNotExists;
4018
} SMDropSmaReq;
4019

4020
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4021
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4022

4023
typedef struct {
4024
  char   dbFName[TSDB_DB_FNAME_LEN];
4025
  char   stbName[TSDB_TABLE_NAME_LEN];
4026
  char   colName[TSDB_COL_NAME_LEN];
4027
  char   idxName[TSDB_INDEX_FNAME_LEN];
4028
  int8_t idxType;
4029
} SCreateTagIndexReq;
4030

4031
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4032
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4033

4034
typedef SMDropSmaReq SDropTagIndexReq;
4035

4036
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4037
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4038

4039
typedef struct {
4040
  int8_t         version;       // for compatibility(default 0)
4041
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4042
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4043
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4044
  int32_t        dstVgId;
4045
  char           indexName[TSDB_INDEX_NAME_LEN];
4046
  int32_t        exprLen;
4047
  int32_t        tagsFilterLen;
4048
  int64_t        indexUid;
4049
  tb_uid_t       tableUid;  // super/child/common table uid
4050
  tb_uid_t       dstTbUid;  // for dstVgroup
4051
  int64_t        interval;
4052
  int64_t        offset;  // use unit by precision of DB
4053
  int64_t        sliding;
4054
  char*          dstTbName;  // for dstVgroup
4055
  char*          expr;       // sma expression
4056
  char*          tagsFilter;
4057
  SSchemaWrapper schemaRow;  // for dstVgroup
4058
  SSchemaWrapper schemaTag;  // for dstVgroup
4059
} STSma;                     // Time-range-wise SMA
4060

4061
typedef STSma SVCreateTSmaReq;
4062

4063
typedef struct {
4064
  int8_t  type;  // 0 status report, 1 update data
4065
  int64_t indexUid;
4066
  int64_t skey;  // start TS key of interval/sliding window
4067
} STSmaMsg;
4068

4069
typedef struct {
4070
  int64_t indexUid;
4071
  char    indexName[TSDB_INDEX_NAME_LEN];
4072
} SVDropTSmaReq;
4073

4074
typedef struct {
4075
  int tmp;  // TODO: to avoid compile error
4076
} SVCreateTSmaRsp, SVDropTSmaRsp;
4077

4078
#if 0
4079
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4080
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4081
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4082
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4083
#endif
4084

4085
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4086
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4087
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4088
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4089

4090
typedef struct {
4091
  int32_t number;
4092
  STSma*  tSma;
4093
} STSmaWrapper;
4094

4095
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4096
  if (pSma) {
×
4097
    taosMemoryFreeClear(pSma->dstTbName);
×
4098
    taosMemoryFreeClear(pSma->expr);
×
4099
    taosMemoryFreeClear(pSma->tagsFilter);
×
4100
  }
4101
}
×
4102

4103
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4104
  if (pSW) {
×
4105
    if (pSW->tSma) {
×
4106
      if (deepCopy) {
×
4107
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4108
          tDestroyTSma(pSW->tSma + i);
×
4109
        }
4110
      }
4111
      taosMemoryFreeClear(pSW->tSma);
×
4112
    }
4113
  }
4114
}
×
4115

4116
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4117
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4118
  taosMemoryFreeClear(pSW);
×
4119
  return NULL;
×
4120
}
4121

4122
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4123
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4124

4125
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4126
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4127

4128
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4129
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4130
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4131
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4132
  }
4133
  return 0;
×
4134
}
4135

4136
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4137
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4138
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4139
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4140
  }
4141
  return 0;
×
4142
}
4143

4144
typedef struct {
4145
  int idx;
4146
} SMCreateFullTextReq;
4147

4148
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4149
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4150
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4151

4152
typedef struct {
4153
  char   name[TSDB_TABLE_FNAME_LEN];
4154
  int8_t igNotExists;
4155
} SMDropFullTextReq;
4156

4157
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4158
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4159

4160
typedef struct {
4161
  char indexFName[TSDB_INDEX_FNAME_LEN];
4162
} SUserIndexReq;
4163

4164
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4165
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4166

4167
typedef struct {
4168
  char dbFName[TSDB_DB_FNAME_LEN];
4169
  char tblFName[TSDB_TABLE_FNAME_LEN];
4170
  char colName[TSDB_COL_NAME_LEN];
4171
  char indexType[TSDB_INDEX_TYPE_LEN];
4172
  char indexExts[TSDB_INDEX_EXTS_LEN];
4173
} SUserIndexRsp;
4174

4175
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4176
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4177

4178
typedef struct {
4179
  char tbFName[TSDB_TABLE_FNAME_LEN];
4180
} STableIndexReq;
4181

4182
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4183
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4184

4185
typedef struct {
4186
  int8_t  intervalUnit;
4187
  int8_t  slidingUnit;
4188
  int64_t interval;
4189
  int64_t offset;
4190
  int64_t sliding;
4191
  int64_t dstTbUid;
4192
  int32_t dstVgId;
4193
  SEpSet  epSet;
4194
  char*   expr;
4195
} STableIndexInfo;
4196

4197
typedef struct {
4198
  char     tbName[TSDB_TABLE_NAME_LEN];
4199
  char     dbFName[TSDB_DB_FNAME_LEN];
4200
  uint64_t suid;
4201
  int32_t  version;
4202
  int32_t  indexSize;
4203
  SArray*  pIndex;  // STableIndexInfo
4204
} STableIndexRsp;
4205

4206
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4207
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4208
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4209

4210
void tFreeSTableIndexInfo(void* pInfo);
4211

4212
typedef struct {
4213
  int8_t  mqMsgType;
4214
  int32_t code;
4215
  int32_t epoch;
4216
  int64_t consumerId;
4217
  int64_t walsver;
4218
  int64_t walever;
4219
} SMqRspHead;
4220

4221
typedef struct {
4222
  SMsgHead     head;
4223
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4224
  int8_t       withTbName;
4225
  int8_t       useSnapshot;
4226
  int32_t      epoch;
4227
  uint64_t     reqId;
4228
  int64_t      consumerId;
4229
  int64_t      timeout;
4230
  STqOffsetVal reqOffset;
4231
  int8_t       enableReplay;
4232
  int8_t       sourceExcluded;
4233
  int8_t       rawData;
4234
  int32_t      minPollRows;
4235
  int8_t       enableBatchMeta;
4236
  SHashObj    *uidHash;  // to find if uid is duplicated
4237
} SMqPollReq;
4238

4239
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4240
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4241
void    tDestroySMqPollReq(SMqPollReq* pReq);
4242

4243
typedef struct {
4244
  int32_t vgId;
4245
  int64_t offset;
4246
  SEpSet  epSet;
4247
} SMqSubVgEp;
4248

4249
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4250
  int32_t tlen = 0;
×
4251
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
×
4252
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
×
4253
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
×
4254
  return tlen;
×
4255
}
4256

4257
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4258
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
×
4259
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
×
4260
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
×
4261
  return buf;
×
4262
}
4263

4264
typedef struct {
4265
  char           topic[TSDB_TOPIC_FNAME_LEN];
4266
  char           db[TSDB_DB_FNAME_LEN];
4267
  SArray*        vgs;  // SArray<SMqSubVgEp>
4268
  SSchemaWrapper schema;
4269
} SMqSubTopicEp;
4270

4271
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4272
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4273
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4274

4275
typedef struct {
4276
  SMqRspHead   head;
4277
  STqOffsetVal rspOffset;
4278
  int16_t      resMsgType;
4279
  int32_t      metaRspLen;
4280
  void*        metaRsp;
4281
} SMqMetaRsp;
4282

4283
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4284
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4285
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4286

4287
#define MQ_DATA_RSP_VERSION 100
4288

4289
typedef struct {
4290
  SMqRspHead   head;
4291
  STqOffsetVal rspOffset;
4292
  STqOffsetVal reqOffset;
4293
  int32_t      blockNum;
4294
  int8_t       withTbName;
4295
  int8_t       withSchema;
4296
  SArray*      blockDataLen;
4297
  SArray*      blockData;
4298
  SArray*      blockTbName;
4299
  SArray*      blockSchema;
4300

4301
  union {
4302
    struct {
4303
      int64_t sleepTime;
4304
    };
4305
    struct {
4306
      int32_t createTableNum;
4307
      SArray* createTableLen;
4308
      SArray* createTableReq;
4309
    };
4310
    struct{
4311
      int32_t len;
4312
      void*   rawData;
4313
    };
4314
  };
4315
  void*   data;  //for free in client, only effected if type is data or metadata. raw data not effected
4316
  bool    blockDataElementFree;   // if true, free blockDataElement in blockData,(true in server, false in client)
4317

4318
} SMqDataRsp;
4319

4320
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4321
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4322
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4323
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4324
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4325

4326
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4327
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4328
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4329

4330
typedef struct SMqBatchMetaRsp {
4331
  SMqRspHead   head;  // not serialize
4332
  STqOffsetVal rspOffset;
4333
  SArray*      batchMetaLen;
4334
  SArray*      batchMetaReq;
4335
  void*        pMetaBuff;    // not serialize
4336
  uint32_t     metaBuffLen;  // not serialize
4337
} SMqBatchMetaRsp;
4338

4339
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4340
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4341
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4342
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4343

4344
typedef struct {
4345
  SMqRspHead head;
4346
  char       cgroup[TSDB_CGROUP_LEN];
4347
  SArray*    topics;  // SArray<SMqSubTopicEp>
4348
} SMqAskEpRsp;
4349

4350
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4351
  int32_t tlen = 0;
×
4352
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4353
  int32_t sz = taosArrayGetSize(pRsp->topics);
×
4354
  tlen += taosEncodeFixedI32(buf, sz);
×
4355
  for (int32_t i = 0; i < sz; i++) {
×
4356
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
×
4357
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
×
4358
  }
4359
  return tlen;
×
4360
}
4361

4362
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4363
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4364
  int32_t sz;
4365
  buf = taosDecodeFixedI32(buf, &sz);
×
4366
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
×
4367
  if (pRsp->topics == NULL) {
×
4368
    return NULL;
×
4369
  }
4370
  for (int32_t i = 0; i < sz; i++) {
×
4371
    SMqSubTopicEp topicEp;
4372
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
×
4373
    if (buf == NULL) {
×
4374
      return NULL;
×
4375
    }
4376
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
×
4377
      return NULL;
×
4378
    }
4379
  }
4380
  return buf;
×
4381
}
4382

4383
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4384
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
×
4385
}
×
4386

4387
typedef struct {
4388
  int32_t      vgId;
4389
  STqOffsetVal offset;
4390
  int64_t      rows;
4391
  int64_t      ever;
4392
} OffsetRows;
4393

4394
typedef struct {
4395
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4396
  SArray* offsetRows;
4397
} TopicOffsetRows;
4398

4399
typedef struct {
4400
  int64_t consumerId;
4401
  int32_t epoch;
4402
  SArray* topics;
4403
  int8_t  pollFlag;
4404
} SMqHbReq;
4405

4406
typedef struct {
4407
  char   topic[TSDB_TOPIC_FNAME_LEN];
4408
  int8_t noPrivilege;
4409
} STopicPrivilege;
4410

4411
typedef struct {
4412
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4413
  int32_t debugFlag;
4414
} SMqHbRsp;
4415

4416
typedef struct {
4417
  SMsgHead head;
4418
  int64_t  consumerId;
4419
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4420
} SMqSeekReq;
4421

4422
#define TD_AUTO_CREATE_TABLE 0x1
4423
typedef struct {
4424
  int64_t       suid;
4425
  int64_t       uid;
4426
  int32_t       sver;
4427
  uint32_t      nData;
4428
  uint8_t*      pData;
4429
  SVCreateTbReq cTbReq;
4430
} SVSubmitBlk;
4431

4432
typedef struct {
4433
  SMsgHead header;
4434
  uint64_t sId;
4435
  uint64_t queryId;
4436
  uint64_t clientId;
4437
  uint64_t taskId;
4438
  uint32_t sqlLen;
4439
  uint32_t phyLen;
4440
  char*    sql;
4441
  char*    msg;
4442
  int8_t   source;
4443
} SVDeleteReq;
4444

4445
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4446
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4447

4448
typedef struct {
4449
  int64_t affectedRows;
4450
} SVDeleteRsp;
4451

4452
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4453
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4454

4455
typedef struct SDeleteRes {
4456
  uint64_t suid;
4457
  SArray*  uidList;
4458
  int64_t  skey;
4459
  int64_t  ekey;
4460
  int64_t  affectedRows;
4461
  char     tableFName[TSDB_TABLE_NAME_LEN];
4462
  char     tsColName[TSDB_COL_NAME_LEN];
4463
  int64_t  ctimeMs;  // fill by vnode
4464
  int8_t   source;
4465
} SDeleteRes;
4466

4467
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4468
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4469

4470
typedef struct {
4471
  // int64_t uid;
4472
  char    tbname[TSDB_TABLE_NAME_LEN];
4473
  int64_t startTs;
4474
  int64_t endTs;
4475
} SSingleDeleteReq;
4476

4477
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4478
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4479

4480
typedef struct {
4481
  int64_t suid;
4482
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4483
  int64_t ctimeMs;     // fill by vnode
4484
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4485
} SBatchDeleteReq;
4486

4487
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4488
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4489
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4490

4491
typedef struct {
4492
  int32_t msgIdx;
4493
  int32_t msgType;
4494
  int32_t msgLen;
4495
  void*   msg;
4496
} SBatchMsg;
4497

4498
typedef struct {
4499
  SMsgHead header;
4500
  SArray*  pMsgs;  // SArray<SBatchMsg>
4501
} SBatchReq;
4502

4503
typedef struct {
4504
  int32_t reqType;
4505
  int32_t msgIdx;
4506
  int32_t msgLen;
4507
  int32_t rspCode;
4508
  void*   msg;
4509
} SBatchRspMsg;
4510

4511
typedef struct {
4512
  SArray* pRsps;  // SArray<SBatchRspMsg>
4513
} SBatchRsp;
4514

4515
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4516
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4517
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
×
4518
  if (NULL == msg) {
×
4519
    return;
×
4520
  }
4521
  SBatchMsg* pMsg = (SBatchMsg*)msg;
×
4522
  taosMemoryFree(pMsg->msg);
×
4523
}
4524

4525
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4526
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4527

4528
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
×
4529
  if (NULL == p) {
×
4530
    return;
×
4531
  }
4532

4533
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
×
4534
  taosMemoryFree(pRsp->msg);
×
4535
}
4536

4537
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4538
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4539
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4540
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4541
void    tDestroySMqHbReq(SMqHbReq* pReq);
4542

4543
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4544
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4545
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4546

4547
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4548
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4549

4550
#define TD_REQ_FROM_APP               0x0
4551
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4552
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4553
#define SUBMIT_REQ_FROM_FILE          0x4
4554
#define TD_REQ_FROM_TAOX              0x8
4555
#define SUBMIT_REQUEST_VERSION        (1)
4556

4557
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4558

4559
typedef struct {
4560
  int32_t        flags;
4561
  SVCreateTbReq* pCreateTbReq;
4562
  int64_t        suid;
4563
  int64_t        uid;
4564
  int32_t        sver;
4565
  union {
4566
    SArray* aRowP;
4567
    SArray* aCol;
4568
  };
4569
  int64_t ctimeMs;
4570
} SSubmitTbData;
4571

4572
typedef struct {
4573
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4574
  bool    raw;
4575
} SSubmitReq2;
4576

4577
typedef struct {
4578
  SMsgHead header;
4579
  int64_t  version;
4580
  char     data[];  // SSubmitReq2
4581
} SSubmitReq2Msg;
4582

4583
int32_t transformRawSSubmitTbData(void* data, int64_t suid, int64_t uid, int32_t sver);
4584
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4585
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq, SArray* rawList);
4586
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4587
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4588

4589
typedef struct {
4590
  int32_t affectedRows;
4591
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4592
} SSubmitRsp2;
4593

4594
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4595
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4596
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4597

4598
#define TSDB_MSG_FLG_ENCODE 0x1
4599
#define TSDB_MSG_FLG_DECODE 0x2
4600
#define TSDB_MSG_FLG_CMPT   0x3
4601

4602
typedef struct {
4603
  union {
4604
    struct {
4605
      void*   msgStr;
4606
      int32_t msgLen;
4607
      int64_t ver;
4608
    };
4609
    void* pDataBlock;
4610
  };
4611
} SPackedData;
4612

4613
typedef struct {
4614
  char     fullname[TSDB_VIEW_FNAME_LEN];
4615
  char     name[TSDB_VIEW_NAME_LEN];
4616
  char     dbFName[TSDB_DB_FNAME_LEN];
4617
  char*    querySql;
4618
  char*    sql;
4619
  int8_t   orReplace;
4620
  int8_t   precision;
4621
  int32_t  numOfCols;
4622
  SSchema* pSchema;
4623
} SCMCreateViewReq;
4624

4625
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4626
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4627
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4628

4629
typedef struct {
4630
  char   fullname[TSDB_VIEW_FNAME_LEN];
4631
  char   name[TSDB_VIEW_NAME_LEN];
4632
  char   dbFName[TSDB_DB_FNAME_LEN];
4633
  char*  sql;
4634
  int8_t igNotExists;
4635
} SCMDropViewReq;
4636

4637
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4638
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4639
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4640

4641
typedef struct {
4642
  char fullname[TSDB_VIEW_FNAME_LEN];
4643
} SViewMetaReq;
4644
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4645
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4646

4647
typedef struct {
4648
  char     name[TSDB_VIEW_NAME_LEN];
4649
  char     dbFName[TSDB_DB_FNAME_LEN];
4650
  char*    user;
4651
  uint64_t dbId;
4652
  uint64_t viewId;
4653
  char*    querySql;
4654
  int8_t   precision;
4655
  int8_t   type;
4656
  int32_t  version;
4657
  int32_t  numOfCols;
4658
  SSchema* pSchema;
4659
} SViewMetaRsp;
4660
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4661
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4662
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4663
typedef struct {
4664
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4665
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4666
} STableTSMAInfoReq;
4667

4668
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4669
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4670

4671
typedef struct {
4672
  int32_t  funcId;
4673
  col_id_t colId;
4674
} STableTSMAFuncInfo;
4675

4676
typedef struct {
4677
  char     name[TSDB_TABLE_NAME_LEN];
4678
  uint64_t tsmaId;
4679
  char     targetTb[TSDB_TABLE_NAME_LEN];
4680
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4681
  char     tb[TSDB_TABLE_NAME_LEN];
4682
  char     dbFName[TSDB_DB_FNAME_LEN];
4683
  uint64_t suid;
4684
  uint64_t destTbUid;
4685
  uint64_t dbId;
4686
  int32_t  version;
4687
  int64_t  interval;
4688
  int8_t   unit;
4689
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4690
  SArray*  pTags;      // SArray<SSchema>
4691
  SArray*  pUsedCols;  // SArray<SSchema>
4692
  char*    ast;
4693

4694
  int64_t streamUid;
4695
  int64_t reqTs;
4696
  int64_t rspTs;
4697
  int64_t delayDuration;  // ms
4698
  bool    fillHistoryFinished;
4699
} STableTSMAInfo;
4700

4701
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4702
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4703
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4704
void    tFreeTableTSMAInfo(void* p);
4705
void    tFreeAndClearTableTSMAInfo(void* p);
4706
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4707

4708
#define STSMAHbRsp            STableTSMAInfoRsp
4709
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4710
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4711
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4712

4713
typedef struct SStreamProgressReq {
4714
  int64_t streamId;
4715
  int32_t vgId;
4716
  int32_t fetchIdx;
4717
  int32_t subFetchIdx;
4718
} SStreamProgressReq;
4719

4720
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4721
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4722

4723
typedef struct SStreamProgressRsp {
4724
  int64_t streamId;
4725
  int32_t vgId;
4726
  bool    fillHisFinished;
4727
  int64_t progressDelay;
4728
  int32_t fetchIdx;
4729
  int32_t subFetchIdx;
4730
} SStreamProgressRsp;
4731

4732
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4733
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4734

4735
typedef struct SDropCtbWithTsmaSingleVgReq {
4736
  SVgroupInfo vgInfo;
4737
  SArray*     pTbs;  // SVDropTbReq
4738
} SMDropTbReqsOnSingleVg;
4739

4740
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4741
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4742
void    tFreeSMDropTbReqOnSingleVg(void* p);
4743

4744
typedef struct SDropTbsReq {
4745
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4746
} SMDropTbsReq;
4747

4748
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4749
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4750
void    tFreeSMDropTbsReq(void*);
4751

4752
typedef struct SVFetchTtlExpiredTbsRsp {
4753
  SArray* pExpiredTbs;  // SVDropTbReq
4754
  int32_t vgId;
4755
} SVFetchTtlExpiredTbsRsp;
4756

4757
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4758
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4759

4760
void tFreeFetchTtlExpiredTbsRsp(void* p);
4761

4762
void setDefaultOptionsForField(SFieldWithOptions* field);
4763
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4764

4765
#pragma pack(pop)
4766

4767
#ifdef __cplusplus
4768
}
4769
#endif
4770

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