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

taosdata / TDengine / #3615

18 Feb 2025 07:41AM UTC coverage: 62.953% (+1.6%) from 61.4%
#3615

push

travis-ci

web-flow
Merge pull request #29812 from taosdata/doc/analysis

doc: update tdgpt doc.

146885 of 299602 branches covered (49.03%)

Branch coverage included in aggregate %.

230802 of 300346 relevant lines covered (76.85%)

17263824.17 hits per line

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

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

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
6,523,869✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
6,499,736✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
13,023,605!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
36,081,911✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
36,081,911✔
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

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

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

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

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

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

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

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

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

527
#pragma pack(push, 1)
528

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

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

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

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

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

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

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

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

600
//
601

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

733
  return pDstWrapper;
734
}
735

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

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

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

769
  taosMemoryFreeClear(pWrapper->pColCmpr);
770
  taosMemoryFreeClear(pWrapper);
771
}
772
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
773
  if (pSchemaWrapper->pSchema == NULL) return NULL;
10,602,295!
774

775
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
10,602,295!
776
  if (pSW == NULL) {
10,597,455!
777
    return NULL;
×
778
  }
779
  pSW->nCols = pSchemaWrapper->nCols;
10,597,455✔
780
  pSW->version = pSchemaWrapper->version;
10,597,455✔
781
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
10,597,455!
782
  if (pSW->pSchema == NULL) {
10,594,244!
783
    taosMemoryFree(pSW);
×
784
    return NULL;
×
785
  }
786

787
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
10,594,244✔
788
  return pSW;
10,594,244✔
789
}
790

791
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
468,428✔
792
  if (pSchemaWrapper) {
25,105,143!
793
    taosMemoryFree(pSchemaWrapper->pSchema);
9,615,079!
794
    taosMemoryFree(pSchemaWrapper);
9,615,085!
795
  }
796
}
25,104,236✔
797

798
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,322,079✔
799
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,322,079!
800
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,322,505!
801
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,322,756!
802
  }
803
}
1,321,891✔
804

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

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

824
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
825
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
359,972,044!
826
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
375,625,722!
827
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
375,625,722!
828
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
375,625,722!
829
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
375,625,722!
830
  return 0;
187,812,861✔
831
}
832

833
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
834
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
655,979,454!
835
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,285,916,258!
836
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,275,823,380!
837
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,297,422,059!
838
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
653,496,925!
839
  return 0;
704,419,859✔
840
}
841

842
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
843
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
214,109,120!
844
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
214,109,120!
845
  return 0;
107,054,560✔
846
}
847

848
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
849
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,407,128!
850
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,407,126!
851
  return 0;
1,703,563✔
852
}
853

854
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
855
  int32_t tlen = 0;
8,962✔
856
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,962✔
857
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,962✔
858
  for (int32_t i = 0; i < pSW->nCols; i++) {
65,942✔
859
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
113,960!
860
  }
861
  return tlen;
8,962✔
862
}
863

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

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

882
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
883
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,341,602!
884
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,341,602!
885
  for (int32_t i = 0; i < pSW->nCols; i++) {
16,324,479✔
886
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
31,307,356!
887
  }
888
  return 0;
670,801✔
889
}
890

891
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
892
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,071,548!
893
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,071,440!
894

895
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
535,693!
896
  if (pSW->pSchema == NULL) {
535,718!
897
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
898
  }
899
  for (int32_t i = 0; i < pSW->nCols; i++) {
7,461,949!
900
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
13,854,063!
901
  }
902

903
  return 0;
534,117✔
904
}
905

906
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
907
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
81,292,579!
908
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
78,257,581!
909

910
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
39,106,917!
911
  if (pSW->pSchema == NULL) {
39,384,038!
912
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
913
  }
914
  for (int32_t i = 0; i < pSW->nCols; i++) {
734,916,226✔
915
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,388,906,946!
916
  }
917

918
  return 0;
41,541,468✔
919
}
920

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1306
typedef STableCfg STableCfgRsp;
1307

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1546
typedef SDbCfgRsp SDbCfgInfo;
1547

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1797
typedef struct {
1798
  int32_t vgId;
1799
  int64_t nTimeSeries;
1800
} SVnodeLoadLite;
1801

1802
typedef struct {
1803
  int8_t  syncState;
1804
  int64_t syncTerm;
1805
  int8_t  syncRestore;
1806
  int64_t roleTimeMs;
1807
} SMnodeLoad;
1808

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

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

1848
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1849
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1850
void    tFreeSStatusReq(SStatusReq* pReq);
1851

1852
typedef struct {
1853
  int32_t forceReadConfig;
1854
  int32_t cver;
1855
  SArray* array;
1856
} SConfigReq;
1857

1858
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
1859
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
1860
void    tFreeSConfigReq(SConfigReq* pReq);
1861

1862
typedef struct {
1863
  int32_t dnodeId;
1864
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
1865
} SDnodeInfoReq;
1866

1867
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1868
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1869

1870
typedef enum {
1871
  MONITOR_TYPE_COUNTER = 0,
1872
  MONITOR_TYPE_SLOW_LOG = 1,
1873
} MONITOR_TYPE;
1874

1875
typedef struct {
1876
  int32_t      contLen;
1877
  char*        pCont;
1878
  MONITOR_TYPE type;
1879
} SStatisReq;
1880

1881
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1882
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1883
void    tFreeSStatisReq(SStatisReq* pReq);
1884

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

1896
typedef struct {
1897
  int32_t dnodeId;
1898
  int64_t clusterId;
1899
  SArray* pVloads;
1900
} SNotifyReq;
1901

1902
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1903
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1904
void    tFreeSNotifyReq(SNotifyReq* pReq);
1905

1906
typedef struct {
1907
  int32_t dnodeId;
1908
  int64_t clusterId;
1909
} SDnodeCfg;
1910

1911
typedef struct {
1912
  int32_t id;
1913
  int8_t  isMnode;
1914
  SEp     ep;
1915
} SDnodeEp;
1916

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

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

1935
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1936
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1937
void    tFreeSStatusRsp(SStatusRsp* pRsp);
1938

1939
typedef struct {
1940
  int32_t forceReadConfig;
1941
  int32_t isConifgVerified;
1942
  int32_t isVersionVerified;
1943
  int32_t cver;
1944
  SArray* array;
1945
} SConfigRsp;
1946

1947
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
1948
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
1949
void    tFreeSConfigRsp(SConfigRsp* pRsp);
1950

1951
typedef struct {
1952
  int32_t reserved;
1953
} SMTimerReq;
1954

1955
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1956
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1957

1958
typedef struct SOrphanTask {
1959
  int64_t streamId;
1960
  int32_t taskId;
1961
  int32_t nodeId;
1962
} SOrphanTask;
1963

1964
typedef struct SMStreamDropOrphanMsg {
1965
  SArray* pList;  // SArray<SOrphanTask>
1966
} SMStreamDropOrphanMsg;
1967

1968
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1969
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1970
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
1971

1972
typedef struct {
1973
  int32_t  id;
1974
  uint16_t port;                 // node sync Port
1975
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
1976
} SReplica;
1977

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

2030
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2031
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2032
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2033

2034
typedef struct {
2035
  int32_t compactId;
2036
  int32_t vgId;
2037
  int32_t dnodeId;
2038
} SQueryCompactProgressReq;
2039

2040
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2041
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2042

2043
typedef struct {
2044
  int32_t compactId;
2045
  int32_t vgId;
2046
  int32_t dnodeId;
2047
  int32_t numberFileset;
2048
  int32_t finished;
2049
  int32_t progress;
2050
  int64_t remainingTime;
2051
} SQueryCompactProgressRsp;
2052

2053
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2054
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2055

2056
typedef struct {
2057
  int32_t vgId;
2058
  int32_t dnodeId;
2059
  int64_t dbUid;
2060
  char    db[TSDB_DB_FNAME_LEN];
2061
  int64_t reserved[8];
2062
} SDropVnodeReq;
2063

2064
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2065
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2066

2067
typedef struct {
2068
  char    colName[TSDB_COL_NAME_LEN];
2069
  char    stb[TSDB_TABLE_FNAME_LEN];
2070
  int64_t stbUid;
2071
  int64_t dbUid;
2072
  int64_t reserved[8];
2073
} SDropIndexReq;
2074

2075
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2076
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2077

2078
typedef struct {
2079
  int64_t     dbUid;
2080
  char        db[TSDB_DB_FNAME_LEN];
2081
  int64_t     compactStartTime;
2082
  STimeWindow tw;
2083
  int32_t     compactId;
2084
} SCompactVnodeReq;
2085

2086
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2087
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2088

2089
typedef struct {
2090
  int32_t compactId;
2091
  int32_t vgId;
2092
  int32_t dnodeId;
2093
} SVKillCompactReq;
2094

2095
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2096
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2097

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

2124
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2125
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2126

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

2140
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2141
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2142

2143
typedef struct {
2144
  int32_t vgId;
2145
  int8_t  disable;
2146
} SDisableVnodeWriteReq;
2147

2148
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2149
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2150

2151
typedef struct {
2152
  int32_t  srcVgId;
2153
  int32_t  dstVgId;
2154
  uint32_t hashBegin;
2155
  uint32_t hashEnd;
2156
  int32_t  changeVersion;
2157
  int32_t  reserved;
2158
} SAlterVnodeHashRangeReq;
2159

2160
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2161
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2162

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

2172
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2173
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2174

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

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

2195
typedef struct {
2196
  int32_t     numOfVgroups;
2197
  SVgroupInfo vgroups[];
2198
} SVgroupsInfo;
2199

2200
typedef struct {
2201
  STableMetaRsp* pMeta;
2202
} SMAlterStbRsp;
2203

2204
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2205
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2206
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2207

2208
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2209
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2210
void    tFreeSTableMetaRsp(void* pRsp);
2211
void    tFreeSTableIndexRsp(void* info);
2212

2213
typedef struct {
2214
  SArray* pMetaRsp;   // Array of STableMetaRsp
2215
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2216
} SSTbHbRsp;
2217

2218
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2219
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2220
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2221

2222
typedef struct {
2223
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2224
} SViewHbRsp;
2225

