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

taosdata / TDengine / #3529

14 Nov 2024 01:56PM UTC coverage: 60.888% (-0.02%) from 60.905%
#3529

push

travis-ci

web-flow
Merge pull request #28764 from taosdata/docs/TS-4937

doc(arch/last): new section for last/last_row cache

119990 of 252020 branches covered (47.61%)

Branch coverage included in aggregate %.

200800 of 274829 relevant lines covered (73.06%)

15624555.39 hits per line

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

58.7
/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) {
71,598,802✔
72
  // static int8_t sz = sizeof(tMsgRangeDict) / sizeof(tMsgRangeDict[0]);
73
  int8_t maxSegIdx = TMSG_SEG_CODE(TDMT_MAX_MSG_MIN);
71,598,802✔
74
  int    segIdx = TMSG_SEG_CODE(type);
71,598,802✔
75
  if (segIdx >= 0 && segIdx < maxSegIdx) {
71,598,802✔
76
    return type < tMsgRangeDict[segIdx];
71,601,547✔
77
  }
78
  return false;
1✔
79
}
80

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

83
static inline bool vnodeIsMsgBlock(tmsg_t type) {
6,698,070✔
84
  return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
6,672,898✔
85
         (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
13,370,968!
86
         (type == TDMT_SYNC_CONFIG_CHANGE);
87
}
88

89
static inline bool syncUtilUserCommit(tmsg_t msgType) {
37,164,613✔
90
  return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER;
37,164,613✔
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_MAX,
165
} EShowType;
166

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

182
#define TSDB_FILL_NONE        0
183
#define TSDB_FILL_NULL        1
184
#define TSDB_FILL_NULL_F      2
185
#define TSDB_FILL_SET_VALUE   3
186
#define TSDB_FILL_SET_VALUE_F 4
187
#define TSDB_FILL_LINEAR      5
188
#define TSDB_FILL_PREV        6
189
#define TSDB_FILL_NEXT        7
190

191
#define TSDB_ALTER_USER_PASSWD          0x1
192
#define TSDB_ALTER_USER_SUPERUSER       0x2
193
#define TSDB_ALTER_USER_ENABLE          0x3
194
#define TSDB_ALTER_USER_SYSINFO         0x4
195
#define TSDB_ALTER_USER_ADD_PRIVILEGES  0x5
196
#define TSDB_ALTER_USER_DEL_PRIVILEGES  0x6
197
#define TSDB_ALTER_USER_ADD_WHITE_LIST  0x7
198
#define TSDB_ALTER_USER_DROP_WHITE_LIST 0x8
199
#define TSDB_ALTER_USER_CREATEDB        0x9
200

201
#define TSDB_KILL_MSG_LEN 30
202

203
#define TSDB_TABLE_NUM_UNIT 100000
204

205
#define TSDB_VN_READ_ACCCESS  ((char)0x1)
206
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
207
#define TSDB_VN_ALL_ACCCESS   (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
208

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

215
#define TSDB_COL_IS_TAG(f)        (((f & (~(TSDB_COL_NULL))) & TSDB_COL_TAG) != 0)
216
#define TSDB_COL_IS_NORMAL_COL(f) ((f & (~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
217
#define TSDB_COL_IS_UD_COL(f)     ((f & (~(TSDB_COL_NULL))) == TSDB_COL_UDC)
218
#define TSDB_COL_REQ_NULL(f)      (((f)&TSDB_COL_NULL) != 0)
219

220
#define TD_SUPER_TABLE  TSDB_SUPER_TABLE
221
#define TD_CHILD_TABLE  TSDB_CHILD_TABLE
222
#define TD_NORMAL_TABLE TSDB_NORMAL_TABLE
223

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

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

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

401
  // logic plan node
402
  QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
403
  QUERY_NODE_LOGIC_PLAN_JOIN,
404
  QUERY_NODE_LOGIC_PLAN_AGG,
405
  QUERY_NODE_LOGIC_PLAN_PROJECT,
406
  QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY,
407
  QUERY_NODE_LOGIC_PLAN_EXCHANGE,
408
  QUERY_NODE_LOGIC_PLAN_MERGE,
409
  QUERY_NODE_LOGIC_PLAN_WINDOW,
410
  QUERY_NODE_LOGIC_PLAN_FILL,
411
  QUERY_NODE_LOGIC_PLAN_SORT,
412
  QUERY_NODE_LOGIC_PLAN_PARTITION,
413
  QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
414
  QUERY_NODE_LOGIC_PLAN_INTERP_FUNC,
415
  QUERY_NODE_LOGIC_SUBPLAN,
416
  QUERY_NODE_LOGIC_PLAN,
417
  QUERY_NODE_LOGIC_PLAN_GROUP_CACHE,
418
  QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL,
419
  QUERY_NODE_LOGIC_PLAN_FORECAST_FUNC,
420

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

477
typedef struct {
478
  int32_t     vgId;
479
  uint8_t     option;  // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID
480
  const char* dbFName;
481
  const char* tbName;
482
} SBuildTableInput;
483

484
typedef struct {
485
  char    db[TSDB_DB_FNAME_LEN];
486
  int64_t dbId;
487
  int32_t vgVersion;
488
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
489
  int64_t stateTs;
490
} SBuildUseDBInput;
491

492
typedef struct SField {
493
  char    name[TSDB_COL_NAME_LEN];
494
  uint8_t type;
495
  int8_t  flags;
496
  int32_t bytes;
497
} SField;
498
typedef struct SFieldWithOptions {
499
  char     name[TSDB_COL_NAME_LEN];
500
  uint8_t  type;
501
  int8_t   flags;
502
  int32_t  bytes;
503
  uint32_t compress;
504
} SFieldWithOptions;
505

506
typedef struct SRetention {
507
  int64_t freq;
508
  int64_t keep;
509
  int8_t  freqUnit;
510
  int8_t  keepUnit;
511
} SRetention;
512

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

515
#pragma pack(push, 1)
516

517
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
518
typedef struct SEp {
519
  char     fqdn[TSDB_FQDN_LEN];
520
  uint16_t port;
521
} SEp;
522

523
typedef struct {
524
  int32_t contLen;
525
  int32_t vgId;
526
} SMsgHead;
527

528
// Submit message for one table
529
typedef struct SSubmitBlk {
530
  int64_t uid;        // table unique id
531
  int64_t suid;       // stable id
532
  int32_t sversion;   // data schema version
533
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
534
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
535
  int32_t numOfRows;  // total number of rows in current submit block
536
  char    data[];
537
} SSubmitBlk;
538

539
// Submit message for this TSDB
540
typedef struct {
541
  SMsgHead header;
542
  int64_t  version;
543
  int32_t  length;
544
  int32_t  numOfBlocks;
545
  char     blocks[];
546
} SSubmitReq;
547

548
typedef struct {
549
  int32_t totalLen;
550
  int32_t len;
551
  STSRow* row;
552
} SSubmitBlkIter;
553

554
typedef struct {
555
  int32_t totalLen;
556
  int32_t len;
557
  // head of SSubmitBlk
558
  int64_t uid;        // table unique id
559
  int64_t suid;       // stable id
560
  int32_t sversion;   // data schema version
561
  int32_t dataLen;    // data part length, not including the SSubmitBlk head
562
  int32_t schemaLen;  // schema length, if length is 0, no schema exists
563
  int32_t numOfRows;  // total number of rows in current submit block
564
  // head of SSubmitBlk
565
  int32_t     numOfBlocks;
566
  const void* pMsg;
567
} SSubmitMsgIter;
568

569
int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
570
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
571
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
572
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
573
// for debug
574
int32_t tPrintFixedSchemaSubmitReq(SSubmitReq* pReq, STSchema* pSchema);
575

576
struct SSchema {
577
  int8_t   type;
578
  int8_t   flags;
579
  col_id_t colId;
580
  int32_t  bytes;
581
  char     name[TSDB_COL_NAME_LEN];
582
};
583
struct SSchemaExt {
584
  col_id_t colId;
585
  uint32_t compress;
586
};
587

588
//
589

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

599
typedef struct {
600
  char        tbName[TSDB_TABLE_NAME_LEN];
601
  char        stbName[TSDB_TABLE_NAME_LEN];
602
  char        dbFName[TSDB_DB_FNAME_LEN];
603
  int64_t     dbId;
604
  int32_t     numOfTags;
605
  int32_t     numOfColumns;
606
  int8_t      precision;
607
  int8_t      tableType;
608
  int32_t     sversion;
609
  int32_t     tversion;
610
  uint64_t    suid;
611
  uint64_t    tuid;
612
  int32_t     vgId;
613
  int8_t      sysInfo;
614
  SSchema*    pSchemas;
615
  SSchemaExt* pSchemaExt;
616
} STableMetaRsp;
617

618
typedef struct {
619
  int32_t        code;
620
  int64_t        uid;
621
  char*          tblFName;
622
  int32_t        numOfRows;
623
  int32_t        affectedRows;
624
  int64_t        sver;
625
  STableMetaRsp* pMeta;
626
} SSubmitBlkRsp;
627

628
typedef struct {
629
  int32_t numOfRows;
630
  int32_t affectedRows;
631
  int32_t nBlocks;
632
  union {
633
    SArray*        pArray;
634
    SSubmitBlkRsp* pBlocks;
635
  };
636
} SSubmitRsp;
637

638
// int32_t tEncodeSSubmitRsp(SEncoder* pEncoder, const SSubmitRsp* pRsp);
639
// int32_t tDecodeSSubmitRsp(SDecoder* pDecoder, SSubmitRsp* pRsp);
640
// void    tFreeSSubmitBlkRsp(void* param);
641
void tFreeSSubmitRsp(SSubmitRsp* pRsp);
642

643
#define COL_SMA_ON     ((int8_t)0x1)
644
#define COL_IDX_ON     ((int8_t)0x2)
645
#define COL_IS_KEY     ((int8_t)0x4)
646
#define COL_SET_NULL   ((int8_t)0x10)
647
#define COL_SET_VAL    ((int8_t)0x20)
648
#define COL_IS_SYSINFO ((int8_t)0x40)
649

650
#define COL_IS_SET(FLG)  (((FLG) & (COL_SET_VAL | COL_SET_NULL)) != 0)
651
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
652

653
#define IS_BSMA_ON(s)  (((s)->flags & 0x01) == COL_SMA_ON)
654
#define IS_IDX_ON(s)   (((s)->flags & 0x02) == COL_IDX_ON)
655
#define IS_SET_NULL(s) (((s)->flags & COL_SET_NULL) == COL_SET_NULL)
656

657
#define SSCHMEA_SET_IDX_ON(s) \
658
  do {                        \
659
    (s)->flags |= COL_IDX_ON; \
660
  } while (0)
661

662
#define SSCHMEA_SET_IDX_OFF(s)   \
663
  do {                           \
664
    (s)->flags &= (~COL_IDX_ON); \
665
  } while (0)
666

667
#define SSCHMEA_TYPE(s)  ((s)->type)
668
#define SSCHMEA_FLAGS(s) ((s)->flags)
669
#define SSCHMEA_COLID(s) ((s)->colId)
670
#define SSCHMEA_BYTES(s) ((s)->bytes)
671
#define SSCHMEA_NAME(s)  ((s)->name)
672

673
typedef struct {
674
  bool    tsEnableMonitor;
675
  int32_t tsMonitorInterval;
676
  int32_t tsSlowLogThreshold;
677
  int32_t tsSlowLogMaxLen;
678
  int32_t tsSlowLogScope;
679
  int32_t tsSlowLogThresholdTest;   //Obsolete
680
  char    tsSlowLogExceptDb[TSDB_DB_NAME_LEN];
681
} SMonitorParas;
682

683
typedef struct {
684
  int32_t  nCols;
685
  int32_t  version;
686
  SSchema* pSchema;
687
} SSchemaWrapper;
688

689
typedef struct {
690
  col_id_t id;
691
  uint32_t alg;
692
} SColCmpr;
693

694
typedef struct {
695
  int32_t   nCols;
696
  int32_t   version;
697
  SColCmpr* pColCmpr;
698
} SColCmprWrapper;
699

700
static FORCE_INLINE SColCmprWrapper* tCloneSColCmprWrapper(const SColCmprWrapper* pSrcWrapper) {
701
  if (pSrcWrapper->pColCmpr == NULL || pSrcWrapper->nCols == 0) {
2,126!
702
    terrno = TSDB_CODE_INVALID_PARA;
×
703
    return NULL;
×
704
  }
705

706
  SColCmprWrapper* pDstWrapper = (SColCmprWrapper*)taosMemoryMalloc(sizeof(SColCmprWrapper));
2,126✔
707
  if (pDstWrapper == NULL) {
2,126!
708
    return NULL;
×
709
  }
710
  pDstWrapper->nCols = pSrcWrapper->nCols;
2,126✔
711
  pDstWrapper->version = pSrcWrapper->version;
2,126✔
712

713
  int32_t size = sizeof(SColCmpr) * pDstWrapper->nCols;
2,126✔
714
  pDstWrapper->pColCmpr = (SColCmpr*)taosMemoryCalloc(1, size);
2,126✔
715
  if (pDstWrapper->pColCmpr == NULL) {
2,126!
716
    taosMemoryFree(pDstWrapper);
×
717
    return NULL;
×
718
  }
719
  (void)memcpy(pDstWrapper->pColCmpr, pSrcWrapper->pColCmpr, size);
2,126✔
720

721
  return pDstWrapper;
2,126✔
722
}
723

724
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapperByCols(SColCmprWrapper* pCmpr, int32_t nCols) {
725
  if (!(!pCmpr->pColCmpr)) {
13,516!
726
    return TSDB_CODE_INVALID_PARA;
×
727
  }
728
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(nCols, sizeof(SColCmpr));
13,516✔
729
  if (pCmpr->pColCmpr == NULL) {
13,516!
730
    return terrno;
×
731
  }
732
  pCmpr->nCols = nCols;
13,516✔
733
  return 0;
13,516✔
734
}
735

736
static FORCE_INLINE int32_t tInitDefaultSColCmprWrapper(SColCmprWrapper* pCmpr, SSchemaWrapper* pSchema) {
737
  pCmpr->nCols = pSchema->nCols;
738
  if (!(!pCmpr->pColCmpr)) {
739
    return TSDB_CODE_INVALID_PARA;
740
  }
741
  pCmpr->pColCmpr = (SColCmpr*)taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
742
  if (pCmpr->pColCmpr == NULL) {
743
    return terrno;
744
  }
745
  for (int32_t i = 0; i < pCmpr->nCols; i++) {
746
    SColCmpr* pColCmpr = &pCmpr->pColCmpr[i];
747
    SSchema*  pColSchema = &pSchema->pSchema[i];
748
    pColCmpr->id = pColSchema->colId;
749
    pColCmpr->alg = 0;
750
  }
751
  return 0;
752
}
753

754
static FORCE_INLINE void tDeleteSColCmprWrapper(SColCmprWrapper* pWrapper) {
755
  if (pWrapper == NULL) return;
2,126!
756

757
  taosMemoryFreeClear(pWrapper->pColCmpr);
2,126!
758
  taosMemoryFreeClear(pWrapper);
2,126!
759
}
760
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
761
  if (pSchemaWrapper->pSchema == NULL) return NULL;
9,802,826!
762

763
  SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
9,802,826✔
764
  if (pSW == NULL) {
9,809,009!
765
    return NULL;
×
766
  }
767
  pSW->nCols = pSchemaWrapper->nCols;
9,809,009✔
768
  pSW->version = pSchemaWrapper->version;
9,809,009✔
769
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
9,809,009✔
770
  if (pSW->pSchema == NULL) {
9,800,820!
771
    taosMemoryFree(pSW);
×
772
    return NULL;
×
773
  }
774

775
  (void)memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
9,813,820✔
776
  return pSW;
9,813,820✔
777
}
778

779
static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
487,656✔
780
  if (pSchemaWrapper) {
17,108,027!
781
    taosMemoryFree(pSchemaWrapper->pSchema);
10,169,003✔
782
    taosMemoryFree(pSchemaWrapper);
10,169,018✔
783
  }
784
}
17,108,210✔
785

786
static FORCE_INLINE void tDeleteSSchemaWrapperForHash(void* pSchemaWrapper) {
1,038✔
787
  if (pSchemaWrapper != NULL && *(SSchemaWrapper**)pSchemaWrapper != NULL) {
1,038!
788
    taosMemoryFree((*(SSchemaWrapper**)pSchemaWrapper)->pSchema);
1,038✔
789
    taosMemoryFree(*(SSchemaWrapper**)pSchemaWrapper);
1,038✔
790
  }
791
}
1,038✔
792

793
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
794
  int32_t tlen = 0;
53,812✔
795
  tlen += taosEncodeFixedI8(buf, pSchema->type);
107,624✔
796
  tlen += taosEncodeFixedI8(buf, pSchema->flags);
53,812!
797
  tlen += taosEncodeFixedI32(buf, pSchema->bytes);
53,812!
798
  tlen += taosEncodeFixedI16(buf, pSchema->colId);
53,812!
799
  tlen += taosEncodeString(buf, pSchema->name);
53,812✔
800
  return tlen;
53,812✔
801
}
802

803
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
804
  buf = taosDecodeFixedI8(buf, &pSchema->type);
49,638✔
805
  buf = taosDecodeFixedI8(buf, &pSchema->flags);
24,819✔
806
  buf = taosDecodeFixedI32(buf, &pSchema->bytes);
24,819!
807
  buf = taosDecodeFixedI16(buf, &pSchema->colId);
24,819!
808
  buf = taosDecodeStringTo(buf, pSchema->name);
24,819✔
809
  return (void*)buf;
24,819✔
810
}
811

812
static FORCE_INLINE int32_t tEncodeSSchema(SEncoder* pEncoder, const SSchema* pSchema) {
813
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->type));
481,684,477!
814
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pSchema->flags));
494,808,480!
815
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSchema->bytes));
494,808,480!
816
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchema->colId));
494,808,480!
817
  TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pSchema->name));
494,808,480!
818
  return 0;
247,404,240✔
819
}
820

821
static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) {
822
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->type));
470,743,721!
823
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pSchema->flags));
936,384,609!
824
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSchema->bytes));
935,183,866!
825
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchema->colId));
935,183,723!
826
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pSchema->name));
467,904,916!
827
  return 0;
468,944,399✔
828
}
829

830
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
831
  TAOS_CHECK_RETURN(tEncodeI16v(pEncoder, pSchemaExt->colId));
296,946,818!
832
  TAOS_CHECK_RETURN(tEncodeU32(pEncoder, pSchemaExt->compress));
296,946,818!
833
  return 0;
148,473,409✔
834
}
835

836
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
837
  TAOS_CHECK_RETURN(tDecodeI16v(pDecoder, &pSchemaExt->colId));
3,321,222!
838
  TAOS_CHECK_RETURN(tDecodeU32(pDecoder, &pSchemaExt->compress));
3,321,218!
839
  return 0;
1,660,607✔
840
}
841

842
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
843
  int32_t tlen = 0;
8,892✔
844
  tlen += taosEncodeVariantI32(buf, pSW->nCols);
8,892✔
845
  tlen += taosEncodeVariantI32(buf, pSW->version);
8,892✔
846
  for (int32_t i = 0; i < pSW->nCols; i++) {
62,704✔
847
    tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
107,624!
848
  }
849
  return tlen;
8,892✔
850
}
851

852
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
853
  buf = taosDecodeVariantI32(buf, &pSW->nCols);
4,151✔
854
  buf = taosDecodeVariantI32(buf, &pSW->version);
4,151✔
855
  if (pSW->nCols > 0) {
4,151✔
856
    pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
2,766✔
857
    if (pSW->pSchema == NULL) {
2,766!
858
      return NULL;
×
859
    }
860

861
    for (int32_t i = 0; i < pSW->nCols; i++) {
27,585✔
862
      buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
49,638✔
863
    }
864
  } else {
865
    pSW->pSchema = NULL;
1,385✔
866
  }
