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

taosdata / TDengine / #3571

31 Dec 2024 08:57AM UTC coverage: 63.276% (+0.3%) from 62.94%
#3571

push

travis-ci

web-flow
Merge pull request #29434 from taosdata/enh/3.0/TD-33266-2

Fix(cover):fix some review errors in pr 29417.

140094 of 284342 branches covered (49.27%)

Branch coverage included in aggregate %.

217978 of 281543 relevant lines covered (77.42%)

20036556.91 hits per line

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

48.94
/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) {
66,695,313✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
66,695,313✔
74
  int    segIdx = TMSG_SEG_CODE(type);
66,695,313✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
66,695,313!
76
    return type < tMsgRangeDict[segIdx];
66,697,196✔
77
  }
78
  return false;
×
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
6,081,117✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
6,055,918✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
12,137,035!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

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

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

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

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

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

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

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

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

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

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

526
#pragma pack(push, 1)
527

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

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

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

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

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

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

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

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

599
//
600

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

732
  return pDstWrapper;
733
}
734

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

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

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

768
  taosMemoryFreeClear(pWrapper->pColCmpr);
769
  taosMemoryFreeClear(pWrapper);
770
}
771
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
772
  if (pSchemaWrapper->pSchema == NULL) return NULL;
11,545,367!
773

774
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
11,545,367!
775
  if (pSW == NULL) {
11,543,797!
776
    return NULL;
×
777
  }
778
  pSW->nCols = pSchemaWrapper->nCols;
11,543,797✔
779
  pSW->version = pSchemaWrapper->version;
11,543,797✔
780
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
11,543,797!
781
  if (pSW->pSchema == NULL) {
11,542,015!
782
    taosMemoryFree(pSW);
×
783
    return NULL;
×
784
  }
785

786
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
11,542,015✔
787
  return pSW;
11,542,015✔
788
}
789

790
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
472,256✔
791
  if (pSchemaWrapper) {
19,105,574!
792
    taosMemoryFree(pSchemaWrapper->pSchema);
10,607,628!
793
    taosMemoryFree(pSchemaWrapper);
10,607,672!
794
  }
795
}
19,106,242✔
796

797
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,324,212✔
798
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,324,212!
799
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,324,678!
800
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,324,893!
801
  }
802
}
1,324,035✔
803

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

814
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
815
  buf = taosDecodeFixedI8(buf, &pSchema->type);
48,424✔
816
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
24,212✔
817
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
24,212!
818
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
24,212!
819
  buf = taosDecodeStringTo(buf, pSchema->name);
24,212✔
820
  return (void*)buf;
24,212✔
821
}
822

823
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
824
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
367,931,678!
825
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
385,712,104!
826
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
385,712,104!
827
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
385,712,104!
828
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
385,712,104!
829
  return 0;
192,856,052✔
830
}
831

832
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
833
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
698,580,091!
834
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
1,368,734,397!
835
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
1,358,599,424!
836
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
1,377,698,577!
837
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
691,478,312!
838
  return 0;
746,246,668✔
839
}
840

841
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
842
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
216,813,204!
843
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
216,813,204!
844
  return 0;
108,406,602✔
845
}
846

847
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
848
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,401,356!
849
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,401,358!
850
  return 0;
1,700,680✔
851
}
852

853
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
854
  int32_t tlen = 0;
8,824✔
855
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,824✔
856
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,824✔
857
  for (int32_t i = 0; i < pSW->nCols; i++) {
61,210✔
858
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
104,772!
859
  }
860
  return tlen;
8,824✔
861
}
862

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

872
    for (int32_t i = 0; i < pSW->nCols; i++) {
26,912✔
873
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
48,424✔
874
    }
875
  } else {
876
    pSW->pSchema = NULL;
1,424✔
877
  }
878
  return (void*)buf;
4,124✔
879
}
880

881
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
882
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,522,600!
883
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,522,600!
884
  for (int32_t i = 0; i < pSW->nCols; i++) {
18,541,726✔
885
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
35,560,852!
886
  }
887
  return 0;
761,300✔
888
}
889

890
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
891
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,227,367!
892
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,227,157!
893

894
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
613,465✔
895
  if (pSW->pSchema == NULL) {
613,675!
896
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
897
  }
898
  for (int32_t i = 0; i < pSW->nCols; i++) {
9,374,054✔
899
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
17,522,225!
900
  }
901

902
  return 0;
612,208✔
903
}
904

905
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
906
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
77,345,431!
907
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
82,816,578!
908

909
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
41,383,539!
910
  if (pSW->pSchema == NULL) {
41,679,309!
911
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
912
  }
913
  for (int32_t i = 0; i < pSW->nCols; i++) {
776,940,748✔
914
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
1,476,731,119!
915
  }
916

917
  return 0;
35,471,068✔
918
}
919

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1305
typedef STableCfg STableCfgRsp;
1306

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1545
typedef SDbCfgRsp SDbCfgInfo;
1546

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2268
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2269

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2616
typedef struct {
2617
  SArray* updateArray;  // SMArbUpdateGroup
2618
} SMArbUpdateGroupBatchReq;
2619

2620
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2621
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2622
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2623

2624
typedef struct {
2625
  char queryStrId[TSDB_QUERY_ID_LEN];
2626
} SKillQueryReq;
2627

2628
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2629
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2630

2631
typedef struct {
2632
  uint32_t connId;
2633
} SKillConnReq;
2634

2635
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2636
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2637

2638
typedef struct {
2639
  int32_t transId;
2640
} SKillTransReq;
2641

2642
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2643
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2644

2645
typedef struct {
2646
  int32_t useless;  // useless
2647
  int32_t sqlLen;
2648
  char*   sql;
2649
} SBalanceVgroupReq;
2650

2651
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2652
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2653
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2654

2655
typedef struct {
2656
  int32_t vgId1;
2657
  int32_t vgId2;
2658
} SMergeVgroupReq;
2659

2660
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2661
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2662

2663
typedef struct {
2664
  int32_t vgId;
2665
  int32_t dnodeId1;
2666
  int32_t dnodeId2;
2667
  int32_t dnodeId3;
2668
  int32_t sqlLen;
2669
  char*   sql;
2670
} SRedistributeVgroupReq;
2671

2672
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2673
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2674
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2675

2676
typedef struct {
2677
  int32_t reserved;
2678
  int32_t vgId;
2679
  int32_t sqlLen;
2680
  char*   sql;
2681
  char    db[TSDB_DB_FNAME_LEN];
2682
} SBalanceVgroupLeaderReq;
2683

2684
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2685
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2686
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2687

2688
typedef struct {
2689
  int32_t vgId;
2690
} SForceBecomeFollowerReq;
2691

2692
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2693
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2694

2695
typedef struct {
2696
  int32_t vgId;
2697
} SSplitVgroupReq;
2698

2699
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2700
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2701

2702
typedef struct {
2703
  char user[TSDB_USER_LEN];
2704
  char spi;
2705
  char encrypt;
2706
  char secret[TSDB_PASSWORD_LEN];
2707
  char ckey[TSDB_PASSWORD_LEN];
2708
} SAuthReq, SAuthRsp;
2709

2710
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2711
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2712

2713
typedef struct {
2714
  int32_t statusCode;
2715
  char    details[1024];
2716
} SServerStatusRsp;
2717

2718
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2719
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2720

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

2747
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2748
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2749
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2750

2751
typedef struct {
2752
  SMsgHead header;
2753
  uint64_t sId;
2754
  uint64_t queryId;
2755
  uint64_t taskId;
2756
} SSinkDataReq;
2757

2758
typedef struct {
2759
  SMsgHead header;
2760
  uint64_t sId;
2761
  uint64_t queryId;
2762
  uint64_t clientId;
2763
  uint64_t taskId;
2764
  int32_t  execId;
2765
} SQueryContinueReq;
2766

