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

taosdata / TDengine / #3630

06 Mar 2025 11:35AM UTC coverage: 63.629% (-0.06%) from 63.692%
#3630

push

travis-ci

web-flow
Merge pull request #30042 from taosdata/doc/internal

docs: format

149060 of 300532 branches covered (49.6%)

Branch coverage included in aggregate %.

233739 of 301077 relevant lines covered (77.63%)

17473135.72 hits per line

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

48.57
/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) {
81,747,218✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
81,747,218✔
74
  int    segIdx = TMSG_SEG_CODE(type);
81,747,218✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
81,747,218!
76
    return type < tMsgRangeDict[segIdx];
81,753,762✔
77
  }
78
  return false;
9✔
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
1,644,902✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
1,619,608!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
3,264,510!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
9,424,201✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
9,424,201✔
91
}
92

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

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

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

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

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

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

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

206
#define TSDB_KILL_MSG_LEN 30
207

208
#define TSDB_TABLE_NUM_UNIT 100000
209

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

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

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

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

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

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

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

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

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

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

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

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

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

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

529
#pragma pack(push, 1)
530

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

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

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

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

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

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

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

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

602
//
603

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

735
  return pDstWrapper;
736
}
737

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

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

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

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

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

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

793
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
591,513✔
794
  if (pSchemaWrapper) {
27,151,536!
795
    taosMemoryFree(pSchemaWrapper->pSchema);
10,352,887!
796
    taosMemoryFree(pSchemaWrapper);
10,352,903!
797
  }
798
}
27,150,636✔
799

800
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,386,824✔
801
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,386,824!
802
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,386,940!
803
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,387,243!
804
  }
805
}
1,386,847✔
806

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

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

826
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
827
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
351,856,407!
828
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
371,140,768!
829
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
371,140,768!
830
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
371,140,768!
831
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
371,140,768!
832
  return 0;
185,570,384✔
833
}
834

835
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
836
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
685,089,069!
837
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,343,387,522!
838
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,336,180,048!
839
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,354,003,820!
840
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
678,668,468!
841
  return 0;
731,780,823✔
842
}
843

844
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
845
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
205,863,190!
846
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
205,863,190!
847
  return 0;
102,931,595✔
848
}
849

850
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
851
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,949,432!
852
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,949,430!
853
  return 0;
1,974,712✔
854
}
855

856
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
857
  int32_t tlen = 0;
1,273,070✔
858
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
1,273,070✔
859
  tlen += taosEncodeVariantI32(buf, pSW->version);
1,273,070✔
860
  for (int32_t i = 0; i < pSW->nCols; i++) {
10,993,606✔
861
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
19,441,072!
862
  }
863
  return tlen;
1,273,070✔
864
}
865

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

875
    for (int32_t i = 0; i < pSW->nCols; i++) {
5,263,852✔
876
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
9,716,602✔
877
    }
878
  } else {
879
    pSW->pSchema = NULL;
230,690✔
880
  }
881
  return (void*)buf;
636,241✔
882
}
883

884
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
885
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,465,710!
886
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,465,710!
887
  for (int32_t i = 0; i < pSW->nCols; i++) {
20,017,216✔
888
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
38,568,722!
889
  }
890
  return 0;
732,855✔
891
}
892

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

897
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
1,494,884!
898
  if (pSW->pSchema == NULL) {
1,494,968!
899
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
900
  }
901
  for (int32_t i = 0; i < pSW->nCols; i++) {
18,066,102!
902
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
33,143,352!
903
  }
904

905
  return 0;
1,493,884✔
906
}
907

908
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
909
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
79,000,556!
910
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
80,804,883!
911

912
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
40,383,699!
913
  if (pSW->pSchema == NULL) {
40,656,324!
914
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
915
  }
916
  for (int32_t i = 0; i < pSW->nCols; i++) {
753,319,784✔
917
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,426,026,628!
918
  }
919

920
  return 0;
39,956,616✔
921
}
922

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1310
typedef STableCfg STableCfgRsp;
1311

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1550
typedef SDbCfgRsp SDbCfgInfo;
1551

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2257
typedef struct {
2258
  int32_t useless;  // useless
2259
} SShowVariablesReq;
2260

2261
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2262
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2263

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

2272
typedef struct {
2273
  SArray* variables;  // SArray<SVariablesInfo>
2274
} SShowVariablesRsp;
2275

2276
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2277
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2278

2279
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2280

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

2293
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2294
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2295
void tFreeSShowReq(SShowReq* pReq);
2296

2297
typedef struct {
2298
  int64_t       showId;
2299
  STableMetaRsp tableMeta;
2300
} SShowRsp, SVShowTablesRsp;
2301

2302
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2303
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2304
// void    tFreeSShowRsp(SShowRsp* pRsp);
2305

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

2316
typedef struct SSysTableSchema {
2317
  int8_t   type;
2318
  col_id_t colId;
2319
  int32_t  bytes;
2320
} SSysTableSchema;
2321

2322
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2323
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2324

2325
#define RETRIEVE_TABLE_RSP_VERSION          0
2326
#define RETRIEVE_TABLE_RSP_TMQ_VERSION      1
2327
#define RETRIEVE_TABLE_RSP_TMQ_RAW_VERSION  2
2328

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

2348
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2349

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

2356
typedef struct {
2357
  int64_t version;
2358
  int64_t numOfRows;
2359
  int8_t  compressed;
2360
  int8_t  precision;
2361
  char    data[];
2362
} SRetrieveTableRspForTmq;
2363

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

2376
typedef struct SExplainExecInfo {
2377
  double   startupCost;
2378
  double   totalCost;
2379
  uint64_t numOfRows;
2380
  uint32_t verboseLen;
2381
  void*    verboseInfo;
2382
} SExplainExecInfo;
2383