867
  return (void*)buf;
4,151✔
868
}
869

870
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SEncoder* pEncoder, const SSchemaWrapper* pSW) {
871
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->nCols));
1,503,030!
872
  TAOS_CHECK_RETURN(tEncodeI32v(pEncoder, pSW->version));
1,503,030!
873
  for (int32_t i = 0; i < pSW->nCols; i++) {
13,875,518✔
874
    TAOS_CHECK_RETURN(tEncodeSSchema(pEncoder, &pSW->pSchema[i]));
26,248,006!
875
  }
876
  return 0;
751,515✔
877
}
878

879
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SDecoder* pDecoder, SSchemaWrapper* pSW) {
880
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
1,602,499!
881
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
1,602,446!
882

883
  pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
801,174✔
884
  if (pSW->pSchema == NULL) {
801,300✔
885
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
6✔
886
  }
887
  for (int32_t i = 0; i < pSW->nCols; i++) {
14,245,554✔
888
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
26,890,747!
889
  }
890

891
  return 0;
799,064✔
892
}
893

894
static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaWrapper* pSW) {
895
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->nCols));
51,572,446!
896
  TAOS_CHECK_RETURN(tDecodeI32v(pDecoder, &pSW->version));
51,625,606!
897

898
  pSW->pSchema = (SSchema*)tDecoderMalloc(pDecoder, pSW->nCols * sizeof(SSchema));
25,809,934✔
899
  if (pSW->pSchema == NULL) {
25,801,298!
900
    TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
901
  }
902
  for (int32_t i = 0; i < pSW->nCols; i++) {
479,037,277✔
903
    TAOS_CHECK_RETURN(tDecodeSSchema(pDecoder, &pSW->pSchema[i]));
906,550,233!
904
  }
905

906
  return 0;
25,723,023✔
907
}
908

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

940
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
941
int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
942
void    tFreeSMCreateStbReq(SMCreateStbReq* pReq);
943

944
typedef struct {
945
  STableMetaRsp* pMeta;
946
} SMCreateStbRsp;
947

948
int32_t tEncodeSMCreateStbRsp(SEncoder* pEncoder, const SMCreateStbRsp* pRsp);
949
int32_t tDecodeSMCreateStbRsp(SDecoder* pDecoder, SMCreateStbRsp* pRsp);
950
void    tFreeSMCreateStbRsp(SMCreateStbRsp* pRsp);
951

952
typedef struct {
953
  char     name[TSDB_TABLE_FNAME_LEN];
954
  int8_t   igNotExists;
955
  int8_t   source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
956
  int8_t   reserved[6];
957
  tb_uid_t suid;
958
  int32_t  sqlLen;
959
  char*    sql;
960
} SMDropStbReq;
961

962
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
963
int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
964
void    tFreeSMDropStbReq(SMDropStbReq* pReq);
965

966
typedef struct {
967
  char    name[TSDB_TABLE_FNAME_LEN];
968
  int8_t  alterType;
969
  int32_t numOfFields;
970
  SArray* pFields;
971
  int32_t ttl;
972
  int32_t commentLen;
973
  char*   comment;
974
  int32_t sqlLen;
975
  char*   sql;
976
} SMAlterStbReq;
977

978
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
979
int32_t tDeserializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
980
void    tFreeSMAltertbReq(SMAlterStbReq* pReq);
981

982
typedef struct SEpSet {
983
  int8_t inUse;
984
  int8_t numOfEps;
985
  SEp    eps[TSDB_MAX_REPLICA];
986
} SEpSet;
987

988

989
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
990
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
991
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
992
void*   taosDecodeSEpSet(const void* buf, SEpSet* pEp);
993

994
int32_t tSerializeSEpSet(void* buf, int32_t bufLen, const SEpSet* pEpset);
995
int32_t tDeserializeSEpSet(void* buf, int32_t buflen, SEpSet* pEpset);
996

997
typedef struct {
998
  int8_t  connType;
999
  int32_t pid;
1000
  char    app[TSDB_APP_NAME_LEN];
1001
  char    db[TSDB_DB_NAME_LEN];
1002
  char    user[TSDB_USER_LEN];
1003
  char    passwd[TSDB_PASSWORD_LEN];
1004
  int64_t startTime;
1005
  char    sVer[TSDB_VERSION_LEN];
1006
} SConnectReq;
1007

1008
int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1009
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
1010

1011
typedef struct {
1012
  int32_t       acctId;
1013
  int64_t       clusterId;
1014
  uint32_t      connId;
1015
  int32_t       dnodeNum;
1016
  int8_t        superUser;
1017
  int8_t        sysInfo;
1018
  int8_t        connType;
1019
  SEpSet        epSet;
1020
  int32_t       svrTimestamp;
1021
  int32_t       passVer;
1022
  int32_t       authVer;
1023
  char          sVer[TSDB_VERSION_LEN];
1024
  char          sDetailVer[128];
1025
  int64_t       whiteListVer;
1026
  SMonitorParas monitorParas;
1027
  int8_t        enableAuditDelete;
1028
} SConnectRsp;
1029

1030
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1031
int32_t tDeserializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
1032

1033
typedef struct {
1034
  char    user[TSDB_USER_LEN];
1035
  char    pass[TSDB_PASSWORD_LEN];
1036
  int32_t maxUsers;
1037
  int32_t maxDbs;
1038
  int32_t maxTimeSeries;
1039
  int32_t maxStreams;
1040
  int32_t accessState;  // Configured only by command
1041
  int64_t maxStorage;
1042
} SCreateAcctReq, SAlterAcctReq;
1043

1044
// int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1045
// int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
1046

1047
typedef struct {
1048
  char    user[TSDB_USER_LEN];
1049
  int32_t sqlLen;
1050
  char*   sql;
1051
} SDropUserReq, SDropAcctReq;
1052

1053
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1054
int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
1055
void    tFreeSDropUserReq(SDropUserReq* pReq);
1056

1057
typedef struct SIpV4Range {
1058
  uint32_t ip;
1059
  uint32_t mask;
1060
} SIpV4Range;
1061

1062
typedef struct {
1063
  int32_t    num;
1064
  SIpV4Range pIpRange[];
1065
} SIpWhiteList;
1066

1067
SIpWhiteList* cloneIpWhiteList(SIpWhiteList* pIpWhiteList);
1068
typedef struct {
1069
  int8_t      createType;
1070
  int8_t      superUser;  // denote if it is a super user or not
1071
  int8_t      sysInfo;
1072
  int8_t      enable;
1073
  char        user[TSDB_USER_LEN];
1074
  char        pass[TSDB_USET_PASSWORD_LEN];
1075
  int32_t     numIpRanges;
1076
  SIpV4Range* pIpRanges;
1077
  int32_t     sqlLen;
1078
  char*       sql;
1079
  int8_t      isImport;
1080
  int8_t      createDb;
1081
} SCreateUserReq;
1082

1083
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1084
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
1085
void    tFreeSCreateUserReq(SCreateUserReq* pReq);
1086

1087
typedef struct {
1088
  int64_t     ver;
1089
  char        user[TSDB_USER_LEN];
1090
  int32_t     numOfRange;
1091
  SIpV4Range* pIpRanges;
1092
} SUpdateUserIpWhite;
1093
typedef struct {
1094
  int64_t             ver;
1095
  int                 numOfUser;
1096
  SUpdateUserIpWhite* pUserIpWhite;
1097
} SUpdateIpWhite;
1098

1099
int32_t tSerializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1100
int32_t tDeserializeSUpdateIpWhite(void* buf, int32_t bufLen, SUpdateIpWhite* pReq);
1101
void    tFreeSUpdateIpWhiteReq(SUpdateIpWhite* pReq);
1102
int32_t cloneSUpdateIpWhiteReq(SUpdateIpWhite* pReq, SUpdateIpWhite** pUpdate);
1103

1104
typedef struct {
1105
  int64_t ipWhiteVer;
1106
} SRetrieveIpWhiteReq;
1107

1108
int32_t tSerializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1109
int32_t tDeserializeRetrieveIpWhite(void* buf, int32_t bufLen, SRetrieveIpWhiteReq* pReq);
1110

1111
typedef struct {
1112
  int32_t dnodeId;
1113
  int64_t analVer;
1114
} SRetrieveAnalAlgoReq;
1115

1116
typedef struct {
1117
  int64_t   ver;
1118
  SHashObj* hash;  // algoname:algotype -> SAnalUrl
1119
} SRetrieveAnalAlgoRsp;
1120

1121
int32_t tSerializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1122
int32_t tDeserializeRetrieveAnalAlgoReq(void* buf, int32_t bufLen, SRetrieveAnalAlgoReq* pReq);
1123
int32_t tSerializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1124
int32_t tDeserializeRetrieveAnalAlgoRsp(void* buf, int32_t bufLen, SRetrieveAnalAlgoRsp* pRsp);
1125
void    tFreeRetrieveAnalAlgoRsp(SRetrieveAnalAlgoRsp* pRsp);
1126

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

1153
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1154
int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
1155
void    tFreeSAlterUserReq(SAlterUserReq* pReq);
1156

1157
typedef struct {
1158
  char user[TSDB_USER_LEN];
1159
} SGetUserAuthReq;
1160

1161
int32_t tSerializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1162
int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq* pReq);
1163

1164
typedef struct {
1165
  char      user[TSDB_USER_LEN];
1166
  int32_t   version;
1167
  int32_t   passVer;
1168
  int8_t    superAuth;
1169
  int8_t    sysInfo;
1170
  int8_t    enable;
1171
  int8_t    dropped;
1172
  SHashObj* createdDbs;
1173
  SHashObj* readDbs;
1174
  SHashObj* writeDbs;
1175
  SHashObj* readTbs;
1176
  SHashObj* writeTbs;
1177
  SHashObj* alterTbs;
1178
  SHashObj* readViews;
1179
  SHashObj* writeViews;
1180
  SHashObj* alterViews;
1181
  SHashObj* useDbs;
1182
  int64_t   whiteListVer;
1183
} SGetUserAuthRsp;
1184

1185
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1186
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
1187
void    tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
1188

1189
typedef struct {
1190
  char user[TSDB_USER_LEN];
1191
} SGetUserWhiteListReq;
1192

1193
int32_t tSerializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1194
int32_t tDeserializeSGetUserWhiteListReq(void* buf, int32_t bufLen, SGetUserWhiteListReq* pReq);
1195

1196
typedef struct {
1197
  char        user[TSDB_USER_LEN];
1198
  int32_t     numWhiteLists;
1199
  SIpV4Range* pWhiteLists;
1200
} SGetUserWhiteListRsp;
1201

1202
int32_t tSerializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1203
int32_t tDeserializeSGetUserWhiteListRsp(void* buf, int32_t bufLen, SGetUserWhiteListRsp* pRsp);
1204
void    tFreeSGetUserWhiteListRsp(SGetUserWhiteListRsp* pRsp);
1205

1206
/*
1207
 * for client side struct, only column id, type, bytes are necessary
1208
 * But for data in vnode side, we need all the following information.
1209
 */
1210
typedef struct {
1211
  union {
1212
    col_id_t colId;
1213
    int16_t  slotId;
1214
  };
1215

1216
  uint8_t precision;
1217
  uint8_t scale;
1218
  int32_t bytes;
1219
  int8_t  type;
1220
  uint8_t pk;
1221
  bool    noData;
1222
} SColumnInfo;
1223

1224
typedef struct STimeWindow {
1225
  TSKEY skey;
1226
  TSKEY ekey;
1227
} STimeWindow;
1228

1229
typedef struct SQueryHint {
1230
  bool batchScan;
1231
} SQueryHint;
1232

1233
typedef struct {
1234
  int32_t tsOffset;       // offset value in current msg body, NOTE: ts list is compressed
1235
  int32_t tsLen;          // total length of ts comp block
1236
  int32_t tsNumOfBlocks;  // ts comp block numbers
1237
  int32_t tsOrder;        // ts comp block order
1238
} STsBufInfo;
1239

1240
typedef struct {
1241
  int32_t tz;  // query client timezone
1242
  char    intervalUnit;
1243
  char    slidingUnit;
1244
  char    offsetUnit;
1245
  int8_t  precision;
1246
  int64_t interval;
1247
  int64_t sliding;
1248
  int64_t offset;
1249
} SInterval;
1250

1251
typedef struct STbVerInfo {
1252
  char    tbFName[TSDB_TABLE_FNAME_LEN];
1253
  int32_t sversion;
1254
  int32_t tversion;
1255
} STbVerInfo;
1256

1257
typedef struct {
1258
  int32_t code;
1259
  int64_t affectedRows;
1260
  SArray* tbVerInfo;  // STbVerInfo
1261
} SQueryTableRsp;
1262

1263
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1264

1265
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
1266

1267
typedef struct {
1268
  SMsgHead header;
1269
  char     dbFName[TSDB_DB_FNAME_LEN];
1270
  char     tbName[TSDB_TABLE_NAME_LEN];
1271
} STableCfgReq;
1272

1273
typedef struct {
1274
  char        tbName[TSDB_TABLE_NAME_LEN];
1275
  char        stbName[TSDB_TABLE_NAME_LEN];
1276
  char        dbFName[TSDB_DB_FNAME_LEN];
1277
  int32_t     numOfTags;
1278
  int32_t     numOfColumns;
1279
  int8_t      tableType;
1280
  int64_t     delay1;
1281
  int64_t     delay2;
1282
  int64_t     watermark1;
1283
  int64_t     watermark2;
1284
  int32_t     ttl;
1285
  SArray*     pFuncs;
1286
  int32_t     commentLen;
1287
  char*       pComment;
1288
  SSchema*    pSchemas;
1289
  int32_t     tagsLen;
1290
  char*       pTags;
1291
  SSchemaExt* pSchemaExt;
1292
} STableCfg;
1293

1294
typedef STableCfg STableCfgRsp;
1295

1296
int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1297
int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq);
1298

1299
int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1300
int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp);
1301
void    tFreeSTableCfgRsp(STableCfgRsp* pRsp);
1302

1303
typedef struct {
1304
  char    db[TSDB_DB_FNAME_LEN];
1305
  int32_t numOfVgroups;
1306
  int32_t numOfStables;  // single_stable
1307
  int32_t buffer;        // MB
1308
  int32_t pageSize;
1309
  int32_t pages;
1310
  int32_t cacheLastSize;
1311
  int32_t daysPerFile;
1312
  int32_t daysToKeep0;
1313
  int32_t daysToKeep1;
1314
  int32_t daysToKeep2;
1315
  int32_t keepTimeOffset;
1316
  int32_t minRows;
1317
  int32_t maxRows;
1318
  int32_t walFsyncPeriod;
1319
  int8_t  walLevel;
1320
  int8_t  precision;  // time resolution
1321
  int8_t  compression;
1322
  int8_t  replications;
1323
  int8_t  strict;
1324
  int8_t  cacheLast;
1325
  int8_t  schemaless;
1326
  int8_t  ignoreExist;
1327
  int32_t numOfRetensions;
1328
  SArray* pRetensions;  // SRetention
1329
  int32_t walRetentionPeriod;
1330
  int64_t walRetentionSize;
1331
  int32_t walRollPeriod;
1332
  int64_t walSegmentSize;
1333
  int32_t sstTrigger;
1334
  int16_t hashPrefix;
1335
  int16_t hashSuffix;
1336
  int32_t s3ChunkSize;
1337
  int32_t s3KeepLocal;
1338
  int8_t  s3Compact;
1339
  int32_t tsdbPageSize;
1340
  int32_t sqlLen;
1341
  char*   sql;
1342
  int8_t  withArbitrator;
1343
  int8_t  encryptAlgorithm;
1344
  char    dnodeListStr[TSDB_DNODE_LIST_LEN];
1345
} SCreateDbReq;
1346

1347
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1348
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
1349
void    tFreeSCreateDbReq(SCreateDbReq* pReq);
1350

1351
typedef struct {
1352
  char    db[TSDB_DB_FNAME_LEN];
1353
  int32_t buffer;
1354
  int32_t pageSize;
1355
  int32_t pages;
1356
  int32_t cacheLastSize;
1357
  int32_t daysPerFile;
1358
  int32_t daysToKeep0;
1359
  int32_t daysToKeep1;
1360
  int32_t daysToKeep2;
1361
  int32_t keepTimeOffset;
1362
  int32_t walFsyncPeriod;
1363
  int8_t  walLevel;
1364
  int8_t  strict;
1365
  int8_t  cacheLast;
1366
  int8_t  replications;
1367
  int32_t sstTrigger;
1368
  int32_t minRows;
1369
  int32_t walRetentionPeriod;
1370
  int32_t walRetentionSize;
1371
  int32_t s3KeepLocal;
1372
  int8_t  s3Compact;
1373
  int32_t sqlLen;
1374
  char*   sql;
1375
  int8_t  withArbitrator;
1376
} SAlterDbReq;
1377

1378
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1379
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
1380
void    tFreeSAlterDbReq(SAlterDbReq* pReq);
1381

1382
typedef struct {
1383
  char    db[TSDB_DB_FNAME_LEN];
1384
  int8_t  ignoreNotExists;
1385
  int32_t sqlLen;
1386
  char*   sql;
1387
} SDropDbReq;
1388

1389
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1390
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
1391
void    tFreeSDropDbReq(SDropDbReq* pReq);
1392

1393
typedef struct {
1394
  char    db[TSDB_DB_FNAME_LEN];
1395
  int64_t uid;
1396
} SDropDbRsp;
1397

1398
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1399
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
1400

1401
typedef struct {
1402
  char    db[TSDB_DB_FNAME_LEN];
1403
  int64_t dbId;
1404
  int32_t vgVersion;
1405
  int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
1406
  int64_t stateTs;     // ms
1407
} SUseDbReq;
1408

1409
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1410
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
1411

1412
typedef struct {
1413
  char    db[TSDB_DB_FNAME_LEN];
1414
  int64_t uid;
1415
  int32_t vgVersion;
1416
  int32_t vgNum;
1417
  int16_t hashPrefix;
1418
  int16_t hashSuffix;
1419
  int8_t  hashMethod;
1420
  SArray* pVgroupInfos;  // Array of SVgroupInfo
1421
  int32_t errCode;
1422
  int64_t stateTs;  // ms
1423
} SUseDbRsp;
1424

1425
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp);
1426
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
1427
int32_t tSerializeSUseDbRspImp(SEncoder* pEncoder, const SUseDbRsp* pRsp);
1428
int32_t tDeserializeSUseDbRspImp(SDecoder* pDecoder, SUseDbRsp* pRsp);
1429
void    tFreeSUsedbRsp(SUseDbRsp* pRsp);
1430

1431
typedef struct {
1432
  char db[TSDB_DB_FNAME_LEN];
1433
} SDbCfgReq;
1434

1435
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1436
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq);
1437

1438
typedef struct {
1439
  char    db[TSDB_DB_FNAME_LEN];
1440
  int32_t maxSpeed;
1441
} STrimDbReq;
1442

1443
int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1444
int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq);
1445

1446
typedef struct {
1447
  int32_t timestamp;
1448
} SVTrimDbReq;
1449

1450
int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1451
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
1452

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

1457
int32_t tSerializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1458
int32_t tDeserializeSS3MigrateDbReq(void* buf, int32_t bufLen, SS3MigrateDbReq* pReq);
1459

1460
typedef struct {
1461
  int32_t timestamp;
1462
} SVS3MigrateDbReq;
1463

1464
int32_t tSerializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1465
int32_t tDeserializeSVS3MigrateDbReq(void* buf, int32_t bufLen, SVS3MigrateDbReq* pReq);
1466