2226
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2227
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2228
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2229

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

2241
typedef struct {
2242
  int32_t dataLen;
2243
  char    name[TSDB_TABLE_FNAME_LEN];
2244
  char*   data;
2245
} STagData;
2246

2247
typedef struct {
2248
  int32_t useless;  // useless
2249
} SShowVariablesReq;
2250

2251
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2252
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2253

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

2262
typedef struct {
2263
  SArray* variables;  // SArray<SVariablesInfo>
2264
} SShowVariablesRsp;
2265

2266
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2267
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2268

2269
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2270

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

2283
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2284
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2285
void tFreeSShowReq(SShowReq* pReq);
2286

2287
typedef struct {
2288
  int64_t       showId;
2289
  STableMetaRsp tableMeta;
2290
} SShowRsp, SVShowTablesRsp;
2291

2292
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2293
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2294
// void    tFreeSShowRsp(SShowRsp* pRsp);
2295

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

2306
typedef struct SSysTableSchema {
2307
  int8_t   type;
2308
  col_id_t colId;
2309
  int32_t  bytes;
2310
} SSysTableSchema;
2311

2312
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2313
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2314

2315
typedef struct {
2316
  int64_t useconds;
2317
  int8_t  completed;  // all results are returned to client
2318
  int8_t  precision;
2319
  int8_t  compressed;
2320
  int8_t  streamBlockType;
2321
  int32_t payloadLen;
2322
  int32_t compLen;
2323
  int32_t numOfBlocks;
2324
  int64_t numOfRows;  // from int32_t change to int64_t
2325
  int64_t numOfCols;
2326
  int64_t skey;
2327
  int64_t ekey;
2328
  int64_t version;                         // for stream
2329
  TSKEY   watermark;                       // for stream
2330
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2331
  char    data[];
2332
} SRetrieveTableRsp;
2333

2334
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2335

2336
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2337
  do {                                          \
2338
    ((int32_t*)(_p))[0] = (_compLen);           \
2339
    ((int32_t*)(_p))[1] = (_fullLen);           \
2340
  } while (0);
2341

2342
typedef struct {
2343
  int64_t version;
2344
  int64_t numOfRows;
2345
  int8_t  compressed;
2346
  int8_t  precision;
2347
  char    data[];
2348
} SRetrieveTableRspForTmq;
2349

2350
typedef struct {
2351
  int64_t handle;
2352
  int64_t useconds;
2353
  int8_t  completed;  // all results are returned to client
2354
  int8_t  precision;
2355
  int8_t  compressed;
2356
  int32_t compLen;
2357
  int32_t numOfRows;
2358
  int32_t fullLen;
2359
  char    data[];
2360
} SRetrieveMetaTableRsp;
2361

2362
typedef struct SExplainExecInfo {
2363
  double   startupCost;
2364
  double   totalCost;
2365
  uint64_t numOfRows;
2366
  uint32_t verboseLen;
2367
  void*    verboseInfo;
2368
} SExplainExecInfo;
2369

2370
typedef struct {
2371
  int32_t           numOfPlans;
2372
  SExplainExecInfo* subplanInfo;
2373
} SExplainRsp;
2374

2375
typedef struct {
2376
  SExplainRsp rsp;
2377
  uint64_t    qId;
2378
  uint64_t    cId;
2379
  uint64_t    tId;
2380
  int64_t     rId;
2381
  int32_t     eId;
2382
} SExplainLocalRsp;
2383

2384
typedef struct STableScanAnalyzeInfo {
2385
  uint64_t totalRows;
2386
  uint64_t totalCheckedRows;
2387
  uint32_t totalBlocks;
2388
  uint32_t loadBlocks;
2389
  uint32_t loadBlockStatis;
2390
  uint32_t skipBlocks;
2391
  uint32_t filterOutBlocks;
2392
  double   elapsedTime;
2393
  double   filterTime;
2394
} STableScanAnalyzeInfo;
2395

2396
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2397
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2398
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2399

2400
typedef struct {
2401
  char    config[TSDB_DNODE_CONFIG_LEN];
2402
  char    value[TSDB_CLUSTER_VALUE_LEN];
2403
  int32_t sqlLen;
2404
  char*   sql;
2405
} SMCfgClusterReq;
2406

2407
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2408
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2409
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2410

2411
typedef struct {
2412
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2413
  int32_t port;
2414
  int32_t sqlLen;
2415
  char*   sql;
2416
} SCreateDnodeReq;
2417

2418
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2419
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2420
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2421

2422
typedef struct {
2423
  int32_t dnodeId;
2424
  char    fqdn[TSDB_FQDN_LEN];
2425
  int32_t port;
2426
  int8_t  force;
2427
  int8_t  unsafe;
2428
  int32_t sqlLen;
2429
  char*   sql;
2430
} SDropDnodeReq;
2431

2432
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2433
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2434
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2435

2436
enum {
2437
  RESTORE_TYPE__ALL = 1,
2438
  RESTORE_TYPE__MNODE,
2439
  RESTORE_TYPE__VNODE,
2440
  RESTORE_TYPE__QNODE,
2441
};
2442

2443
typedef struct {
2444
  int32_t dnodeId;
2445
  int8_t  restoreType;
2446
  int32_t sqlLen;
2447
  char*   sql;
2448
} SRestoreDnodeReq;
2449

2450
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2451
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2452
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2453

2454
typedef struct {
2455
  int32_t dnodeId;
2456
  char    config[TSDB_DNODE_CONFIG_LEN];
2457
  char    value[TSDB_DNODE_VALUE_LEN];
2458
  int32_t sqlLen;
2459
  char*   sql;
2460
} SMCfgDnodeReq;
2461

2462
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2463
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2464
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2465

2466
typedef struct {
2467
  char    config[TSDB_DNODE_CONFIG_LEN];
2468
  char    value[TSDB_DNODE_VALUE_LEN];
2469
  int32_t version;
2470
} SDCfgDnodeReq;
2471

2472
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2473
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2474

