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

taosdata / TDengine / #3558

17 Dec 2024 06:05AM UTC coverage: 59.778% (+1.6%) from 58.204%
#3558

push

travis-ci

web-flow
Merge pull request #29179 from taosdata/merge/mainto3.0

merge: form main to 3.0 branch

132787 of 287595 branches covered (46.17%)

Branch coverage included in aggregate %.

104 of 191 new or added lines in 5 files covered. (54.45%)

6085 existing lines in 168 files now uncovered.

209348 of 284746 relevant lines covered (73.52%)

8164844.48 hits per line

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

47.02
/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) {
56,810,598✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
56,810,598✔
74
  int    segIdx = TMSG_SEG_CODE(type);
56,810,598✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
56,810,598!
76
    return type < tMsgRangeDict[segIdx];
56,812,245✔
77
  }
78
  return false;
2✔
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
6,714,962✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
6,691,395✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
13,406,357!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
35,333,234✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
35,333,234✔
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_MAX,
167
} EShowType;
168

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

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

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

205
#define TSDB_KILL_MSG_LEN 30
206

207
#define TSDB_TABLE_NUM_UNIT 100000
208

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

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

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

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

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

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

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

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

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

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

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

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

514
typedef struct SRetention {
515
  int64_t freq;
516
  int64_t keep;
517
  int8_t  freqUnit;
518
  int8_t  keepUnit;
519
} SRetention;
520

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

523
#pragma pack(push, 1)
524

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

531
typedef struct {
532
  int32_t contLen;
533
  int32_t vgId;
534
} SMsgHead;
535

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

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

556
typedef struct {
557
  int32_t totalLen;
558
  int32_t len;
559
  STSRow* row;
560
} SSubmitBlkIter;
561

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

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

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

596
//
597

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

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

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

636
typedef struct {
637
  int32_t numOfRows;
638
  int32_t affectedRows;
639
  int32_t nBlocks;
640
  union {
641
    SArray*        pArray;
642
    SSubmitBlkRsp* pBlocks;
643
  };
644
} SSubmitRsp;
645

646
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
647
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
648
// void    tFreeSSubmitBlkRsp(void* param);
649
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
650

651
#define COL_SMA_ON     ((int8_t)0x1)
652
#define COL_IDX_ON     ((int8_t)0x2)
653
#define COL_IS_KEY     ((int8_t)0x4)
654
#define COL_SET_NULL   ((int8_t)0x10)
655
#define COL_SET_VAL    ((int8_t)0x20)
656
#define COL_IS_SYSINFO ((int8_t)0x40)
657

658
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
659
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
660

661
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
662
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
663
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
664

665
#define SSCHMEA_SET_IDX_ON(s) \
666
  do {                        \
667
    (s)->flags |= COL_IDX_ON; \
668
  } while (0)
669

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

675
#define SSCHMEA_TYPE(s)  ((s)->type)
676
#define SSCHMEA_FLAGS(s) ((s)->flags)
677
#define SSCHMEA_COLID(s) ((s)->colId)
678
#define SSCHMEA_BYTES(s) ((s)->bytes)
679
#define SSCHMEA_NAME(s)  ((s)->name)
680

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

691
typedef struct {
692
  int32_t  nCols;
693
  int32_t  version;
694
  SSchema* pSchema;
695
} SSchemaWrapper;
696

697
typedef struct {
698
  col_id_t id;
699
  uint32_t alg;
700
} SColCmpr;
701

702
typedef struct {
703
  int32_t   nCols;
704
  int32_t   version;
705
  SColCmpr* pColCmpr;
706
} SColCmprWrapper;
707

708
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
UNCOV
709
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
×
710
    terrno = TSDB_CODE_INVALID_PARA;
×
711
    return NULL;
×
712
  }
713

UNCOV
714
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
×
UNCOV
715
  if (pDstWrapper == NULL) {
×
716
    return NULL;
×
717
  }
UNCOV
718
  pDstWrapper->nCols = pSrcWrapper->nCols;
×
UNCOV
719
  pDstWrapper->version = pSrcWrapper->version;
×
720

UNCOV
721
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
×
UNCOV
722
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
×
UNCOV
723
  if (pDstWrapper->pColCmpr == NULL) {
×
724
    taosMemoryFree(pDstWrapper);
×
725
    return NULL;
×
726
  }
UNCOV
727
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
×
728

UNCOV
729
  return pDstWrapper;
×
730
}
731

732
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
733
  if (!(!pCmpr->pColCmpr)) {
12,292!
734
    return TSDB_CODE_INVALID_PARA;
×
735
  }
736
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
12,292!
737
  if (pCmpr->pColCmpr == NULL) {
12,292!
738
    return terrno;
×
739
  }
740
  pCmpr->nCols = nCols;
12,292✔
741
  return 0;
12,292✔
742
}
743

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

762
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
UNCOV
763
  if (pWrapper == NULL) return;
×
764

UNCOV
765
  taosMemoryFreeClear(pWrapper->pColCmpr);
×
UNCOV
766
  taosMemoryFreeClear(pWrapper);
×
767
}
768
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
769
  if (pSchemaWrapper->pSchema == NULL) return NULL;
2,702,809!
770

771
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
2,702,809!
772
  if (pSW == NULL) {
2,703,196!
773
    return NULL;
×
774
  }
775
  pSW->nCols = pSchemaWrapper->nCols;
2,703,196✔
776
  pSW->version = pSchemaWrapper->version;
2,703,196✔
777
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
2,703,196!
778
  if (pSW->pSchema == NULL) {
2,702,100!
779
    taosMemoryFree(pSW);
×
780
    return NULL;
×
781
  }
782

783
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
2,702,100✔
784
  return pSW;
2,702,100✔
785
}
786

787
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
465,349✔
788
  if (pSchemaWrapper) {
5,237,114!
789
    taosMemoryFree(pSchemaWrapper->pSchema);
2,906,265!
790
    taosMemoryFree(pSchemaWrapper);
2,906,250!
791
  }
792
}
5,237,257✔
793

794
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
78,498✔
795
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
78,498!
796
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
78,522!
797
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
78,463!
798
  }
799
}
78,145✔
800

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

811
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
812
  buf = taosDecodeFixedI8(buf, &pSchema->type);
48,498✔
813
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
24,249✔
814
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
24,249!
815
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
24,249!
816
  buf = taosDecodeStringTo(buf, pSchema->name);
24,249✔
817
  return (void*)buf;
24,249✔
818
}
819

820
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
821
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
35,836,709!
822
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
54,263,220!
823
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
54,263,220!
824
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
54,263,220!
825
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
54,263,220!
826
  return 0;
27,131,610✔
827
}
828

829
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
830
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
111,417,342!
831
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
217,811,348!
832
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
217,403,273!
833
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
217,768,323!
834
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
109,131,523!
835
  return 0;
109,401,183✔
836
}
837

838
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
839
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
7,947,748!
840
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
7,947,748!
841
  return 0;
3,973,874✔
842
}
843

844
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
845
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,811,961!
846
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,811,961!
847
  return 0;
1,905,979✔
848
}
849

850
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
851
  int32_t tlen = 0;
8,308✔
852
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,308✔
853
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,308✔
854
  for (int32_t i = 0; i < pSW->nCols; i++) {
60,788✔
855
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
104,960!
856
  }
857
  return tlen;
8,308✔
858
}
859

860
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
861
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
3,858✔
862
  buf = taosDecodeVariantI32(buf, &pSW->version);
3,858✔
863
  if (pSW->nCols > 0) {
3,858✔
864
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
2,664!
865
    if (pSW->pSchema == NULL) {
2,664!
866
      return NULL;
×
867
    }
868

869
    for (int32_t i = 0; i < pSW->nCols; i++) {
26,913✔
870
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
48,498✔
871
    }
872
  } else {
873
    pSW->pSchema = NULL;
1,194✔
874
  }
875
  return (void*)buf;
3,858✔
876
}
877

878
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
879
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,317,830!
880
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,317,830!
881
  for (int32_t i = 0; i < pSW->nCols; i++) {
19,085,426✔
882
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
36,853,022!
883
  }
884
  return 0;
658,915✔
885
}
886

887
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
888
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,095,147!
889
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,095,041!
890

891
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
547,499✔
892
  if (pSW->pSchema == NULL) {
547,664!
893
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
894
  }
895
  for (int32_t i = 0; i < pSW->nCols; i++) {
8,473,235✔
896
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
15,852,170!
897
  }
898

899
  return 0;
546,636✔
900
}
901

902
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
903
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
16,227,373!
904
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
16,244,934!
905

906
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
8,122,541!
907
  if (pSW->pSchema == NULL) {
8,132,964!
908
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
909
  }
910
  for (int32_t i = 0; i < pSW->nCols; i++) {
107,236,117✔
911
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
198,245,637!
912
  }
913

914
  return 0;
8,093,633✔
915
}
916

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

948
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
949
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
950
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
951

952
typedef struct {
953
  STableMetaRsp* pMeta;
954
} SMCreateStbRsp;
955

956
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
957
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
958
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
959

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

970
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
971
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
972
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
973

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

986
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
987
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
988
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
989

990
typedef struct SEpSet {
991
  int8_t inUse;
992
  int8_t numOfEps;
993
  SEp    eps[TSDB_MAX_REPLICA];
994
} SEpSet;
995