2384
typedef struct {
2385
  int32_t           numOfPlans;
2386
  SExplainExecInfo* subplanInfo;
2387
} SExplainRsp;
2388

2389
typedef struct {
2390
  SExplainRsp rsp;
2391
  uint64_t    qId;
2392
  uint64_t    cId;
2393
  uint64_t    tId;
2394
  int64_t     rId;
2395
  int32_t     eId;
2396
} SExplainLocalRsp;
2397

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

2410
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2411
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2412
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2413

2414
typedef struct {
2415
  char    config[TSDB_DNODE_CONFIG_LEN];
2416
  char    value[TSDB_CLUSTER_VALUE_LEN];
2417
  int32_t sqlLen;
2418
  char*   sql;
2419
} SMCfgClusterReq;
2420

2421
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2422
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2423
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2424

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

2432
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2433
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2434
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2435

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

2446
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2447
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2448
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2449

2450
enum {
2451
  RESTORE_TYPE__ALL = 1,
2452
  RESTORE_TYPE__MNODE,
2453
  RESTORE_TYPE__VNODE,
2454
  RESTORE_TYPE__QNODE,
2455
};
2456

2457
typedef struct {
2458
  int32_t dnodeId;
2459
  int8_t  restoreType;
2460
  int32_t sqlLen;
2461
  char*   sql;
2462
} SRestoreDnodeReq;
2463

2464
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2465
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2466
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2467

2468
typedef struct {
2469
  int32_t dnodeId;
2470
  char    config[TSDB_DNODE_CONFIG_LEN];
2471
  char    value[TSDB_DNODE_VALUE_LEN];
2472
  int32_t sqlLen;
2473
  char*   sql;
2474
} SMCfgDnodeReq;
2475

2476
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2477
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2478
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2479

2480
typedef struct {
2481
  char    config[TSDB_DNODE_CONFIG_LEN];
2482
  char    value[TSDB_DNODE_VALUE_LEN];
2483
  int32_t version;
2484
} SDCfgDnodeReq;
2485

2486
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2487
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2488

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

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

2508
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2509
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2510

2511
typedef struct {
2512
  int32_t urlLen;
2513
  int32_t sqlLen;
2514
  char*   url;
2515
  char*   sql;
2516
} SMCreateAnodeReq;
2517

2518
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2519
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2520
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2521

2522
typedef struct {
2523
  int32_t anodeId;
2524
  int32_t sqlLen;
2525
  char*   sql;
2526
} SMDropAnodeReq, SMUpdateAnodeReq;
2527

2528
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2529
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2530
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2531
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2532
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2533
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2534

2535
typedef struct {
2536
  int32_t vgId;
2537
  int32_t hbSeq;
2538
} SVArbHbReqMember;
2539

2540
typedef struct {
2541
  int32_t dnodeId;
2542
  char*   arbToken;
2543
  int64_t arbTerm;
2544
  SArray* hbMembers;  // SVArbHbReqMember
2545
} SVArbHeartBeatReq;
2546

2547
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2548
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2549
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2550

2551
typedef struct {
2552
  int32_t vgId;
2553
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2554
  int32_t hbSeq;
2555
} SVArbHbRspMember;
2556

2557
typedef struct {
2558
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2559
  int32_t dnodeId;
2560
  SArray* hbMembers;  // SVArbHbRspMember
2561
} SVArbHeartBeatRsp;
2562

2563
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2564
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2565
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2566

2567
typedef struct {
2568
  char*   arbToken;
2569
  int64_t arbTerm;
2570
  char*   member0Token;
2571
  char*   member1Token;
2572
} SVArbCheckSyncReq;
2573

2574
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2575
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2576
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2577

2578
typedef struct {
2579
  char*   arbToken;
2580
  char*   member0Token;
2581
  char*   member1Token;
2582
  int32_t vgId;
2583
  int32_t errCode;
2584
} SVArbCheckSyncRsp;
2585

2586
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2587
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2588
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2589

2590
typedef struct {
2591
  char*   arbToken;
2592
  int64_t arbTerm;
2593
  char*   memberToken;
2594
  int8_t  force;
2595
} SVArbSetAssignedLeaderReq;
2596

2597
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2598
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2599
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2600

2601
typedef struct {
2602
  char*   arbToken;
2603
  char*   memberToken;
2604
  int32_t vgId;
2605
} SVArbSetAssignedLeaderRsp;
2606

2607
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2608
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2609
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2610

2611
typedef struct {
2612
  int32_t dnodeId;
2613
  char*   token;
2614
} SMArbUpdateGroupMember;
2615

2616
typedef struct {
2617
  int32_t dnodeId;
2618
  char*   token;
2619
  int8_t  acked;
2620
} SMArbUpdateGroupAssigned;
2621

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

2634
typedef struct {
2635
  SArray* updateArray;  // SMArbUpdateGroup
2636
} SMArbUpdateGroupBatchReq;
2637

2638
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2639
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2640
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2641

2642
typedef struct {
2643
  char queryStrId[TSDB_QUERY_ID_LEN];
2644
} SKillQueryReq;
2645

2646
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2647
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2648

2649
typedef struct {
2650
  uint32_t connId;
2651
} SKillConnReq;
2652

2653
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2654
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2655

2656
typedef struct {
2657
  int32_t transId;
2658
} SKillTransReq;
2659

2660
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2661
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2662

2663
typedef struct {
2664
  int32_t useless;  // useless
2665
  int32_t sqlLen;
2666
  char*   sql;
2667
} SBalanceVgroupReq;
2668

2669
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2670
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2671
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2672

2673
typedef struct {
2674
  int32_t useless;  // useless
2675
  int32_t sqlLen;
2676
  char*   sql;
2677
} SAssignLeaderReq;
2678

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