2767
typedef struct {
2768
  SMsgHead header;
2769
  uint64_t sId;
2770
  uint64_t queryId;
2771
  uint64_t taskId;
2772
} SResReadyReq;
2773

2774
typedef struct {
2775
  int32_t code;
2776
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2777
  int32_t sversion;
2778
  int32_t tversion;
2779
} SResReadyRsp;
2780

2781
typedef struct SOperatorParam {
2782
  int32_t opType;
2783
  int32_t downstreamIdx;
2784
  void*   value;
2785
  SArray* pChildren;  // SArray<SOperatorParam*>
2786
} SOperatorParam;
2787

2788
typedef struct STableScanOperatorParam {
2789
  bool    tableSeq;
2790
  SArray* pUidList;
2791
} STableScanOperatorParam;
2792

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

2803
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2804
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2805

2806
typedef struct {
2807
  SMsgHead header;
2808
  uint64_t clientId;
2809
} SSchTasksStatusReq;
2810

2811
typedef struct {
2812
  uint64_t queryId;
2813
  uint64_t clientId;
2814
  uint64_t taskId;
2815
  int64_t  refId;
2816
  int32_t  execId;
2817
  int8_t   status;
2818
} STaskStatus;
2819

2820
typedef struct {
2821
  int64_t refId;
2822
  SArray* taskStatus;  // SArray<STaskStatus>
2823
} SSchedulerStatusRsp;
2824

2825
typedef struct {
2826
  uint64_t queryId;
2827
  uint64_t taskId;
2828
  int8_t   action;
2829
} STaskAction;
2830

2831
typedef struct SQueryNodeEpId {
2832
  int32_t nodeId;  // vgId or qnodeId
2833
  SEp     ep;
2834
} SQueryNodeEpId;
2835

2836
typedef struct {
2837
  SMsgHead       header;
2838
  uint64_t       clientId;
2839
  SQueryNodeEpId epId;
2840
  SArray*        taskAction;  // SArray<STaskAction>
2841
} SSchedulerHbReq;
2842

2843
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2844
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2845
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2846

2847
typedef struct {
2848
  SQueryNodeEpId epId;
2849
  SArray*        taskStatus;  // SArray<STaskStatus>
2850
} SSchedulerHbRsp;
2851

2852
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2853
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2854
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2855

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

2866
typedef struct {
2867
  int32_t code;
2868
} STaskCancelRsp;
2869

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

2880
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2881
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2882

2883
typedef enum {
2884
  TASK_NOTIFY_FINISHED = 1,
2885
} ETaskNotifyType;
2886

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

2898
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2899
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2900

2901
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2902
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2903

2904
typedef struct {
2905
  int32_t code;
2906
} STaskDropRsp;
2907

2908
#define STREAM_TRIGGER_AT_ONCE            1
2909
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2910
#define STREAM_TRIGGER_MAX_DELAY          3
2911
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2912

2913
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2914
#define STREAM_FILL_HISTORY_ON        1
2915
#define STREAM_FILL_HISTORY_OFF       0
2916
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2917
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2918
#define STREAM_CREATE_STABLE_TRUE     1
2919
#define STREAM_CREATE_STABLE_FALSE    0
2920

2921
typedef struct SColLocation {
2922
  int16_t  slotId;
2923
  col_id_t colId;
2924
  int8_t   type;
2925
} SColLocation;
2926

2927
typedef struct SVgroupVer {
2928
  int32_t vgId;
2929
  int64_t ver;
2930
} SVgroupVer;
2931

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

2961
typedef struct {
2962
  int64_t streamId;
2963
} SCMCreateStreamRsp;
2964

2965
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
2966
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
2967
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
2968

2969
enum {
2970
  TOPIC_SUB_TYPE__DB = 1,
2971
  TOPIC_SUB_TYPE__TABLE,
2972
  TOPIC_SUB_TYPE__COLUMN,
2973
};
2974

2975
#define DEFAULT_MAX_POLL_INTERVAL 300000
2976
#define DEFAULT_SESSION_TIMEOUT   12000
2977

2978
typedef struct {
2979
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
2980
  int8_t igExists;
2981
  int8_t subType;
2982
  int8_t withMeta;
2983
  char*  sql;
2984
  char   subDbName[TSDB_DB_FNAME_LEN];
2985
  char*  ast;
2986
  char   subStbName[TSDB_TABLE_FNAME_LEN];
2987
} SCMCreateTopicReq;
2988

2989
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
2990
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
2991
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
2992

2993
typedef struct {
2994
  int64_t consumerId;
2995
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
2996

2997
typedef struct {
2998
  int64_t consumerId;
2999
  char    cgroup[TSDB_CGROUP_LEN];
3000
  char    clientId[TSDB_CLIENT_ID_LEN];
3001
  char    user[TSDB_USER_LEN];
3002
  char    fqdn[TSDB_FQDN_LEN];
3003
  SArray* topicNames;  // SArray<char**>
3004

3005
  int8_t  withTbName;
3006
  int8_t  autoCommit;
3007
  int32_t autoCommitInterval;
3008
  int8_t  resetOffsetCfg;
3009
  int8_t  enableReplay;
3010
  int8_t  enableBatchMeta;
3011
  int32_t sessionTimeoutMs;
3012
  int32_t maxPollIntervalMs;
3013
} SCMSubscribeReq;
3014

3015
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
3016
  int32_t tlen = 0;
2,420✔
3017
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,420!
3018
  tlen += taosEncodeString(buf, pReq->cgroup);
2,420✔
3019
  tlen += taosEncodeString(buf, pReq->clientId);
2,420✔
3020

3021
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,420!
3022
  tlen += taosEncodeFixedI32(buf, topicNum);
2,420✔
3023

3024
  for (int32_t i = 0; i < topicNum; i++) {
3,414✔
3025
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
1,988✔
3026
  }
3027

3028
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,420!
3029
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,420!
3030
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,420!
3031
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,420!
3032
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,420!
3033
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,420!
3034
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,420!
3035
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,420!
3036
  tlen += taosEncodeString(buf, pReq->user);
2,420✔
3037
  tlen += taosEncodeString(buf, pReq->fqdn);
2,420✔
3038

3039
  return tlen;
2,420✔
3040
}
3041

3042
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3043
  void* start = buf;
1,317✔
3044
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,317!
3045
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,317✔
3046
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,317✔
3047

3048
  int32_t topicNum = 0;
1,317!
3049
  buf = taosDecodeFixedI32(buf, &topicNum);
1,317✔
3050

3051
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,317✔
3052
  if (pReq->topicNames == NULL) {
1,317!
3053
    return terrno;
×
3054
  }
3055
  for (int32_t i = 0; i < topicNum; i++) {
1,924✔
3056
    char* name = NULL;
607✔
3057
    buf = taosDecodeString(buf, &name);
607✔
3058
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,214!
3059
      return terrno;
×
3060
    }
3061
  }
3062

3063
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,317✔
3064
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,317✔
3065
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,317!
3066
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,317✔
3067
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,317✔
3068
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,317✔
3069
  if ((char*)buf - (char*)start < len) {
1,317!
3070
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,317!
3071
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,317!
3072
    buf = taosDecodeStringTo(buf, pReq->user);
1,317✔
3073
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,634✔
3074
  } else {
3075
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3076
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3077
  }
3078

3079
  return 0;
1,317✔
3080
}
3081

3082
typedef struct {
3083
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3084
  SArray* removedConsumers;  // SArray<int64_t>
3085
  SArray* newConsumers;      // SArray<int64_t>
3086
} SMqRebInfo;
3087

3088
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3089
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,298!
3090
  if (pRebInfo == NULL) {
1,298!
3091
    return NULL;
×
3092
  }
3093
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,298✔
3094
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,298✔
3095
  if (pRebInfo->removedConsumers == NULL) {
1,298!
3096
    goto _err;
×
3097
  }