996
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
997
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
998
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
999
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
1000

1001
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
1002
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
1003

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

1015
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1016
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1017

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

1037
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1038
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1039

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

1051
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1052
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1053

1054
typedef struct {
1055
  char    user[TSDB_USER_LEN];
1056
  int32_t sqlLen;
1057
  char*   sql;
1058
} SDropUserReq, SDropAcctReq;
1059

1060
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1061
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1062
void    tFreeSDropUserReq(SDropUserReq* pReq);
1063

1064
typedef struct SIpV4Range {
1065
  uint32_t ip;
1066
  uint32_t mask;
1067
} SIpV4Range;
1068

1069
typedef struct {
1070
  int32_t    num;
1071
  SIpV4Range pIpRange[];
1072
} SIpWhiteList;
1073

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

1090
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1091
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1092
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1093

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

1106
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1107
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1108
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1109
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1110

1111
typedef struct {
1112
  int64_t ipWhiteVer;
1113
} SRetrieveIpWhiteReq;
1114

1115
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1116
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1117

1118
typedef struct {
1119
  int32_t dnodeId;
1120
  int64_t analVer;
1121
} SRetrieveAnalAlgoReq;
1122

1123
typedef struct {
1124
  int64_t   ver;
1125
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1126
} SRetrieveAnalAlgoRsp;
1127

1128
int32_t tSerializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1129
int32_t tDeserializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1130
int32_t tSerializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1131
int32_t tDeserializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1132
void    tFreeRetrieveAnalAlgoRsp(SRetrieveAnalAlgoRsp* pRsp);
1133

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

1160
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1161
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1162
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1163

1164
typedef struct {
1165
  char user[TSDB_USER_LEN];
1166
} SGetUserAuthReq;
1167

1168
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1169
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1170

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

1192
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1193
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1194
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1195

1196
typedef struct {
1197
  char user[TSDB_USER_LEN];
1198
} SGetUserWhiteListReq;
1199

1200
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1201
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1202

1203
typedef struct {
1204
  char        user[TSDB_USER_LEN];
1205
  int32_t     numWhiteLists;
1206
  SIpV4Range* pWhiteLists;
1207
} SGetUserWhiteListRsp;
1208

1209
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1210
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1211
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1212

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

1223
  uint8_t precision;
1224
  uint8_t scale;
1225
  int32_t bytes;
1226
  int8_t  type;
1227
  uint8_t pk;
1228
  bool    noData;
1229
} SColumnInfo;
1230

1231
typedef struct STimeWindow {
1232
  TSKEY skey;
1233
  TSKEY ekey;
1234
} STimeWindow;
1235

1236
typedef struct SQueryHint {
1237
  bool batchScan;
1238
} SQueryHint;
1239

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

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

1259
typedef struct STbVerInfo {
1260
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1261
  int32_t sversion;
1262
  int32_t tversion;
1263
} STbVerInfo;
1264

1265
typedef struct {
1266
  int32_t code;
1267
  int64_t affectedRows;
1268
  SArray* tbVerInfo;  // STbVerInfo
1269
} SQueryTableRsp;
1270

1271
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1272

1273
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1274

1275
typedef struct {
1276
  SMsgHead header;
1277
  char     dbFName[TSDB_DB_FNAME_LEN];
1278
  char     tbName[TSDB_TABLE_NAME_LEN];
1279
} STableCfgReq;
1280

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

1302
typedef STableCfg STableCfgRsp;
1303

1304
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1305
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1306

1307
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1308
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1309
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1310

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

1360
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1361
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1362
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1363

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

1396
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1397
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1398
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1399

1400
typedef struct {
1401
  char    db[TSDB_DB_FNAME_LEN];
1402
  int8_t  ignoreNotExists;
1403
  int32_t sqlLen;
1404
  char*   sql;
1405
} SDropDbReq;
1406

1407
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1408
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1409
void    tFreeSDropDbReq(SDropDbReq* pReq);
1410

1411
typedef struct {
1412
  char    db[TSDB_DB_FNAME_LEN];
1413
  int64_t uid;
1414
} SDropDbRsp;
1415

1416
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1417
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1418

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

1427
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1428
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1429

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

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

1449
typedef struct {
1450
  char db[TSDB_DB_FNAME_LEN];
1451
} SDbCfgReq;
1452

1453
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1454
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1455

1456
typedef struct {
1457
  char    db[TSDB_DB_FNAME_LEN];
1458
  int32_t maxSpeed;
1459
} STrimDbReq;
1460

1461
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1462
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1463

1464
typedef struct {
1465
  int32_t timestamp;
1466
} SVTrimDbReq;
1467

1468
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1469
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1470

1471
typedef struct {
1472
  char db[TSDB_DB_FNAME_LEN];
1473
} SS3MigrateDbReq;
1474

1475
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1476
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1477

1478
typedef struct {
1479
  int32_t timestamp;
1480
} SVS3MigrateDbReq;
1481

1482
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1483
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1484

1485
typedef struct {
1486
  int32_t timestampSec;
1487
  int32_t ttlDropMaxCount;
1488
  int32_t nUids;
1489
  SArray* pTbUids;
1490
} SVDropTtlTableReq;
1491

1492
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1493
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1494

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

1542
typedef SDbCfgRsp SDbCfgInfo;
1543

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

1550
typedef struct {
1551
  int32_t rowNum;
1552
} SQnodeListReq;
1553

1554
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1555
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1556

1557
typedef struct {
1558
  int32_t rowNum;
1559
} SDnodeListReq;
1560

1561
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1562

1563
typedef struct {
1564
  int32_t useless;  // useless
1565
} SServerVerReq;
1566

1567
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1568
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1569

1570
typedef struct {
1571
  char ver[TSDB_VERSION_LEN];
1572
} SServerVerRsp;
1573

1574
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1575
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1576

1577
typedef struct SQueryNodeAddr {
1578
  int32_t nodeId;  // vgId or qnodeId
1579
  SEpSet  epSet;
1580
} SQueryNodeAddr;
1581

1582
typedef struct {
1583
  SQueryNodeAddr addr;
1584
  uint64_t       load;
1585
} SQueryNodeLoad;
1586

1587
typedef struct {
1588
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1589
} SQnodeListRsp;
1590

1591
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1592
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1593
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1594

1595
typedef struct {
1596
  SArray* dnodeList;  // SArray<SEpSet>
1597
} SDnodeListRsp;
1598

1599
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1600
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1601
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1602

1603
typedef struct {
1604
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1605
} STableTSMAInfoRsp;
1606

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

1616
typedef struct {
1617
  SArray* pArray;  // Array of SDbHbRsp
1618
} SDbHbBatchRsp;
1619

1620
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1621
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1622
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1623

1624
typedef struct {
1625
  SArray* pArray;  // Array of SGetUserAuthRsp
1626
} SUserAuthBatchRsp;
1627

1628
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1629
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1630
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1631

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

1640
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1641
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1642
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1643

1644
typedef struct {
1645
  int32_t compactId;
1646
  int8_t  bAccepted;
1647
} SCompactDbRsp;
1648

1649
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1650
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1651

1652
typedef struct {
1653
  int32_t compactId;
1654
  int32_t sqlLen;
1655
  char*   sql;
1656
} SKillCompactReq;
1657

1658
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1659
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1660
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1661

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

1677
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1678
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1679
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1680

1681
typedef struct {
1682
  char   name[TSDB_FUNC_NAME_LEN];
1683
  int8_t igNotExists;
1684
} SDropFuncReq;
1685

1686
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1687
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1688

1689
typedef struct {
1690
  int32_t numOfFuncs;
1691
  bool    ignoreCodeComment;
1692
  SArray* pFuncNames;
1693
} SRetrieveFuncReq;
1694

1695
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1696
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1697
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1698

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

1713
typedef struct {
1714
  int32_t funcVersion;
1715
  int64_t funcCreatedTime;
1716
} SFuncExtraInfo;
1717

1718
typedef struct {
1719
  int32_t numOfFuncs;
1720
  SArray* pFuncInfos;
1721
  SArray* pFuncExtraInfos;
1722
} SRetrieveFuncRsp;
1723

1724
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1725
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1726
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1727
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1728

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

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

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

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

1793
typedef struct {
1794
  int32_t vgId;
1795
  int64_t nTimeSeries;
1796
} SVnodeLoadLite;
1797

1798
typedef struct {
1799
  int8_t  syncState;
1800
  int64_t syncTerm;
1801
  int8_t  syncRestore;
1802
  int64_t roleTimeMs;
1803
} SMnodeLoad;
1804

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

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

1844
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1845
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1846
void    tFreeSStatusReq(SStatusReq* pReq);
1847

1848
typedef struct {
1849
  int32_t forceReadConfig;
1850
  int32_t cver;
1851
  SArray* array;
1852
} SConfigReq;
1853

1854
int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
1855
int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq);
1856
void    tFreeSConfigReq(SConfigReq* pReq);
1857

1858
typedef struct {
1859
  int32_t dnodeId;
1860
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
1861
} SDnodeInfoReq;
1862

1863
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1864
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1865

1866
typedef enum {
1867
  MONITOR_TYPE_COUNTER = 0,
1868
  MONITOR_TYPE_SLOW_LOG = 1,
1869
} MONITOR_TYPE;
1870

1871
typedef struct {
1872
  int32_t      contLen;
1873
  char*        pCont;
1874
  MONITOR_TYPE type;
1875
} SStatisReq;
1876