2687
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2688
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2689

2690
typedef struct {
2691
  int32_t vgId;
2692
  int32_t dnodeId1;
2693
  int32_t dnodeId2;
2694
  int32_t dnodeId3;
2695
  int32_t sqlLen;
2696
  char*   sql;
2697
} SRedistributeVgroupReq;
2698

2699
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2700
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2701
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2702

2703
typedef struct {
2704
  int32_t reserved;
2705
  int32_t vgId;
2706
  int32_t sqlLen;
2707
  char*   sql;
2708
  char    db[TSDB_DB_FNAME_LEN];
2709
} SBalanceVgroupLeaderReq;
2710

2711
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2712
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2713
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2714

2715
typedef struct {
2716
  int32_t vgId;
2717
} SForceBecomeFollowerReq;
2718

2719
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2720
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2721

2722
typedef struct {
2723
  int32_t vgId;
2724
} SSplitVgroupReq;
2725

2726
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2727
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2728

2729
typedef struct {
2730
  char user[TSDB_USER_LEN];
2731
  char spi;
2732
  char encrypt;
2733
  char secret[TSDB_PASSWORD_LEN];
2734
  char ckey[TSDB_PASSWORD_LEN];
2735
} SAuthReq, SAuthRsp;
2736

2737
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2738
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2739

2740
typedef struct {
2741
  int32_t statusCode;
2742
  char    details[1024];
2743
} SServerStatusRsp;
2744

2745
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2746
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2747

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

2774
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2775
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2776
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2777

2778
typedef struct {
2779
  SMsgHead header;
2780
  uint64_t sId;
2781
  uint64_t queryId;
2782
  uint64_t taskId;
2783
} SSinkDataReq;
2784

2785
typedef struct {
2786
  SMsgHead header;
2787
  uint64_t sId;
2788
  uint64_t queryId;
2789
  uint64_t clientId;
2790
  uint64_t taskId;
2791
  int32_t  execId;
2792
} SQueryContinueReq;
2793

2794
typedef struct {
2795
  SMsgHead header;
2796
  uint64_t sId;
2797
  uint64_t queryId;
2798
  uint64_t taskId;
2799
} SResReadyReq;
2800

2801
typedef struct {
2802
  int32_t code;
2803
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2804
  int32_t sversion;
2805
  int32_t tversion;
2806
} SResReadyRsp;
2807

2808
typedef struct SOperatorParam {
2809
  int32_t opType;
2810
  int32_t downstreamIdx;
2811
  void*   value;
2812
  SArray* pChildren;  // SArray<SOperatorParam*>
2813
} SOperatorParam;
2814

2815
typedef struct STableScanOperatorParam {
2816
  bool    tableSeq;
2817
  SArray* pUidList;
2818
} STableScanOperatorParam;
2819

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

2830
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2831
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2832

2833
typedef struct {
2834
  SMsgHead header;
2835
  uint64_t clientId;
2836
} SSchTasksStatusReq;
2837

2838
typedef struct {
2839
  uint64_t queryId;
2840
  uint64_t clientId;
2841
  uint64_t taskId;
2842
  int64_t  refId;
2843
  int32_t  execId;
2844
  int8_t   status;
2845
} STaskStatus;
2846

2847
typedef struct {
2848
  int64_t refId;
2849
  SArray* taskStatus;  // SArray<STaskStatus>
2850
} SSchedulerStatusRsp;
2851

2852
typedef struct {
2853
  uint64_t queryId;
2854
  uint64_t taskId;
2855
  int8_t   action;
2856
} STaskAction;
2857

2858
typedef struct SQueryNodeEpId {
2859
  int32_t nodeId;  // vgId or qnodeId
2860
  SEp     ep;
2861
} SQueryNodeEpId;
2862

2863
typedef struct {
2864
  SMsgHead       header;
2865
  uint64_t       clientId;
2866
  SQueryNodeEpId epId;
2867
  SArray*        taskAction;  // SArray<STaskAction>
2868
} SSchedulerHbReq;
2869

2870
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2871
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2872
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2873

2874
typedef struct {
2875
  SQueryNodeEpId epId;
2876
  SArray*        taskStatus;  // SArray<STaskStatus>
2877
} SSchedulerHbRsp;
2878

2879
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2880
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2881
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2882

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

2893
typedef struct {
2894
  int32_t code;
2895
} STaskCancelRsp;
2896

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

2907
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2908
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2909

2910
typedef enum {
2911
  TASK_NOTIFY_FINISHED = 1,
2912
} ETaskNotifyType;
2913

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

2925
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2926
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2927

2928
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2929
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2930

2931
typedef struct {
2932
  int32_t code;
2933
} STaskDropRsp;
2934

2935
#define STREAM_TRIGGER_AT_ONCE            1
2936
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2937
#define STREAM_TRIGGER_MAX_DELAY          3
2938
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2939

2940
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2941
#define STREAM_FILL_HISTORY_ON        1
2942
#define STREAM_FILL_HISTORY_OFF       0
2943
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2944
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2945
#define STREAM_CREATE_STABLE_TRUE     1
2946
#define STREAM_CREATE_STABLE_FALSE    0
2947

2948
typedef struct SColLocation {
2949
  int16_t  slotId;
2950
  col_id_t colId;
2951
  int8_t   type;
2952
} SColLocation;
2953

2954
typedef struct SVgroupVer {
2955
  int32_t vgId;
2956
  int64_t ver;
2957
} SVgroupVer;
2958

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

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

3009
typedef struct {
3010
  int64_t streamId;
3011
} SCMCreateStreamRsp;
3012

3013
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
3014
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
3015
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
3016