2475
typedef struct {
2476
  int32_t dnodeId;
2477
  int32_t sqlLen;
2478
  char*   sql;
2479
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2480
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2481

2482
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2483
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2484
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2485
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2486
typedef struct {
2487
  int8_t   replica;
2488
  SReplica replicas[TSDB_MAX_REPLICA];
2489
  int8_t   learnerReplica;
2490
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2491
  int64_t  lastIndex;
2492
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2493

2494
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2495
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2496

2497
typedef struct {
2498
  int32_t urlLen;
2499
  int32_t sqlLen;
2500
  char*   url;
2501
  char*   sql;
2502
} SMCreateAnodeReq;
2503

2504
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2505
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2506
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2507

2508
typedef struct {
2509
  int32_t anodeId;
2510
  int32_t sqlLen;
2511
  char*   sql;
2512
} SMDropAnodeReq, SMUpdateAnodeReq;
2513

2514
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2515
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2516
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2517
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2518
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2519
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2520

2521
typedef struct {
2522
  int32_t vgId;
2523
  int32_t hbSeq;
2524
} SVArbHbReqMember;
2525

2526
typedef struct {
2527
  int32_t dnodeId;
2528
  char*   arbToken;
2529
  int64_t arbTerm;
2530
  SArray* hbMembers;  // SVArbHbReqMember
2531
} SVArbHeartBeatReq;
2532

2533
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2534
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2535
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2536

2537
typedef struct {
2538
  int32_t vgId;
2539
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2540
  int32_t hbSeq;
2541
} SVArbHbRspMember;
2542

2543
typedef struct {
2544
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2545
  int32_t dnodeId;
2546
  SArray* hbMembers;  // SVArbHbRspMember
2547
} SVArbHeartBeatRsp;
2548

2549
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2550
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2551
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2552

2553
typedef struct {
2554
  char*   arbToken;
2555
  int64_t arbTerm;
2556
  char*   member0Token;
2557
  char*   member1Token;
2558
} SVArbCheckSyncReq;
2559

2560
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2561
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2562
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2563

2564
typedef struct {
2565
  char*   arbToken;
2566
  char*   member0Token;
2567
  char*   member1Token;
2568
  int32_t vgId;
2569
  int32_t errCode;
2570
} SVArbCheckSyncRsp;
2571

2572
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2573
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2574
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2575

2576
typedef struct {
2577
  char*   arbToken;
2578
  int64_t arbTerm;
2579
  char*   memberToken;
2580
} SVArbSetAssignedLeaderReq;
2581

2582
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2583
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2584
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2585

2586
typedef struct {
2587
  char*   arbToken;
2588
  char*   memberToken;
2589
  int32_t vgId;
2590
} SVArbSetAssignedLeaderRsp;
2591

2592
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2593
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2594
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2595

2596
typedef struct {
2597
  int32_t dnodeId;
2598
  char*   token;
2599
} SMArbUpdateGroupMember;
2600

2601
typedef struct {
2602
  int32_t dnodeId;
2603
  char*   token;
2604
  int8_t  acked;
2605
} SMArbUpdateGroupAssigned;
2606

2607
typedef struct {
2608
  int32_t                  vgId;
2609
  int64_t                  dbUid;
2610
  SMArbUpdateGroupMember   members[2];
2611
  int8_t                   isSync;
2612
  int8_t                   assignedAcked;
2613
  SMArbUpdateGroupAssigned assignedLeader;
2614
  int64_t                  version;
2615
  int32_t                  code;
2616
  int64_t                  updateTimeMs;
2617
} SMArbUpdateGroup;
2618

2619
typedef struct {
2620
  SArray* updateArray;  // SMArbUpdateGroup
2621
} SMArbUpdateGroupBatchReq;
2622

2623
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2624
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2625
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2626

2627
typedef struct {
2628
  char queryStrId[TSDB_QUERY_ID_LEN];
2629
} SKillQueryReq;
2630

2631
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2632
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2633

2634
typedef struct {
2635
  uint32_t connId;
2636
} SKillConnReq;
2637

2638
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2639
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2640

2641
typedef struct {
2642
  int32_t transId;
2643
} SKillTransReq;
2644

2645
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2646
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2647

2648
typedef struct {
2649
  int32_t useless;  // useless
2650
  int32_t sqlLen;
2651
  char*   sql;
2652
} SBalanceVgroupReq;
2653

2654
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2655
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2656
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2657

2658
typedef struct {
2659
  int32_t vgId1;
2660
  int32_t vgId2;
2661
} SMergeVgroupReq;
2662

2663
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2664
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2665

2666
typedef struct {
2667
  int32_t vgId;
2668
  int32_t dnodeId1;
2669
  int32_t dnodeId2;
2670
  int32_t dnodeId3;
2671
  int32_t sqlLen;
2672
  char*   sql;
2673
} SRedistributeVgroupReq;
2674

2675
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2676
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2677
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2678

2679
typedef struct {
2680
  int32_t reserved;
2681
  int32_t vgId;
2682
  int32_t sqlLen;
2683
  char*   sql;
2684
  char    db[TSDB_DB_FNAME_LEN];
2685
} SBalanceVgroupLeaderReq;
2686

2687
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2688
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2689
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2690

2691
typedef struct {
2692
  int32_t vgId;
2693
} SForceBecomeFollowerReq;
2694

2695
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2696
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2697

2698
typedef struct {
2699
  int32_t vgId;
2700
} SSplitVgroupReq;
2701

2702
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2703
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2704

2705
typedef struct {
2706
  char user[TSDB_USER_LEN];
2707
  char spi;
2708
  char encrypt;
2709
  char secret[TSDB_PASSWORD_LEN];
2710
  char ckey[TSDB_PASSWORD_LEN];
2711
} SAuthReq, SAuthRsp;
2712

2713
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2714
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2715

2716
typedef struct {
2717
  int32_t statusCode;
2718
  char    details[1024];
2719
} SServerStatusRsp;
2720

2721
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2722
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2723

2724
/**
2725
 * The layout of the query message payload is as following:
2726
 * +--------------------+---------------------------------+
2727
 * |Sql statement       | Physical plan                   |
2728
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2729
 * +--------------------+---------------------------------+
2730
 */
2731
typedef struct SSubQueryMsg {
2732
  SMsgHead header;
2733
  uint64_t sId;
2734
  uint64_t queryId;
2735
  uint64_t clientId;
2736
  uint64_t taskId;
2737
  int64_t  refId;
2738
  int32_t  execId;
2739
  int32_t  msgMask;
2740
  int8_t   taskType;
2741
  int8_t   explain;
2742
  int8_t   needFetch;
2743
  int8_t   compress;
2744
  uint32_t sqlLen;
2745
  char*    sql;
2746
  uint32_t msgLen;
2747
  char*    msg;
2748
} SSubQueryMsg;
2749

2750
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2751
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2752
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2753

2754
typedef struct {
2755
  SMsgHead header;
2756
  uint64_t sId;
2757
  uint64_t queryId;
2758
  uint64_t taskId;
2759
} SSinkDataReq;
2760

2761
typedef struct {
2762
  SMsgHead header;
2763
  uint64_t sId;
2764
  uint64_t queryId;
2765
  uint64_t clientId;
2766
  uint64_t taskId;
2767
  int32_t  execId;
2768
} SQueryContinueReq;
2769

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

2777
typedef struct {
2778
  int32_t code;
2779
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2780
  int32_t sversion;
2781
  int32_t tversion;
2782
} SResReadyRsp;
2783

2784
typedef struct SOperatorParam {
2785
  int32_t opType;
2786
  int32_t downstreamIdx;
2787
  void*   value;
2788
  SArray* pChildren;  // SArray<SOperatorParam*>
2789
} SOperatorParam;
2790

2791
typedef struct STableScanOperatorParam {
2792
  bool    tableSeq;
2793
  SArray* pUidList;
2794
} STableScanOperatorParam;
2795

2796
typedef struct {
2797
  SMsgHead        header;
2798
  uint64_t        sId;
2799
  uint64_t        queryId;
2800
  uint64_t        clientId;
2801
  uint64_t        taskId;
2802
  int32_t         execId;
2803
  SOperatorParam* pOpParam;
2804
} SResFetchReq;
2805

2806
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2807
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2808

2809
typedef struct {
2810
  SMsgHead header;
2811
  uint64_t clientId;
2812
} SSchTasksStatusReq;
2813

2814
typedef struct {
2815
  uint64_t queryId;
2816
  uint64_t clientId;
2817
  uint64_t taskId;
2818
  int64_t  refId;
2819
  int32_t  execId;
2820
  int8_t   status;
2821
} STaskStatus;
2822

2823
typedef struct {
2824
  int64_t refId;
2825
  SArray* taskStatus;  // SArray<STaskStatus>
2826
} SSchedulerStatusRsp;
2827

2828
typedef struct {
2829
  uint64_t queryId;
2830
  uint64_t taskId;
2831
  int8_t   action;
2832
} STaskAction;
2833

2834
typedef struct SQueryNodeEpId {
2835
  int32_t nodeId;  // vgId or qnodeId
2836
  SEp     ep;
2837
} SQueryNodeEpId;
2838

2839
typedef struct {
2840
  SMsgHead       header;
2841
  uint64_t       clientId;
2842
  SQueryNodeEpId epId;
2843
  SArray*        taskAction;  // SArray<STaskAction>
2844
} SSchedulerHbReq;
2845

2846
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2847
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2848
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2849

2850
typedef struct {
2851
  SQueryNodeEpId epId;
2852
  SArray*        taskStatus;  // SArray<STaskStatus>
2853
} SSchedulerHbRsp;
2854

2855
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2856
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2857
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2858

2859
typedef struct {
2860
  SMsgHead header;
2861
  uint64_t sId;
2862
  uint64_t queryId;
2863
  uint64_t clientId;
2864
  uint64_t taskId;
2865
  int64_t  refId;
2866
  int32_t  execId;
2867
} STaskCancelReq;
2868

2869
typedef struct {
2870
  int32_t code;
2871
} STaskCancelRsp;
2872

2873
typedef struct {
2874
  SMsgHead header;
2875
  uint64_t sId;
2876
  uint64_t queryId;
2877
  uint64_t clientId;
2878
  uint64_t taskId;
2879
  int64_t  refId;
2880
  int32_t  execId;
2881
} STaskDropReq;
2882

2883
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2884
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2885

2886
typedef enum {
2887
  TASK_NOTIFY_FINISHED = 1,
2888
} ETaskNotifyType;
2889

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

2901
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2902
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2903

2904
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2905
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2906

2907
typedef struct {
2908
  int32_t code;
2909
} STaskDropRsp;
2910

2911
#define STREAM_TRIGGER_AT_ONCE            1
2912
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2913
#define STREAM_TRIGGER_MAX_DELAY          3
2914
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2915

2916
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2917
#define STREAM_FILL_HISTORY_ON        1
2918
#define STREAM_FILL_HISTORY_OFF       0
2919
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2920
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2921
#define STREAM_CREATE_STABLE_TRUE     1
2922
#define STREAM_CREATE_STABLE_FALSE    0
2923

2924
typedef struct SColLocation {
2925
  int16_t  slotId;
2926
  col_id_t colId;
2927
  int8_t   type;
2928
} SColLocation;
2929

2930
typedef struct SVgroupVer {
2931
  int32_t vgId;
2932
  int64_t ver;
2933
} SVgroupVer;
2934

2935
typedef struct {
2936
  char    name[TSDB_STREAM_FNAME_LEN];
2937
  char    sourceDB[TSDB_DB_FNAME_LEN];
2938
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
2939
  char*   sql;
2940
  char*   ast;
2941
  int8_t  igExists;
2942
  int8_t  triggerType;
2943
  int8_t  igExpired;
2944
  int8_t  fillHistory;  // process data inserted before creating stream
2945
  int64_t maxDelay;
2946
  int64_t watermark;
2947
  int32_t numOfTags;
2948
  SArray* pTags;  // array of SField
2949
  // 3.0.20
2950
  int64_t checkpointFreq;  // ms
2951
  // 3.0.2.3
2952
  int8_t   createStb;
2953
  uint64_t targetStbUid;
2954
  SArray*  fillNullCols;  // array of SColLocation
2955
  int64_t  deleteMark;
2956
  int8_t   igUpdate;
2957
  int64_t  lastTs;
2958
  SArray*  pVgroupVerList;
2959
  // 3.3.0.0
2960
  SArray* pCols;  // array of SField
2961
  int64_t smaId;
2962
  // 3.3.6.0
2963
  SArray* pNotifyAddrUrls;
2964
  int32_t notifyEventTypes;
2965
  int32_t notifyErrorHandle;
2966
  int8_t  notifyHistory;
2967
} SCMCreateStreamReq;
2968

2969
typedef struct STaskNotifyEventStat {
2970
  int64_t notifyEventAddTimes;     // call times of add function
2971
  int64_t notifyEventAddElems;     // elements added by add function
2972
  double  notifyEventAddCostSec;   // time cost of add function
2973
  int64_t notifyEventPushTimes;    // call times of push function
2974
  int64_t notifyEventPushElems;    // elements pushed by push function
2975
  double  notifyEventPushCostSec;  // time cost of push function
2976
  int64_t notifyEventPackTimes;    // call times of pack function
2977
  int64_t notifyEventPackElems;    // elements packed by pack function
2978
  double  notifyEventPackCostSec;  // time cost of pack function
2979
  int64_t notifyEventSendTimes;    // call times of send function
2980
  int64_t notifyEventSendElems;    // elements sent by send function
2981
  double  notifyEventSendCostSec;  // time cost of send function
2982
  int64_t notifyEventHoldElems;    // elements hold due to watermark
2983
} STaskNotifyEventStat;
2984

2985
typedef struct {
2986
  int64_t streamId;
2987
} SCMCreateStreamRsp;
2988

2989
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
2990
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
2991
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
2992

2993
enum {
2994
  TOPIC_SUB_TYPE__DB = 1,
2995
  TOPIC_SUB_TYPE__TABLE,
2996
  TOPIC_SUB_TYPE__COLUMN,
2997
};
2998

2999
#define DEFAULT_MAX_POLL_INTERVAL 300000
3000
#define DEFAULT_SESSION_TIMEOUT   12000
3001

3002
typedef struct {
3003
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
3004
  int8_t igExists;
3005
  int8_t subType;
3006
  int8_t withMeta;
3007
  char*  sql;
3008
  char   subDbName[TSDB_DB_FNAME_LEN];
3009
  char*  ast;
3010
  char   subStbName[TSDB_TABLE_FNAME_LEN];
3011
} SCMCreateTopicReq;
3012

3013
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3014
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3015
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3016

3017
typedef struct {
3018
  int64_t consumerId;
3019
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3020

3021
typedef struct {
3022
  int64_t consumerId;
3023
  char    cgroup[TSDB_CGROUP_LEN];
3024
  char    clientId[TSDB_CLIENT_ID_LEN];
3025
  char    user[TSDB_USER_LEN];
3026
  char    fqdn[TSDB_FQDN_LEN];
3027
  SArray* topicNames;  // SArray<char**>
3028

3029
  int8_t  withTbName;
3030
  int8_t  autoCommit;
3031
  int32_t autoCommitInterval;
3032
  int8_t  resetOffsetCfg;
3033
  int8_t  enableReplay;
3034
  int8_t  enableBatchMeta;
3035
  int32_t sessionTimeoutMs;
3036
  int32_t maxPollIntervalMs;
3037
} SCMSubscribeReq;
3038

3039
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3040
  int32_t tlen = 0;
2,450✔
3041
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,450!
3042
  tlen += taosEncodeString(buf, pReq->cgroup);
2,450✔
3043
  tlen += taosEncodeString(buf, pReq->clientId);
2,450✔
3044

3045
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,450!
3046
  tlen += taosEncodeFixedI32(buf, topicNum);
2,450✔
3047

3048
  for (int32_t i = 0; i < topicNum; i++) {
3,456✔
3049
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,012✔
3050
  }
3051

3052
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,450!
3053
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,450!
3054
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,450!
3055
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,450!
3056
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,450!
3057
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,450!
3058
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,450!
3059
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,450!
3060
  tlen += taosEncodeString(buf, pReq->user);
2,450✔
3061
  tlen += taosEncodeString(buf, pReq->fqdn);
2,450✔
3062

3063
  return tlen;
2,450✔
3064
}
3065

3066
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3067
  void* start = buf;
1,214✔
3068
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,214!
3069
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,214✔
3070
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,214✔
3071

3072
  int32_t topicNum = 0;
1,214!
3073
  buf = taosDecodeFixedI32(buf, &topicNum);
1,214✔
3074

3075
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,214✔
3076
  if (pReq->topicNames == NULL) {
1,214!
3077
    return terrno;
×
3078
  }
3079
  for (int32_t i = 0; i < topicNum; i++) {
1,712✔
3080
    char* name = NULL;
498✔
3081
    buf = taosDecodeString(buf, &name);
498✔
3082
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
996!
3083
      return terrno;
×
3084
    }
3085
  }
3086

3087
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,214✔
3088
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,214✔
3089
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,214!
3090
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,214✔
3091
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,214✔
3092
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,214✔
3093
  if ((char*)buf - (char*)start < len) {
1,214!
3094
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,214!
3095
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,214!
3096
    buf = taosDecodeStringTo(buf, pReq->user);
1,214✔
3097
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,428✔
3098
  } else {
3099
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3100
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3101
  }
3102

3103
  return 0;
1,214✔
3104
}
3105