1877
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1878
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1879
void    tFreeSStatisReq(SStatisReq* pReq);
1880

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

1892
typedef struct {
1893
  int32_t dnodeId;
1894
  int64_t clusterId;
1895
  SArray* pVloads;
1896
} SNotifyReq;
1897

1898
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1899
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1900
void    tFreeSNotifyReq(SNotifyReq* pReq);
1901

1902
typedef struct {
1903
  int32_t dnodeId;
1904
  int64_t clusterId;
1905
} SDnodeCfg;
1906

1907
typedef struct {
1908
  int32_t id;
1909
  int8_t  isMnode;
1910
  SEp     ep;
1911
} SDnodeEp;
1912

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

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

1931
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1932
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1933
void    tFreeSStatusRsp(SStatusRsp* pRsp);
1934

1935
typedef struct {
1936
  int32_t forceReadConfig;
1937
  int32_t isConifgVerified;
1938
  int32_t isVersionVerified;
1939
  int32_t cver;
1940
  SArray* array;
1941
} SConfigRsp;
1942

1943
int32_t tSerializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
1944
int32_t tDeserializeSConfigRsp(void* buf, int32_t bufLen, SConfigRsp* pRsp);
1945
void    tFreeSConfigRsp(SConfigRsp* pRsp);
1946

1947
typedef struct {
1948
  int32_t reserved;
1949
} SMTimerReq;
1950

1951
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1952
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1953

1954
typedef struct SOrphanTask {
1955
  int64_t streamId;
1956
  int32_t taskId;
1957
  int32_t nodeId;
1958
} SOrphanTask;
1959

1960
typedef struct SMStreamDropOrphanMsg {
1961
  SArray* pList;  // SArray<SOrphanTask>
1962
} SMStreamDropOrphanMsg;
1963

1964
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1965
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1966
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
1967

1968
typedef struct {
1969
  int32_t  id;
1970
  uint16_t port;                 // node sync Port
1971
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
1972
} SReplica;
1973

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

2026
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2027
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
2028
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
2029

2030
typedef struct {
2031
  int32_t compactId;
2032
  int32_t vgId;
2033
  int32_t dnodeId;
2034
} SQueryCompactProgressReq;
2035

2036
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2037
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
2038

2039
typedef struct {
2040
  int32_t compactId;
2041
  int32_t vgId;
2042
  int32_t dnodeId;
2043
  int32_t numberFileset;
2044
  int32_t finished;
2045
  int32_t progress;
2046
  int64_t remainingTime;
2047
} SQueryCompactProgressRsp;
2048

2049
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2050
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
2051

2052
typedef struct {
2053
  int32_t vgId;
2054
  int32_t dnodeId;
2055
  int64_t dbUid;
2056
  char    db[TSDB_DB_FNAME_LEN];
2057
  int64_t reserved[8];
2058
} SDropVnodeReq;
2059

2060
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2061
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2062

2063
typedef struct {
2064
  char    colName[TSDB_COL_NAME_LEN];
2065
  char    stb[TSDB_TABLE_FNAME_LEN];
2066
  int64_t stbUid;
2067
  int64_t dbUid;
2068
  int64_t reserved[8];
2069
} SDropIndexReq;
2070

2071
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2072
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2073

2074
typedef struct {
2075
  int64_t     dbUid;
2076
  char        db[TSDB_DB_FNAME_LEN];
2077
  int64_t     compactStartTime;
2078
  STimeWindow tw;
2079
  int32_t     compactId;
2080
} SCompactVnodeReq;
2081

2082
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2083
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2084

2085
typedef struct {
2086
  int32_t compactId;
2087
  int32_t vgId;
2088
  int32_t dnodeId;
2089
} SVKillCompactReq;
2090

2091
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2092
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2093

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

2120
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2121
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2122

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

2136
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2137
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2138

2139
typedef struct {
2140
  int32_t vgId;
2141
  int8_t  disable;
2142
} SDisableVnodeWriteReq;
2143

2144
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2145
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2146

2147
typedef struct {
2148
  int32_t  srcVgId;
2149
  int32_t  dstVgId;
2150
  uint32_t hashBegin;
2151
  uint32_t hashEnd;
2152
  int32_t  changeVersion;
2153
  int32_t  reserved;
2154
} SAlterVnodeHashRangeReq;
2155

2156
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2157
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2158

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

2168
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2169
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2170

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

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

2191
typedef struct {
2192
  int32_t     numOfVgroups;
2193
  SVgroupInfo vgroups[];
2194
} SVgroupsInfo;
2195

2196
typedef struct {
2197
  STableMetaRsp* pMeta;
2198
} SMAlterStbRsp;
2199

2200
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2201
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2202
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2203

2204
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2205
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2206
void    tFreeSTableMetaRsp(void* pRsp);
2207
void    tFreeSTableIndexRsp(void* info);
2208

2209
typedef struct {
2210
  SArray* pMetaRsp;   // Array of STableMetaRsp
2211
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2212
} SSTbHbRsp;
2213

2214
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2215
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2216
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2217

2218
typedef struct {
2219
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2220
} SViewHbRsp;
2221

2222
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2223
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2224
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2225

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

2237
typedef struct {
2238
  int32_t dataLen;
2239
  char    name[TSDB_TABLE_FNAME_LEN];
2240
  char*   data;
2241
} STagData;
2242

2243
typedef struct {
2244
  int32_t useless;  // useless
2245
} SShowVariablesReq;
2246

2247
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2248
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2249

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

2258
typedef struct {
2259
  SArray* variables;  // SArray<SVariablesInfo>
2260
} SShowVariablesRsp;
2261

2262
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2263
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2264

2265
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2266

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

2279
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2280
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2281
void tFreeSShowReq(SShowReq* pReq);
2282

2283
typedef struct {
2284
  int64_t       showId;
2285
  STableMetaRsp tableMeta;
2286
} SShowRsp, SVShowTablesRsp;
2287

2288
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2289
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2290
// void    tFreeSShowRsp(SShowRsp* pRsp);
2291

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

2302
typedef struct SSysTableSchema {
2303
  int8_t   type;
2304
  col_id_t colId;
2305
  int32_t  bytes;
2306
} SSysTableSchema;
2307

2308
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2309
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2310

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

2330
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2331

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

2338
typedef struct {
2339
  int64_t version;
2340
  int64_t numOfRows;
2341
  int8_t  compressed;
2342
  int8_t  precision;
2343
  char    data[];
2344
} SRetrieveTableRspForTmq;
2345

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

2358
typedef struct SExplainExecInfo {
2359
  double   startupCost;
2360
  double   totalCost;
2361
  uint64_t numOfRows;
2362
  uint32_t verboseLen;
2363
  void*    verboseInfo;
2364
} SExplainExecInfo;
2365

2366
typedef struct {
2367
  int32_t           numOfPlans;
2368
  SExplainExecInfo* subplanInfo;
2369
} SExplainRsp;
2370

2371
typedef struct {
2372
  SExplainRsp rsp;
2373
  uint64_t    qId;
2374
  uint64_t    cId;
2375
  uint64_t    tId;
2376
  int64_t     rId;
2377
  int32_t     eId;
2378
} SExplainLocalRsp;
2379

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

2392
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2393
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2394
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2395

2396
typedef struct {
2397
  char    config[TSDB_DNODE_CONFIG_LEN];
2398
  char    value[TSDB_CLUSTER_VALUE_LEN];
2399
  int32_t sqlLen;
2400
  char*   sql;
2401
} SMCfgClusterReq;
2402

2403
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2404
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2405
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2406

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

2414
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2415
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2416
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2417

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

2428
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2429
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2430
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2431

2432
enum {
2433
  RESTORE_TYPE__ALL = 1,
2434
  RESTORE_TYPE__MNODE,
2435
  RESTORE_TYPE__VNODE,
2436
  RESTORE_TYPE__QNODE,
2437
};
2438

2439
typedef struct {
2440
  int32_t dnodeId;
2441
  int8_t  restoreType;
2442
  int32_t sqlLen;
2443
  char*   sql;
2444
} SRestoreDnodeReq;
2445

2446
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2447
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2448
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2449

2450
typedef struct {
2451
  int32_t dnodeId;
2452
  char    config[TSDB_DNODE_CONFIG_LEN];
2453
  char    value[TSDB_DNODE_VALUE_LEN];
2454
  int32_t sqlLen;
2455
  char*   sql;
2456
} SMCfgDnodeReq;
2457

2458
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2459
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2460
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2461

2462
typedef struct {
2463
  char    config[TSDB_DNODE_CONFIG_LEN];
2464
  char    value[TSDB_DNODE_VALUE_LEN];
2465
  int32_t version;
2466
} SDCfgDnodeReq;
2467

2468
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2469
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2470

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

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

2490
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2491
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2492

2493
typedef struct {
2494
  int32_t urlLen;
2495
  int32_t sqlLen;
2496
  char*   url;
2497
  char*   sql;
2498
} SMCreateAnodeReq;
2499

2500
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2501
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2502
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2503

2504
typedef struct {
2505
  int32_t anodeId;
2506
  int32_t sqlLen;
2507
  char*   sql;
2508
} SMDropAnodeReq, SMUpdateAnodeReq;
2509

2510
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2511
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2512
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2513
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2514
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2515
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2516