3098
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,298✔
3099
  if (pRebInfo->newConsumers == NULL) {
1,298!
3100
    goto _err;
×
3101
  }
3102
  return pRebInfo;
1,298✔
3103
_err:
×
3104
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3105
  taosArrayDestroy(pRebInfo->newConsumers);
×
3106
  taosMemoryFreeClear(pRebInfo);
×
3107
  return NULL;
×
3108
}
3109

3110
typedef struct {
3111
  int64_t streamId;
3112
  int64_t checkpointId;
3113
  char    streamName[TSDB_STREAM_FNAME_LEN];
3114
} SMStreamDoCheckpointMsg;
3115

3116
typedef struct {
3117
  int64_t status;
3118
} SMVSubscribeRsp;
3119

3120
typedef struct {
3121
  char    name[TSDB_TOPIC_FNAME_LEN];
3122
  int8_t  igNotExists;
3123
  int32_t sqlLen;
3124
  char*   sql;
3125
} SMDropTopicReq;
3126

3127
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3128
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3129
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3130

3131
typedef struct {
3132
  char   topic[TSDB_TOPIC_FNAME_LEN];
3133
  char   cgroup[TSDB_CGROUP_LEN];
3134
  int8_t igNotExists;
3135
} SMDropCgroupReq;
3136

3137
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3138
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3139

3140
typedef struct {
3141
  int8_t reserved;
3142
} SMDropCgroupRsp;
3143

3144
typedef struct {
3145
  char    name[TSDB_TABLE_FNAME_LEN];
3146
  int8_t  alterType;
3147
  SSchema schema;
3148
} SAlterTopicReq;
3149

3150
typedef struct {
3151
  SMsgHead head;
3152
  char     name[TSDB_TABLE_FNAME_LEN];
3153
  int64_t  tuid;
3154
  int32_t  sverson;
3155
  int32_t  execLen;
3156
  char*    executor;
3157
  int32_t  sqlLen;
3158
  char*    sql;
3159
} SDCreateTopicReq;
3160

3161
typedef struct {
3162
  SMsgHead head;
3163
  char     name[TSDB_TABLE_FNAME_LEN];
3164
  int64_t  tuid;
3165
} SDDropTopicReq;
3166

3167
typedef struct {
3168
  int64_t maxdelay[2];
3169
  int64_t watermark[2];
3170
  int64_t deleteMark[2];
3171
  int32_t qmsgLen[2];
3172
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3173
} SRSmaParam;
3174

3175
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3176
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3177

3178
// TDMT_VND_CREATE_STB ==============
3179
typedef struct SVCreateStbReq {
3180
  char*           name;
3181
  tb_uid_t        suid;
3182
  int8_t          rollup;
3183
  SSchemaWrapper  schemaRow;
3184
  SSchemaWrapper  schemaTag;
3185
  SRSmaParam      rsmaParam;
3186
  int32_t         alterOriDataLen;
3187
  void*           alterOriData;
3188
  int8_t          source;
3189
  int8_t          colCmpred;
3190
  SColCmprWrapper colCmpr;
3191
} SVCreateStbReq;
3192

3193
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3194
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3195

3196
// TDMT_VND_DROP_STB ==============
3197
typedef struct SVDropStbReq {
3198
  char*    name;
3199
  tb_uid_t suid;
3200
} SVDropStbReq;
3201

3202
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3203
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3204

3205
// TDMT_VND_CREATE_TABLE ==============
3206
#define TD_CREATE_IF_NOT_EXISTS 0x1
3207
typedef struct SVCreateTbReq {
3208
  int32_t  flags;
3209
  char*    name;
3210
  tb_uid_t uid;
3211
  int64_t  btime;
3212
  int32_t  ttl;
3213
  int32_t  commentLen;
3214
  char*    comment;
3215
  int8_t   type;
3216
  union {
3217
    struct {
3218
      char*    stbName;  // super table name
3219
      uint8_t  tagNum;
3220
      tb_uid_t suid;
3221
      SArray*  tagName;
3222
      uint8_t* pTag;
3223
    } ctb;
3224
    struct {
3225
      SSchemaWrapper schemaRow;
3226
    } ntb;
3227
  };
3228
  int32_t         sqlLen;
3229
  char*           sql;
3230
  SColCmprWrapper colCmpr;
3231
} SVCreateTbReq;
3232

3233
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3234
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3235
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3236

3237
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,796✔
3238
  if (NULL == req) {
19,715,302!
3239
    return;
19,430,250✔
3240
  }
3241

3242
  taosMemoryFreeClear(req->sql);
285,052!
3243
  taosMemoryFreeClear(req->name);
285,052!
3244
  taosMemoryFreeClear(req->comment);
285,072!
3245
  if (req->type == TSDB_CHILD_TABLE) {
285,072!
3246
    taosMemoryFreeClear(req->ctb.pTag);
269,293!
3247
    taosMemoryFreeClear(req->ctb.stbName);
269,309!
3248
    taosArrayDestroy(req->ctb.tagName);
269,313✔
3249
    req->ctb.tagName = NULL;
269,329✔
3250
  } else if (req->type == TSDB_NORMAL_TABLE) {
15,781!
3251
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
15,748!
3252
  }
3253
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
285,108!
3254
}
3255

3256
typedef struct {
3257
  int32_t nReqs;
3258
  union {
3259
    SVCreateTbReq* pReqs;
3260
    SArray*        pArray;
3261
  };
3262
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3263
} SVCreateTbBatchReq;
3264

3265
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3266
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3267
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3268

3269
typedef struct {
3270
  int32_t        code;
3271
  STableMetaRsp* pMeta;
3272
} SVCreateTbRsp, SVUpdateTbRsp;
3273

3274
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3275
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3276
void tFreeSVCreateTbRsp(void* param);
3277

3278
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3279
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3280

3281
typedef struct {
3282
  int32_t nRsps;
3283
  union {
3284
    SVCreateTbRsp* pRsps;
3285
    SArray*        pArray;
3286
  };
3287
} SVCreateTbBatchRsp;
3288

3289
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3290
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3291

3292
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3293
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3294

3295
// TDMT_VND_DROP_TABLE =================
3296
typedef struct {
3297
  char*    name;
3298
  uint64_t suid;  // for tmq in wal format
3299
  int64_t  uid;
3300
  int8_t   igNotExists;
3301
} SVDropTbReq;
3302

3303
typedef struct {
3304
  int32_t code;
3305
} SVDropTbRsp;
3306

3307
typedef struct {
3308
  int32_t nReqs;
3309
  union {
3310
    SVDropTbReq* pReqs;
3311
    SArray*      pArray;
3312
  };
3313
} SVDropTbBatchReq;
3314

3315
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3316
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3317

3318
typedef struct {
3319
  int32_t nRsps;
3320
  union {
3321
    SVDropTbRsp* pRsps;
3322
    SArray*      pArray;
3323
  };
3324
} SVDropTbBatchRsp;
3325

3326
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3327
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3328

3329
// TDMT_VND_ALTER_TABLE =====================
3330
typedef struct SMultiTagUpateVal {
3331
  char*    tagName;
3332
  int32_t  colId;
3333
  int8_t   tagType;
3334
  int8_t   tagFree;
3335
  uint32_t nTagVal;
3336
  uint8_t* pTagVal;
3337
  int8_t   isNull;
3338
  SArray*  pTagArray;
3339
} SMultiTagUpateVal;
3340
typedef struct {
3341
  char*   tbName;
3342
  int8_t  action;
3343
  char*   colName;
3344
  int32_t colId;
3345
  // TSDB_ALTER_TABLE_ADD_COLUMN
3346
  int8_t  type;
3347
  int8_t  flags;
3348
  int32_t bytes;
3349
  // TSDB_ALTER_TABLE_DROP_COLUMN
3350
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3351
  int8_t   colModType;
3352
  int32_t  colModBytes;
3353
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3354
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3355
  int8_t   isNull;
3356
  int8_t   tagType;
3357
  int8_t   tagFree;
3358
  uint32_t nTagVal;
3359
  uint8_t* pTagVal;
3360
  SArray*  pTagArray;
3361
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3362
  int8_t   updateTTL;
3363
  int32_t  newTTL;
3364
  int32_t  newCommentLen;
3365
  char*    newComment;
3366
  int64_t  ctimeMs;    // fill by vnode
3367
  int8_t   source;     // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3368
  uint32_t compress;   // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3369
  SArray*  pMultiTag;  // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
3370
} SVAlterTbReq;
3371