1467
typedef struct {
1468
  int32_t timestampSec;
1469
  int32_t ttlDropMaxCount;
1470
  int32_t nUids;
1471
  SArray* pTbUids;
1472
} SVDropTtlTableReq;
1473

1474
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1475
int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
1476

1477
typedef struct {
1478
  char    db[TSDB_DB_FNAME_LEN];
1479
  int64_t dbId;
1480
  int32_t cfgVersion;
1481
  int32_t numOfVgroups;
1482
  int32_t numOfStables;
1483
  int32_t buffer;
1484
  int32_t cacheSize;
1485
  int32_t pageSize;
1486
  int32_t pages;
1487
  int32_t daysPerFile;
1488
  int32_t daysToKeep0;
1489
  int32_t daysToKeep1;
1490
  int32_t daysToKeep2;
1491
  int32_t keepTimeOffset;
1492
  int32_t minRows;
1493
  int32_t maxRows;
1494
  int32_t walFsyncPeriod;
1495
  int16_t hashPrefix;
1496
  int16_t hashSuffix;
1497
  int8_t  hashMethod;
1498
  int8_t  walLevel;
1499
  int8_t  precision;
1500
  int8_t  compression;
1501
  int8_t  replications;
1502
  int8_t  strict;
1503
  int8_t  cacheLast;
1504
  int8_t  encryptAlgorithm;
1505
  int32_t s3ChunkSize;
1506
  int32_t s3KeepLocal;
1507
  int8_t  s3Compact;
1508
  int32_t tsdbPageSize;
1509
  int32_t walRetentionPeriod;
1510
  int32_t walRollPeriod;
1511
  int64_t walRetentionSize;
1512
  int64_t walSegmentSize;
1513
  int32_t numOfRetensions;
1514
  SArray* pRetensions;
1515
  int8_t  schemaless;
1516
  int16_t sstTrigger;
1517
  int8_t  withArbitrator;
1518
} SDbCfgRsp;
1519

1520
typedef SDbCfgRsp SDbCfgInfo;
1521

1522
int32_t tSerializeSDbCfgRspImpl(SEncoder* encoder, const SDbCfgRsp* pRsp);
1523
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp);
1524
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp);
1525
int32_t tDeserializeSDbCfgRspImpl(SDecoder* decoder, SDbCfgRsp* pRsp);
1526
void    tFreeSDbCfgRsp(SDbCfgRsp* pRsp);
1527

1528
typedef struct {
1529
  int32_t rowNum;
1530
} SQnodeListReq;
1531

1532
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1533
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
1534

1535
typedef struct {
1536
  int32_t rowNum;
1537
} SDnodeListReq;
1538

1539
int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq);
1540

1541
typedef struct {
1542
  int32_t useless;  // useless
1543
} SServerVerReq;
1544

1545
int32_t tSerializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1546
// int32_t tDeserializeSServerVerReq(void* buf, int32_t bufLen, SServerVerReq* pReq);
1547

1548
typedef struct {
1549
  char ver[TSDB_VERSION_LEN];
1550
} SServerVerRsp;
1551

1552
int32_t tSerializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1553
int32_t tDeserializeSServerVerRsp(void* buf, int32_t bufLen, SServerVerRsp* pRsp);
1554

1555
typedef struct SQueryNodeAddr {
1556
  int32_t nodeId;  // vgId or qnodeId
1557
  SEpSet  epSet;
1558
} SQueryNodeAddr;
1559

1560
typedef struct {
1561
  SQueryNodeAddr addr;
1562
  uint64_t       load;
1563
} SQueryNodeLoad;
1564

1565
typedef struct {
1566
  SArray* qnodeList;  // SArray<SQueryNodeLoad>
1567
} SQnodeListRsp;
1568

1569
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1570
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
1571
void    tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
1572

1573
typedef struct {
1574
  SArray* dnodeList;  // SArray<SEpSet>
1575
} SDnodeListRsp;
1576

1577
int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1578
int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp);
1579
void    tFreeSDnodeListRsp(SDnodeListRsp* pRsp);
1580

1581
typedef struct {
1582
  SArray* pTsmas;  // SArray<STableTSMAInfo*>
1583
} STableTSMAInfoRsp;
1584

1585
typedef struct {
1586
  SUseDbRsp*         useDbRsp;
1587
  SDbCfgRsp*         cfgRsp;
1588
  STableTSMAInfoRsp* pTsmaRsp;
1589
  int32_t            dbTsmaVersion;
1590
  char               db[TSDB_DB_FNAME_LEN];
1591
  int64_t            dbId;
1592
} SDbHbRsp;
1593

1594
typedef struct {
1595
  SArray* pArray;  // Array of SDbHbRsp
1596
} SDbHbBatchRsp;
1597

1598
int32_t tSerializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1599
int32_t tDeserializeSDbHbBatchRsp(void* buf, int32_t bufLen, SDbHbBatchRsp* pRsp);
1600
void    tFreeSDbHbBatchRsp(SDbHbBatchRsp* pRsp);
1601

1602
typedef struct {
1603
  SArray* pArray;  // Array of SGetUserAuthRsp
1604
} SUserAuthBatchRsp;
1605

1606
int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1607
int32_t tDeserializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp* pRsp);
1608
void    tFreeSUserAuthBatchRsp(SUserAuthBatchRsp* pRsp);
1609

1610
typedef struct {
1611
  char        db[TSDB_DB_FNAME_LEN];
1612
  STimeWindow timeRange;
1613
  int32_t     sqlLen;
1614
  char*       sql;
1615
} SCompactDbReq;
1616

1617
int32_t tSerializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1618
int32_t tDeserializeSCompactDbReq(void* buf, int32_t bufLen, SCompactDbReq* pReq);
1619
void    tFreeSCompactDbReq(SCompactDbReq* pReq);
1620

1621
typedef struct {
1622
  int32_t compactId;
1623
  int8_t  bAccepted;
1624
} SCompactDbRsp;
1625

1626
int32_t tSerializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1627
int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp);
1628

1629
typedef struct {
1630
  int32_t compactId;
1631
  int32_t sqlLen;
1632
  char*   sql;
1633
} SKillCompactReq;
1634

1635
int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1636
int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq);
1637
void    tFreeSKillCompactReq(SKillCompactReq* pReq);
1638

1639
typedef struct {
1640
  char    name[TSDB_FUNC_NAME_LEN];
1641
  int8_t  igExists;
1642
  int8_t  funcType;
1643
  int8_t  scriptType;
1644
  int8_t  outputType;
1645
  int32_t outputLen;
1646
  int32_t bufSize;
1647
  int32_t codeLen;
1648
  int64_t signature;
1649
  char*   pComment;
1650
  char*   pCode;
1651
  int8_t  orReplace;
1652
} SCreateFuncReq;
1653

1654
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1655
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
1656
void    tFreeSCreateFuncReq(SCreateFuncReq* pReq);
1657

1658
typedef struct {
1659
  char   name[TSDB_FUNC_NAME_LEN];
1660
  int8_t igNotExists;
1661
} SDropFuncReq;
1662

1663
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1664
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
1665

1666
typedef struct {
1667
  int32_t numOfFuncs;
1668
  bool    ignoreCodeComment;
1669
  SArray* pFuncNames;
1670
} SRetrieveFuncReq;
1671

1672
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1673
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
1674
void    tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
1675

1676
typedef struct {
1677
  char    name[TSDB_FUNC_NAME_LEN];
1678
  int8_t  funcType;
1679
  int8_t  scriptType;
1680
  int8_t  outputType;
1681
  int32_t outputLen;
1682
  int32_t bufSize;
1683
  int64_t signature;
1684
  int32_t commentSize;
1685
  int32_t codeSize;
1686
  char*   pComment;
1687
  char*   pCode;
1688
} SFuncInfo;
1689

1690
typedef struct {
1691
  int32_t funcVersion;
1692
  int64_t funcCreatedTime;
1693
} SFuncExtraInfo;
1694

1695
typedef struct {
1696
  int32_t numOfFuncs;
1697
  SArray* pFuncInfos;
1698
  SArray* pFuncExtraInfos;
1699
} SRetrieveFuncRsp;
1700

1701
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1702
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
1703
void    tFreeSFuncInfo(SFuncInfo* pInfo);
1704
void    tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
1705

1706
typedef struct {
1707
  int32_t       statusInterval;
1708
  int64_t       checkTime;                  // 1970-01-01 00:00:00.000
1709
  char          timezone[TD_TIMEZONE_LEN];  // tsTimezone
1710
  char          locale[TD_LOCALE_LEN];      // tsLocale
1711
  char          charset[TD_LOCALE_LEN];     // tsCharset
1712
  int8_t        ttlChangeOnWrite;
1713
  int8_t        enableWhiteList;
1714
  int8_t        encryptionKeyStat;
1715
  uint32_t      encryptionKeyChksum;
1716
  SMonitorParas monitorParas;
1717
} SClusterCfg;
1718

1719
typedef struct {
1720
  int32_t openVnodes;
1721
  int32_t dropVnodes;
1722
  int32_t totalVnodes;
1723
  int32_t masterNum;
1724
  int64_t numOfSelectReqs;
1725
  int64_t numOfInsertReqs;
1726
  int64_t numOfInsertSuccessReqs;
1727
  int64_t numOfBatchInsertReqs;
1728
  int64_t numOfBatchInsertSuccessReqs;
1729
  int64_t errors;
1730
} SVnodesStat;
1731

1732
typedef struct {
1733
  int32_t vgId;
1734
  int8_t  syncState;
1735
  int8_t  syncRestore;
1736
  int64_t syncTerm;
1737
  int64_t roleTimeMs;
1738
  int64_t startTimeMs;
1739
  int8_t  syncCanRead;
1740
  int64_t cacheUsage;
1741
  int64_t numOfTables;
1742
  int64_t numOfTimeSeries;
1743
  int64_t totalStorage;
1744
  int64_t compStorage;
1745
  int64_t pointsWritten;
1746
  int64_t numOfSelectReqs;
1747
  int64_t numOfInsertReqs;
1748
  int64_t numOfInsertSuccessReqs;
1749
  int64_t numOfBatchInsertReqs;
1750
  int64_t numOfBatchInsertSuccessReqs;
1751
  int32_t numOfCachedTables;
1752
  int32_t learnerProgress;  // use one reservered
1753
} SVnodeLoad;
1754

1755
typedef struct {
1756
  int32_t vgId;
1757
  int64_t nTimeSeries;
1758
} SVnodeLoadLite;
1759

1760
typedef struct {
1761
  int8_t  syncState;
1762
  int64_t syncTerm;
1763
  int8_t  syncRestore;
1764
  int64_t roleTimeMs;
1765
} SMnodeLoad;
1766

1767
typedef struct {
1768
  int32_t dnodeId;
1769
  int64_t numOfProcessedQuery;
1770
  int64_t numOfProcessedCQuery;
1771
  int64_t numOfProcessedFetch;
1772
  int64_t numOfProcessedDrop;
1773
  int64_t numOfProcessedNotify;
1774
  int64_t numOfProcessedHb;
1775
  int64_t numOfProcessedDelete;
1776
  int64_t cacheDataSize;
1777
  int64_t numOfQueryInQueue;
1778
  int64_t numOfFetchInQueue;
1779
  int64_t timeInQueryQueue;
1780
  int64_t timeInFetchQueue;
1781
} SQnodeLoad;
1782

1783
typedef struct {
1784
  int32_t     sver;      // software version
1785
  int64_t     dnodeVer;  // dnode table version in sdb
1786
  int32_t     dnodeId;
1787
  int64_t     clusterId;
1788
  int64_t     rebootTime;
1789
  int64_t     updateTime;
1790
  float       numOfCores;
1791
  int32_t     numOfSupportVnodes;
1792
  int32_t     numOfDiskCfg;
1793
  int64_t     memTotal;
1794
  int64_t     memAvail;
1795
  char        dnodeEp[TSDB_EP_LEN];
1796
  char        machineId[TSDB_MACHINE_ID_LEN + 1];
1797
  SMnodeLoad  mload;
1798
  SQnodeLoad  qload;
1799
  SClusterCfg clusterCfg;
1800
  SArray*     pVloads;  // array of SVnodeLoad
1801
  int32_t     statusSeq;
1802
  int64_t     ipWhiteVer;
1803
  int64_t     analVer;
1804
} SStatusReq;
1805

1806
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1807
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
1808
void    tFreeSStatusReq(SStatusReq* pReq);
1809

1810
typedef struct {
1811
  int32_t dnodeId;
1812
  char    machineId[TSDB_MACHINE_ID_LEN + 1];
1813
} SDnodeInfoReq;
1814

1815
int32_t tSerializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1816
int32_t tDeserializeSDnodeInfoReq(void* buf, int32_t bufLen, SDnodeInfoReq* pReq);
1817

1818
typedef enum {
1819
  MONITOR_TYPE_COUNTER = 0,
1820
  MONITOR_TYPE_SLOW_LOG = 1,
1821
} MONITOR_TYPE;
1822

1823
typedef struct {
1824
  int32_t      contLen;
1825
  char*        pCont;
1826
  MONITOR_TYPE type;
1827
} SStatisReq;
1828

1829
int32_t tSerializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1830
int32_t tDeserializeSStatisReq(void* buf, int32_t bufLen, SStatisReq* pReq);
1831
void    tFreeSStatisReq(SStatisReq* pReq);
1832

1833
typedef struct {
1834
  char    db[TSDB_DB_FNAME_LEN];
1835
  char    table[TSDB_TABLE_NAME_LEN];
1836
  char    operation[AUDIT_OPERATION_LEN];
1837
  int32_t sqlLen;
1838
  char*   pSql;
1839
} SAuditReq;
1840
int32_t tSerializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
1841
int32_t tDeserializeSAuditReq(void* buf, int32_t bufLen, SAuditReq* pReq);
1842
void    tFreeSAuditReq(SAuditReq* pReq);
1843

1844
typedef struct {
1845
  int32_t dnodeId;
1846
  int64_t clusterId;
1847
  SArray* pVloads;
1848
} SNotifyReq;
1849

1850
int32_t tSerializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1851
int32_t tDeserializeSNotifyReq(void* buf, int32_t bufLen, SNotifyReq* pReq);
1852
void    tFreeSNotifyReq(SNotifyReq* pReq);
1853

1854
typedef struct {
1855
  int32_t dnodeId;
1856
  int64_t clusterId;
1857
} SDnodeCfg;
1858

1859
typedef struct {
1860
  int32_t id;
1861
  int8_t  isMnode;
1862
  SEp     ep;
1863
} SDnodeEp;
1864

1865
typedef struct {
1866
  int32_t id;
1867
  int8_t  isMnode;
1868
  int8_t  offlineReason;
1869
  SEp     ep;
1870
  char    active[TSDB_ACTIVE_KEY_LEN];
1871
  char    connActive[TSDB_CONN_ACTIVE_KEY_LEN];
1872
} SDnodeInfo;
1873

1874
typedef struct {
1875
  int64_t   dnodeVer;
1876
  SDnodeCfg dnodeCfg;
1877
  SArray*   pDnodeEps;  // Array of SDnodeEp
1878
  int32_t   statusSeq;
1879
  int64_t   ipWhiteVer;
1880
  int64_t   analVer;
1881
} SStatusRsp;
1882

1883
int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1884
int32_t tDeserializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp);
1885
void    tFreeSStatusRsp(SStatusRsp* pRsp);
1886

1887
typedef struct {
1888
  int32_t reserved;
1889
} SMTimerReq;
1890

1891
int32_t tSerializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1892
// int32_t tDeserializeSMTimerMsg(void* buf, int32_t bufLen, SMTimerReq* pReq);
1893

1894
typedef struct SOrphanTask {
1895
  int64_t streamId;
1896
  int32_t taskId;
1897
  int32_t nodeId;
1898
} SOrphanTask;
1899

1900
typedef struct SMStreamDropOrphanMsg {
1901
  SArray* pList;  // SArray<SOrphanTask>
1902
} SMStreamDropOrphanMsg;
1903

1904
int32_t tSerializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1905
int32_t tDeserializeDropOrphanTaskMsg(void* buf, int32_t bufLen, SMStreamDropOrphanMsg* pMsg);
1906
void    tDestroyDropOrphanTaskMsg(SMStreamDropOrphanMsg* pMsg);
1907

1908
typedef struct {
1909
  int32_t  id;
1910
  uint16_t port;                 // node sync Port
1911
  char     fqdn[TSDB_FQDN_LEN];  // node FQDN
1912
} SReplica;
1913

1914
typedef struct {
1915
  int32_t  vgId;
1916
  char     db[TSDB_DB_FNAME_LEN];
1917
  int64_t  dbUid;
1918
  int32_t  vgVersion;
1919
  int32_t  numOfStables;
1920
  int32_t  buffer;
1921
  int32_t  pageSize;
1922
  int32_t  pages;
1923
  int32_t  cacheLastSize;
1924
  int32_t  daysPerFile;
1925
  int32_t  daysToKeep0;
1926
  int32_t  daysToKeep1;
1927
  int32_t  daysToKeep2;
1928
  int32_t  keepTimeOffset;
1929
  int32_t  minRows;
1930
  int32_t  maxRows;
1931
  int32_t  walFsyncPeriod;
1932
  uint32_t hashBegin;
1933
  uint32_t hashEnd;
1934
  int8_t   hashMethod;
1935
  int8_t   walLevel;
1936
  int8_t   precision;
1937
  int8_t   compression;
1938
  int8_t   strict;
1939
  int8_t   cacheLast;
1940
  int8_t   isTsma;
1941
  int8_t   replica;
1942
  int8_t   selfIndex;
1943
  SReplica replicas[TSDB_MAX_REPLICA];
1944
  int32_t  numOfRetensions;
1945
  SArray*  pRetensions;  // SRetention
1946
  void*    pTsma;
1947
  int32_t  walRetentionPeriod;
1948
  int64_t  walRetentionSize;
1949
  int32_t  walRollPeriod;
1950
  int64_t  walSegmentSize;
1951
  int16_t  sstTrigger;
1952
  int16_t  hashPrefix;
1953
  int16_t  hashSuffix;
1954
  int32_t  tsdbPageSize;
1955
  int32_t  s3ChunkSize;
1956
  int32_t  s3KeepLocal;
1957
  int8_t   s3Compact;
1958
  int64_t  reserved[6];
1959
  int8_t   learnerReplica;
1960
  int8_t   learnerSelfIndex;
1961
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
1962
  int32_t  changeVersion;
1963
  int8_t   encryptAlgorithm;
1964
} SCreateVnodeReq;
1965

1966
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
1967
int32_t tDeserializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
1968
int32_t tFreeSCreateVnodeReq(SCreateVnodeReq* pReq);
1969

1970
typedef struct {
1971
  int32_t compactId;
1972
  int32_t vgId;
1973
  int32_t dnodeId;
1974
} SQueryCompactProgressReq;
1975

1976
int32_t tSerializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1977
int32_t tDeserializeSQueryCompactProgressReq(void* buf, int32_t bufLen, SQueryCompactProgressReq* pReq);
1978

1979
typedef struct {
1980
  int32_t compactId;
1981
  int32_t vgId;
1982
  int32_t dnodeId;
1983
  int32_t numberFileset;
1984
  int32_t finished;
1985
} SQueryCompactProgressRsp;
1986

1987
int32_t tSerializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
1988
int32_t tDeserializeSQueryCompactProgressRsp(void* buf, int32_t bufLen, SQueryCompactProgressRsp* pReq);
1989

1990
typedef struct {
1991
  int32_t vgId;
1992
  int32_t dnodeId;
1993
  int64_t dbUid;
1994
  char    db[TSDB_DB_FNAME_LEN];
1995
  int64_t reserved[8];
1996
} SDropVnodeReq;
1997

1998
int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
1999
int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq);
2000