2517
typedef struct {
2518
  int32_t vgId;
2519
  int32_t hbSeq;
2520
} SVArbHbReqMember;
2521

2522
typedef struct {
2523
  int32_t dnodeId;
2524
  char*   arbToken;
2525
  int64_t arbTerm;
2526
  SArray* hbMembers;  // SVArbHbReqMember
2527
} SVArbHeartBeatReq;
2528

2529
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2530
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2531
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2532

2533
typedef struct {
2534
  int32_t vgId;
2535
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2536
  int32_t hbSeq;
2537
} SVArbHbRspMember;
2538

2539
typedef struct {
2540
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2541
  int32_t dnodeId;
2542
  SArray* hbMembers;  // SVArbHbRspMember
2543
} SVArbHeartBeatRsp;
2544

2545
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2546
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2547
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2548

2549
typedef struct {
2550
  char*   arbToken;
2551
  int64_t arbTerm;
2552
  char*   member0Token;
2553
  char*   member1Token;
2554
} SVArbCheckSyncReq;
2555

2556
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2557
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2558
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2559

2560
typedef struct {
2561
  char*   arbToken;
2562
  char*   member0Token;
2563
  char*   member1Token;
2564
  int32_t vgId;
2565
  int32_t errCode;
2566
} SVArbCheckSyncRsp;
2567

2568
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2569
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2570
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2571

2572
typedef struct {
2573
  char*   arbToken;
2574
  int64_t arbTerm;
2575
  char*   memberToken;
2576
} SVArbSetAssignedLeaderReq;
2577

2578
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2579
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2580
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2581

2582
typedef struct {
2583
  char*   arbToken;
2584
  char*   memberToken;
2585
  int32_t vgId;
2586
} SVArbSetAssignedLeaderRsp;
2587

2588
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2589
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2590
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2591

2592
typedef struct {
2593
  int32_t dnodeId;
2594
  char*   token;
2595
} SMArbUpdateGroupMember;
2596

2597
typedef struct {
2598
  int32_t dnodeId;
2599
  char*   token;
2600
  int8_t  acked;
2601
} SMArbUpdateGroupAssigned;
2602

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

2613
typedef struct {
2614
  SArray* updateArray;  // SMArbUpdateGroup
2615
} SMArbUpdateGroupBatchReq;
2616

2617
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2618
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2619
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2620

2621
typedef struct {
2622
  char queryStrId[TSDB_QUERY_ID_LEN];
2623
} SKillQueryReq;
2624

2625
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2626
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2627

2628
typedef struct {
2629
  uint32_t connId;
2630
} SKillConnReq;
2631

2632
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2633
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2634

2635
typedef struct {
2636
  int32_t transId;
2637
} SKillTransReq;
2638

2639
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2640
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2641

2642
typedef struct {
2643
  int32_t useless;  // useless
2644
  int32_t sqlLen;
2645
  char*   sql;
2646
} SBalanceVgroupReq;
2647

2648
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2649
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2650
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2651

2652
typedef struct {
2653
  int32_t vgId1;
2654
  int32_t vgId2;
2655
} SMergeVgroupReq;
2656

2657
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2658
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2659

2660
typedef struct {
2661
  int32_t vgId;
2662
  int32_t dnodeId1;
2663
  int32_t dnodeId2;
2664
  int32_t dnodeId3;
2665
  int32_t sqlLen;
2666
  char*   sql;
2667
} SRedistributeVgroupReq;
2668

2669
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2670
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2671
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2672

2673
typedef struct {
2674
  int32_t reserved;
2675
  int32_t vgId;
2676
  int32_t sqlLen;
2677
  char*   sql;
2678
  char    db[TSDB_DB_FNAME_LEN];
2679
} SBalanceVgroupLeaderReq;
2680

2681
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2682
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2683
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2684

2685
typedef struct {
2686
  int32_t vgId;
2687
} SForceBecomeFollowerReq;
2688

2689
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2690
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2691

2692
typedef struct {
2693
  int32_t vgId;
2694
} SSplitVgroupReq;
2695

2696
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2697
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2698

2699
typedef struct {
2700
  char user[TSDB_USER_LEN];
2701
  char spi;
2702
  char encrypt;
2703
  char secret[TSDB_PASSWORD_LEN];
2704
  char ckey[TSDB_PASSWORD_LEN];
2705
} SAuthReq, SAuthRsp;
2706

2707
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2708
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2709

2710
typedef struct {
2711
  int32_t statusCode;
2712
  char    details[1024];
2713
} SServerStatusRsp;
2714

2715
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2716
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2717

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

2744
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2745
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2746
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2747

2748
typedef struct {
2749
  SMsgHead header;
2750
  uint64_t sId;
2751
  uint64_t queryId;
2752
  uint64_t taskId;
2753
} SSinkDataReq;
2754

2755
typedef struct {
2756
  SMsgHead header;
2757
  uint64_t sId;
2758
  uint64_t queryId;
2759
  uint64_t clientId;
2760
  uint64_t taskId;
2761
  int32_t  execId;
2762
} SQueryContinueReq;
2763

2764
typedef struct {
2765
  SMsgHead header;
2766
  uint64_t sId;
2767
  uint64_t queryId;
2768
  uint64_t taskId;
2769
} SResReadyReq;
2770

2771
typedef struct {
2772
  int32_t code;
2773
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2774
  int32_t sversion;
2775
  int32_t tversion;
2776
} SResReadyRsp;
2777

2778
typedef struct SOperatorParam {
2779
  int32_t opType;
2780
  int32_t downstreamIdx;
2781
  void*   value;
2782
  SArray* pChildren;  // SArray<SOperatorParam*>
2783
} SOperatorParam;
2784

2785
typedef struct STableScanOperatorParam {
2786
  bool    tableSeq;
2787
  SArray* pUidList;
2788
} STableScanOperatorParam;
2789

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

2800
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2801
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2802

2803
typedef struct {
2804
  SMsgHead header;
2805
  uint64_t clientId;
2806
} SSchTasksStatusReq;
2807

2808
typedef struct {
2809
  uint64_t queryId;
2810
  uint64_t clientId;
2811
  uint64_t taskId;
2812
  int64_t  refId;
2813
  int32_t  execId;
2814
  int8_t   status;
2815
} STaskStatus;
2816

2817
typedef struct {
2818
  int64_t refId;
2819
  SArray* taskStatus;  // SArray<STaskStatus>
2820
} SSchedulerStatusRsp;
2821

2822
typedef struct {
2823
  uint64_t queryId;
2824
  uint64_t taskId;
2825
  int8_t   action;
2826
} STaskAction;
2827

2828
typedef struct SQueryNodeEpId {
2829
  int32_t nodeId;  // vgId or qnodeId
2830
  SEp     ep;
2831
} SQueryNodeEpId;
2832

2833
typedef struct {
2834
  SMsgHead       header;
2835
  uint64_t       clientId;
2836
  SQueryNodeEpId epId;
2837
  SArray*        taskAction;  // SArray<STaskAction>
2838
} SSchedulerHbReq;
2839

2840
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2841
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2842
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2843

2844
typedef struct {
2845
  SQueryNodeEpId epId;
2846
  SArray*        taskStatus;  // SArray<STaskStatus>
2847
} SSchedulerHbRsp;
2848

2849
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2850
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2851
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2852

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

2863
typedef struct {
2864
  int32_t code;
2865
} STaskCancelRsp;
2866

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

2877
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2878
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2879

2880
typedef enum {
2881
  TASK_NOTIFY_FINISHED = 1,
2882
} ETaskNotifyType;
2883

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

2895
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2896
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2897

2898
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2899
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2900

2901
typedef struct {
2902
  int32_t code;
2903
} STaskDropRsp;
2904

2905
#define STREAM_TRIGGER_AT_ONCE            1
2906
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2907
#define STREAM_TRIGGER_MAX_DELAY          3
2908
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2909

2910
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2911
#define STREAM_FILL_HISTORY_ON        1
2912
#define STREAM_FILL_HISTORY_OFF       0
2913
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2914
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2915
#define STREAM_CREATE_STABLE_TRUE     1
2916
#define STREAM_CREATE_STABLE_FALSE    0
2917

2918
typedef struct SColLocation {
2919
  int16_t  slotId;
2920
  col_id_t colId;
2921
  int8_t   type;
2922
} SColLocation;
2923

2924
typedef struct SVgroupVer {
2925
  int32_t vgId;
2926
  int64_t ver;
2927
} SVgroupVer;
2928

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

2958
typedef struct {
2959
  int64_t streamId;
2960
} SCMCreateStreamRsp;
2961

2962
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
2963
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
2964
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
2965

2966
enum {
2967
  TOPIC_SUB_TYPE__DB = 1,
2968
  TOPIC_SUB_TYPE__TABLE,
2969
  TOPIC_SUB_TYPE__COLUMN,
2970
};
2971

2972
#define DEFAULT_MAX_POLL_INTERVAL 300000
2973
#define DEFAULT_SESSION_TIMEOUT   12000
2974

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

2986
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
2987
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
2988
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
2989

2990
typedef struct {
2991
  int64_t consumerId;
2992
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
2993

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

3002
  int8_t  withTbName;
3003
  int8_t  autoCommit;
3004
  int32_t autoCommitInterval;
3005
  int8_t  resetOffsetCfg;
3006
  int8_t  enableReplay;
3007
  int8_t  enableBatchMeta;
3008
  int32_t sessionTimeoutMs;
3009
  int32_t maxPollIntervalMs;
3010
} SCMSubscribeReq;
3011

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