3106
typedef struct {
3107
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3108
  SArray* removedConsumers;  // SArray<int64_t>
3109
  SArray* newConsumers;      // SArray<int64_t>
3110
} SMqRebInfo;
3111

3112
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3113
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,205!
3114
  if (pRebInfo == NULL) {
1,205!
3115
    return NULL;
×
3116
  }
3117
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,205✔
3118
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,205✔
3119
  if (pRebInfo->removedConsumers == NULL) {
1,205!
3120
    goto _err;
×
3121
  }
3122
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,205✔
3123
  if (pRebInfo->newConsumers == NULL) {
1,205!
3124
    goto _err;
×
3125
  }
3126
  return pRebInfo;
1,205✔
3127
_err:
×
3128
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3129
  taosArrayDestroy(pRebInfo->newConsumers);
×
3130
  taosMemoryFreeClear(pRebInfo);
×
3131
  return NULL;
×
3132
}
3133

3134
typedef struct {
3135
  int64_t streamId;
3136
  int64_t checkpointId;
3137
  char    streamName[TSDB_STREAM_FNAME_LEN];
3138
} SMStreamDoCheckpointMsg;
3139

3140
typedef struct {
3141
  int64_t status;
3142
} SMVSubscribeRsp;
3143

3144
typedef struct {
3145
  char    name[TSDB_TOPIC_FNAME_LEN];
3146
  int8_t  igNotExists;
3147
  int32_t sqlLen;
3148
  char*   sql;
3149
} SMDropTopicReq;
3150

3151
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3152
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3153
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3154

3155
typedef struct {
3156
  char   topic[TSDB_TOPIC_FNAME_LEN];
3157
  char   cgroup[TSDB_CGROUP_LEN];
3158
  int8_t igNotExists;
3159
} SMDropCgroupReq;
3160

3161
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3162
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3163

3164
typedef struct {
3165
  int8_t reserved;
3166
} SMDropCgroupRsp;
3167

3168
typedef struct {
3169
  char    name[TSDB_TABLE_FNAME_LEN];
3170
  int8_t  alterType;
3171
  SSchema schema;
3172
} SAlterTopicReq;
3173

3174
typedef struct {
3175
  SMsgHead head;
3176
  char     name[TSDB_TABLE_FNAME_LEN];
3177
  int64_t  tuid;
3178
  int32_t  sverson;
3179
  int32_t  execLen;
3180
  char*    executor;
3181
  int32_t  sqlLen;
3182
  char*    sql;
3183
} SDCreateTopicReq;
3184

3185
typedef struct {
3186
  SMsgHead head;
3187
  char     name[TSDB_TABLE_FNAME_LEN];
3188
  int64_t  tuid;
3189
} SDDropTopicReq;
3190

3191
typedef struct {
3192
  int64_t maxdelay[2];
3193
  int64_t watermark[2];
3194
  int64_t deleteMark[2];
3195
  int32_t qmsgLen[2];
3196
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3197
} SRSmaParam;
3198

3199
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3200
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3201

3202
// TDMT_VND_CREATE_STB ==============
3203
typedef struct SVCreateStbReq {
3204
  char*           name;
3205
  tb_uid_t        suid;
3206
  int8_t          rollup;
3207
  SSchemaWrapper  schemaRow;
3208
  SSchemaWrapper  schemaTag;
3209
  SRSmaParam      rsmaParam;
3210
  int32_t         alterOriDataLen;
3211
  void*           alterOriData;
3212
  int8_t          source;
3213
  int8_t          colCmpred;
3214
  SColCmprWrapper colCmpr;
3215
} SVCreateStbReq;
3216

3217
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3218
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3219

3220
// TDMT_VND_DROP_STB ==============
3221
typedef struct SVDropStbReq {
3222
  char*    name;
3223
  tb_uid_t suid;
3224
} SVDropStbReq;
3225

3226
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3227
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3228

3229
// TDMT_VND_CREATE_TABLE ==============
3230
#define TD_CREATE_IF_NOT_EXISTS 0x1
3231
typedef struct SVCreateTbReq {
3232
  int32_t  flags;
3233
  char*    name;
3234
  tb_uid_t uid;
3235
  int64_t  btime;
3236
  int32_t  ttl;
3237
  int32_t  commentLen;
3238
  char*    comment;
3239
  int8_t   type;
3240
  union {
3241
    struct {
3242
      char*    stbName;  // super table name
3243
      uint8_t  tagNum;
3244
      tb_uid_t suid;
3245
      SArray*  tagName;
3246
      uint8_t* pTag;
3247
    } ctb;
3248
    struct {
3249
      SSchemaWrapper schemaRow;
3250
    } ntb;
3251
  };
3252
  int32_t         sqlLen;
3253
  char*           sql;
3254
  SColCmprWrapper colCmpr;
3255
} SVCreateTbReq;
3256

3257
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3258
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3259
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3260

3261
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
5,677✔
3262
  if (NULL == req) {
19,242,516!
3263
    return;
18,953,067✔
3264
  }
3265

3266
  taosMemoryFreeClear(req->sql);
289,449!
3267
  taosMemoryFreeClear(req->name);
289,449!
3268
  taosMemoryFreeClear(req->comment);
289,479!
3269
  if (req->type == TSDB_CHILD_TABLE) {
289,479!
3270
    taosMemoryFreeClear(req->ctb.pTag);
275,062!
3271
    taosMemoryFreeClear(req->ctb.stbName);
275,071!
3272
    taosArrayDestroy(req->ctb.tagName);
275,076✔
3273
    req->ctb.tagName = NULL;
275,082✔
3274
  } else if (req->type == TSDB_NORMAL_TABLE) {
14,417!
3275
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
14,387!
3276
  }
3277
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
289,499!
3278
}
3279

3280
typedef struct {
3281
  int32_t nReqs;
3282
  union {
3283
    SVCreateTbReq* pReqs;
3284
    SArray*        pArray;
3285
  };
3286
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3287
} SVCreateTbBatchReq;
3288

3289
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3290
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3291
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3292

3293
typedef struct {
3294
  int32_t        code;
3295
  STableMetaRsp* pMeta;
3296
} SVCreateTbRsp, SVUpdateTbRsp;
3297

3298
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3299
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3300
void tFreeSVCreateTbRsp(void* param);
3301

3302
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3303
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3304

3305
typedef struct {
3306
  int32_t nRsps;
3307
  union {
3308
    SVCreateTbRsp* pRsps;
3309
    SArray*        pArray;
3310
  };
3311
} SVCreateTbBatchRsp;
3312

3313
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3314
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3315

3316
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3317
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3318

3319
// TDMT_VND_DROP_TABLE =================
3320
typedef struct {
3321
  char*    name;
3322
  uint64_t suid;  // for tmq in wal format
3323
  int64_t  uid;
3324
  int8_t   igNotExists;
3325
} SVDropTbReq;
3326