3017
enum {
3018
  TOPIC_SUB_TYPE__DB = 1,
3019
  TOPIC_SUB_TYPE__TABLE,
3020
  TOPIC_SUB_TYPE__COLUMN,
3021
};
3022

3023
#define DEFAULT_MAX_POLL_INTERVAL  300000
3024
#define DEFAULT_SESSION_TIMEOUT    12000
3025
#define DEFAULT_MAX_POLL_WAIT_TIME 1000
3026
#define DEFAULT_MIN_POLL_ROWS      4096
3027

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

3039
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
3040
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
3041
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
3042

3043
typedef struct {
3044
  int64_t consumerId;
3045
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
3046

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

3055
  int8_t  withTbName;
3056
  int8_t  autoCommit;
3057
  int32_t autoCommitInterval;
3058
  int8_t  resetOffsetCfg;
3059
  int8_t  enableReplay;
3060
  int8_t  enableBatchMeta;
3061
  int32_t sessionTimeoutMs;
3062
  int32_t maxPollIntervalMs;
3063
} SCMSubscribeReq;
3064

3065
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3066
  int32_t tlen = 0;
2,422✔
3067
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,422!
3068
  tlen += taosEncodeString(buf, pReq->cgroup);
2,422✔
3069
  tlen += taosEncodeString(buf, pReq->clientId);
2,422✔
3070

3071
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,422!
3072
  tlen += taosEncodeFixedI32(buf, topicNum);
2,422✔
3073

3074
  for (int32_t i = 0; i < topicNum; i++) {
3,430✔
3075
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,016✔
3076
  }
3077

3078
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,422!
3079
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,422!
3080
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,422!
3081
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,422!
3082
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,422!
3083
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,422!
3084
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,422!
3085
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,422!
3086
  tlen += taosEncodeString(buf, pReq->user);
2,422✔
3087
  tlen += taosEncodeString(buf, pReq->fqdn);
2,422✔
3088

3089
  return tlen;
2,422✔
3090
}
3091

3092
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3093
  void* start = buf;
1,312✔
3094
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,312!
3095
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,312✔
3096
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,312✔
3097

3098
  int32_t topicNum = 0;
1,312!
3099
  buf = taosDecodeFixedI32(buf, &topicNum);
1,312✔
3100

3101
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,312✔
3102
  if (pReq->topicNames == NULL) {
1,312!
3103
    return terrno;
×
3104
  }
3105
  for (int32_t i = 0; i < topicNum; i++) {
1,920✔
3106
    char* name = NULL;
608✔
3107
    buf = taosDecodeString(buf, &name);
608✔
3108
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,216!
3109
      return terrno;
×
3110
    }
3111
  }
3112

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

3129
  return 0;
1,312✔
3130
}
3131

3132
typedef struct {
3133
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3134
  SArray* removedConsumers;  // SArray<int64_t>
3135
  SArray* newConsumers;      // SArray<int64_t>
3136
} SMqRebInfo;
3137

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

3160
typedef struct {
3161
  int64_t streamId;
3162
  int64_t checkpointId;
3163
  char    streamName[TSDB_STREAM_FNAME_LEN];
3164
} SMStreamDoCheckpointMsg;
3165

3166
typedef struct {
3167
  int64_t status;
3168
} SMVSubscribeRsp;
3169

3170
typedef struct {
3171
  char    name[TSDB_TOPIC_FNAME_LEN];
3172
  int8_t  igNotExists;
3173
  int32_t sqlLen;
3174
  char*   sql;
3175
} SMDropTopicReq;
3176

3177
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3178
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3179
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3180

3181
typedef struct {
3182
  char   topic[TSDB_TOPIC_FNAME_LEN];
3183
  char   cgroup[TSDB_CGROUP_LEN];
3184
  int8_t igNotExists;
3185
} SMDropCgroupReq;
3186

3187
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3188
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3189

3190
typedef struct {
3191
  int8_t reserved;
3192
} SMDropCgroupRsp;
3193

3194
typedef struct {
3195
  char    name[TSDB_TABLE_FNAME_LEN];
3196
  int8_t  alterType;
3197
  SSchema schema;
3198
} SAlterTopicReq;
3199

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

3211
typedef struct {
3212
  SMsgHead head;
3213
  char     name[TSDB_TABLE_FNAME_LEN];
3214
  int64_t  tuid;
3215
} SDDropTopicReq;
3216

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

3225
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3226
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3227

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

3243
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3244
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3245

3246
// TDMT_VND_DROP_STB ==============
3247
typedef struct SVDropStbReq {
3248
  char*    name;
3249
  tb_uid_t suid;
3250
} SVDropStbReq;
3251

3252
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3253
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3254

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

3283
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3284
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3285
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3286

3287
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,705✔
3288
  if (NULL == req) {
4,541,756!
3289
    return;
4,271,228✔
3290
  }
3291

3292
  taosMemoryFreeClear(req->sql);
270,528!
3293
  taosMemoryFreeClear(req->name);
270,528!
3294
  taosMemoryFreeClear(req->comment);
270,534!
3295
  if (req->type == TSDB_CHILD_TABLE) {
270,534!
3296
    taosMemoryFreeClear(req->ctb.pTag);
255,007!
3297
    taosMemoryFreeClear(req->ctb.stbName);
255,015!
3298
    taosArrayDestroy(req->ctb.tagName);
255,016✔
3299
    req->ctb.tagName = NULL;
255,020✔
3300
  } else if (req->type == TSDB_NORMAL_TABLE) {
15,529!
3301
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
15,528!
3302
  }
3303
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
270,547!
3304
}
3305

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

3315
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3316
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3317
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3318

3319
typedef struct {
3320
  int32_t        code;
3321
  STableMetaRsp* pMeta;
3322
} SVCreateTbRsp, SVUpdateTbRsp;
3323