2001
typedef struct {
2002
  char    colName[TSDB_COL_NAME_LEN];
2003
  char    stb[TSDB_TABLE_FNAME_LEN];
2004
  int64_t stbUid;
2005
  int64_t dbUid;
2006
  int64_t reserved[8];
2007
} SDropIndexReq;
2008

2009
int32_t tSerializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2010
int32_t tDeserializeSDropIdxReq(void* buf, int32_t bufLen, SDropIndexReq* pReq);
2011

2012
typedef struct {
2013
  int64_t     dbUid;
2014
  char        db[TSDB_DB_FNAME_LEN];
2015
  int64_t     compactStartTime;
2016
  STimeWindow tw;
2017
  int32_t     compactId;
2018
} SCompactVnodeReq;
2019

2020
int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2021
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
2022

2023
typedef struct {
2024
  int32_t compactId;
2025
  int32_t vgId;
2026
  int32_t dnodeId;
2027
} SVKillCompactReq;
2028

2029
int32_t tSerializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2030
int32_t tDeserializeSVKillCompactReq(void* buf, int32_t bufLen, SVKillCompactReq* pReq);
2031

2032
typedef struct {
2033
  int32_t vgVersion;
2034
  int32_t buffer;
2035
  int32_t pageSize;
2036
  int32_t pages;
2037
  int32_t cacheLastSize;
2038
  int32_t daysPerFile;
2039
  int32_t daysToKeep0;
2040
  int32_t daysToKeep1;
2041
  int32_t daysToKeep2;
2042
  int32_t keepTimeOffset;
2043
  int32_t walFsyncPeriod;
2044
  int8_t  walLevel;
2045
  int8_t  strict;
2046
  int8_t  cacheLast;
2047
  int64_t reserved[7];
2048
  // 1st modification
2049
  int16_t sttTrigger;
2050
  int32_t minRows;
2051
  // 2nd modification
2052
  int32_t walRetentionPeriod;
2053
  int32_t walRetentionSize;
2054
  int32_t s3KeepLocal;
2055
  int8_t  s3Compact;
2056
} SAlterVnodeConfigReq;
2057

2058
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2059
int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
2060

2061
typedef struct {
2062
  int32_t  vgId;
2063
  int8_t   strict;
2064
  int8_t   selfIndex;
2065
  int8_t   replica;
2066
  SReplica replicas[TSDB_MAX_REPLICA];
2067
  int64_t  reserved[8];
2068
  int8_t   learnerSelfIndex;
2069
  int8_t   learnerReplica;
2070
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2071
  int32_t  changeVersion;
2072
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
2073

2074
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2075
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
2076

2077
typedef struct {
2078
  int32_t vgId;
2079
  int8_t  disable;
2080
} SDisableVnodeWriteReq;
2081

2082
int32_t tSerializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2083
int32_t tDeserializeSDisableVnodeWriteReq(void* buf, int32_t bufLen, SDisableVnodeWriteReq* pReq);
2084

2085
typedef struct {
2086
  int32_t  srcVgId;
2087
  int32_t  dstVgId;
2088
  uint32_t hashBegin;
2089
  uint32_t hashEnd;
2090
  int32_t  changeVersion;
2091
  int32_t  reserved;
2092
} SAlterVnodeHashRangeReq;
2093

2094
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2095
int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
2096

2097
#define REQ_OPT_TBNAME 0x0
2098
#define REQ_OPT_TBUID  0x01
2099
typedef struct {
2100
  SMsgHead header;
2101
  char     dbFName[TSDB_DB_FNAME_LEN];
2102
  char     tbName[TSDB_TABLE_NAME_LEN];
2103
  uint8_t  option;
2104
} STableInfoReq;
2105

2106
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2107
int32_t tDeserializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
2108

2109
typedef struct {
2110
  int8_t  metaClone;  // create local clone of the cached table meta
2111
  int32_t numOfVgroups;
2112
  int32_t numOfTables;
2113
  int32_t numOfUdfs;
2114
  char    tableNames[];
2115
} SMultiTableInfoReq;
2116

2117
// todo refactor
2118
typedef struct SVgroupInfo {
2119
  int32_t  vgId;
2120
  uint32_t hashBegin;
2121
  uint32_t hashEnd;
2122
  SEpSet   epSet;
2123
  union {
2124
    int32_t numOfTable;  // unit is TSDB_TABLE_NUM_UNIT
2125
    int32_t taskId;      // used in stream
2126
  };
2127
} SVgroupInfo;
2128

2129
typedef struct {
2130
  int32_t     numOfVgroups;
2131
  SVgroupInfo vgroups[];
2132
} SVgroupsInfo;
2133

2134
typedef struct {
2135
  STableMetaRsp* pMeta;
2136
} SMAlterStbRsp;
2137

2138
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
2139
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
2140
void    tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
2141

2142
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2143
int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
2144
void    tFreeSTableMetaRsp(void* pRsp);
2145
void    tFreeSTableIndexRsp(void* info);
2146

2147
typedef struct {
2148
  SArray* pMetaRsp;   // Array of STableMetaRsp
2149
  SArray* pIndexRsp;  // Array of STableIndexRsp;
2150
} SSTbHbRsp;
2151

2152
int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2153
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
2154
void    tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
2155

2156
typedef struct {
2157
  SArray* pViewRsp;  // Array of SViewMetaRsp*;
2158
} SViewHbRsp;
2159

2160
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2161
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
2162
void    tFreeSViewHbRsp(SViewHbRsp* pRsp);
2163

2164
typedef struct {
2165
  int32_t numOfTables;
2166
  int32_t numOfVgroup;
2167
  int32_t numOfUdf;
2168
  int32_t contLen;
2169
  int8_t  compressed;  // denote if compressed or not
2170
  int32_t rawLen;      // size before compress
2171
  uint8_t metaClone;   // make meta clone after retrieve meta from mnode
2172
  char    meta[];
2173
} SMultiTableMeta;
2174

2175
typedef struct {
2176
  int32_t dataLen;
2177
  char    name[TSDB_TABLE_FNAME_LEN];
2178
  char*   data;
2179
} STagData;
2180

2181
typedef struct {
2182
  int32_t useless;  // useless
2183
} SShowVariablesReq;
2184

2185
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2186
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
2187

2188
typedef struct {
2189
  char name[TSDB_CONFIG_OPTION_LEN + 1];
2190
  char value[TSDB_CONFIG_VALUE_LEN + 1];
2191
  char scope[TSDB_CONFIG_SCOPE_LEN + 1];
2192
} SVariablesInfo;
2193

2194
typedef struct {
2195
  SArray* variables;  // SArray<SVariablesInfo>
2196
} SShowVariablesRsp;
2197

2198
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2199
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pReq);
2200

2201
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp);
2202

2203
/*
2204
 * sql: show tables like '%a_%'
2205
 * payload is the query condition, e.g., '%a_%'
2206
 * payloadLen is the length of payload
2207
 */
2208
typedef struct {
2209
  int32_t type;
2210
  char    db[TSDB_DB_FNAME_LEN];
2211
  int32_t payloadLen;
2212
  char*   payload;
2213
} SShowReq;
2214

2215
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2216
// int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
2217
void tFreeSShowReq(SShowReq* pReq);
2218

2219
typedef struct {
2220
  int64_t       showId;
2221
  STableMetaRsp tableMeta;
2222
} SShowRsp, SVShowTablesRsp;
2223

2224
// int32_t tSerializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2225
// int32_t tDeserializeSShowRsp(void* buf, int32_t bufLen, SShowRsp* pRsp);
2226
// void    tFreeSShowRsp(SShowRsp* pRsp);
2227

2228
typedef struct {
2229
  char    db[TSDB_DB_FNAME_LEN];
2230
  char    tb[TSDB_TABLE_NAME_LEN];
2231
  char    user[TSDB_USER_LEN];
2232
  char    filterTb[TSDB_TABLE_NAME_LEN];  // for ins_columns
2233
  int64_t showId;
2234
  int64_t compactId;  // for compact
2235
  bool    withFull;   // for show users full
2236
} SRetrieveTableReq;
2237

2238
typedef struct SSysTableSchema {
2239
  int8_t   type;
2240
  col_id_t colId;
2241
  int32_t  bytes;
2242
} SSysTableSchema;
2243

2244
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2245
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
2246

2247
typedef struct {
2248
  int64_t useconds;
2249
  int8_t  completed;  // all results are returned to client
2250
  int8_t  precision;
2251
  int8_t  compressed;
2252
  int8_t  streamBlockType;
2253
  int32_t payloadLen;
2254
  int32_t compLen;
2255
  int32_t numOfBlocks;
2256
  int64_t numOfRows;  // from int32_t change to int64_t
2257
  int64_t numOfCols;
2258
  int64_t skey;
2259
  int64_t ekey;
2260
  int64_t version;                         // for stream
2261
  TSKEY   watermark;                       // for stream
2262
  char    parTbName[TSDB_TABLE_NAME_LEN];  // for stream
2263
  char    data[];
2264
} SRetrieveTableRsp;
2265

2266
#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1)
2267

2268
#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \
2269
  do {                                          \
2270
    ((int32_t*)(_p))[0] = (_compLen);           \
2271
    ((int32_t*)(_p))[1] = (_fullLen);           \
2272
  } while (0);
2273

2274
typedef struct {
2275
  int64_t version;
2276
  int64_t numOfRows;
2277
  int8_t  compressed;
2278
  int8_t  precision;
2279
  char    data[];
2280
} SRetrieveTableRspForTmq;
2281

2282
typedef struct {
2283
  int64_t handle;
2284
  int64_t useconds;
2285
  int8_t  completed;  // all results are returned to client
2286
  int8_t  precision;
2287
  int8_t  compressed;
2288
  int32_t compLen;
2289
  int32_t numOfRows;
2290
  int32_t fullLen;
2291
  char    data[];
2292
} SRetrieveMetaTableRsp;
2293

2294
typedef struct SExplainExecInfo {
2295
  double   startupCost;
2296
  double   totalCost;
2297
  uint64_t numOfRows;
2298
  uint32_t verboseLen;
2299
  void*    verboseInfo;
2300
} SExplainExecInfo;
2301

2302
typedef struct {
2303
  int32_t           numOfPlans;
2304
  SExplainExecInfo* subplanInfo;
2305
} SExplainRsp;
2306

2307
typedef struct {
2308
  SExplainRsp rsp;
2309
  uint64_t    qId;
2310
  uint64_t    cId;
2311
  uint64_t    tId;
2312
  int64_t     rId;
2313
  int32_t     eId;
2314
} SExplainLocalRsp;
2315

2316
typedef struct STableScanAnalyzeInfo {
2317
  uint64_t totalRows;
2318
  uint64_t totalCheckedRows;
2319
  uint32_t totalBlocks;
2320
  uint32_t loadBlocks;
2321
  uint32_t loadBlockStatis;
2322
  uint32_t skipBlocks;
2323
  uint32_t filterOutBlocks;
2324
  double   elapsedTime;
2325
  double   filterTime;
2326
} STableScanAnalyzeInfo;
2327

2328
int32_t tSerializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2329
int32_t tDeserializeSExplainRsp(void* buf, int32_t bufLen, SExplainRsp* pRsp);
2330
void    tFreeSExplainRsp(SExplainRsp* pRsp);
2331

2332
typedef struct {
2333
  char    config[TSDB_DNODE_CONFIG_LEN];
2334
  char    value[TSDB_CLUSTER_VALUE_LEN];
2335
  int32_t sqlLen;
2336
  char*   sql;
2337
} SMCfgClusterReq;
2338

2339
int32_t tSerializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2340
int32_t tDeserializeSMCfgClusterReq(void* buf, int32_t bufLen, SMCfgClusterReq* pReq);
2341
void    tFreeSMCfgClusterReq(SMCfgClusterReq* pReq);
2342

2343
typedef struct {
2344
  char    fqdn[TSDB_FQDN_LEN];  // end point, hostname:port
2345
  int32_t port;
2346
  int32_t sqlLen;
2347
  char*   sql;
2348
} SCreateDnodeReq;
2349

2350
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2351
int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
2352
void    tFreeSCreateDnodeReq(SCreateDnodeReq* pReq);
2353

2354
typedef struct {
2355
  int32_t dnodeId;
2356
  char    fqdn[TSDB_FQDN_LEN];
2357
  int32_t port;
2358
  int8_t  force;
2359
  int8_t  unsafe;
2360
  int32_t sqlLen;
2361
  char*   sql;
2362
} SDropDnodeReq;
2363

2364
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2365
int32_t tDeserializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
2366
void    tFreeSDropDnodeReq(SDropDnodeReq* pReq);
2367

2368
enum {
2369
  RESTORE_TYPE__ALL = 1,
2370
  RESTORE_TYPE__MNODE,
2371
  RESTORE_TYPE__VNODE,
2372
  RESTORE_TYPE__QNODE,
2373
};
2374

2375
typedef struct {
2376
  int32_t dnodeId;
2377
  int8_t  restoreType;
2378
  int32_t sqlLen;
2379
  char*   sql;
2380
} SRestoreDnodeReq;
2381

2382
int32_t tSerializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2383
int32_t tDeserializeSRestoreDnodeReq(void* buf, int32_t bufLen, SRestoreDnodeReq* pReq);
2384
void    tFreeSRestoreDnodeReq(SRestoreDnodeReq* pReq);
2385

2386
typedef struct {
2387
  int32_t dnodeId;
2388
  char    config[TSDB_DNODE_CONFIG_LEN];
2389
  char    value[TSDB_DNODE_VALUE_LEN];
2390
  int32_t sqlLen;
2391
  char*   sql;
2392
} SMCfgDnodeReq;
2393

2394
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2395
int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
2396
void    tFreeSMCfgDnodeReq(SMCfgDnodeReq* pReq);
2397

2398
typedef struct {
2399
  char config[TSDB_DNODE_CONFIG_LEN];
2400
  char value[TSDB_DNODE_VALUE_LEN];
2401
} SDCfgDnodeReq;
2402

2403
int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2404
int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq);
2405

2406
typedef struct {
2407
  int32_t dnodeId;
2408
  int32_t sqlLen;
2409
  char*   sql;
2410
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
2411
    SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
2412

2413
int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2414
int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
2415
void    tFreeSMCreateQnodeReq(SMCreateQnodeReq* pReq);
2416
void    tFreeSDDropQnodeReq(SDDropQnodeReq* pReq);
2417
typedef struct {
2418
  int8_t   replica;
2419
  SReplica replicas[TSDB_MAX_REPLICA];
2420
  int8_t   learnerReplica;
2421
  SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
2422
  int64_t  lastIndex;
2423
} SDCreateMnodeReq, SDAlterMnodeReq, SDAlterMnodeTypeReq;
2424

2425
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2426
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
2427

2428
typedef struct {
2429
  int32_t urlLen;
2430
  int32_t sqlLen;
2431
  char*   url;
2432
  char*   sql;
2433
} SMCreateAnodeReq;
2434

2435
int32_t tSerializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2436
int32_t tDeserializeSMCreateAnodeReq(void* buf, int32_t bufLen, SMCreateAnodeReq* pReq);
2437
void    tFreeSMCreateAnodeReq(SMCreateAnodeReq* pReq);
2438

2439
typedef struct {
2440
  int32_t anodeId;
2441
  int32_t sqlLen;
2442
  char*   sql;
2443
} SMDropAnodeReq, SMUpdateAnodeReq;
2444

2445
int32_t tSerializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2446
int32_t tDeserializeSMDropAnodeReq(void* buf, int32_t bufLen, SMDropAnodeReq* pReq);
2447
void    tFreeSMDropAnodeReq(SMDropAnodeReq* pReq);
2448
int32_t tSerializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2449
int32_t tDeserializeSMUpdateAnodeReq(void* buf, int32_t bufLen, SMUpdateAnodeReq* pReq);
2450
void    tFreeSMUpdateAnodeReq(SMUpdateAnodeReq* pReq);
2451

2452
typedef struct {
2453
  int32_t vgId;
2454
  int32_t hbSeq;
2455
} SVArbHbReqMember;
2456

2457
typedef struct {
2458
  int32_t dnodeId;
2459
  char*   arbToken;
2460
  int64_t arbTerm;
2461
  SArray* hbMembers;  // SVArbHbReqMember
2462
} SVArbHeartBeatReq;
2463

2464
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2465
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
2466
void    tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
2467

2468
typedef struct {
2469
  int32_t vgId;
2470
  char    memberToken[TSDB_ARB_TOKEN_SIZE];
2471
  int32_t hbSeq;
2472
} SVArbHbRspMember;
2473

2474
typedef struct {
2475
  char    arbToken[TSDB_ARB_TOKEN_SIZE];
2476
  int32_t dnodeId;
2477
  SArray* hbMembers;  // SVArbHbRspMember
2478
} SVArbHeartBeatRsp;
2479

2480
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2481
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
2482
void    tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
2483

2484
typedef struct {
2485
  char*   arbToken;
2486
  int64_t arbTerm;
2487
  char*   member0Token;
2488
  char*   member1Token;
2489
} SVArbCheckSyncReq;
2490

2491
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2492
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
2493
void    tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
2494

2495
typedef struct {
2496
  char*   arbToken;
2497
  char*   member0Token;
2498
  char*   member1Token;
2499
  int32_t vgId;
2500
  int32_t errCode;
2501
} SVArbCheckSyncRsp;
2502

2503
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2504
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
2505
void    tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
2506

2507
typedef struct {
2508
  char*   arbToken;
2509
  int64_t arbTerm;
2510
  char*   memberToken;
2511
} SVArbSetAssignedLeaderReq;
2512

2513
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2514
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
2515
void    tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
2516

2517
typedef struct {
2518
  char*   arbToken;
2519
  char*   memberToken;
2520
  int32_t vgId;
2521
} SVArbSetAssignedLeaderRsp;
2522

2523
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2524
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
2525
void    tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
2526

2527
typedef struct {
2528
  int32_t dnodeId;
2529
  char*   token;
2530
} SMArbUpdateGroupMember;
2531

2532
typedef struct {
2533
  int32_t dnodeId;
2534
  char*   token;
2535
  int8_t  acked;
2536
} SMArbUpdateGroupAssigned;
2537

2538
typedef struct {
2539
  int32_t                  vgId;
2540
  int64_t                  dbUid;
2541
  SMArbUpdateGroupMember   members[2];
2542
  int8_t                   isSync;
2543
  int8_t                   assignedAcked;
2544
  SMArbUpdateGroupAssigned assignedLeader;
2545
  int64_t                  version;
2546
} SMArbUpdateGroup;
2547

2548
typedef struct {
2549
  SArray* updateArray;  // SMArbUpdateGroup
2550
} SMArbUpdateGroupBatchReq;
2551

2552
int32_t tSerializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2553
int32_t tDeserializeSMArbUpdateGroupBatchReq(void* buf, int32_t bufLen, SMArbUpdateGroupBatchReq* pReq);
2554
void    tFreeSMArbUpdateGroupBatchReq(SMArbUpdateGroupBatchReq* pReq);
2555

2556
typedef struct {
2557
  char queryStrId[TSDB_QUERY_ID_LEN];
2558
} SKillQueryReq;
2559

2560
int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2561
int32_t tDeserializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq);
2562

2563
typedef struct {
2564
  uint32_t connId;
2565
} SKillConnReq;
2566

2567
int32_t tSerializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2568
int32_t tDeserializeSKillConnReq(void* buf, int32_t bufLen, SKillConnReq* pReq);
2569

2570
typedef struct {
2571
  int32_t transId;
2572
} SKillTransReq;
2573

2574
int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2575
int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq);
2576

2577
typedef struct {
2578
  int32_t useless;  // useless
2579
  int32_t sqlLen;
2580
  char*   sql;
2581
} SBalanceVgroupReq;
2582