3018
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,394!
3019
  tlen += taosEncodeFixedI32(buf, topicNum);
2,394✔
3020

3021
  for (int32_t i = 0; i < topicNum; i++) {
3,390✔
3022
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
1,992✔
3023
  }
3024

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

3036
  return tlen;
2,394✔
3037
}
3038

3039
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
3040
  void* start = buf;
1,293✔
3041
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,293!
3042
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,293✔
3043
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,293✔
3044

3045
  int32_t topicNum = 0;
1,293!
3046
  buf = taosDecodeFixedI32(buf, &topicNum);
1,293✔
3047

3048
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,293✔
3049
  if (pReq->topicNames == NULL) {
1,293!
3050
    return terrno;
×
3051
  }
3052
  for (int32_t i = 0; i < topicNum; i++) {
1,898✔
3053
    char* name = NULL;
605✔
3054
    buf = taosDecodeString(buf, &name);
605✔
3055
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,210!
3056
      return terrno;
×
3057
    }
3058
  }
3059

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

3076
  return 0;
1,293✔
3077
}
3078

3079
typedef struct {
3080
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3081
  SArray* removedConsumers;  // SArray<int64_t>
3082
  SArray* newConsumers;      // SArray<int64_t>
3083
} SMqRebInfo;
3084

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

3107
typedef struct {
3108
  int64_t streamId;
3109
  int64_t checkpointId;
3110
  char    streamName[TSDB_STREAM_FNAME_LEN];
3111
} SMStreamDoCheckpointMsg;
3112

3113
typedef struct {
3114
  int64_t status;
3115
} SMVSubscribeRsp;
3116

3117
typedef struct {
3118
  char    name[TSDB_TOPIC_FNAME_LEN];
3119
  int8_t  igNotExists;
3120
  int32_t sqlLen;
3121
  char*   sql;
3122
} SMDropTopicReq;
3123

3124
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3125
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3126
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3127

3128
typedef struct {
3129
  char   topic[TSDB_TOPIC_FNAME_LEN];
3130
  char   cgroup[TSDB_CGROUP_LEN];
3131
  int8_t igNotExists;
3132
} SMDropCgroupReq;
3133

3134
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3135
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3136

3137
typedef struct {
3138
  int8_t reserved;
3139
} SMDropCgroupRsp;
3140

3141
typedef struct {
3142
  char    name[TSDB_TABLE_FNAME_LEN];
3143
  int8_t  alterType;
3144
  SSchema schema;
3145
} SAlterTopicReq;
3146

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

3158
typedef struct {
3159
  SMsgHead head;
3160
  char     name[TSDB_TABLE_FNAME_LEN];
3161
  int64_t  tuid;
3162
} SDDropTopicReq;
3163

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

3172
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3173
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3174

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

3190
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3191
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3192

3193
// TDMT_VND_DROP_STB ==============
3194
typedef struct SVDropStbReq {
3195
  char*    name;
3196
  tb_uid_t suid;
3197
} SVDropStbReq;
3198

3199
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3200
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3201

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

3230
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3231
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3232
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3233

3234
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,601✔
3235
  if (NULL == req) {
19,113,997!
3236
    return;
18,975,831✔
3237
  }
3238

3239
  taosMemoryFreeClear(req->sql);
138,166!
3240
  taosMemoryFreeClear(req->name);
138,166!
3241
  taosMemoryFreeClear(req->comment);
138,176!
3242
  if (req->type == TSDB_CHILD_TABLE) {
138,176!
3243
    taosMemoryFreeClear(req->ctb.pTag);
125,885!
3244
    taosMemoryFreeClear(req->ctb.stbName);
125,892!
3245
    taosArrayDestroy(req->ctb.tagName);
125,893✔
3246
    req->ctb.tagName = NULL;
125,886✔
3247
  } else if (req->type == TSDB_NORMAL_TABLE) {
12,292!
3248
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
12,292!
3249
  }
3250
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
138,177!
3251
}
3252

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

3262
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3263
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3264
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3265

3266
typedef struct {
3267
  int32_t        code;
3268
  STableMetaRsp* pMeta;
3269
} SVCreateTbRsp, SVUpdateTbRsp;
3270

3271
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3272
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3273
void tFreeSVCreateTbRsp(void* param);
3274

3275
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3276
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3277

3278
typedef struct {
3279
  int32_t nRsps;
3280
  union {
3281
    SVCreateTbRsp* pRsps;
3282
    SArray*        pArray;
3283
  };
3284
} SVCreateTbBatchRsp;
3285

3286
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3287
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3288

3289
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3290
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3291

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

3300
typedef struct {
3301
  int32_t code;
3302
} SVDropTbRsp;
3303

3304
typedef struct {
3305
  int32_t nReqs;
3306
  union {
3307
    SVDropTbReq* pReqs;
3308
    SArray*      pArray;
3309
  };
3310
} SVDropTbBatchReq;
3311

3312
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3313
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3314

3315
typedef struct {
3316
  int32_t nRsps;
3317
  union {
3318
    SVDropTbRsp* pRsps;
3319
    SArray*      pArray;
3320
  };
3321
} SVDropTbBatchRsp;
3322

3323
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3324
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3325

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

3369
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3370
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3371
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3372
void    tfreeMultiTagUpateVal(void* pMultiTag);
3373

3374
typedef struct {
3375
  int32_t        code;
3376
  STableMetaRsp* pMeta;
3377
} SVAlterTbRsp;
3378

3379
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3380
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3381
// ======================
3382

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

3397
typedef struct {
3398
  SMsgHead head;
3399
} SUpdateTagValRsp;
3400

3401
typedef struct {
3402
  SMsgHead head;
3403
} SVShowTablesReq;
3404

3405
typedef struct {
3406
  SMsgHead head;
3407
  int32_t  id;
3408
} SVShowTablesFetchReq;
3409

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

3420
typedef struct {
3421
  int64_t consumerId;
3422
  int32_t epoch;
3423
  char    cgroup[TSDB_CGROUP_LEN];
3424
} SMqAskEpReq;
3425

3426
typedef struct {
3427
  int32_t key;
3428
  int32_t valueLen;
3429
  void*   value;
3430
} SKv;
3431

3432
typedef struct {
3433
  int64_t tscRid;
3434
  int8_t  connType;
3435
} SClientHbKey;
3436

3437
typedef struct {
3438
  int64_t tid;
3439
  char    status[TSDB_JOB_STATUS_LEN];
3440
} SQuerySubDesc;
3441

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

3455
typedef struct {
3456
  uint32_t connId;
3457
  SArray*  queryDesc;  // SArray<SQueryDesc>
3458
} SQueryHbReqBasic;
3459

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

3471
typedef struct SAppClusterSummary {
3472
  uint64_t numOfInsertsReq;
3473
  uint64_t numOfInsertRows;
3474
  uint64_t insertElapsedTime;
3475
  uint64_t insertBytes;  // submit to tsdb since launched.
3476

3477
  uint64_t fetchBytes;
3478
  uint64_t numOfQueryReq;
3479
  uint64_t queryElapsedTime;
3480
  uint64_t numOfSlowQueries;
3481
  uint64_t totalRequests;
3482
  uint64_t currentRequests;  // the number of SRequestObj
3483
} SAppClusterSummary;
3484

3485
typedef struct {
3486
  int64_t            appId;
3487
  int32_t            pid;
3488
  char               name[TSDB_APP_NAME_LEN];
3489
  int64_t            startTime;
3490
  SAppClusterSummary summary;
3491
} SAppHbReq;
3492

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

3503
typedef struct {
3504
  int64_t reqId;
3505
  SArray* reqs;  // SArray<SClientHbReq>
3506
  int64_t ipWhiteList;
3507
} SClientHbBatchReq;
3508

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

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

3525
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
202,853✔
3526

3527
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3528
  void* pIter = taosHashIterate(info, NULL);
238,081✔
3529
  while (pIter != NULL) {
331,357!
3530
    SKv* kv = (SKv*)pIter;
93,276✔
3531
    taosMemoryFreeClear(kv->value);
93,276!
3532
    pIter = taosHashIterate(info, pIter);
93,276✔
3533
  }
3534
}
238,081✔
3535

3536
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
58,155✔
3537
  SQueryDesc* desc = (SQueryDesc*)pDesc;
58,155✔
3538
  if (desc->subDesc) {
58,155✔
3539
    taosArrayDestroy(desc->subDesc);
52,783✔
3540
    desc->subDesc = NULL;
52,783✔
3541
  }
3542
}
58,155✔
3543

3544
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
337,245✔
3545
  SClientHbReq* req = (SClientHbReq*)pReq;
346,444✔
3546
  if (req->query) {
346,444!
3547
    if (req->query->queryDesc) {
329,383!
3548
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
37,294✔
3549
    }
3550
    taosMemoryFreeClear(req->query);
329,383!
3551
  }
3552

3553
  if (req->info) {
346,444!
3554
    tFreeReqKvHash(req->info);
238,081✔
3555
    taosHashCleanup(req->info);
238,081✔
3556
    req->info = NULL;
238,081✔
3557
  }
3558
}
219,275✔
3559

3560
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3561
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3562