3372
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3373
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3374
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3375
void    tfreeMultiTagUpateVal(void* pMultiTag);
3376

3377
typedef struct {
3378
  int32_t        code;
3379
  STableMetaRsp* pMeta;
3380
} SVAlterTbRsp;
3381

3382
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3383
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3384
// ======================
3385

3386
typedef struct {
3387
  SMsgHead head;
3388
  int64_t  uid;
3389
  int32_t  tid;
3390
  int16_t  tversion;
3391
  int16_t  colId;
3392
  int8_t   type;
3393
  int16_t  bytes;
3394
  int32_t  tagValLen;
3395
  int16_t  numOfTags;
3396
  int32_t  schemaLen;
3397
  char     data[];
3398
} SUpdateTagValReq;
3399

3400
typedef struct {
3401
  SMsgHead head;
3402
} SUpdateTagValRsp;
3403

3404
typedef struct {
3405
  SMsgHead head;
3406
} SVShowTablesReq;
3407

3408
typedef struct {
3409
  SMsgHead head;
3410
  int32_t  id;
3411
} SVShowTablesFetchReq;
3412

3413
typedef struct {
3414
  int64_t useconds;
3415
  int8_t  completed;  // all results are returned to client
3416
  int8_t  precision;
3417
  int8_t  compressed;
3418
  int32_t compLen;
3419
  int32_t numOfRows;
3420
  char    data[];
3421
} SVShowTablesFetchRsp;
3422

3423
typedef struct {
3424
  int64_t consumerId;
3425
  int32_t epoch;
3426
  char    cgroup[TSDB_CGROUP_LEN];
3427
} SMqAskEpReq;
3428

3429
typedef struct {
3430
  int32_t key;
3431
  int32_t valueLen;
3432
  void*   value;
3433
} SKv;
3434

3435
typedef struct {
3436
  int64_t tscRid;
3437
  int8_t  connType;
3438
} SClientHbKey;
3439

3440
typedef struct {
3441
  int64_t tid;
3442
  char    status[TSDB_JOB_STATUS_LEN];
3443
} SQuerySubDesc;
3444

3445
typedef struct {
3446
  char     sql[TSDB_SHOW_SQL_LEN];
3447
  uint64_t queryId;
3448
  int64_t  useconds;
3449
  int64_t  stime;  // timestamp precision ms
3450
  int64_t  reqRid;
3451
  bool     stableQuery;
3452
  bool     isSubQuery;
3453
  char     fqdn[TSDB_FQDN_LEN];
3454
  int32_t  subPlanNum;
3455
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3456
} SQueryDesc;
3457

3458
typedef struct {
3459
  uint32_t connId;
3460
  SArray*  queryDesc;  // SArray<SQueryDesc>
3461
} SQueryHbReqBasic;
3462

3463
typedef struct {
3464
  uint32_t connId;
3465
  uint64_t killRid;
3466
  int32_t  totalDnodes;
3467
  int32_t  onlineDnodes;
3468
  int8_t   killConnection;
3469
  int8_t   align[3];
3470
  SEpSet   epSet;
3471
  SArray*  pQnodeList;
3472
} SQueryHbRspBasic;
3473

3474
typedef struct SAppClusterSummary {
3475
  uint64_t numOfInsertsReq;
3476
  uint64_t numOfInsertRows;
3477
  uint64_t insertElapsedTime;
3478
  uint64_t insertBytes;  // submit to tsdb since launched.
3479

3480
  uint64_t fetchBytes;
3481
  uint64_t numOfQueryReq;
3482
  uint64_t queryElapsedTime;
3483
  uint64_t numOfSlowQueries;
3484
  uint64_t totalRequests;
3485
  uint64_t currentRequests;  // the number of SRequestObj
3486
} SAppClusterSummary;
3487

3488
typedef struct {
3489
  int64_t            appId;
3490
  int32_t            pid;
3491
  char               name[TSDB_APP_NAME_LEN];
3492
  int64_t            startTime;
3493
  SAppClusterSummary summary;
3494
} SAppHbReq;
3495

3496
typedef struct {
3497
  SClientHbKey      connKey;
3498
  int64_t           clusterId;
3499
  SAppHbReq         app;
3500
  SQueryHbReqBasic* query;
3501
  SHashObj*         info;  // hash<Skv.key, Skv>
3502
  char              userApp[TSDB_APP_NAME_LEN];
3503
  uint32_t          userIp;
3504
} SClientHbReq;
3505

3506
typedef struct {
3507
  int64_t reqId;
3508
  SArray* reqs;  // SArray<SClientHbReq>
3509
  int64_t ipWhiteList;
3510
} SClientHbBatchReq;
3511

3512
typedef struct {
3513
  SClientHbKey      connKey;
3514
  int32_t           status;
3515
  SQueryHbRspBasic* query;
3516
  SArray*           info;  // Array<Skv>
3517
} SClientHbRsp;
3518

3519
typedef struct {
3520
  int64_t       reqId;
3521
  int64_t       rspId;
3522
  int32_t       svrTimestamp;
3523
  SArray*       rsps;  // SArray<SClientHbRsp>
3524
  SMonitorParas monitorParas;
3525
  int8_t        enableAuditDelete;
3526
} SClientHbBatchRsp;
3527

3528
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
233,165✔
3529

3530
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3531
  void* pIter = taosHashIterate(info, NULL);
565,270✔
3532
  while (pIter != NULL) {
965,632!
3533
    SKv* kv = (SKv*)pIter;
400,333✔
3534
    taosMemoryFreeClear(kv->value);
400,333!
3535
    pIter = taosHashIterate(info, pIter);
400,333✔
3536
  }
3537
}
565,299✔
3538

3539
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
368,751✔
3540
  SQueryDesc* desc = (SQueryDesc*)pDesc;
368,751✔
3541
  if (desc->subDesc) {
368,751✔
3542
    taosArrayDestroy(desc->subDesc);
362,370✔
3543
    desc->subDesc = NULL;
362,367✔
3544
  }
3545
}
368,748✔
3546

3547
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
673,967✔
3548
  SClientHbReq* req = (SClientHbReq*)pReq;
685,031✔
3549
  if (req->query) {
685,031!
3550
    if (req->query->queryDesc) {
664,711!
3551
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
45,183✔
3552
    }
3553
    taosMemoryFreeClear(req->query);
664,711!
3554
  }
3555

3556
  if (req->info) {
685,034!
3557
    tFreeReqKvHash(req->info);
565,270✔
3558
    taosHashCleanup(req->info);
565,299✔
3559
    req->info = NULL;
565,265✔
3560
  }
3561
}
542,382✔
3562

3563
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3564
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3565

3566
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3567
  if (pReq == NULL) return;
41,858!
3568
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
41,858✔
3569
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
41,858✔
3570
  taosMemoryFree(pReq);
41,858!
3571
}
3572

3573
static FORCE_INLINE void tFreeClientKv(void* pKv) {
152,136✔
3574
  SKv* kv = (SKv*)pKv;
152,136✔
3575
  if (kv) {
152,136!
3576
    taosMemoryFreeClear(kv->value);
152,137!
3577
  }
3578
}
152,136✔
3579

3580
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
671,540✔
3581
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
671,540✔
3582
  if (rsp->query) {
671,540✔
3583
    taosArrayDestroy(rsp->query->pQnodeList);
662,394✔
3584
    taosMemoryFreeClear(rsp->query);
662,481!
3585
  }