2583
int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2584
int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq);
2585
void    tFreeSBalanceVgroupReq(SBalanceVgroupReq* pReq);
2586

2587
typedef struct {
2588
  int32_t vgId1;
2589
  int32_t vgId2;
2590
} SMergeVgroupReq;
2591

2592
int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2593
int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq);
2594

2595
typedef struct {
2596
  int32_t vgId;
2597
  int32_t dnodeId1;
2598
  int32_t dnodeId2;
2599
  int32_t dnodeId3;
2600
  int32_t sqlLen;
2601
  char*   sql;
2602
} SRedistributeVgroupReq;
2603

2604
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2605
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
2606
void    tFreeSRedistributeVgroupReq(SRedistributeVgroupReq* pReq);
2607

2608
typedef struct {
2609
  int32_t reserved;
2610
  int32_t vgId;
2611
  int32_t sqlLen;
2612
  char*   sql;
2613
  char    db[TSDB_DB_FNAME_LEN];
2614
} SBalanceVgroupLeaderReq;
2615

2616
int32_t tSerializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2617
int32_t tDeserializeSBalanceVgroupLeaderReq(void* buf, int32_t bufLen, SBalanceVgroupLeaderReq* pReq);
2618
void    tFreeSBalanceVgroupLeaderReq(SBalanceVgroupLeaderReq* pReq);
2619

2620
typedef struct {
2621
  int32_t vgId;
2622
} SForceBecomeFollowerReq;
2623

2624
int32_t tSerializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2625
// int32_t tDeserializeSForceBecomeFollowerReq(void* buf, int32_t bufLen, SForceBecomeFollowerReq* pReq);
2626

2627
typedef struct {
2628
  int32_t vgId;
2629
} SSplitVgroupReq;
2630

2631
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2632
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
2633

2634
typedef struct {
2635
  char user[TSDB_USER_LEN];
2636
  char spi;
2637
  char encrypt;
2638
  char secret[TSDB_PASSWORD_LEN];
2639
  char ckey[TSDB_PASSWORD_LEN];
2640
} SAuthReq, SAuthRsp;
2641

2642
// int32_t tSerializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2643
// int32_t tDeserializeSAuthReq(void* buf, int32_t bufLen, SAuthReq* pReq);
2644

2645
typedef struct {
2646
  int32_t statusCode;
2647
  char    details[1024];
2648
} SServerStatusRsp;
2649

2650
int32_t tSerializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2651
int32_t tDeserializeSServerStatusRsp(void* buf, int32_t bufLen, SServerStatusRsp* pRsp);
2652

2653
/**
2654
 * The layout of the query message payload is as following:
2655
 * +--------------------+---------------------------------+
2656
 * |Sql statement       | Physical plan                   |
2657
 * |(denoted by sqlLen) |(In JSON, denoted by contentLen) |
2658
 * +--------------------+---------------------------------+
2659
 */
2660
typedef struct SSubQueryMsg {
2661
  SMsgHead header;
2662
  uint64_t sId;
2663
  uint64_t queryId;
2664
  uint64_t clientId;
2665
  uint64_t taskId;
2666
  int64_t  refId;
2667
  int32_t  execId;
2668
  int32_t  msgMask;
2669
  int8_t   taskType;
2670
  int8_t   explain;
2671
  int8_t   needFetch;
2672
  int8_t   compress;
2673
  uint32_t sqlLen;
2674
  char*    sql;
2675
  uint32_t msgLen;
2676
  char*    msg;
2677
} SSubQueryMsg;
2678

2679
int32_t tSerializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2680
int32_t tDeserializeSSubQueryMsg(void* buf, int32_t bufLen, SSubQueryMsg* pReq);
2681
void    tFreeSSubQueryMsg(SSubQueryMsg* pReq);
2682

2683
typedef struct {
2684
  SMsgHead header;
2685
  uint64_t sId;
2686
  uint64_t queryId;
2687
  uint64_t taskId;
2688
} SSinkDataReq;
2689

2690
typedef struct {
2691
  SMsgHead header;
2692
  uint64_t sId;
2693
  uint64_t queryId;
2694
  uint64_t clientId;
2695
  uint64_t taskId;
2696
  int32_t  execId;
2697
} SQueryContinueReq;
2698

2699
typedef struct {
2700
  SMsgHead header;
2701
  uint64_t sId;
2702
  uint64_t queryId;
2703
  uint64_t taskId;
2704
} SResReadyReq;
2705

2706
typedef struct {
2707
  int32_t code;
2708
  char    tbFName[TSDB_TABLE_FNAME_LEN];
2709
  int32_t sversion;
2710
  int32_t tversion;
2711
} SResReadyRsp;
2712

2713
typedef struct SOperatorParam {
2714
  int32_t opType;
2715
  int32_t downstreamIdx;
2716
  void*   value;
2717
  SArray* pChildren;  // SArray<SOperatorParam*>
2718
} SOperatorParam;
2719

2720
typedef struct STableScanOperatorParam {
2721
  bool    tableSeq;
2722
  SArray* pUidList;
2723
} STableScanOperatorParam;
2724

2725
typedef struct {
2726
  SMsgHead        header;
2727
  uint64_t        sId;
2728
  uint64_t        queryId;
2729
  uint64_t        clientId;
2730
  uint64_t        taskId;
2731
  int32_t         execId;
2732
  SOperatorParam* pOpParam;
2733
} SResFetchReq;
2734

2735
int32_t tSerializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2736
int32_t tDeserializeSResFetchReq(void* buf, int32_t bufLen, SResFetchReq* pReq);
2737

2738
typedef struct {
2739
  SMsgHead header;
2740
  uint64_t sId;
2741
} SSchTasksStatusReq;
2742

2743
typedef struct {
2744
  uint64_t queryId;
2745
  uint64_t clientId;
2746
  uint64_t taskId;
2747
  int64_t  refId;
2748
  int32_t  execId;
2749
  int8_t   status;
2750
} STaskStatus;
2751

2752
typedef struct {
2753
  int64_t refId;
2754
  SArray* taskStatus;  // SArray<STaskStatus>
2755
} SSchedulerStatusRsp;
2756

2757
typedef struct {
2758
  uint64_t queryId;
2759
  uint64_t taskId;
2760
  int8_t   action;
2761
} STaskAction;
2762

2763
typedef struct SQueryNodeEpId {
2764
  int32_t nodeId;  // vgId or qnodeId
2765
  SEp     ep;
2766
} SQueryNodeEpId;
2767

2768
typedef struct {
2769
  SMsgHead       header;
2770
  uint64_t       sId;
2771
  SQueryNodeEpId epId;
2772
  SArray*        taskAction;  // SArray<STaskAction>
2773
} SSchedulerHbReq;
2774

2775
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2776
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
2777
void    tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
2778

2779
typedef struct {
2780
  SQueryNodeEpId epId;
2781
  SArray*        taskStatus;  // SArray<STaskStatus>
2782
} SSchedulerHbRsp;
2783

2784
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2785
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
2786
void    tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
2787

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

2798
typedef struct {
2799
  int32_t code;
2800
} STaskCancelRsp;
2801

2802
typedef struct {
2803
  SMsgHead header;
2804
  uint64_t sId;
2805
  uint64_t queryId;
2806
  uint64_t clientId;
2807
  uint64_t taskId;
2808
  int64_t  refId;
2809
  int32_t  execId;
2810
} STaskDropReq;
2811

2812
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2813
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
2814

2815
typedef enum {
2816
  TASK_NOTIFY_FINISHED = 1,
2817
} ETaskNotifyType;
2818

2819
typedef struct {
2820
  SMsgHead        header;
2821
  uint64_t        sId;
2822
  uint64_t        queryId;
2823
  uint64_t        clientId;
2824
  uint64_t        taskId;
2825
  int64_t         refId;
2826
  int32_t         execId;
2827
  ETaskNotifyType type;
2828
} STaskNotifyReq;
2829

2830
int32_t tSerializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2831
int32_t tDeserializeSTaskNotifyReq(void* buf, int32_t bufLen, STaskNotifyReq* pReq);
2832

2833
int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2834
int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp);
2835

2836
typedef struct {
2837
  int32_t code;
2838
} STaskDropRsp;
2839

2840
#define STREAM_TRIGGER_AT_ONCE            1
2841
#define STREAM_TRIGGER_WINDOW_CLOSE       2
2842
#define STREAM_TRIGGER_MAX_DELAY          3
2843
#define STREAM_TRIGGER_FORCE_WINDOW_CLOSE 4
2844

2845
#define STREAM_DEFAULT_IGNORE_EXPIRED 1
2846
#define STREAM_FILL_HISTORY_ON        1
2847
#define STREAM_FILL_HISTORY_OFF       0
2848
#define STREAM_DEFAULT_FILL_HISTORY   STREAM_FILL_HISTORY_OFF
2849
#define STREAM_DEFAULT_IGNORE_UPDATE  1
2850
#define STREAM_CREATE_STABLE_TRUE     1
2851
#define STREAM_CREATE_STABLE_FALSE    0
2852

2853
typedef struct SColLocation {
2854
  int16_t  slotId;
2855
  col_id_t colId;
2856
  int8_t   type;
2857
} SColLocation;
2858

2859
typedef struct SVgroupVer {
2860
  int32_t vgId;
2861
  int64_t ver;
2862
} SVgroupVer;
2863

2864
typedef struct {
2865
  char    name[TSDB_STREAM_FNAME_LEN];
2866
  char    sourceDB[TSDB_DB_FNAME_LEN];
2867
  char    targetStbFullName[TSDB_TABLE_FNAME_LEN];
2868
  char*   sql;
2869
  char*   ast;
2870
  int8_t  igExists;
2871
  int8_t  triggerType;
2872
  int8_t  igExpired;
2873
  int8_t  fillHistory;  // process data inserted before creating stream
2874
  int64_t maxDelay;
2875
  int64_t watermark;
2876
  int32_t numOfTags;
2877
  SArray* pTags;  // array of SField
2878
  // 3.0.20
2879
  int64_t checkpointFreq;  // ms
2880
  // 3.0.2.3
2881
  int8_t   createStb;
2882
  uint64_t targetStbUid;
2883
  SArray*  fillNullCols;  // array of SColLocation
2884
  int64_t  deleteMark;
2885
  int8_t   igUpdate;
2886
  int64_t  lastTs;
2887
  SArray*  pVgroupVerList;
2888
  // 3.3.0.0
2889
  SArray* pCols;  // array of SField
2890
  int64_t smaId;
2891
} SCMCreateStreamReq;
2892

2893
typedef struct {
2894
  int64_t streamId;
2895
} SCMCreateStreamRsp;
2896

2897
int32_t tSerializeSCMCreateStreamReq(void* buf, int32_t bufLen, const SCMCreateStreamReq* pReq);
2898
int32_t tDeserializeSCMCreateStreamReq(void* buf, int32_t bufLen, SCMCreateStreamReq* pReq);
2899
void    tFreeSCMCreateStreamReq(SCMCreateStreamReq* pReq);
2900

2901
enum {
2902
  TOPIC_SUB_TYPE__DB = 1,
2903
  TOPIC_SUB_TYPE__TABLE,
2904
  TOPIC_SUB_TYPE__COLUMN,
2905
};
2906

2907
#define DEFAULT_MAX_POLL_INTERVAL 300000
2908
#define DEFAULT_SESSION_TIMEOUT   12000
2909

2910
typedef struct {
2911
  char   name[TSDB_TOPIC_FNAME_LEN];  // accout.topic
2912
  int8_t igExists;
2913
  int8_t subType;
2914
  int8_t withMeta;
2915
  char*  sql;
2916
  char   subDbName[TSDB_DB_FNAME_LEN];
2917
  char*  ast;
2918
  char   subStbName[TSDB_TABLE_FNAME_LEN];
2919
} SCMCreateTopicReq;
2920

2921
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
2922
int32_t tDeserializeSCMCreateTopicReq(void* buf, int32_t bufLen, SCMCreateTopicReq* pReq);
2923
void    tFreeSCMCreateTopicReq(SCMCreateTopicReq* pReq);
2924

2925
typedef struct {
2926
  int64_t consumerId;
2927
} SMqConsumerRecoverMsg, SMqConsumerClearMsg;
2928

2929
typedef struct {
2930
  int64_t consumerId;
2931
  char    cgroup[TSDB_CGROUP_LEN];
2932
  char    clientId[TSDB_CLIENT_ID_LEN];
2933
  char    user[TSDB_USER_LEN];
2934
  char    fqdn[TSDB_FQDN_LEN];
2935
  SArray* topicNames;  // SArray<char**>
2936

2937
  int8_t  withTbName;
2938
  int8_t  autoCommit;
2939
  int32_t autoCommitInterval;
2940
  int8_t  resetOffsetCfg;
2941
  int8_t  enableReplay;
2942
  int8_t  enableBatchMeta;
2943
  int32_t sessionTimeoutMs;
2944
  int32_t maxPollIntervalMs;
2945
} SCMSubscribeReq;
2946

2947
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
2948
  int32_t tlen = 0;
2,586✔
2949
  tlen += taosEncodeFixedI64(buf, pReq->consumerId);
2,586!
2950
  tlen += taosEncodeString(buf, pReq->cgroup);
2,586✔
2951
  tlen += taosEncodeString(buf, pReq->clientId);
2,586✔
2952

2953
  int32_t topicNum = taosArrayGetSize(pReq->topicNames);
2,586!
2954
  tlen += taosEncodeFixedI32(buf, topicNum);
2,586✔
2955

2956
  for (int32_t i = 0; i < topicNum; i++) {
3,628✔
2957
    tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
2,084✔
2958
  }
2959

2960
  tlen += taosEncodeFixedI8(buf, pReq->withTbName);
2,586!
2961
  tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
2,586!
2962
  tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
2,586!
2963
  tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
2,586!
2964
  tlen += taosEncodeFixedI8(buf, pReq->enableReplay);
2,586!
2965
  tlen += taosEncodeFixedI8(buf, pReq->enableBatchMeta);
2,586!
2966
  tlen += taosEncodeFixedI32(buf, pReq->sessionTimeoutMs);
2,586!
2967
  tlen += taosEncodeFixedI32(buf, pReq->maxPollIntervalMs);
2,586!
2968
  tlen += taosEncodeString(buf, pReq->user);
2,586✔
2969
  tlen += taosEncodeString(buf, pReq->fqdn);
2,586✔
2970

2971
  return tlen;
2,586✔
2972
}
2973

2974
static FORCE_INLINE int32_t tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq, int32_t len) {
2975
  void* start = buf;
1,404✔
2976
  buf = taosDecodeFixedI64(buf, &pReq->consumerId);
1,404!
2977
  buf = taosDecodeStringTo(buf, pReq->cgroup);
1,404✔
2978
  buf = taosDecodeStringTo(buf, pReq->clientId);
1,404✔
2979

2980
  int32_t topicNum = 0;
1,404!
2981
  buf = taosDecodeFixedI32(buf, &topicNum);
1,404✔
2982

2983
  pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
1,404✔
2984
  if (pReq->topicNames == NULL) {
1,404!
2985
    return terrno;
×
2986
  }
2987
  for (int32_t i = 0; i < topicNum; i++) {
2,036✔
2988
    char* name = NULL;
632✔
2989
    buf = taosDecodeString(buf, &name);
632✔
2990
    if (taosArrayPush(pReq->topicNames, &name) == NULL) {
1,264!
2991
      return terrno;
×
2992
    }
2993
  }
2994

2995
  buf = taosDecodeFixedI8(buf, &pReq->withTbName);
1,404✔
2996
  buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
1,404✔
2997
  buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
1,404!
2998
  buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
1,404✔
2999
  buf = taosDecodeFixedI8(buf, &pReq->enableReplay);
1,404✔
3000
  buf = taosDecodeFixedI8(buf, &pReq->enableBatchMeta);
1,404✔
3001
  if ((char*)buf - (char*)start < len) {
1,404!
3002
    buf = taosDecodeFixedI32(buf, &pReq->sessionTimeoutMs);
1,404!
3003
    buf = taosDecodeFixedI32(buf, &pReq->maxPollIntervalMs);
1,404!
3004
    buf = taosDecodeStringTo(buf, pReq->user);
1,404✔
3005
    buf = taosDecodeStringTo(buf, pReq->fqdn);
2,808✔
3006
  } else {
3007
    pReq->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
×
3008
    pReq->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
×
3009
  }
3010

3011
  return 0;
1,404✔
3012
}
3013

3014
typedef struct {
3015
  char    key[TSDB_SUBSCRIBE_KEY_LEN];
3016
  SArray* removedConsumers;  // SArray<int64_t>
3017
  SArray* newConsumers;      // SArray<int64_t>
3018
} SMqRebInfo;
3019

3020
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
3021
  SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
1,338✔
3022
  if (pRebInfo == NULL) {
1,338!
3023
    return NULL;
×
3024
  }
3025
  tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
1,338✔
3026
  pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
1,338✔
3027
  if (pRebInfo->removedConsumers == NULL) {
1,338!
3028
    goto _err;
×
3029
  }
3030
  pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t));
1,338✔
3031
  if (pRebInfo->newConsumers == NULL) {
1,338!
3032
    goto _err;
×
3033
  }
3034
  return pRebInfo;
1,338✔
3035
_err:
×
3036
  taosArrayDestroy(pRebInfo->removedConsumers);
×
3037
  taosArrayDestroy(pRebInfo->newConsumers);
×
3038
  taosMemoryFreeClear(pRebInfo);
×
3039
  return NULL;
×
3040
}
3041

3042
typedef struct {
3043
  int64_t streamId;
3044
  int64_t checkpointId;
3045
  char    streamName[TSDB_STREAM_FNAME_LEN];
3046
} SMStreamDoCheckpointMsg;
3047

3048
typedef struct {
3049
  int64_t status;
3050
} SMVSubscribeRsp;
3051

3052
typedef struct {
3053
  char    name[TSDB_TOPIC_FNAME_LEN];
3054
  int8_t  igNotExists;
3055
  int32_t sqlLen;
3056
  char*   sql;
3057
} SMDropTopicReq;
3058

3059
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3060
int32_t tDeserializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
3061
void    tFreeSMDropTopicReq(SMDropTopicReq* pReq);
3062

3063
typedef struct {
3064
  char   topic[TSDB_TOPIC_FNAME_LEN];
3065
  char   cgroup[TSDB_CGROUP_LEN];
3066
  int8_t igNotExists;
3067
} SMDropCgroupReq;
3068

3069
int32_t tSerializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3070
int32_t tDeserializeSMDropCgroupReq(void* buf, int32_t bufLen, SMDropCgroupReq* pReq);
3071

3072
typedef struct {
3073
  int8_t reserved;
3074
} SMDropCgroupRsp;
3075

3076
typedef struct {
3077
  char    name[TSDB_TABLE_FNAME_LEN];
3078
  int8_t  alterType;
3079
  SSchema schema;
3080
} SAlterTopicReq;
3081

3082
typedef struct {
3083
  SMsgHead head;
3084
  char     name[TSDB_TABLE_FNAME_LEN];
3085
  int64_t  tuid;
3086
  int32_t  sverson;
3087
  int32_t  execLen;
3088
  char*    executor;
3089
  int32_t  sqlLen;
3090
  char*    sql;
3091
} SDCreateTopicReq;
3092

3093
typedef struct {
3094
  SMsgHead head;
3095
  char     name[TSDB_TABLE_FNAME_LEN];
3096
  int64_t  tuid;
3097
} SDDropTopicReq;
3098

3099
typedef struct {
3100
  int64_t maxdelay[2];
3101
  int64_t watermark[2];
3102
  int64_t deleteMark[2];
3103
  int32_t qmsgLen[2];
3104
  char*   qmsg[2];  // pAst:qmsg:SRetention => trigger aggr task1/2
3105
} SRSmaParam;
3106

