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

taosdata / TDengine / #3654

14 Mar 2025 08:10AM UTC coverage: 36.951% (+14.4%) from 22.565%
#3654

push

travis-ci

web-flow
feat(keep): support keep on super table level. (#30097)

* Feat: support use keep while create super table.

* Test(keep): add test for create super table with keep option.

* Feat(keep): Add tmsg for create keep.

* Feat(keep): support alter table option keep.

* Fix(keep): Add baisc test for alter table option.

* Fix(keep): memory leek.

* Feat(keep): add keep to metaEntry&metaCache and fix earliestTs with stn keep.

* Test(keep): add some cases for select with stb keep.

* Fix: fix ci core while alter stb.

* Feat(keep): delete expired data in super table level.

* Feat: remove get stb keep while query.

* Fix : build error.

* Revert "Fix : build error."

This reverts commit 0ed66e4e8.

* Revert "Feat(keep): delete expired data in super table level."

This reverts commit 36330f6b4.

* Fix : build errors.

* Feat : support restart taosd.

* Fix : alter table comment problems.

* Test : add tests for super table keep.

* Fix: change sdb stb reserve size.

* Test: add more tests.

* Feat: Disable normal tables and sub tables from setting the keep parameter

* Fix: add more checks to avoid unknown address.

* Docs: Add docs for stable keep.

* Fix: some review changes.

* Fix: review errors.

83566 of 302527 branches covered (27.62%)

Branch coverage included in aggregate %.

54 of 99 new or added lines in 12 files covered. (54.55%)

5128 existing lines in 33 files now uncovered.

140127 of 302857 relevant lines covered (46.27%)

678538.13 hits per line

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

37.17
/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) {
3,008,280✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
3,008,280✔
74
  int    segIdx = TMSG_SEG_CODE(type);
3,008,280✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
3,008,280!
76
    return type < tMsgRangeDict[segIdx];
3,008,398✔
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) {
680,167✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
677,201!
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
1,357,368!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

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

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

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

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

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

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

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

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

206
#define TSDB_KILL_MSG_LEN 30
207

208
#define TSDB_TABLE_NUM_UNIT 100000
209

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

601
//
602

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

734
  return pDstWrapper;
735
}
736

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

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

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

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

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

788
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
27,006✔
789
  return pSW;
27,006✔
790
}
791

792
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
366✔
793
  if (pSchemaWrapper) {
69,950!
794
    taosMemoryFree(pSchemaWrapper->pSchema);
31,459!
795
    taosMemoryFree(pSchemaWrapper);
31,457!
796
  }
797
}
69,949✔
798

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

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

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

825
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
826
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
102,397!
827
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
193,106!
828
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
193,106!
829
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
193,106!
830
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
193,106!
831
  return 0;
96,553✔
832
}
833

834
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
835
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
366,392!
836
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
655,535!
837
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
655,424!
838
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
655,390!
839
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
327,706!
840
  return 0;
327,728✔
841
}
842

843
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
844
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
9,088!
845
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
9,088!
846
  return 0;
4,544✔
847
}
848

849
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
850
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
74,642!
851
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
74,642!
852
  return 0;
37,321✔
853
}
854

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

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

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

883
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
884
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
26,592!
885
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
26,592!
886
  for (int32_t i = 0; i < pSW->nCols; i++) {
104,005!
887
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
181,418!
888
  }
889
  return 0;
13,296✔
890
}
891

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

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

904
  return 0;
189✔
905
}
906

907
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
908
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
360,121!
909
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
360,126!
910

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

919
  return 0;
180,079✔
920
}
921

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1311
typedef STableCfg STableCfgRsp;
1312

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1551
typedef SDbCfgRsp SDbCfgInfo;
1552

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2283
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2284

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2883
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2884
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2885
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
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
} STaskCancelReq;
2896

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3075
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
40!
3076
  tlen += taosEncodeFixedI32(buf, topicNum);
40✔
3077

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

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

3093
  return tlen;
40✔
3094
}
3095

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

3102
  int32_t topicNum = 0;
18!
3103
  buf = taosDecodeFixedI32(buf, &topicNum);
18✔
3104

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

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

3133
  return 0;
18✔
3134
}
3135

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3248
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3249
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3250

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

3257
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3258
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3259

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

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

UNCOV
3292
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
×
3293
  if (NULL == req) {
482,615!
3294
    return;
339,168✔
3295
  }
3296

3297
  taosMemoryFreeClear(req->sql);
143,447!
3298
  taosMemoryFreeClear(req->name);
143,447!
3299
  taosMemoryFreeClear(req->comment);