3324
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3325
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3326
void tFreeSVCreateTbRsp(void* param);
3327

3328
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3329
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3330

3331
typedef struct {
3332
  int32_t nRsps;
3333
  union {
3334
    SVCreateTbRsp* pRsps;
3335
    SArray*        pArray;
3336
  };
3337
} SVCreateTbBatchRsp;
3338

3339
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3340
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3341

3342
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3343
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3344

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

3353
typedef struct {
3354
  int32_t code;
3355
} SVDropTbRsp;
3356

3357
typedef struct {
3358
  int32_t nReqs;
3359
  union {
3360
    SVDropTbReq* pReqs;
3361
    SArray*      pArray;
3362
  };
3363
} SVDropTbBatchReq;
3364

3365
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3366
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3367

3368
typedef struct {
3369
  int32_t nRsps;
3370
  union {
3371
    SVDropTbRsp* pRsps;
3372
    SArray*      pArray;
3373
  };
3374
} SVDropTbBatchRsp;
3375

3376
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3377
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3378

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

3422
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3423
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3424
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3425
void    tfreeMultiTagUpateVal(void* pMultiTag);
3426

3427
typedef struct {
3428
  int32_t        code;
3429
  STableMetaRsp* pMeta;
3430
} SVAlterTbRsp;
3431

3432
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3433
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3434
// ======================
3435

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

3450
typedef struct {
3451
  SMsgHead head;
3452
} SUpdateTagValRsp;
3453

3454
typedef struct {
3455
  SMsgHead head;
3456
} SVShowTablesReq;
3457

3458
typedef struct {
3459
  SMsgHead head;
3460
  int32_t  id;
3461
} SVShowTablesFetchReq;
3462

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

3473
typedef struct {
3474
  int64_t consumerId;
3475
  int32_t epoch;
3476
  char    cgroup[TSDB_CGROUP_LEN];
3477
} SMqAskEpReq;
3478

3479
typedef struct {
3480
  int32_t key;
3481
  int32_t valueLen;
3482
  void*   value;
3483
} SKv;
3484

3485
typedef struct {
3486
  int64_t tscRid;
3487
  int8_t  connType;
3488
} SClientHbKey;
3489

3490
typedef struct {
3491
  int64_t tid;
3492
  char    status[TSDB_JOB_STATUS_LEN];
3493
} SQuerySubDesc;
3494

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

3508
typedef struct {
3509
  uint32_t connId;
3510
  SArray*  queryDesc;  // SArray<SQueryDesc>
3511
} SQueryHbReqBasic;
3512

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

3524
typedef struct SAppClusterSummary {
3525
  uint64_t numOfInsertsReq;
3526
  uint64_t numOfInsertRows;
3527
  uint64_t insertElapsedTime;
3528
  uint64_t insertBytes;  // submit to tsdb since launched.
3529

3530
  uint64_t fetchBytes;
3531
  uint64_t numOfQueryReq;
3532
  uint64_t queryElapsedTime;
3533
  uint64_t numOfSlowQueries;
3534
  uint64_t totalRequests;
3535
  uint64_t currentRequests;  // the number of SRequestObj
3536
} SAppClusterSummary;
3537

3538
typedef struct {
3539
  int64_t            appId;
3540
  int32_t            pid;
3541
  char               name[TSDB_APP_NAME_LEN];
3542
  int64_t            startTime;
3543
  SAppClusterSummary summary;
3544
} SAppHbReq;
3545

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

3556
typedef struct {
3557
  int64_t reqId;
3558
  SArray* reqs;  // SArray<SClientHbReq>
3559
  int64_t ipWhiteList;
3560
} SClientHbBatchReq;
3561

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

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

3579
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
205,412✔
3580

3581
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3582
  void* pIter = taosHashIterate(info, NULL);
497,818✔
3583
  while (pIter != NULL) {
880,043!
3584
    SKv* kv = (SKv*)pIter;
382,169✔
3585
    taosMemoryFreeClear(kv->value);
382,169!
3586
    pIter = taosHashIterate(info, pIter);
382,171✔
3587
  }
3588
}
497,874✔
3589

3590
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
337,898✔
3591
  SQueryDesc* desc = (SQueryDesc*)pDesc;
337,898✔
3592
  if (desc->subDesc) {
337,898✔
3593
    taosArrayDestroy(desc->subDesc);
331,978✔
3594
    desc->subDesc = NULL;
331,978✔
3595
  }
3596
}
337,898✔
3597

3598
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
565,570✔
3599
  SClientHbReq* req = (SClientHbReq*)pReq;
580,200✔
3600
  if (req->query) {
580,200!
3601
    if (req->query->queryDesc) {
557,240!
3602
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
41,172✔
3603
    }
3604
    taosMemoryFreeClear(req->query);
557,240!
3605
  }
3606

3607
  if (req->info) {
580,176!
3608
    tFreeReqKvHash(req->info);
497,818✔
3609
    taosHashCleanup(req->info);
497,874✔
3610
    req->info = NULL;
497,853✔
3611
  }
3612
}
478,047✔
3613

3614
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3615
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3616

3617
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3618
  if (pReq == NULL) return;
42,542!
3619
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
42,542✔
3620
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
42,542✔
3621
  taosMemoryFree(pReq);
42,542!
3622
}
3623

3624
static FORCE_INLINE void tFreeClientKv(void* pKv) {
144,357✔
3625
  SKv* kv = (SKv*)pKv;
144,357✔
3626
  if (kv) {
144,357!
3627
    taosMemoryFreeClear(kv->value);
144,357!
3628
  }
3629
}
144,357✔
3630

3631
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
562,091✔
3632
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
562,091✔
3633
  if (rsp->query) {
562,091✔
3634
    taosArrayDestroy(rsp->query->pQnodeList);
553,910✔
3635
    taosMemoryFreeClear(rsp->query);
554,027!
3636
  }