3586
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
671,641!
3587
}
140,527✔
3588

3589
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3590
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
441,414✔
3591
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
441,414✔
3592
}
441,557✔
3593

3594
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3595
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3596
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3597

3598
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3599
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
737,696!
3600
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
737,696!
3601
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
737,696!
3602
  return 0;
368,848✔
3603
}
3604

3605
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3606
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
736,019!
3607
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
736,023!
3608
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
368,018!
3609
  if (pKv->value == NULL) {
368,027!
3610
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3611
  }
3612
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
368,027!
3613
  return 0;
368,017✔
3614
}
3615

3616
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3617
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,694,330!
3618
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,694,330!
3619
  return 0;
1,347,165✔
3620
}
3621

3622
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3623
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,343,594!
3624
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,343,637!
3625
  return 0;
671,833✔
3626
}
3627

3628
typedef struct {
3629
  int32_t vgId;
3630
  // TODO stas
3631
} SMqReportVgInfo;
3632

3633
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3634
  int32_t tlen = 0;
3635
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3636
  return tlen;
3637
}
3638

3639
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3640
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3641
  return buf;
3642
}
3643

3644
typedef struct {
3645
  int32_t epoch;
3646
  int64_t topicUid;
3647
  char    name[TSDB_TOPIC_FNAME_LEN];
3648
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3649
} SMqTopicInfo;
3650

3651
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3652
  int32_t tlen = 0;
3653
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3654
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3655
  tlen += taosEncodeString(buf, pTopicInfo->name);
3656
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3657
  tlen += taosEncodeFixedI32(buf, sz);
3658
  for (int32_t i = 0; i < sz; i++) {
3659
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3660
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3661
  }
3662
  return tlen;
3663
}
3664

3665
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3666
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3667
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3668
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3669
  int32_t sz;
3670
  buf = taosDecodeFixedI32(buf, &sz);
3671
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3672
    return NULL;
3673
  }
3674
  for (int32_t i = 0; i < sz; i++) {
3675
    SMqReportVgInfo vgInfo;
3676
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3677
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3678
      return NULL;
3679
    }
3680
  }
3681
  return buf;
3682
}
3683

3684
typedef struct {
3685
  int32_t status;  // ask hb endpoint
3686
  int32_t epoch;
3687
  int64_t consumerId;
3688
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3689
} SMqReportReq;
3690

3691
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3692
  int32_t tlen = 0;
3693
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3694
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3695
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3696
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3697
  tlen += taosEncodeFixedI32(buf, sz);
3698
  for (int32_t i = 0; i < sz; i++) {
3699
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3700
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3701
  }
3702
  return tlen;
3703
}
3704

3705
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3706
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3707
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3708
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3709
  int32_t sz;
3710
  buf = taosDecodeFixedI32(buf, &sz);
3711
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3712
    return NULL;
3713
  }
3714
  for (int32_t i = 0; i < sz; i++) {
3715
    SMqTopicInfo topicInfo;
3716
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3717
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3718
      return NULL;
3719
    }
3720
  }
3721
  return buf;
3722
}
3723

3724
typedef struct {
3725
  SMsgHead head;
3726
  int64_t  leftForVer;
3727
  int32_t  vgId;
3728
  int64_t  consumerId;
3729
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3730
} SMqVDeleteReq;
3731

3732
typedef struct {
3733
  int8_t reserved;
3734
} SMqVDeleteRsp;
3735

3736
typedef struct {
3737
  char    name[TSDB_STREAM_FNAME_LEN];
3738
  int8_t  igNotExists;
3739
  int32_t sqlLen;
3740
  char*   sql;
3741
} SMDropStreamReq;
3742

3743
typedef struct {
3744
  int8_t reserved;
3745
} SMDropStreamRsp;
3746

3747
typedef struct {
3748
  SMsgHead head;
3749
  int64_t  resetRelHalt;  // reset related stream task halt status
3750
  int64_t  streamId;
3751
  int32_t  taskId;
3752
} SVDropStreamTaskReq;
3753

3754
typedef struct {
3755
  int8_t reserved;
3756
} SVDropStreamTaskRsp;
3757

3758
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3759
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3760
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3761

3762
typedef struct SVUpdateCheckpointInfoReq {
3763
  SMsgHead head;
3764
  int64_t  streamId;
3765
  int32_t  taskId;
3766
  int64_t  checkpointId;
3767
  int64_t  checkpointVer;
3768
  int64_t  checkpointTs;
3769
  int32_t  transId;
3770
  int64_t  hStreamId;  // add encode/decode
3771
  int64_t  hTaskId;
3772
  int8_t   dropRelHTask;
3773
} SVUpdateCheckpointInfoReq;
3774

3775
typedef struct {
3776
  int64_t leftForVer;
3777
  int32_t vgId;
3778
  int64_t oldConsumerId;
3779
  int64_t newConsumerId;
3780
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3781
  int8_t  subType;
3782
  int8_t  withMeta;
3783
  char*   qmsg;  // SubPlanToString
3784
  int64_t suid;
3785
} SMqRebVgReq;
3786

3787
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3788
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3789

3790
typedef struct {
3791
  char    topic[TSDB_TOPIC_FNAME_LEN];
3792
  int64_t ntbUid;
3793
  SArray* colIdList;  // SArray<int16_t>
3794
} STqCheckInfo;
3795

3796
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3797
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3798
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3799

3800
// tqOffset
3801
enum {
3802
  TMQ_OFFSET__RESET_NONE = -3,
3803
  TMQ_OFFSET__RESET_EARLIEST = -2,
3804
  TMQ_OFFSET__RESET_LATEST = -1,
3805
  TMQ_OFFSET__LOG = 1,
3806
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3807
  TMQ_OFFSET__SNAPSHOT_META = 3,
3808
};
3809

3810
enum {
3811
  WITH_DATA = 0,
3812
  WITH_META = 1,
3813
  ONLY_META = 2,
3814
};
3815

3816
#define TQ_OFFSET_VERSION 1
3817

3818
typedef struct {
3819
  int8_t type;
3820
  union {
3821
    // snapshot
3822
    struct {
3823
      int64_t uid;
3824
      int64_t ts;
3825
      SValue  primaryKey;
3826
    };
3827
    // log
3828
    struct {
3829
      int64_t version;
3830
    };
3831
  };
3832
} STqOffsetVal;
3833

3834
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3835
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
25,104✔
3836
  pOffsetVal->uid = uid;
25,104✔
3837
  pOffsetVal->ts = ts;
25,104✔
3838
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
25,104!
3839
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3840
  }
3841
  pOffsetVal->primaryKey = primaryKey;
25,106✔
3842
}
25,106✔
3843

3844
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3845
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
149✔
3846
  pOffsetVal->uid = uid;
149✔
3847
}
149✔
3848

3849
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3850
  pOffsetVal->type = TMQ_OFFSET__LOG;
522,530✔
3851
  pOffsetVal->version = ver;
522,530✔
3852
}
522,530✔
3853

3854
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3855
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3856
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3857
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3858
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3859
void    tOffsetDestroy(void* pVal);
3860

3861
typedef struct {
3862
  STqOffsetVal val;
3863
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3864
} STqOffset;
3865

3866
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3867
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3868
void    tDeleteSTqOffset(void* val);
3869

3870
typedef struct SMqVgOffset {
3871
  int64_t   consumerId;
3872
  STqOffset offset;
3873
} SMqVgOffset;
3874

3875
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3876
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3877

3878
typedef struct {
3879
  SMsgHead head;
3880
  int64_t  streamId;
3881
  int32_t  taskId;
3882
} SVPauseStreamTaskReq;
3883

3884
typedef struct {
3885
  SMsgHead head;
3886
  int64_t  streamId;
3887
  int32_t  taskId;
3888
  int64_t  chkptId;
3889
} SVResetStreamTaskReq;
3890