143,447!
3300
  if (req->type == TSDB_CHILD_TABLE) {
143,447!
3301
    taosMemoryFreeClear(req->ctb.pTag);
140,359!
3302
    taosMemoryFreeClear(req->ctb.stbName);
140,359!
3303
    taosArrayDestroy(req->ctb.tagName);
140,359✔
3304
    req->ctb.tagName = NULL;
140,359✔
3305
  } else if (req->type == TSDB_NORMAL_TABLE) {
3,088!
3306
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
3,088!
3307
  }
3308
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
143,447!
3309
}
3310

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

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

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

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

3333
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3334
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3335

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

3344
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3345
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3346

3347
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3348
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3349

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

3358
typedef struct {
3359
  int32_t code;
3360
} SVDropTbRsp;
3361

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

3370
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3371
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3372

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

3381
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3382
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3383

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

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

3432
typedef struct {
3433
  int32_t        code;
3434
  STableMetaRsp* pMeta;
3435
} SVAlterTbRsp;
3436

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

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

3455
typedef struct {
3456
  SMsgHead head;
3457
} SUpdateTagValRsp;
3458

3459
typedef struct {
3460
  SMsgHead head;
3461
} SVShowTablesReq;
3462

3463
typedef struct {
3464
  SMsgHead head;
3465
  int32_t  id;
3466
} SVShowTablesFetchReq;
3467

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

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

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

3490
typedef struct {
3491
  int64_t tscRid;
3492
  int8_t  connType;
3493
} SClientHbKey;
3494

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

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

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

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

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

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

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

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

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

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

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

3584
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
7,275✔
3585

3586
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3587
  void* pIter = taosHashIterate(info, NULL);
4,285✔
3588
  while (pIter != NULL) {
10,326!
3589
    SKv* kv = (SKv*)pIter;
6,041✔
3590
    taosMemoryFreeClear(kv->value);
6,041!
3591
    pIter = taosHashIterate(info, pIter);
6,041✔
3592
  }
3593
}
4,285✔
3594

3595
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
1,078✔
3596
  SQueryDesc* desc = (SQueryDesc*)pDesc;
1,078✔
3597
  if (desc->subDesc) {
1,078✔
3598
    taosArrayDestroy(desc->subDesc);
1,054✔
3599
    desc->subDesc = NULL;
1,054✔
3600
  }
3601
}
1,078✔
3602

3603
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
4,660✔
3604
  SClientHbReq* req = (SClientHbReq*)pReq;
4,955✔
3605
  if (req->query) {
4,955!
3606
    if (req->query->queryDesc) {
4,616!
3607
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
1,957✔
3608
    }
3609
    taosMemoryFreeClear(req->query);
4,616!
3610
  }
3611

3612
  if (req->info) {
4,955!
3613
    tFreeReqKvHash(req->info);
4,285✔
3614
    taosHashCleanup(req->info);
4,285✔
3615
    req->info = NULL;
4,285✔
3616
  }
3617
}
2,067✔
3618

3619
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3620
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3621

3622
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3623
  if (pReq == NULL) return;
2,544!
3624
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
2,544✔
3625
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
2,544✔
3626
  taosMemoryFree(pReq);
2,544!
3627
}
3628

3629
static FORCE_INLINE void tFreeClientKv(void* pKv) {
2,041✔
3630
  SKv* kv = (SKv*)pKv;
2,041✔
3631
  if (kv) {
2,041!
3632
    taosMemoryFreeClear(kv->value);
2,041!
3633
  }
3634
}
2,041✔
3635

3636
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
4,304✔
3637
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
4,304✔
3638
  if (rsp->query) {
4,304✔
3639
    taosArrayDestroy(rsp->query->pQnodeList);
4,261✔
3640
    taosMemoryFreeClear(rsp->query);
4,261!
3641
  }
3642
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
4,304!
3643
}
2,533✔
3644

3645
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3646
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
3,991✔
3647
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
3,991✔
3648
}
3,991✔
3649

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

3654
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3655
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
17,824!
3656
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
17,824!
3657
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
17,824!
3658
  return 0;
8,912✔
3659
}
3660

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

3672
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3673
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
18,364!
3674
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
18,364!
3675
  return 0;
9,182✔
3676
}
3677

3678
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3679
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
8,510!
3680
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
8,510!
3681
  return 0;
4,255✔
3682
}
3683

3684
typedef struct {
3685
  int32_t vgId;
3686
  // TODO stas
3687
} SMqReportVgInfo;
3688

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

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

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

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

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

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

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

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

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