3107
int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam);
3108
int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
3109

3110
// TDMT_VND_CREATE_STB ==============
3111
typedef struct SVCreateStbReq {
3112
  char*           name;
3113
  tb_uid_t        suid;
3114
  int8_t          rollup;
3115
  SSchemaWrapper  schemaRow;
3116
  SSchemaWrapper  schemaTag;
3117
  SRSmaParam      rsmaParam;
3118
  int32_t         alterOriDataLen;
3119
  void*           alterOriData;
3120
  int8_t          source;
3121
  int8_t          colCmpred;
3122
  SColCmprWrapper colCmpr;
3123
} SVCreateStbReq;
3124

3125
int tEncodeSVCreateStbReq(SEncoder* pCoder, const SVCreateStbReq* pReq);
3126
int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
3127

3128
// TDMT_VND_DROP_STB ==============
3129
typedef struct SVDropStbReq {
3130
  char*    name;
3131
  tb_uid_t suid;
3132
} SVDropStbReq;
3133

3134
int32_t tEncodeSVDropStbReq(SEncoder* pCoder, const SVDropStbReq* pReq);
3135
int32_t tDecodeSVDropStbReq(SDecoder* pCoder, SVDropStbReq* pReq);
3136

3137
// TDMT_VND_CREATE_TABLE ==============
3138
#define TD_CREATE_IF_NOT_EXISTS 0x1
3139
typedef struct SVCreateTbReq {
3140
  int32_t  flags;
3141
  char*    name;
3142
  tb_uid_t uid;
3143
  int64_t  btime;
3144
  int32_t  ttl;
3145
  int32_t  commentLen;
3146
  char*    comment;
3147
  int8_t   type;
3148
  union {
3149
    struct {
3150
      char*    stbName;  // super table name
3151
      uint8_t  tagNum;
3152
      tb_uid_t suid;
3153
      SArray*  tagName;
3154
      uint8_t* pTag;
3155
    } ctb;
3156
    struct {
3157
      SSchemaWrapper schemaRow;
3158
    } ntb;
3159
  };
3160
  int32_t         sqlLen;
3161
  char*           sql;
3162
  SColCmprWrapper colCmpr;
3163
} SVCreateTbReq;
3164

3165
int  tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
3166
int  tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
3167
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
3168

3169
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
6,727✔
3170
  if (NULL == req) {
21,403,826!
3171
    return;
21,227,641✔
3172
  }
3173

3174
  taosMemoryFreeClear(req->sql);
176,185!
3175
  taosMemoryFreeClear(req->name);
176,185!
3176
  taosMemoryFreeClear(req->comment);
176,189!
3177
  if (req->type == TSDB_CHILD_TABLE) {
176,189!
3178
    taosMemoryFreeClear(req->ctb.pTag);
162,673!
3179
    taosMemoryFreeClear(req->ctb.stbName);
162,682!
3180
    taosArrayDestroy(req->ctb.tagName);
162,682✔
3181
    req->ctb.tagName = NULL;
162,679✔
3182
  } else if (req->type == TSDB_NORMAL_TABLE) {
13,518!
3183
    taosMemoryFreeClear(req->ntb.schemaRow.pSchema);
13,516!
3184
  }
3185
  taosMemoryFreeClear(req->colCmpr.pColCmpr);
176,195!
3186
}
3187

3188
typedef struct {
3189
  int32_t nReqs;
3190
  union {
3191
    SVCreateTbReq* pReqs;
3192
    SArray*        pArray;
3193
  };
3194
  int8_t source;  // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3195
} SVCreateTbBatchReq;
3196

3197
int  tEncodeSVCreateTbBatchReq(SEncoder* pCoder, const SVCreateTbBatchReq* pReq);
3198
int  tDecodeSVCreateTbBatchReq(SDecoder* pCoder, SVCreateTbBatchReq* pReq);
3199
void tDeleteSVCreateTbBatchReq(SVCreateTbBatchReq* pReq);
3200

3201
typedef struct {
3202
  int32_t        code;
3203
  STableMetaRsp* pMeta;
3204
} SVCreateTbRsp, SVUpdateTbRsp;
3205

3206
int  tEncodeSVCreateTbRsp(SEncoder* pCoder, const SVCreateTbRsp* pRsp);
3207
int  tDecodeSVCreateTbRsp(SDecoder* pCoder, SVCreateTbRsp* pRsp);
3208
void tFreeSVCreateTbRsp(void* param);
3209

3210
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
3211
void*   tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
3212

3213
typedef struct {
3214
  int32_t nRsps;
3215
  union {
3216
    SVCreateTbRsp* pRsps;
3217
    SArray*        pArray;
3218
  };
3219
} SVCreateTbBatchRsp;
3220

3221
int tEncodeSVCreateTbBatchRsp(SEncoder* pCoder, const SVCreateTbBatchRsp* pRsp);
3222
int tDecodeSVCreateTbBatchRsp(SDecoder* pCoder, SVCreateTbBatchRsp* pRsp);
3223

3224
// int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3225
// int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
3226

3227
// TDMT_VND_DROP_TABLE =================
3228
typedef struct {
3229
  char*    name;
3230
  uint64_t suid;  // for tmq in wal format
3231
  int64_t  uid;
3232
  int8_t   igNotExists;
3233
} SVDropTbReq;
3234

3235
typedef struct {
3236
  int32_t code;
3237
} SVDropTbRsp;
3238

3239
typedef struct {
3240
  int32_t nReqs;
3241
  union {
3242
    SVDropTbReq* pReqs;
3243
    SArray*      pArray;
3244
  };
3245
} SVDropTbBatchReq;
3246

3247
int32_t tEncodeSVDropTbBatchReq(SEncoder* pCoder, const SVDropTbBatchReq* pReq);
3248
int32_t tDecodeSVDropTbBatchReq(SDecoder* pCoder, SVDropTbBatchReq* pReq);
3249

3250
typedef struct {
3251
  int32_t nRsps;
3252
  union {
3253
    SVDropTbRsp* pRsps;
3254
    SArray*      pArray;
3255
  };
3256
} SVDropTbBatchRsp;
3257

3258
int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
3259
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
3260

3261
// TDMT_VND_ALTER_TABLE =====================
3262
typedef struct {
3263
  char*   tbName;
3264
  int8_t  action;
3265
  char*   colName;
3266
  int32_t colId;
3267
  // TSDB_ALTER_TABLE_ADD_COLUMN
3268
  int8_t  type;
3269
  int8_t  flags;
3270
  int32_t bytes;
3271
  // TSDB_ALTER_TABLE_DROP_COLUMN
3272
  // TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
3273
  int8_t   colModType;
3274
  int32_t  colModBytes;
3275
  char*    colNewName;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
3276
  char*    tagName;     // TSDB_ALTER_TABLE_UPDATE_TAG_VAL
3277
  int8_t   isNull;
3278
  int8_t   tagType;
3279
  int8_t   tagFree;
3280
  uint32_t nTagVal;
3281
  uint8_t* pTagVal;
3282
  SArray*  pTagArray;
3283
  // TSDB_ALTER_TABLE_UPDATE_OPTIONS
3284
  int8_t   updateTTL;
3285
  int32_t  newTTL;
3286
  int32_t  newCommentLen;
3287
  char*    newComment;
3288
  int64_t  ctimeMs;   // fill by vnode
3289
  int8_t   source;    // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
3290
  uint32_t compress;  // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
3291
} SVAlterTbReq;
3292

3293
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
3294
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
3295
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
3296

3297
typedef struct {
3298
  int32_t        code;
3299
  STableMetaRsp* pMeta;
3300
} SVAlterTbRsp;
3301

3302
int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp);
3303
int32_t tDecodeSVAlterTbRsp(SDecoder* pDecoder, SVAlterTbRsp* pRsp);
3304
// ======================
3305

3306
typedef struct {
3307
  SMsgHead head;
3308
  int64_t  uid;
3309
  int32_t  tid;
3310
  int16_t  tversion;
3311
  int16_t  colId;
3312
  int8_t   type;
3313
  int16_t  bytes;
3314
  int32_t  tagValLen;
3315
  int16_t  numOfTags;
3316
  int32_t  schemaLen;
3317
  char     data[];
3318
} SUpdateTagValReq;
3319

3320
typedef struct {
3321
  SMsgHead head;
3322
} SUpdateTagValRsp;
3323

3324
typedef struct {
3325
  SMsgHead head;
3326
} SVShowTablesReq;
3327

3328
typedef struct {
3329
  SMsgHead head;
3330
  int32_t  id;
3331
} SVShowTablesFetchReq;
3332

3333
typedef struct {
3334
  int64_t useconds;
3335
  int8_t  completed;  // all results are returned to client
3336
  int8_t  precision;
3337
  int8_t  compressed;
3338
  int32_t compLen;
3339
  int32_t numOfRows;
3340
  char    data[];
3341
} SVShowTablesFetchRsp;
3342

3343
typedef struct {
3344
  int64_t consumerId;
3345
  int32_t epoch;
3346
  char    cgroup[TSDB_CGROUP_LEN];
3347
} SMqAskEpReq;
3348

3349
typedef struct {
3350
  int32_t key;
3351
  int32_t valueLen;
3352
  void*   value;
3353
} SKv;
3354

3355
typedef struct {
3356
  int64_t tscRid;
3357
  int8_t  connType;
3358
} SClientHbKey;
3359

3360
typedef struct {
3361
  int64_t tid;
3362
  char    status[TSDB_JOB_STATUS_LEN];
3363
} SQuerySubDesc;
3364

3365
typedef struct {
3366
  char     sql[TSDB_SHOW_SQL_LEN];
3367
  uint64_t queryId;
3368
  int64_t  useconds;
3369
  int64_t  stime;  // timestamp precision ms
3370
  int64_t  reqRid;
3371
  bool     stableQuery;
3372
  bool     isSubQuery;
3373
  char     fqdn[TSDB_FQDN_LEN];
3374
  int32_t  subPlanNum;
3375
  SArray*  subDesc;  // SArray<SQuerySubDesc>
3376
} SQueryDesc;
3377

3378
typedef struct {
3379
  uint32_t connId;
3380
  SArray*  queryDesc;  // SArray<SQueryDesc>
3381
} SQueryHbReqBasic;
3382

3383
typedef struct {
3384
  uint32_t connId;
3385
  uint64_t killRid;
3386
  int32_t  totalDnodes;
3387
  int32_t  onlineDnodes;
3388
  int8_t   killConnection;
3389
  int8_t   align[3];
3390
  SEpSet   epSet;
3391
  SArray*  pQnodeList;
3392
} SQueryHbRspBasic;
3393

3394
typedef struct SAppClusterSummary {
3395
  uint64_t numOfInsertsReq;
3396
  uint64_t numOfInsertRows;
3397
  uint64_t insertElapsedTime;
3398
  uint64_t insertBytes;  // submit to tsdb since launched.
3399

3400
  uint64_t fetchBytes;
3401
  uint64_t numOfQueryReq;
3402
  uint64_t queryElapsedTime;
3403
  uint64_t numOfSlowQueries;
3404
  uint64_t totalRequests;
3405
  uint64_t currentRequests;  // the number of SRequestObj
3406
} SAppClusterSummary;
3407

3408
typedef struct {
3409
  int64_t            appId;
3410
  int32_t            pid;
3411
  char               name[TSDB_APP_NAME_LEN];
3412
  int64_t            startTime;
3413
  SAppClusterSummary summary;
3414
} SAppHbReq;
3415

3416
typedef struct {
3417
  SClientHbKey      connKey;
3418
  int64_t           clusterId;
3419
  SAppHbReq         app;
3420
  SQueryHbReqBasic* query;
3421
  SHashObj*         info;  // hash<Skv.key, Skv>
3422
} SClientHbReq;
3423

3424
typedef struct {
3425
  int64_t reqId;
3426
  SArray* reqs;  // SArray<SClientHbReq>
3427
  int64_t ipWhiteList;
3428
} SClientHbBatchReq;
3429

3430
typedef struct {
3431
  SClientHbKey      connKey;
3432
  int32_t           status;
3433
  SQueryHbRspBasic* query;
3434
  SArray*           info;  // Array<Skv>
3435
} SClientHbRsp;
3436

3437
typedef struct {
3438
  int64_t       reqId;
3439
  int64_t       rspId;
3440
  int32_t       svrTimestamp;
3441
  SArray*       rsps;  // SArray<SClientHbRsp>
3442
  SMonitorParas monitorParas;
3443
  int8_t        enableAuditDelete;
3444
} SClientHbBatchRsp;
3445

3446
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
202,099✔
3447

3448
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
3449
  void* pIter = taosHashIterate(info, NULL);
482,124✔
3450
  while (pIter != NULL) {
830,915!
3451
    SKv* kv = (SKv*)pIter;
348,751✔
3452
    taosMemoryFreeClear(kv->value);
348,751!
3453
    pIter = taosHashIterate(info, pIter);
348,751✔
3454
  }
3455
}
482,164✔
3456

3457
static FORCE_INLINE void tFreeClientHbQueryDesc(void* pDesc) {
281,604✔
3458
  SQueryDesc* desc = (SQueryDesc*)pDesc;
281,604✔
3459
  if (desc->subDesc) {
281,604✔
3460
    taosArrayDestroy(desc->subDesc);
275,375✔
3461
    desc->subDesc = NULL;
275,373✔
3462
  }
3463
}
281,602✔
3464

3465
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
567,645✔
3466
  SClientHbReq* req = (SClientHbReq*)pReq;
579,066✔
3467
  if (req->query) {
579,066!
3468
    if (req->query->queryDesc) {
558,813!
3469
      taosArrayDestroyEx(req->query->queryDesc, tFreeClientHbQueryDesc);
39,813✔
3470
    }
3471
    taosMemoryFreeClear(req->query);
558,813!
3472
  }
3473

3474
  if (req->info) {
579,070!
3475
    tFreeReqKvHash(req->info);
482,124✔
3476
    taosHashCleanup(req->info);
482,164✔
3477
    req->info = NULL;
482,128✔
3478
  }
3479
}
463,043✔
3480

3481
int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
3482
int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
3483

3484
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
3485
  if (pReq == NULL) return;
37,790!
3486
  SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
37,790✔
3487
  taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
37,790✔
3488
  taosMemoryFree(pReq);
37,790✔
3489
}
3490

3491
static FORCE_INLINE void tFreeClientKv(void* pKv) {
129,440✔
3492
  SKv* kv = (SKv*)pKv;
129,440✔
3493
  if (kv) {
129,440!
3494
    taosMemoryFreeClear(kv->value);
129,440!
3495
  }
3496
}
129,440✔
3497

3498
static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
565,277✔
3499
  SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
565,277✔
3500
  if (rsp->query) {
565,277✔
3501
    taosArrayDestroy(rsp->query->pQnodeList);
556,529✔
3502
    taosMemoryFreeClear(rsp->query);
556,691!
3503
  }
3504
  if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
565,531!
3505
}
113,930✔
3506

3507
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
3508
  SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
404,984✔
3509
  taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
404,984✔
3510
}
405,117✔
3511

3512
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
3513
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
3514
void    tFreeSClientHbBatchRsp(SClientHbBatchRsp* pBatchRsp);
3515

3516
static FORCE_INLINE int32_t tEncodeSKv(SEncoder* pEncoder, const SKv* pKv) {
3517
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->key));
632,730!
3518
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pKv->valueLen));
632,730!
3519
  TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, (uint8_t*)pKv->value, pKv->valueLen));
632,730!
3520
  return 0;
316,365✔
3521
}
3522

3523
static FORCE_INLINE int32_t tDecodeSKv(SDecoder* pDecoder, SKv* pKv) {
3524
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->key));
639,978!
3525
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pKv->valueLen));
639,985!
3526
  pKv->value = taosMemoryMalloc(pKv->valueLen + 1);
319,996✔
3527
  if (pKv->value == NULL) {
319,997!
3528
    TAOS_CHECK_RETURN(TSDB_CODE_OUT_OF_MEMORY);
×
3529
  }
3530
  TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, (char*)pKv->value));
319,997!
3531
  return 0;
319,991✔
3532
}
3533

3534
static FORCE_INLINE int32_t tEncodeSClientHbKey(SEncoder* pEncoder, const SClientHbKey* pKey) {
3535
  TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pKey->tscRid));
2,269,596!
3536
  TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pKey->connType));
2,269,596!
3537
  return 0;
1,134,798✔
3538
}
3539

3540
static FORCE_INLINE int32_t tDecodeSClientHbKey(SDecoder* pDecoder, SClientHbKey* pKey) {
3541
  TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pKey->tscRid));
1,130,977!
3542
  TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pKey->connType));
1,130,977!
3543
  return 0;
565,474✔
3544
}
3545

3546
typedef struct {
3547
  int32_t vgId;
3548
  // TODO stas
3549
} SMqReportVgInfo;
3550

3551
static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqReportVgInfo* pVgInfo) {
3552
  int32_t tlen = 0;
3553
  tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
3554
  return tlen;
3555
}
3556

3557
static FORCE_INLINE void* taosDecodeSMqVgInfo(void* buf, SMqReportVgInfo* pVgInfo) {
3558
  buf = taosDecodeFixedI32(buf, &pVgInfo->vgId);
3559
  return buf;
3560
}
3561

3562
typedef struct {
3563
  int32_t epoch;
3564
  int64_t topicUid;
3565
  char    name[TSDB_TOPIC_FNAME_LEN];
3566
  SArray* pVgInfo;  // SArray<SMqHbVgInfo>
3567
} SMqTopicInfo;
3568

3569
static FORCE_INLINE int32_t taosEncodeSMqTopicInfoMsg(void** buf, const SMqTopicInfo* pTopicInfo) {
3570
  int32_t tlen = 0;
3571
  tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
3572
  tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
3573
  tlen += taosEncodeString(buf, pTopicInfo->name);
3574
  int32_t sz = taosArrayGetSize(pTopicInfo->pVgInfo);
3575
  tlen += taosEncodeFixedI32(buf, sz);
3576
  for (int32_t i = 0; i < sz; i++) {
3577
    SMqReportVgInfo* pVgInfo = (SMqReportVgInfo*)taosArrayGet(pTopicInfo->pVgInfo, i);
3578
    tlen += taosEncodeSMqVgInfo(buf, pVgInfo);
3579
  }
3580
  return tlen;
3581
}
3582

3583
static FORCE_INLINE void* taosDecodeSMqTopicInfoMsg(void* buf, SMqTopicInfo* pTopicInfo) {
3584
  buf = taosDecodeFixedI32(buf, &pTopicInfo->epoch);
3585
  buf = taosDecodeFixedI64(buf, &pTopicInfo->topicUid);
3586
  buf = taosDecodeStringTo(buf, pTopicInfo->name);
3587
  int32_t sz;
3588
  buf = taosDecodeFixedI32(buf, &sz);
3589
  if ((pTopicInfo->pVgInfo = taosArrayInit(sz, sizeof(SMqReportVgInfo))) == NULL) {
3590
    return NULL;
3591
  }
3592
  for (int32_t i = 0; i < sz; i++) {
3593
    SMqReportVgInfo vgInfo;
3594
    buf = taosDecodeSMqVgInfo(buf, &vgInfo);
3595
    if (taosArrayPush(pTopicInfo->pVgInfo, &vgInfo) == NULL) {
3596
      return NULL;
3597
    }
3598
  }
3599
  return buf;
3600
}
3601

3602
typedef struct {
3603
  int32_t status;  // ask hb endpoint
3604
  int32_t epoch;
3605
  int64_t consumerId;
3606
  SArray* pTopics;  // SArray<SMqHbTopicInfo>
3607
} SMqReportReq;
3608