3563
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3564
  if (pReq == NULL) return;
34,844!
3565
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
34,844✔
3566
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
34,844✔
3567
  taosMemoryFree(pReq);
34,844!
3568
}
3569

3570
static FORCE_INLINE void tFreeClientKv(void* pKv) {
35,432✔
3571
  SKv* kv = (SKv*)pKv;
35,432✔
3572
  if (kv) {
35,432!
3573
    taosMemoryFreeClear(kv->value);
35,432!
3574
  }
3575
}
35,432✔
3576

3577
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
335,276✔
3578
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
335,276✔
3579
  if (rsp->query) {
335,276✔
3580
    taosArrayDestroy(rsp->query->pQnodeList);
327,416✔
3581
    taosMemoryFreeClear(rsp->query);
327,416!
3582
  }
3583
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
335,276!
3584
}
125,201✔
3585

3586
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3587
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
73,644✔
3588
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
73,644✔
3589
}
73,644✔
3590

3591
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3592
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3593
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3594

3595
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3596
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
248,944!
3597
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
248,944!
3598
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
248,944!
3599
  return 0;
124,472✔
3600
}
3601

3602
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3603
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
132,944!
3604
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
132,945!
3605
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
66,473!
3606
  if (pKv->value == NULL) {
66,473!
3607
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3608
  }
3609
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
66,473!
3610
  return 0;
66,473✔
3611
}
3612

3613
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3614
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
1,348,980!
3615
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
1,348,980!
3616
  return 0;
674,490✔
3617
}
3618

3619
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3620
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
670,554!
3621
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
670,554!
3622
  return 0;
335,277✔
3623
}
3624

3625
typedef struct {
3626
  int32_t vgId;
3627
  // TODO stas
3628
} SMqReportVgInfo;
3629

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

3636
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3637
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3638
  return buf;
3639
}
3640

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

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

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

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

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

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

3721
typedef struct {
3722
  SMsgHead head;
3723
  int64_t  leftForVer;
3724
  int32_t  vgId;
3725
  int64_t  consumerId;
3726
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3727
} SMqVDeleteReq;
3728

3729
typedef struct {
3730
  int8_t reserved;
3731
} SMqVDeleteRsp;
3732

3733
typedef struct {
3734
  char    name[TSDB_STREAM_FNAME_LEN];
3735
  int8_t  igNotExists;
3736
  int32_t sqlLen;
3737
  char*   sql;
3738
} SMDropStreamReq;
3739

3740
typedef struct {
3741
  int8_t reserved;
3742
} SMDropStreamRsp;
3743

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

3751
typedef struct {
3752
  int8_t reserved;
3753
} SVDropStreamTaskRsp;
3754

3755
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3756
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3757
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3758

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

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

3784
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3785
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3786

3787
typedef struct {
3788
  char    topic[TSDB_TOPIC_FNAME_LEN];
3789
  int64_t ntbUid;
3790
  SArray* colIdList;  // SArray<int16_t>
3791
} STqCheckInfo;
3792

3793
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3794
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3795
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3796

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

3807
enum {
3808
  WITH_DATA = 0,
3809
  WITH_META = 1,
3810
  ONLY_META = 2,
3811
};
3812

3813
#define TQ_OFFSET_VERSION 1
3814

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

3831
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3832
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
25,747✔
3833
  pOffsetVal->uid = uid;
25,747✔
3834
  pOffsetVal->ts = ts;
25,747✔
3835
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
25,747!
3836
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3837
  }
3838
  pOffsetVal->primaryKey = primaryKey;
25,753✔
3839
}
25,753✔
3840

3841
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3842
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
148✔
3843
  pOffsetVal->uid = uid;
148✔
3844
}
148✔
3845

3846
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3847
  pOffsetVal->type = TMQ_OFFSET__LOG;
555,037✔
3848
  pOffsetVal->version = ver;
555,037✔
3849
}
555,037✔
3850

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

3858
typedef struct {
3859
  STqOffsetVal val;
3860
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3861
} STqOffset;
3862

3863
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3864
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3865
void    tDeleteSTqOffset(void* val);
3866

3867
typedef struct SMqVgOffset {
3868
  int64_t   consumerId;
3869
  STqOffset offset;
3870
} SMqVgOffset;
3871

3872
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3873
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3874

3875
typedef struct {
3876
  SMsgHead head;
3877
  int64_t  streamId;
3878
  int32_t  taskId;
3879
} SVPauseStreamTaskReq;
3880

3881
typedef struct {
3882
  SMsgHead head;
3883
  int64_t  streamId;
3884
  int32_t  taskId;
3885
  int64_t  chkptId;
3886
} SVResetStreamTaskReq;
3887

3888
typedef struct {
3889
  char   name[TSDB_STREAM_FNAME_LEN];
3890
  int8_t igNotExists;
3891
} SMPauseStreamReq;
3892

3893
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3894
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3895

3896
typedef struct {
3897
  SMsgHead head;
3898
  int32_t  taskId;
3899
  int64_t  streamId;
3900
  int8_t   igUntreated;
3901
} SVResumeStreamTaskReq;
3902

3903
typedef struct {
3904
  int8_t reserved;
3905
} SVResumeStreamTaskRsp;
3906

3907
typedef struct {
3908
  char   name[TSDB_STREAM_FNAME_LEN];
3909
  int8_t igNotExists;
3910
  int8_t igUntreated;
3911
} SMResumeStreamReq;
3912

3913
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3914
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3915

3916
typedef struct {
3917
  char    name[TSDB_TABLE_FNAME_LEN];
3918
  char    stb[TSDB_TABLE_FNAME_LEN];
3919
  int8_t  igExists;
3920
  int8_t  intervalUnit;
3921
  int8_t  slidingUnit;
3922
  int8_t  timezone;    // int8_t is not enough, timezone is unit of second
3923
  int32_t dstVgId;  // for stream
3924
  int64_t interval;
3925
  int64_t offset;
3926
  int64_t sliding;
3927
  int64_t maxDelay;
3928
  int64_t watermark;
3929
  int32_t exprLen;        // strlen + 1
3930
  int32_t tagsFilterLen;  // strlen + 1
3931
  int32_t sqlLen;         // strlen + 1
3932
  int32_t astLen;         // strlen + 1
3933
  char*   expr;
3934
  char*   tagsFilter;
3935
  char*   sql;
3936
  char*   ast;
3937
  int64_t deleteMark;
3938
  int64_t lastTs;
3939
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3940
  SArray* pVgroupVerList;
3941
  int8_t  recursiveTsma;
3942
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3943
} SMCreateSmaReq;
3944

3945
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3946
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3947
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3948

3949
typedef struct {
3950
  char   name[TSDB_TABLE_FNAME_LEN];
3951
  int8_t igNotExists;
3952
} SMDropSmaReq;
3953

3954
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3955
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3956

3957
typedef struct {
3958
  char   dbFName[TSDB_DB_FNAME_LEN];
3959
  char   stbName[TSDB_TABLE_NAME_LEN];
3960
  char   colName[TSDB_COL_NAME_LEN];
3961
  char   idxName[TSDB_INDEX_FNAME_LEN];
3962
  int8_t idxType;
3963
} SCreateTagIndexReq;
3964

3965
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3966
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3967

3968
typedef SMDropSmaReq SDropTagIndexReq;
3969

3970
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3971
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3972

3973
typedef struct {
3974
  int8_t         version;       // for compatibility(default 0)
3975
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
3976
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
3977
  int8_t         timezoneInt;   // sma data expired if timezone changes.
3978
  int32_t        dstVgId;
3979
  char           indexName[TSDB_INDEX_NAME_LEN];
3980
  int32_t        exprLen;
3981
  int32_t        tagsFilterLen;
3982
  int64_t        indexUid;
3983
  tb_uid_t       tableUid;  // super/child/common table uid
3984
  tb_uid_t       dstTbUid;  // for dstVgroup
3985
  int64_t        interval;
3986
  int64_t        offset;  // use unit by precision of DB
3987
  int64_t        sliding;
3988
  char*          dstTbName;  // for dstVgroup
3989
  char*          expr;       // sma expression
3990
  char*          tagsFilter;
3991
  SSchemaWrapper schemaRow;  // for dstVgroup
3992
  SSchemaWrapper schemaTag;  // for dstVgroup
3993
} STSma;                     // Time-range-wise SMA
3994

3995
typedef STSma SVCreateTSmaReq;
3996

3997
typedef struct {
3998
  int8_t  type;  // 0 status report, 1 update data
3999
  int64_t indexUid;
4000
  int64_t skey;  // start TS key of interval/sliding window
4001
} STSmaMsg;
4002

4003
typedef struct {
4004
  int64_t indexUid;
4005
  char    indexName[TSDB_INDEX_NAME_LEN];
4006
} SVDropTSmaReq;
4007

4008
typedef struct {
4009
  int tmp;  // TODO: to avoid compile error
4010
} SVCreateTSmaRsp, SVDropTSmaRsp;
4011

4012
#if 0
4013
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
4014
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
4015
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
4016
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
4017
#endif
4018

4019
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4020
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4021
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
4022
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
4023

4024
typedef struct {
4025
  int32_t number;
4026
  STSma*  tSma;
4027
} STSmaWrapper;
4028