3788
typedef struct {
3789
  int8_t reserved;
3790
} SMqVDeleteRsp;
3791

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

3799
typedef struct {
3800
  int8_t reserved;
3801
} SMDropStreamRsp;
3802

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

3810
typedef struct {
3811
  int8_t reserved;
3812
} SVDropStreamTaskRsp;
3813

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

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

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

3843
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3844
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3845

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

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

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

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

3872
#define TQ_OFFSET_VERSION 1
3873

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

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

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

3905
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3906
  pOffsetVal->type = TMQ_OFFSET__LOG;
396✔
3907
  pOffsetVal->version = ver;
396✔
3908
}
396✔
3909

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

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

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

3926
typedef struct SMqVgOffset {
3927
  int64_t   consumerId;
3928
  STqOffset offset;
3929
} SMqVgOffset;
3930

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

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

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

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

3952
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3953
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3954

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

3962
typedef struct {
3963
  int8_t reserved;
3964
} SVResumeStreamTaskRsp;
3965

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

3972
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3973
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3974

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

3981
int32_t tSerializeSMResetStreamReq(void* buf, int32_t bufLen, const SMResetStreamReq* pReq);
3982
int32_t tDeserializeSMResetStreamReq(void* buf, int32_t bufLen, SMResetStreamReq* pReq);
3983

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

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

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

4022
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4023
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
4024

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

4033
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4034
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
4035

4036
typedef SMDropSmaReq SDropTagIndexReq;
4037

4038
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4039
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
4040

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

4063
typedef STSma SVCreateTSmaReq;
4064

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

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

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

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

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

4092
typedef struct {
4093
  int32_t number;
4094
  STSma*  tSma;
4095
} STSmaWrapper;
4096

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

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

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

4124
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4125
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4126

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

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

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

4146
typedef struct {
4147
  int idx;
4148
} SMCreateFullTextReq;
4149

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

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

4159
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4160
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4161

4162
typedef struct {
4163
  char indexFName[TSDB_INDEX_FNAME_LEN];
4164
} SUserIndexReq;
4165

4166
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4167
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4168

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

4177
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4178
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4179

4180
typedef struct {
4181
  char tbFName[TSDB_TABLE_FNAME_LEN];
4182
} STableIndexReq;
4183

4184
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4185
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4186

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

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

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

4212
void tFreeSTableIndexInfo(void* pInfo);
4213

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

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

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

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

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

4259
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4260
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
23!
4261
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
23!
4262
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
23✔
4263
  return buf;
23✔
4264
}
4265

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

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

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

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

4289
#define MQ_DATA_RSP_VERSION 100
4290

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

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

4320
} SMqDataRsp;
4321

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

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

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

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

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

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

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

4385
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4386
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
97✔
4387
}
97✔
4388

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

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

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

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

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

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

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

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

4447
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4448
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4449

4450
typedef struct {
4451
  int64_t affectedRows;
4452
} SVDeleteRsp;
4453

4454
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4455
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4456

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

4469
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4470
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4471

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

4479
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4480
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4481

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

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

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

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

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

4513
typedef struct {
4514
  SArray* pRsps;  // SArray<SBatchRspMsg>
4515
} SBatchRsp;
4516

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

4527
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4528
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4529

4530
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
40,937✔
4531
  if (NULL == p) {
40,937!
UNCOV
4532
    return;
×
4533
  }
4534

4535
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
40,937✔
4536
  taosMemoryFree(pRsp->msg);
40,937!
4537
}
4538

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

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

4549
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4550
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4551

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

4559
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4560

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

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

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

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

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

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

4600
#define TSDB_MSG_FLG_ENCODE 0x1
4601
#define TSDB_MSG_FLG_DECODE 0x2
4602
#define TSDB_MSG_FLG_CMPT   0x3
4603

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

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

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

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

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

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

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

4670
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4671
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4672

4673
typedef struct {
4674
  int32_t  funcId;
4675
  col_id_t colId;
4676
} STableTSMAFuncInfo;
4677

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

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

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

4710
#define STSMAHbRsp            STableTSMAInfoRsp
4711
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4712
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4713
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4714

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

4722
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4723
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4724

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

4734
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4735
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4736

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

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

4746
typedef struct SDropTbsReq {
4747
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4748
} SMDropTbsReq;
4749

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

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

4759
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4760
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4761

4762
void tFreeFetchTtlExpiredTbsRsp(void* p);
4763

4764
void setDefaultOptionsForField(SFieldWithOptions* field);
4765
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4766

4767
#pragma pack(pop)
4768

4769
#ifdef __cplusplus
4770
}
4771
#endif
4772

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