3891
typedef struct {
3892
  char   name[TSDB_STREAM_FNAME_LEN];
3893
  int8_t igNotExists;
3894
} SMPauseStreamReq;
3895

3896
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3897
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3898

3899
typedef struct {
3900
  SMsgHead head;
3901
  int32_t  taskId;
3902
  int64_t  streamId;
3903
  int8_t   igUntreated;
3904
} SVResumeStreamTaskReq;
3905

3906
typedef struct {
3907
  int8_t reserved;
3908
} SVResumeStreamTaskRsp;
3909

3910
typedef struct {
3911
  char   name[TSDB_STREAM_FNAME_LEN];
3912
  int8_t igNotExists;
3913
  int8_t igUntreated;
3914
} SMResumeStreamReq;
3915

3916
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3917
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3918

3919
typedef struct {
3920
  char   name[TSDB_STREAM_FNAME_LEN];
3921
  int8_t igNotExists;
3922
  int8_t igUntreated;
3923
} SMResetStreamReq;
3924

3925
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
3926
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
3927

3928
typedef struct {
3929
  char    name[TSDB_TABLE_FNAME_LEN];
3930
  char    stb[TSDB_TABLE_FNAME_LEN];
3931
  int8_t  igExists;
3932
  int8_t  intervalUnit;
3933
  int8_t  slidingUnit;
3934
  int8_t  timezone;    // int8_t is not enough, timezone is unit of second
3935
  int32_t dstVgId;  // for stream
3936
  int64_t interval;
3937
  int64_t offset;
3938
  int64_t sliding;
3939
  int64_t maxDelay;
3940
  int64_t watermark;
3941
  int32_t exprLen;        // strlen + 1
3942
  int32_t tagsFilterLen;  // strlen + 1
3943
  int32_t sqlLen;         // strlen + 1
3944
  int32_t astLen;         // strlen + 1
3945
  char*   expr;
3946
  char*   tagsFilter;
3947
  char*   sql;
3948
  char*   ast;
3949
  int64_t deleteMark;
3950
  int64_t lastTs;
3951
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3952
  SArray* pVgroupVerList;
3953
  int8_t  recursiveTsma;
3954
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3955
} SMCreateSmaReq;
3956

3957
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3958
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3959
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3960

3961
typedef struct {
3962
  char   name[TSDB_TABLE_FNAME_LEN];
3963
  int8_t igNotExists;
3964
} SMDropSmaReq;
3965

3966
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3967
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3968

3969
typedef struct {
3970
  char   dbFName[TSDB_DB_FNAME_LEN];
3971
  char   stbName[TSDB_TABLE_NAME_LEN];
3972
  char   colName[TSDB_COL_NAME_LEN];
3973
  char   idxName[TSDB_INDEX_FNAME_LEN];
3974
  int8_t idxType;
3975
} SCreateTagIndexReq;
3976

3977
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3978
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3979

3980
typedef SMDropSmaReq SDropTagIndexReq;
3981

3982
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3983
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3984

3985
typedef struct {
3986
  int8_t         version;       // for compatibility(default 0)
3987
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
3988
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
3989
  int8_t         timezoneInt;   // sma data expired if timezone changes.
3990
  int32_t        dstVgId;
3991
  char           indexName[TSDB_INDEX_NAME_LEN];
3992
  int32_t        exprLen;
3993
  int32_t        tagsFilterLen;
3994
  int64_t        indexUid;
3995
  tb_uid_t       tableUid;  // super/child/common table uid
3996
  tb_uid_t       dstTbUid;  // for dstVgroup
3997
  int64_t        interval;
3998
  int64_t        offset;  // use unit by precision of DB
3999
  int64_t        sliding;
4000
  char*          dstTbName;  // for dstVgroup
4001
  char*          expr;       // sma expression
4002
  char*          tagsFilter;
4003
  SSchemaWrapper schemaRow;  // for dstVgroup
4004
  SSchemaWrapper schemaTag;  // for dstVgroup
4005
} STSma;                     // Time-range-wise SMA
4006

4007
typedef STSma SVCreateTSmaReq;
4008

4009
typedef struct {
4010
  int8_t  type;  // 0 status report, 1 update data
4011
  int64_t indexUid;
4012
  int64_t skey;  // start TS key of interval/sliding window
4013
} STSmaMsg;
4014

4015
typedef struct {
4016
  int64_t indexUid;
4017
  char    indexName[TSDB_INDEX_NAME_LEN];
4018
} SVDropTSmaReq;
4019

4020
typedef struct {
4021
  int tmp;  // TODO: to avoid compile error
4022
} SVCreateTSmaRsp, SVDropTSmaRsp;
4023

4024
#if 0
4025
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4026
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4027
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4028
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4029
#endif
4030

4031
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4032
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4033
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4034
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4035

4036
typedef struct {
4037
  int32_t number;
4038
  STSma*  tSma;
4039
} STSmaWrapper;
4040

4041
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4042
  if (pSma) {
2!
4043
    taosMemoryFreeClear(pSma->dstTbName);
2!
4044
    taosMemoryFreeClear(pSma->expr);
2!
4045
    taosMemoryFreeClear(pSma->tagsFilter);
2!
4046
  }
4047
}
2✔
4048

4049
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4050
  if (pSW) {
×
4051
    if (pSW->tSma) {
×
4052
      if (deepCopy) {
×
4053
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4054
          tDestroyTSma(pSW->tSma + i);
×
4055
        }
4056
      }
4057
      taosMemoryFreeClear(pSW->tSma);
×
4058
    }
4059
  }
4060
}
×
4061

4062
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4063
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4064
  taosMemoryFreeClear(pSW);
×
4065
  return NULL;
×
4066
}
4067

4068
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4069
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4070

4071
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4072
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4073

4074
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4075
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4076
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4077
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4078
  }
4079
  return 0;
×
4080
}
4081

4082
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4083
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4084
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4085
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4086
  }
4087
  return 0;
×
4088
}
4089

4090
typedef struct {
4091
  int idx;
4092
} SMCreateFullTextReq;
4093

4094
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4095
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4096
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4097

4098
typedef struct {
4099
  char   name[TSDB_TABLE_FNAME_LEN];
4100
  int8_t igNotExists;
4101
} SMDropFullTextReq;
4102

4103
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4104
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4105

4106
typedef struct {
4107
  char indexFName[TSDB_INDEX_FNAME_LEN];
4108
} SUserIndexReq;
4109

4110
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4111
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4112

4113
typedef struct {
4114
  char dbFName[TSDB_DB_FNAME_LEN];
4115
  char tblFName[TSDB_TABLE_FNAME_LEN];
4116
  char colName[TSDB_COL_NAME_LEN];
4117
  char indexType[TSDB_INDEX_TYPE_LEN];
4118
  char indexExts[TSDB_INDEX_EXTS_LEN];
4119
} SUserIndexRsp;
4120

4121
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4122
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4123

4124
typedef struct {
4125
  char tbFName[TSDB_TABLE_FNAME_LEN];
4126
} STableIndexReq;
4127

4128
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4129
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4130

4131
typedef struct {
4132
  int8_t  intervalUnit;
4133
  int8_t  slidingUnit;
4134
  int64_t interval;
4135
  int64_t offset;
4136
  int64_t sliding;
4137
  int64_t dstTbUid;
4138
  int32_t dstVgId;
4139
  SEpSet  epSet;
4140
  char*   expr;
4141
} STableIndexInfo;
4142

4143
typedef struct {
4144
  char     tbName[TSDB_TABLE_NAME_LEN];
4145
  char     dbFName[TSDB_DB_FNAME_LEN];
4146
  uint64_t suid;
4147
  int32_t  version;
4148
  int32_t  indexSize;
4149
  SArray*  pIndex;  // STableIndexInfo
4150
} STableIndexRsp;
4151