3637
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
562,282!
3638
}
98,999✔
3639

3640
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3641
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
421,118✔
3642
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
421,118✔
3643
}
421,375✔
3644

3645
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3646
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3647
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3648

3649
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3650
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
710,834!
3651
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
710,834!
3652
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
710,834!
3653
  return 0;
355,417✔
3654
}
3655

3656
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3657
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
697,564!
3658
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
697,573!
3659
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
348,797!
3660
  if (pKv->value == NULL) {
348,801!
3661
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3662
  }
3663
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
348,801!
3664
  return 0;
348,794✔
3665
}
3666

3667
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3668
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,260,646!
3669
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,260,646!
3670
  return 0;
1,130,323✔
3671
}
3672

3673
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3674
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,124,593!
3675
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,124,656!
3676
  return 0;
562,346✔
3677
}
3678

3679
typedef struct {
3680
  int32_t vgId;
3681
  // TODO stas
3682
} SMqReportVgInfo;
3683

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

3690
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3691
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3692
  return buf;
3693
}
3694

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

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

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

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

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

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

3775
typedef struct {
3776
  SMsgHead head;
3777
  int64_t  leftForVer;
3778
  int32_t  vgId;
3779
  int64_t  consumerId;
3780
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3781
} SMqVDeleteReq;
3782

3783
typedef struct {
3784
  int8_t reserved;
3785
} SMqVDeleteRsp;
3786

3787
typedef struct {
3788
  char    name[TSDB_STREAM_FNAME_LEN];
3789
  int8_t  igNotExists;
3790
  int32_t sqlLen;
3791
  char*   sql;
3792
} SMDropStreamReq;
3793

3794
typedef struct {
3795
  int8_t reserved;
3796
} SMDropStreamRsp;
3797

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

3805
typedef struct {
3806
  int8_t reserved;
3807
} SVDropStreamTaskRsp;
3808

3809
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3810
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3811
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3812

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

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

3838
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3839
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3840

3841
typedef struct {
3842
  char    topic[TSDB_TOPIC_FNAME_LEN];
3843
  int64_t ntbUid;
3844
  SArray* colIdList;  // SArray<int16_t>
3845
} STqCheckInfo;
3846

3847
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3848
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3849
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3850

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

3861
enum {
3862
  WITH_DATA = 0,
3863
  WITH_META = 1,
3864
  ONLY_META = 2,
3865
};
3866

3867
#define TQ_OFFSET_VERSION 1
3868

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

3885
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3886
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
221,277✔
3887
  pOffsetVal->uid = uid;
221,277✔
3888
  pOffsetVal->ts = ts;
221,277✔
3889
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
221,277!
3890
    taosMemoryFree(pOffsetVal->primaryKey.pData);
1!
3891
  }
3892
  pOffsetVal->primaryKey = primaryKey;
221,283✔
3893
}
221,283✔
3894

3895
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3896
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
143✔
3897
  pOffsetVal->uid = uid;
143✔
3898
}
143✔
3899

3900
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3901
  pOffsetVal->type = TMQ_OFFSET__LOG;
3,516,404✔
3902
  pOffsetVal->version = ver;
3,516,404✔
3903
}
3,516,404✔
3904

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

3912
typedef struct {
3913
  STqOffsetVal val;
3914
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3915
} STqOffset;
3916

3917
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3918
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3919
void    tDeleteSTqOffset(void* val);
3920

3921
typedef struct SMqVgOffset {
3922
  int64_t   consumerId;
3923
  STqOffset offset;
3924
} SMqVgOffset;
3925

3926
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3927
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3928

3929
typedef struct {
3930
  SMsgHead head;
3931
  int64_t  streamId;
3932
  int32_t  taskId;
3933
} SVPauseStreamTaskReq;
3934

3935
typedef struct {
3936
  SMsgHead head;
3937
  int64_t  streamId;
3938
  int32_t  taskId;
3939
  int64_t  chkptId;
3940
} SVResetStreamTaskReq;
3941

3942
typedef struct {
3943
  char   name[TSDB_STREAM_FNAME_LEN];
3944
  int8_t igNotExists;
3945
} SMPauseStreamReq;
3946

3947
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3948
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3949

3950
typedef struct {
3951
  SMsgHead head;
3952
  int32_t  taskId;
3953
  int64_t  streamId;
3954
  int8_t   igUntreated;
3955
} SVResumeStreamTaskReq;
3956

3957
typedef struct {
3958
  int8_t reserved;
3959
} SVResumeStreamTaskRsp;
3960

3961
typedef struct {
3962
  char   name[TSDB_STREAM_FNAME_LEN];
3963
  int8_t igNotExists;
3964
  int8_t igUntreated;
3965
} SMResumeStreamReq;
3966

3967
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3968
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3969

3970
typedef struct {
3971
  char   name[TSDB_STREAM_FNAME_LEN];
3972
  int8_t igNotExists;
3973
  int8_t igUntreated;
3974
} SMResetStreamReq;
3975

3976
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
3977
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
3978

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

4008
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4009
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
4010
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
4011

4012
typedef struct {
4013
  char   name[TSDB_TABLE_FNAME_LEN];
4014
  int8_t igNotExists;
4015
} SMDropSmaReq;
4016

4017
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4018
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4019

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

4028
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4029
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4030

4031
typedef SMDropSmaReq SDropTagIndexReq;
4032

4033
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4034
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4035

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

4058
typedef STSma SVCreateTSmaReq;
4059

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

4066
typedef struct {
4067
  int64_t indexUid;
4068
  char    indexName[TSDB_INDEX_NAME_LEN];
4069
} SVDropTSmaReq;
4070