4029
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
4030
  if (pSma) {
1!
4031
    taosMemoryFreeClear(pSma->dstTbName);
1!
4032
    taosMemoryFreeClear(pSma->expr);
1!
4033
    taosMemoryFreeClear(pSma->tagsFilter);
1!
4034
  }
4035
}
1✔
4036

4037
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4038
  if (pSW) {
×
4039
    if (pSW->tSma) {
×
4040
      if (deepCopy) {
×
4041
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
4042
          tDestroyTSma(pSW->tSma + i);
×
4043
        }
4044
      }
4045
      taosMemoryFreeClear(pSW->tSma);
×
4046
    }
4047
  }
4048
}
×
4049

4050
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
4051
  tDestroyTSmaWrapper(pSW, deepCopy);
×
4052
  taosMemoryFreeClear(pSW);
×
4053
  return NULL;
×
4054
}
4055

4056
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
4057
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
4058

4059
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
4060
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
4061

4062
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
4063
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
4064
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4065
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
4066
  }
4067
  return 0;
×
4068
}
4069

4070
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
4071
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
4072
  for (int32_t i = 0; i < pReq->number; ++i) {
×
4073
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
4074
  }
4075
  return 0;
×
4076
}
4077

4078
typedef struct {
4079
  int idx;
4080
} SMCreateFullTextReq;
4081

4082
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4083
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
4084
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
4085

4086
typedef struct {
4087
  char   name[TSDB_TABLE_FNAME_LEN];
4088
  int8_t igNotExists;
4089
} SMDropFullTextReq;
4090

4091
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4092
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4093

4094
typedef struct {
4095
  char indexFName[TSDB_INDEX_FNAME_LEN];
4096
} SUserIndexReq;
4097

4098
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4099
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4100

4101
typedef struct {
4102
  char dbFName[TSDB_DB_FNAME_LEN];
4103
  char tblFName[TSDB_TABLE_FNAME_LEN];
4104
  char colName[TSDB_COL_NAME_LEN];
4105
  char indexType[TSDB_INDEX_TYPE_LEN];
4106
  char indexExts[TSDB_INDEX_EXTS_LEN];
4107
} SUserIndexRsp;
4108

4109
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4110
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4111

4112
typedef struct {
4113
  char tbFName[TSDB_TABLE_FNAME_LEN];
4114
} STableIndexReq;
4115

4116
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4117
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4118

4119
typedef struct {
4120
  int8_t  intervalUnit;
4121
  int8_t  slidingUnit;
4122
  int64_t interval;
4123
  int64_t offset;
4124
  int64_t sliding;
4125
  int64_t dstTbUid;
4126
  int32_t dstVgId;
4127
  SEpSet  epSet;
4128
  char*   expr;
4129
} STableIndexInfo;
4130

4131
typedef struct {
4132
  char     tbName[TSDB_TABLE_NAME_LEN];
4133
  char     dbFName[TSDB_DB_FNAME_LEN];
4134
  uint64_t suid;
4135
  int32_t  version;
4136
  int32_t  indexSize;
4137
  SArray*  pIndex;  // STableIndexInfo
4138
} STableIndexRsp;
4139

4140
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4141
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4142
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4143

4144
void tFreeSTableIndexInfo(void* pInfo);
4145

4146
typedef struct {
4147
  int8_t  mqMsgType;
4148
  int32_t code;
4149
  int32_t epoch;
4150
  int64_t consumerId;
4151
  int64_t walsver;
4152
  int64_t walever;
4153
} SMqRspHead;
4154

4155
typedef struct {
4156
  SMsgHead     head;
4157
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4158
  int8_t       withTbName;
4159
  int8_t       useSnapshot;
4160
  int32_t      epoch;
4161
  uint64_t     reqId;
4162
  int64_t      consumerId;
4163
  int64_t      timeout;
4164
  STqOffsetVal reqOffset;
4165
  int8_t       enableReplay;
4166
  int8_t       sourceExcluded;
4167
  int8_t       enableBatchMeta;
4168
} SMqPollReq;
4169

4170
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4171
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4172
void    tDestroySMqPollReq(SMqPollReq* pReq);
4173

4174
typedef struct {
4175
  int32_t vgId;
4176
  int64_t offset;
4177
  SEpSet  epSet;
4178
} SMqSubVgEp;
4179

4180
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4181
  int32_t tlen = 0;
8,260✔
4182
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
8,260✔
4183
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
8,260✔
4184
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
8,260✔
4185
  return tlen;
8,260✔
4186
}
4187

4188
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4189
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,017!
4190
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,017!
4191
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,017✔
4192
  return buf;
4,017✔
4193
}
4194

4195
typedef struct {
4196
  char           topic[TSDB_TOPIC_FNAME_LEN];
4197
  char           db[TSDB_DB_FNAME_LEN];
4198
  SArray*        vgs;  // SArray<SMqSubVgEp>
4199
  SSchemaWrapper schema;
4200
} SMqSubTopicEp;
4201

4202
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4203
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4204
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4205

4206
typedef struct {
4207
  SMqRspHead   head;
4208
  STqOffsetVal rspOffset;
4209
  int16_t      resMsgType;
4210
  int32_t      metaRspLen;
4211
  void*        metaRsp;
4212
} SMqMetaRsp;
4213

4214
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4215
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4216
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4217

4218
#define MQ_DATA_RSP_VERSION 100
4219

4220
typedef struct {
4221
  SMqRspHead   head;
4222
  STqOffsetVal rspOffset;
4223
  STqOffsetVal reqOffset;
4224
  int32_t      blockNum;
4225
  int8_t       withTbName;
4226
  int8_t       withSchema;
4227
  SArray*      blockDataLen;
4228
  SArray*      blockData;
4229
  SArray*      blockTbName;
4230
  SArray*      blockSchema;
4231

4232
  union {
4233
    struct {
4234
      int64_t sleepTime;
4235
    };
4236
    struct {
4237
      int32_t createTableNum;
4238
      SArray* createTableLen;
4239
      SArray* createTableReq;
4240
    };
4241
  };
4242

4243
} SMqDataRsp;
4244

4245
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
4246
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4247
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4248

4249
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4250
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4251
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4252

4253
typedef struct SMqBatchMetaRsp {
4254
  SMqRspHead   head;  // not serialize
4255
  STqOffsetVal rspOffset;
4256
  SArray*      batchMetaLen;
4257
  SArray*      batchMetaReq;
4258
  void*        pMetaBuff;    // not serialize
4259
  uint32_t     metaBuffLen;  // not serialize
4260
} SMqBatchMetaRsp;
4261

4262
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4263
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4264
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4265
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4266

4267
typedef struct {
4268
  SMqRspHead head;
4269
  char       cgroup[TSDB_CGROUP_LEN];
4270
  SArray*    topics;  // SArray<SMqSubTopicEp>
4271
} SMqAskEpRsp;
4272

4273
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4274
  int32_t tlen = 0;
16,329✔
4275
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4276
  int32_t sz = taosArrayGetSize(pRsp->topics);
16,329!
4277
  tlen += taosEncodeFixedI32(buf, sz);
16,329✔
4278
  for (int32_t i = 0; i < sz; i++) {
22,956✔
4279
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
6,628✔
4280
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
6,628✔
4281
  }
4282
  return tlen;
16,328✔
4283
}
4284

4285
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4286
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4287
  int32_t sz;
4288
  buf = taosDecodeFixedI32(buf, &sz);
7,773✔
4289
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
7,773✔
4290
  if (pRsp->topics == NULL) {
7,773!
4291
    return NULL;
×
4292
  }
4293
  for (int32_t i = 0; i < sz; i++) {
10,980✔
4294
    SMqSubTopicEp topicEp;
4295
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,207✔
4296
    if (buf == NULL) {
3,207!
4297
      return NULL;
×
4298
    }
4299
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,414!
4300
      return NULL;
×
4301
    }
4302
  }
4303
  return buf;
7,773✔
4304
}
4305

4306
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4307
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
18,931✔
4308
}
18,931✔
4309

4310
typedef struct {
4311
  int32_t      vgId;
4312
  STqOffsetVal offset;
4313
  int64_t      rows;
4314
  int64_t      ever;
4315
} OffsetRows;
4316

4317
typedef struct {
4318
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4319
  SArray* offsetRows;
4320
} TopicOffsetRows;
4321

4322
typedef struct {
4323
  int64_t consumerId;
4324
  int32_t epoch;
4325
  SArray* topics;
4326
  int8_t  pollFlag;
4327
} SMqHbReq;
4328

4329
typedef struct {
4330
  char   topic[TSDB_TOPIC_FNAME_LEN];
4331
  int8_t noPrivilege;
4332
} STopicPrivilege;
4333

4334
typedef struct {
4335
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4336
  int32_t debugFlag;
4337
} SMqHbRsp;
4338

4339
typedef struct {
4340
  SMsgHead head;
4341
  int64_t  consumerId;
4342
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4343
} SMqSeekReq;
4344

4345
#define TD_AUTO_CREATE_TABLE 0x1
4346
typedef struct {
4347
  int64_t       suid;
4348
  int64_t       uid;
4349
  int32_t       sver;
4350
  uint32_t      nData;
4351
  uint8_t*      pData;
4352
  SVCreateTbReq cTbReq;
4353
} SVSubmitBlk;
4354