4152
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4153
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4154
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4155

4156
void tFreeSTableIndexInfo(void* pInfo);
4157

4158
typedef struct {
4159
  int8_t  mqMsgType;
4160
  int32_t code;
4161
  int32_t epoch;
4162
  int64_t consumerId;
4163
  int64_t walsver;
4164
  int64_t walever;
4165
} SMqRspHead;
4166

4167
typedef struct {
4168
  SMsgHead     head;
4169
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4170
  int8_t       withTbName;
4171
  int8_t       useSnapshot;
4172
  int32_t      epoch;
4173
  uint64_t     reqId;
4174
  int64_t      consumerId;
4175
  int64_t      timeout;
4176
  STqOffsetVal reqOffset;
4177
  int8_t       enableReplay;
4178
  int8_t       sourceExcluded;
4179
  int8_t       enableBatchMeta;
4180
} SMqPollReq;
4181

4182
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4183
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4184
void    tDestroySMqPollReq(SMqPollReq* pReq);
4185

4186
typedef struct {
4187
  int32_t vgId;
4188
  int64_t offset;
4189
  SEpSet  epSet;
4190
} SMqSubVgEp;
4191

4192
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4193
  int32_t tlen = 0;
8,850✔
4194
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,850✔
4195
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,850✔
4196
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,850✔
4197
  return tlen;
8,850✔
4198
}
4199

4200
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4201
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,298!
4202
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,298!
4203
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,298✔
4204
  return buf;
4,298✔
4205
}
4206

4207
typedef struct {
4208
  char           topic[TSDB_TOPIC_FNAME_LEN];
4209
  char           db[TSDB_DB_FNAME_LEN];
4210
  SArray*        vgs;  // SArray<SMqSubVgEp>
4211
  SSchemaWrapper schema;
4212
} SMqSubTopicEp;
4213

4214
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4215
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4216
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4217

4218
typedef struct {
4219
  SMqRspHead   head;
4220
  STqOffsetVal rspOffset;
4221
  int16_t      resMsgType;
4222
  int32_t      metaRspLen;
4223
  void*        metaRsp;
4224
} SMqMetaRsp;
4225

4226
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4227
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4228
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4229

4230
#define MQ_DATA_RSP_VERSION 100
4231

4232
typedef struct {
4233
  SMqRspHead   head;
4234
  STqOffsetVal rspOffset;
4235
  STqOffsetVal reqOffset;
4236
  int32_t      blockNum;
4237
  int8_t       withTbName;
4238
  int8_t       withSchema;
4239
  SArray*      blockDataLen;
4240
  SArray*      blockData;
4241
  SArray*      blockTbName;
4242
  SArray*      blockSchema;
4243

4244
  union {
4245
    struct {
4246
      int64_t sleepTime;
4247
    };
4248
    struct {
4249
      int32_t createTableNum;
4250
      SArray* createTableLen;
4251
      SArray* createTableReq;
4252
    };
4253
  };
4254

4255
} SMqDataRsp;
4256

4257
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4258
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4259
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4260

4261
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4262
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4263
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4264

4265
typedef struct SMqBatchMetaRsp {
4266
  SMqRspHead   head;  // not serialize
4267
  STqOffsetVal rspOffset;
4268
  SArray*      batchMetaLen;
4269
  SArray*      batchMetaReq;
4270
  void*        pMetaBuff;    // not serialize
4271
  uint32_t     metaBuffLen;  // not serialize
4272
} SMqBatchMetaRsp;
4273

4274
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4275
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4276
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4277
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4278

4279
typedef struct {
4280
  SMqRspHead head;
4281
  char       cgroup[TSDB_CGROUP_LEN];
4282
  SArray*    topics;  // SArray<SMqSubTopicEp>
4283
} SMqAskEpRsp;
4284

4285
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4286
  int32_t tlen = 0;
18,448✔
4287
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4288
  int32_t sz = taosArrayGetSize(pRsp->topics);
18,448!
4289
  tlen += taosEncodeFixedI32(buf, sz);
18,448✔
4290
  for (int32_t i = 0; i < sz; i++) {
25,532✔
4291
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
7,084✔
4292
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
7,084✔
4293
  }
4294
  return tlen;
18,448✔
4295
}
4296

4297
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4298
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4299
  int32_t sz;
4300
  buf = taosDecodeFixedI32(buf, &sz);
8,323✔
4301
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,323✔
4302
  if (pRsp->topics == NULL) {
8,323!
4303
    return NULL;
×
4304
  }
4305
  for (int32_t i = 0; i < sz; i++) {
11,755✔
4306
    SMqSubTopicEp topicEp;
4307
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,432✔
4308
    if (buf == NULL) {
3,432!
4309
      return NULL;
×
4310
    }
4311
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,864!
4312
      return NULL;
×
4313
    }
4314
  }
4315
  return buf;
8,323✔
4316
}
4317

4318
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4319
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
20,587✔
4320
}
20,587✔
4321

4322
typedef struct {
4323
  int32_t      vgId;
4324
  STqOffsetVal offset;
4325
  int64_t      rows;
4326
  int64_t      ever;
4327
} OffsetRows;
4328

4329
typedef struct {
4330
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4331
  SArray* offsetRows;
4332
} TopicOffsetRows;
4333

4334
typedef struct {
4335
  int64_t consumerId;
4336
  int32_t epoch;
4337
  SArray* topics;
4338
  int8_t  pollFlag;
4339
} SMqHbReq;
4340

4341
typedef struct {
4342
  char   topic[TSDB_TOPIC_FNAME_LEN];
4343
  int8_t noPrivilege;
4344
} STopicPrivilege;
4345

4346
typedef struct {
4347
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4348
  int32_t debugFlag;
4349
} SMqHbRsp;
4350

4351
typedef struct {
4352
  SMsgHead head;
4353
  int64_t  consumerId;
4354
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4355
} SMqSeekReq;
4356

4357
#define TD_AUTO_CREATE_TABLE 0x1
4358
typedef struct {
4359
  int64_t       suid;
4360
  int64_t       uid;
4361
  int32_t       sver;
4362
  uint32_t      nData;
4363
  uint8_t*      pData;
4364
  SVCreateTbReq cTbReq;
4365
} SVSubmitBlk;
4366

4367
typedef struct {
4368
  SMsgHead header;
4369
  uint64_t sId;
4370
  uint64_t queryId;
4371
  uint64_t clientId;
4372
  uint64_t taskId;
4373
  uint32_t sqlLen;
4374
  uint32_t phyLen;
4375
  char*    sql;
4376
  char*    msg;
4377
  int8_t   source;
4378
} SVDeleteReq;
4379

4380
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4381
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4382

4383
typedef struct {
4384
  int64_t affectedRows;
4385
} SVDeleteRsp;
4386

4387
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4388
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4389

4390
typedef struct SDeleteRes {
4391
  uint64_t suid;
4392
  SArray*  uidList;
4393
  int64_t  skey;
4394
  int64_t  ekey;
4395
  int64_t  affectedRows;
4396
  char     tableFName[TSDB_TABLE_NAME_LEN];
4397
  char     tsColName[TSDB_COL_NAME_LEN];
4398
  int64_t  ctimeMs;  // fill by vnode
4399
  int8_t   source;
4400
} SDeleteRes;
4401

4402
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4403
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4404

4405
typedef struct {
4406
  // int64_t uid;
4407
  char    tbname[TSDB_TABLE_NAME_LEN];
4408
  int64_t startTs;
4409
  int64_t endTs;
4410
} SSingleDeleteReq;
4411

4412
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4413
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4414

4415
typedef struct {
4416
  int64_t suid;
4417
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4418
  int64_t ctimeMs;     // fill by vnode
4419
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4420
} SBatchDeleteReq;
4421

4422
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4423
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4424
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4425

4426
typedef struct {
4427
  int32_t msgIdx;
4428
  int32_t msgType;
4429
  int32_t msgLen;
4430
  void*   msg;
4431
} SBatchMsg;
4432