3609
static FORCE_INLINE int32_t taosEncodeSMqReportMsg(void** buf, const SMqReportReq* pMsg) {
3610
  int32_t tlen = 0;
3611
  tlen += taosEncodeFixedI32(buf, pMsg->status);
3612
  tlen += taosEncodeFixedI32(buf, pMsg->epoch);
3613
  tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
3614
  int32_t sz = taosArrayGetSize(pMsg->pTopics);
3615
  tlen += taosEncodeFixedI32(buf, sz);
3616
  for (int32_t i = 0; i < sz; i++) {
3617
    SMqTopicInfo* topicInfo = (SMqTopicInfo*)taosArrayGet(pMsg->pTopics, i);
3618
    tlen += taosEncodeSMqTopicInfoMsg(buf, topicInfo);
3619
  }
3620
  return tlen;
3621
}
3622

3623
static FORCE_INLINE void* taosDecodeSMqReportMsg(void* buf, SMqReportReq* pMsg) {
3624
  buf = taosDecodeFixedI32(buf, &pMsg->status);
3625
  buf = taosDecodeFixedI32(buf, &pMsg->epoch);
3626
  buf = taosDecodeFixedI64(buf, &pMsg->consumerId);
3627
  int32_t sz;
3628
  buf = taosDecodeFixedI32(buf, &sz);
3629
  if ((pMsg->pTopics = taosArrayInit(sz, sizeof(SMqTopicInfo))) == NULL) {
3630
    return NULL;
3631
  }
3632
  for (int32_t i = 0; i < sz; i++) {
3633
    SMqTopicInfo topicInfo;
3634
    buf = taosDecodeSMqTopicInfoMsg(buf, &topicInfo);
3635
    if (taosArrayPush(pMsg->pTopics, &topicInfo) == NULL) {
3636
      return NULL;
3637
    }
3638
  }
3639
  return buf;
3640
}
3641

3642
typedef struct {
3643
  SMsgHead head;
3644
  int64_t  leftForVer;
3645
  int32_t  vgId;
3646
  int64_t  consumerId;
3647
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
3648
} SMqVDeleteReq;
3649

3650
typedef struct {
3651
  int8_t reserved;
3652
} SMqVDeleteRsp;
3653

3654
typedef struct {
3655
  char    name[TSDB_STREAM_FNAME_LEN];
3656
  int8_t  igNotExists;
3657
  int32_t sqlLen;
3658
  char*   sql;
3659
} SMDropStreamReq;
3660

3661
typedef struct {
3662
  int8_t reserved;
3663
} SMDropStreamRsp;
3664

3665
typedef struct {
3666
  SMsgHead head;
3667
  int64_t  resetRelHalt;  // reset related stream task halt status
3668
  int64_t  streamId;
3669
  int32_t  taskId;
3670
} SVDropStreamTaskReq;
3671

3672
typedef struct {
3673
  int8_t reserved;
3674
} SVDropStreamTaskRsp;
3675

3676
int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq);
3677
int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq);
3678
void    tFreeMDropStreamReq(SMDropStreamReq* pReq);
3679

3680
typedef struct SVUpdateCheckpointInfoReq {
3681
  SMsgHead head;
3682
  int64_t  streamId;
3683
  int32_t  taskId;
3684
  int64_t  checkpointId;
3685
  int64_t  checkpointVer;
3686
  int64_t  checkpointTs;
3687
  int32_t  transId;
3688
  int64_t  hStreamId;  // add encode/decode
3689
  int64_t  hTaskId;
3690
  int8_t   dropRelHTask;
3691
} SVUpdateCheckpointInfoReq;
3692

3693
typedef struct {
3694
  int64_t leftForVer;
3695
  int32_t vgId;
3696
  int64_t oldConsumerId;
3697
  int64_t newConsumerId;
3698
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
3699
  int8_t  subType;
3700
  int8_t  withMeta;
3701
  char*   qmsg;  // SubPlanToString
3702
  int64_t suid;
3703
} SMqRebVgReq;
3704

3705
int32_t tEncodeSMqRebVgReq(SEncoder* pCoder, const SMqRebVgReq* pReq);
3706
int32_t tDecodeSMqRebVgReq(SDecoder* pCoder, SMqRebVgReq* pReq);
3707

3708
typedef struct {
3709
  char    topic[TSDB_TOPIC_FNAME_LEN];
3710
  int64_t ntbUid;
3711
  SArray* colIdList;  // SArray<int16_t>
3712
} STqCheckInfo;
3713

3714
int32_t tEncodeSTqCheckInfo(SEncoder* pEncoder, const STqCheckInfo* pInfo);
3715
int32_t tDecodeSTqCheckInfo(SDecoder* pDecoder, STqCheckInfo* pInfo);
3716
void    tDeleteSTqCheckInfo(STqCheckInfo* pInfo);
3717

3718
// tqOffset
3719
enum {
3720
  TMQ_OFFSET__RESET_NONE = -3,
3721
  TMQ_OFFSET__RESET_EARLIEST = -2,
3722
  TMQ_OFFSET__RESET_LATEST = -1,
3723
  TMQ_OFFSET__LOG = 1,
3724
  TMQ_OFFSET__SNAPSHOT_DATA = 2,
3725
  TMQ_OFFSET__SNAPSHOT_META = 3,
3726
};
3727

3728
enum {
3729
  WITH_DATA = 0,
3730
  WITH_META = 1,
3731
  ONLY_META = 2,
3732
};
3733

3734
#define TQ_OFFSET_VERSION 1
3735

3736
typedef struct {
3737
  int8_t type;
3738
  union {
3739
    // snapshot
3740
    struct {
3741
      int64_t uid;
3742
      int64_t ts;
3743
      SValue  primaryKey;
3744
    };
3745
    // log
3746
    struct {
3747
      int64_t version;
3748
    };
3749
  };
3750
} STqOffsetVal;
3751

3752
static FORCE_INLINE void tqOffsetResetToData(STqOffsetVal* pOffsetVal, int64_t uid, int64_t ts, SValue primaryKey) {
3753
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_DATA;
26,082✔
3754
  pOffsetVal->uid = uid;
26,082✔
3755
  pOffsetVal->ts = ts;
26,082✔
3756
  if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
26,082!
3757
    taosMemoryFree(pOffsetVal->primaryKey.pData);
×
3758
  }
3759
  pOffsetVal->primaryKey = primaryKey;
26,088✔
3760
}
26,088✔
3761

3762
static FORCE_INLINE void tqOffsetResetToMeta(STqOffsetVal* pOffsetVal, int64_t uid) {
3763
  pOffsetVal->type = TMQ_OFFSET__SNAPSHOT_META;
149✔
3764
  pOffsetVal->uid = uid;
149✔
3765
}
149✔
3766

3767
static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ver) {
3768
  pOffsetVal->type = TMQ_OFFSET__LOG;
646,860✔
3769
  pOffsetVal->version = ver;
646,860✔
3770
}
646,860✔
3771

3772
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
3773
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
3774
void    tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
3775
bool    tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3776
void    tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
3777
void    tOffsetDestroy(void* pVal);
3778

3779
typedef struct {
3780
  STqOffsetVal val;
3781
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
3782
} STqOffset;
3783

3784
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
3785
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
3786
void    tDeleteSTqOffset(void* val);
3787

3788
typedef struct SMqVgOffset {
3789
  int64_t   consumerId;
3790
  STqOffset offset;
3791
} SMqVgOffset;
3792

3793
int32_t tEncodeMqVgOffset(SEncoder* pEncoder, const SMqVgOffset* pOffset);
3794
int32_t tDecodeMqVgOffset(SDecoder* pDecoder, SMqVgOffset* pOffset);
3795

3796
typedef struct {
3797
  SMsgHead head;
3798
  int64_t  streamId;
3799
  int32_t  taskId;
3800
} SVPauseStreamTaskReq, SVResetStreamTaskReq;
3801

3802
typedef struct {
3803
  char   name[TSDB_STREAM_FNAME_LEN];
3804
  int8_t igNotExists;
3805
} SMPauseStreamReq;
3806

3807
int32_t tSerializeSMPauseStreamReq(void* buf, int32_t bufLen, const SMPauseStreamReq* pReq);
3808
int32_t tDeserializeSMPauseStreamReq(void* buf, int32_t bufLen, SMPauseStreamReq* pReq);
3809

3810
typedef struct {
3811
  SMsgHead head;
3812
  int32_t  taskId;
3813
  int64_t  streamId;
3814
  int8_t   igUntreated;
3815
} SVResumeStreamTaskReq;
3816

3817
typedef struct {
3818
  int8_t reserved;
3819
} SVResumeStreamTaskRsp;
3820

3821
typedef struct {
3822
  char   name[TSDB_STREAM_FNAME_LEN];
3823
  int8_t igNotExists;
3824
  int8_t igUntreated;
3825
} SMResumeStreamReq;
3826

3827
int32_t tSerializeSMResumeStreamReq(void* buf, int32_t bufLen, const SMResumeStreamReq* pReq);
3828
int32_t tDeserializeSMResumeStreamReq(void* buf, int32_t bufLen, SMResumeStreamReq* pReq);
3829

3830
typedef struct {
3831
  char    name[TSDB_TABLE_FNAME_LEN];
3832
  char    stb[TSDB_TABLE_FNAME_LEN];
3833
  int8_t  igExists;
3834
  int8_t  intervalUnit;
3835
  int8_t  slidingUnit;
3836
  int8_t  timezone;
3837
  int32_t dstVgId;  // for stream
3838
  int64_t interval;
3839
  int64_t offset;
3840
  int64_t sliding;
3841
  int64_t maxDelay;
3842
  int64_t watermark;
3843
  int32_t exprLen;        // strlen + 1
3844
  int32_t tagsFilterLen;  // strlen + 1
3845
  int32_t sqlLen;         // strlen + 1
3846
  int32_t astLen;         // strlen + 1
3847
  char*   expr;
3848
  char*   tagsFilter;
3849
  char*   sql;
3850
  char*   ast;
3851
  int64_t deleteMark;
3852
  int64_t lastTs;
3853
  int64_t normSourceTbUid;  // the Uid of source tb if its a normal table, otherwise 0
3854
  SArray* pVgroupVerList;
3855
  int8_t  recursiveTsma;
3856
  char    baseTsmaName[TSDB_TABLE_FNAME_LEN];  // base tsma name for recursively created tsma
3857
} SMCreateSmaReq;
3858

3859
int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3860
int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq);
3861
void    tFreeSMCreateSmaReq(SMCreateSmaReq* pReq);
3862

3863
typedef struct {
3864
  char   name[TSDB_TABLE_FNAME_LEN];
3865
  int8_t igNotExists;
3866
} SMDropSmaReq;
3867

3868
int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3869
int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq);
3870

3871
typedef struct {
3872
  char   dbFName[TSDB_DB_FNAME_LEN];
3873
  char   stbName[TSDB_TABLE_NAME_LEN];
3874
  char   colName[TSDB_COL_NAME_LEN];
3875
  char   idxName[TSDB_INDEX_FNAME_LEN];
3876
  int8_t idxType;
3877
} SCreateTagIndexReq;
3878

3879
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3880
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
3881

3882
typedef SMDropSmaReq SDropTagIndexReq;
3883

3884
// int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3885
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
3886

3887
typedef struct {
3888
  int8_t         version;       // for compatibility(default 0)
3889
  int8_t         intervalUnit;  // MACRO: TIME_UNIT_XXX
3890
  int8_t         slidingUnit;   // MACRO: TIME_UNIT_XXX
3891
  int8_t         timezoneInt;   // sma data expired if timezone changes.
3892
  int32_t        dstVgId;
3893
  char           indexName[TSDB_INDEX_NAME_LEN];
3894
  int32_t        exprLen;
3895
  int32_t        tagsFilterLen;
3896
  int64_t        indexUid;
3897
  tb_uid_t       tableUid;  // super/child/common table uid
3898
  tb_uid_t       dstTbUid;  // for dstVgroup
3899
  int64_t        interval;
3900
  int64_t        offset;  // use unit by precision of DB
3901
  int64_t        sliding;
3902
  char*          dstTbName;  // for dstVgroup
3903
  char*          expr;       // sma expression
3904
  char*          tagsFilter;
3905
  SSchemaWrapper schemaRow;  // for dstVgroup
3906
  SSchemaWrapper schemaTag;  // for dstVgroup
3907
} STSma;                     // Time-range-wise SMA
3908

3909
typedef STSma SVCreateTSmaReq;
3910

3911
typedef struct {
3912
  int8_t  type;  // 0 status report, 1 update data
3913
  int64_t indexUid;
3914
  int64_t skey;  // start TS key of interval/sliding window
3915
} STSmaMsg;
3916

3917
typedef struct {
3918
  int64_t indexUid;
3919
  char    indexName[TSDB_INDEX_NAME_LEN];
3920
} SVDropTSmaReq;
3921

3922
typedef struct {
3923
  int tmp;  // TODO: to avoid compile error
3924
} SVCreateTSmaRsp, SVDropTSmaRsp;
3925

3926
#if 0
3927
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
3928
void*   tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
3929
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
3930
void*   tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
3931
#endif
3932

3933
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3934
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3935
int32_t tEncodeSVDropTSmaReq(SEncoder* pCoder, const SVDropTSmaReq* pReq);
3936
// int32_t tDecodeSVDropTSmaReq(SDecoder* pCoder, SVDropTSmaReq* pReq);
3937

3938
typedef struct {
3939
  int32_t number;
3940
  STSma*  tSma;
3941
} STSmaWrapper;
3942

3943
static FORCE_INLINE void tDestroyTSma(STSma* pSma) {
3944
  if (pSma) {
3!
3945
    taosMemoryFreeClear(pSma->dstTbName);
3!
3946
    taosMemoryFreeClear(pSma->expr);
3!
3947
    taosMemoryFreeClear(pSma->tagsFilter);
3!
3948
  }
3949
}
3✔
3950

3951
static FORCE_INLINE void tDestroyTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
3952
  if (pSW) {
×
3953
    if (pSW->tSma) {
×
3954
      if (deepCopy) {
×
3955
        for (uint32_t i = 0; i < pSW->number; ++i) {
×
3956
          tDestroyTSma(pSW->tSma + i);
×
3957
        }
3958
      }
3959
      taosMemoryFreeClear(pSW->tSma);
×
3960
    }
3961
  }
3962
}
×
3963

3964
static FORCE_INLINE void* tFreeTSmaWrapper(STSmaWrapper* pSW, bool deepCopy) {
3965
  tDestroyTSmaWrapper(pSW, deepCopy);
×
3966
  taosMemoryFreeClear(pSW);
×
3967
  return NULL;
×
3968
}
3969

3970
int32_t tEncodeSVCreateTSmaReq(SEncoder* pCoder, const SVCreateTSmaReq* pReq);
3971
int32_t tDecodeSVCreateTSmaReq(SDecoder* pCoder, SVCreateTSmaReq* pReq);
3972

3973
int32_t tEncodeTSma(SEncoder* pCoder, const STSma* pSma);
3974
int32_t tDecodeTSma(SDecoder* pCoder, STSma* pSma, bool deepCopy);
3975

3976
static int32_t tEncodeTSmaWrapper(SEncoder* pEncoder, const STSmaWrapper* pReq) {
×
3977
  TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->number));
×
3978
  for (int32_t i = 0; i < pReq->number; ++i) {
×
3979
    TAOS_CHECK_RETURN(tEncodeTSma(pEncoder, pReq->tSma + i));
×
3980
  }
3981
  return 0;
×
3982
}
3983

3984
static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq, bool deepCopy) {
×
3985
  TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->number));
×
3986
  for (int32_t i = 0; i < pReq->number; ++i) {
×
3987
    TAOS_CHECK_RETURN(tDecodeTSma(pDecoder, pReq->tSma + i, deepCopy));
×
3988
  }
3989
  return 0;
×
3990
}
3991

3992
typedef struct {
3993
  int idx;
3994
} SMCreateFullTextReq;
3995

3996
int32_t tSerializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
3997
int32_t tDeserializeSMCreateFullTextReq(void* buf, int32_t bufLen, SMCreateFullTextReq* pReq);
3998
void    tFreeSMCreateFullTextReq(SMCreateFullTextReq* pReq);
3999

4000
typedef struct {
4001
  char   name[TSDB_TABLE_FNAME_LEN];
4002
  int8_t igNotExists;
4003
} SMDropFullTextReq;
4004

4005
// int32_t tSerializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4006
// int32_t tDeserializeSMDropFullTextReq(void* buf, int32_t bufLen, SMDropFullTextReq* pReq);
4007

4008
typedef struct {
4009
  char indexFName[TSDB_INDEX_FNAME_LEN];
4010
} SUserIndexReq;
4011

4012
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4013
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq);
4014

4015
typedef struct {
4016
  char dbFName[TSDB_DB_FNAME_LEN];
4017
  char tblFName[TSDB_TABLE_FNAME_LEN];
4018
  char colName[TSDB_COL_NAME_LEN];
4019
  char indexType[TSDB_INDEX_TYPE_LEN];
4020
  char indexExts[TSDB_INDEX_EXTS_LEN];
4021
} SUserIndexRsp;
4022

4023
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
4024
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
4025

4026
typedef struct {
4027
  char tbFName[TSDB_TABLE_FNAME_LEN];
4028
} STableIndexReq;
4029

4030
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4031
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
4032

4033
typedef struct {
4034
  int8_t  intervalUnit;
4035
  int8_t  slidingUnit;
4036
  int64_t interval;
4037
  int64_t offset;
4038
  int64_t sliding;
4039
  int64_t dstTbUid;
4040
  int32_t dstVgId;
4041
  SEpSet  epSet;
4042
  char*   expr;
4043
} STableIndexInfo;
4044

4045
typedef struct {
4046
  char     tbName[TSDB_TABLE_NAME_LEN];
4047
  char     dbFName[TSDB_DB_FNAME_LEN];
4048
  uint64_t suid;
4049
  int32_t  version;
4050
  int32_t  indexSize;
4051
  SArray*  pIndex;  // STableIndexInfo
4052
} STableIndexRsp;
4053

4054
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
4055
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
4056
void    tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp);
4057

4058
void tFreeSTableIndexInfo(void* pInfo);
4059

4060
typedef struct {
4061
  int8_t  mqMsgType;
4062
  int32_t code;
4063
  int32_t epoch;
4064
  int64_t consumerId;
4065
  int64_t walsver;
4066
  int64_t walever;
4067
} SMqRspHead;
4068

4069
typedef struct {
4070
  SMsgHead     head;
4071
  char         subKey[TSDB_SUBSCRIBE_KEY_LEN];
4072
  int8_t       withTbName;
4073
  int8_t       useSnapshot;
4074
  int32_t      epoch;
4075
  uint64_t     reqId;
4076
  int64_t      consumerId;
4077
  int64_t      timeout;
4078
  STqOffsetVal reqOffset;
4079
  int8_t       enableReplay;
4080
  int8_t       sourceExcluded;
4081
  int8_t       enableBatchMeta;
4082
} SMqPollReq;
4083

4084
int32_t tSerializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4085
int32_t tDeserializeSMqPollReq(void* buf, int32_t bufLen, SMqPollReq* pReq);
4086
void    tDestroySMqPollReq(SMqPollReq* pReq);
4087

4088
typedef struct {
4089
  int32_t vgId;
4090
  int64_t offset;
4091
  SEpSet  epSet;
4092
} SMqSubVgEp;
4093

4094
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
4095
  int32_t tlen = 0;
9,072✔
4096
  tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
9,072✔
4097
  tlen += taosEncodeFixedI64(buf, pVgEp->offset);
9,072✔
4098
  tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
9,072✔
4099
  return tlen;
9,072✔
4100
}
4101

4102
static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
4103
  buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
4,407!
4104
  buf = taosDecodeFixedI64(buf, &pVgEp->offset);
4,407!
4105
  buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
4,407✔
4106
  return buf;