3327
typedef struct {
3328
  int32_t code;
3329
} SVDropTbRsp;
3330

3331
typedef struct {
3332
  int32_t nReqs;
3333
  union {
3334
    SVDropTbReq* pReqs;
3335
    SArray*      pArray;
3336
  };
3337
} SVDropTbBatchReq;
3338

3339
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3340
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3341

3342
typedef struct {
3343
  int32_t nRsps;
3344
  union {
3345
    SVDropTbRsp* pRsps;
3346
    SArray*      pArray;
3347
  };
3348
} SVDropTbBatchRsp;
3349

3350
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3351
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3352

3353
// TDMT_VND_ALTER_TABLE =====================
3354
typedef struct SMultiTagUpateVal {
3355
  char*    tagName;
3356
  int32_t  colId;
3357
  int8_t   tagType;
3358
  int8_t   tagFree;
3359
  uint32_t nTagVal;
3360
  uint8_t* pTagVal;
3361
  int8_t   isNull;
3362
  SArray*  pTagArray;
3363
} SMultiTagUpateVal;
3364
typedef struct {
3365
  char*   tbName;
3366
  int8_t  action;
3367
  char*   colName;
3368
  int32_t colId;
3369
  // TSDB_ALTER_TABLE_ADD_COLUMN
3370
  int8_t  type;
3371
  int8_t  flags;
3372
  int32_t bytes;
3373
  // TSDB_ALTER_TABLE_DROP_COLUMN
3374
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3375
  int8_t   colModType;
3376
  int32_t  colModBytes;
3377
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3378
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3379
  int8_t   isNull;
3380
  int8_t   tagType;
3381
  int8_t   tagFree;
3382
  uint32_t nTagVal;
3383
  uint8_t* pTagVal;
3384
  SArray*  pTagArray;
3385
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3386
  int8_t   updateTTL;
3387
  int32_t  newTTL;
3388
  int32_t  newCommentLen;
3389
  char*    newComment;
3390
  int64_t  ctimeMs;    // fill by vnode
3391
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3392
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3393
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3394
} SVAlterTbReq;
3395

3396
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3397
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3398
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3399
void    tfreeMultiTagUpateVal(void* pMultiTag);
3400

3401
typedef struct {
3402
  int32_t        code;
3403
  STableMetaRsp* pMeta;
3404
} SVAlterTbRsp;
3405

3406
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3407
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3408
// ======================
3409

3410
typedef struct {
3411
  SMsgHead head;
3412
  int64_t  uid;
3413
  int32_t  tid;
3414
  int16_t  tversion;
3415
  int16_t  colId;
3416
  int8_t   type;
3417
  int16_t  bytes;
3418
  int32_t  tagValLen;
3419
  int16_t  numOfTags;
3420
  int32_t  schemaLen;
3421
  char     data[];
3422
} SUpdateTagValReq;
3423

3424
typedef struct {
3425
  SMsgHead head;
3426
} SUpdateTagValRsp;
3427

3428
typedef struct {
3429
  SMsgHead head;
3430
} SVShowTablesReq;
3431

3432
typedef struct {
3433
  SMsgHead head;
3434
  int32_t  id;
3435
} SVShowTablesFetchReq;
3436

3437
typedef struct {
3438
  int64_t useconds;
3439
  int8_t  completed;  // all results are returned to client
3440
  int8_t  precision;
3441
  int8_t  compressed;
3442
  int32_t compLen;
3443
  int32_t numOfRows;
3444
  char    data[];
3445
} SVShowTablesFetchRsp;
3446

3447
typedef struct {
3448
  int64_t consumerId;
3449
  int32_t epoch;
3450
  char    cgroup[TSDB_CGROUP_LEN];
3451
} SMqAskEpReq;
3452

3453
typedef struct {
3454
  int32_t key;
3455
  int32_t valueLen;
3456
  void*   value;
3457
} SKv;
3458

3459
typedef struct {
3460
  int64_t tscRid;
3461
  int8_t  connType;
3462
} SClientHbKey;
3463

3464
typedef struct {
3465
  int64_t tid;
3466
  char    status[TSDB_JOB_STATUS_LEN];
3467
} SQuerySubDesc;
3468

3469
typedef struct {
3470
  char     sql[TSDB_SHOW_SQL_LEN];
3471
  uint64_t queryId;
3472
  int64_t  useconds;
3473
  int64_t  stime;  // timestamp precision ms
3474
  int64_t  reqRid;
3475
  bool     stableQuery;
3476
  bool     isSubQuery;
3477
  char     fqdn[TSDB_FQDN_LEN];
3478
  int32_t  subPlanNum;
3479
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3480
} SQueryDesc;
3481

3482
typedef struct {
3483
  uint32_t connId;
3484
  SArray*  queryDesc;  // SArray<SQueryDesc>
3485
} SQueryHbReqBasic;
3486

3487
typedef struct {
3488
  uint32_t connId;
3489
  uint64_t killRid;
3490
  int32_t  totalDnodes;
3491
  int32_t  onlineDnodes;
3492
  int8_t   killConnection;
3493
  int8_t   align[3];
3494
  SEpSet   epSet;
3495
  SArray*  pQnodeList;
3496
} SQueryHbRspBasic;
3497

3498
typedef struct SAppClusterSummary {
3499
  uint64_t numOfInsertsReq;
3500
  uint64_t numOfInsertRows;
3501
  uint64_t insertElapsedTime;
3502
  uint64_t insertBytes;  // submit to tsdb since launched.
3503

3504
  uint64_t fetchBytes;
3505
  uint64_t numOfQueryReq;
3506
  uint64_t queryElapsedTime;
3507
  uint64_t numOfSlowQueries;
3508
  uint64_t totalRequests;
3509
  uint64_t currentRequests;  // the number of SRequestObj
3510
} SAppClusterSummary;
3511

3512
typedef struct {
3513
  int64_t            appId;
3514
  int32_t            pid;
3515
  char               name[TSDB_APP_NAME_LEN];
3516
  int64_t            startTime;
3517
  SAppClusterSummary summary;
3518
} SAppHbReq;
3519

3520
typedef struct {
3521
  SClientHbKey      connKey;
3522
  int64_t           clusterId;
3523
  SAppHbReq         app;
3524
  SQueryHbReqBasic* query;
3525
  SHashObj*         info;  // hash<Skv.key, Skv>
3526
  char              userApp[TSDB_APP_NAME_LEN];
3527
  uint32_t          userIp;
3528
} SClientHbReq;
3529

3530
typedef struct {
3531
  int64_t reqId;
3532
  SArray* reqs;  // SArray<SClientHbReq>
3533
  int64_t ipWhiteList;
3534
} SClientHbBatchReq;
3535

3536
typedef struct {
3537
  SClientHbKey      connKey;
3538
  int32_t           status;
3539
  SQueryHbRspBasic* query;
3540
  SArray*           info;  // Array<Skv>
3541
} SClientHbRsp;
3542

3543
typedef struct {
3544
  int64_t       reqId;
3545
  int64_t       rspId;
3546
  int32_t       svrTimestamp;
3547
  SArray*       rsps;  // SArray<SClientHbRsp>
3548
  SMonitorParas monitorParas;
3549
  int8_t        enableAuditDelete;
3550
} SClientHbBatchRsp;
3551

3552
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
227,987✔
3553

3554
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3555
  void* pIter = taosHashIterate(info, NULL);
509,533✔
3556
  while (pIter != NULL) {
897,931!
3557
    SKv* kv = (SKv*)pIter;
388,320✔
3558
    taosMemoryFreeClear(kv->value);
388,320!
3559
    pIter = taosHashIterate(info, pIter);
388,321✔
3560
  }
3561
}
509,611✔
3562

3563
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
338,899✔
3564
  SQueryDesc* desc = (SQueryDesc*)pDesc;
338,899✔
3565
  if (desc->subDesc) {
338,899✔
3566
    taosArrayDestroy(desc->subDesc);
327,285✔
3567
    desc->subDesc = NULL;
327,287✔
3568
  }
3569
}
338,901✔
3570

3571
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
593,508✔
3572
  SClientHbReq* req = (SClientHbReq*)pReq;
606,345✔
3573
  if (req->query) {
606,345!
3574
    if (req->query->queryDesc) {
579,177!
3575
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
44,647✔
3576
    }
3577
    taosMemoryFreeClear(req->query);
579,177!
3578
  }
3579

3580
  if (req->info) {
606,319!
3581
    tFreeReqKvHash(req->info);
509,533✔
3582
    taosHashCleanup(req->info);
509,611✔
3583
    req->info = NULL;
509,585✔
3584
  }
3585
}
481,132✔
3586

3587
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3588
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3589

3590
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3591
  if (pReq == NULL) return;
54,291!
3592
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
54,291✔
3593
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
54,291✔
3594
  taosMemoryFree(pReq);
54,291!
3595
}
3596

3597
static FORCE_INLINE void tFreeClientKv(void* pKv) {
146,794✔
3598
  SKv* kv = (SKv*)pKv;
146,794✔
3599
  if (kv) {
146,794!
3600
    taosMemoryFreeClear(kv->value);
146,795!
3601
  }
3602
}
146,793✔
3603

3604
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
590,710✔
3605
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
590,710✔
3606
  if (rsp->query) {
590,710✔
3607
    taosArrayDestroy(rsp->query->pQnodeList);
576,507✔
3608
    taosMemoryFreeClear(rsp->query);
576,597!
3609
  }
3610
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
590,853!
3611
}
122,704✔
3612

3613
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3614
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
430,927✔
3615
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
430,927✔
3616
}
431,074✔
3617

3618
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3619
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3620
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3621

3622
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3623
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
746,234!
3624
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
746,234!
3625
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
746,234!
3626
  return 0;
373,117✔
3627
}
3628

3629
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3630
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
697,045!
3631
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
697,042!
3632
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
348,524!
3633
  if (pKv->value == NULL) {
348,538!
3634
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3635
  }
3636
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
348,538!
3637
  return 0;
348,528✔
3638
}
3639

3640
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3641
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,372,302!
3642
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,372,302!
3643
  return 0;