4071
typedef struct {
4072
  int tmp;  // TODO: to avoid compile error
4073
} SVCreateTSmaRsp, SVDropTSmaRsp;
4074

4075
#if 0
4076
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4077
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4078
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4079
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4080
#endif
4081

4082
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4083
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4084
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4085
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4086

4087
typedef struct {
4088
  int32_t number;
4089
  STSma*  tSma;
4090
} STSmaWrapper;
4091

4092
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4093
  if (pSma) {
2!
4094
    taosMemoryFreeClear(pSma->dstTbName);
2!
4095
    taosMemoryFreeClear(pSma->expr);
2!
4096
    taosMemoryFreeClear(pSma->tagsFilter);
2!
4097
  }
4098
}
2✔
4099

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

4113
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4114
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4115
  taosMemoryFreeClear(pSW);
×
4116
  return NULL;
×
4117
}
4118

4119
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4120
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4121

4122
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4123
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4124

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

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

4141
typedef struct {
4142
  int idx;
4143
} SMCreateFullTextReq;
4144

4145
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4146
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4147
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4148

4149
typedef struct {
4150
  char   name[TSDB_TABLE_FNAME_LEN];
4151
  int8_t igNotExists;
4152
} SMDropFullTextReq;
4153

4154
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4155
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4156

4157
typedef struct {
4158
  char indexFName[TSDB_INDEX_FNAME_LEN];
4159
} SUserIndexReq;
4160

4161
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4162
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4163

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

4172
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4173
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4174

4175
typedef struct {
4176
  char tbFName[TSDB_TABLE_FNAME_LEN];
4177
} STableIndexReq;
4178

4179
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4180
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4181

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

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

4203
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4204
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4205
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4206

4207
void tFreeSTableIndexInfo(void* pInfo);
4208

4209
typedef struct {
4210
  int8_t  mqMsgType;
4211
  int32_t code;
4212
  int32_t epoch;
4213
  int64_t consumerId;
4214
  int64_t walsver;
4215
  int64_t walever;
4216
} SMqRspHead;
4217

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

4236
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4237
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4238
void    tDestroySMqPollReq(SMqPollReq* pReq);
4239

4240
typedef struct {
4241
  int32_t vgId;
4242
  int64_t offset;
4243
  SEpSet  epSet;
4244
} SMqSubVgEp;
4245

4246
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4247
  int32_t tlen = 0;
1,273,058✔
4248
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
1,273,058✔
4249
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
1,273,058✔
4250
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
1,273,058✔
4251
  return tlen;
1,273,058✔
4252
}
4253

4254
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4255
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
636,411!
4256
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
636,411!
4257
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
636,411✔
4258
  return buf;
636,411✔
4259
}
4260

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

4268
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4269
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4270
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4271

4272
typedef struct {
4273
  SMqRspHead   head;
4274
  STqOffsetVal rspOffset;
4275
  int16_t      resMsgType;
4276
  int32_t      metaRspLen;
4277
  void*        metaRsp;
4278
} SMqMetaRsp;
4279

4280
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4281
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4282
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4283

4284
#define MQ_DATA_RSP_VERSION 100
4285

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

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

4315
} SMqDataRsp;
4316

4317
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4318
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4319
int32_t tDecodeMqRawDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4320
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4321
void    tDeleteMqRawDataRsp(SMqDataRsp* pRsp);
4322

4323
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4324
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4325
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4326

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

4336
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4337
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4338
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4339
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4340

4341
typedef struct {
4342
  SMqRspHead head;
4343
  char       cgroup[TSDB_CGROUP_LEN];
4344
  SArray*    topics;  // SArray<SMqSubTopicEp>
4345
} SMqAskEpRsp;
4346

4347
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4348
  int32_t tlen = 0;
1,281,799✔
4349
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4350
  int32_t sz = taosArrayGetSize(pRsp->topics);
1,281,799!
4351
  tlen += taosEncodeFixedI32(buf, sz);
1,281,799✔
4352
  for (int32_t i = 0; i < sz; i++) {
2,553,103✔
4353
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
1,271,304✔
4354
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
1,271,304✔
4355
  }
4356
  return tlen;
1,281,799✔
4357
}
4358

4359
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4360
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4361
  int32_t sz;
4362
  buf = taosDecodeFixedI32(buf, &sz);
640,483✔
4363
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
640,483✔
4364
  if (pRsp->topics == NULL) {
640,483!
4365
    return NULL;
×
4366
  }
4367
  for (int32_t i = 0; i < sz; i++) {
1,276,026✔
4368
    SMqSubTopicEp topicEp;
4369
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
635,543✔
4370
    if (buf == NULL) {
635,543!
4371
      return NULL;
×
4372
    }
4373
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
1,271,086!
4374
      return NULL;
×
4375
    }
4376
  }
4377
  return buf;
640,483✔
4378
}
4379

4380
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4381
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
1,284,437✔
4382
}
1,284,437✔
4383

4384
typedef struct {
4385
  int32_t      vgId;
4386
  STqOffsetVal offset;
4387
  int64_t      rows;
4388
  int64_t      ever;
4389
} OffsetRows;
4390

4391
typedef struct {
4392
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4393
  SArray* offsetRows;
4394
} TopicOffsetRows;
4395

4396
typedef struct {
4397
  int64_t consumerId;
4398
  int32_t epoch;
4399
  SArray* topics;
4400
  int8_t  pollFlag;
4401
} SMqHbReq;
4402

4403
typedef struct {
4404
  char   topic[TSDB_TOPIC_FNAME_LEN];
4405
  int8_t noPrivilege;
4406
} STopicPrivilege;
4407

4408
typedef struct {
4409
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4410
  int32_t debugFlag;
4411
} SMqHbRsp;
4412