4,407✔
4107
}
4108

4109
typedef struct {
4110
  char           topic[TSDB_TOPIC_FNAME_LEN];
4111
  char           db[TSDB_DB_FNAME_LEN];
4112
  SArray*        vgs;  // SArray<SMqSubVgEp>
4113
  SSchemaWrapper schema;
4114
} SMqSubTopicEp;
4115

4116
int32_t tEncodeMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp);
4117
void*   tDecodeMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp);
4118
void    tDeleteMqSubTopicEp(SMqSubTopicEp* pSubTopicEp);
4119

4120
typedef struct {
4121
  SMqRspHead   head;
4122
  STqOffsetVal rspOffset;
4123
  int16_t      resMsgType;
4124
  int32_t      metaRspLen;
4125
  void*        metaRsp;
4126
} SMqMetaRsp;
4127

4128
int32_t tEncodeMqMetaRsp(SEncoder* pEncoder, const SMqMetaRsp* pRsp);
4129
int32_t tDecodeMqMetaRsp(SDecoder* pDecoder, SMqMetaRsp* pRsp);
4130
void    tDeleteMqMetaRsp(SMqMetaRsp* pRsp);
4131

4132
#define MQ_DATA_RSP_VERSION 100
4133

4134
typedef struct {
4135
  SMqRspHead   head;
4136
  STqOffsetVal rspOffset;
4137
  STqOffsetVal reqOffset;
4138
  int32_t      blockNum;
4139
  int8_t       withTbName;
4140
  int8_t       withSchema;
4141
  SArray*      blockDataLen;
4142
  SArray*      blockData;
4143
  SArray*      blockTbName;
4144
  SArray*      blockSchema;
4145

4146
  union{
4147
    struct{
4148
      int64_t          sleepTime;
4149
    };
4150
    struct{
4151
      int32_t          createTableNum;
4152
      SArray*          createTableLen;
4153
      SArray*          createTableReq;
4154
    };
4155
  };
4156

4157
} SMqDataRsp;
4158

4159
int32_t tEncodeMqDataRsp(SEncoder *pEncoder, const SMqDataRsp *pObj);
4160
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4161
void    tDeleteMqDataRsp(SMqDataRsp* pRsp);
4162

4163
int32_t tEncodeSTaosxRsp(SEncoder* pEncoder, const SMqDataRsp* pRsp);
4164
int32_t tDecodeSTaosxRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
4165
void    tDeleteSTaosxRsp(SMqDataRsp* pRsp);
4166

4167
typedef struct SMqBatchMetaRsp {
4168
  SMqRspHead   head;  // not serialize
4169
  STqOffsetVal rspOffset;
4170
  SArray*      batchMetaLen;
4171
  SArray*      batchMetaReq;
4172
  void*        pMetaBuff;    // not serialize
4173
  uint32_t     metaBuffLen;  // not serialize
4174
} SMqBatchMetaRsp;
4175

4176
int32_t tEncodeMqBatchMetaRsp(SEncoder* pEncoder, const SMqBatchMetaRsp* pRsp);
4177
int32_t tDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4178
int32_t tSemiDecodeMqBatchMetaRsp(SDecoder* pDecoder, SMqBatchMetaRsp* pRsp);
4179
void    tDeleteMqBatchMetaRsp(SMqBatchMetaRsp* pRsp);
4180

4181
typedef struct {
4182
  SMqRspHead head;
4183
  char       cgroup[TSDB_CGROUP_LEN];
4184
  SArray*    topics;  // SArray<SMqSubTopicEp>
4185
} SMqAskEpRsp;
4186

4187
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
4188
  int32_t tlen = 0;
19,537✔
4189
  // tlen += taosEncodeString(buf, pRsp->cgroup);
4190
  int32_t sz = taosArrayGetSize(pRsp->topics);
19,537!
4191
  tlen += taosEncodeFixedI32(buf, sz);
19,538✔
4192
  for (int32_t i = 0; i < sz; i++) {
26,550✔
4193
    SMqSubTopicEp* pVgEp = (SMqSubTopicEp*)taosArrayGet(pRsp->topics, i);
7,012✔
4194
    tlen += tEncodeMqSubTopicEp(buf, pVgEp);
7,012✔
4195
  }
4196
  return tlen;
19,538✔
4197
}
4198

4199
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
4200
  // buf = taosDecodeStringTo(buf, pRsp->cgroup);
4201
  int32_t sz;
4202
  buf = taosDecodeFixedI32(buf, &sz);
8,356✔
4203
  pRsp->topics = taosArrayInit(sz, sizeof(SMqSubTopicEp));
8,356✔
4204
  if (pRsp->topics == NULL) {
8,355!
4205
    return NULL;
×
4206
  }
4207
  for (int32_t i = 0; i < sz; i++) {
11,750✔
4208
    SMqSubTopicEp topicEp;
4209
    buf = tDecodeMqSubTopicEp(buf, &topicEp);
3,395✔
4210
    if (buf == NULL) {
3,395!
4211
      return NULL;
×
4212
    }
4213
    if ((taosArrayPush(pRsp->topics, &topicEp) == NULL)) {
6,790!
4214
      return NULL;
×
4215
    }
4216
  }
4217
  return buf;
8,355✔
4218
}
4219

4220
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
4221
  taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteMqSubTopicEp);
21,282✔
4222
}
21,282✔
4223

4224
typedef struct {
4225
  int32_t      vgId;
4226
  STqOffsetVal offset;
4227
  int64_t      rows;
4228
  int64_t      ever;
4229
} OffsetRows;
4230

4231
typedef struct {
4232
  char    topicName[TSDB_TOPIC_FNAME_LEN];
4233
  SArray* offsetRows;
4234
} TopicOffsetRows;
4235

4236
typedef struct {
4237
  int64_t consumerId;
4238
  int32_t epoch;
4239
  SArray* topics;
4240
  int8_t  pollFlag;
4241
} SMqHbReq;
4242

4243
typedef struct {
4244
  char   topic[TSDB_TOPIC_FNAME_LEN];
4245
  int8_t noPrivilege;
4246
} STopicPrivilege;
4247

4248
typedef struct {
4249
  SArray* topicPrivileges;  // SArray<STopicPrivilege>
4250
  int32_t debugFlag;
4251
} SMqHbRsp;
4252

4253
typedef struct {
4254
  SMsgHead head;
4255
  int64_t  consumerId;
4256
  char     subKey[TSDB_SUBSCRIBE_KEY_LEN];
4257
} SMqSeekReq;
4258

4259
#define TD_AUTO_CREATE_TABLE 0x1
4260
typedef struct {
4261
  int64_t       suid;
4262
  int64_t       uid;
4263
  int32_t       sver;
4264
  uint32_t      nData;
4265
  uint8_t*      pData;
4266
  SVCreateTbReq cTbReq;
4267
} SVSubmitBlk;
4268

4269
typedef struct {
4270
  SMsgHead header;
4271
  uint64_t sId;
4272
  uint64_t queryId;
4273
  uint64_t clientId;
4274
  uint64_t taskId;
4275
  uint32_t sqlLen;
4276
  uint32_t phyLen;
4277
  char*    sql;
4278
  char*    msg;
4279
  int8_t   source;
4280
} SVDeleteReq;
4281

4282
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4283
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
4284

4285
typedef struct {
4286
  int64_t affectedRows;
4287
} SVDeleteRsp;
4288

4289
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq);
4290
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq);
4291

4292
typedef struct SDeleteRes {
4293
  uint64_t suid;
4294
  SArray*  uidList;
4295
  int64_t  skey;
4296
  int64_t  ekey;
4297
  int64_t  affectedRows;
4298
  char     tableFName[TSDB_TABLE_NAME_LEN];
4299
  char     tsColName[TSDB_COL_NAME_LEN];
4300
  int64_t  ctimeMs;  // fill by vnode
4301
  int8_t   source;
4302
} SDeleteRes;
4303

4304
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
4305
int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes);
4306

4307
typedef struct {
4308
  // int64_t uid;
4309
  char    tbname[TSDB_TABLE_NAME_LEN];
4310
  int64_t startTs;
4311
  int64_t endTs;
4312
} SSingleDeleteReq;
4313

4314
int32_t tEncodeSSingleDeleteReq(SEncoder* pCoder, const SSingleDeleteReq* pReq);
4315
int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
4316

4317
typedef struct {
4318
  int64_t suid;
4319
  SArray* deleteReqs;  // SArray<SSingleDeleteReq>
4320
  int64_t ctimeMs;     // fill by vnode
4321
  int8_t  level;       // 0 tsdb(default), 1 rsma1 , 2 rsma2
4322
} SBatchDeleteReq;
4323

4324
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
4325
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
4326
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
4327

4328
typedef struct {
4329
  int32_t msgIdx;
4330
  int32_t msgType;
4331
  int32_t msgLen;
4332
  void*   msg;
4333
} SBatchMsg;
4334

4335
typedef struct {
4336
  SMsgHead header;
4337
  SArray*  pMsgs;  // SArray<SBatchMsg>
4338
} SBatchReq;
4339

4340
typedef struct {
4341
  int32_t reqType;
4342
  int32_t msgIdx;
4343
  int32_t msgLen;
4344
  int32_t rspCode;
4345
  void*   msg;
4346
} SBatchRspMsg;
4347

4348
typedef struct {
4349
  SArray* pRsps;  // SArray<SBatchRspMsg>
4350
} SBatchRsp;
4351

4352
int32_t                  tSerializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4353
int32_t                  tDeserializeSBatchReq(void* buf, int32_t bufLen, SBatchReq* pReq);
4354
static FORCE_INLINE void tFreeSBatchReqMsg(void* msg) {
12,847,644✔
4355
  if (NULL == msg) {
12,847,644!
4356
    return;
×
4357
  }
4358
  SBatchMsg* pMsg = (SBatchMsg*)msg;
12,847,644✔
4359
  taosMemoryFree(pMsg->msg);
12,847,644✔
4360
}
4361

4362
int32_t tSerializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4363
int32_t tDeserializeSBatchRsp(void* buf, int32_t bufLen, SBatchRsp* pRsp);
4364

4365
static FORCE_INLINE void tFreeSBatchRspMsg(void* p) {
3,734,067✔
4366
  if (NULL == p) {
3,734,067!
4367
    return;
×
4368
  }
4369

4370
  SBatchRspMsg* pRsp = (SBatchRspMsg*)p;
3,734,067✔
4371
  taosMemoryFree(pRsp->msg);
3,734,067✔
4372
}
4373

4374
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4375
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
4376
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4377
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
4378
void    tDestroySMqHbReq(SMqHbReq* pReq);
4379

4380
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4381
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
4382
void    tDestroySMqHbRsp(SMqHbRsp* pRsp);
4383

4384
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4385
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
4386

4387
#define TD_REQ_FROM_APP               0x0
4388
#define SUBMIT_REQ_AUTO_CREATE_TABLE  0x1
4389
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
4390
#define SUBMIT_REQ_FROM_FILE          0x4
4391
#define TD_REQ_FROM_TAOX              0x8
4392
#define SUBMIT_REQUEST_VERSION        (1)
4393

4394
#define TD_REQ_FROM_TAOX_OLD 0x1  // for compatibility
4395

4396
typedef struct {
4397
  int32_t        flags;
4398
  SVCreateTbReq* pCreateTbReq;
4399
  int64_t        suid;
4400
  int64_t        uid;
4401
  int32_t        sver;
4402
  union {
4403
    SArray* aRowP;
4404
    SArray* aCol;
4405
  };
4406
  int64_t ctimeMs;
4407
} SSubmitTbData;
4408

4409
typedef struct {
4410
  SArray* aSubmitTbData;  // SArray<SSubmitTbData>
4411
} SSubmitReq2;
4412

4413
typedef struct {
4414
  SMsgHead header;
4415
  int64_t  version;
4416
  char     data[];  // SSubmitReq2
4417
} SSubmitReq2Msg;
4418

4419
int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
4420
int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
4421
void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
4422
void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
4423

4424
typedef struct {
4425
  int32_t affectedRows;
4426
  SArray* aCreateTbRsp;  // SArray<SVCreateTbRsp>
4427
} SSubmitRsp2;
4428

4429
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
4430
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
4431
void    tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
4432

4433
#define TSDB_MSG_FLG_ENCODE 0x1
4434
#define TSDB_MSG_FLG_DECODE 0x2
4435
#define TSDB_MSG_FLG_CMPT   0x3
4436

4437
typedef struct {
4438
  union {
4439
    struct {
4440
      void*   msgStr;
4441
      int32_t msgLen;
4442
      int64_t ver;
4443
    };
4444
    void* pDataBlock;
4445
  };
4446
} SPackedData;
4447

4448
typedef struct {
4449
  char     fullname[TSDB_VIEW_FNAME_LEN];
4450
  char     name[TSDB_VIEW_NAME_LEN];
4451
  char     dbFName[TSDB_DB_FNAME_LEN];
4452
  char*    querySql;
4453
  char*    sql;
4454
  int8_t   orReplace;
4455
  int8_t   precision;
4456
  int32_t  numOfCols;
4457
  SSchema* pSchema;
4458
} SCMCreateViewReq;
4459

4460
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
4461
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
4462
void    tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
4463

4464
typedef struct {
4465
  char   fullname[TSDB_VIEW_FNAME_LEN];
4466
  char   name[TSDB_VIEW_NAME_LEN];
4467
  char   dbFName[TSDB_DB_FNAME_LEN];
4468
  char*  sql;
4469
  int8_t igNotExists;
4470
} SCMDropViewReq;
4471

4472
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
4473
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
4474
void    tFreeSCMDropViewReq(SCMDropViewReq* pReq);
4475

4476
typedef struct {
4477
  char fullname[TSDB_VIEW_FNAME_LEN];
4478
} SViewMetaReq;
4479
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
4480
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
4481

4482
typedef struct {
4483
  char     name[TSDB_VIEW_NAME_LEN];
4484
  char     dbFName[TSDB_DB_FNAME_LEN];
4485
  char*    user;
4486
  uint64_t dbId;
4487
  uint64_t viewId;
4488
  char*    querySql;
4489
  int8_t   precision;
4490
  int8_t   type;
4491
  int32_t  version;
4492
  int32_t  numOfCols;
4493
  SSchema* pSchema;
4494
} SViewMetaRsp;
4495
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
4496
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
4497
void    tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
4498
typedef struct {
4499
  char name[TSDB_TABLE_FNAME_LEN];  // table name or tsma name
4500
  bool fetchingWithTsmaName;        // if we are fetching with tsma name
4501
} STableTSMAInfoReq;
4502

4503
int32_t tSerializeTableTSMAInfoReq(void* buf, int32_t bufLen, const STableTSMAInfoReq* pReq);
4504
int32_t tDeserializeTableTSMAInfoReq(void* buf, int32_t bufLen, STableTSMAInfoReq* pReq);
4505

4506
typedef struct {
4507
  int32_t  funcId;
4508
  col_id_t colId;
4509
} STableTSMAFuncInfo;
4510

4511
typedef struct {
4512
  char     name[TSDB_TABLE_NAME_LEN];
4513
  uint64_t tsmaId;
4514
  char     targetTb[TSDB_TABLE_NAME_LEN];
4515
  char     targetDbFName[TSDB_DB_FNAME_LEN];
4516
  char     tb[TSDB_TABLE_NAME_LEN];
4517
  char     dbFName[TSDB_DB_FNAME_LEN];
4518
  uint64_t suid;
4519
  uint64_t destTbUid;
4520
  uint64_t dbId;
4521
  int32_t  version;
4522
  int64_t  interval;
4523
  int8_t   unit;
4524
  SArray*  pFuncs;     // SArray<STableTSMAFuncInfo>
4525
  SArray*  pTags;      // SArray<SSchema>
4526
  SArray*  pUsedCols;  // SArray<SSchema>
4527
  char*    ast;
4528

4529
  int64_t streamUid;
4530
  int64_t reqTs;
4531
  int64_t rspTs;
4532
  int64_t delayDuration;  // ms
4533
  bool    fillHistoryFinished;
4534
} STableTSMAInfo;
4535

4536
int32_t tSerializeTableTSMAInfoRsp(void* buf, int32_t bufLen, const STableTSMAInfoRsp* pRsp);
4537
int32_t tDeserializeTableTSMAInfoRsp(void* buf, int32_t bufLen, STableTSMAInfoRsp* pRsp);
4538
int32_t tCloneTbTSMAInfo(STableTSMAInfo* pInfo, STableTSMAInfo** pRes);
4539
void    tFreeTableTSMAInfo(void* p);
4540
void    tFreeAndClearTableTSMAInfo(void* p);
4541
void    tFreeTableTSMAInfoRsp(STableTSMAInfoRsp* pRsp);
4542

4543
#define STSMAHbRsp            STableTSMAInfoRsp
4544
#define tSerializeTSMAHbRsp   tSerializeTableTSMAInfoRsp
4545
#define tDeserializeTSMAHbRsp tDeserializeTableTSMAInfoRsp
4546
#define tFreeTSMAHbRsp        tFreeTableTSMAInfoRsp
4547

4548
typedef struct SStreamProgressReq {
4549
  int64_t streamId;
4550
  int32_t vgId;
4551
  int32_t fetchIdx;
4552
  int32_t subFetchIdx;
4553
} SStreamProgressReq;
4554

4555
int32_t tSerializeStreamProgressReq(void* buf, int32_t bufLen, const SStreamProgressReq* pReq);
4556
int32_t tDeserializeStreamProgressReq(void* buf, int32_t bufLen, SStreamProgressReq* pReq);
4557

4558
typedef struct SStreamProgressRsp {
4559
  int64_t streamId;
4560
  int32_t vgId;
4561
  bool    fillHisFinished;
4562
  int64_t progressDelay;
4563
  int32_t fetchIdx;
4564
  int32_t subFetchIdx;
4565
} SStreamProgressRsp;
4566

4567
int32_t tSerializeStreamProgressRsp(void* buf, int32_t bufLen, const SStreamProgressRsp* pRsp);
4568
int32_t tDeserializeSStreamProgressRsp(void* buf, int32_t bufLen, SStreamProgressRsp* pRsp);
4569

4570
typedef struct SDropCtbWithTsmaSingleVgReq {
4571
  SVgroupInfo vgInfo;
4572
  SArray*     pTbs;  // SVDropTbReq
4573
} SMDropTbReqsOnSingleVg;
4574

4575
int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder* pEncoder, const SMDropTbReqsOnSingleVg* pReq);
4576
int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder* pDecoder, SMDropTbReqsOnSingleVg* pReq);
4577
void    tFreeSMDropTbReqOnSingleVg(void* p);
4578

4579
typedef struct SDropTbsReq {
4580
  SArray* pVgReqs;  // SMDropTbReqsOnSingleVg
4581
} SMDropTbsReq;
4582

4583
int32_t tSerializeSMDropTbsReq(void* buf, int32_t bufLen, const SMDropTbsReq* pReq);
4584
int32_t tDeserializeSMDropTbsReq(void* buf, int32_t bufLen, SMDropTbsReq* pReq);
4585
void    tFreeSMDropTbsReq(void*);
4586

4587
typedef struct SVFetchTtlExpiredTbsRsp {
4588
  SArray* pExpiredTbs;  // SVDropTbReq
4589
  int32_t vgId;
4590
} SVFetchTtlExpiredTbsRsp;
4591

4592
int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder* pCoder, const SVFetchTtlExpiredTbsRsp* pRsp);
4593
int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder* pCoder, SVFetchTtlExpiredTbsRsp* pRsp);
4594

4595
void tFreeFetchTtlExpiredTbsRsp(void* p);
4596

4597
void setDefaultOptionsForField(SFieldWithOptions* field);
4598
void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
4599

4600
#pragma pack(pop)
4601

4602
#ifdef __cplusplus
4603
}
4604
#endif
4605

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