1,186,151✔
3644
}
3645

3646
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3647
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,181,776!
3648
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,181,889!
3649
  return 0;
590,988✔
3650
}
3651

3652
typedef struct {
3653
  int32_t vgId;
3654
  // TODO stas
3655
} SMqReportVgInfo;
3656

3657
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3658
  int32_t tlen = 0;
3659
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3660
  return tlen;
3661
}
3662

3663
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3664
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3665
  return buf;
3666
}
3667

3668
typedef struct {
3669
  int32_t epoch;
3670
  int64_t topicUid;
3671
  char    name[TSDB_TOPIC_FNAME_LEN];
3672
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3673
} SMqTopicInfo;
3674

3675
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3676
  int32_t tlen = 0;
3677
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3678
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3679
  tlen += taosEncodeString(buf, pTopicInfo->name);
3680
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3681
  tlen += taosEncodeFixedI32(buf, sz);
3682
  for (int32_t i = 0; i < sz; i++) {
3683
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3684
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3685
  }
3686
  return tlen;
3687
}
3688

3689
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3690
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3691
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3692
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3693
  int32_t sz;
3694
  buf = taosDecodeFixedI32(buf, &sz);
3695
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3696
    return NULL;
3697
  }
3698
  for (int32_t i = 0; i < sz; i++) {
3699
    SMqReportVgInfo vgInfo;
3700
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3701
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3702
      return NULL;
3703
    }
3704
  }
3705
  return buf;
3706
}
3707

3708
typedef struct {
3709
  int32_t status;  // ask hb endpoint
3710
  int32_t epoch;
3711
  int64_t consumerId;
3712
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3713
} SMqReportReq;
3714

3715
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3716
  int32_t tlen = 0;
3717
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3718
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3719
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3720
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3721
  tlen += taosEncodeFixedI32(buf, sz);
3722
  for (int32_t i = 0; i < sz; i++) {
3723
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3724
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3725
  }
3726
  return tlen;
3727
}
3728

3729
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3730
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3731
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3732
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3733
  int32_t sz;
3734
  buf = taosDecodeFixedI32(buf, &sz);
3735
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3736
    return NULL;
3737
  }
3738
  for (int32_t i = 0; i < sz; i++) {
3739
    SMqTopicInfo topicInfo;
3740
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3741
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3742
      return NULL;
3743
    }
3744
  }
3745
  return buf;
3746
}
3747

3748
typedef struct {
3749
  SMsgHead head;
3750
  int64_t  leftForVer;
3751
  int32_t  vgId;
3752
  int64_t  consumerId;
3753
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3754
} SMqVDeleteReq;
3755

3756
typedef struct {
3757
  int8_t reserved;
3758
} SMqVDeleteRsp;
3759

3760
typedef struct {
3761
  char    name[TSDB_STREAM_FNAME_LEN];
3762
  int8_t  igNotExists;
3763
  int32_t sqlLen;
3764
  char*   sql;
3765
} SMDropStreamReq;
3766

3767
typedef struct {
3768
  int8_t reserved;
3769
} SMDropStreamRsp;
3770

3771
typedef struct {
3772
  SMsgHead head;
3773
  int64_t  resetRelHalt;  // reset related stream task halt status
3774
  int64_t  streamId;
3775
  int32_t  taskId;
3776
} SVDropStreamTaskReq;
3777

3778
typedef struct {
3779
  int8_t reserved;
3780
} SVDropStreamTaskRsp;
3781

3782
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3783
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3784
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3785

3786
typedef struct SVUpdateCheckpointInfoReq {
3787
  SMsgHead head;
3788
  int64_t  streamId;
3789
  int32_t  taskId;
3790
  int64_t  checkpointId;
3791
  int64_t  checkpointVer;
3792
  int64_t  checkpointTs;
3793
  int32_t  transId;
3794
  int64_t  hStreamId;  // add encode/decode
3795
  int64_t  hTaskId;
3796
  int8_t   dropRelHTask;
3797
} SVUpdateCheckpointInfoReq;
3798

3799
typedef struct {
3800
  int64_t leftForVer;
3801
  int32_t vgId;
3802
  int64_t oldConsumerId;
3803
  int64_t newConsumerId;
3804
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3805
  int8_t  subType;
3806
  int8_t  withMeta;
3807
  char*   qmsg;  // SubPlanToString
3808
  int64_t suid;
3809
} SMqRebVgReq;
3810

3811
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3812
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3813

3814
typedef struct {
3815
  char    topic[TSDB_TOPIC_FNAME_LEN];
3816
  int64_t ntbUid;
3817
  SArray* colIdList;  // SArray<int16_t>
3818
} STqCheckInfo;
3819

3820
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3821
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3822
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3823

3824
// tqOffset
3825
enum {
3826
  TMQ_OFFSET__RESET_NONE = -3,
3827
  TMQ_OFFSET__RESET_EARLIEST = -2,
3828
  TMQ_OFFSET__RESET_LATEST = -1,
3829
  TMQ_OFFSET__LOG = 1,
3830
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3831
  TMQ_OFFSET__SNAPSHOT_META = 3,
3832
};
3833

3834
enum {
3835
  WITH_DATA = 0,
3836
  WITH_META = 1,
3837
  ONLY_META = 2,
3838
};
3839

3840
#define TQ_OFFSET_VERSION 1
3841

3842
typedef struct {
3843
  int8_t type;
3844
  union {
3845
    // snapshot
3846
    struct {
3847
      int64_t uid;
3848
      int64_t ts;
3849
      SValue  primaryKey;
3850
    };
3851
    // log
3852
    struct {
3853
      int64_t version;
3854
    };
3855
  };
3856
} STqOffsetVal;
3857

3858
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3859
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
25,148✔
3860
  pOffsetVal->uid = uid;
25,148✔
3861
  pOffsetVal->ts = ts;
25,148✔
3862
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
25,148!
3863
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3864
  }
3865
  pOffsetVal->primaryKey = primaryKey;
25,168✔
3866
}
25,168✔
3867

3868
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3869
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
149✔
3870
  pOffsetVal->uid = uid;
149✔
3871
}
149✔
3872

3873
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3874
  pOffsetVal->type = TMQ_OFFSET__LOG;
271,204✔
3875
  pOffsetVal->version = ver;
271,204✔
3876
}
271,204✔
3877

3878
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3879
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3880
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3881
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3882
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3883
void    tOffsetDestroy(void* pVal);
3884

3885
typedef struct {
3886
  STqOffsetVal val;
3887
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3888
} STqOffset;
3889

3890
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3891
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3892
void    tDeleteSTqOffset(void* val);
3893

3894
typedef struct SMqVgOffset {
3895
  int64_t   consumerId;
3896
  STqOffset offset;
3897
} SMqVgOffset;
3898

3899
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3900
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3901

3902
typedef struct {
3903
  SMsgHead head;
3904
  int64_t  streamId;
3905
  int32_t  taskId;
3906
} SVPauseStreamTaskReq;
3907

3908
typedef struct {
3909
  SMsgHead head;
3910
  int64_t  streamId;
3911
  int32_t  taskId;
3912
  int64_t  chkptId;
3913
} SVResetStreamTaskReq;
3914

3915
typedef struct {
3916
  char   name[TSDB_STREAM_FNAME_LEN];
3917
  int8_t igNotExists;
3918
} SMPauseStreamReq;
3919

3920
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3921
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3922

3923
typedef struct {
3924
  SMsgHead head;
3925
  int32_t  taskId;
3926
  int64_t  streamId;
3927
  int8_t   igUntreated;
3928
} SVResumeStreamTaskReq;
3929

3930
typedef struct {
3931
  int8_t reserved;
3932
} SVResumeStreamTaskRsp;
3933

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

3940
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3941
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3942

3943
typedef struct {
3944
  char   name[TSDB_STREAM_FNAME_LEN];
3945
  int8_t igNotExists;
3946
  int8_t igUntreated;
3947
} SMResetStreamReq;
3948

3949
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
3950
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
3951

3952
typedef struct {
3953
  char    name[TSDB_TABLE_FNAME_LEN];
3954
  char    stb[TSDB_TABLE_FNAME_LEN];
3955
  int8_t  igExists;
3956
  int8_t  intervalUnit;
3957
  int8_t  slidingUnit;
3958
  int8_t  timezone;    // int8_t is not enough, timezone is unit of second
3959
  int32_t dstVgId;  // for stream
3960
  int64_t interval;
3961
  int64_t offset;
3962
  int64_t sliding;
3963
  int64_t maxDelay;
3964
  int64_t watermark;
3965
  int32_t exprLen;        // strlen + 1
3966
  int32_t tagsFilterLen;  // strlen + 1
3967
  int32_t sqlLen;         // strlen + 1
3968
  int32_t astLen;         // strlen + 1
3969
  char*   expr;
3970
  char*   tagsFilter;
3971
  char*   sql;
3972
  char*   ast;
3973
  int64_t deleteMark;
3974
  int64_t lastTs;
3975
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3976
  SArray* pVgroupVerList;
3977
  int8_t  recursiveTsma;
3978
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3979
} SMCreateSmaReq;
3980

3981
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3982
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3983
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3984

3985
typedef struct {
3986
  char   name[TSDB_TABLE_FNAME_LEN];
3987
  int8_t igNotExists;
3988
} SMDropSmaReq;
3989

3990
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3991
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3992

3993
typedef struct {
3994
  char   dbFName[TSDB_DB_FNAME_LEN];
3995
  char   stbName[TSDB_TABLE_NAME_LEN];
3996
  char   colName[TSDB_COL_NAME_LEN];
3997
  char   idxName[TSDB_INDEX_FNAME_LEN];
3998
  int8_t idxType;
3999
} SCreateTagIndexReq;
4000

4001
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4002
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4003

4004
typedef SMDropSmaReq SDropTagIndexReq;
4005

4006
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4007
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4008