4433
typedef struct {
4434
  SMsgHead header;
4435
  SArray*  pMsgs;  // SArray<SBatchMsg>
4436
} SBatchReq;
4437

4438
typedef struct {
4439
  int32_t reqType;
4440
  int32_t msgIdx;
4441
  int32_t msgLen;
4442
  int32_t rspCode;
4443
  void*   msg;
4444
} SBatchRspMsg;
4445

4446
typedef struct {
4447
  SArray* pRsps;  // SArray<SBatchRspMsg>
4448
} SBatchRsp;
4449

4450
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4451
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4452
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
7,128,728✔
4453
  if (NULL == msg) {
7,128,728!
4454
    return;
×
4455
  }
4456
  SBatchMsg* pMsg = (SBatchMsg*)msg;
7,128,728✔
4457
  taosMemoryFree(pMsg->msg);
7,128,728!
4458
}
4459

4460
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4461
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4462

4463
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
1,504,087✔
4464
  if (NULL == p) {
1,504,087!
4465
    return;
×
4466
  }
4467

4468
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
1,504,087✔
4469
  taosMemoryFree(pRsp->msg);
1,504,087!
4470
}
4471

4472
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4473
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4474
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4475
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4476
void    tDestroySMqHbReq(SMqHbReq* pReq);
4477

4478
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4479
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4480
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4481

4482
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4483
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4484

4485
#define TD_REQ_FROM_APP               0x0
4486
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4487
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4488
#define SUBMIT_REQ_FROM_FILE          0x4
4489
#define TD_REQ_FROM_TAOX              0x8
4490
#define SUBMIT_REQUEST_VERSION        (1)
4491

4492
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4493

4494
typedef struct {
4495
  int32_t        flags;
4496
  SVCreateTbReq* pCreateTbReq;
4497
  int64_t        suid;
4498
  int64_t        uid;
4499
  int32_t        sver;
4500
  union {
4501
    SArray* aRowP;
4502
    SArray* aCol;
4503
  };
4504
  int64_t ctimeMs;
4505
} SSubmitTbData;
4506

4507
typedef struct {
4508
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4509
} SSubmitReq2;
4510

4511
typedef struct {
4512
  SMsgHead header;
4513
  int64_t  version;
4514
  char     data[];  // SSubmitReq2
4515
} SSubmitReq2Msg;
4516

4517
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4518
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
4519
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4520
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4521

4522
typedef struct {
4523
  int32_t affectedRows;
4524
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4525
} SSubmitRsp2;
4526

4527
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4528
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4529
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4530

4531
#define TSDB_MSG_FLG_ENCODE 0x1
4532
#define TSDB_MSG_FLG_DECODE 0x2
4533
#define TSDB_MSG_FLG_CMPT   0x3
4534

4535
typedef struct {
4536
  union {
4537
    struct {
4538
      void*   msgStr;
4539
      int32_t msgLen;
4540
      int64_t ver;
4541
    };
4542
    void* pDataBlock;
4543
  };
4544
} SPackedData;
4545

4546
typedef struct {
4547
  char     fullname[TSDB_VIEW_FNAME_LEN];
4548
  char     name[TSDB_VIEW_NAME_LEN];
4549
  char     dbFName[TSDB_DB_FNAME_LEN];
4550
  char*    querySql;
4551
  char*    sql;
4552
  int8_t   orReplace;
4553
  int8_t   precision;
4554
  int32_t  numOfCols;
4555
  SSchema* pSchema;
4556
} SCMCreateViewReq;
4557

4558
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4559
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4560
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4561

4562
typedef struct {
4563
  char   fullname[TSDB_VIEW_FNAME_LEN];
4564
  char   name[TSDB_VIEW_NAME_LEN];
4565
  char   dbFName[TSDB_DB_FNAME_LEN];
4566
  char*  sql;
4567
  int8_t igNotExists;
4568
} SCMDropViewReq;
4569

4570
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4571
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4572
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4573

4574
typedef struct {
4575
  char fullname[TSDB_VIEW_FNAME_LEN];
4576
} SViewMetaReq;
4577
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4578
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4579

4580
typedef struct {
4581
  char     name[TSDB_VIEW_NAME_LEN];
4582
  char     dbFName[TSDB_DB_FNAME_LEN];
4583
  char*    user;
4584
  uint64_t dbId;
4585
  uint64_t viewId;
4586
  char*    querySql;
4587
  int8_t   precision;
4588
  int8_t   type;
4589
  int32_t  version;
4590
  int32_t  numOfCols;
4591
  SSchema* pSchema;
4592
} SViewMetaRsp;
4593
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4594
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4595
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4596
typedef struct {
4597
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4598
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4599
} STableTSMAInfoReq;
4600

4601
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4602
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4603

4604
typedef struct {
4605
  int32_t  funcId;
4606
  col_id_t colId;
4607
} STableTSMAFuncInfo;
4608

4609
typedef struct {
4610
  char     name[TSDB_TABLE_NAME_LEN];
4611
  uint64_t tsmaId;
4612
  char     targetTb[TSDB_TABLE_NAME_LEN];
4613
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4614
  char     tb[TSDB_TABLE_NAME_LEN];
4615
  char     dbFName[TSDB_DB_FNAME_LEN];
4616
  uint64_t suid;
4617
  uint64_t destTbUid;
4618
  uint64_t dbId;
4619
  int32_t  version;
4620
  int64_t  interval;
4621
  int8_t   unit;
4622
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4623
  SArray*  pTags;      // SArray<SSchema>
4624
  SArray*  pUsedCols;  // SArray<SSchema>
4625
  char*    ast;
4626

4627
  int64_t streamUid;
4628
  int64_t reqTs;
4629
  int64_t rspTs;
4630
  int64_t delayDuration;  // ms
4631
  bool    fillHistoryFinished;
4632
} STableTSMAInfo;
4633

4634
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4635
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4636
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4637
void    tFreeTableTSMAInfo(void* p);
4638
void    tFreeAndClearTableTSMAInfo(void* p);
4639
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4640

4641
#define STSMAHbRsp            STableTSMAInfoRsp
4642
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4643
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4644
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4645

4646
typedef struct SStreamProgressReq {
4647
  int64_t streamId;
4648
  int32_t vgId;
4649
  int32_t fetchIdx;
4650
  int32_t subFetchIdx;
4651
} SStreamProgressReq;
4652

4653
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4654
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4655

4656
typedef struct SStreamProgressRsp {
4657
  int64_t streamId;
4658
  int32_t vgId;
4659
  bool    fillHisFinished;
4660
  int64_t progressDelay;
4661
  int32_t fetchIdx;
4662
  int32_t subFetchIdx;
4663
} SStreamProgressRsp;
4664

4665
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4666
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4667

4668
typedef struct SDropCtbWithTsmaSingleVgReq {
4669
  SVgroupInfo vgInfo;
4670
  SArray*     pTbs;  // SVDropTbReq
4671
} SMDropTbReqsOnSingleVg;
4672

4673
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4674
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4675
void    tFreeSMDropTbReqOnSingleVg(void* p);
4676

4677
typedef struct SDropTbsReq {
4678
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4679
} SMDropTbsReq;
4680

4681
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4682
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4683
void    tFreeSMDropTbsReq(void*);
4684

4685
typedef struct SVFetchTtlExpiredTbsRsp {
4686
  SArray* pExpiredTbs;  // SVDropTbReq
4687
  int32_t vgId;
4688
} SVFetchTtlExpiredTbsRsp;
4689

4690
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4691
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4692

4693
void tFreeFetchTtlExpiredTbsRsp(void* p);
4694

4695
void setDefaultOptionsForField(SFieldWithOptions* field);
4696
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4697

4698
#pragma pack(pop)
4699

4700
#ifdef __cplusplus
4701
}
4702
#endif
4703

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