4413
typedef struct {
4414
  SMsgHead head;
4415
  int64_t  consumerId;
4416
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4417
} SMqSeekReq;
4418

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

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

4442
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4443
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4444

4445
typedef struct {
4446
  int64_t affectedRows;
4447
} SVDeleteRsp;
4448

4449
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4450
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4451

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

4464
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4465
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4466

4467
typedef struct {
4468
  // int64_t uid;
4469
  char    tbname[TSDB_TABLE_NAME_LEN];
4470
  int64_t startTs;
4471
  int64_t endTs;
4472
} SSingleDeleteReq;
4473

4474
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4475
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4476

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

4484
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4485
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4486
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4487

4488
typedef struct {
4489
  int32_t msgIdx;
4490
  int32_t msgType;
4491
  int32_t msgLen;
4492
  void*   msg;
4493
} SBatchMsg;
4494

4495
typedef struct {
4496
  SMsgHead header;
4497
  SArray*  pMsgs;  // SArray<SBatchMsg>
4498
} SBatchReq;
4499

4500
typedef struct {
4501
  int32_t reqType;
4502
  int32_t msgIdx;
4503
  int32_t msgLen;
4504
  int32_t rspCode;
4505
  void*   msg;
4506
} SBatchRspMsg;
4507

4508
typedef struct {
4509
  SArray* pRsps;  // SArray<SBatchRspMsg>
4510
} SBatchRsp;
4511

4512
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4513
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4514
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
6,811,838✔
4515
  if (NULL == msg) {
6,811,838!
4516
    return;
×
4517
  }
4518
  SBatchMsg* pMsg = (SBatchMsg*)msg;
6,811,838✔
4519
  taosMemoryFree(pMsg->msg);
6,811,838!
4520
}
4521

4522
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4523
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4524

4525
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,477,616✔
4526
  if (NULL == p) {
1,477,616!
4527
    return;
×
4528
  }
4529

4530
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,477,616✔
4531
  taosMemoryFree(pRsp->msg);
1,477,616!
4532
}
4533

4534
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4535
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4536
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4537
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4538
void    tDestroySMqHbReq(SMqHbReq* pReq);
4539

4540
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4541
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4542
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4543

4544
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4545
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4546

4547
#define TD_REQ_FROM_APP               0x0
4548
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4549
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4550
#define SUBMIT_REQ_FROM_FILE          0x4
4551
#define TD_REQ_FROM_TAOX              0x8
4552
#define SUBMIT_REQUEST_VERSION        (1)
4553

4554
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4555

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

4569
typedef struct {
4570
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4571
  bool    raw;
4572
} SSubmitReq2;
4573

4574
typedef struct {
4575
  SMsgHead header;
4576
  int64_t  version;
4577
  char     data[];  // SSubmitReq2
4578
} SSubmitReq2Msg;
4579

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

4586
typedef struct {
4587
  int32_t affectedRows;
4588
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4589
} SSubmitRsp2;
4590

4591
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4592
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4593
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4594

4595
#define TSDB_MSG_FLG_ENCODE 0x1
4596
#define TSDB_MSG_FLG_DECODE 0x2
4597
#define TSDB_MSG_FLG_CMPT   0x3
4598

4599
typedef struct {
4600
  union {
4601
    struct {
4602
      void*   msgStr;
4603
      int32_t msgLen;
4604
      int64_t ver;
4605
    };
4606
    void* pDataBlock;
4607
  };
4608
} SPackedData;
4609

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

4622
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4623
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4624
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4625

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

4634
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4635
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4636
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4637

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

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

4665
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4666
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4667

4668
typedef struct {
4669
  int32_t  funcId;
4670
  col_id_t colId;
4671
} STableTSMAFuncInfo;
4672

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

4691
  int64_t streamUid;
4692
  int64_t reqTs;
4693
  int64_t rspTs;
4694
  int64_t delayDuration;  // ms
4695
  bool    fillHistoryFinished;
4696
} STableTSMAInfo;
4697

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

4705
#define STSMAHbRsp            STableTSMAInfoRsp
4706
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4707
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4708
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4709

4710
typedef struct SStreamProgressReq {
4711
  int64_t streamId;
4712
  int32_t vgId;
4713
  int32_t fetchIdx;
4714
  int32_t subFetchIdx;
4715
} SStreamProgressReq;
4716

4717
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4718
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4719

4720
typedef struct SStreamProgressRsp {
4721
  int64_t streamId;
4722
  int32_t vgId;
4723
  bool    fillHisFinished;
4724
  int64_t progressDelay;
4725
  int32_t fetchIdx;
4726
  int32_t subFetchIdx;
4727
} SStreamProgressRsp;
4728

4729
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4730
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4731

4732
typedef struct SDropCtbWithTsmaSingleVgReq {
4733
  SVgroupInfo vgInfo;
4734
  SArray*     pTbs;  // SVDropTbReq
4735
} SMDropTbReqsOnSingleVg;
4736

4737
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4738
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4739
void    tFreeSMDropTbReqOnSingleVg(void* p);
4740

4741
typedef struct SDropTbsReq {
4742
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4743
} SMDropTbsReq;
4744

4745
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4746
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4747
void    tFreeSMDropTbsReq(void*);
4748

4749
typedef struct SVFetchTtlExpiredTbsRsp {
4750
  SArray* pExpiredTbs;  // SVDropTbReq
4751
  int32_t vgId;
4752
} SVFetchTtlExpiredTbsRsp;
4753

4754
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4755
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4756

4757
void tFreeFetchTtlExpiredTbsRsp(void* p);
4758

4759
void setDefaultOptionsForField(SFieldWithOptions* field);
4760
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4761

4762
#pragma pack(pop)
4763

4764
#ifdef __cplusplus
4765
}
4766
#endif
4767

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