4009
typedef struct {
4010
  int8_t         version;       // for compatibility(default 0)
4011
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
4012
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
4013
  int8_t         timezoneInt;   // sma data expired if timezone changes.
4014
  int32_t        dstVgId;
4015
  char           indexName[TSDB_INDEX_NAME_LEN];
4016
  int32_t        exprLen;
4017
  int32_t        tagsFilterLen;
4018
  int64_t        indexUid;
4019
  tb_uid_t       tableUid;  // super/child/common table uid
4020
  tb_uid_t       dstTbUid;  // for dstVgroup
4021
  int64_t        interval;
4022
  int64_t        offset;  // use unit by precision of DB
4023
  int64_t        sliding;
4024
  char*          dstTbName;  // for dstVgroup
4025
  char*          expr;       // sma expression
4026
  char*          tagsFilter;
4027
  SSchemaWrapper schemaRow;  // for dstVgroup
4028
  SSchemaWrapper schemaTag;  // for dstVgroup
4029
} STSma;                     // Time-range-wise SMA
4030

4031
typedef STSma SVCreateTSmaReq;
4032

4033
typedef struct {
4034
  int8_t  type;  // 0 status report, 1 update data
4035
  int64_t indexUid;
4036
  int64_t skey;  // start TS key of interval/sliding window
4037
} STSmaMsg;
4038

4039
typedef struct {
4040
  int64_t indexUid;
4041
  char    indexName[TSDB_INDEX_NAME_LEN];
4042
} SVDropTSmaReq;
4043

4044
typedef struct {
4045
  int tmp;  // TODO: to avoid compile error
4046
} SVCreateTSmaRsp, SVDropTSmaRsp;
4047

4048
#if 0
4049
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4050
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4051
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4052
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4053
#endif
4054

4055
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4056
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4057
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4058
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4059

4060
typedef struct {
4061
  int32_t number;
4062
  STSma*  tSma;
4063
} STSmaWrapper;
4064

4065
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4066
  if (pSma) {
1!
4067
    taosMemoryFreeClear(pSma->dstTbName);
1!
4068
    taosMemoryFreeClear(pSma->expr);
1!
4069
    taosMemoryFreeClear(pSma->tagsFilter);
1!
4070
  }
4071
}
1✔
4072

4073
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4074
  if (pSW) {
×
4075
    if (pSW->tSma) {
×
4076
      if (deepCopy) {
×
4077
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4078
          tDestroyTSma(pSW->tSma + i);
×
4079
        }
4080
      }
4081
      taosMemoryFreeClear(pSW->tSma);
×
4082
    }
4083
  }
4084
}
×
4085

4086
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4087
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4088
  taosMemoryFreeClear(pSW);
×
4089
  return NULL;
×
4090
}
4091

4092
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4093
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4094

4095
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4096
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4097

4098
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4099
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4100
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4101
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4102
  }
4103
  return 0;
×
4104
}
4105

4106
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4107
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4108
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4109
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4110
  }
4111
  return 0;
×
4112
}
4113

4114
typedef struct {
4115
  int idx;
4116
} SMCreateFullTextReq;
4117

4118
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4119
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4120
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4121

4122
typedef struct {
4123
  char   name[TSDB_TABLE_FNAME_LEN];
4124
  int8_t igNotExists;
4125
} SMDropFullTextReq;
4126

4127
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4128
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4129

4130
typedef struct {
4131
  char indexFName[TSDB_INDEX_FNAME_LEN];
4132
} SUserIndexReq;
4133

4134
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4135
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4136

4137
typedef struct {
4138
  char dbFName[TSDB_DB_FNAME_LEN];
4139
  char tblFName[TSDB_TABLE_FNAME_LEN];
4140
  char colName[TSDB_COL_NAME_LEN];
4141
  char indexType[TSDB_INDEX_TYPE_LEN];
4142
  char indexExts[TSDB_INDEX_EXTS_LEN];
4143
} SUserIndexRsp;
4144

4145
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4146
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4147

4148
typedef struct {
4149
  char tbFName[TSDB_TABLE_FNAME_LEN];
4150
} STableIndexReq;
4151

4152
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4153
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4154

4155
typedef struct {
4156
  int8_t  intervalUnit;
4157
  int8_t  slidingUnit;
4158
  int64_t interval;
4159
  int64_t offset;
4160
  int64_t sliding;
4161
  int64_t dstTbUid;
4162
  int32_t dstVgId;
4163
  SEpSet  epSet;
4164
  char*   expr;
4165
} STableIndexInfo;
4166

4167
typedef struct {
4168
  char     tbName[TSDB_TABLE_NAME_LEN];
4169
  char     dbFName[TSDB_DB_FNAME_LEN];
4170
  uint64_t suid;
4171
  int32_t  version;
4172
  int32_t  indexSize;
4173
  SArray*  pIndex;  // STableIndexInfo
4174
} STableIndexRsp;
4175

4176
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4177
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4178
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4179

4180
void tFreeSTableIndexInfo(void* pInfo);
4181

4182
typedef struct {
4183
  int8_t  mqMsgType;
4184
  int32_t code;
4185
  int32_t epoch;
4186
  int64_t consumerId;
4187
  int64_t walsver;
4188
  int64_t walever;
4189
} SMqRspHead;
4190

4191
typedef struct {
4192
  SMsgHead     head;
4193
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4194
  int8_t       withTbName;
4195
  int8_t       useSnapshot;
4196
  int32_t      epoch;
4197
  uint64_t     reqId;
4198
  int64_t      consumerId;
4199
  int64_t      timeout;
4200
  STqOffsetVal reqOffset;
4201
  int8_t       enableReplay;
4202
  int8_t       sourceExcluded;
4203
  int8_t       enableBatchMeta;
4204
} SMqPollReq;
4205

4206
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4207
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4208
void    tDestroySMqPollReq(SMqPollReq* pReq);
4209

4210
typedef struct {
4211
  int32_t vgId;
4212
  int64_t offset;
4213
  SEpSet  epSet;
4214
} SMqSubVgEp;
4215

4216
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4217
  int32_t tlen = 0;
8,904✔
4218
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,904✔
4219
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,904✔
4220
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,904✔
4221
  return tlen;
8,904✔
4222
}
4223

4224
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4225
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,450!
4226
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,450!
4227
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,450✔
4228
  return buf;
4,450✔
4229
}
4230

4231
typedef struct {
4232
  char           topic[TSDB_TOPIC_FNAME_LEN];
4233
  char           db[TSDB_DB_FNAME_LEN];
4234
  SArray*        vgs;  // SArray<SMqSubVgEp>
4235
  SSchemaWrapper schema;
4236
} SMqSubTopicEp;
4237

4238
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4239
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4240
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4241

4242
typedef struct {
4243
  SMqRspHead   head;
4244
  STqOffsetVal rspOffset;
4245
  int16_t      resMsgType;
4246
  int32_t      metaRspLen;
4247
  void*        metaRsp;
4248
} SMqMetaRsp;
4249

4250
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4251
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4252
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4253

4254
#define MQ_DATA_RSP_VERSION 100
4255

4256
typedef struct {
4257
  SMqRspHead   head;
4258
  STqOffsetVal rspOffset;
4259
  STqOffsetVal reqOffset;
4260
  int32_t      blockNum;
4261
  int8_t       withTbName;
4262
  int8_t       withSchema;
4263
  SArray*      blockDataLen;
4264
  SArray*      blockData;
4265
  SArray*      blockTbName;
4266
  SArray*      blockSchema;
4267

4268
  union {
4269
    struct {
4270
      int64_t sleepTime;
4271
    };
4272
    struct {
4273
      int32_t createTableNum;
4274
      SArray* createTableLen;
4275
      SArray* createTableReq;
4276
    };
4277
  };
4278

4279
} SMqDataRsp;
4280

4281
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4282
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4283
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4284

4285
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4286
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4287
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4288

4289
typedef struct SMqBatchMetaRsp {
4290
  SMqRspHead   head;  // not serialize
4291
  STqOffsetVal rspOffset;
4292
  SArray*      batchMetaLen;
4293
  SArray*      batchMetaReq;
4294
  void*        pMetaBuff;    // not serialize
4295
  uint32_t     metaBuffLen;  // not serialize
4296
} SMqBatchMetaRsp;
4297

4298
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4299
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4300
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4301
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4302

4303
typedef struct {
4304
  SMqRspHead head;
4305
  char       cgroup[TSDB_CGROUP_LEN];
4306
  SArray*    topics;  // SArray<SMqSubTopicEp>
4307
} SMqAskEpRsp;
4308

4309
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4310
  int32_t tlen = 0;
16,543✔
4311
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4312
  int32_t sz = taosArrayGetSize(pRsp->topics);
16,543!
4313
  tlen += taosEncodeFixedI32(buf, sz);
16,543✔
4314
  for (int32_t i = 0; i < sz; i++) {
23,773✔
4315
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
7,230✔
4316
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
7,230✔
4317
  }
4318
  return tlen;
16,543✔
4319
}
4320

4321
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4322
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4323
  int32_t sz;
4324
  buf = taosDecodeFixedI32(buf, &sz);
8,390✔
4325
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,390✔
4326
  if (pRsp->topics == NULL) {
8,390!
4327
    return NULL;
×
4328
  }
4329
  for (int32_t i = 0; i < sz; i++) {
12,005✔
4330
    SMqSubTopicEp topicEp;
4331
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,615✔
4332
    if (buf == NULL) {
3,615!
4333
      return NULL;
×
4334
    }
4335
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
7,230!
4336
      return NULL;
×
4337
    }
4338
  }
4339
  return buf;
8,390✔
4340
}
4341

4342
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4343
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
19,188✔
4344
}
19,188✔
4345

4346
typedef struct {
4347
  int32_t      vgId;
4348
  STqOffsetVal offset;
4349
  int64_t      rows;
4350
  int64_t      ever;
4351
} OffsetRows;
4352

4353
typedef struct {
4354
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4355
  SArray* offsetRows;
4356
} TopicOffsetRows;
4357

4358
typedef struct {
4359
  int64_t consumerId;
4360
  int32_t epoch;
4361
  SArray* topics;
4362
  int8_t  pollFlag;
4363
} SMqHbReq;
4364

4365
typedef struct {
4366
  char   topic[TSDB_TOPIC_FNAME_LEN];
4367
  int8_t noPrivilege;
4368
} STopicPrivilege;
4369