4355
typedef struct {
4356
  SMsgHead header;
4357
  uint64_t sId;
4358
  uint64_t queryId;
4359
  uint64_t clientId;
4360
  uint64_t taskId;
4361
  uint32_t sqlLen;
4362
  uint32_t phyLen;
4363
  char*    sql;
4364
  char*    msg;
4365
  int8_t   source;
4366
} SVDeleteReq;
4367

4368
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4369
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4370

4371
typedef struct {
4372
  int64_t affectedRows;
4373
} SVDeleteRsp;
4374

4375
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4376
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4377

4378
typedef struct SDeleteRes {
4379
  uint64_t suid;
4380
  SArray*  uidList;
4381
  int64_t  skey;
4382
  int64_t  ekey;
4383
  int64_t  affectedRows;
4384
  char     tableFName[TSDB_TABLE_NAME_LEN];
4385
  char     tsColName[TSDB_COL_NAME_LEN];
4386
  int64_t  ctimeMs;  // fill by vnode
4387
  int8_t   source;
4388
} SDeleteRes;
4389

4390
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4391
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4392

4393
typedef struct {
4394
  // int64_t uid;
4395
  char    tbname[TSDB_TABLE_NAME_LEN];
4396
  int64_t startTs;
4397
  int64_t endTs;
4398
} SSingleDeleteReq;
4399

4400
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4401
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4402

4403
typedef struct {
4404
  int64_t suid;
4405
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4406
  int64_t ctimeMs;     // fill by vnode
4407
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4408
} SBatchDeleteReq;
4409

4410
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4411
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4412
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4413

4414
typedef struct {
4415
  int32_t msgIdx;
4416
  int32_t msgType;
4417
  int32_t msgLen;
4418
  void*   msg;
4419
} SBatchMsg;
4420

4421
typedef struct {
4422
  SMsgHead header;
4423
  SArray*  pMsgs;  // SArray<SBatchMsg>
4424
} SBatchReq;
4425

4426
typedef struct {
4427
  int32_t reqType;
4428
  int32_t msgIdx;
4429
  int32_t msgLen;
4430
  int32_t rspCode;
4431
  void*   msg;
4432
} SBatchRspMsg;
4433

4434
typedef struct {
4435
  SArray* pRsps;  // SArray<SBatchRspMsg>
4436
} SBatchRsp;
4437

4438
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4439
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4440
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
803,399✔
4441
  if (NULL == msg) {
803,399!
4442
    return;
×
4443
  }
4444
  SBatchMsg* pMsg = (SBatchMsg*)msg;
803,399✔
4445
  taosMemoryFree(pMsg->msg);
803,399!
4446
}
4447

4448
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4449
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4450

4451
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
194,144✔
4452
  if (NULL == p) {
194,144!
4453
    return;
×
4454
  }
4455

4456
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
194,144✔
4457
  taosMemoryFree(pRsp->msg);
194,144!
4458
}
4459

4460
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4461
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4462
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4463
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4464
void    tDestroySMqHbReq(SMqHbReq* pReq);
4465

4466
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4467
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4468
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4469

4470
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4471
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4472

4473
#define TD_REQ_FROM_APP               0x0
4474
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4475
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4476
#define SUBMIT_REQ_FROM_FILE          0x4
4477
#define TD_REQ_FROM_TAOX              0x8
4478
#define SUBMIT_REQUEST_VERSION        (1)
4479

4480
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4481

4482
typedef struct {
4483
  int32_t        flags;
4484
  SVCreateTbReq* pCreateTbReq;
4485
  int64_t        suid;
4486
  int64_t        uid;
4487
  int32_t        sver;
4488
  union {
4489
    SArray* aRowP;
4490
    SArray* aCol;
4491
  };
4492
  int64_t ctimeMs;
4493
} SSubmitTbData;
4494

4495
typedef struct {
4496
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4497
} SSubmitReq2;
4498

4499
typedef struct {
4500
  SMsgHead header;
4501
  int64_t  version;
4502
  char     data[];  // SSubmitReq2
4503
} SSubmitReq2Msg;
4504

4505
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4506
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
4507
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4508
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4509

4510
typedef struct {
4511
  int32_t affectedRows;
4512
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4513
} SSubmitRsp2;
4514

4515
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4516
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4517
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4518

4519
#define TSDB_MSG_FLG_ENCODE 0x1
4520
#define TSDB_MSG_FLG_DECODE 0x2
4521
#define TSDB_MSG_FLG_CMPT   0x3
4522

4523
typedef struct {
4524
  union {
4525
    struct {
4526
      void*   msgStr;
4527
      int32_t msgLen;
4528
      int64_t ver;
4529
    };
4530
    void* pDataBlock;
4531
  };
4532
} SPackedData;
4533

4534
typedef struct {
4535
  char     fullname[TSDB_VIEW_FNAME_LEN];
4536
  char     name[TSDB_VIEW_NAME_LEN];
4537
  char     dbFName[TSDB_DB_FNAME_LEN];
4538
  char*    querySql;
4539
  char*    sql;
4540
  int8_t   orReplace;
4541
  int8_t   precision;
4542
  int32_t  numOfCols;
4543
  SSchema* pSchema;
4544
} SCMCreateViewReq;
4545

4546
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4547
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4548
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4549

4550
typedef struct {
4551
  char   fullname[TSDB_VIEW_FNAME_LEN];
4552
  char   name[TSDB_VIEW_NAME_LEN];
4553
  char   dbFName[TSDB_DB_FNAME_LEN];
4554
  char*  sql;
4555
  int8_t igNotExists;
4556
} SCMDropViewReq;
4557

4558
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4559
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4560
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4561

4562
typedef struct {
4563
  char fullname[TSDB_VIEW_FNAME_LEN];
4564
} SViewMetaReq;
4565
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4566
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4567

4568
typedef struct {
4569
  char     name[TSDB_VIEW_NAME_LEN];
4570
  char     dbFName[TSDB_DB_FNAME_LEN];
4571
  char*    user;
4572
  uint64_t dbId;
4573
  uint64_t viewId;
4574
  char*    querySql;
4575
  int8_t   precision;
4576
  int8_t   type;
4577
  int32_t  version;
4578
  int32_t  numOfCols;
4579
  SSchema* pSchema;
4580
} SViewMetaRsp;
4581
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4582
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4583
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4584
typedef struct {
4585
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4586
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4587
} STableTSMAInfoReq;
4588

4589
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4590
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4591

4592
typedef struct {
4593
  int32_t  funcId;
4594
  col_id_t colId;
4595
} STableTSMAFuncInfo;
4596

4597
typedef struct {
4598
  char     name[TSDB_TABLE_NAME_LEN];
4599
  uint64_t tsmaId;
4600
  char     targetTb[TSDB_TABLE_NAME_LEN];
4601
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4602
  char     tb[TSDB_TABLE_NAME_LEN];
4603
  char     dbFName[TSDB_DB_FNAME_LEN];
4604
  uint64_t suid;
4605
  uint64_t destTbUid;
4606
  uint64_t dbId;
4607
  int32_t  version;
4608
  int64_t  interval;
4609
  int8_t   unit;
4610
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4611
  SArray*  pTags;      // SArray<SSchema>
4612
  SArray*  pUsedCols;  // SArray<SSchema>
4613
  char*    ast;
4614

4615
  int64_t streamUid;
4616
  int64_t reqTs;
4617
  int64_t rspTs;
4618
  int64_t delayDuration;  // ms
4619
  bool    fillHistoryFinished;
4620
} STableTSMAInfo;
4621

4622
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4623
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4624
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4625
void    tFreeTableTSMAInfo(void* p);
4626
void    tFreeAndClearTableTSMAInfo(void* p);
4627
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4628

4629
#define STSMAHbRsp            STableTSMAInfoRsp
4630
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4631
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4632
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4633

4634
typedef struct SStreamProgressReq {
4635
  int64_t streamId;
4636
  int32_t vgId;
4637
  int32_t fetchIdx;
4638
  int32_t subFetchIdx;
4639
} SStreamProgressReq;
4640

4641
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4642
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4643

4644
typedef struct SStreamProgressRsp {
4645
  int64_t streamId;
4646
  int32_t vgId;
4647
  bool    fillHisFinished;
4648
  int64_t progressDelay;
4649
  int32_t fetchIdx;
4650
  int32_t subFetchIdx;
4651
} SStreamProgressRsp;
4652

4653
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4654
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4655

4656
typedef struct SDropCtbWithTsmaSingleVgReq {
4657
  SVgroupInfo vgInfo;
4658
  SArray*     pTbs;  // SVDropTbReq
4659
} SMDropTbReqsOnSingleVg;
4660

4661
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4662
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4663
void    tFreeSMDropTbReqOnSingleVg(void* p);
4664

4665
typedef struct SDropTbsReq {
4666
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4667
} SMDropTbsReq;
4668

4669
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4670
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4671
void    tFreeSMDropTbsReq(void*);
4672

4673
typedef struct SVFetchTtlExpiredTbsRsp {
4674
  SArray* pExpiredTbs;  // SVDropTbReq
4675
  int32_t vgId;
4676
} SVFetchTtlExpiredTbsRsp;
4677

4678
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4679
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4680

4681
void tFreeFetchTtlExpiredTbsRsp(void* p);
4682

4683
void setDefaultOptionsForField(SFieldWithOptions* field);
4684
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4685

4686
#pragma pack(pop)
4687

4688
#ifdef __cplusplus
4689
}
4690
#endif
4691

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