4370
typedef struct {
4371
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4372
  int32_t debugFlag;
4373
} SMqHbRsp;
4374

4375
typedef struct {
4376
  SMsgHead head;
4377
  int64_t  consumerId;
4378
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4379
} SMqSeekReq;
4380

4381
#define TD_AUTO_CREATE_TABLE 0x1
4382
typedef struct {
4383
  int64_t       suid;
4384
  int64_t       uid;
4385
  int32_t       sver;
4386
  uint32_t      nData;
4387
  uint8_t*      pData;
4388
  SVCreateTbReq cTbReq;
4389
} SVSubmitBlk;
4390

4391
typedef struct {
4392
  SMsgHead header;
4393
  uint64_t sId;
4394
  uint64_t queryId;
4395
  uint64_t clientId;
4396
  uint64_t taskId;
4397
  uint32_t sqlLen;
4398
  uint32_t phyLen;
4399
  char*    sql;
4400
  char*    msg;
4401
  int8_t   source;
4402
} SVDeleteReq;
4403

4404
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4405
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4406

4407
typedef struct {
4408
  int64_t affectedRows;
4409
} SVDeleteRsp;
4410

4411
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4412
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4413

4414
typedef struct SDeleteRes {
4415
  uint64_t suid;
4416
  SArray*  uidList;
4417
  int64_t  skey;
4418
  int64_t  ekey;
4419
  int64_t  affectedRows;
4420
  char     tableFName[TSDB_TABLE_NAME_LEN];
4421
  char     tsColName[TSDB_COL_NAME_LEN];
4422
  int64_t  ctimeMs;  // fill by vnode
4423
  int8_t   source;
4424
} SDeleteRes;
4425

4426
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4427
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4428

4429
typedef struct {
4430
  // int64_t uid;
4431
  char    tbname[TSDB_TABLE_NAME_LEN];
4432
  int64_t startTs;
4433
  int64_t endTs;
4434
} SSingleDeleteReq;
4435

4436
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4437
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4438

4439
typedef struct {
4440
  int64_t suid;
4441
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4442
  int64_t ctimeMs;     // fill by vnode
4443
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4444
} SBatchDeleteReq;
4445

4446
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4447
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4448
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4449

4450
typedef struct {
4451
  int32_t msgIdx;
4452
  int32_t msgType;
4453
  int32_t msgLen;
4454
  void*   msg;
4455
} SBatchMsg;
4456

4457
typedef struct {
4458
  SMsgHead header;
4459
  SArray*  pMsgs;  // SArray<SBatchMsg>
4460
} SBatchReq;
4461

4462
typedef struct {
4463
  int32_t reqType;
4464
  int32_t msgIdx;
4465
  int32_t msgLen;
4466
  int32_t rspCode;
4467
  void*   msg;
4468
} SBatchRspMsg;
4469

4470
typedef struct {
4471
  SArray* pRsps;  // SArray<SBatchRspMsg>
4472
} SBatchRsp;
4473

4474
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4475
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4476
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
7,039,202✔
4477
  if (NULL == msg) {
7,039,202!
4478
    return;
×
4479
  }
4480
  SBatchMsg* pMsg = (SBatchMsg*)msg;
7,039,202✔
4481
  taosMemoryFree(pMsg->msg);
7,039,202!
4482
}
4483

4484
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4485
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4486

4487
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,480,754✔
4488
  if (NULL == p) {
1,480,754!
4489
    return;
×
4490
  }
4491

4492
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,480,754✔
4493
  taosMemoryFree(pRsp->msg);
1,480,754!
4494
}
4495

4496
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4497
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4498
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4499
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4500
void    tDestroySMqHbReq(SMqHbReq* pReq);
4501

4502
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4503
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4504
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4505

4506
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4507
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4508

4509
#define TD_REQ_FROM_APP               0x0
4510
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4511
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4512
#define SUBMIT_REQ_FROM_FILE          0x4
4513
#define TD_REQ_FROM_TAOX              0x8
4514
#define SUBMIT_REQUEST_VERSION        (1)
4515

4516
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4517

4518
typedef struct {
4519
  int32_t        flags;
4520
  SVCreateTbReq* pCreateTbReq;
4521
  int64_t        suid;
4522
  int64_t        uid;
4523
  int32_t        sver;
4524
  union {
4525
    SArray* aRowP;
4526
    SArray* aCol;
4527
  };
4528
  int64_t ctimeMs;
4529
} SSubmitTbData;
4530

4531
typedef struct {
4532
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4533
} SSubmitReq2;
4534

4535
typedef struct {
4536
  SMsgHead header;
4537
  int64_t  version;
4538
  char     data[];  // SSubmitReq2
4539
} SSubmitReq2Msg;
4540

4541
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4542
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
4543
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4544
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4545

4546
typedef struct {
4547
  int32_t affectedRows;
4548
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4549
} SSubmitRsp2;
4550

4551
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4552
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4553
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4554

4555
#define TSDB_MSG_FLG_ENCODE 0x1
4556
#define TSDB_MSG_FLG_DECODE 0x2
4557
#define TSDB_MSG_FLG_CMPT   0x3
4558

4559
typedef struct {
4560
  union {
4561
    struct {
4562
      void*   msgStr;
4563
      int32_t msgLen;
4564
      int64_t ver;
4565
    };
4566
    void* pDataBlock;
4567
  };
4568
} SPackedData;
4569

4570
typedef struct {
4571
  char     fullname[TSDB_VIEW_FNAME_LEN];
4572
  char     name[TSDB_VIEW_NAME_LEN];
4573
  char     dbFName[TSDB_DB_FNAME_LEN];
4574
  char*    querySql;
4575
  char*    sql;
4576
  int8_t   orReplace;
4577
  int8_t   precision;
4578
  int32_t  numOfCols;
4579
  SSchema* pSchema;
4580
} SCMCreateViewReq;
4581

4582
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4583
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4584
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4585

4586
typedef struct {
4587
  char   fullname[TSDB_VIEW_FNAME_LEN];
4588
  char   name[TSDB_VIEW_NAME_LEN];
4589
  char   dbFName[TSDB_DB_FNAME_LEN];
4590
  char*  sql;
4591
  int8_t igNotExists;
4592
} SCMDropViewReq;
4593

4594
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4595
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4596
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4597

4598
typedef struct {
4599
  char fullname[TSDB_VIEW_FNAME_LEN];
4600
} SViewMetaReq;
4601
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4602
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4603

4604
typedef struct {
4605
  char     name[TSDB_VIEW_NAME_LEN];
4606
  char     dbFName[TSDB_DB_FNAME_LEN];
4607
  char*    user;
4608
  uint64_t dbId;
4609
  uint64_t viewId;
4610
  char*    querySql;
4611
  int8_t   precision;
4612
  int8_t   type;
4613
  int32_t  version;
4614
  int32_t  numOfCols;
4615
  SSchema* pSchema;
4616
} SViewMetaRsp;
4617
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4618
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4619
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4620
typedef struct {
4621
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4622
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4623
} STableTSMAInfoReq;
4624

4625
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4626
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4627

4628
typedef struct {
4629
  int32_t  funcId;
4630
  col_id_t colId;
4631
} STableTSMAFuncInfo;
4632

4633
typedef struct {
4634
  char     name[TSDB_TABLE_NAME_LEN];
4635
  uint64_t tsmaId;
4636
  char     targetTb[TSDB_TABLE_NAME_LEN];
4637
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4638
  char     tb[TSDB_TABLE_NAME_LEN];
4639
  char     dbFName[TSDB_DB_FNAME_LEN];
4640
  uint64_t suid;
4641
  uint64_t destTbUid;
4642
  uint64_t dbId;
4643
  int32_t  version;
4644
  int64_t  interval;
4645
  int8_t   unit;
4646
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4647
  SArray*  pTags;      // SArray<SSchema>
4648
  SArray*  pUsedCols;  // SArray<SSchema>
4649
  char*    ast;
4650

4651
  int64_t streamUid;
4652
  int64_t reqTs;
4653
  int64_t rspTs;
4654
  int64_t delayDuration;  // ms
4655
  bool    fillHistoryFinished;
4656
} STableTSMAInfo;
4657

4658
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4659
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4660
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4661
void    tFreeTableTSMAInfo(void* p);
4662
void    tFreeAndClearTableTSMAInfo(void* p);
4663
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4664

4665
#define STSMAHbRsp            STableTSMAInfoRsp
4666
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4667
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4668
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4669

4670
typedef struct SStreamProgressReq {
4671
  int64_t streamId;
4672
  int32_t vgId;
4673
  int32_t fetchIdx;
4674
  int32_t subFetchIdx;
4675
} SStreamProgressReq;
4676

4677
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4678
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4679

4680
typedef struct SStreamProgressRsp {
4681
  int64_t streamId;
4682
  int32_t vgId;
4683
  bool    fillHisFinished;
4684
  int64_t progressDelay;
4685
  int32_t fetchIdx;
4686
  int32_t subFetchIdx;
4687
} SStreamProgressRsp;
4688

4689
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4690
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4691

4692
typedef struct SDropCtbWithTsmaSingleVgReq {
4693
  SVgroupInfo vgInfo;
4694
  SArray*     pTbs;  // SVDropTbReq
4695
} SMDropTbReqsOnSingleVg;
4696

4697
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4698
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4699
void    tFreeSMDropTbReqOnSingleVg(void* p);
4700

4701
typedef struct SDropTbsReq {
4702
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4703
} SMDropTbsReq;
4704

4705
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4706
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4707
void    tFreeSMDropTbsReq(void*);
4708

4709
typedef struct SVFetchTtlExpiredTbsRsp {
4710
  SArray* pExpiredTbs;  // SVDropTbReq
4711
  int32_t vgId;
4712
} SVFetchTtlExpiredTbsRsp;
4713

4714
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4715
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4716

4717
void tFreeFetchTtlExpiredTbsRsp(void* p);
4718

4719
void setDefaultOptionsForField(SFieldWithOptions* field);
4720
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4721

4722
#pragma pack(pop)
4723

4724
#ifdef __cplusplus
4725
}
4726
#endif
4727

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